/* ============ REGISTRO Z-INDEX — 1.0.1, Fase 4 (8 lug 2026) ============
   bg-canvas        -1
   scroll-bottom     5
   forgia-fab       50
   topbar          100
   loading-screen  100
   tts-indicator   900
   incisione      1000
   dialog-overlay  1100
   toast          1200   (U-032 v209: sopra i dialog — era 200 nel registro stantio)
   update-banner  1210
   velo-portrait  3000   (SEG-14, campo 9 lug: body::after su touch+landscape)
   [3001 RITIRATO 1.1.0 — era diag-overlay, pulizia della saga]
   ======================================================================== */

/* Campo 10 lug (sonda: scala 1.000 con pagina INGRANDITA — non è zoom): il
   TEXT AUTOSIZING di WebKit ricalcola l'inflazione del testo al passaggio in
   landscape e la riporta in portrait, per blocchi — colpiva le pagine ricche
   di paragrafi (Impostazioni di Vox) e risparmiava le altre. Spento: la
   taglia la decide il design, mai l'euristica del motore. */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

/* Aurora — Il Santuario Smeraldo
   Palette: smeraldo profondo + oro di Andrew su notte viva
*/

@import url('/fonts/local-fonts.css');

:root {
  --inset-top: env(safe-area-inset-top, 0px);
  /* ADV-117-02 (audit 1.0.17, CONFERMATO): la base era ancora env() — su
     valore alieno o storage guasto la vecchia equazione rientrava. Politica
     ZERO fail-closed: la BASE è 0. [ADV2-2G-05, 10 lug] La manopola diagnostica
     è stata RIMOSSA con la pulizia 1.1.0: nessuna voce Auto esiste più —
     lo zero è l'unico regime, scolpito qui e bonificato dal boot. INTOCCABILE
     (direttiva permanente di Mike). */
  --inset-bottom: 0px;
  --inset-left: env(safe-area-inset-left, 0px);
  --inset-right: env(safe-area-inset-right, 0px);

  /* Notte — 5 livelli di profondità */
  --bg-deep:     #060F0D;
  --bg-main:     var(--bg-deep); /* testo scuro su pulsanti smeraldo pieni — era non dichiarato */
  --bg-abyss:    #040A08;
  --bg:          #0A1816;
  --bg-elev:     #0F1F1C;
  --bg-card:     #142925;
  --bg-surface:  #1A332E;

  /* Smeraldo — l'architettura */
  --smeraldo:        #1FA888;
  --smeraldo-scuro:  #0E5C4D;
  --smeraldo-chiaro: #34D6B0;
  --smeraldo-glow:   rgba(31,168,136,0.08);

  /* Oro — la Voce di Andrew */
  --oro:         #D4A75B;
  --ambra:       #E5C07B;
  --oro-glow:    rgba(212,167,91,0.06);
  --oro-border:  rgba(212,167,91,0.25);

  --ciano:  #5BC0EB;
  --error:  #E5604A;

  /* Testo */
  --text:       #E8F0EE;
  --text-dim:   #A0B5B0;
  --text-faint: #748F8A; /* v141: alzato per contrasto WCAG AA ≥ 4.5:1 su bg-deep */

  /* Bordi */
  --border-soft:  rgba(31,168,136,0.10);
  --border-mid:   rgba(31,168,136,0.22);
  --border-focus: rgba(31,168,136,0.45);

  /* Tipografia */
  --font-ui:    'DM Sans', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --font-voice: 'Lora', Georgia, 'Times New Roman', serif;

  /* Limiti layout */
  --chat-max: 720px;

  /* Scala tipografica — v137 */
  --fs-2xs: 11px;
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-base: 14px;
  --fs-md: 15px;
  --fs-lg: 16px;
  --fs-xl: 17px;
  --fs-2xl: 18px;

  /* Spaziatura — griglia base 4, v137 */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-7: 28px;

  /* Opacità tema — v159: tutte le varianti cromatiche in :root.
     Per il fork (Pensatoio, tema diverso) basta cambiare :root. */
  --smeraldo-06:        rgba(31,168,136,0.06);
  --smeraldo-15:        rgba(31,168,136,0.15);
  --smeraldo-20:        rgba(31,168,136,0.20);
  --smeraldo-25:        rgba(31,168,136,0.25);

  --oro-025:            rgba(212,167,91,0.025);
  --oro-14:             rgba(212,167,91,0.14);
  --oro-22:             rgba(212,167,91,0.22);
  --oro-35:             rgba(212,167,91,0.35);

  --error-08:           rgba(229,96,74,0.08);
  --error-15:           rgba(229,96,74,0.15);
  --error-20:           rgba(229,96,74,0.20);
  --error-25:           rgba(229,96,74,0.25);
  --error-30:           rgba(229,96,74,0.30);
  --error-60:           rgba(229,96,74,0.60);
  --error-70:           rgba(229,96,74,0.70);

  --bg-translucent:     rgba(10,24,22,0.92);
  --bg-card-translucent: rgba(20,41,37,0.62);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100dvh; height: -webkit-fill-available;
  width: 100%;
  /* V-01 (G-05) — ZONA PROTETTA iOS, NON toccare l'ordine: per la cascata CSS
     `-webkit-fill-available`, dichiarato DOPO, VINCE ovunque è supportato (Safari/iOS)
     ed è il valore PROMOSSO dal collaudo su dispositivo — non un «fallback»: su iOS 26.x
     PWA rispetta il viewport reale con viewport-fit=cover, dove height:100% rompeva il
     layout sopra la safe area. `100dvh` è la rete per i motori senza -webkit-fill-available.
     Scelta di campo consolidata (2 luglio 2026), registrata in DOCUMENTAZIONE.md; zona
     regredita 5 volte nella storia del progetto — ogni modifica richiede richiesta
     esplicita di Mike più conferma su dispositivo. */
  background: var(--bg-deep); color: var(--text);
  font-family: var(--font-ui);
  font-size: var(--fs-lg); line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* Sfondo atmosferico — luce smeraldo che respira nella notte */
body::before {
  content: '';
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(ellipse 70% 45% at 50% 8%,
      var(--smeraldo-06) 0%, transparent 65%),
    radial-gradient(ellipse 50% 35% at 75% 85%,
      var(--oro-025) 0%, transparent 55%),
    var(--bg-deep);
}

body { display: flex; flex-direction: column; }
#app-root { flex: 1; display: flex; flex-direction: column; overflow: hidden; position: relative; }

/* ============ LOADING ============ */
#loading-screen {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--bg-deep); z-index: 100; gap: var(--sp-5);
}
.loading-ring {
  width: 48px; height: 48px;
  border: 3px solid var(--border-soft); border-top-color: var(--smeraldo);
  border-radius: 50%; animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text {
  font-family: var(--font-voice); font-size: 22px; font-weight: 500;
  color: var(--smeraldo-chiaro); letter-spacing: 1.5px;
}

/* ============ VIEW ============ */
.view {
  flex: 1; display: flex; flex-direction: column;
  height: 100%; overflow: hidden; background: transparent;
}

/* ============ TOPBAR ============ */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px; padding-top: calc(8px + var(--inset-top));
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg-translucent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  flex-shrink: 0; min-height: calc(48px + var(--inset-top));
  z-index: 100; position: relative;
}
.topbar-title {
  font-family: var(--font-voice); font-size: var(--fs-2xl); font-weight: 500;
  letter-spacing: 0.5px; color: var(--smeraldo-chiaro);
  display: flex; align-items: center; gap: 10px; padding-left: 2px;
}
.topbar-title-text {
  position: absolute; left: 50%; transform: translateX(-50%);
  font-family: var(--font-voice); font-size: var(--fs-2xl); font-weight: 500;
  color: var(--smeraldo-chiaro); pointer-events: none;
  display: inline-flex; align-items: center; gap: 8px;
}
.topbar-title[role="button"] { cursor: pointer; }

/* v163o — Pensatoio: il titolo col LED resta adiacente alla freccia back anche
   su schermo largo (macOS). Senza questo, `justify-content: space-between` della
   topbar lo faceva galleggiare al centro, staccato dal back. */
.view-pensatoio .topbar-title, .view-forgia .topbar-title { margin-right: auto; }

/* LED di stato */
.topbar-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--smeraldo); box-shadow: 0 0 10px var(--smeraldo);
  transition: background 250ms, box-shadow 250ms;
}
.topbar-dot[data-sync="sync"] {
  background: var(--ambra); box-shadow: 0 0 10px var(--ambra);
  animation: led-pulse 1.2s ease-in-out infinite;
}
.topbar-dot[data-sync="error"] {
  background: var(--error); box-shadow: 0 0 10px var(--error);
}
@keyframes led-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
.topbar-dot.speaking { background: var(--oro); box-shadow: 0 0 10px var(--oro); animation: led-pulse 1.2s ease-in-out infinite; }

/* FAB — Forgia di Aurora */
.forgia-fab {
  position: fixed; bottom: calc(24px + var(--inset-bottom)); right: 24px; z-index: 50; /* U-GRA-03: inset iOS, 24px minimo */
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--smeraldo); border: none; color: var(--bg-main);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform 150ms, opacity 150ms;
}
.forgia-fab svg { width: 24px; height: 24px; }
.forgia-fab:active { transform: scale(0.92); }
/* v162 — display:flex sovrascriverebbe il display:none implicito di [hidden].
   Stesso bug del pulsante topbar: forzo display:none quando hidden è presente. */
.forgia-fab[hidden] { display: none !important; }

