/* ===========================================================
   Token system
   Ispirazione: sala carte / plancia di navigazione — non un
   assistente chat generico. Toni ardesia-blu, accento ottone
   (strumenti di bordo), etichette in monospaced come coordinate.
   =========================================================== */

@import url('https://fonts.googleapis.com/css2?family=Spectral:ital,wght@0,400;0,600;1,400&family=Inter:wght@400;500;600&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
  --ink-900: #0f1720;
  --ink-800: #16212c;
  --ink-700: #1f2e3c;
  --ink-650: #253647;
  --line: #2c3e4f;
  --line-soft: #223140;

  --paper: #dbe4ea;
  --paper-dim: #a9bac7;
  --muted: #7c93a3;

  --brass: #c9973f;
  --brass-dim: #8a6b34;
  --brass-soft: rgba(201, 151, 63, 0.14);

  --signal-ok: #6fae8c;
  --signal-warn: #c9973f;
  --signal-bad: #b85c4a;

  --font-display: 'Spectral', Georgia, 'Iowan Old Style', serif;
  --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;

  --radius: 3px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--ink-900);
  color: var(--paper);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
}

/* ===========================================================
   Layout
   =========================================================== */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-width, 280px) 6px 1fr;
  height: 100vh;
}

/* Maniglia per ridimensionare la sidebar trascinando (solo desktop — vedi
   js/app.js per il drag e la persistenza in localStorage; nascosta sotto i
   780px nella media query più sotto, dove il layout passa a colonna singola
   e la sidebar diventa il foglio a comparsa mobile). */
.sidebar-resize-handle {
  cursor: col-resize;
  position: relative;
}
.sidebar-resize-handle::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 2px;
  width: 2px;
  background: var(--line);
  transition: background 150ms ease;
}
.sidebar-resize-handle:hover::after,
.sidebar-resize-handle.is-dragging::after {
  background: var(--brass-dim);
}

/* Schede in basso mobile (Percorso/Lacune/Token/Account/Altro): stili
   completi in fondo al foglio (vedi ultima sezione) — devono vincere sulla
   cascata su regole come .chat{height:100vh} più specifiche in ordine di
   sorgente ma con la stessa specificità; un media query da solo, se
   dichiarato prima nel file, NON basta a garantire la precedenza. */

/* ===========================================================
   Sidebar
   =========================================================== */

.sidebar {
  background: var(--ink-800);
  border-right: 1px solid var(--line);
  padding: 22px 20px;
  display: flex;
  flex-direction: column;
  gap: 26px;
  overflow-y: auto;
}

.sidebar__header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar__mark {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--ink-900);
  background: var(--brass);
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  flex-shrink: 0;
}

.sidebar__header h1 {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  margin: 0;
  color: var(--paper);
}

.sidebar__header p {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 2px 0 0;
}

.user-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  background: var(--ink-700);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  font-size: 12px;
}
.user-bar__name {
  color: var(--paper-dim);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-bar__actions {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}
.user-bar__link {
  background: none;
  border: none;
  padding: 0;
  color: var(--muted);
  font-family: var(--font-body);
  font-size: 11.5px;
  text-decoration: underline;
  text-decoration-color: transparent;
  cursor: pointer;
}
.user-bar__link:hover {
  color: var(--brass);
  text-decoration-color: var(--brass-dim);
}

/* Switch modalità automatica / semi-automatica */
.mode-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.mode-toggle-label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.mode-switch {
  position: relative;
  display: inline-block;
  cursor: pointer;
}
.mode-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.mode-switch__track {
  display: block;
  width: 38px;
  height: 20px;
  background: var(--ink-700);
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  transition: background 150ms ease, border-color 150ms ease;
}
.mode-switch__thumb {
  display: block;
  width: 14px;
  height: 14px;
  margin: 2px;
  background: var(--paper-dim);
  border-radius: 999px;
  transition: transform 150ms ease, background 150ms ease;
}
.mode-switch input:checked + .mode-switch__track {
  background: var(--brass-soft);
  border-color: var(--brass);
}
.mode-switch input:checked + .mode-switch__track .mode-switch__thumb {
  transform: translateX(18px);
  background: var(--brass);
}
.mode-switch input:disabled + .mode-switch__track {
  opacity: 0.5;
  cursor: not-allowed;
}
.mode-hint {
  margin: 8px 0 0;
  font-size: 11.5px;
  color: var(--muted);
}

/* Selettore modalità di conoscenza (EIL) — coerente con la sidebar scura */
#modalitaConoscenzaSelect {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--paper);
  background: var(--ink-700);
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  padding: 4px 6px;
  max-width: 58%;
  cursor: pointer;
}
#modalitaConoscenzaSelect:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
#modalitaConoscenzaSelect option {
  background: var(--ink-800);
  color: var(--paper);
}

