/*
 * ai.nekoh.it — il sistema visivo.
 *
 * Il concetto viene dal dominio: "ai" in giapponese e' 藍, l'indaco della tintura
 * aizome. Carta di cotone e inchiostro indaco, con i colori derivati dalle sue
 * tonalita' (kon, asagi) e due soli accenti semantici: l'ocra (kincha) per
 * "occupato", il vermiglio dei sigilli (shu) per "esaurito" ed errori.
 * Il gesto memorabile e' il SIGILLO: il pulsante d'invio e i segni di stato dei
 * modelli hanno la forma di un timbro hanko. Il resto resta quieto.
 *
 * Caratteri: Figtree per testo e interfaccia; Zen Maru Gothic solo per il
 * marchio, il saluto e i titoli di pagina; IBM Plex Mono solo per il codice.
 * Tutto servito da qui: la CSP del vhost e' `self`, niente terze parti.
 */

@font-face {
  font-family: "Figtree";
  src: url("../fonts/figtree-latin-wght-normal.woff2") format("woff2");
  font-weight: 300 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Zen Maru Gothic";
  src: url("../fonts/zen-maru-gothic-latin-700-normal.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("../fonts/ibm-plex-mono-latin-400-normal.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --paper: #f3f5f4;
  --surface: #ffffff;
  --raised: #f8f9fb;
  --ink: #1a1d3a;
  --ink-soft: #4a5072;
  --ink-faint: #7a7f9c;
  --line: #d8dde0;
  --line-strong: #bcc3cb;
  --indigo: #233f87;
  --indigo-ink: #ffffff;
  --indigo-wash: #e3e9f6;
  --asagi: #2f7f8c;
  --asagi-wash: #dcefef;
  --kincha: #8f6210;
  --kincha-wash: #f6ecd6;
  --shu: #bd3b2a;
  --shu-wash: #f9e3df;
  --code-bg: #eef1f6;
  --focus: #233f87;
  --shadow: 0 10px 30px -12px rgba(35, 63, 135, 0.28);
  /* Serie dei grafici: tavolozza validata con validate_palette.js della skill
     dataviz (chiaro su #ffffff, scuro su #181c38), distinta dai colori di stato. */
  --series-1: #2f55c4;
  --series-2: #00908c;
  --series-3: #9a4fc0;
  --series-4: #6f9020;
  --series-other: #9aa0b4;
  --sidebar: 17rem;
  --column: 46rem;
  --font: "Figtree", "Segoe UI", system-ui, sans-serif;
  --font-display: "Zen Maru Gothic", "Figtree", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #10132a;
    --surface: #181c38;
    --raised: #1d2243;
    --ink: #e8eaf4;
    --ink-soft: #a5abcb;
    --ink-faint: #7d84a8;
    --line: #2c325a;
    --line-strong: #3b4373;
    --indigo: #93a9f2;
    --indigo-ink: #10132a;
    --indigo-wash: #232a57;
    --asagi: #69bcc6;
    --asagi-wash: #173a43;
    --kincha: #e0b157;
    --kincha-wash: #3a3017;
    --shu: #f08268;
    --shu-wash: #44221d;
    --code-bg: #12162f;
    --focus: #93a9f2;
    --shadow: 0 12px 34px -14px rgba(0, 0, 0, 0.6);
    --series-1: #5f80e0;
    --series-2: #1aa39c;
    --series-3: #a970d6;
    --series-4: #76a02c;
    --series-other: #5b6185;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #10132a;
  --surface: #181c38;
  --raised: #1d2243;
  --ink: #e8eaf4;
  --ink-soft: #a5abcb;
  --ink-faint: #7d84a8;
  --line: #2c325a;
  --line-strong: #3b4373;
  --indigo: #93a9f2;
  --indigo-ink: #10132a;
  --indigo-wash: #232a57;
  --asagi: #69bcc6;
  --asagi-wash: #173a43;
  --kincha: #e0b157;
  --kincha-wash: #3a3017;
  --shu: #f08268;
  --shu-wash: #44221d;
  --code-bg: #12162f;
  --focus: #93a9f2;
  --shadow: 0 12px 34px -14px rgba(0, 0, 0, 0.6);
  --series-1: #5f80e0;
  --series-2: #1aa39c;
  --series-3: #a970d6;
  --series-4: #76a02c;
  --series-other: #5b6185;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 15.5px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--indigo); text-underline-offset: 0.18em; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
[hidden] { display: none !important; }

/* --- pulsanti ------------------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; gap: 0.45rem;
  border: 1px solid var(--line-strong); background: var(--surface);
  border-radius: 0.6rem; padding: 0.45rem 0.8rem; cursor: pointer;
  font-weight: 550; font-size: 0.93rem; line-height: 1.2;
  transition: background-color 0.12s, border-color 0.12s;
}
.btn:hover { background: var(--raised); border-color: var(--ink-faint); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--indigo); color: var(--indigo-ink); border-color: var(--indigo); }
.btn-primary:hover { background: var(--indigo); filter: brightness(1.08); }
.btn-danger { color: var(--shu); border-color: color-mix(in srgb, var(--shu) 45%, var(--line)); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: color-mix(in srgb, var(--ink) 6%, transparent); border-color: transparent; }
.icon-btn {
  display: inline-grid; place-items: center; width: 2.1rem; height: 2.1rem;
  border: 0; background: transparent; border-radius: 0.55rem; cursor: pointer; color: var(--ink-soft);
}
.icon-btn:hover { background: color-mix(in srgb, var(--ink) 7%, transparent); color: var(--ink); }
.icon { width: 1.15rem; height: 1.15rem; flex: none; }

/* --- struttura dell'app ----------------------------------------------------- */
.app { display: grid; grid-template-columns: var(--sidebar) 1fr; height: 100dvh; }
.sidebar {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--raised); border-right: 1px solid var(--line);
}
.brand {
  display: flex; align-items: center; gap: 0.55rem; padding: 1rem 1rem 0.75rem;
  font: 700 1.12rem/1 var(--font-display); letter-spacing: 0.01em; color: var(--ink); text-decoration: none;
}
.brand-mark { width: 1.7rem; height: 1.7rem; flex: none; }
.brand-tld { color: var(--ink-faint); }
.sidebar-actions { padding: 0.25rem 0.75rem 0.5rem; }
.new-chat { width: 100%; justify-content: flex-start; }
.conv-list { flex: 1; overflow-y: auto; padding: 0.25rem 0.5rem 1rem; }
.conv-group { margin-top: 0.85rem; }
.conv-group h2 {
  margin: 0 0.5rem 0.25rem; font-size: 0.78rem; font-weight: 600; color: var(--ink-faint);
}
.conv-item {
  display: flex; align-items: center; gap: 0.25rem; border-radius: 0.55rem;
  padding: 0 0.15rem 0 0.6rem; min-height: 2.2rem;
}
.conv-item a {
  flex: 1; min-width: 0; color: var(--ink); text-decoration: none; padding: 0.4rem 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 0.93rem;
}
.conv-item:hover, .conv-item:focus-within { background: color-mix(in srgb, var(--ink) 6%, transparent); }
.conv-item[aria-current="page"] { background: var(--indigo-wash); }
.conv-item .icon-btn { width: 1.8rem; height: 1.8rem; opacity: 0; }
.conv-item:hover .icon-btn, .conv-item:focus-within .icon-btn, .conv-item[aria-current="page"] .icon-btn { opacity: 1; }
.conv-item input {
  flex: 1; min-width: 0; border: 1px solid var(--indigo); border-radius: 0.4rem;
  background: var(--surface); padding: 0.25rem 0.4rem; font-size: 0.93rem;
}
.conv-empty { color: var(--ink-faint); font-size: 0.9rem; padding: 0.75rem; }

.sidebar-foot { border-top: 1px solid var(--line); padding: 0.75rem; display: grid; gap: 0.6rem; }
.me { display: flex; align-items: center; gap: 0.6rem; min-width: 0; }
.avatar {
  width: 2rem; height: 2rem; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--indigo); color: var(--indigo-ink); font-weight: 700; font-size: 0.9rem;
}
.me-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-links { display: flex; flex-wrap: wrap; gap: 0.15rem 0.75rem; font-size: 0.86rem; }
.me-links a, .me-links button {
  background: none; border: 0; padding: 0; color: var(--ink-soft); cursor: pointer; text-decoration: none;
}
.me-links a:hover, .me-links button:hover { color: var(--ink); text-decoration: underline; }

