/* ============================================================
   Gestionale — design system
   Stessa famiglia di Saldo: impianto Apple (SF, gerarchia di grigi,
   materiali traslucidi) su fondo azzurrino, con raggi ampi e
   tipografia a tracking stretto.
   ============================================================ */

/* ---------- token ---------- */

:root {
  /* Superfici — schema chiaro. Il fondo azzurrino resta visibile
     attraverso superfici bianche traslucide. */
  --bg: #DFF2FD;
  --bg-elev: rgba(255, 255, 255, .60);
  --bg-group: rgba(255, 255, 255, .60);
  --bg-sunken: #D0E9F8;
  --glass: saturate(170%) blur(20px);

  /* testo — navy della stessa famiglia */
  --text: #17405F;
  --text-2: rgba(24, 64, 95, .66);
  --text-3: rgba(24, 64, 95, .40);

  /* riempimenti e separatori */
  --fill1: rgba(47, 168, 238, .26);
  --fill2: rgba(47, 168, 238, .18);
  --fill3: rgba(47, 168, 238, .12);
  --sep: rgba(18, 57, 94, .13);
  --sep-strong: rgba(18, 57, 94, .26);

  /* colori semantici */
  --accent: #2FA8EE;
  --accent-2: #54BCF5;
  --accent-soft: rgba(47, 168, 238, .14);
  --ink: #12395E;
  --blue: #2FA8EE;
  --green: #1FA35C;
  --red: #E74C3C;
  --orange: #F9B234;
  --yellow: #F9B234;
  --purple: #7E7BE8;
  --teal: #3FB1F0;

  /* Superfici in evidenza: l'accento virato verso il navy, per reggere
     il testo bianco su aree grandi. Testi e icone usano --accent puro. */
  --accent-fill: color-mix(in srgb, var(--accent) 50%, #072A45);
  --tile-surface: #F2FAFE;
  --grad: var(--accent-fill);

  /* forma */
  --r-xs: 10px;
  --r-sm: 14px;
  --r-md: 18px;
  --r-lg: 24px;
  --r-xl: 30px;
  --shadow-1: 0 1px 2px rgba(18, 57, 94, .05), 0 6px 20px rgba(18, 57, 94, .07);
  --shadow-2: 0 2px 6px rgba(18, 57, 94, .08), 0 16px 40px rgba(18, 57, 94, .13);
  --shadow-pop: 0 -2px 10px rgba(18, 57, 94, .07), 0 -20px 60px rgba(18, 57, 94, .2);

  /* misure */
  --tabbar-h: 58px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --gutter: 16px;
  --maxw: 720px;

  --ease: cubic-bezier(.32, .72, 0, 1);
  --spring: cubic-bezier(.34, 1.4, .5, 1);

  color-scheme: light dark;
}

/* Scuro: stessa famiglia, virata sul navy profondo invece che sul nero. */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #071726;
    --bg-elev: rgba(23, 64, 95, .46);
    --bg-group: rgba(23, 64, 95, .46);
    --bg-sunken: #04101B;
    --text: #EAF6FE;
    --text-2: rgba(217, 238, 252, .64);
    --text-3: rgba(217, 238, 252, .36);
    --fill1: rgba(84, 188, 245, .30);
    --fill2: rgba(84, 188, 245, .20);
    --fill3: rgba(84, 188, 245, .14);
    --sep: rgba(147, 199, 232, .20);
    --sep-strong: rgba(147, 199, 232, .38);
    --accent: #54BCF5;
    --accent-2: #3FB1F0;
    --accent-soft: rgba(84, 188, 245, .20);
    --ink: #EAF6FE;
    --blue: #54BCF5;
    --green: #2ECC71;
    --red: #FF6B5E;
    --orange: #F9B234;
    --yellow: #F9B234;
    --tile-surface: #0F2941;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-2: 0 12px 40px rgba(0, 0, 0, .55);
    --shadow-pop: 0 -20px 60px rgba(0, 0, 0, .65);
  }
}

/* preferenza esplicita dall'utente: vince sul sistema */
:root[data-theme="light"] {
  --bg: #DFF2FD; --bg-elev: rgba(255,255,255,.60); --bg-group: rgba(255,255,255,.60); --bg-sunken: #D0E9F8;
  --text: #17405F; --text-2: rgba(24,64,95,.66); --text-3: rgba(24,64,95,.40);
  --fill1: rgba(47,168,238,.26); --fill2: rgba(47,168,238,.18); --fill3: rgba(47,168,238,.12);
  --sep: rgba(18,57,94,.13); --sep-strong: rgba(18,57,94,.26);
  --accent: #2FA8EE; --accent-2: #54BCF5; --accent-soft: rgba(47,168,238,.14);
  --ink: #12395E; --blue: #2FA8EE; --green: #1FA35C; --red: #E74C3C; --orange: #F9B234; --yellow: #F9B234;
  --tile-surface: #F2FAFE;
  --shadow-1: 0 1px 2px rgba(18,57,94,.05), 0 6px 20px rgba(18,57,94,.07);
  --shadow-2: 0 2px 6px rgba(18,57,94,.08), 0 16px 40px rgba(18,57,94,.13);
  --shadow-pop: 0 -2px 10px rgba(18,57,94,.07), 0 -20px 60px rgba(18,57,94,.2);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #071726; --bg-elev: rgba(23,64,95,.46); --bg-group: rgba(23,64,95,.46); --bg-sunken: #04101B;
  --text: #EAF6FE; --text-2: rgba(217,238,252,.64); --text-3: rgba(217,238,252,.36);
  --fill1: rgba(84,188,245,.30); --fill2: rgba(84,188,245,.20); --fill3: rgba(84,188,245,.14);
  --sep: rgba(147,199,232,.20); --sep-strong: rgba(147,199,232,.38);
  --accent: #54BCF5; --accent-2: #3FB1F0; --accent-soft: rgba(84,188,245,.20);
  --ink: #EAF6FE; --blue: #54BCF5; --green: #2ECC71; --red: #FF6B5E; --orange: #F9B234; --yellow: #F9B234;
  --tile-surface: #0F2941;
  --shadow-1: 0 1px 2px rgba(0,0,0,.4);
  --shadow-2: 0 12px 40px rgba(0,0,0,.55);
  --shadow-pop: 0 -20px 60px rgba(0,0,0,.65);
  color-scheme: dark;
}