/* Form di modifica manuale dei parametri P02 (vedi js/app.js, costruisciFormP02) */
.p02-input {
  background: var(--ink-700);
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  color: var(--paper);
  font-family: inherit;
  font-size: 13px;
  padding: 6px 8px;
  box-sizing: border-box;
}
.p02-input:focus { outline: none; border-color: var(--brass); }
.p02-input option { background: var(--ink-800); color: var(--paper); }

.account-panel { display: flex; flex-direction: column; }
.account-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 12px;
}

.sidebar__block h2 {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line-soft);
}

/* Elenco fasi: badge su 2 colonne invece della lista verticale precedente
   (vedi PostToolUse/demo approvata) — stato non-raggiunta / attiva (lampeggia)
   / già completata, sullo stesso codice/testo di sempre (data-phase invariato,
   così markPhaseActive()/markPhaseDone() in js/app.js non cambiano logica). */
.activity-badges {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  min-width: 0;
}
.activity-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  height: 30px;
  padding: 0 7px;
  border-radius: 7px;
  font-size: 10px;
  font-weight: 500;
  line-height: 1.15;
  overflow: hidden;
}
.activity-badge-txt {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.activity-badge-dot {
  width: 5px;
  height: 5px;
  flex-shrink: 0;
  border-radius: 50%;
}

.activity-badge.is-idle {
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.4);
  border: 0.5px solid rgba(255, 255, 255, 0.08);
}
.activity-badge.is-idle .activity-badge-dot { background: rgba(255, 255, 255, 0.3); }

.activity-badge.is-active {
  background: rgba(74, 222, 128, 0.12);
  color: #6ee79b;
  border: 0.5px solid rgba(74, 222, 128, 0.4);
  animation: activity-badge-blink 1.3s ease-in-out infinite;
}
.activity-badge.is-active .activity-badge-dot { background: #4ade80; box-shadow: 0 0 6px #4ade80; }

/* Già completata: stesso verde dell'attiva ma fisso (nessun lampeggio) e più
   tenue — distingue "fatta" da "in corso ora", persa altrimenti passando
   direttamente da is-active a is-idle. Approvata nella demo. */
.activity-badge.is-done {
  background: rgba(74, 222, 128, 0.07);
  color: rgba(110, 231, 155, 0.75);
  border: 0.5px solid rgba(74, 222, 128, 0.18);
}
.activity-badge.is-done .activity-badge-dot { background: rgba(74, 222, 128, 0.55); }

@keyframes activity-badge-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}
@media (prefers-reduced-motion: reduce) {
  .activity-badge.is-active { animation: none; }
}

.tipo-badge {
  font-family: var(--font-mono);
  font-size: 12.5px;
  padding: 8px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--ink-700);
  color: var(--paper-dim);
}
.tipo-badge--set {
  border-color: var(--brass-dim);
  background: var(--brass-soft);
  color: var(--brass);
}

.lacune-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12.5px;
  color: var(--paper-dim);
  /* Altezza limitata con scroll verticale proprio: senza, un'analisi con
     molte lacune allunga indefinitamente l'intera sidebar invece di
     restare contenuta nel proprio riquadro. */
  max-height: 260px;
  overflow-y: auto;
}
.lacune-list__empty { color: var(--muted); font-style: italic; }
.lacune-list li:not(.lacune-list__empty) {
  padding-left: 12px;
  /* Custom property invece di sovrascrivere border-left in una regola a
     parte: due selettori a specificità UGUALE (.lacune-list li.xxx contro
     .lacune-list li:not(...)) darebbero la vittoria a chi arriva dopo nel
     file, fragile e già causa di un bug reale in sessione — così invece
     ogni classe di gravità si limita a impostare la variabile letta qui. */
  border-left: 2px solid var(--lacuna-gravita-colore, var(--signal-warn));
}
.lacune-list li.lacune-list__item--alta  { --lacuna-gravita-colore: var(--signal-bad); }
.lacune-list li.lacune-list__item--bassa { --lacuna-gravita-colore: var(--muted); }
.lacune-list__impatto {
  margin-top: 2px;
  font-size: 11px;
  color: var(--muted);
}
.lacune-list__fase {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--brass-dim);
  background: var(--brass-soft);
  border-radius: var(--radius);
  padding: 1px 5px;
  margin-right: 5px;
}