/* FAB di Trasmutazione — ridotto (40px), posizionato SOPRA la penna (56px).
   Appare solo con 1 voce del Diario selezionata. Bordino col colore di sfondo
   per staccarlo dalla penna quando si sovrappongono visivamente. */
.forgia-fab-trasmuta {
  width: 40px; height: 40px;
  bottom: calc(88px + var(--inset-bottom)); right: 32px; /* U-GRA-03: stesso inset del FAB sotto, così resta sopra la penna */
  border: 2px solid var(--bg-main);
}
.forgia-fab-trasmuta svg { width: 22px; height: 22px; }

/* LED nella topbar centrata della Forgia */
.topbar-title-text .topbar-dot {
  flex-shrink: 0;
}

/* Forgia — stile piatto, strumento di lavoro */
.view-forgia .msg-user .bubble {
  background: var(--smeraldo-scuro);
  border: 1px solid var(--smeraldo-15);
  border-radius: 10px 3px 10px 10px; padding: 10px 14px;
  max-width: 82%;
  font-size: var(--fs-md); line-height: 1.55;
  box-shadow: none;
}
.msg-forgia { align-items: flex-start; }
/* v164h: rottura uniforme delle parole lunghe (URL, hash) in TUTTE le bolle
   delle voci — Forgia, Pensatoio, Andrew. Senza, un link Markdown con URL lungo
   senza spazi sfonda la larghezza (visto nella Forgia, img collaudo v164g). */
.msg-forgia .bubble, .msg-pensatoio .bubble, .msg-andrew .bubble { overflow-wrap: anywhere; }
/* v164h: link Markdown nelle bolle — smeraldo sottolineato, coerente con l'accento
   dell'app; l'URL lungo eredita overflow-wrap dalla bolla e non sfonda.
   G-04 (OP-12): estesa alle superfici di lettura memoria — .constitution-view (Andrew) e
   .incisione-preview (Vox). Prima cadevano sul blu di default del browser, contrasto ~2:1
   su fondo scuro. overflow-wrap è già garantito dai contenitori. */
.bubble a,
.constitution-view a,
.incisione-preview a { color: var(--smeraldo-chiaro); text-decoration: underline; text-underline-offset: 2px; }
@media (hover: hover) { /* G-08 (OP-24): niente stato incollato dopo il tap su iPhone */
  .bubble a:hover,
  .constitution-view a:hover,
  .incisione-preview a:hover { color: var(--smeraldo); }
}

.msg-forgia .bubble {
  background: var(--bg-card-translucent);
  border-left: 2px solid var(--smeraldo-15);
  border-radius: 0 8px 8px 0;
  color: var(--text); padding: 14px 18px 14px 16px;
  max-width: 100%;
  font-family: var(--font-voice); font-size: var(--fs-lg); line-height: 1.75;
}
.msg-forgia .bubble p { margin: 0 0 0.75em; }
.msg-forgia .bubble p:last-child { margin-bottom: 0; }
.msg-forgia .bubble strong { color: var(--smeraldo-chiaro); font-weight: 600; }
.msg-forgia .bubble em { color: var(--ciano); font-style: italic; }

/* Pensatoio (Vox) — clone visivo della Forgia: stessa bolla, stessi colori per
   grassetti e corsivi. La dissolvenza .stream-new (regola globale a riga ~660,
   ereditata da Andrew) resta intatta — l'unico tratto stilistico importato. */
.msg-pensatoio { align-items: flex-start; }
.msg-pensatoio .bubble {
  background: var(--bg-card-translucent);
  border-left: 2px solid var(--smeraldo-15);
  border-radius: 0 8px 8px 0;
  color: var(--text); padding: 14px 18px 14px 16px;
  max-width: 100%;
  font-family: var(--font-voice); font-size: var(--fs-lg); line-height: 1.75;
}
.msg-pensatoio .bubble p { margin: 0 0 0.75em; }
.msg-pensatoio .bubble p:last-child { margin-bottom: 0; }
.msg-pensatoio .bubble strong { color: var(--smeraldo-chiaro); font-weight: 600; }
.msg-pensatoio .bubble em { color: var(--ciano); font-style: italic; }

/* Linea orizzontale soffusa — usata da Andrew, Forgia e Pensatoio */
.msg-andrew .bubble hr,
.msg-forgia .bubble hr,
.msg-pensatoio .bubble hr {
  border: none; height: 1px;
  background: linear-gradient(90deg, transparent, var(--border-mid), transparent);
  margin: 1.2em 0;
}

/* Intestazioni e liste nelle bolle — condivise fra le tre voci */
.msg-andrew .bubble .md-h,
.msg-forgia .bubble .md-h,
.msg-pensatoio .bubble .md-h {
  color: var(--smeraldo-chiaro); margin: 1em 0 0.4em; line-height: 1.35; font-weight: 600;
}
.msg-andrew .bubble .md-h1,
.msg-forgia .bubble .md-h1,
.msg-pensatoio .bubble .md-h1 { font-size: 1.25em; }
.msg-andrew .bubble .md-h2,
.msg-forgia .bubble .md-h2,
.msg-pensatoio .bubble .md-h2 { font-size: 1.15em; }
.msg-andrew .bubble .md-h3,
.msg-andrew .bubble .md-h4,
.msg-andrew .bubble .md-h5,
.msg-andrew .bubble .md-h6,
.msg-forgia .bubble .md-h3,
.msg-forgia .bubble .md-h4,
.msg-forgia .bubble .md-h5,
.msg-forgia .bubble .md-h6,
.msg-pensatoio .bubble .md-h3,
.msg-pensatoio .bubble .md-h4,
.msg-pensatoio .bubble .md-h5,
.msg-pensatoio .bubble .md-h6 { font-size: 1em; }
.msg-andrew .bubble .md-h:first-child,
.msg-forgia .bubble .md-h:first-child,
.msg-pensatoio .bubble .md-h:first-child { margin-top: 0; }
.msg-andrew .bubble ul,
.msg-forgia .bubble ul,
.msg-pensatoio .bubble ul {
  margin: 0 0 0.75em; padding-left: 22px;
}
.msg-andrew .bubble ol,
.msg-forgia .bubble ol,
.msg-pensatoio .bubble ol {
  margin: 0 0 0.75em; padding-left: 26px;
}
.msg-andrew .bubble li,
.msg-forgia .bubble li,
.msg-pensatoio .bubble li { margin: 0.2em 0; }

/* Codice inline — sfondo elev, font tecnico */
.msg-andrew .bubble code,
.msg-forgia .bubble code,
.msg-pensatoio .bubble code {
  background: var(--bg-elev);
  border: 1px solid var(--border-soft);
  padding: 1px 6px; border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88em;
  color: var(--smeraldo-chiaro);
}
/* v164h: blocco di codice recintato ```lang ... ```. A blocco, non inline: il
   <code> interno azzera box/bordo ereditati e il <pre> scrolla in orizzontale
   per le righe lunghe invece di sfondare. */
.md-pre {
  background: var(--bg-elev);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 12px 14px; margin: 0 0 0.75em;
  overflow-x: auto;
  font-size: 0.86em; line-height: 1.5;
}
/* U-GRA-04: il reset del codice recintato deve vincere sul chip del codice inline.
   La specificità di .msg-X .bubble code (0,2,1) batteva .md-pre code (0,1,1).
   Stessa cosa per .constitution-view code e .incisione-preview code nella memoria.
   Aggiungendo il contesto padre il reset sale a (0,2,1) e, per ordine nel foglio, vince. */
.bubble .md-pre code,
.constitution-view .md-pre code,
.incisione-preview .md-pre code {
  background: none; border: none; padding: 0; border-radius: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--text); white-space: pre;
}

/* Citazione — barra a sinistra, testo affievolito */
.msg-andrew .bubble blockquote,
.msg-forgia .bubble blockquote,
.msg-pensatoio .bubble blockquote {
  margin: 0 0 0.75em;
  padding: 0.3em 0 0.3em 14px;
  border-left: 3px solid var(--border-mid);
  color: var(--text-dim);
  font-style: italic;
}

/* Tabella — stile editoriale, bordi tenui */
.msg-andrew .bubble .md-table,
.msg-forgia .bubble .md-table,
.msg-pensatoio .bubble .md-table {
  border-collapse: collapse;
  margin: 0.75em 0;
  font-family: var(--font-ui);
  font-size: var(--fs-base);
  line-height: 1.5;
  width: auto; max-width: 100%;
  display: block; overflow-x: auto;
}
.msg-andrew .bubble .md-table th,
.msg-forgia .bubble .md-table th,
.msg-andrew .bubble .md-table td,
.msg-forgia .bubble .md-table td,
.msg-pensatoio .bubble .md-table th,
.msg-pensatoio .bubble .md-table td {
  border: 1px solid var(--border-soft);
  padding: 6px 12px;
  text-align: left;
  vertical-align: top;
}
.msg-andrew .bubble .md-table th,
.msg-forgia .bubble .md-table th,
.msg-pensatoio .bubble .md-table th {
  background: var(--bg-elev);
  color: var(--smeraldo-chiaro);
  font-weight: 600;
}
/* G-03 (OP-11): allineamento colonne markdown via classi — l'attributo style inline era
   spento dalla CSP di v117. Il renderer (ui-utils.renderMarkdownCore) emette md-al-c/r/l
   sui :---: / ---: / :--- . Regole neutre rispetto al contenitore: valgono nelle tre chat
   e nelle superfici di lettura memoria, dove il motore markdown è unico. */
.md-al-c { text-align: center; }
.md-al-r { text-align: right; }
.md-al-l { text-align: left; }