/* ---------- base ---------- */

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  /* Due aloni fissi, azzurro e ambra: danno la profondità che rende
     percepibile la trasparenza delle superfici sopra. */
  background: var(--bg);
  background-image:
    radial-gradient(115% 75% at -5% -5%, rgba(84, 188, 245, .38), transparent 60%),
    radial-gradient(95% 65% at 105% 8%, rgba(249, 178, 52, .16), transparent 55%);
  background-attachment: fixed;
  color: var(--text);
  font-size: 17px;
  line-height: 1.35;
  letter-spacing: -.01em;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
button { background: none; border: none; cursor: pointer; }
input, select, textarea { background: none; border: none; outline: none; }
a { color: var(--accent); text-decoration: none; }
ul, ol { list-style: none; }

.num, .tile-val, .stat-val { font-variant-numeric: tabular-nums; }

::selection { background: var(--accent-soft); }

/* ---------- impianto ---------- */

#app {
  max-width: var(--maxw);
  margin-inline: auto;
  min-height: 100dvh;
  position: relative;
}

.view {
  padding: 14px var(--gutter) calc(var(--tabbar-h) + var(--safe-b) + 34px);
  animation: viewIn .34s var(--ease) both;
}
.view > *:first-child { margin-top: 0; }

@keyframes viewIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- barra superiore ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  padding: calc(var(--safe-t) + 8px) var(--gutter) 8px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(24px);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: calc(var(--safe-t) + 50px);
  transition: box-shadow .2s, border-color .2s;
  border-bottom: .5px solid transparent;
}
.topbar.scrolled { border-bottom-color: var(--sep); }

.topbar h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.5px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar .sub { font-size: 12.5px; font-weight: 500; color: var(--text-2); letter-spacing: 0; }
.topbar .title-wrap { flex: 1; min-width: 0; }

.icon-btn {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border-radius: 50%;
  color: var(--accent);
  background: var(--fill3);
  font-size: 17px;
  flex: none;
  transition: transform .15s var(--spring), background .15s;
}
.icon-btn:active { transform: scale(.9); background: var(--fill1); }
.icon-btn svg { width: 19px; height: 19px; fill: currentColor; }
.icon-btn.plain { background: none; }

/* titolo grande, stile iOS */
.big-title {
  font-size: 34px;
  font-weight: 800;
  letter-spacing: -1.1px;
  margin: 4px 0 2px;
}
.view-intro { color: var(--text-2); font-size: 14.5px; margin-bottom: 16px; }

/* ---------- schede ---------- */

/* Vetro: le superfici sono traslucide e sfocano ciò che sta sotto.
   Applicato ai contenitori, mai alle singole righe, per non moltiplicare
   i livelli di sfocatura in una lista lunga. */
.card, .list, .tile, .stat, .field-group, .hero, .cli-head, .rec {
  backdrop-filter: var(--glass);
  -webkit-backdrop-filter: var(--glass);
  border: .5px solid rgba(255, 255, 255, .5);
}
@media (prefers-color-scheme: dark) {
  .card, .list, .tile, .stat, .field-group, .hero, .cli-head, .rec {
    border-color: rgba(147, 199, 232, .14);
  }
}
:root[data-theme="dark"] .card, :root[data-theme="dark"] .list,
:root[data-theme="dark"] .tile, :root[data-theme="dark"] .stat,
:root[data-theme="dark"] .field-group, :root[data-theme="dark"] .hero,
:root[data-theme="dark"] .cli-head, :root[data-theme="dark"] .rec {
  border-color: rgba(147, 199, 232, .14);
}
:root[data-theme="light"] .card, :root[data-theme="light"] .list,
:root[data-theme="light"] .tile, :root[data-theme="light"] .stat,
:root[data-theme="light"] .field-group, :root[data-theme="light"] .hero,
:root[data-theme="light"] .cli-head, :root[data-theme="light"] .rec {
  border-color: rgba(255, 255, 255, .5);
}

.card {
  background: var(--bg-elev);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  padding: 16px;
  margin-bottom: 14px;
}
.card.tight { padding: 12px; }
.card.flush { padding: 0; overflow: hidden; }

.card-head {
  display: flex; align-items: baseline; gap: 8px;
  margin-bottom: 12px;
}
.card-head h2 { font-size: 17px; font-weight: 700; letter-spacing: -.35px; flex: 1; }
.card-head .link { font-size: 14px; font-weight: 600; color: var(--accent); }