.sidebar__footer { margin-top: auto; }
.release-label {
  margin-top: 6px;
  text-align: center;
  font-size: 11px;
  color: var(--muted);
}

/* ===========================================================
   Pannello token
   =========================================================== */

.token-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.token-panel-header h2 {
  margin: 0;
  padding-bottom: 0;
  border-bottom: none;
}
/* allinea il bordo inferiore alla coppia header+pannello */
.sidebar__block:has(.token-panel-header) h2 {
  border-bottom: 1px solid var(--line-soft);
  padding-bottom: 8px;
  flex: 1;
}

.btn-icon {
  background: none;
  border: 1px solid var(--line-soft);
  color: var(--muted);
  font-size: 13px;
  line-height: 1;
  padding: 3px 6px;
  border-radius: var(--radius);
  cursor: pointer;
  flex-shrink: 0;
}
.btn-icon:hover { border-color: var(--brass-dim); color: var(--brass); }

.token-panel {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.token-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 12px;
  color: var(--paper-dim);
}
.token-row--total {
  margin-top: 4px;
  padding-top: 6px;
  border-top: 1px solid var(--line-soft);
  font-weight: 600;
  color: var(--paper);
}

.token-label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.token-row--total .token-label { color: var(--paper-dim); }

.token-value {
  font-family: var(--font-mono);
  font-size: 11.5px;
  text-align: right;
}

.token-cost {
  margin-top: 8px;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--brass);
  text-align: right;
  letter-spacing: 0.03em;
}

/* chip inline nei messaggi */
.token-chip {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--line-soft);
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--muted);
  letter-spacing: 0.04em;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.token-chip span { white-space: nowrap; }
.token-chip .tc-cost { color: var(--brass-dim); }

/* badge "ricerca web reale" in cima al contenuto di una fase, quando ha usato il grounding */
.grounding-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
  padding: 7px 12px;
  background: rgba(111, 174, 140, 0.14);
  border-left: 3px solid var(--signal-ok);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--paper-dim);
}
.grounding-badge strong { color: var(--signal-ok); }

/* Citazioni in-text "[Autore, Anno, N]" nel report finale — vedi
   evidenziaCitazioniInText() in js/app.js. */
.citazione-intext {
  font-style: italic;
  color: var(--muted);
}

/* ===========================================================
   Modale setup costi
   =========================================================== */

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.modal[aria-hidden="false"] { pointer-events: auto; }

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 32, 0.72);
  opacity: 0;
  transition: opacity 180ms ease;
}
.modal[aria-hidden="false"] .modal__backdrop { opacity: 1; }

.modal__box {
  position: relative;
  background: var(--ink-800);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) * 2);
  width: min(420px, calc(100vw - 40px));
  max-height: calc(100vh - 80px);
  overflow-y: auto;
  transform: translateY(8px);
  opacity: 0;
  transition: transform 180ms ease, opacity 180ms ease;
}
.modal[aria-hidden="false"] .modal__box {
  transform: translateY(0);
  opacity: 1;
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--line-soft);
}
.modal__header h3 {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  color: var(--paper);
}

.modal__body {
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal__note {
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.5;
  margin: 0;
  padding: 10px 12px;
  background: var(--ink-700);
  border-radius: var(--radius);
  border-left: 2px solid var(--line);
}
.modal__note code {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--paper-dim);
}

.setup-presets {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}
.setup-preset-label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-right: 2px;
}

.btn--sm {
  font-size: 11.5px;
  padding: 5px 10px;
}

