/* =========================================================================
   Paglia — nuovo frontend mobile-first (canary next.*)  ·  F0-F1: guscio
   Token e font IDENTICI all'app attuale (da styles.css :root). Qui si risolvono
   i 3 bug mobile visti dal vivo: composer che galleggia, drawer trasparente,
   testata che mangia lo schermo. Desktop preservato via breakpoint.
   ========================================================================= */
:root {
  /* superfici (avorio caldo) */
  --bg: oklch(0.95 0.011 82);
  --bg-2: oklch(0.985 0.006 82);
  --panel: oklch(1 0 0 / 0.66);
  --panel-2: oklch(1 0 0 / 0.55);
  --line: oklch(0.86 0.014 82);
  --line-soft: oklch(0.80 0.016 82 / 0.7);
  /* testo (bruno caldo) */
  --text: oklch(0.28 0.016 70);
  --muted: oklch(0.50 0.018 70);
  --faint: oklch(0.62 0.016 70);
  /* accento paglia (oro/ambra) */
  --accent: oklch(0.66 0.125 75);
  --accent-ink: oklch(0.99 0.012 85);
  --accent-soft: oklch(0.70 0.13 78 / 0.16);
  --accent-line: oklch(0.62 0.13 75 / 0.42);
  --accent-deep: oklch(0.44 0.10 72);
  --ok: oklch(0.60 0.14 150);

  --font-display: "Bricolage Grotesque", system-ui, sans-serif;
  --font-body: "Hanken Grotesk", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
  --font-serif: "Spectral", Georgia, "Times New Roman", serif;

  --r-sm: 10px; --r-md: 14px; --r-lg: 22px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);

  --topbar-h: 56px;
  --side-w: 288px;
  --rail-w: 300px;
  /* Banda "anteprima" rimossa al cutover del 18/08/2026, quando next.html e' diventata l'unica
     interfaccia. Resta a 0 e le regole che la usano restano innocue: rimetterla e' una riga di
     stile in next.html (--flag-h: 24px) piu' il div .canary-flag. */
  --flag-h: 0px;
}

/* ===================== DARK MODE (F13) — layer di override sui token =====================
   L'identità chiara resta la sorgente; qui si ridefiniscono SOLO i token (bruno caldo scuro +
   oro più brillante). Segue l'OS via prefers-color-scheme; il toggle del viewer stampa data-theme. */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: oklch(0.20 0.012 70); --bg-2: oklch(0.235 0.012 70);
    --panel: oklch(0.28 0.012 70 / 0.55); --panel-2: oklch(0.28 0.012 70 / 0.45);
    --line: oklch(0.36 0.012 70); --line-soft: oklch(0.32 0.012 70 / 0.7);
    --text: oklch(0.92 0.012 82); --muted: oklch(0.72 0.014 82); --faint: oklch(0.56 0.014 82);
    --accent: oklch(0.78 0.13 78); --accent-ink: oklch(0.20 0.02 70);
    --accent-soft: oklch(0.78 0.13 78 / 0.16); --accent-line: oklch(0.72 0.13 75 / 0.4);
    --accent-deep: oklch(0.84 0.11 80); --ok: oklch(0.74 0.15 150);
  }
}
:root[data-theme="dark"] {
  --bg: oklch(0.20 0.012 70); --bg-2: oklch(0.235 0.012 70);
  --panel: oklch(0.28 0.012 70 / 0.55); --panel-2: oklch(0.28 0.012 70 / 0.45);
  --line: oklch(0.36 0.012 70); --line-soft: oklch(0.32 0.012 70 / 0.7);
  --text: oklch(0.92 0.012 82); --muted: oklch(0.72 0.014 82); --faint: oklch(0.56 0.014 82);
  --accent: oklch(0.78 0.13 78); --accent-ink: oklch(0.20 0.02 70);
  --accent-soft: oklch(0.78 0.13 78 / 0.16); --accent-line: oklch(0.72 0.13 75 / 0.4);
  --accent-deep: oklch(0.84 0.11 80); --ok: oklch(0.74 0.15 150);
}
/* il toggle chiaro esplicito vince sempre sul prefers dark del sistema */
:root[data-theme="light"] {
  --bg: oklch(0.95 0.011 82); --bg-2: oklch(0.985 0.006 82);
  --panel: oklch(1 0 0 / 0.66); --panel-2: oklch(1 0 0 / 0.55);
  --line: oklch(0.86 0.014 82); --line-soft: oklch(0.80 0.016 82 / 0.7);
  --text: oklch(0.28 0.016 70); --muted: oklch(0.50 0.018 70); --faint: oklch(0.62 0.016 70);
  --accent: oklch(0.66 0.125 75); --accent-ink: oklch(0.99 0.012 85);
  --accent-soft: oklch(0.70 0.13 78 / 0.16); --accent-line: oklch(0.62 0.13 75 / 0.42);
  --accent-deep: oklch(0.44 0.10 72); --ok: oklch(0.60 0.14 150);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font-body);
  color: var(--text);
  background:
    radial-gradient(1100px 620px at 82% -12%, var(--accent-soft), transparent 60%),
    radial-gradient(820px 500px at -8% 112%, oklch(0.88 0.02 82 / 0.5), transparent 55%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow: hidden; /* lo scroll vive DENTRO .chat, mai sul body */
}
button { font: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* banda "anteprima" in alto (solo canary) */
.canary-flag {
  position: fixed; top: 0; left: 0; right: 0; z-index: 90;
  height: var(--flag-h); display: flex; align-items: center; justify-content: center;
  font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase;
  font-weight: 700; color: var(--accent-ink);
  background: linear-gradient(90deg, oklch(0.66 0.125 75), oklch(0.62 0.13 72));
}

/* ===================== LAYOUT BASE = MOBILE ===================== */
/* La banda canary è fissa in alto: si riserva il suo spazio UNA volta con padding-top su .app,
   e .main riempie il resto (height:100%). Niente doppio padding → niente clip in fondo. */
.app { height: 100dvh; padding-top: var(--flag-h); }
.main {
  height: 100%;
  display: flex; flex-direction: column; min-height: 0;
}

/* --- topbar: altezza fissa, non cresce --- */
.topbar {
  flex: 0 0 auto; height: var(--topbar-h);
  display: flex; align-items: center; gap: 10px; padding: 0 14px;
  background: var(--bg-2); border-bottom: 1px solid var(--line);
}
.burger {
  width: 38px; height: 38px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  font-size: 16px; display: grid; place-items: center;
}
.wordmark { font-family: var(--font-serif); font-weight: 700; font-size: 21px; letter-spacing: -0.01em; }
.wordmark .para { color: var(--accent); margin-right: 1px; }
.ke { margin-left: auto; font-size: 10px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--faint); }