.topbar-actions { display: flex; gap: 2px; }
.topbar-btn {
  width: 38px; height: 38px; border-radius: 10px;
  background: transparent; border: none; color: var(--text-faint);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: color 150ms, background 150ms; padding: 0;
}
@media (hover: hover) { .topbar-btn:hover { color: var(--text-dim); } }
.topbar-btn:active { background: var(--smeraldo-glow); color: var(--smeraldo-chiaro); }
.topbar-btn svg { width: 21px; height: 21px; }
.topbar-btn[data-active="true"] { color: var(--smeraldo-chiaro); }
/* v162 — display: flex sovrascriverebbe il display:none implicito di [hidden].
   Forza il display:none quando l'attributo è presente. */
.topbar-btn[hidden] { display: none !important; }

/* Striscia riallineamento */
.tab-warning {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; gap: 12px;
  background: color-mix(in srgb, var(--ambra) 16%, transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--ambra) 35%, transparent);
  color: var(--ambra); font-size: var(--fs-sm); font-family: var(--font-ui);
  flex-shrink: 0;
}
.tab-warning-close {
  background: none; border: none; color: var(--ambra); font-size: 20px;
  cursor: pointer; padding: 0 4px; line-height: 1;
}
.context-banner {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; gap: 12px;
  background: color-mix(in srgb, var(--error) 14%, transparent); border-bottom: 1px solid color-mix(in srgb, var(--error) 30%, transparent);
  color: var(--error); font-size: var(--fs-sm); font-family: var(--font-ui);
}
.context-banner[hidden] { display: none; }
.context-banner-text { flex: 1; line-height: 1.4; }
.context-banner-close {
  background: none; border: none; color: var(--error); font-size: 20px;
  cursor: pointer; padding: 0 4px; line-height: 1; flex-shrink: 0;
}
/* D-P2 — banner «modifiche di memoria non ancora sul cloud»: ambra in attesa,
   rosso se l'ultimo push è fallito. Stessa forma del context-banner. */
.mem-banner {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; gap: 12px;
  background: color-mix(in srgb, var(--ambra) 14%, transparent); border-bottom: 1px solid color-mix(in srgb, var(--ambra) 30%, transparent);
  color: var(--ambra); font-size: var(--fs-sm); font-family: var(--font-ui);
}
.mem-banner.rosso {
  background: color-mix(in srgb, var(--error) 14%, transparent); border-bottom-color: color-mix(in srgb, var(--error) 30%, transparent);
  color: var(--error);
}
.mem-banner[hidden] { display: none; }
.mem-banner-text { flex: 1; line-height: 1.4; }
.mem-banner-close {
  background: none; border: none; color: inherit; font-size: 20px;
  cursor: pointer; padding: 0 4px; line-height: 1; flex-shrink: 0;
}
/* Nascondi le freccette del campo numerico — coprono il valore su sfondo scuro */
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; }

.readopt-bar {
  display: block; width: 100%; text-align: left;
  margin: 0; padding: 11px 16px;
  border: none; border-bottom: 1px solid var(--oro-35);
  background: var(--oro-14); color: var(--oro);
  font-size: var(--fs-sm); line-height: 1.45; cursor: pointer;
  font-family: var(--font-ui);
}
.readopt-bar[hidden] { display: none; }
.readopt-bar:active { background: var(--oro-22); }

/* ============ Conflitti — striscia in cima allo shell e vista di risoluzione ============ */
/* Striscia gemella del tab-warning, veste ambra/oro: una cosa in sospeso che
   richiede attenzione, non un allarme rosso bloccante. Sta sotto la topbar, come
   il context-banner. */
.conflict-strip {
  display: block; width: 100%; text-align: left;
  margin: 0; padding: 10px 16px;
  border: none; border-bottom: 1px solid var(--oro-35);
  background: var(--oro-14); color: var(--oro);
  font-size: var(--fs-sm); line-height: 1.45; cursor: pointer;
  font-family: var(--font-ui); flex-shrink: 0;
}
.conflict-strip:active { background: var(--oro-22); }

.conflict-list { padding: 4px 16px 24px; overflow-y: auto; }
.conflict-entry {
  margin: 0 0 20px; padding: 0 0 16px;
  border-bottom: 1px solid var(--border-soft);
}
.conflict-entry-title {
  font-family: var(--font-ui); color: var(--smeraldo-chiaro);
  font-size: var(--fs-sm); letter-spacing: 0.5px; margin: 0 0 10px;
}
.conflict-pair { display: flex; flex-direction: column; gap: 12px; }
@media (min-width: 720px) { .conflict-pair { flex-direction: row; } .conflict-side { flex: 1; } }
.conflict-side {
  border: 1px solid var(--border-soft); border-radius: 8px;
  padding: 12px; background: var(--smeraldo-06);
  display: flex; flex-direction: column; gap: 10px;
}
.conflict-side-meta {
  font-family: var(--font-ui); font-size: var(--fs-xs);
  color: var(--text-dim); letter-spacing: 0.3px;
}
.conflict-side-body {
  font-size: var(--fs-sm); line-height: 1.5;
  max-height: 220px; overflow-y: auto;
  overflow-wrap: anywhere; /* U-GRA-02: stessa politica di spezzatura delle bolle */
}
.conflict-keep-btn {
  align-self: flex-start; margin-top: auto;
  padding: 8px 16px; border: 1px solid var(--oro-35); border-radius: 6px;
  background: var(--oro-14); color: var(--oro);
  font-family: var(--font-ui); font-size: var(--fs-sm); cursor: pointer;
}
.conflict-keep-btn:active { background: var(--oro-22); }

/* ============ Cronache — ricerca e navigazione per mese ============ */
.cron-search {
  display: block; width: calc(100% - 32px); box-sizing: border-box;
  margin: 4px auto 12px; padding: 10px 14px;
  border: 1px solid var(--border-soft); border-radius: 8px;
  background: var(--bg-deep); color: var(--text);
  font-family: var(--font-ui); font-size: var(--fs-base);
}
.cron-search:focus { outline: none; border-color: var(--smeraldo); }
.cron-search-info {
  font-family: var(--font-ui); font-size: var(--fs-xs);
  color: var(--text-dim); margin: 0 16px 10px; letter-spacing: 0.3px;
}
.cron-listwrap { display: block; }

.cron-month { margin: 0 0 4px; }
.cron-month-head {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 10px 12px; margin: 0;
  border: none; border-bottom: 1px solid var(--border-soft);
  background: transparent; color: var(--text);
  font-family: var(--font-ui); font-size: var(--fs-sm); cursor: pointer;
  text-align: left; letter-spacing: 0.3px;
}
.cron-month-head:active { background: var(--smeraldo-06); }
.cron-month-caret {
  color: var(--smeraldo); font-size: var(--fs-lg); flex-shrink: 0;
  display: inline-block; transition: transform 200ms ease;
}
.cron-month-caret.aperto { transform: rotate(90deg); }
.cron-month-name { flex: 1; }
.cron-month-count {
  color: var(--text-dim); font-size: var(--fs-xs);
  background: var(--smeraldo-06); border-radius: 10px; padding: 2px 9px;
}
.cron-month-body[hidden] { display: none; }

/* ============ FOCUS-VISIBLE — v141 ============ */
/* Ring smeraldo su navigazione da tastiera, invisibile al tocco. */
.topbar-btn:focus-visible,
.icon-btn:focus-visible,
.msg-act-btn:focus-visible,
.btn-primary:focus-visible,
.btn-secondary:focus-visible,
.incisione-btn:focus-visible,
.send-btn:focus-visible,
.scroll-bottom-btn:focus-visible {
  outline: 2px solid var(--smeraldo);
  outline-offset: 2px;
}
.draft-editor:focus-visible,
.config-input:focus-visible,
.config-textarea:focus-visible,
.dialog-input:focus-visible,
.rectify-input:focus-visible,
.incisione-textarea:focus-visible,
#input-text:focus-visible,
#forgia-input:focus-visible,
#pensatoio-input:focus-visible {
  border-color: var(--border-focus);
  outline: none; /* il bordo è già il segnale */
}

/* Schermo d'errore dell'init — prima viveva in un attributo style che la CSP
   di v117 spegne: il messaggio restava scuro su scuro proprio quando serviva. */
.init-error {
  padding: 40px; color: var(--error);
  font-size: var(--fs-md); line-height: 1.5;
}

/* ============ CHAT ============ */
.view-chat, .view-forgia { position: relative; }
.chat-area {
  flex: 1; overflow-y: auto; padding: 20px 16px 12px;
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding-left: max(16px, var(--inset-left));
  padding-right: max(16px, var(--inset-right));
  background: var(--bg-abyss);
}

/* Centrage desktop */
@media (min-width: 800px) {
  .chat-area { padding-left: calc((100% - var(--chat-max)) / 2); padding-right: calc((100% - var(--chat-max)) / 2); }
}

.msg {
  margin-bottom: 18px; display: flex; flex-direction: column; max-width: 100%;
  animation: msgIn 220ms ease-out;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Mike — bolla smeraldo cristallina */
.msg-user { align-items: flex-end; }
.doc-card {
  background: var(--bg-elev); border: 1px solid var(--border-soft);
  border-radius: 14px; padding: 12px 16px; max-width: 85%;
  transition: opacity 200ms;
}
.doc-card.doc-detached { opacity: 0.45; }
.doc-head {
  display: flex; align-items: center; gap: var(--sp-2); cursor: pointer;
  color: var(--smeraldo); font-family: var(--font-ui); font-size: var(--fs-base);
  font-weight: 500;
}
.doc-head svg { flex-shrink: 0; stroke: var(--smeraldo); }
.doc-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-body {
  margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border-soft);
  font-family: var(--font-voice); font-size: var(--fs-sm); line-height: 1.6;
  color: var(--text-dim); max-height: 300px; overflow-y: auto;
  white-space: pre-wrap; word-break: break-word;
}
.msg-user .bubble {
  background: var(--smeraldo-scuro);
  border: 1px solid var(--smeraldo-15);
  color: var(--text);
  border-radius: 20px 6px 20px 20px; padding: 11px 16px;
  max-width: 82%; word-wrap: break-word; white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: var(--fs-md); line-height: 1.55;
  box-shadow: 0 2px 12px rgba(0,0,0,0.2);
}