/* Report item */
.report-item {
  background: var(--ink-900);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
}
.report-item__info {
  flex: 1;
  min-width: 0;
}
.report-item__name {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--paper);
  word-break: break-all;
  margin-bottom: 2px;
  display: block;
  text-decoration: none;
  border-bottom: 1px dotted transparent;
}
.report-item__name:hover {
  color: var(--brass);
  border-bottom-color: var(--brass-dim);
}
.report-item__meta {
  font-size: 10px;
  color: var(--muted);
}
.report-item__meta span { margin-right: 8px; }
.report-item__type {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: var(--brass-soft);
  color: var(--brass);
  padding: 2px 5px;
  border-radius: 2px;
  white-space: nowrap;
}
.report-item__actions {
  display: flex;
  gap: 4px;
}
.report-item__btn {
  background: none;
  border: 1px solid var(--line-soft);
  color: var(--paper-dim);
  font-size: 11px;
  padding: 4px 6px;
  border-radius: var(--radius);
  cursor: pointer;
  flex-shrink: 0;
  transition: all 150ms ease;
}
.report-item__btn:hover {
  border-color: var(--brass-dim);
  color: var(--brass);
}
.report-item__btn.btn-danger:hover {
  border-color: #b85c4a;
  color: #b85c4a;
}

/* Gruppo per utente nella modale "Tutti i report" (admin) */
.all-reports-group__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--brass);
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line-soft);
}

/* ===========================================================
   Pannello azioni disponibili
   =========================================================== */

.actions-panel {
  background: var(--brass-soft);
  border-left: 3px solid var(--brass);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-top: 8px;
  font-size: 13px;
  color: var(--paper);
}

.actions-panel__title {
  font-family: var(--font-mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--brass);
  margin: 0 0 8px;
  font-weight: 600;
}

.actions-panel__list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.actions-panel__item {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.actions-panel__item::before {
  content: '→';
  color: var(--brass-dim);
  flex-shrink: 0;
  margin-top: 1px;
}

.actions-panel__trigger {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  flex: 1;
  min-width: 0;
  background: none;
  border: none;
  margin: -3px -6px;
  padding: 3px 6px;
  border-radius: 4px;
  font: inherit;
  text-align: left;
  color: inherit;
  cursor: pointer;
  transition: background 120ms ease;
}
.actions-panel__trigger:hover,
.actions-panel__trigger:focus-visible {
  background: rgba(0, 0, 0, 0.15);
  outline: none;
}
.actions-panel__trigger:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}
.actions-panel__trigger:disabled:hover { background: none; }

.actions-panel__cmd {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--brass);
  background: rgba(0, 0, 0, 0.2);
  padding: 1px 5px;
  border-radius: 2px;
  white-space: nowrap;
}

.actions-panel__desc {
  color: var(--paper-dim);
  font-size: 12px;
}

.actions-panel__continue {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--brass-dim);
  font-style: italic;
  color: var(--paper-dim);
  font-size: 12px;
}

.setup-fields {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.setup-label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
  color: var(--paper-dim);
  cursor: default;
}
.setup-label em {
  font-style: normal;
  font-size: 11px;
  color: var(--muted);
  margin-left: 4px;
}
.setup-label--valuta { grid-column: 1 / -1; }

.setup-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.setup-input-row input[type="number"],
.setup-label input[type="text"] {
  flex: 1;
  background: var(--ink-900);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--paper);
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 8px 10px;
}
.setup-input-row input[type="number"]:focus,
.setup-label input[type="text"]:focus {
  outline: 2px solid var(--brass);
  outline-offset: 1px;
}
.setup-valuta-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  min-width: 32px;
}

.info-box {
  margin-top: 12px;
  padding: 12px 14px;
  background: var(--brass-soft);
  border-left: 3px solid var(--brass);
  border-radius: var(--radius);
  font-size: 12.5px;
  color: var(--paper-dim);
}
.info-box strong { color: var(--brass); }

.warning-box {
  margin-top: 12px;
  padding: 12px 14px;
  background: rgba(201, 151, 63, 0.12);
  border-left: 3px solid var(--signal-warn);
  border-radius: var(--radius);
  font-size: 12.5px;
  color: var(--paper-dim);
}
.warning-box strong { color: var(--signal-warn); }

.modal__footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px 18px;
  border-top: 1px solid var(--line-soft);
  justify-content: flex-end;
}

/* ===========================================================
   Chat
   =========================================================== */

.chat {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-width: 0;
}