/* --- chat: l'UNICA area che scorre (fix del composer che galleggiava) --- */
.chat {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden;
  padding: 18px 14px; display: flex; flex-direction: column; gap: 16px;
  scroll-behavior: smooth;
}
/* messaggi: struttura .msg > .avatar + .bubble > .body (come l'app attuale) */
.msg { display: flex; gap: 10px; align-items: flex-start; }
.msg.user { flex-direction: row-reverse; }
.avatar {
  flex: 0 0 auto; width: 30px; height: 30px; border-radius: 9px; margin-top: 2px;
  display: grid; place-items: center; font-size: 12px; font-weight: 700;
}
/* avatar utente: sfondo chiaro FISSO → testo scuro fisso (regge anche in dark) */
.msg.user .avatar { background: oklch(0.90 0.03 82); color: oklch(0.44 0.10 72); }
.msg.bot .avatar { background: var(--accent-soft); color: var(--accent); font-family: var(--font-serif); font-size: 17px; }
/* la RISPOSTA riempie la larghezza della colonna (meno righe, meno scroll verticale);
   la DOMANDA resta compatta a destra */
.bubble { border-radius: var(--r-md); padding: 12px 16px; font-size: 15px; line-height: 1.58; max-width: 100%; min-width: 0; }
.msg.user .bubble { background: oklch(0.92 0.035 82); border: 1px solid oklch(0.86 0.04 82); color: oklch(0.30 0.03 70); max-width: min(88%, 60ch); }
.msg.bot .bubble { flex: 1 1 auto; background: var(--panel); border: 1px solid var(--line); backdrop-filter: blur(6px); }

/* contenuto markdown della risposta */
.body > *:first-child { margin-top: 0; }
.body > *:last-child { margin-bottom: 0; }
.body p { margin: 0 0 10px; }
.body h3 { font-family: var(--font-display); font-weight: 700; font-size: 16px; margin: 18px 0 8px; }
.body ul, .body ol { margin: 0 0 10px; padding-left: 20px; }
.body li { margin-bottom: 4px; }
.body strong { font-weight: 700; color: var(--text); }
.body code { font-family: var(--font-mono); font-size: 0.88em; background: var(--accent-soft); padding: 1px 5px; border-radius: 5px; }
.body a { color: var(--accent-deep); text-underline-offset: 2px; }
.reveal { animation: fadein 0.4s var(--ease); }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* indicatore "sto pensando" */
.typing { display: inline-flex; gap: 5px; padding: 4px 2px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); opacity: 0.4; animation: tdot 1.3s ease-in-out infinite; }
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes tdot { 0%, 100% { opacity: 0.25; transform: translateY(0); } 50% { opacity: 1; transform: translateY(-3px); } }

/* barra di avanzamento (F5) */
.progress { margin-bottom: 12px; }
.progress-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 7px; gap: 12px; }
.progress-label { font-size: 13px; color: var(--muted); font-weight: 600; }
.progress-pct { font-size: 12px; color: var(--faint); font-variant-numeric: tabular-nums; }
.progress-track { height: 6px; border-radius: 999px; background: var(--line); overflow: hidden; }
.progress-fill { height: 100%; width: 0; border-radius: 999px; background: linear-gradient(90deg, oklch(0.72 0.13 78), oklch(0.63 0.13 72)); }
.progress-steps { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.pstep { font-size: 11px; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--line); color: var(--faint); background: transparent; transition: color 0.2s var(--ease), background 0.2s var(--ease), border-color 0.2s var(--ease); }
.pstep--active { border-color: var(--accent-line); background: var(--accent-soft); color: var(--accent-deep); font-weight: 600; }
.pstep--done { color: var(--muted); border-color: var(--line-soft); }
.pstep--done::before { content: "✓ "; color: var(--ok); }
.progress--done .progress-fill { background: linear-gradient(90deg, oklch(0.62 0.14 150), oklch(0.60 0.14 150)); }
.progress--gone { opacity: 0; transform: translateY(-4px); transition: opacity 0.4s var(--ease), transform 0.4s var(--ease); }