.section-title {
  font-size: 13px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .5px; color: var(--text-2);
  margin: 22px 4px 8px;
}
.section-title .n { color: var(--text-3); font-weight: 600; }

/* ---------- griglia riquadri ---------- */

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
@media (min-width: 560px) { .tiles { grid-template-columns: repeat(4, 1fr); } }

.tile {
  background: var(--bg-elev);
  border-radius: var(--r-md);
  padding: 13px 14px;
  box-shadow: var(--shadow-1);
  text-align: left;
  display: flex; flex-direction: column; gap: 2px;
  transition: transform .18s var(--spring);
  width: 100%;
}
.tile:active { transform: scale(.965); }
.tile .top { display: flex; align-items: center; gap: 7px; }
.tile .ico {
  width: 26px; height: 26px; border-radius: 8px;
  display: grid; place-items: center; font-size: 14px; flex: none;
}
.tile .name { font-size: 13px; font-weight: 600; color: var(--text-2); }
.tile-val { font-size: 22px; font-weight: 700; letter-spacing: -.5px; }
.tile .hint { font-size: 11.5px; font-weight: 600; color: var(--text-3); }
.tile .hint.warn { color: var(--orange); }
.tile .hint.bad { color: var(--red); }
.tile .hint.good { color: var(--green); }

/* ---------- righe di elenco ---------- */

.list { background: var(--bg-elev); border-radius: var(--r-lg); overflow: hidden; box-shadow: var(--shadow-1); margin-bottom: 14px; }
.list.plain { background: none; box-shadow: none; border-radius: 0; }

.row {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px;
  position: relative;
  width: 100%;
  text-align: left;
  transition: background .12s;
}
.row + .row::before {
  content: ''; position: absolute; left: 56px; right: 0; top: 0;
  height: .5px; background: var(--sep);
}
.row:active { background: var(--fill3); }
.row.tap { cursor: pointer; }