/* La quota del giorno: una barra sola, che cambia colore avvicinandosi al tetto. */
.quota { display: grid; gap: 0.3rem; font-size: 0.82rem; color: var(--ink-soft); }
.quota-row { display: flex; justify-content: space-between; gap: 0.5rem; font-variant-numeric: tabular-nums; }
.meter { height: 0.38rem; border-radius: 999px; background: var(--line); overflow: hidden; }
.meter > span { display: block; height: 100%; width: 0; background: var(--asagi); border-radius: inherit; }
.meter[data-level="warn"] > span { background: var(--kincha); }
.meter[data-level="full"] > span { background: var(--shu); }

/* --- area principale ---------------------------------------------------------- */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
.topbar {
  display: flex; align-items: center; gap: 0.5rem; padding: 0.6rem 1rem;
  min-height: 3.4rem; border-bottom: 1px solid transparent;
}
.topbar.scrolled { border-bottom-color: var(--line); }
.menu-btn { display: none; }
.conv-title {
  flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--ink-soft); text-align: right; font-size: 0.93rem;
}

/* Il selettore dei modelli. */
.model-picker { position: relative; }
.model-btn {
  display: inline-flex; align-items: center; gap: 0.5rem; border: 1px solid transparent;
  background: transparent; border-radius: 0.6rem; padding: 0.4rem 0.6rem; cursor: pointer;
  font-weight: 650; font-size: 0.98rem;
}
.model-btn:hover, .model-btn[aria-expanded="true"] { background: var(--surface); border-color: var(--line); }
.model-menu {
  position: absolute; top: calc(100% + 0.35rem); left: 0; z-index: 30; width: min(25rem, calc(100vw - 2rem));
  background: var(--surface); border: 1px solid var(--line); border-radius: 0.9rem; box-shadow: var(--shadow);
  padding: 0.35rem; max-height: min(70vh, 34rem); overflow-y: auto;
}
.model-option {
  display: grid; grid-template-columns: auto 1fr; gap: 0.15rem 0.7rem; align-items: start; width: 100%;
  text-align: left; background: none; border: 0; border-radius: 0.6rem; padding: 0.55rem 0.6rem; cursor: pointer;
}
.model-option:hover:not(:disabled), .model-option:focus-visible { background: var(--raised); }
.model-option[aria-checked="true"] { background: var(--indigo-wash); }
.model-option:disabled { cursor: not-allowed; }
.model-option:disabled .model-name { color: var(--ink-faint); }
.model-option .seal { grid-row: span 2; margin-top: 0.15rem; }
.model-name { font-weight: 600; display: flex; gap: 0.4rem; align-items: baseline; flex-wrap: wrap; }
.model-provider { color: var(--ink-faint); font-weight: 500; font-size: 0.85rem; }
.model-state { font-size: 0.84rem; color: var(--ink-soft); }
.model-option[data-status="exhausted"] .model-state { color: var(--shu); }
.model-option[data-status="busy"] .model-state { color: var(--kincha); }
.tag {
  font-size: 0.72rem; font-weight: 650; padding: 0.05rem 0.4rem; border-radius: 999px;
  background: var(--kincha-wash); color: var(--kincha);
}