/* ===================== FONTI: chip pannello + modale (F6-F7) ===================== */
.sources { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line-soft); }
.sources-title { font-size: 11px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--faint); margin-right: 2px; }
.source { display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--accent-line); background: var(--accent-soft); color: var(--accent-deep); font-size: 12.5px; font-weight: 600; font-family: inherit; transition: background 0.15s var(--ease); }
.source:hover { background: oklch(0.70 0.13 78 / 0.28); }
.source-sent, .source-prassi, .source-ccnl { border-color: var(--line); background: var(--panel); color: var(--text); }
.source-sent--fav { border-color: oklch(0.70 0.14 150 / 0.5); background: oklch(0.70 0.14 150 / 0.12); }
.source-sent--contra { border-color: oklch(0.62 0.16 28 / 0.5); background: oklch(0.62 0.16 28 / 0.10); }
.stance { font-size: 10px; font-weight: 700; text-transform: uppercase; padding: 1px 6px; border-radius: 999px; margin-left: 3px; }
.stance--fav { background: oklch(0.70 0.14 150 / 0.2); color: oklch(0.42 0.12 150); }
.stance--contra { background: oklch(0.62 0.16 28 / 0.18); color: oklch(0.50 0.16 28); }

/* rail (desktop): gruppi verticali; sostituisce le fonti inline per non duplicarle */
.src-group { margin-bottom: 16px; }
.src-group .sources-title { display: block; margin-bottom: 8px; }
.src-chips { display: flex; flex-wrap: wrap; gap: 6px; }
@media (min-width: 1024px) { .msg .sources { display: none; } }

/* modale della fonte (norma / sentenza / prassi / ccnl) */
.norma-overlay { position: fixed; inset: 0; z-index: 110; display: grid; place-items: center; padding: 18px; background: oklch(0.20 0.02 70 / 0.5); }
.norma-overlay[hidden] { display: none; }
.norma-modal { width: 100%; max-width: 720px; max-height: 86dvh; display: flex; flex-direction: column; background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: 0 40px 84px -32px oklch(0.20 0.03 70 / 0.6); overflow: hidden; }
.norma-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 14px 0; }
.norma-copy { padding: 6px 12px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--panel); color: var(--muted); font-size: 13px; }
.norma-close { width: 34px; height: 34px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--panel); color: var(--text); font-size: 20px; line-height: 1; }
.norma-head { padding: 10px 22px 14px; border-bottom: 1px solid var(--line); }
.norma-head h3 { font-family: var(--font-serif); font-weight: 700; font-size: 20px; margin: 0 0 6px; text-wrap: balance; }
.norma-meta { font-size: 13px; color: var(--muted); line-height: 1.45; }
.norma-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 18px 22px; white-space: pre-wrap; font-size: 14.5px; line-height: 1.6; color: var(--text); }
.norma-foot { flex: 0 0 auto; padding: 10px 22px; border-top: 1px solid var(--line); font-family: var(--font-mono); font-size: 12px; color: var(--faint); word-break: break-all; }

/* ===================== BARRA AZIONI · ALLEGATI · CHIARIMENTI (F8-F10) ===================== */
.msg-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line-soft); }
.msg-action { padding: 6px 12px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--bg-2); color: var(--muted); font-size: 13px; font-family: inherit; }
.msg-action:hover { background: var(--panel); color: var(--text); }
.msg-cost { margin-left: auto; font-size: 12px; color: var(--faint); font-variant-numeric: tabular-nums; }

.allegati { display: flex; flex-wrap: wrap; gap: 6px; }
.allegati:empty { display: none; }
.allegati:not(:empty) { margin-bottom: 10px; }
.allegato { display: inline-flex; align-items: center; gap: 6px; max-width: 220px; padding: 5px 8px 5px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg-2); font-size: 12.5px; }
.allegato.is-loading { opacity: 0.7; }
.allegato.is-error { border-color: oklch(0.62 0.16 28 / 0.5); background: oklch(0.62 0.16 28 / 0.08); }
.allegato-nome { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.allegato-x { width: 18px; height: 18px; border-radius: 50%; border: 0; background: transparent; color: var(--faint); font-size: 14px; line-height: 1; }
.allegato-x:hover { color: var(--text); background: var(--line); }
.composer-msg { font-size: 12.5px; color: oklch(0.50 0.16 28); margin-bottom: 8px; display: none; }
.composer-msg.show { display: block; }
.composer.drag { outline: 2px dashed var(--accent-line); outline-offset: 3px; }

.msg-files { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.msg-file { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: oklch(0.86 0.04 82); color: oklch(0.35 0.03 70); }

.questions { margin-top: 12px; display: flex; flex-direction: column; gap: 14px; }
.q .qtext { font-size: 14.5px; line-height: 1.5; margin-bottom: 8px; }
.qopts { display: flex; flex-wrap: wrap; gap: 8px; }
.qopt { padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); color: var(--text); font-size: 13.5px; font-family: inherit; }
.qopt:hover { border-color: var(--accent-line); }
.qopt.sel { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-deep); font-weight: 600; }
/* Casella di testo libero: c'è SEMPRE, anche sotto le opzioni (le opzioni sono ipotesi del
   triage, il caso vero spesso non è nessuna delle due). Tratteggiata da ferma, piena a fuoco. */