.row .ico {
  width: 30px; height: 30px; border-radius: 9px;
  display: grid; place-items: center; font-size: 15px; flex: none;
}
.row .ico.lg { width: 38px; height: 38px; border-radius: 11px; font-size: 18px; }
.row .body { flex: 1; min-width: 0; }
.row .t { display: block; font-size: 16px; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .s { display: block; font-size: 12.5px; color: var(--text-2); margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .end { font-size: 12.5px; font-weight: 600; color: var(--text-2); text-align: right; flex: none; }
.row .end small { display: block; font-size: 11px; font-weight: 600; color: var(--text-3); }
.row .chev { color: var(--text-3); font-size: 13px; flex: none; margin-left: -4px; }

.muted { color: var(--text-2); }
.dim { opacity: .55; }

/* Pastiglia con le iniziali al posto della foto: identifica il cliente
   nell'elenco senza dover caricare immagini. */
.avatar {
  width: 40px; height: 40px; border-radius: 13px; flex: none;
  display: grid; place-items: center;
  font-size: 14.5px; font-weight: 700; letter-spacing: -.3px;
  color: #fff;
}
.avatar.sm { width: 30px; height: 30px; border-radius: 10px; font-size: 12px; }
.avatar.lg { width: 58px; height: 58px; border-radius: 19px; font-size: 21px; }

/* intestazione di gruppo (iniziale alfabetica nell'elenco clienti) */
.group-head {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 14px;
  background: var(--fill3);
  font-weight: 700; font-size: 13px;
  letter-spacing: .4px;
  color: var(--text-2);
  width: 100%; text-align: left;
  position: sticky; top: calc(var(--safe-t) + 50px); z-index: 5;
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
}
.group-head .total { margin-left: auto; font-weight: 650; color: var(--text-3); }

/* ---------- segmenti e chip ---------- */

.segmented {
  display: flex; background: var(--fill3); border-radius: 11px; padding: 2px; gap: 2px;
  margin-bottom: 14px;
}
.segmented button {
  flex: 1; padding: 7px 4px; border-radius: 9px;
  font-size: 13.5px; font-weight: 600; color: var(--text);
  transition: background .18s var(--ease), transform .15s;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.segmented button[aria-selected="true"] { background: var(--bg-elev); box-shadow: var(--shadow-1); font-weight: 650; }
.segmented button:active { transform: scale(.97); }

.chips { display: flex; gap: 7px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  padding: 6px 13px; border-radius: 999px; background: var(--fill3);
  font-size: 13.5px; font-weight: 600; white-space: nowrap; flex: none;
  transition: transform .15s var(--spring);
  display: inline-flex; align-items: center; gap: 6px;
}
.chip[aria-pressed="true"] { background: var(--accent); color: #fff; }
.chip:active { transform: scale(.94); }
.chip .n { opacity: .6; font-size: 12px; font-weight: 700; }

/* etichetta statica (tag del cliente) */
.tag {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  background: var(--fill3); color: var(--text-2);
  font-size: 11.5px; font-weight: 650;
}
.tag-row { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- barra delle azioni rapide ---------- */

/* Il cuore operativo della scheda cliente: sei comandi grandi,
   raggiungibili col pollice, che aprono telefono, messaggi e mappe. */
.actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(72px, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}
.act-btn {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 12px 4px 10px;
  border-radius: var(--r-md);
  background: var(--bg-elev);
  border: .5px solid var(--sep);
  box-shadow: var(--shadow-1);
  transition: transform .16s var(--spring), opacity .15s;
  backdrop-filter: var(--glass); -webkit-backdrop-filter: var(--glass);
}
.act-btn:active { transform: scale(.93); }
.act-btn:disabled { opacity: .32; box-shadow: none; }
.act-btn .e {
  width: 34px; height: 34px; border-radius: 12px;
  display: grid; place-items: center; font-size: 17px;
}
.act-btn .n { font-size: 11.5px; font-weight: 650; color: var(--text-2); text-align: center; line-height: 1.15; }

/* ---------- intestazione della scheda cliente ---------- */

.cli-head {
  background: var(--bg-elev);
  border-radius: var(--r-xl);
  padding: 18px;
  box-shadow: var(--shadow-1);
  margin-bottom: 14px;
  display: flex; gap: 14px; align-items: center;
}
.cli-head .info { flex: 1; min-width: 0; }
.cli-head h2 { font-size: 21px; font-weight: 800; letter-spacing: -.7px; line-height: 1.2; }
.cli-head .ref { font-size: 14.5px; color: var(--text-2); font-weight: 550; margin-top: 3px; }
.cli-head .meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; align-items: center; }

/* ---------- pillole di stato ---------- */

.pill {
  display: inline-block; padding: 2.5px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 700; letter-spacing: .1px;
  white-space: nowrap;
}

/* ---------- timeline delle interazioni ---------- */

.tl { position: relative; padding-left: 2px; }
.tl-item {
  display: flex; gap: 12px; padding: 9px 0;
  position: relative;
  width: 100%; text-align: left;
}
.tl-item::before {
  content: ''; position: absolute; left: 18px; top: 0; bottom: 0;
  width: 1.5px; background: var(--sep);
}
.tl-item:first-child::before { top: 20px; }
.tl-item:last-child::before { bottom: calc(100% - 20px); }
.tl-ico {
  width: 34px; height: 34px; border-radius: 12px;
  display: grid; place-items: center; font-size: 15px;
  flex: none; position: relative; z-index: 1;
  box-shadow: 0 0 0 4px var(--bg);
  margin-top: 3px;
}
.tl-body { flex: 1; min-width: 0; padding-bottom: 4px; }
.tl-top { display: flex; align-items: baseline; gap: 8px; }
.tl-kind { font-size: 15px; font-weight: 650; letter-spacing: -.2px; }
.tl-when { font-size: 12px; font-weight: 600; color: var(--text-3); margin-left: auto; white-space: nowrap; }
.tl-note {
  font-size: 14px; color: var(--text-2); line-height: 1.4; margin-top: 3px;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
}
.tl-note.full { -webkit-line-clamp: unset; }
.tl-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; align-items: center; }
.tl-mic { font-size: 11.5px; font-weight: 650; color: var(--accent); display: inline-flex; align-items: center; gap: 3px; }

/* ---------- registratore vocale ---------- */

.rec {
  background: var(--bg-elev);
  border-radius: var(--r-lg);
  padding: 18px;
  box-shadow: var(--shadow-1);
  margin-bottom: 14px;
  text-align: center;
}
.rec-btn {
  width: 76px; height: 76px; border-radius: 50%;
  display: grid; place-items: center;
  margin: 0 auto 12px;
  background: var(--accent-fill); color: #fff;
  font-size: 30px;
  box-shadow: 0 8px 26px -8px color-mix(in srgb, var(--accent) 70%, transparent);
  transition: transform .18s var(--spring), background .2s;
}
.rec-btn:active { transform: scale(.92); }
.rec-btn.on { background: var(--red); animation: recPulse 1.5s ease-in-out infinite; }
@keyframes recPulse { 50% { box-shadow: 0 0 0 14px color-mix(in srgb, var(--red) 12%, transparent); } }
.rec-time { font-size: 26px; font-weight: 800; letter-spacing: -.8px; font-variant-numeric: tabular-nums; }
.rec-hint { font-size: 13px; color: var(--text-2); margin-top: 4px; line-height: 1.4; }

/* onda: barre animate mentre si registra */
.rec-wave { display: flex; align-items: center; justify-content: center; gap: 3px; height: 26px; margin: 8px 0 2px; }
.rec-wave i {
  width: 3px; border-radius: 999px; background: var(--accent);
  height: 6px; transition: height .09s linear;
}

.rec-text {
  text-align: left; margin-top: 14px; padding: 12px 14px;
  background: var(--fill3); border-radius: var(--r-sm);
  font-size: 15px; line-height: 1.45; min-height: 70px;
  white-space: pre-wrap;
}
.rec-text:empty::before { content: 'La trascrizione comparirà qui mentre parli…'; color: var(--text-3); }
.rec-text .interim { color: var(--text-3); }

audio { width: 100%; margin-top: 12px; }

/* ---------- barra a schede ---------- */

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  display: flex;
  padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--bg-elev) 78%, transparent);
  backdrop-filter: saturate(180%) blur(26px);
  -webkit-backdrop-filter: saturate(180%) blur(26px);
  border-top: .5px solid var(--sep);
  max-width: var(--maxw);
  margin-inline: auto;
}
.tabbar button {
  flex: 1; height: var(--tabbar-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--text-3); font-size: 10.5px; font-weight: 600;
  transition: color .18s;
  position: relative;
}
.tabbar button svg { width: 24px; height: 24px; fill: currentColor; transition: transform .22s var(--spring); }
.tabbar button[aria-current="page"] { color: var(--accent); }
.tabbar button[aria-current="page"] svg { transform: translateY(-1px) scale(1.06); }
.tabbar button:active svg { transform: scale(.86); }
.tabbar .badge {
  position: absolute; top: 6px; left: 54%;
  min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 999px; background: var(--red); color: #fff;
  font-size: 10px; font-weight: 700; display: grid; place-items: center;
  font-variant-numeric: tabular-nums;
}