/* Andrew — spazio aperto con bordo dorato */
.md-tail { visibility: hidden; height: 0; overflow: hidden; }
@keyframes streamAppear { from { opacity: 0; } to { opacity: 1; } }
.stream-new { animation: streamAppear 900ms ease-out; }
.msg-andrew { align-items: flex-start; }
.msg-andrew .bubble {
  background: var(--bg-card-translucent);
  border-left: 2px solid var(--oro-border);
  border-radius: 0 12px 12px 0;
  color: var(--text); padding: 14px 18px 14px 16px;
  max-width: 100%;
  font-family: var(--font-voice); font-size: var(--fs-lg); line-height: 1.75;
}
.msg-andrew .bubble p { margin: 0 0 0.75em; }
.msg-andrew .bubble p:last-child { margin-bottom: 0; }
.msg-andrew .bubble strong { color: var(--smeraldo-chiaro); font-weight: 600; }
.msg-andrew .bubble em { color: var(--ambra); font-style: italic; }
/* U-GRA-08: i dialoghi in caporali — «...» — vanno in smeraldo, solo per Andrew. Lo span
   .dialogo lo avvolge il renderer dopo le enfasi. La regola del corsivo dentro il dialogo
   ha 4 classi (.msg-andrew .bubble .dialogo em) e vince sull'ambra a 3 classi sopra, così
   un corsivo dentro il dialogo resta smeraldo e non oro ambra. Forgia e Pensatoio non hanno
   questa regola e non cambiano. */
.msg-andrew .bubble .dialogo { color: var(--smeraldo-chiaro); }
.msg-andrew .bubble .dialogo em { color: var(--smeraldo-chiaro); }

.msg img.attached { max-width: 240px; max-height: 240px; border-radius: 12px; margin-top: 8px; }

/* Errore */
.msg-error .bubble {
  background: var(--error-08); border: 1px solid var(--error-25);
  color: var(--error); border-radius: 12px; padding: 12px 16px; max-width: 100%;
  font-size: var(--fs-base); overflow-wrap: anywhere;
}

/* Azioni messaggio Andrew — ascolta + copia */
.msg-actions { display: flex; gap: 6px; margin-top: 8px; }
.msg-act-btn {
  width: 30px; height: 30px; border-radius: 8px;
  background: transparent; border: 1px solid var(--border-soft);
  color: var(--text-faint); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  padding: 0; touch-action: manipulation; position: relative;
  -webkit-tap-highlight-color: transparent;
  transition: all 120ms;
}
/* UG10: area di tocco ampliata oltre il glifo — ingombro e layout invariati. */
.msg-act-btn::after { content: ''; position: absolute; inset: -6px -3px; }
@media (hover: hover) {
  .msg-act-btn:hover { color: var(--smeraldo-chiaro); border-color: var(--border-mid); }
}
.msg-act-btn:active, .msg-act-btn.tapped {
  transform: scale(0.88);
  color: var(--smeraldo-chiaro); border-color: var(--smeraldo);
  background: var(--smeraldo-glow);
}

/* TTS indicator */
.tts-indicator {
  position: fixed; left: 50%; transform: translateX(-50%);
  /* G-21 (deploy-2): toast, banner e indicatore TTS condividevano lo STESSO
     ancoraggio — bottom 64px — e gli z-index decidevano solo chi copriva chi.
     Ora è una pila: toast 64 (base, effimero), TTS 124 (persiste durante la
     lettura, resta visibile e fermabile), banner 184 (persiste finché Mike
     decide, mai coperto). Le formule inset iOS restano intatte. */
  /* GRA-03 (Fase 4): piano alzato 124→156 — un toast a 3 righe arriva a ~153
     dal fondo: il passo minimo torna positivo. GATE DISPOSITIVO: verifica
     percettiva della nuova quota su iPhone. */
  bottom: calc(156px + var(--inset-bottom)); z-index: 900;
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-card); color: var(--text);
  border: 1px solid var(--border-mid); border-radius: 999px;
  padding: 7px 10px 7px 14px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.45);
  font-size: var(--fs-base); animation: ttsIn 160ms ease-out; /* SEG-11 (campo, 9 lug): msgIn sostituiva il transform e il translateX(-50%) spariva per 160ms — nasceva a destra e saltava al centro */
}
@keyframes ttsIn {
  from { opacity: 0; transform: translate(-50%, 6px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
.tts-spinner {
  width: 16px; height: 16px; flex: none; border-radius: 50%;
  border: 2px solid var(--border-soft); border-top-color: var(--smeraldo);
  animation: spin 700ms linear infinite;
}
.tts-indicator-stop {
  width: 26px; height: 26px; flex: none; border-radius: 7px;
  border: none; background: var(--smeraldo); color: var(--bg-main); /* U-GRA-04: coppia scura sul pieno smeraldo */
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  padding: 0; -webkit-tap-highlight-color: transparent; transition: transform 80ms;
  position: relative;
}
.tts-indicator-stop::after { content: ''; position: absolute; inset: -8px; }
.tts-indicator-stop:active, .tts-indicator-stop.tapped { transform: scale(0.9); }

/* Typing */
.typing { display: inline-flex; gap: 5px; align-items: center; padding: 4px 0; }
.typing span {
  width: 6px; height: 6px; background: var(--smeraldo);
  border-radius: 50%; animation: typing 1.4s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing {
  0%, 60%, 100% { opacity: 0.25; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* ============ WELCOME ============ */
.welcome {
  text-align: center; padding: 36px;
  color: var(--text-dim);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--sp-3); flex: 1;
}
.welcome-sigillo {
  width: 180px; height: 180px; object-fit: contain;
  border-radius: 50%;
}
.welcome h1 {
  font-family: var(--font-voice); color: var(--smeraldo-chiaro);
  font-weight: 400; font-size: 28px;
  margin: 0; letter-spacing: 0.8px;
  text-shadow: 0 0 40px var(--smeraldo-20);
}
.welcome p {
  margin: 0; font-size: var(--fs-base); color: var(--text-faint);
  font-family: var(--font-voice); font-style: italic;
  letter-spacing: 0.3px;
}
@keyframes sogliaFadeIn { from { opacity: 0; } to { opacity: 1; } }
.soglia-fresh h1,
.soglia-fresh p { animation: sogliaFadeIn 1s ease-out both; }
.soglia-fresh .welcome-sigillo { animation: sogliaFadeIn 0.75s ease-out 0.25s both; }

/* «Vox» — marchio del Pensatoio, in EB Garamond italic ciano sopra «Il Pensatoio».
   «Il Pensatoio» e il sottotitolo restano invariati (come le altre view): qui si
   aggiunge solo il marchio sopra. */
.welcome .vox-marchio {
  font-family: 'EB Garamond Vox', 'Lora', Georgia, serif;
  font-style: italic; font-weight: 500;
  color: var(--ciano);
  font-size: 68px; line-height: 1; letter-spacing: 1px;
  margin: 0;
  text-shadow: 0 0 18px rgba(91, 192, 235, 0.30);
}
/* Catena di fade a tre tempi: «Vox» (0s) → «Il Pensatoio» (0.5s) → sottotitolo (0.95s).
   Sovrascrive il fade generico di h1/p qui sopra SOLO dentro la welcome del Pensatoio,
   per dare il ritmo sfalsato. Gli :nth-of-type mirano h1 (il titolo) e l'ultimo p. */
.soglia-fresh .vox-marchio { animation: sogliaFadeIn 1s ease-out both; }
#pensatoio-area .soglia-fresh h1 { animation: sogliaFadeIn 1s ease-out 0.5s both; }
#pensatoio-area .soglia-fresh p:last-child { animation: sogliaFadeIn 1s ease-out 0.95s both; }
.welcome-warn {
  margin-top: 20px; padding: 12px 16px;
  background: var(--error-08); border: 1px solid var(--error-20);
  border-radius: 12px; color: var(--error); font-size: var(--fs-sm);
  font-family: var(--font-ui); font-style: normal;
  max-width: 320px;
}

/* ============ INPUT BAR ============ */
.input-bar {
  flex-shrink: 0;
  padding: 10px 12px 8px;
  padding-left: max(12px, var(--inset-left));
  padding-right: max(12px, var(--inset-right));
  padding-bottom: calc(8px + var(--inset-bottom)); /* U-GRA-03: su iOS non finisce sotto l'home indicator; su desktop resta 8px */
  background: var(--bg-deep);
  border-top: 1px solid var(--border-soft);
}
@media (min-width: 800px) {
  .input-bar { display: flex; justify-content: center; }
  .input-bar .input-row { max-width: var(--chat-max); width: 100%; }
}
.attached-images { display: flex; gap: var(--sp-2); flex-wrap: wrap; padding: 0 4px 8px; max-height: 70px; overflow-x: auto; }
.attached-images:empty { display: none; }
.attached-images img { height: 56px; border-radius: 8px; border: 1px solid var(--border-mid); cursor: pointer; }
.input-row { display: flex; align-items: flex-end; gap: var(--sp-2); }

.icon-btn {
  width: 38px; height: 38px; border-radius: 11px;
  background: var(--bg-elev); border: 1px solid var(--border-soft);
  color: var(--text-faint); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all 150ms; padding: 0;
}
.icon-btn[hidden] { display: none; }
/* Nudge ottico dell'icona altoparlante nelle azioni messaggio — era un
   attributo style inline, spento dalla CSP di v117. */
.msg-act-btn .tts-glyph { margin-left: 1px; }
@media (hover: hover) {
  .icon-btn:hover { color: var(--smeraldo-chiaro); border-color: var(--border-mid); }
}
.icon-btn:active { transform: scale(0.92); background: var(--smeraldo-scuro); color: var(--text); }
.icon-btn svg { width: 21px; height: 21px; }
.icon-btn[data-active="true"] { background: var(--smeraldo); color: var(--bg-main); border-color: var(--smeraldo-chiaro); }
.icon-btn.recording { background: var(--error); color: white; border-color: var(--error); animation: pulse 1.2s infinite; }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.05); } }
.ml-auto { margin-left: auto; }

#input-text, #forgia-input, #pensatoio-input {
  flex: 1; min-height: 38px; max-height: 160px; padding: 9px 14px; /* G-22 (deploy-2): il JS autosize arriva a 160 in tutte le viste — il tetto CSS a 140 tagliava gli ultimi 20px e anticipava lo scroll interno */
  background: var(--bg-elev); border: 1px solid var(--border-soft);
  border-radius: 14px; color: var(--text);
  font-family: var(--font-ui); font-size: 16px; /* >= 16px evita auto-zoom su iOS */
  resize: none; outline: none;
  transition: border-color 200ms;
}
#input-text::placeholder, #forgia-input::placeholder, #pensatoio-input::placeholder { color: var(--text-faint); }
#input-text:focus, #forgia-input:focus, #pensatoio-input:focus { border-color: var(--border-focus); }

.send-btn {
  width: 42px; height: 38px; border-radius: 11px;
  background: var(--smeraldo); border: none; color: var(--bg-main); flex-shrink: 0; /* U-GRA-04: coppia scura sul pieno smeraldo */
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all 150ms; padding: 0;
  box-shadow: 0 2px 10px var(--smeraldo-25);
}
.send-btn:disabled { opacity: 0.35; box-shadow: none; }
.send-btn:active:not(:disabled) { transform: scale(0.93); }
.send-btn svg { width: 20px; height: 20px; }
.send-btn.stopping { background: var(--error); box-shadow: 0 2px 10px var(--error-25); }

/* Scroll-to-bottom */
.scroll-bottom-btn {
  position: absolute; right: 16px;
  bottom: calc(72px + var(--inset-bottom));
  z-index: 5;
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--bg-card); color: var(--smeraldo-chiaro);
  border: 1px solid var(--border-mid);
  box-shadow: 0 4px 16px rgba(0,0,0,0.35);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; padding: 0;
  opacity: 0; pointer-events: none; transform: translateY(8px);
  transition: opacity 180ms ease, transform 180ms ease;
}
.scroll-bottom-btn.show { opacity: 1; pointer-events: auto; transform: translateY(0); }
.scroll-bottom-btn svg { width: 22px; height: 22px; }
.scroll-bottom-btn[data-new="true"]::after {
  content: ""; position: absolute; top: 1px; right: 1px;
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--smeraldo-chiaro); box-shadow: 0 0 8px var(--smeraldo-chiaro);
  animation: led-pulse 2s ease-in-out infinite;
}