.chat__log {
  flex: 1;
  overflow-y: auto;
  padding: 32px clamp(20px, 5vw, 96px);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.msg {
  max-width: 720px;
  padding: 14px 16px;
  border-radius: var(--radius);
  font-size: 14.5px;
}

.msg p { margin: 0 0 8px; }
.msg p:last-child { margin-bottom: 0; }

.msg--system {
  background: var(--ink-700);
  border: 1px solid var(--line);
  color: var(--paper-dim);
  font-style: italic;
}

.msg--user {
  align-self: flex-end;
  background: var(--brass-soft);
  border: 1px solid var(--brass-dim);
  color: var(--paper);
}

.msg--assistant {
  background: var(--ink-800);
  border: 1px solid var(--line);
}

.msg--assistant .msg__section-title {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--brass);
  margin: 14px 0 6px;
}
.msg--assistant .msg__section-title:first-child { margin-top: 0; }

.msg--assistant a { color: var(--brass); text-decoration: underline; text-decoration-color: var(--brass-dim); }
.msg--assistant a:hover { color: #d9a84d; }

.msg--error {
  background: rgba(184, 92, 74, 0.12);
  border: 1px solid var(--signal-bad);
  color: var(--paper);
}

.msg--rifiuto {
  background: rgba(184, 92, 74, 0.08);
  border-left: 3px solid var(--signal-bad);
  border-top: 1px solid var(--line);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.msg--avviso {
  background: var(--brass-soft);
  border-left: 3px solid var(--signal-warn);
  border-top: 1px solid var(--line);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.msg--thinking {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 12.5px;
  letter-spacing: 0.04em;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.grafo-arco { transition: opacity .15s ease; }

.barra-progresso {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  margin-top: 10px;
  font-family: var(--font-mono);
  font-size: 12px;
}
.barra-progresso__tappa {
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  transition: background .2s ease, border-color .2s ease, color .2s ease;
}
.barra-progresso__tappa.is-done { color: var(--paper-dim); border-color: var(--line-soft); }
.barra-progresso__tappa.is-active {
  color: var(--ink-900);
  background: var(--brass);
  border-color: var(--brass);
  font-weight: 600;
}
.barra-progresso__freccia { color: var(--muted); }

.grafo-legenda {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin-top: 10px;
  font-size: 11px;
  color: var(--muted);
}
.grafo-legenda__voce { display: inline-flex; align-items: center; gap: 5px; }
.grafo-legenda__swatch {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}
.chip {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--paper-dim);
}
.chip--ok   { border-color: var(--signal-ok);   color: var(--signal-ok); }
.chip--warn { border-color: var(--signal-warn); color: var(--signal-warn); }
.chip--none { color: var(--muted); font-style: italic; }

pre.raw-json {
  background: var(--ink-900);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--paper-dim);
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ===========================================================
   Input
   =========================================================== */

.chat__input {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 16px clamp(20px, 5vw, 96px) 22px;
  border-top: 1px solid var(--line);
  background: var(--ink-900);
}

textarea#chatInput {
  flex: 1;
  resize: none;
  background: var(--ink-800);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--paper);
  font-family: var(--font-body);
  font-size: 14px;
  padding: 12px 14px;
  max-height: 160px;
}

textarea#chatInput:focus-visible,
.btn:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
}

.btn {
  font-family: var(--font-body);
  font-size: 13.5px;
  font-weight: 500;
  padding: 12px 18px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
}

.btn--primary {
  background: var(--brass);
  color: var(--ink-900);
}
.btn--primary:hover { background: #d9a84d; }
.btn--primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn--ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--paper-dim);
  width: 100%;
}
.btn--ghost:hover { border-color: var(--muted); color: var(--paper); }

/* Preset prezzi (configurazione.html): evidenzia quello i cui valori
   coincidono con i campi attuali — vedi evidenziaPresetAttivo() in
   js/configurazione.js. */
.setup-presets .btn--ghost.is-active {
  border-color: var(--brass);
  background: var(--brass-soft);
  color: var(--brass);
  font-weight: 600;
}
.setup-presets .btn--ghost.is-active:hover { border-color: var(--brass); color: var(--brass); }