.qfree { display: block; width: 100%; max-width: 520px; margin-top: 8px; padding: 9px 13px; border-radius: var(--r-md); border: 1px dashed var(--line); background: var(--bg-2); color: var(--text); font-size: 13.5px; font-family: inherit; }
.qfree::placeholder { color: var(--muted); }
.qfree:focus { outline: none; border-style: solid; border-color: var(--accent-line); background: var(--panel); }
.qfree:disabled { opacity: 0.5; }
.qsend { align-self: flex-start; padding: 9px 18px; border-radius: var(--r-md); border: 0; background: linear-gradient(160deg, oklch(0.72 0.13 78), oklch(0.63 0.13 72)); color: #fff; font-weight: 700; font-size: 14px; }
.qsend:disabled { opacity: 0.5; }

/* --- chip citazione: sembrano cliccabili --- */
.cite {
  display: inline; padding: 1px 7px; border-radius: 7px; white-space: nowrap;
  background: var(--accent-soft); border: 1px solid var(--accent-line);
  color: var(--accent-deep); font-weight: 600; font-size: 0.95em;
  transition: background 0.15s var(--ease);
}
.cite:hover { background: oklch(0.70 0.13 78 / 0.28); }
.cite-sent, .cite-prassi { font-variant-numeric: tabular-nums; }

/* --- composer: ANCORATO in basso (non più fluttuante) --- */
.composer {
  flex: 0 0 auto; margin: 10px 12px; padding: 12px 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: 0 8px 26px -14px oklch(0.4 0.05 70 / 0.35);
  backdrop-filter: blur(8px);
}
.composer-input {
  width: 100%; border: 0; background: transparent; resize: none; color: var(--text);
  font: inherit; font-size: 15px; line-height: 1.5; max-height: 40vh;
}
.composer-input::placeholder { color: var(--faint); }
.composer-input:focus { outline: none; }
.composer-bar { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.btn-attach {
  font-size: 13px; padding: 8px 13px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--bg-2); color: var(--muted);
}
.btn-send {
  margin-left: auto; width: 46px; height: 42px; border: 0; border-radius: 13px;
  background: linear-gradient(160deg, oklch(0.72 0.13 78), oklch(0.63 0.13 72));
  color: #fff; font-size: 18px;
  box-shadow: 0 8px 16px -6px oklch(0.66 0.125 75 / 0.7);
}
.disclaimer {
  flex: 0 0 auto; text-align: center; font-size: 12.5px; line-height: 1.5;
  color: var(--faint); padding: 0 20px 12px;
}
.disclaimer strong { color: var(--muted); }

/* ===================== SIDEBAR — drawer su mobile ===================== */
.scrim {
  position: fixed; inset: 0; z-index: 40; background: oklch(0.2 0.02 70 / 0.42);
  opacity: 0; pointer-events: none; transition: opacity 0.28s var(--ease);
}
.app.drawer-open .scrim { opacity: 1; pointer-events: auto; }
.sidebar {
  position: fixed; top: var(--flag-h); bottom: 0; left: 0; z-index: 50;
  width: min(85vw, 320px);
  background: var(--bg-2);                 /* SFONDO PIENO (fix drawer trasparente) */
  border-right: 1px solid var(--line);
  box-shadow: 8px 0 40px -12px oklch(0.2 0.03 70 / 0.35);
  transform: translateX(-100%); transition: transform 0.3s var(--ease);
  display: flex; flex-direction: column;
}
.app.drawer-open .sidebar { transform: none; }
.side-collapse { display: none; }
.side-top { flex: 0 0 auto; padding: 16px 14px 10px; }
.btn-new {
  width: 100%; padding: 11px; border-radius: var(--r-md);
  border: 1px solid var(--accent-line); background: var(--accent-soft);
  color: var(--accent-deep); font-weight: 700; font-size: 14px;
}
.side-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 4px 12px 12px; }
.side-lbl { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--faint); font-weight: 700; margin: 12px 4px 8px; }
.side-search input {
  width: 100%; padding: 9px 12px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; font-size: 13px;
}
.side-search input::placeholder { color: var(--faint); }
.side-filters { display: flex; gap: 6px; margin: 11px 0 12px; flex-wrap: wrap; }
.side-tab { font-size: 12px; padding: 5px 11px; border-radius: 999px; border: 1px solid var(--line); background: transparent; color: var(--muted); font-family: inherit; }
.side-tab.attiva { background: var(--text); color: var(--bg); border-color: var(--text); }
.side-list { display: flex; flex-direction: column; gap: 2px; }
.side-empty { color: var(--faint); font-size: 13px; padding: 10px; line-height: 1.5; }
.side-item { display: flex; align-items: center; gap: 6px; padding: 8px 8px 8px 6px; border-radius: var(--r-sm); cursor: pointer; }
.side-item:hover { background: var(--panel); }
.side-item.attiva { background: var(--accent-soft); }
.si-star { flex: 0 0 auto; width: 26px; height: 26px; border: 0; background: transparent; color: var(--faint); font-size: 14px; border-radius: 6px; }
.si-star.on { color: var(--accent); }
.si-star:hover { background: var(--line); }
.si-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.si-titolo { font-size: 13.5px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.si-data { font-size: 11px; color: var(--faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.si-tag { color: var(--accent-deep); }
.si-menu { flex: 0 0 auto; width: 26px; height: 26px; border: 0; background: transparent; color: var(--faint); font-size: 16px; border-radius: 6px; opacity: 0; }
.side-item:hover .si-menu { opacity: 1; }
.si-menu:hover { background: var(--line); }
@media (max-width: 759px) { .si-menu { opacity: 1; } }

/* menu ⋯ flottante (etichetta / rinomina / elimina) */
.chat-menu { position: fixed; z-index: 80; background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px -10px oklch(0.20 0.03 70 / 0.35); padding: 5px; min-width: 172px; display: flex; flex-direction: column; }
.chat-menu button { text-align: left; padding: 9px 12px; border: 0; background: transparent; color: var(--text); font-size: 13.5px; border-radius: 7px; font-family: inherit; }
.chat-menu button:hover { background: var(--accent-soft); }
.chat-menu button.danger { color: oklch(0.55 0.17 25); }
.chat-menu button.danger:hover { background: oklch(0.62 0.16 28 / 0.1); }

.side-foot { flex: 0 0 auto; border-top: 1px solid var(--line); padding: 12px; display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.sf-id { display: flex; align-items: center; gap: 10px; padding: 6px; border: 0; background: transparent; border-radius: var(--r-sm); text-align: left; min-width: 0; }
.sf-id:hover { background: var(--accent-soft); }
.sf-avatar { flex: 0 0 auto; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-deep); font-weight: 700; font-size: 13px; }
.sf-info { display: flex; flex-direction: column; min-width: 0; }
.sf-nome { font-size: 13.5px; font-weight: 600; color: var(--text); text-transform: capitalize; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sf-ruolo { font-size: 11px; color: var(--faint); }
.sf-gear { margin-left: auto; color: var(--faint); font-size: 14px; }
.sf-logout { align-self: center; padding: 8px 12px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--panel); color: var(--muted); font-size: 13px; }
.sf-credito { grid-column: 1 / -1; margin-top: 2px; }
.sf-credito-top { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--muted); margin-bottom: 5px; font-variant-numeric: tabular-nums; }
.sf-bar { height: 6px; border-radius: 999px; background: var(--line); overflow: hidden; }
.sf-bar span { display: block; height: 100%; background: linear-gradient(90deg, oklch(0.72 0.13 78), oklch(0.63 0.13 72)); }

/* ===================== RAIL FONTI (solo desktop) ===================== */
.rail { display: none; }

/* ===================== BREAKPOINT ===================== */
/* Tablet: la sidebar diventa colonna fissa (niente drawer), rail ancora nascosto */
@media (min-width: 760px) {
  /* la banda canary resta fissa in alto; .app riserva il suo spazio con padding-top (invariato),
     il grid riempie il resto e stira le colonne all'altezza della riga */
  .app { display: grid; grid-template-columns: var(--side-w) 1fr; }
  .burger { display: none; }
  .scrim { display: none; }
  .sidebar { position: static; transform: none; width: auto; box-shadow: none; height: 100%; min-height: 0; }
  .side-collapse { display: grid; place-items: center; width: 34px; height: 34px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--panel); color: var(--muted); }
  .side-top { display: flex; align-items: center; gap: 8px; }
}
/* Desktop pieno: compare il rail fonti a destra */
@media (min-width: 1024px) {
  .app { grid-template-columns: var(--side-w) 1fr var(--rail-w); }
  .rail {
    display: flex; flex-direction: column; height: 100%; min-height: 0; overflow-y: auto;
    background: var(--bg-2); border-left: 1px solid var(--line); padding: 16px 14px;
  }
  .rail-lbl { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--faint); font-weight: 700; margin: 2px 2px 12px; }
  .src { padding: 11px 12px; border-radius: var(--r-md); border: 1px solid var(--line); background: var(--panel); margin-bottom: 10px; }
  .src-t { font-size: 13px; font-weight: 700; color: var(--accent-deep); }
  .src-s { font-size: 11.5px; color: var(--muted); margin-top: 3px; line-height: 1.4; }
  .chat { padding: 24px 28px; }
  .composer { margin: 12px 24px; }
}