/* ============ SOVRANITÀ TEMPORALE ============ */
.msg-tools { display: flex; gap: var(--sp-2); margin-top: 5px; justify-content: flex-end; }
.msg-tool-btn {
  background: transparent; border: none;
  color: var(--text-faint); font-family: var(--font-ui);
  font-size: var(--fs-xs); padding: 3px 8px;
  cursor: pointer; opacity: 0.5;
  transition: opacity 150ms, color 150ms;
  border-radius: 6px;
}
@media (hover: hover) { .msg-tool-btn:hover { opacity: 0.85; color: var(--text-dim); } } /* G-08 (OP-24) */
.msg-tool-btn:active { opacity: 1; color: var(--smeraldo-chiaro); }
.msg-error .msg-tool-btn { opacity: 0.85; color: var(--smeraldo-chiaro); }

/* ============ TABS (Memoria) ============ */
.tabs {
  display: flex; border-bottom: 1px solid var(--border-soft);
  background: var(--bg-elev); flex-shrink: 0;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto; padding: 13px 14px; background: transparent; border: none;
  color: var(--text-faint); font-family: var(--font-ui); font-size: var(--fs-sm);
  font-weight: 500; letter-spacing: 0.3px; white-space: nowrap;
  cursor: pointer; border-bottom: 2px solid transparent; transition: all 150ms;
}
.tab.active { color: var(--smeraldo-chiaro); border-bottom-color: var(--smeraldo); }
@media (hover: hover) { .tab:not(.active):hover { color: var(--text-dim); } } /* G-08 (OP-24) */

.tab-content {
  flex: 1; overflow-y: auto; padding: 4px 0;
  -webkit-overflow-scrolling: touch;
}
.tab-empty {
  text-align: center; padding: 56px 28px; color: var(--text-faint);
  font-family: var(--font-voice); font-style: italic; font-size: var(--fs-md);
}