@media (prefers-reduced-motion: no-preference) {
  .msg { animation: rise 220ms ease-out; }
}
@keyframes rise {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===========================================================
   Tabelle dati (attori P08, confronti P14, elenco utenti admin)
   =========================================================== */

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.data-table th {
  text-align: left;
  font-family: var(--font-mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}
table.data-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line-soft);
  color: var(--paper-dim);
  vertical-align: top;
}
table.data-table tr:last-child td { border-bottom: none; }

/* ===========================================================
   Pannello Account (quota utente) — sidebar app principale
   =========================================================== */

.quota-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--ink-900);
  overflow: hidden;
  margin-top: 4px;
}
.quota-bar__fill {
  height: 100%;
  background: var(--signal-ok);
  transition: width 200ms ease;
}
.quota-bar__fill.is-warn { background: var(--signal-warn); }
.quota-bar__fill.is-bad  { background: var(--signal-bad); }

.quota-avviso {
  margin-top: 8px;
  padding: 8px 10px;
  background: rgba(184, 92, 74, 0.1);
  border-left: 2px solid var(--signal-bad);
  border-radius: var(--radius);
  font-size: 11.5px;
  color: var(--paper-dim);
}

/* ===========================================================
   Pagina amministrazione (public/admin.html)
   =========================================================== */

.admin-page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px clamp(16px, 4vw, 40px) 80px;
}

.admin-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.admin-topbar h1 {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  margin: 0;
  color: var(--paper);
}
.admin-topbar .subtitle {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.admin-topbar__actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.admin-panel {
  background: var(--ink-800);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) * 2);
  padding: 22px 24px;
  margin-bottom: 24px;
}
.admin-panel h2 {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 16px;
  color: var(--paper);
}

.admin-form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  align-items: end;
}
.admin-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.admin-field label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}
.admin-field input,
.admin-field select {
  background: var(--ink-900);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--paper);
  font-family: var(--font-body);
  font-size: 13px;
  padding: 8px 10px;
}
.admin-field input::placeholder { color: var(--muted); }

.admin-users-table-wrap { overflow-x: auto; }

.admin-users-table td { white-space: nowrap; }
.admin-users-table td.wrap { white-space: normal; }

/* Dump grezzo di tabella (log_utilizzo / utenti, vedi js/admin.js
   apriDump()): altezza massima con scroll verticale; in larghezza il
   testo si restringe con la finestra (clamp legato al viewport, non
   scelto a scatti) finché non tocca il minimo leggibile, poi la riga
   smette di comprimersi e subentra lo scroll orizzontale del contenitore
   invece di spezzare le celle su più righe. */
.admin-dump-wrap {
  max-height: 60vh;
  overflow-y: auto;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
table.admin-dump-table {
  /* table.data-table (sopra) ha la stessa specificità (elemento+classe):
     serve qui lo stesso "peso" del selettore, non solo .admin-dump-table
     da solo, altrimenti la regola font-size:13px fissa di .data-table
     vince sempre e il clamp() qui sotto non ha mai effetto. */
  font-size: clamp(9px, 1.1vw, 13px);
}
.admin-dump-table th, .admin-dump-table td {
  white-space: nowrap;
}
.admin-dump-table thead th {
  position: sticky;
  top: 0;
  background: var(--ink-800);
  z-index: 1;
}

.admin-quota-cell { min-width: 130px; }
.admin-quota-cell .quota-label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--muted);
}