/* collapse della sidebar su desktop (il ☰ riappare per riaprirla) */
@media (min-width: 760px) {
  .app.side-collapsed { grid-template-columns: 1fr; }
  .app.side-collapsed > .sidebar { display: none; }
  .app.side-collapsed .burger { display: grid; }
}
@media (min-width: 1024px) {
  .app.side-collapsed { grid-template-columns: 1fr var(--rail-w); }
}

/* ===================== EMPTY-STATE + STATISTICHE (F2) ===================== */
.welcome { margin: auto; max-width: 640px; width: 100%; text-align: center; padding: 20px 6px; }
.welcome-mark {
  font-family: var(--font-serif); font-weight: 700; font-size: 42px; line-height: 1; color: var(--accent);
  display: inline-grid; place-items: center; width: 84px; height: 84px; margin: 0 auto 4px;
  border-radius: 24px; background: var(--accent-soft); position: relative;
  animation: mark-breath 4.5s var(--ease) infinite;
}
.welcome-mark::before {
  content: ''; position: absolute; inset: -6px; border-radius: 28px; border: 1px solid var(--accent-line);
  animation: mark-halo 4.5s var(--ease) infinite;
}
@keyframes mark-breath { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
@keyframes mark-halo { 0%, 100% { transform: scale(1); opacity: 0.4; } 50% { transform: scale(1.06); opacity: 0.12; } }
@media (prefers-reduced-motion: reduce) { .welcome-mark, .welcome-mark::before { animation: none !important; } }
.welcome-title { font-family: var(--font-display); font-weight: 700; font-size: clamp(20px, 5vw, 26px); margin: 12px 0 8px; text-wrap: balance; }
.welcome-sub { color: var(--muted); font-size: 14.5px; line-height: 1.55; margin: 0 auto; max-width: 52ch; }
.hstats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 24px; text-align: left; }
.hstat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-md); padding: 12px 13px; display: flex; flex-direction: column; gap: 1px; backdrop-filter: blur(6px); }
.hval { font-family: var(--font-display); font-weight: 700; font-size: 20px; color: var(--text); font-variant-numeric: tabular-nums; line-height: 1.15; }
.hval-sm { font-size: 14px; }
.hlab { font-size: 11.5px; color: var(--faint); }
.hsub { font-size: 11px; color: var(--accent-deep); margin-top: 1px; }
@media (min-width: 560px) { .hstats { grid-template-columns: repeat(4, 1fr); } }