/* ---------- pulsante d'azione ---------- */

.fab {
  position: fixed;
  right: max(var(--gutter), calc(50vw - var(--maxw) / 2 + var(--gutter)));
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px);
  width: 56px; height: 56px; border-radius: 20px;
  background: var(--tile-surface); color: var(--accent);
  border: .5px solid var(--sep);
  display: grid; place-items: center;
  box-shadow: var(--shadow-2);
  z-index: 45;
  transition: transform .2s var(--spring);
}
.fab svg { width: 26px; height: 26px; fill: currentColor; }
.fab:active { transform: scale(.9); }

/* ---------- fogli modali ---------- */

.scrim {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0, 0, 0, .42);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  animation: fade .28s var(--ease) both;
  display: flex; align-items: flex-end; justify-content: center;
}
@keyframes fade { from { opacity: 0; } }

.sheet {
  /* stesso fondo della pagina, aloni compresi: senza, le superfici
     traslucide del foglio finirebbero su una tinta piatta e sparirebbero */
  background: var(--bg);
  background-image:
    radial-gradient(120% 60% at 0% 0%, rgba(84, 188, 245, .30), transparent 62%),
    radial-gradient(100% 50% at 100% 4%, rgba(249, 178, 52, .14), transparent 58%);
  width: 100%; max-width: var(--maxw);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: var(--shadow-pop);
  max-height: 92dvh;
  display: flex; flex-direction: column;
  animation: sheetUp .42s var(--ease) both;
  overflow: hidden;
}
@keyframes sheetUp { from { transform: translateY(100%); } }
.sheet.closing { animation: sheetDown .28s var(--ease) both; }
@keyframes sheetDown { to { transform: translateY(100%); } }

.sheet-grab { padding: 8px 0 2px; display: grid; place-items: center; flex: none; }
.sheet-grab span { width: 36px; height: 5px; border-radius: 999px; background: var(--fill1); }

.sheet-head {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 14px 12px;
  flex: none;
}
.sheet-head h2 { flex: 1; font-size: 18px; font-weight: 700; letter-spacing: -.4px; text-align: center; }
.sheet-head .act { font-size: 16px; font-weight: 600; color: var(--accent); padding: 4px; min-width: 62px; }
.sheet-head .act.right { text-align: right; font-weight: 650; }
.sheet-head .act:disabled { opacity: .35; }

.sheet-body {
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 0 var(--gutter) calc(var(--safe-b) + 24px);
  flex: 1;
}

/* ---------- moduli ---------- */

.field-group {
  background: var(--bg-elev);
  border-radius: var(--r-md);
  overflow: hidden;
  margin-bottom: 14px;
  box-shadow: var(--shadow-1);
}
.field {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  position: relative;
  min-height: 48px;
  width: 100%; text-align: left;
}
.field + .field::before {
  content: ''; position: absolute; left: 14px; right: 0; top: 0; height: .5px; background: var(--sep);
}
.field > label, .field .k { font-size: 16px; font-weight: 500; flex: none; min-width: 112px; color: var(--text); }
.field input, .field select, .field textarea {
  flex: 1; font-size: 16px; text-align: right; min-width: 0; background: none;
}
.field input::placeholder, .field textarea::placeholder { color: var(--text-3); }
.field .v { flex: 1; text-align: right; font-size: 16px; color: var(--text-2); }
.field .v.set { color: var(--text); font-weight: 500; }
.field .chev { color: var(--text-3); font-size: 13px; flex: none; }
.field textarea { resize: none; text-align: left; min-height: 76px; line-height: 1.45; }
.field.col { flex-direction: column; align-items: stretch; gap: 6px; }
.field.col > label { font-size: 13px; font-weight: 600; color: var(--text-2); min-width: 0; }
.field.col input, .field.col textarea { text-align: left; }
.field:active.tap { background: var(--fill3); }
.field .del { color: var(--red); font-size: 15px; flex: none; padding: 4px; }

/* campo data/ora: stessa geometria delle altre righe */
.field > label.date-wrap {
  flex: 1; min-width: 0;
  display: flex; align-items: center; justify-content: flex-end; gap: 12px;
  font-size: inherit; font-weight: inherit; color: inherit;
}
.date-wrap input[type="date"], .date-wrap input[type="datetime-local"], .date-wrap input[type="time"] {
  flex: 0 1 auto; width: auto;
  text-align: right; font-size: 16px; font-weight: 500;
  color: var(--text);
  -webkit-appearance: none; appearance: none;
  padding: 0; margin: 0; background: none; min-height: 22px;
}
.date-wrap input::-webkit-date-and-time-value { text-align: right; margin: 0; }
.date-wrap input::-webkit-calendar-picker-indicator { display: none; }
.date-wrap input::-webkit-inner-spin-button, .date-wrap input::-webkit-clear-button { display: none; }

