/* Scanner documenti: a tutto schermo, scuro come la fotocamera del telefono. */

html.scanner-open,
html.scanner-open body { overflow: hidden; overscroll-behavior: none; }

.scanner {
  --sc-accent: #00b7cd;
  --sc-accent-strong: #0a95a8;
  --sc-bg: #000;
  --sc-panel: #141414;
  --sc-panel-2: #1f1f1f;
  --sc-line: rgba(255, 255, 255, 0.14);
  --sc-text: #fff;
  --sc-muted: rgba(255, 255, 255, 0.65);
  --sc-danger: #ff6b5e;
  --sc-safe-top: env(safe-area-inset-top, 0px);
  --sc-safe-bottom: env(safe-area-inset-bottom, 0px);
  position: fixed;
  inset: 0;
  z-index: 1000;
  height: 100vh;
  height: 100dvh;
  background: var(--sc-bg);
  color: var(--sc-text);
  font-family: 'Montserrat', system-ui, -apple-system, 'Segoe UI', sans-serif;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

.scanner button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.scanner button:disabled { opacity: 0.4; cursor: default; }
/* Icone: solo quelle dei pulsanti (i riquadri sopra foto e video sono SVG a tutto schermo). */
.scanner button svg, .sc-nocam > svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.scanner button svg { width: 22px; height: 22px; flex: none; }
.scanner :focus-visible { outline: 3px solid var(--sc-accent); outline-offset: 2px; }

.sc-screen { position: absolute; inset: 0; display: none; flex-direction: column; }
.sc-screen.is-active { display: flex; }

/* ===== Pulsanti comuni ===== */
.sc-round {
  width: 46px; height: 46px; flex: none;
  display: grid; place-items: center;
  border: none; border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
}
.sc-round[aria-pressed="true"] { background: #ffd60a; color: #000; }
.sc-pill {
  min-height: 36px; padding: 0 16px;
  border: none; border-radius: 999px;
  background: rgba(0, 0, 0, 0.45); backdrop-filter: blur(8px);
  font-weight: 700; font-size: 0.85rem; letter-spacing: 0.02em;
}
.sc-pill[aria-pressed="true"] { background: var(--sc-accent); color: #00262b; }
.sc-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px;
  border: 1px solid var(--sc-line); border-radius: 14px;
  background: var(--sc-panel-2);
  font-weight: 700; font-size: 0.95rem;
}
.sc-btn-primary { background: var(--sc-accent); border-color: var(--sc-accent); color: #00262b; }
.sc-btn-wide { width: 100%; }
.sc-text-btn {
  display: inline-flex; align-items: center; gap: 2px;
  min-height: 44px; padding: 0 6px;
  border: none; background: none;
  color: var(--sc-accent); font-weight: 600; font-size: 1rem;
}
.sc-text-btn svg { width: 20px; height: 20px; }
.sc-danger { color: var(--sc-danger) !important; }
.sc-link { border: none; background: none; color: var(--sc-muted); text-decoration: underline; min-height: 44px; }

.sc-bar {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px;
  padding: calc(6px + var(--sc-safe-top)) 10px 6px;
  background: var(--sc-panel);
  border-bottom: 1px solid var(--sc-line);
}
.sc-bar > strong, .sc-bar > input { justify-self: center; text-align: center; min-width: 0; }
.sc-bar-bottom { grid-template-columns: 1fr; border-bottom: none; border-top: 1px solid var(--sc-line); padding: 10px 14px calc(10px + var(--sc-safe-bottom)); }
.sc-bar-spacer { width: 60px; }

/* ===== Fotocamera ===== */
.sc-camera { background: #000; }
.sc-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
.sc-overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.sc-quad {
  fill: rgba(0, 183, 205, calc(0.12 + 0.3 * var(--stable, 0)));
  stroke: var(--sc-accent); stroke-width: 3; stroke-linejoin: round;
  transition: fill 0.15s linear;
}
.sc-overlay:not(.has-quad) .sc-quad { display: none; }
.sc-flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.sc-flash.is-on { animation: sc-flash 0.35s ease-out; }
@keyframes sc-flash { 0% { opacity: 0.85; } 100% { opacity: 0; } }

.sc-top {
  position: absolute; left: 0; right: 0; top: 0; z-index: 2;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + var(--sc-safe-top)) 14px 10px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.55), transparent);
}
.sc-hint {
  position: absolute; z-index: 2; left: 50%; top: calc(72px + var(--sc-safe-top)); transform: translateX(-50%);
  max-width: 86%; padding: 7px 14px; border-radius: 999px;
  background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(8px);
  font-size: 0.9rem; font-weight: 600; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sc-hint:empty { display: none; }

.sc-bottom {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 2;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 18px 20px calc(18px + var(--sc-safe-bottom));
  background: linear-gradient(to top, rgba(0,0,0,0.7), transparent);
}
.sc-pages {
  position: relative; justify-self: start;
  width: 58px; height: 72px; padding: 0;
  border: 2px solid rgba(255,255,255,0.85); border-radius: 8px;
  background: rgba(255,255,255,0.08); overflow: visible;
}
.sc-pages img { width: 100%; height: 100%; object-fit: cover; border-radius: 6px; display: block; }
.sc-badge {
  position: absolute; top: -9px; right: -9px; min-width: 22px; height: 22px; padding: 0 6px;
  border-radius: 999px; background: var(--sc-accent); color: #00262b;
  font-size: 0.75rem; font-weight: 800; display: grid; place-items: center;
}
.sc-pages .sc-spinner-mini { position: absolute; inset: 0; margin: auto; }
.sc-shutter {
  width: 78px; height: 78px; padding: 0;
  border: 4px solid #fff; border-radius: 50%; background: transparent;
  display: grid; place-items: center;
}
.sc-shutter span { width: 62px; height: 62px; border-radius: 50%; background: #fff; transition: transform 0.12s ease; }
.sc-shutter:active span { transform: scale(0.88); }
.sc-side { justify-self: end; display: flex; flex-direction: column; gap: 10px; }
.sc-hd { font-weight: 800; font-size: 0.8rem; }

.sc-nocam {
  position: absolute; inset: 0; z-index: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  padding: 24px 28px 140px; text-align: center; background: #000;
}
.sc-nocam > svg { width: 56px; height: 56px; color: var(--sc-muted); }
.sc-nocam p { color: var(--sc-muted); max-width: 320px; line-height: 1.45; }
.sc-nocam .sc-btn { width: min(320px, 100%); }

/* ===== Regola i bordi ===== */
.sc-adjust { background: #0b0b0b; }
.sc-adjust-stage { position: relative; flex: 1; min-height: 0; touch-action: none; overflow: hidden; }
.sc-adjust-image { position: absolute; display: block; }
.sc-adjust-svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.sc-adjust-shade { fill: rgba(0, 0, 0, 0.5); }
.sc-adjust-outline { fill: none; stroke: var(--sc-accent); stroke-width: 2.5; stroke-linejoin: round; }
.sc-adjust-handle { fill: rgba(255,255,255,0.95); stroke: var(--sc-accent); stroke-width: 3; }
.sc-adjust-handle.is-active { fill: var(--sc-accent); stroke: #fff; }
.sc-adjust-svg.is-invalid .sc-adjust-outline { stroke: var(--sc-danger); }
.sc-adjust-svg.is-invalid .sc-adjust-handle { stroke: var(--sc-danger); }
.sc-loupe {
  position: absolute; z-index: 2; pointer-events: none;
  border-radius: 50%; border: 3px solid #fff;
  box-shadow: 0 8px 28px rgba(0,0,0,0.6);
}
.sc-adjust-help { text-align: center; color: var(--sc-muted); font-size: 0.85rem; padding: 6px 12px; }

/* ===== Documento ===== */
.sc-review { background: var(--sc-panel); }
.sc-name {
  width: 100%; max-width: 280px; min-height: 40px; padding: 0 10px;
  border: 1px solid transparent; border-radius: 10px; background: transparent;
  color: var(--sc-text); font: inherit; font-weight: 700; font-size: 16px; text-overflow: ellipsis;
}
.sc-name:focus { border-color: var(--sc-line); background: var(--sc-panel-2); outline: none; }
.sc-filter-all { padding: 12px 14px 4px; }
.sc-filter-all > span { display: block; color: var(--sc-muted); font-size: 0.8rem; margin-bottom: 8px; }
.sc-chips, .sc-filter-row { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.sc-chips::-webkit-scrollbar, .sc-filter-row::-webkit-scrollbar { display: none; }
.sc-chip {
  flex: none; display: flex; flex-direction: column; align-items: center; gap: 6px;
  min-height: 38px; padding: 8px 14px;
  border: 1.5px solid var(--sc-line); border-radius: 12px; background: var(--sc-panel-2);
  font-size: 0.82rem; font-weight: 600; white-space: nowrap;
}
.sc-chip[aria-pressed="true"] { border-color: var(--sc-accent); color: var(--sc-accent); }
.sc-chip img { width: 64px; height: 84px; object-fit: cover; border-radius: 6px; background: #2a2a2a; }
.sc-chip img:not([src]) { animation: sc-pulse 1.2s ease-in-out infinite; }
@keyframes sc-pulse { 50% { opacity: 0.45; } }
.sc-empty { padding: 32px 20px; text-align: center; color: var(--sc-muted); }
.sc-grid {
  flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  list-style: none; margin: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 14px;
  padding: 14px; align-content: start;
}
.sc-tile {
  position: relative; display: block; width: 100%; padding: 0;
  border: none; border-radius: 10px; background: #fff; overflow: hidden;
  box-shadow: 0 6px 18px rgba(0,0,0,0.4);
}
.sc-tile img { display: block; width: 100%; aspect-ratio: 1 / 1.414; object-fit: contain; background: #fff; }
.sc-tile-number {
  position: absolute; left: 8px; bottom: 8px; min-width: 26px; height: 26px; padding: 0 8px;
  border-radius: 999px; background: rgba(0,0,0,0.72); color: #fff;
  font-size: 0.8rem; font-weight: 800; display: grid; place-items: center;
}
.sc-review-actions {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
  padding: 12px 14px calc(12px + var(--sc-safe-bottom));
  border-top: 1px solid var(--sc-line); background: var(--sc-panel);
}
.sc-review-actions #sc-review-print { grid-column: 1 / -1; min-height: 54px; font-size: 1.05rem; }

/* ===== Pagina ===== */
.sc-page { background: #0b0b0b; }
.sc-page-view { flex: 1; min-height: 0; display: grid; place-items: center; padding: 14px; }
.sc-page-view img { max-width: 100%; max-height: 100%; object-fit: contain; background: #fff; box-shadow: 0 10px 30px rgba(0,0,0,0.6); }
.sc-filter-row { padding: 6px 14px 10px; justify-content: safe center; }
.sc-tools {
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 6px 6px calc(8px + var(--sc-safe-bottom));
  border-top: 1px solid var(--sc-line); background: var(--sc-panel);
}
.sc-tools button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 58px; border: none; background: none; color: var(--sc-text); font-size: 0.72rem; font-weight: 600;
}

/* ===== Nome del file ===== */
.sc-modal {
  position: absolute; inset: 0; z-index: 7;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  padding: 16px 16px calc(16px + var(--sc-safe-bottom));
}
@media (min-height: 560px) and (min-width: 600px) { .sc-modal { align-items: center; } }
.sc-modal-card {
  width: min(460px, 100%);
  display: grid; gap: 14px;
  padding: 18px; border-radius: 18px;
  background: var(--sc-panel-2); border: 1px solid var(--sc-line);
  box-shadow: 0 20px 50px rgba(0,0,0,0.6);
  -webkit-user-select: text; user-select: text;
}
.sc-modal-title { font-weight: 700; font-size: 1.05rem; }
.sc-name-row { display: flex; align-items: center; gap: 8px; }
.sc-name-row input {
  flex: 1; min-width: 0; min-height: 48px; padding: 0 12px;
  border: 1.5px solid var(--sc-line); border-radius: 12px;
  background: #0f0f0f; color: var(--sc-text); font: inherit; font-size: 16px; font-weight: 600;
}
.sc-name-row input:focus { outline: none; border-color: var(--sc-accent); }
.sc-name-row span { color: var(--sc-muted); font-weight: 600; }
.sc-modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ===== Attesa e messaggi ===== */
.sc-busy {
  position: absolute; inset: 0; z-index: 5;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(3px);
  font-weight: 600;
}
.sc-spinner {
  width: 38px; height: 38px; border-radius: 50%;
  border: 4px solid rgba(255,255,255,0.25); border-top-color: var(--sc-accent);
  animation: sc-spin 0.8s linear infinite;
}
.sc-spinner-mini { width: 24px; height: 24px; border-width: 3px; }
@keyframes sc-spin { to { transform: rotate(360deg); } }
.sc-toast {
  position: absolute; left: 50%; bottom: calc(130px + var(--sc-safe-bottom)); transform: translateX(-50%);
  z-index: 6; width: max-content; max-width: 88%;
  padding: 10px 16px; border-radius: 12px;
  background: rgba(30, 30, 30, 0.95); color: #fff; font-weight: 600; font-size: 0.9rem; text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}
.sc-toast.is-error { background: #b8382c; }
.sc-toast.is-success { background: #2f7d32; }

.scanner [hidden], .scanner[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  .scanner *, .scanner *::before, .scanner *::after { animation: none !important; transition: none !important; }
}