.chat-list .empty, .rail-empty { color: var(--faint); font-size: 13px; padding: 10px; line-height: 1.5; }
.side-foot:empty { display: none; }
.sf-bar span.vuoto { background: oklch(0.62 0.16 28); }

/* ===================== OVERLAY AUTENTICAZIONE (F3) ===================== */
.auth-overlay {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; overflow-y: auto;
  background: radial-gradient(1000px 560px at 80% -10%, var(--accent-soft), transparent 60%),
              radial-gradient(820px 500px at -8% 112%, oklch(0.88 0.02 82 / 0.6), transparent 55%), var(--bg);
}
.auth-card { width: 100%; max-width: 400px; background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 28px 26px; box-shadow: 0 30px 70px -32px oklch(0.3 0.04 70 / 0.5); }
.auth-logo { font-family: var(--font-serif); font-weight: 700; font-size: 36px; line-height: 1; color: var(--accent); text-align: center; margin-bottom: 10px; }
.auth-card h2 { font-family: var(--font-display); font-weight: 700; font-size: 22px; margin: 0 0 4px; text-align: center; }
.auth-sub { color: var(--muted); font-size: 14px; line-height: 1.5; margin: 0 0 18px; text-align: center; }
.auth-field { margin-bottom: 12px; display: flex; flex-direction: column; gap: 5px; }
.auth-field label { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.auth-field input, .auth-field select { padding: 11px 12px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; font-size: 15px; }
.auth-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.auth-otp { font-family: var(--font-mono); letter-spacing: 6px; text-align: center; font-size: 22px !important; }
.auth-err { color: oklch(0.55 0.17 25); font-size: 13px; min-height: 18px; margin: 2px 0 6px; }
.auth-btn { width: 100%; padding: 12px; border-radius: var(--r-md); border: 0; background: linear-gradient(160deg, oklch(0.72 0.13 78), oklch(0.63 0.13 72)); color: #fff; font-weight: 700; font-size: 15px; margin-top: 4px; }
.auth-btn.secondario { background: transparent; color: var(--muted); border: 1px solid var(--line); margin-top: 8px; }
.auth-switch { text-align: center; font-size: 13px; color: var(--muted); margin-top: 16px; }
.auth-switch button { background: none; border: 0; color: var(--accent-deep); font-weight: 600; padding: 0; }
.auth-back { background: none; border: 0; color: var(--muted); font-size: 13px; padding: 0 0 12px; }

/* ===================== LOGO MASCOTTE ANIMATO (solo pagina di login) ===================== */
.auth-mascot { position: relative; width: 149px; height: 144px; margin: 0 auto 12px; }
.auth-mascot .pl-mascot { position: absolute; top: 0; left: 0; transform: scale(0.557); transform-origin: top left; }
.pl-mascot { position: relative; width: 268px; height: 248px; }
.pl-spark { position: absolute; font-family: var(--font-serif); opacity: 0; animation: pl-spark 2.6s ease-out infinite; }
.pl-spark.s1 { left: 40px; top: 10px; font-size: 20px; color: var(--accent); animation-delay: .4s; }
.pl-spark.s2 { right: 40px; top: 18px; font-size: 15px; color: #b98f3e; animation-delay: 1.5s; }
.pl-suit { position: absolute; left: 24px; bottom: 0; width: 220px; height: 120px; z-index: 1; background: linear-gradient(165deg, #dcb96f 0%, #c39a4d 52%, #a67d35 100%); border-radius: 120px 120px 22px 22px / 96px 96px 22px 22px; box-shadow: inset 0 6px 16px rgba(255,240,200,.25), inset 0 -10px 22px rgba(80,55,15,.4); }
.pl-lapel-l { position: absolute; left: 78px; top: 6px; width: 0; height: 0; border-left: 30px solid transparent; border-top: 64px solid rgba(150,112,46,.55); }
.pl-lapel-r { position: absolute; right: 78px; top: 6px; width: 0; height: 0; border-right: 30px solid transparent; border-top: 64px solid rgba(150,112,46,.55); }
.pl-collar { position: absolute; left: 50%; top: 4px; transform: translateX(-50%); width: 0; height: 0; border-left: 24px solid transparent; border-right: 24px solid transparent; border-top: 62px solid #e9ecf0; }
.pl-knot { position: absolute; left: 50%; top: 6px; transform: translateX(-50%); width: 13px; height: 8px; background: #5d6675; clip-path: polygon(20% 0,80% 0,100% 100%,0 100%); }
.pl-tie { position: absolute; left: 50%; top: 13px; transform: translateX(-50%); width: 15px; height: 46px; background: repeating-linear-gradient(135deg,#5d6675 0 5px,#6b7484 5px 7px); clip-path: polygon(28% 0,72% 0,100% 88%,50% 100%,0 88%); }
.pl-head { position: absolute; left: 58px; top: 6px; width: 152px; height: 152px; z-index: 3; animation: pl-bob 3s ease-in-out infinite; transform-origin: 50% 90%; }
.pl-head-inner { position: relative; width: 152px; height: 152px; border-radius: 50%; overflow: hidden; box-shadow: 0 0 0 4px var(--accent), 0 0 0 6px rgba(0,0,0,.45), 0 14px 30px -10px rgba(80,55,15,.5); }
.pl-head-inner img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pl-scan { position: absolute; left: 0; right: 0; top: 0; height: 40%; background: linear-gradient(180deg, transparent, rgba(216,169,78,.55), transparent); mix-blend-mode: screen; animation: pl-scan 4.2s ease-in-out infinite; }
.pl-book { position: absolute; left: 30px; bottom: -6px; width: 208px; height: 150px; z-index: 4; display: flex; justify-content: center; }
.pl-book-persp { position: relative; width: 204px; height: 128px; perspective: 920px; }
.pl-book-3d { position: absolute; inset: 0; transform: rotateX(29deg); transform-style: preserve-3d; }
.pl-cover { position: absolute; left: -8px; top: 16px; width: 220px; height: 104px; background: linear-gradient(158deg,#3c2817,#241509 68%,#180e05); border-radius: 9px; box-shadow: 0 12px 20px rgba(0,0,0,.45); }
.pl-cover-inset { position: absolute; left: -4px; top: 18px; width: 212px; height: 100px; border-radius: 7px; box-shadow: inset 0 0 0 1.5px rgba(206,166,84,.45); }
.pl-thick { position: absolute; left: -3px; top: 9px; width: 206px; height: 99px; border-radius: 6px; background: repeating-linear-gradient(180deg,#f3e7c6 0 2px,#d9c899 2px 3.2px); box-shadow: 0 7px 11px rgba(0,0,0,.3), inset 0 1px 0 rgba(255,255,255,.5); }
.pl-base { position: absolute; top: 2px; width: 95px; height: 97px; overflow: hidden; }
.pl-base-l { left: 6px; background: linear-gradient(135deg,#f9f2dd,#ece0bb); border-radius: 7px 2px 2px 8px; box-shadow: inset -9px 0 15px rgba(120,90,30,.22); }
.pl-base-r { right: 6px; background: linear-gradient(225deg,#f9f2dd,#ece0bb); border-radius: 2px 7px 8px 2px; box-shadow: inset 9px 0 15px rgba(120,90,30,.22); }
.pl-strip { animation: pl-strip 36s steps(4) infinite; }
.pl-base-l .pl-strip { animation-delay: -4.5s; }
.pl-base-r .pl-strip { animation-delay: -13.5s; }
.pl-spine { position: absolute; left: 50%; top: 1px; transform: translateX(-50%); width: 8px; height: 98px; background: linear-gradient(90deg,rgba(70,48,14,.6),rgba(150,110,40,.12),rgba(70,48,14,.6)); border-radius: 3px; z-index: 2; }
.pl-art { height: 97px; padding: 11px 10px 0; font-family: var(--font-serif); color: #3c2c0e; }
.pl-art-h { font-size: 8px; font-weight: 700; letter-spacing: .3px; }
.pl-art-b { font-size: 6.5px; line-height: 1.5; color: rgba(50,36,10,.85); margin-top: 2px; }
.pl-flip { position: absolute; left: 102px; top: 2px; width: 95px; height: 97px; transform-origin: left center; transform-style: preserve-3d; animation: pl-turn 36s linear infinite; }
.pl-flip .pl-face { position: absolute; inset: 0; backface-visibility: hidden; overflow: hidden; padding: 9px 9px 0; font-family: var(--font-serif); color: #3c2c0e; border: 1px solid rgba(120,90,30,.3); }
.pl-flip .pl-front { background: linear-gradient(115deg,#fbf4df,#ece0bb); border-radius: 2px 8px 8px 2px; box-shadow: -6px 0 13px rgba(0,0,0,.22); }
.pl-flip .pl-back { transform: rotateY(180deg); background: linear-gradient(245deg,#f7f0d8,#e8dcb6); border-radius: 8px 2px 2px 8px; box-shadow: 6px 0 13px rgba(0,0,0,.22); }
@keyframes pl-bob { 0%,100% { transform: translateY(0) rotate(-1.6deg); } 50% { transform: translateY(-4px) rotate(1.6deg); } }
@keyframes pl-turn { 0% { transform: rotateY(0deg) translateZ(2px); opacity: 0; } 0.8% { opacity: 1; } 4.6% { transform: rotateY(0deg) translateZ(2px); opacity: 1; } 5.2% { transform: rotateY(0deg) translateZ(15px); } 10.6% { transform: rotateY(-180deg) translateZ(15px); opacity: 1; } 11.2% { transform: rotateY(-180deg) translateZ(3px); } 15% { transform: rotateY(-180deg) translateZ(3px); opacity: 1; } 15.8% { opacity: 0; } 100% { transform: rotateY(-180deg) translateZ(3px); opacity: 0; } }
@keyframes pl-strip { 0% { transform: translateY(0); } 100% { transform: translateY(-388px); } }
@keyframes pl-spark { 0% { transform: translateY(8px) scale(.55) rotate(-8deg); opacity: 0; } 22% { opacity: 1; } 100% { transform: translateY(-30px) scale(1.05) rotate(8deg); opacity: 0; } }
@keyframes pl-scan { 0%, 66% { transform: translateY(-30%); opacity: 0; } 74% { opacity: .42; } 90% { opacity: .42; } 100% { transform: translateY(150%); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .pl-head, .pl-strip { animation: none !important; } .pl-flip, .pl-spark, .pl-scan { display: none; } }

/* ===================== PAGINA PROFILO (F3, compatta) ===================== */
.page-profilo { position: fixed; inset: 0; z-index: 100; background: var(--bg); overflow-y: auto; }
.pp-bar { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; background: var(--bg-2); border-bottom: 1px solid var(--line); }
.pp-title { font-family: var(--font-display); font-weight: 700; font-size: 17px; }
.pp-close { width: 34px; height: 34px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--panel); color: var(--text); font-size: 14px; }
.pp-body { max-width: 620px; margin: 0 auto; padding: 22px 18px 60px; }
.pp-sec { margin-bottom: 28px; }
.pp-sec h3 { font-family: var(--font-display); font-weight: 700; font-size: 16px; margin: 0 0 14px; }
.pp-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pp-field { margin-bottom: 12px; display: flex; flex-direction: column; gap: 5px; }
.pp-field label { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.pp-field input, .pp-field select { padding: 10px 12px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--bg-2); color: var(--text); font: inherit; font-size: 15px; }
.pp-ro { padding: 10px 12px; border-radius: var(--r-sm); background: var(--panel); border: 1px solid var(--line-soft); color: var(--muted); font-size: 15px; }
.pp-err { color: oklch(0.55 0.17 25); font-size: 13px; min-height: 16px; }
.pp-save { padding: 11px 20px; border-radius: var(--r-md); border: 0; background: linear-gradient(160deg, oklch(0.72 0.13 78), oklch(0.63 0.13 72)); color: #fff; font-weight: 700; font-size: 14px; margin-top: 6px; }
.pp-muted { color: var(--muted); font-size: 14px; line-height: 1.55; }
.prof-saldo-top { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 8px; }
.prof-saldo-sub { font-size: 12.5px; color: var(--muted); margin-top: 8px; }

/* Pannello admin "Modelli Claude" (solo PAGLIA_ADMIN_EMAILS) */
.pp-hint { font-size: 12px; color: var(--muted); line-height: 1.45; }
.mm-h4 { font-family: var(--font-display); font-weight: 700; font-size: 14px; margin: 20px 0 6px; }
.mm-card { border: 1px solid var(--line-soft); border-radius: var(--r-sm); padding: 12px 14px; margin: 10px 0; display: flex; flex-direction: column; gap: 7px; }
.mm-card-h { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; font-size: 14.5px; }
.mm-costo, .mm-costo-edit { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.mm-costo-edit input { width: 74px; padding: 5px 7px; margin: 0 4px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--bg-2); color: var(--text); font: inherit; font-size: 13px; }
.mm-dove { font-size: 13px; color: var(--muted); line-height: 1.5; margin: 0; }
.mm-card select { padding: 9px 11px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--bg-2); color: var(--text); font: inherit; font-size: 14.5px; }
.mm-prezzi { display: flex; flex-direction: column; gap: 8px; margin: 10px 0 14px; }
.mm-riga { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; }
.mm-nome { font-size: 13.5px; font-weight: 600; display: flex; flex-direction: column; }
.mm-nome small { font-weight: 400; color: var(--muted); font-size: 11.5px; }
.mm-riga label { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); font-weight: 600; }
.mm-riga input { width: 84px; padding: 7px 9px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--bg-2); color: var(--text); font: inherit; font-size: 14px; }
@media (max-width: 560px) {
  .mm-riga { grid-template-columns: 1fr; gap: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