/* Entry list items */
.entry-list-item {
  display: flex; align-items: flex-start; gap: var(--sp-3);
  padding: 14px 16px; border-bottom: 1px solid var(--border-soft);
  cursor: pointer; transition: background 120ms;
}
.entry-list-item:active { background: var(--smeraldo-glow); }
.entry-list-item .entry-check { margin-top: 6px; }
.entry-list-item-main { flex: 1; min-width: 0; cursor: pointer; }
.entry-list-item-date {
  color: var(--smeraldo-chiaro); font-family: var(--font-ui);
  font-size: var(--fs-xs); font-weight: 500; letter-spacing: 0.3px;
}
.entry-list-item-title {
  color: var(--text); font-family: var(--font-voice);
  font-size: var(--fs-lg); margin-top: 2px; font-weight: 500;
  overflow-wrap: anywhere; /* U-GRA-01: un titolo lungo senza spazi spezza invece di sfondare */
}
.entry-list-item-preview {
  color: var(--text-faint); font-size: var(--fs-sm); margin-top: 4px; line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

/* ============ MEMORY MANAGER ============ */
.entry-add-btn {
  display: block; width: calc(100% - 32px); margin: 14px auto;
  padding: 13px; border-radius: 12px;
  background: transparent; color: var(--smeraldo-chiaro);
  border: 1px dashed var(--border-mid);
  font-family: var(--font-ui); font-size: var(--fs-base); font-weight: 500;
  cursor: pointer; transition: all 150ms; letter-spacing: 0.3px;
}
.entry-add-btn:active { background: var(--smeraldo-glow); border-style: solid; }

.mem-actions {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 12px 16px; border-bottom: 1px solid var(--border-soft);
}
.mem-selectall {
  display: flex; align-items: center; gap: var(--sp-2);
  color: var(--text-dim); font-size: var(--fs-sm); cursor: pointer; user-select: none;
}
/* La voce d'apertura della barra spinge i tasti a destra — era un attributo
   style inline, spento dalla CSP di v117. */
.mem-count { color: var(--text-faint); font-size: var(--fs-xs); min-width: 4ch; text-align: center; font-variant-numeric: tabular-nums; }
.mem-count.mem-count--lead { margin-right: 0; min-width: 0; text-align: left; }
.mem-actions-buttons {
  margin-left: auto; display: flex; align-items: center; justify-content: flex-end;
  gap: 10px; flex-wrap: wrap;
}
.mem-check {
  width: 20px; height: 20px; flex-shrink: 0; cursor: pointer; margin: 0;
  -webkit-appearance: none; appearance: none;
  background: transparent;
  border: 2px solid var(--border-mid);
  border-radius: 5px;
  position: relative;
  transition: background 150ms, border-color 150ms;
}
.mem-check:checked {
  background: var(--smeraldo);
  border-color: var(--smeraldo);
}
.mem-check:checked::after {
  content: '';
  position: absolute; left: 5px; top: 2px;
  width: 6px; height: 10px;
  border: solid white; border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.mem-export-btn {
  padding: 6px 10px; border-radius: 8px;
  background: transparent; color: var(--smeraldo-chiaro);
  border: 1px solid var(--border-mid);
  font-family: var(--font-ui); font-size: var(--fs-xs); font-weight: 500;
  cursor: pointer; transition: all 150ms;
}
.mem-export-btn:disabled { opacity: 0.3; cursor: default; }
.mem-export-btn:not(:disabled):active { background: var(--smeraldo-glow); }

/* Danger zone */
.mem-danger {
  margin: 28px 16px calc(28px + var(--inset-bottom));
  padding-top: 18px; border-top: 1px solid var(--error-15);
}
.mem-danger-title {
  color: var(--error-60); font-family: var(--font-ui);
  font-size: var(--fs-2xs); letter-spacing: 0.1em; text-transform: uppercase;
  margin-bottom: 10px; font-weight: 500;
}
.mem-danger-btn {
  display: block; width: 100%; padding: 12px; border-radius: 10px;
  border: 1px solid var(--error-25); background: transparent; color: var(--error);
  font-family: var(--font-ui); font-size: var(--fs-base); cursor: pointer; transition: background 150ms;
}
.mem-danger-btn:disabled { opacity: 0.3; cursor: default; }
.mem-danger-btn:not(:disabled):active { background: var(--error-08); }

/* Markdown toggle */
.mem-md-toggle {
  padding: 6px 10px; border-radius: 8px; background: transparent;
  border: 1px solid var(--border-soft); color: var(--text-faint);
  font-family: var(--font-ui); font-size: var(--fs-2xs); font-weight: 500;
  cursor: pointer; transition: all 150ms;
}
.mem-md-toggle[data-on="true"] {
  color: var(--smeraldo-chiaro); border-color: var(--border-mid);
  background: var(--smeraldo-glow);
}

/* Costituzione renderizzata */
.constitution-view {
  padding: 16px 18px; /* G-09 (OP-25, D-08): parità con .incisione-preview di Vox — più arioso in lettura su telefono */
  white-space: pre-wrap;
  overflow-wrap: anywhere; word-break: break-word;
  font-family: var(--font-voice); font-size: var(--fs-base); line-height: 1.7; color: var(--text-dim);
}
.constitution-view.md-rendered { white-space: normal; }
.constitution-view .md-h { color: var(--smeraldo-chiaro); margin: 20px 0 8px; line-height: 1.35; font-weight: 600; }
.constitution-view .md-h1 { font-size: 20px; }
.constitution-view .md-h2 { font-size: var(--fs-xl); }
.constitution-view .md-h3, .constitution-view .md-h4, .constitution-view .md-h5, .constitution-view .md-h6 { font-size: var(--fs-md); }
.constitution-view.md-rendered p { margin: 0 0 12px; }
.constitution-view.md-rendered ul, .constitution-view.md-rendered ol { margin: 0 0 12px; padding-left: 22px; }
.constitution-view.md-rendered strong { color: var(--smeraldo-chiaro); font-weight: 600; }
.constitution-view.md-rendered em { color: var(--ciano); font-style: italic; }
.constitution-view.md-rendered code { background: var(--bg-elev); padding: 2px 6px; border-radius: 4px; font-size: 0.88em; color: var(--smeraldo-chiaro); }
/* U-GRA-01: citazione e linea orizzontale allineate a incisione-preview. */
.constitution-view.md-rendered blockquote { margin: 0 0 0.75em; padding: 0.3em 0 0.3em 14px; border-left: 3px solid var(--border-mid); color: var(--text-dim); font-style: italic; }

/* U-GRA-01: hr e tabelle condivise fra le due superfici di lettura memoria — Andrew e Vox.
   Stessa grammatica delle bolle di chat, così la lettura converge davvero. */
.constitution-view.md-rendered hr,
.incisione-preview hr {
  border: none; height: 1px;
  background: linear-gradient(90deg, transparent, var(--border-mid), transparent);
  margin: 1.2em 0;
}
.constitution-view.md-rendered .md-table,
.incisione-preview .md-table {
  border-collapse: collapse; margin: 0.75em 0;
  font-family: var(--font-ui); font-size: var(--fs-base); line-height: 1.5;
  width: auto; max-width: 100%; display: block; overflow-x: auto;
}
.constitution-view.md-rendered .md-table th,
.constitution-view.md-rendered .md-table td,
.incisione-preview .md-table th,
.incisione-preview .md-table td {
  border: 1px solid var(--border-soft); padding: 6px 12px; text-align: left; vertical-align: top;
}
.constitution-view.md-rendered .md-table th,
.incisione-preview .md-table th {
  background: var(--bg-elev); color: var(--smeraldo-chiaro); font-weight: 600;
}

/* ============ DRAFT (Forgia) ============ */
.draft-area { flex: 1; display: flex; flex-direction: column; padding: 18px; overflow: hidden; }
.draft-status {
  color: var(--text-dim); font-family: var(--font-voice);
  font-size: var(--fs-md); font-style: italic; margin-bottom: 14px;
}
.draft-loader { display: flex; justify-content: center; padding: 40px 0; }
.draft-editor {
  flex: 1; background: var(--bg-elev); color: var(--text);
  border: 1px solid var(--border-soft); border-radius: 14px; padding: 16px;
  font-family: var(--font-voice); font-size: var(--fs-md); line-height: 1.7;
  resize: none; outline: none; margin-bottom: 14px;
  transition: border-color 200ms;
}
.draft-editor:focus { border-color: var(--border-focus); }
.draft-counters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; font-size: var(--fs-xs); font-family: var(--font-ui); }
.counter {
  background: var(--bg-elev); padding: 5px 12px; border-radius: 8px;
  color: var(--text-dim); border: 1px solid var(--border-soft);
  font-weight: 500;
}
.draft-actions { display: flex; gap: 10px; }
.btn, .btn-primary, .btn-secondary {
  padding: 13px; border-radius: 12px; border: none;
  font-family: var(--font-ui); font-size: var(--fs-md); font-weight: 500;
  cursor: pointer; transition: all 150ms;
}
.btn-primary, .btn-secondary { flex: 1; }
.btn-primary {
  background: var(--smeraldo); color: var(--bg-main); /* U-GRA-04: testo scuro sul pieno smeraldo, il bianco era 2,99:1 */
  box-shadow: 0 2px 10px var(--smeraldo-20);
}
.btn-primary:active { transform: scale(0.97); }
.btn-primary:disabled { opacity: 0.35; box-shadow: none; }
.btn-secondary {
  background: transparent; color: var(--smeraldo-chiaro);
  border: 1px solid var(--border-mid);
}
.btn-secondary:active { background: var(--smeraldo-glow); }

/* ============ CONFIG ============ */
.config-area {
  flex: 1; overflow-y: auto; padding: 16px 18px;
  padding-bottom: calc(20px + var(--inset-bottom));
  scrollbar-gutter: stable;
}
@media (min-width: 800px) {
  .config-area { width: 100%; max-width: var(--chat-max); margin: 0 auto; }
}
.config-section { margin-bottom: 28px; }
.config-section-title {
  color: var(--smeraldo); font-family: var(--font-ui);
  font-size: var(--fs-2xs); letter-spacing: 1.4px; text-transform: uppercase;
  margin: 24px 0 10px; font-weight: 600;
}
.config-section-title:first-child { margin-top: 0; }
.config-label {
  color: var(--text-dim); font-family: var(--font-ui);
  font-size: var(--fs-sm); margin: 12px 0 5px; display: block;
}
.config-input, .config-textarea, .config-area select {
  width: 100%; background: var(--bg-elev); color: var(--text);
  border: 1px solid var(--border-soft); border-radius: 10px;
  padding: 11px 14px; font-family: var(--font-ui); font-size: var(--fs-base);
  outline: none; display: block; -webkit-appearance: none;
  transition: border-color 200ms;
}
.config-input:focus, .config-textarea:focus, .config-area select:focus { border-color: var(--border-focus); }
/* G-19 (deploy-2): appearance:none spogliava i select della freccia — erano
   indistinguibili da un input di testo. Il chevron inline restituisce
   l'affordance senza toccare il tema. */
.config-area select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%238a9a8e' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
  padding-right: 34px;
}
.config-textarea { resize: vertical; min-height: 80px; font-family: ui-monospace, 'SF Mono', monospace; font-size: var(--fs-xs); }
/* 1.0.1 R01: Safari iOS ingrandisce i controlli sotto 16px e può conservare
   la scala dopo una rotazione. Limite ristretto ai dispositivi touch: nessun
   intervento sul viewport o sull'altezza PWA. */
@media (hover: none) and (pointer: coarse) {
  /* SEG-15 (campo, 9 lug): FOCUS-BUMP — il 16px fisso gonfiava i campi (chiavi API
     illeggibili, una per riga che non ci sta). iOS decide lo zoom AL FOCUS, sulla
     taglia dell'elemento in quel momento: quindi compatti a riposo (taglia di
     design) e 16px SOLO al focus. Copre le stesse superfici di UG-01/R01. */
  .config-input:focus, .config-textarea:focus, .config-area select:focus,
  .cron-search:focus, .incisione-textarea:focus, .draft-editor:focus,
  .dialog-input:focus, .rectify-input:focus { font-size: 16px; }
}

/* SEG-14 (campo, 9 lug): VELO PORTRAIT — iOS ignora l'orientation del manifest
   per le PWA e il lock di Screen Orientation richiede fullscreen: il velo è
   l'unica via. Gated su touch: il Mac non lo vede mai. Puro CSS additivo,
   l'app sotto resta montata; elimina alla radice anche lo zoom anomalo del
   landscape e l'artefatto di rotazione con tastiera aperta (residuo SEG-02).
   z-index 3000 — sopra tutto, registrato in testa. */
@media (hover: none) and (pointer: coarse) and (orientation: landscape) {
  body::after {
    content: 'Il portale vive in ritratto — riporta Aurora in verticale.';
    position: fixed; inset: 0; z-index: 3000;
    display: flex; align-items: center; justify-content: center;
    padding: 24px; text-align: center;
    background: var(--bg-deep); color: var(--smeraldo-chiaro);
    font-family: var(--font-title, inherit); font-size: 18px; line-height: 1.6;
  }
}
.config-hint { color: var(--text-faint); font-size: var(--fs-2xs); margin-top: 5px; line-height: 1.5; }
.config-row { display: flex; align-items: center; justify-content: space-between; padding: 11px 0; }
.config-row-label { color: var(--text); flex: 1; font-size: var(--fs-md); }
.config-row-value { color: var(--smeraldo-chiaro); font-weight: 500; min-width: 40px; text-align: right; }
.config-slider-row { display: flex; align-items: center; gap: var(--sp-3); }
.config-slider-row input[type="range"] { flex: 1; accent-color: var(--smeraldo); }
.config-info {
  font-size: var(--fs-xs); color: var(--text-faint); margin-top: 10px;
  padding: 10px 12px; background: var(--smeraldo-glow); border-radius: 8px;
  border: 1px solid var(--border-soft); line-height: 1.55;
}
.config-details { margin-top: 20px; }
.config-details summary { list-style: none; cursor: pointer; display: flex; align-items: center; }
.config-details summary::-webkit-details-marker { display: none; }
.config-details summary::after {
  content: '▸'; margin-left: auto; font-size: var(--fs-lg);
  transition: transform 200ms ease; display: inline-block;
}
.config-details[open] summary::after { transform: rotate(90deg); }