.field-note { font-size: 12.5px; color: var(--text-2); padding: 0 6px 14px; margin-top: -8px; line-height: 1.4; }

/* interruttore */
.switch { width: 51px; height: 31px; border-radius: 999px; background: var(--fill1); position: relative; flex: none; transition: background .25s var(--ease); }
.switch[aria-checked="true"] { background: var(--green); }
.switch::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 27px; height: 27px; border-radius: 50%; background: #fff;
  box-shadow: 0 2px 5px rgba(0, 0, 0, .2);
  transition: transform .25s var(--spring);
}
.switch[aria-checked="true"]::after { transform: translateX(20px); }

/* pulsanti */
.btn {
  display: block; width: 100%;
  padding: 14px; border-radius: var(--r-sm);
  font-size: 17px; font-weight: 650;
  background: var(--bg-elev); color: var(--accent);
  backdrop-filter: var(--glass); -webkit-backdrop-filter: var(--glass);
  border: .5px solid var(--sep);
  transition: transform .15s var(--spring), opacity .15s;
  text-align: center;
  box-shadow: var(--shadow-1);
}
.btn:active { transform: scale(.975); }
.btn:disabled { opacity: .4; box-shadow: none; }
.btn.primary { background: var(--accent-fill); color: #fff; border-color: transparent; }
.btn.secondary { background: var(--fill3); color: var(--accent); box-shadow: none; }
.btn.danger { background: var(--fill3); color: var(--red); box-shadow: none; }
.btn.sm { padding: 10px; font-size: 15px; border-radius: var(--r-xs); }
.btn + .btn { margin-top: 10px; }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { margin: 0; }

/* selezione a griglia (esiti, stati) */
.pick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; padding: 4px 0 10px; }
.pick {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 12px 6px; border-radius: var(--r-sm);
  background: var(--bg-elev); box-shadow: var(--shadow-1);
  border: .5px solid var(--sep);
  transition: transform .15s var(--spring);
}
.pick:active { transform: scale(.93); }
.pick[aria-pressed="true"] { outline: 2.5px solid var(--accent); outline-offset: -2.5px; }
.pick .e { width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; font-size: 17px; }
.pick .n { font-size: 11.5px; font-weight: 600; text-align: center; line-height: 1.2; }

/* ---------- tabella (anteprima import) ---------- */

.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 340px; }
.tbl th, .tbl td { padding: 8px 6px; text-align: left; white-space: nowrap; max-width: 150px; overflow: hidden; text-overflow: ellipsis; }
.tbl thead th { font-size: 11px; font-weight: 700; color: var(--text-2); text-transform: uppercase; letter-spacing: .3px; }
.tbl tbody tr + tr td { border-top: .5px solid var(--sep); }
.tbl-wrap {
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  margin: 0 -4px; padding: 0 4px;
  scrollbar-width: thin;
  -webkit-mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 18px), transparent 100%);
  mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 18px), transparent 100%);
}

/* ---------- statistiche in riga ---------- */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(138px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat {
  background: var(--bg-elev); border-radius: var(--r-md); padding: 11px 12px;
  box-shadow: var(--shadow-1); display: flex; align-items: center; gap: 8px;
}
.stat .e { font-size: 17px; flex: none; }
.stat .body { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.stat .k { font-size: 11.5px; font-weight: 600; color: var(--text-2); line-height: 1.25; }
.stat-val { font-size: 16px; font-weight: 700; letter-spacing: -.4px; white-space: nowrap; }
.stat-val.good { color: var(--green); }
.stat-val.bad { color: var(--red); }

/* ---------- stato vuoto ---------- */

.empty {
  text-align: center; padding: 46px 20px; color: var(--text-2);
}
.empty .e { font-size: 44px; margin-bottom: 12px; opacity: .85; }
.empty h3 { font-size: 18px; font-weight: 700; color: var(--text); margin-bottom: 5px; letter-spacing: -.3px; }
.empty p { font-size: 14.5px; line-height: 1.45; max-width: 320px; margin-inline: auto; }
.empty .btn { max-width: 260px; margin: 18px auto 0; }

/* ---------- avvisi ---------- */

.notice {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border-radius: var(--r-md);
  font-size: 14px; font-weight: 550; line-height: 1.35;
  margin-bottom: 14px;
  width: 100%; text-align: left;
}
.notice.warn { background: color-mix(in srgb, var(--orange) 14%, transparent); color: var(--orange); }
.notice.bad { background: color-mix(in srgb, var(--red) 13%, transparent); color: var(--red); }
.notice.good { background: color-mix(in srgb, var(--green) 13%, transparent); color: var(--green); }
.notice.info { background: var(--accent-soft); color: var(--accent); }
.notice .e { font-size: 18px; flex: none; }
.notice .x { margin-left: auto; opacity: .6; font-size: 16px; flex: none; padding: 2px 4px; color: inherit; }

/* ---------- ricerca ---------- */

.search-bar {
  display: flex; align-items: center; gap: 8px;
  background: var(--fill3); border-radius: 11px; padding: 8px 12px;
  margin-bottom: 12px;
}
.search-bar input { flex: 1; font-size: 16px; }
.search-bar .i { color: var(--text-3); font-size: 15px; }
.search-bar .x { color: var(--text-3); font-size: 15px; padding: 0 2px; }

/* ---------- avvisi temporanei ---------- */

.toast-host {
  position: fixed; left: 0; right: 0;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 82px);
  z-index: 90; display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none; padding: 0 20px;
}
.toast {
  background: color-mix(in srgb, var(--text) 88%, transparent);
  color: var(--bg-elev);
  padding: 11px 18px; border-radius: 999px;
  font-size: 14.5px; font-weight: 600;
  box-shadow: var(--shadow-2);
  animation: toastIn .34s var(--spring) both;
  max-width: 100%; text-align: center;
}
.toast.out { animation: toastOut .26s var(--ease) both; }
@keyframes toastIn { from { opacity: 0; transform: translateY(14px) scale(.94); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(8px) scale(.96); } }

/* ---------- indicatore di sincronizzazione ---------- */

.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); flex: none; transition: background .3s; }
.sync-dot.ok { background: var(--green); }
.sync-dot.syncing { background: var(--orange); animation: pulse 1.1s ease-in-out infinite; }
.sync-dot.error, .sync-dot.offline { background: var(--red); }
@keyframes pulse { 50% { opacity: .3; } }