/* Il sigillo: stato di un modello come un timbro. */
.seal {
  --c: var(--asagi);
  display: inline-grid; place-items: center; width: 1.05rem; height: 1.05rem; border-radius: 0.3rem;
  border: 2px solid var(--c); background: var(--c); flex: none;
}
.seal[data-status="busy"] { --c: var(--kincha); background: linear-gradient(135deg, var(--c) 50%, transparent 50%); }
.seal[data-status="exhausted"] { --c: var(--shu); background: transparent; }
.seal[data-status="exhausted"]::after { content: ""; width: 0.35rem; height: 0.35rem; border-radius: 50%; background: var(--c); }
.seal[data-status="disabled"], .seal[data-status="unconfigured"] { --c: var(--line-strong); background: transparent; }

/* --- conversazione -------------------------------------------------------------- */
.thread { flex: 1; overflow-y: auto; scroll-behavior: smooth; padding: 1rem 1rem 9.5rem; }
.thread-inner { max-width: var(--column); margin: 0 auto; display: grid; gap: 1.6rem; }

.msg { display: grid; gap: 0.35rem; min-width: 0; }
.msg-user { justify-items: end; }
.msg-user .bubble {
  background: var(--indigo-wash); border-radius: 1rem 1rem 0.3rem 1rem; padding: 0.65rem 0.95rem;
  max-width: min(36rem, 92%); white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg-meta { display: flex; align-items: center; gap: 0.25rem; color: var(--ink-faint); font-size: 0.8rem; min-height: 1.8rem; }
.msg-user .msg-meta { justify-content: flex-end; }
.msg-meta .icon-btn { width: 1.8rem; height: 1.8rem; }
.msg-model { margin-right: 0.35rem; }
.msg-note { color: var(--ink-faint); font-size: 0.82rem; }
.msg-note.warn { color: var(--kincha); }

.edit-box { width: min(36rem, 100%); display: grid; gap: 0.5rem; }
.edit-box textarea {
  width: 100%; min-height: 5rem; resize: vertical; border: 1px solid var(--indigo); border-radius: 0.8rem;
  background: var(--surface); padding: 0.65rem 0.8rem; line-height: 1.5;
}
.edit-box .row { display: flex; gap: 0.5rem; justify-content: flex-end; }

/* La risposta: testo pieno, niente riquadro. */
.answer { overflow-wrap: anywhere; line-height: 1.65; font-size: 1rem; }
.answer > :first-child { margin-top: 0; }
.answer > :last-child { margin-bottom: 0; }
.answer p, .answer ul, .answer ol, .answer blockquote, .answer table, .answer pre { margin: 0 0 0.9rem; }
.answer h1, .answer h2, .answer h3, .answer h4 { line-height: 1.3; margin: 1.3rem 0 0.5rem; }
.answer h1 { font-size: 1.35rem; } .answer h2 { font-size: 1.2rem; } .answer h3 { font-size: 1.07rem; }
.answer ul, .answer ol { padding-left: 1.4rem; }
.answer li + li { margin-top: 0.25rem; }
.answer blockquote { border-left: 3px solid var(--line-strong); padding-left: 0.9rem; color: var(--ink-soft); }
.answer hr { border: 0; border-top: 1px solid var(--line); margin: 1.2rem 0; }
.answer table { border-collapse: collapse; display: block; overflow-x: auto; max-width: 100%; font-size: 0.94rem; }
.answer th, .answer td { border: 1px solid var(--line); padding: 0.4rem 0.6rem; text-align: left; vertical-align: top; }
.answer th { background: var(--raised); }
.answer :not(pre) > code {
  font-family: var(--font-mono); font-size: 0.88em; background: var(--code-bg);
  padding: 0.1em 0.35em; border-radius: 0.35rem;
}
.code-block { border: 1px solid var(--line); border-radius: 0.75rem; overflow: hidden; margin: 0 0 0.9rem; background: var(--code-bg); }
.code-head {
  display: flex; justify-content: space-between; align-items: center; gap: 0.5rem;
  padding: 0.3rem 0.4rem 0.3rem 0.85rem; font-size: 0.8rem; color: var(--ink-soft);
  border-bottom: 1px solid var(--line);
}
.code-head button {
  display: inline-flex; gap: 0.35rem; align-items: center; background: none; border: 0; cursor: pointer;
  color: var(--ink-soft); padding: 0.25rem 0.45rem; border-radius: 0.4rem; font-size: 0.8rem;
}
.code-head button:hover { background: color-mix(in srgb, var(--ink) 8%, transparent); color: var(--ink); }
.code-block pre { margin: 0; padding: 0.85rem 1rem; overflow-x: auto; }
.code-block code { font-family: var(--font-mono); font-size: 0.86rem; line-height: 1.6; }

/* Evidenziazione: colori presi dalla stessa tavolozza, nei due temi. */
.hljs-keyword, .hljs-selector-tag, .hljs-built_in, .hljs-meta .hljs-keyword { color: var(--indigo); font-weight: 600; }
.hljs-string, .hljs-regexp, .hljs-addition, .hljs-attribute .hljs-string { color: var(--asagi); }
.hljs-number, .hljs-literal, .hljs-symbol, .hljs-bullet { color: var(--kincha); }
.hljs-comment, .hljs-quote, .hljs-meta { color: var(--ink-faint); font-style: italic; }
.hljs-title, .hljs-title.function_, .hljs-section, .hljs-name { color: var(--ink); font-weight: 650; }
.hljs-attr, .hljs-variable, .hljs-template-variable, .hljs-property, .hljs-params { color: var(--ink-soft); }
.hljs-deletion { color: var(--shu); }
.hljs-type, .hljs-class .hljs-title, .hljs-title.class_ { color: var(--asagi); font-weight: 600; }

.cursor::after {
  content: ""; display: inline-block; width: 0.55em; height: 1.05em; margin-left: 0.1em; vertical-align: -0.15em;
  background: var(--indigo); border-radius: 0.15rem; animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { to { visibility: hidden; } }

.thinking { display: inline-flex; gap: 0.3rem; padding: 0.4rem 0; }
.thinking span {
  width: 0.45rem; height: 0.45rem; border-radius: 0.12rem; background: var(--indigo); opacity: 0.25;
  animation: pulse 1.2s infinite ease-in-out;
}
.thinking span:nth-child(2) { animation-delay: 0.15s; }
.thinking span:nth-child(3) { animation-delay: 0.3s; }
@keyframes pulse { 40% { opacity: 0.9; transform: translateY(-2px); } }

/* Un errore e' un'indicazione, non un allarme: dice cosa e' successo e cosa fare. */
.notice {
  border: 1px solid var(--line); border-left: 3px solid var(--shu); background: var(--surface);
  border-radius: 0.6rem; padding: 0.75rem 0.9rem; display: grid; gap: 0.55rem; font-size: 0.95rem;
}
.notice[data-kind="busy"] { border-left-color: var(--kincha); }
.notice[data-kind="info"] { border-left-color: var(--indigo); }
.notice p { margin: 0; }
.notice .row { display: flex; flex-wrap: wrap; gap: 0.4rem; }

/* --- saluto iniziale -------------------------------------------------------------- */
.empty { max-width: var(--column); margin: 12vh auto 0; padding: 0 0.25rem; }
.empty h1 {
  font: 700 clamp(1.9rem, 4.2vw, 2.6rem)/1.15 var(--font-display); margin: 0 0 0.6rem; letter-spacing: -0.005em;
}
.empty p { margin: 0; color: var(--ink-soft); max-width: 34rem; }

/* --- composer ------------------------------------------------------------------------ */
.composer-wrap {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 0 1rem 1rem;
  background: linear-gradient(to bottom, transparent, var(--paper) 1.6rem);
}
.composer {
  max-width: var(--column); margin: 0 auto; background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: 1.25rem; box-shadow: var(--shadow); padding: 0.6rem 0.6rem 0.6rem 1rem;
  display: grid; grid-template-columns: 1fr auto; gap: 0.5rem; align-items: end;
}
.composer:focus-within { border-color: var(--indigo); }
.composer textarea {
  border: 0; outline: 0; resize: none; background: transparent; max-height: 40vh; min-height: 1.6rem;
  padding: 0.35rem 0; line-height: 1.5; font-size: 1rem;
}
.composer-hint { max-width: var(--column); margin: 0.4rem auto 0; font-size: 0.76rem; color: var(--ink-faint); text-align: center; }

/* Il pulsante d'invio e' un sigillo: quadrato a angoli morbidi, bordo interno. */
.send {
  width: 2.5rem; height: 2.5rem; border-radius: 0.7rem; border: 0; cursor: pointer;
  background: var(--indigo); color: var(--indigo-ink); display: grid; place-items: center;
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--indigo-ink) 35%, transparent);
  transition: transform 0.1s, filter 0.12s;
}
.send:hover:not(:disabled) { filter: brightness(1.1); }
.send:active:not(:disabled) { transform: scale(0.95); }
.send:disabled { background: var(--line-strong); cursor: not-allowed; box-shadow: none; }
.send.stop { background: var(--ink); color: var(--paper); }