/* ============ SWITCH ============ */
.switch {
  position: relative; width: 44px; height: 26px;
  background: var(--bg-elev); border-radius: 13px;
  border: 1px solid var(--border-mid); cursor: pointer;
  transition: all 180ms; flex-shrink: 0;
}
.switch::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 20px; height: 20px; background: var(--text-faint);
  border-radius: 50%; transition: all 180ms;
}
.switch.on { background: var(--smeraldo); border-color: var(--smeraldo-chiaro); }
.switch.on::after { left: 20px; background: white; }
/* U-GRA-07: anello di focus visibile per navigazione da tastiera. Senza ARIA, per scelta. */
.switch:focus-visible { outline: 2px solid var(--smeraldo); outline-offset: 2px; }

/* G-20 (deploy-2): stato disabled UNIFORME — i bottoni senza regola dedicata
   restavano visivamente attivi da spenti. La regola globale ha specificità
   minima: le classi già stilate restano padrone. */
button:disabled { opacity: 0.35; cursor: default; }
/* G-04 (deploy-2): focus visibile da tastiera per OGNI bottone — i 18
   focus-visible dedicati esistenti restano e prevalgono. */
button:focus-visible { outline: 2px solid var(--smeraldo); outline-offset: 2px; }

/* ============ TOAST ============ */
.toast {
  position: fixed; bottom: calc(64px + var(--inset-bottom)); left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card); color: var(--text); padding: 12px 22px;
  border-radius: 14px; font-family: var(--font-ui); font-size: var(--fs-base);
  border: 1px solid var(--border-mid);
  /* U-032 (v209): i toast nascevano a 200, SOTTO i dialog (1100): «Errore
     eliminazione» sotto un confirmDialog era invisibile — feedback perso.
     1200 li porta sopra dialog e overlay; il banner segue a 1210. */
  z-index: 1200; max-width: 88%; text-align: center;
  overflow-wrap: anywhere; /* G-05 (v209): un token lungo (URL, id) non sfonda il bordo */
  animation: toastIn 200ms ease-out;
  box-shadow: 0 8px 28px rgba(0,0,0,0.5);
}
@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 16px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
.toast.error { border-color: var(--error-30); color: var(--error); }
/* Azione nel toast — v149: bottone accanto al testo (es. «Riprova»). */
.toast-action {
  margin-left: 14px; padding: 4px 12px; border-radius: 8px;
  background: transparent; color: var(--smeraldo-chiaro);
  border: 1px solid var(--border-mid);
  font-family: var(--font-ui); font-size: var(--fs-sm); font-weight: 600;
  cursor: pointer; flex-shrink: 0;
}
.toast-action:active { background: var(--smeraldo-glow); }

/* ============ BANNER AGGIORNAMENTO ============ */
/* Stessa casa del toast, ma persiste finché Mike non decide: tocca il testo
   per ricaricare, la croce per restare sulla versione corrente fino al
   prossimo avvio. [ADV2-2G-05] Pila REALE dagli z-index: banner 1210 SOPRA i
   toast (1200) e SOPRA i dialog (1100); solo gli overlay a schermo pieno
   (3000) lo coprono. Il vecchio «sotto i dialog» descriveva la pila di v209. */
.update-banner {
  position: fixed; bottom: calc(184px + var(--inset-bottom)); left: 50%; /* G-21 (deploy-2): terzo piano della pila — vedi .tts-indicator */
  transform: translateX(-50%);
  display: flex; align-items: center; gap: var(--sp-1);
  background: var(--bg-card); color: var(--text);
  border: 1px solid var(--border-mid); border-radius: 14px;
  z-index: 1210; max-width: 88%; /* U-032 (v209): sopra i toast (1200), come prima era 210 sopra 200 */
  box-shadow: 0 8px 28px rgba(0,0,0,0.5);
  animation: toastIn 200ms ease-out;
}
.update-banner-text {
  background: none; border: none; color: var(--text);
  font-family: var(--font-ui); font-size: var(--fs-base);
  padding: 12px 4px 12px 18px; cursor: pointer; text-align: left;
}
.update-banner-close {
  background: none; border: none; color: var(--text-dim);
  font-family: var(--font-ui); font-size: var(--fs-2xl); line-height: 1;
  padding: 12px 14px; cursor: pointer;
}

/* G-06 (deploy-2): le croci di chiusura dei banner erano target da ~20px —
   sotto ogni soglia tattile. Il minimo sale a 44px con margini negativi di
   compenso: l'area cresce, il layout non si muove. */
.tab-warning-close, .context-banner-close, .mem-banner-close, .update-banner-close {
  min-width: 44px; min-height: 44px;
  display: inline-flex; align-items: center; justify-content: center;
  margin: -12px -12px -12px -8px;
}