/* ---------- accessibilità e rifiniture ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

:focus-visible { outline: 2.5px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* iPad e desktop: due colonne dove ha senso */
@media (min-width: 700px) {
  .cols-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }
  .cols-2 > * { margin-bottom: 0; }
}

/* ============================================================
   Libreria — componenti propri
   Tutto quello che sta sopra è il design system condiviso con
   Gestionale e Saldo: token, schede, righe, fogli, barra schede.
   Qui sotto solo ciò che serve a un catalogo di libri.
   ============================================================ */

/* ---------- intestazione di sezione ---------- */

.hero {
  background: var(--bg-elev);
  border-radius: var(--r-xl);
  padding: 18px;
  box-shadow: var(--shadow-1);
  margin-bottom: 14px;
}

/* Scheda grande di una sezione nella schermata iniziale: il dorso
   colorato a sinistra la fa leggere come un volume su uno scaffale. */
.sez {
  display: flex; align-items: stretch; gap: 0;
  background: var(--bg-elev);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  backdrop-filter: var(--glass); -webkit-backdrop-filter: var(--glass);
  border: .5px solid rgba(255, 255, 255, .5);
  overflow: hidden;
  margin-bottom: 12px;
  width: 100%; text-align: left;
  transition: transform .18s var(--spring);
}
@media (prefers-color-scheme: dark) { .sez { border-color: rgba(147, 199, 232, .14); } }
:root[data-theme="dark"] .sez { border-color: rgba(147, 199, 232, .14); }
:root[data-theme="light"] .sez { border-color: rgba(255, 255, 255, .5); }
.sez:active { transform: scale(.98); }
.sez .dorso { width: 12px; flex: none; }
.sez .in { flex: 1; min-width: 0; padding: 15px 16px; }
.sez .tit { display: flex; align-items: center; gap: 9px; }
.sez .tit h3 { font-size: 19px; font-weight: 800; letter-spacing: -.5px; }
.sez .tit .e { font-size: 20px; }
.sez .n { margin-left: auto; font-size: 13px; font-weight: 700; color: var(--text-3); font-variant-numeric: tabular-nums; }
.sez .desc {
  font-size: 13.5px; color: var(--text-2); margin-top: 6px; line-height: 1.4;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.sez .meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

/* ---------- barra dei filtri ---------- */

/* Resta appiccicata sotto la testata: con cento titoli, filtrare è
   l'azione principale e non deve richiedere di risalire la pagina. */
.filtri {
  position: sticky;
  top: calc(var(--safe-t) + 50px);
  z-index: 30;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 0 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  margin: 0 calc(var(--gutter) * -1);
  padding-inline: var(--gutter);
}
.filtri .search-bar { flex: 1; margin: 0; min-width: 0; }
.f-btn {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  padding: 8px 13px; border-radius: 11px;
  background: var(--fill3); color: var(--accent);
  font-size: 14px; font-weight: 650;
  transition: transform .15s var(--spring), background .15s;
}
.f-btn:active { transform: scale(.94); }
.f-btn.on { background: var(--accent); color: #fff; }
.f-btn .n {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  background: rgba(255, 255, 255, .28); display: grid; place-items: center;
  font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums;
}

/* riga di riepilogo sotto i filtri */
.f-esito {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-size: 12.5px; font-weight: 600; color: var(--text-2);
  margin: 2px 2px 12px;
}
.f-esito .clear { color: var(--accent); font-weight: 650; }

/* ---------- riga libro ---------- */

/* Il "dorso" al posto della copertina: colore del tema, numero di
   catalogo sopra. Identifica il libro senza scaricare immagini. */
.dorso-libro {
  width: 34px; height: 46px; border-radius: 4px 8px 8px 4px; flex: none;
  display: grid; place-items: center;
  color: #fff; font-size: 11px; font-weight: 800;
  font-variant-numeric: tabular-nums;
  box-shadow: inset 3px 0 0 rgba(0, 0, 0, .22), var(--shadow-1);
  letter-spacing: -.2px;
}
.dorso-libro.sm { width: 26px; height: 34px; font-size: 9.5px; }
.dorso-libro.lg { width: 54px; height: 74px; font-size: 15px; border-radius: 5px 12px 12px 5px; }

.row.libro { align-items: flex-start; padding: 12px 14px; }
.row.libro + .row.libro::before { left: 60px; }
.row.libro .body { padding-top: 1px; }
.row.libro .t { white-space: normal; font-weight: 650; line-height: 1.25; font-size: 15.5px; }
.row.libro .s { white-space: normal; margin-top: 3px; }
.row.libro .segni { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; align-items: center; }

/* marcatori compatti: livello, lingua, essenziale, cautela */
.mk {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 2px 7px; border-radius: 999px;
  font-size: 10.5px; font-weight: 700; letter-spacing: .2px;
  background: var(--fill3); color: var(--text-2);
  white-space: nowrap;
}
.mk.ess { background: color-mix(in srgb, var(--orange) 18%, transparent); color: #A9700D; }
.mk.cautela { background: color-mix(in srgb, var(--red) 14%, transparent); color: var(--red); }
.mk.it { background: color-mix(in srgb, var(--green) 15%, transparent); color: var(--green); }
.mk.liv { font-family: inherit; letter-spacing: 0; }
.mk.stato { background: var(--accent-soft); color: var(--accent); }
@media (prefers-color-scheme: dark) { .mk.ess { color: var(--orange); } }
:root[data-theme="dark"] .mk.ess { color: var(--orange); }
:root[data-theme="light"] .mk.ess { color: #A9700D; }

/* ---------- scheda del libro ---------- */

.libro-head { display: flex; gap: 15px; align-items: flex-start; }
.libro-head .info { flex: 1; min-width: 0; }
.libro-head h2 { font-size: 21px; font-weight: 800; letter-spacing: -.6px; line-height: 1.18; }
.libro-head .tit-it { font-size: 15px; color: var(--text-2); font-weight: 550; margin-top: 3px; font-style: italic; }
.libro-head .aut { font-size: 15px; font-weight: 600; margin-top: 7px; }
.libro-head .ed { font-size: 13px; color: var(--text-2); margin-top: 2px; }
.libro-head .meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 11px; }

.perche {
  font-size: 15.5px; line-height: 1.5; color: var(--text);
}
.perche.cautela {
  border-left: 3px solid var(--red);
  padding-left: 12px;
}

/* stelle di valutazione */
.voto { display: flex; gap: 4px; align-items: center; }
.voto button {
  font-size: 24px; line-height: 1; color: var(--fill1); padding: 2px;
  transition: transform .15s var(--spring), color .15s;
}
.voto button.on { color: var(--orange); }
.voto button:active { transform: scale(1.25); }

/* ---------- percorsi di lettura ---------- */

.perc {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 14px; width: 100%; text-align: left;
  position: relative;
}
.perc + .perc::before {
  content: ''; position: absolute; left: 14px; right: 0; top: 0; height: .5px; background: var(--sep);
}
.perc:active { background: var(--fill3); }
.perc .num {
  width: 30px; height: 30px; border-radius: 10px; flex: none;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
  font-size: 13px; font-weight: 800; font-variant-numeric: tabular-nums;
}
.perc .body { flex: 1; min-width: 0; }
.perc .t { font-size: 15.5px; font-weight: 650; display: block; }
.perc .s { font-size: 12.5px; color: var(--text-2); display: block; margin-top: 1px; }

/* catena dei dorsi in anteprima al percorso */
.catena { display: flex; gap: 3px; flex: none; }

/* ---------- barra di avanzamento della lettura ---------- */

.prog { height: 6px; border-radius: 999px; background: var(--fill2); overflow: hidden; display: flex; }
.prog i { display: block; height: 100%; }
.prog-leg { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 9px; font-size: 12px; font-weight: 600; color: var(--text-2); }
.prog-leg span { display: inline-flex; align-items: center; gap: 5px; }
.prog-leg b { width: 8px; height: 8px; border-radius: 3px; }

/* ---------- gruppi di scelta nel foglio filtri ---------- */

.gruppo { margin-bottom: 18px; }
.gruppo > h4 {
  font-size: 12.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .5px; color: var(--text-2); margin: 0 4px 8px;
  display: flex; align-items: center; gap: 8px;
}
.gruppo > h4 .azzera { margin-left: auto; text-transform: none; letter-spacing: 0; color: var(--accent); font-size: 13px; font-weight: 600; }
.opzioni { display: flex; flex-wrap: wrap; gap: 7px; }
.opz {
  padding: 8px 13px; border-radius: 999px;
  background: var(--fill3); color: var(--text);
  font-size: 14px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px;
  transition: transform .15s var(--spring), background .15s;
  border: .5px solid transparent;
}
.opz:active { transform: scale(.94); }
.opz[aria-pressed="true"] { background: var(--accent); color: #fff; }
.opz .n { opacity: .55; font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }
.opz .pt { width: 10px; height: 10px; border-radius: 3px; flex: none; }

/* elenco lungo (autori): scorre dentro il suo riquadro */
.opzioni.scroll { max-height: 210px; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 2px; }

/* due tendine per l'intervallo di anni */
.anni { display: flex; align-items: center; gap: 10px; }
.anni select {
  flex: 1; padding: 10px 12px; border-radius: var(--r-xs);
  background: var(--fill3); font-size: 15px; font-weight: 600;
  -webkit-appearance: none; appearance: none; text-align: center;
}
.anni span { color: var(--text-3); font-size: 13px; font-weight: 600; }

/* Quattro stati di lettura: due per riga stanno meglio in mano di
   tre più uno spaiato, e le etichette non vanno a capo. */
.pick-grid.stati { grid-template-columns: repeat(2, 1fr); }