/* --- dialoghi e avvisi -------------------------------------------------------------- */
dialog {
  border: 1px solid var(--line); border-radius: 1rem; background: var(--surface); color: var(--ink);
  padding: 1.25rem; width: min(26rem, calc(100vw - 2rem)); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(16, 19, 42, 0.45); }
dialog h2 { margin: 0 0 0.5rem; font-size: 1.1rem; }
dialog p { margin: 0 0 1rem; color: var(--ink-soft); }
dialog .row { display: flex; justify-content: flex-end; gap: 0.5rem; }
.toast {
  position: fixed; left: 50%; bottom: 1.25rem; transform: translateX(-50%); z-index: 60;
  background: var(--ink); color: var(--paper); padding: 0.55rem 0.9rem; border-radius: 0.6rem; font-size: 0.9rem;
}
.scrim { display: none; }

/* --- pagine (utilizzo, admin, accesso) ------------------------------------------------ */
.page { max-width: 72rem; margin: 0 auto; padding: 1.25rem 1.25rem 4rem; }
.page-head { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.page-head .brand { padding: 0; }
.page-head nav { margin-left: auto; display: flex; gap: 1rem; font-size: 0.93rem; }
.page h1 { font: 700 1.8rem/1.2 var(--font-display); margin: 0 0 0.35rem; }
.page h2 { font-size: 1.12rem; margin: 2.2rem 0 0.4rem; }
.page .lede { color: var(--ink-soft); margin: 0 0 1rem; max-width: 46rem; }
.section-note { color: var(--ink-soft); font-size: 0.9rem; margin: 0 0 0.85rem; max-width: 52rem; }
.stats { display: flex; flex-wrap: wrap; gap: 0.5rem 2.5rem; margin: 1rem 0; }
.stat { display: grid; gap: 0.1rem; }
.stat b { font-size: 1.6rem; font-variant-numeric: tabular-nums; font-weight: 650; }
.stat span { color: var(--ink-soft); font-size: 0.86rem; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 0.75rem; background: var(--surface); }
table.data { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
table.data th, table.data td { padding: 0.55rem 0.75rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data th { font-weight: 600; color: var(--ink-soft); background: var(--raised); white-space: nowrap; }
table.data tr:last-child td { border-bottom: 0; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data .sub { color: var(--ink-faint); font-size: 0.82rem; }
table.data input[type="number"], table.data input[type="text"], table.data select {
  width: 5.4rem; border: 1px solid var(--line-strong); border-radius: 0.4rem; padding: 0.25rem 0.4rem; background: var(--surface);
}
table.data input[type="text"] { width: 10rem; }
table.data select { width: 7.2rem; }
.cap-cell { min-width: 9rem; display: grid; gap: 0.25rem; }
.cap-cell .meter { height: 0.32rem; }
.pill { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.82rem; white-space: nowrap; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); gap: 0.85rem 1rem; align-items: end; }
.field { display: grid; gap: 0.3rem; font-size: 0.88rem; }
.field span { color: var(--ink-soft); font-weight: 550; }
.field input, .field select {
  border: 1px solid var(--line-strong); border-radius: 0.5rem; padding: 0.45rem 0.55rem; background: var(--surface);
}
.form-actions { display: flex; gap: 0.5rem; margin-top: 0.85rem; align-items: center; }
.form-status { font-size: 0.88rem; color: var(--ink-soft); }
.form-status.error { color: var(--shu); }

/* Grafici: barre in SVG, assi leggeri, legenda sotto. */
.chart { width: 100%; height: auto; display: block; }
.chart .axis { stroke: var(--line); }
.chart .grid { stroke: var(--line); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover, .chart .hit:focus { fill: color-mix(in srgb, var(--ink) 6%, transparent); outline: none; }
.chart text { fill: var(--ink-faint); font-size: 11px; font-family: var(--font); }
.chart-card { border: 1px solid var(--line); border-radius: 0.75rem; background: var(--surface); padding: 0.85rem 1rem 0.6rem; }
.legend { display: flex; flex-wrap: wrap; gap: 0.35rem 1rem; font-size: 0.82rem; color: var(--ink-soft); margin-top: 0.4rem; }
.legend i { display: inline-block; width: 0.7rem; height: 0.7rem; border-radius: 0.2rem; margin-right: 0.35rem; vertical-align: -0.05rem; }
.chart-tip {
  position: fixed; z-index: 70; pointer-events: none; background: var(--ink); color: var(--paper);
  font-size: 0.8rem; padding: 0.35rem 0.55rem; border-radius: 0.4rem; white-space: pre;
}

.access { max-width: 32rem; margin: 18vh auto 0; padding: 0 1.25rem; }
.access h1 { font: 700 1.9rem/1.2 var(--font-display); margin: 1rem 0 0.6rem; }
.access p { color: var(--ink-soft); }

/* --- mobile -------------------------------------------------------------------------- */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(19rem, 86vw); z-index: 50;
    transform: translateX(-102%); transition: transform 0.2s ease;
  }
  .app.nav-open .sidebar { transform: none; box-shadow: var(--shadow); }
  .app.nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 40; background: rgba(16, 19, 42, 0.4); }
  .menu-btn { display: inline-grid; }
  .conv-title { display: none; }
  .thread { padding: 0.75rem 0.85rem 9rem; }
  .composer-wrap { padding: 0 0.6rem 0.6rem; }
  .composer-hint { display: none; }
  .empty { margin-top: 8vh; }
  .conv-item .icon-btn { opacity: 1; }
}

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