.admin-badge {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--paper-dim);
}
.admin-badge--admin { border-color: var(--brass-dim); color: var(--brass); background: var(--brass-soft); }
.admin-badge--on  { border-color: #bfe0cd; color: var(--signal-ok); }
.admin-badge--off { border-color: #e3aca6; color: var(--signal-bad); }

.admin-row-actions { display: flex; gap: 4px; flex-wrap: wrap; }
.admin-row-actions button {
  background: none;
  border: 1px solid var(--line-soft);
  color: var(--paper-dim);
  font-size: 10.5px;
  padding: 4px 7px;
  border-radius: var(--radius);
  cursor: pointer;
  white-space: nowrap;
}
.admin-row-actions button:hover { border-color: var(--brass-dim); color: var(--brass); }
.admin-row-actions button.is-danger:hover { border-color: var(--signal-bad); color: var(--signal-bad); }

.admin-empty {
  text-align: center;
  color: var(--muted);
  font-style: italic;
  padding: 30px 0;
}

.admin-note {
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 16px;
}

@media (prefers-reduced-motion: reduce) {
  .msg { animation: none; }
}

/* ===========================================================
   Schede in basso mobile (Percorso/Lacune/Token/Account/Altro)
   In fondo al foglio di stile deliberatamente: alcune regole qui sotto
   (es. .chat) hanno la stessa specificità di regole già definite sopra
   (es. .chat { height:100vh } nella sezione "Chat") — a parità di
   specificità vince l'ultima dichiarata nel sorgente, non la più
   "importante" concettualmente, quindi il media query da solo non
   basterebbe se fosse posizionato più in alto.
   =========================================================== */

.sidebar__panels, .mobile-panel { display: contents; }
.tabbar, .mobile-sheet-backdrop { display: none; }

@media (max-width: 780px) {
  :root { --tabbar-h: 60px; }

  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr var(--tabbar-h); }

  /* Posizionamento esplicito delle 3 righe: necessario perché
     .mobile-sheet-backdrop (position:fixed, escluso dall'auto-placement)
     altererebbe altrimenti l'ordine "sidebar, chat, tabbar" dedotto dal DOM. */
  .sidebar { grid-row: 1; }
  main.chat { grid-row: 2; }
  .tabbar { grid-row: 3; }
  /* Ridimensionamento della sidebar: solo desktop, dove sta accanto al
     contenuto in una griglia a colonne. Su mobile la sidebar è un foglio a
     comparsa a piena larghezza — la maniglia non avrebbe senso ed è comunque
     esclusa dall'auto-placement delle 3 righe qui sopra. */
  .sidebar-resize-handle { display: none; }

  /* .chat ha height:100vh per il layout desktop (colonna unica accanto alla
     sidebar): su mobile è una riga della griglia, non l'intera viewport —
     altrimenti trabocca sotto la tabbar. */
  .chat { height: 100%; min-height: 0; }

  /* La sidebar, su mobile, mostra solo l'header (logo + titolo): il resto
     del contenuto vive in .sidebar__panels, sollevato a foglio a comparsa. */
  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--line-soft);
    padding: 14px 16px;
    overflow: visible;
    gap: 0;
  }

  .sidebar__panels {
    display: flex;
    flex-direction: column;
    gap: 20px;
    position: fixed;
    left: 0;
    right: 0;
    bottom: var(--tabbar-h);
    max-height: 68vh;
    overflow-y: auto;
    background: var(--ink-800);
    border-top: 1px solid var(--line);
    border-radius: 16px 16px 0 0;
    padding: 18px 20px;
    box-shadow: 0 -16px 30px -16px rgba(0, 0, 0, 0.55);
    transform: translateY(12px);
    opacity: 0;
    visibility: hidden;
    transition: transform 200ms ease, opacity 200ms ease, visibility 200ms;
    z-index: 40;
  }
  .sidebar__panels.is-open { transform: translateY(0); opacity: 1; visibility: visible; }

  .mobile-panel { display: none; flex-direction: column; gap: 20px; }
  .mobile-panel.is-active-panel { display: flex; }

  .mobile-sheet-backdrop {
    display: block;
    position: fixed;
    left: 0; right: 0; top: 0; bottom: var(--tabbar-h);
    background: rgba(9, 13, 18, 0.55);
    opacity: 0;
    pointer-events: none;
    transition: opacity 200ms ease;
    z-index: 39;
  }
  .mobile-sheet-backdrop.is-open { opacity: 1; pointer-events: auto; }

  .tabbar {
    display: flex;
    align-items: stretch;
    border-top: 1px solid var(--line-soft);
    background: var(--ink-800);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    z-index: 41; /* sopra il foglio: resta sempre toccabile */
  }
  .tabbar__btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    background: none;
    border: none;
    color: var(--muted);
    font-family: var(--font-body);
    font-size: 10.5px;
    padding: 8px 4px;
    cursor: pointer;
    position: relative;
  }
  .tabbar__ico { font-size: 15px; line-height: 1; }
  .tabbar__btn.is-active { color: var(--brass); }
  .tabbar__badge {
    position: absolute;
    top: 4px;
    right: 22%;
    background: var(--signal-warn);
    color: var(--ink-900);
    font-family: var(--font-mono);
    font-size: 9px;
    font-weight: 700;
    border-radius: 999px;
    min-width: 14px;
    height: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 3px;
  }
}