/* ============ DIALOG (classi, non inline) ============ */
.dialog-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 1100; padding: 24px;
  animation: dialogFade 180ms ease-out;
}
@keyframes dialogFade { from { opacity: 0; } to { opacity: 1; } }
.dialog-box {
  background: var(--bg-card); color: var(--text);
  max-width: 380px; width: 100%; border-radius: 16px;
  padding: 24px; border: 1px solid var(--border-mid);
  /* U-033 (v209): un dialog con molto testo (import lungo, errori multipli)
     sforava il viewport basso su schermi piccoli e i bottoni diventavano
     irraggiungibili. Tetto al viewport (dvh dove c'è) e scroll interno. */
  max-height: calc(100vh - 48px);
  max-height: calc(100dvh - 48px);
  overflow-y: auto;
  box-shadow: 0 16px 48px rgba(0,0,0,0.5);
  animation: dialogScale 200ms ease-out;
}
@keyframes dialogScale { from { transform: scale(0.95); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@media (min-width: 600px) { .dialog-box { max-width: 440px; } }
.dialog-title {
  margin: 0 0 14px; font-family: var(--font-voice);
  font-size: var(--fs-xl); font-weight: 600; line-height: 1.4; color: var(--text);
}
.dialog-msg {
  margin: 0 0 22px; line-height: 1.6; font-size: var(--fs-base); color: var(--text-dim);
  overflow-wrap: anywhere;
}
.dialog-hint {
  margin: 0 0 14px; font-size: var(--fs-sm); color: var(--text-faint); line-height: 1.5;
}
.dialog-input {
  width: 100%; box-sizing: border-box; padding: 11px 14px;
  border-radius: 10px; border: 1px solid var(--border-mid);
  background: var(--bg-elev); color: var(--text);
  font-family: var(--font-ui); font-size: var(--fs-md);
  margin-bottom: 20px; outline: none;
}
.dialog-input::placeholder { color: var(--text-faint); }
.dialog-input:focus { border-color: var(--border-focus); }
.dialog-row { display: flex; gap: 10px; justify-content: flex-end; }
.dialog-btn {
  padding: 10px 18px; border-radius: 10px;
  font-family: var(--font-ui); font-size: var(--fs-base); font-weight: 500;
  cursor: pointer; transition: all 150ms; border: none;
}
.dialog-btn-cancel {
  background: transparent; color: var(--text-dim);
  border: 1px solid var(--border-mid);
}
.dialog-btn-cancel:active { background: var(--bg-surface); }
.dialog-btn-confirm { background: var(--smeraldo); color: var(--bg-main); } /* U-GRA-04: testo scuro sul pieno smeraldo, il bianco era 2,55:1 */
.dialog-btn-confirm:active { transform: scale(0.97); }
.dialog-btn-confirm.danger { background: var(--error); color: white; } /* il pieno error (rosso) tiene il bianco */
.dialog-btn-ok { background: var(--smeraldo); color: var(--bg-main); } /* U-GRA-04: testo scuro sul pieno smeraldo */
.dialog-btn-ok:active { transform: scale(0.97); }

/* Info dialog lines */
.dialog-lines { margin: 0 0 22px; line-height: 1.65; font-size: var(--fs-base); color: var(--text-dim); overflow-wrap: anywhere; }
.dialog-lines > div:empty { height: 8px; }
/* [DESIGN 10 lug, ordine di Mike] Pannello Diagnostica ridisegnato. Gerarchia:
   titoli di sezione come intestazioni piccole in maiuscolo spaziato (calco iOS
   grouped-list), valori a taglia propria con cifre tabellari, TONO come pallino
   di stato prima del valore (scansione a colpo d'occhio, il colore da solo era
   segnale debole), corpo tecnico in recinto monospace con scroll proprio (i 400
   caratteri grezzi erano il vero orrore visivo). Sotto i 380px le coppie si
   impilano CON gerarchia (etichetta soprascritta), niente piu' zuppa. */
.vault-diagnostic { max-width: min(520px, calc(100vw - 28px)); }
.diagnostic-grid {
  display: grid; gap: 12px; margin: 0 0 18px;
  max-height: min(58vh, 460px); overflow-y: auto;
  -webkit-overflow-scrolling: touch; padding-right: 2px;
}
.diagnostic-section {
  border: 1px solid var(--border-soft); border-radius: 12px;
  padding: 12px 14px; background: var(--smeraldo-06);
}
.diagnostic-section-title {
  margin: 0 0 8px; color: var(--smeraldo-chiaro); font-family: var(--font-ui);
  font-size: var(--fs-2xs); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.7px; opacity: 0.92;
}
.diagnostic-row {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr);
  gap: 12px; padding: 8px 0; border-top: 1px solid var(--border-soft);
  align-items: baseline;
}
.diagnostic-section-title + .diagnostic-row { border-top: 0; padding-top: 0; }
.diagnostic-row:last-child { padding-bottom: 0; }
.diagnostic-label { color: var(--text-faint); font-family: var(--font-ui); font-size: var(--fs-xs); line-height: 1.4; }
.diagnostic-value {
  color: var(--text); text-align: right; overflow-wrap: anywhere;
  font-size: var(--fs-sm); line-height: 1.45; font-variant-numeric: tabular-nums;
}
.diagnostic-value[data-tone]::before {
  content: ''; display: inline-block; width: 7px; height: 7px;
  border-radius: 50%; margin-right: 7px; vertical-align: 1px;
}
.diagnostic-value[data-tone="ok"] { color: var(--text); }
.diagnostic-value[data-tone="ok"]::before { background: var(--smeraldo-chiaro); }
.diagnostic-value[data-tone="warn"] { color: var(--oro); }
.diagnostic-value[data-tone="warn"]::before { background: var(--oro); }
.diagnostic-value[data-tone="error"] { color: var(--error); }
.diagnostic-value[data-tone="error"]::before { background: var(--error); }
.diagnostic-note {
  margin: 10px 0 0; padding: 8px 10px;
  background: var(--bg-abyss); border: 1px solid var(--border-soft); border-radius: 8px;
  color: var(--text-dim); font-size: var(--fs-2xs); line-height: 1.55;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  overflow-wrap: anywhere; max-height: 10.5em; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
@media (max-width: 380px) {
  .diagnostic-row { grid-template-columns: 1fr; gap: 2px; }
  .diagnostic-value { text-align: left; }
  .diagnostic-label { font-size: var(--fs-2xs); letter-spacing: 0.2px; }
}

/* Lista di scelta — v149 (chooseDialog): voci toccabili con etichetta e sottotesto. */
.dialog-list {
  display: flex; flex-direction: column; gap: var(--sp-2);
  margin: 0 0 20px; max-height: 320px; overflow-y: auto;
}
.dialog-list-item {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  width: 100%; box-sizing: border-box; text-align: left;
  padding: 11px 14px; border-radius: 10px;
  background: var(--bg-elev); color: var(--text);
  border: 1px solid var(--border-mid);
  font-family: var(--font-ui); cursor: pointer; transition: all 150ms;
}
.dialog-list-item:active { border-color: var(--border-focus); background: var(--bg-surface); }
.dialog-list-label { font-size: var(--fs-base); color: var(--text); }
.dialog-list-sub { font-size: var(--fs-sm); color: var(--text-faint); }

/* Rectify textarea */
.rectify-input {
  width: 100%; min-height: 64px; border-radius: 12px; padding: 12px;
  font-family: var(--font-ui); font-size: var(--fs-md);
  background: var(--bg-elev); color: var(--text);
  border: 1px solid var(--border-mid); outline: none; resize: vertical;
}
.rectify-input:focus { border-color: var(--border-focus); }

/* ============ DIALOG BUTTONS — v146 ============ */
.dialog-btns { display: flex; gap: 10px; margin-top: 12px; }
.dialog-btns > button { flex: 1; }
.threshold-group { display: flex; align-items: center; gap: 8px; margin-top: 16px; font-size: var(--fs-md); color: var(--text); }
.threshold-input { width: 60px; text-align: center; }

/* ============ ACCESSIBILITÀ ============ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* ============ UTILITIES ============ */

/* Utility di layout (erano width/margin inline in views/config.js) */
.btn-block { display: block; width: 100%; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mb-8 { margin-bottom: 8px; }

/* Impostazioni */
.config-summary { cursor: pointer; }
.config-details-body { padding-top: 8px; }
.config-version { margin-top: 18px; text-align: center; opacity: .5; font-size: var(--fs-xs); }
.config-diagnostica { margin-top: 6px; opacity: .4; font-size: var(--fs-2xs); white-space: pre-line; word-break: break-word; } /* diagnostica di campo (9 lug) */

/* Toast a riga (auto-lettura, con interruttore inline) */
.toast-row { display: flex; align-items: center; gap: var(--sp-3); }

/* Bozza del diario — il loader ha display:flex, che vincerebbe sull'[hidden]
   dello user agent: la regola esplicita ristabilisce la gerarchia. */
.draft-loader[hidden] { display: none; }
.draft-saved { margin-top: 18px; display: flex; flex-direction: column; gap: var(--sp-3); }
.draft-saved-note { margin: 0; line-height: 1.5; opacity: .8; font-size: var(--fs-base); }

/* Editor del prompt — Incisione (era un blocco cssText in diary-draft.js).
   NB: --bg-input era indefinito anche nell'originale → il fallback
   transparent riproduce la resa storica, senza inventare token. */
.incisione-overlay { position: fixed; inset: 0; background: var(--bg-deep); display: flex; flex-direction: column; z-index: 1000; }
.incisione-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; padding-top: calc(12px + var(--inset-top));
  border-bottom: 1px solid var(--smeraldo-15); flex-shrink: 0;
}
.incisione-title {
  font-size: var(--fs-xl); font-weight: 500; color: var(--smeraldo-chiaro);
  flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.incisione-btns { display: flex; gap: 10px; flex-shrink: 0; }
.incisione-btn { padding: 7px 12px; border-radius: 8px; font-size: var(--fs-sm); cursor: pointer; font-family: var(--font-ui); }

.incisione-btn--save { padding: 7px 14px; border: none; background: var(--smeraldo); color: var(--bg-main); } /* U-GRA-04: testo scuro sul pieno smeraldo */
.incisione-btn--close { border: 1px solid var(--smeraldo-25); background: transparent; color: var(--text-dim); }
/* v162r (M-08): bottone Elimina nell'editor — stile danger gemello di
   .mem-danger-btn di Andrew (bordo rosso, sfondo trasparente, testo rosso). */
.incisione-btn--delete { border: 1px solid var(--error-25); background: transparent; color: var(--error); }
.incisione-btn--delete:active { background: var(--error-08); }
/* v162r (M-09): bottone Anteprima/Modifica — stile coerente col tema di Vox,
   acceso quando l'anteprima è attiva (dataset.on="true"). */
.incisione-btn--preview { border: 1px solid var(--smeraldo-25); background: transparent; color: var(--text-dim); }
.incisione-btn--preview[data-on="true"] { color: var(--smeraldo-chiaro); border-color: var(--border-mid); background: var(--smeraldo-glow); }
/* Pannello anteprima — U-GRA-01: colore del corpo allineato a --text-dim di Andrew. */
.incisione-preview {
  flex: 1; padding: 16px 18px; overflow-y: auto;
  padding-bottom: calc(16px + var(--inset-bottom)); /* GRA-05 */
  background: var(--bg-input, transparent); color: var(--text-dim);
  font-family: var(--font-voice); font-size: var(--fs-base); line-height: 1.7;
  overflow-wrap: anywhere; word-break: break-word;
}
.incisione-preview .md-h { color: var(--smeraldo-chiaro); margin: 20px 0 8px; line-height: 1.35; font-weight: 600; }
.incisione-preview .md-h1 { font-size: 20px; }
.incisione-preview .md-h2 { font-size: var(--fs-xl); }
.incisione-preview .md-h3, .incisione-preview .md-h4, .incisione-preview .md-h5, .incisione-preview .md-h6 { font-size: var(--fs-md); }
.incisione-preview p { margin: 0 0 12px; }
.incisione-preview ul, .incisione-preview ol { margin: 0 0 12px; padding-left: 22px; }
.incisione-preview strong { color: var(--smeraldo-chiaro); font-weight: 600; }
.incisione-preview em { color: var(--ciano); font-style: italic; }
.incisione-preview code { background: var(--bg-elev); padding: 2px 6px; border-radius: 4px; font-size: 0.88em; color: var(--smeraldo-chiaro); }
.incisione-preview blockquote { margin: 0 0 0.75em; padding: 0.3em 0 0.3em 14px; border-left: 3px solid var(--border-mid); color: var(--text-dim); font-style: italic; }
.incisione-textarea {
  flex: 1; margin: 0; padding: 16px;
  padding-bottom: calc(16px + var(--inset-bottom)); /* GRA-05: safe area inferiore, come il resto dell'app */
  background: var(--bg-input, transparent); color: var(--text);
  border: none; font-family: inherit; font-size: var(--fs-base); line-height: 1.6;
  resize: none; outline: none;
}
/* v162 — la vista di lettura della Cronaca (rendering) dentro l'overlay flex
   deve scrollare, altrimenti le Cronache lunghe vengono tagliate. */
.incisione-overlay .constitution-view { flex: 1; overflow-y: auto; padding-bottom: calc(16px + var(--inset-bottom)); } /* GRA-05 */

/* ============ RESPONSIVE ============ */
@media (min-width: 680px) {
  .welcome-sigillo { width: 240px; height: 240px; }
  .welcome h1 { font-size: 34px; }
  .welcome .vox-marchio { font-size: 92px; }
  .msg-user .bubble { max-width: 70%; }
}

@media (min-width: 1080px) {
  .msg-user .bubble { max-width: 55%; }
}
