/* ============================================================================
   LocalMind — interfaccia applicazione
   ----------------------------------------------------------------------------
   Colori, tipografia, raggi, focus e movimento vengono da ../tokens.css.
   In questo foglio non esiste nessun valore esadecimale: se serve un colore
   che i token non coprono, si aggiunge un token là.

   Sfondo sabbia · sidebar grafite a tutta altezza · accento corallo ·
   tipografia Archivo · nessuna ombra: la separazione è un bordo da 1px.
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; height: 100%; }
body {
  height: 100%;
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.45;
  color: var(--graphite);
  background: var(--sand);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-weight: 700;
  letter-spacing: var(--ls-heading);
  line-height: 1.2;
}

.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea, select { font-family: inherit; color: inherit; }
a { color: inherit; }

/* Le icone dell'interfaccia sono SVG, non emoji: ereditano il colore del
   testo, hanno lo stesso peso di tratto ovunque e si vedono uguali su ogni
   sistema. Dentro un contenitore flex si allineano da sole; in mezzo al testo
   corrente vanno abbassate sulla riga di base. */
.ico { display: inline-block; vertical-align: -0.16em; flex-shrink: 0; }

/* Il marchio non si ruota, non riceve ombre e non cambia spessore d'anello
   (assets/brand/README.md). L'area di rispetto — metà del suo diametro per
   lato — è lo `gap` delle righe che lo contengono. */
.aegis { display: block; flex-shrink: 0; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--ash-strong); border-radius: var(--r-panel);
  border: 3px solid transparent; background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--stone); background-clip: padding-box; }
.on-graphite ::-webkit-scrollbar-thumb { background: var(--graphite-up); background-clip: padding-box; }

/* ============================================================================
   Bottoni condivisi
   ----------------------------------------------------------------------------
   Il corallo è un colore da RIEMPIMENTO: sta dietro al testo bianco, mai
   sotto forma di testo su fondo chiaro (su bianco fa ~3,2:1 e non passa).
   Il testo corallo esiste solo come `--accent-text`, che è corallo-inchiostro.
   ========================================================================== */
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  width: 100%; padding: 9px 16px; border-radius: var(--r-control);
  background: var(--coral);
  color: var(--graphite); font-weight: 600; font-size: .9rem;
  transition: background var(--t);
}
.btn-primary:hover { background: var(--coral-press); color: var(--surface); }
.btn-inline { width: auto; padding: 7px 13px; font-size: .85rem; }

.btn-soft {
  padding: 7px 13px; border-radius: var(--r-control);
  background: var(--surface); border: 1px solid var(--ash);
  color: var(--graphite); font-weight: 500; font-size: .85rem;
  transition: background var(--t), border-color var(--t);
}
.btn-soft:hover { background: var(--sand); border-color: var(--ash-strong); }

.btn-ghost {
  width: 100%; padding: 9px 16px; border-radius: var(--r-control);
  background: transparent; border: 1px solid var(--ash-strong);
  color: var(--graphite); font-weight: 500; font-size: .88rem;
  transition: background var(--t), border-color var(--t);
}
.btn-ghost:hover { background: var(--sand); }

/* Le azioni distruttive non hanno un rosso proprio: l'unico rosso in
   tavolozza è il corallo del marchio, e usarlo qui renderebbe "elimina" e
   "invia" lo stesso colore. Sono testo corallo-inchiostro su bordo neutro. */
.btn-danger {
  width: 100%; padding: 9px 16px; border-radius: var(--r-control);
  background: transparent; border: 1px solid var(--ash-strong);
  color: var(--accent-text); font-weight: 600; font-size: .88rem;
  transition: background var(--t), border-color var(--t);
}
.btn-danger:hover { background: var(--coral-soft); border-color: var(--coral); }

.icon-btn {
  width: 30px; height: 30px; border-radius: var(--r-nav); flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--stone);
  transition: background var(--t), color var(--t);
}
.icon-btn:hover { background: var(--sand-sunk); color: var(--graphite); }

.mini-add {
  width: 24px; height: 24px; border-radius: var(--r-nav); line-height: 1; font-size: 1rem;
  background: transparent; border: 1px solid var(--ash);
  color: var(--stone);
  display: inline-flex; align-items: center; justify-content: center;
  transition: background var(--t), color var(--t), border-color var(--t);
}
.mini-add:hover { background: var(--coral-soft); color: var(--accent-text); border-color: var(--coral); }

.chip-btn {
  background: var(--surface); border: 1px solid var(--ash); color: var(--graphite);
  border-radius: var(--r-control); padding: 5px 11px; font-size: .8rem; white-space: nowrap;
  transition: border-color var(--t), background var(--t);
}
.chip-btn:hover { border-color: var(--ash-strong); background: var(--sand); }
.chip-btn.chip-danger { color: var(--accent-text); }
.chip-btn.chip-danger:hover { border-color: var(--coral); background: var(--coral-soft); }

.kbd {
  font-size: .72rem; color: var(--stone);
  border: 1px solid var(--ash); border-radius: var(--r-nav);
  padding: 2px 6px; background: var(--sand);
}

/* ============================================================================
   Login
   ========================================================================== */
#login-view {
  display: flex; align-items: center; justify-content: center;
  height: 100vh; padding: 24px;
}
.login-box {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--ash);
  border-radius: var(--r-panel);
  padding: 32px 30px;
}
/* Area di rispetto del marchio: `gap` pari a metà del diametro (40px → 20px).
   Il marchio è anche il ritorno alla pagina iniziale: da qui non si esce in
   nessun altro modo, e un link sul marchio è dove lo si cerca per primo. */
.login-brand {
  display: inline-flex; align-items: center; gap: 20px;
  margin-bottom: 14px;
  text-decoration: none;
  color: var(--graphite);
  border-radius: var(--r-nav);
}
.login-brand:hover h1 { color: var(--accent-text); }
.brand-mark { display: inline-flex; flex-shrink: 0; }
.login-box h1 { font-size: 1.7rem; }
.login-box .subtitle { color: var(--stone); font-size: .9rem; margin-bottom: 22px; }

.field-label { display: block; font-size: .82rem; font-weight: 600; color: var(--graphite); margin-bottom: 5px; }
.login-box input {
  display: block; width: 100%;
  padding: 9px 12px; border-radius: var(--r-control);
  border: 1px solid var(--ash-strong);
  background: var(--surface);
  font-size: .94rem; margin-bottom: 14px; outline: none;
  transition: border-color var(--t);
}
.login-box input:focus { border-color: var(--coral); }
.login-box .btn-primary { margin-bottom: 8px; }

/* Un esito non riuscito non è rosso — vedi `.btn-danger`. */
.error {
  color: var(--graphite); font-size: .86rem;
  padding: 9px 12px; background: var(--coral-soft);
  border-radius: var(--r-control); margin-top: 12px;
}
.error.success { color: var(--graphite); background: var(--success-soft); }

/* ============================================================================
   Contenitore principale
   ----------------------------------------------------------------------------
   Niente scheda che galleggia: la shell riempie la finestra e la sidebar
   grafite arriva in alto e in basso.
   ========================================================================== */
#main-view { height: 100vh; padding: 0; }
.app-shell {
  height: 100%; width: 100%;
  display: flex; overflow: hidden;
  background: var(--surface);
  position: relative;
}

/* ░░ Sidebar ░░ */
.sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  background: var(--graphite);
  color: var(--sidebar-text);
  display: flex; flex-direction: column;
  transition: margin-left var(--t);
}
.sidebar.collapsed { margin-left: calc(-1 * var(--sidebar-w)); pointer-events: none; }

/* Area di rispetto del marchio: metà del diametro (22px → 11px). */
.sidebar-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 12px 10px;
}
.brand-row { display: flex; align-items: center; gap: 11px; min-width: 0; }
.app-name { font-size: 1.05rem; color: var(--surface); }
.sidebar .icon-btn { color: var(--sidebar-muted); }
.sidebar .icon-btn:hover { background: var(--graphite-up); color: var(--surface); }

.new-chat-btn {
  margin: 0 12px 10px; padding: 8px 12px;
  display: flex; align-items: center; gap: 8px;
  background: var(--coral);
  color: var(--graphite); border-radius: var(--r-control);
  font-size: .9rem; font-weight: 600;
  transition: background var(--t);
}
.new-chat-btn:hover { background: var(--coral-press); color: var(--surface); }

.search-row {
  margin: 0 12px 10px; display: flex; align-items: center; gap: 8px;
  background: var(--graphite-up); border: 1px solid transparent;
  border-radius: var(--r-control); padding: 6px 10px;
  transition: border-color var(--t);
}
.search-row:focus-within { border-color: var(--coral); }
.search-ico { color: var(--sidebar-muted); flex-shrink: 0; }
.search-row input {
  flex: 1; min-width: 0; background: transparent; border: none; outline: none;
  font-size: .87rem; color: var(--surface);
}
.search-row input::placeholder { color: var(--sidebar-muted); }

.sidebar-scroll { flex: 1; overflow-y: auto; padding: 0 8px 10px; }

.nav-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 6px 4px;
}
/* Sentence case: le etichette maiuscole spaziate erano uno dei tell. */
.nav-head h3 {
  font-size: .78rem; color: var(--stone);
  font-weight: 600; letter-spacing: 0;
}
.sidebar .nav-head h3 { color: var(--sidebar-muted); }

.nav-list { display: flex; flex-direction: column; }
/* Il contenitore porta sfondo e raggio; dentro ci sono due <button> veri —
   la voce e il cestino — così tutto arriva da tastiera. */
.nav-item {
  display: flex; align-items: center;
  border-radius: var(--r-nav);
  color: var(--graphite);
  transition: background var(--t);
}
.ni-main {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 8px;
  padding: 5px 8px; border-radius: var(--r-nav);
  font-size: .875rem; line-height: 1.35; text-align: left;
  background: none; border: none; color: inherit; font-family: inherit;
}
.nav-item:hover { background: var(--sand-sunk); }
.nav-item.active { background: var(--sand-sunk); }
.nav-item.active .ni-main { font-weight: 600; }
.nav-item .ni-ico { flex-shrink: 0; display: inline-flex; color: var(--stone); }
.nav-item .ni-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .ni-meta { font-size: .78rem; color: var(--stone); flex-shrink: 0; }
.nav-item .ni-del {
  opacity: 0; color: var(--stone); font-size: 1rem; line-height: 1;
  width: 20px; height: 20px; border-radius: var(--r-nav); flex-shrink: 0; margin-right: 4px;
  display: inline-flex; align-items: center; justify-content: center;
  transition: opacity var(--t), color var(--t), background var(--t);
}
.nav-item:hover .ni-del, .nav-item .ni-del:focus-visible { opacity: 1; }
.nav-item .ni-del:hover { color: var(--accent-text); background: var(--coral-soft); }
.nav-item.set-active { background: var(--success-soft); color: var(--green); }
.nav-item.set-active .ni-main { font-weight: 600; }
.nav-item.set-active .ni-ico { color: var(--green); }

/* Le stesse voci sulla sidebar grafite. L'elemento attivo è grafite-rialzato,
   raggio 6px; i conteggi sono verdi, e diventano corallo quando chiedono
   attenzione (per esempio la posta non letta). */
.sidebar .nav-item { color: var(--sidebar-text); }
.sidebar .nav-item:hover { background: var(--graphite-up); }
.sidebar .nav-item.active { background: var(--graphite-up); color: var(--surface); }
.sidebar .nav-item .ni-main { color: inherit; }
.sidebar .nav-item .ni-ico,
.sidebar .nav-item .ni-meta,
.sidebar .nav-item .ni-del { color: var(--sidebar-muted); }
.sidebar .nav-item .ni-del:hover { color: var(--coral); background: transparent; }

.muted-empty { font-size: .85rem; color: var(--stone); padding: 6px 8px; display: block; }
.sidebar .muted-empty { color: var(--sidebar-muted); }

/* piede sidebar */
.sidebar-foot { padding: 8px; border-top: 1px solid var(--graphite-line); }
.foot-btn {
  width: 100%; display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: var(--r-nav);
  background: transparent; border: none;
  color: var(--sidebar-text); font-size: .875rem; font-weight: 500;
  transition: background var(--t);
}
.foot-btn:hover { background: var(--graphite-up); }
.foot-btn svg { color: var(--sidebar-muted); flex-shrink: 0; }
.foot-btn span:not(.foot-count):not(.foot-badge):not(.conn-led) { flex: 1; text-align: left; }
.foot-count, .foot-badge {
  color: var(--green-on-dark); font-size: .78rem; font-weight: 600;
  flex-shrink: 0; font-variant-numeric: tabular-nums;
}
/* Un conteggio che chiede attenzione — posta non letta, notifiche — è corallo. */
.foot-count.attention, .foot-badge.attention { color: var(--coral); }

.user-row {
  display: flex; align-items: center; gap: 8px;
  margin-top: 6px; padding: 6px 6px 2px;
  border-top: 1px solid var(--graphite-line);
}
.avatar {
  width: 26px; height: 26px; border-radius: var(--r-nav); flex-shrink: 0;
  background: var(--coral);
  color: var(--graphite); font-weight: 700; font-size: .78rem;
  display: inline-flex; align-items: center; justify-content: center;
}
.user-block-text { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.2; }
.user-name { font-size: .87rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar .user-name { color: var(--surface); }
.user-sub { font-size: .74rem; color: var(--stone); }
.sidebar .user-sub { color: var(--sidebar-muted); }

/* ============================================================================
   Area chat
   ========================================================================== */
#chat-area { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; background: var(--shell); }

#chat-topbar {
  height: 46px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; border-bottom: 1px solid var(--ash);
}
.topbar-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.conv-title { font-weight: 600; font-size: .95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.set-badge {
  font-size: .76rem; color: var(--graphite); background: var(--success-soft);
  border: 1px solid var(--ash); border-radius: var(--r-control); padding: 2px 8px; flex-shrink: 0;
}

/* La chat è da leggere, non da scandagliare: una colonna sola, misura di
   lettura fissa a 72 caratteri, interlinea generosa. La densità alta vale
   per la dashboard, non qui. */
.messages {
  flex: 1; overflow-y: auto;
  padding: 24px clamp(16px, 4vw, 40px) 8px;
  display: flex; flex-direction: column; align-items: center; gap: 22px;
  scroll-behavior: smooth;
}
.messages > * { width: 100%; max-width: var(--measure); }

/* ── stato vuoto ──
   Non un'icona centrata con "Come posso aiutarti?", che non dice niente: un
   invito ad agire che nomina quello che l'assistente sa fare davvero con i
   documenti e con la posta. Allineato a sinistra, come il testo che seguirà. */
.empty-state {
  margin: auto 0; text-align: left;
  display: flex; flex-direction: column; align-items: stretch;
}
.empty-state h2 { font-size: 1.5rem; margin-bottom: 8px; }
.empty-state p { color: var(--stone); font-size: .95rem; margin-bottom: 22px; max-width: 58ch; }
.empty-input-slot { width: 100%; }

/* ── ingresso alla modalità conversazione ──
   Al posto del testo d'apertura: un solo bersaglio tondo, corallo pieno con
   l'onda bianca dentro (il corallo è un colore da riempimento). Nessuna ombra,
   nessun ingrandimento in hover: cambia solo il riempimento, perché il bottone
   non cambia stato finché non lo si preme. */
.empty-voice {
  display: flex; align-items: center; gap: 14px;
  margin-bottom: 22px;
}
.voice-orb {
  /* Misure dell'onda: le barre e l'altezza massima cambiano con la sfera,
     il disegno no — un solo componente per il cerchietto della schermata
     iniziale e per la sfera grande della conversazione. */
  --wave-bar: 4px;
  --wave-gap: 3px;
  --wave-height: 30px;
  width: 76px; height: 76px; border-radius: 50%;
  display: grid; place-items: center; flex-shrink: 0;
  background: var(--coral); color: var(--surface);
  transition: background var(--t);
}

/* ── L'onda dentro il cerchio ──
   Sette barre bianche sul corallo, al posto dell'icona del microfono ferma.
   A riposo sono una fila di punti; quando c'è voce le altezze seguono
   l'audio vero, scritte da `voiceWave` in app.js una barra alla volta.
   Solo `transform`: nessun riflusso a 60 fotogrammi al secondo. */
.voice-wave {
  display: flex; align-items: center; justify-content: center;
  gap: var(--wave-gap); height: var(--wave-height);
  pointer-events: none;
}
.voice-wave i {
  display: block; width: var(--wave-bar); height: 100%;
  border-radius: 999px; background: currentColor;
  transform: scaleY(.18); transform-origin: center;
}
.voice-orb:hover { background: var(--coral-press); }
.voice-orb:focus-visible {
  outline: var(--focus-width) solid var(--focus-ring);
  outline-offset: var(--focus-offset);
}
.voice-orb-label { font-size: 1.05rem; font-weight: 600; letter-spacing: var(--ls-heading); }

/* ── superficie della modalità conversazione ── */
.voice-stage {
  position: relative;
  width: min(440px, 100%);
  background: var(--shell); border-radius: var(--r-panel);
  padding: 44px 32px 36px;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  text-align: center;
  animation: pop-in 180ms var(--ease);
}
.voice-close {
  position: absolute; top: 12px; right: 12px;
  width: 32px; height: 32px; border-radius: var(--r-control);
  display: grid; place-items: center; color: var(--stone);
  transition: background var(--t), color var(--t);
}
.voice-close:hover { background: var(--surface-2); color: var(--text); }
.voice-close:focus-visible {
  outline: var(--focus-width) solid var(--focus-ring);
  outline-offset: var(--focus-offset);
}
.voice-orb-lg {
  width: 132px; height: 132px;
  --wave-bar: 6px; --wave-gap: 6px; --wave-height: 54px;
}

/* Lo stato della conversazione si legge dalla sfera prima che dal testo.
   L'anello è l'unico movimento della schermata e c'è solo mentre qualcosa
   sta davvero succedendo: in ascolto pulsa piano, mentre pensa gira, mentre
   parla respira. Fermo vuol dire fermo. */
/* L'anello è un pseudo-elemento con un bordo, non un'ombra: in questo
   prodotto `box-shadow` non esiste, e un anello che si espande e svanisce
   dice la stessa cosa restando dentro la regola. */
.voice-orb-lg { position: relative; }
.voice-orb-lg::after {
  content: ""; position: absolute; inset: -12px; border-radius: 50%;
  border: 2px solid var(--coral); opacity: 0; pointer-events: none;
}
.voice-orb-lg.is-listening::after { animation: voice-ring 2s var(--ease) infinite; }
.voice-orb-lg.is-thinking::after { animation: voice-ring 900ms var(--ease) infinite; }
/* Mentre parla non c'è più il respiro del cerchio: l'onda dentro si muove
   già con la voce, e due movimenti sovrapposti sono rumore. */
@keyframes voice-ring {
  0%   { opacity: .55; transform: scale(.92); }
  100% { opacity: 0;   transform: scale(1.14); }
}

/* Il cerchietto della schermata iniziale non ha audio da seguire: l'onda
   cammina piano da sola, perché si veda che quel bottone è la voce e non
   un'altra icona tonda. */
.empty-voice .voice-wave i { animation: voice-wave-idle 1.9s var(--ease) infinite; }
.empty-voice .voice-wave i:nth-child(1) { animation-delay: -1.55s; }
.empty-voice .voice-wave i:nth-child(2) { animation-delay: -1.25s; }
.empty-voice .voice-wave i:nth-child(3) { animation-delay: -.95s; }
.empty-voice .voice-wave i:nth-child(4) { animation-delay: -.65s; }
.empty-voice .voice-wave i:nth-child(5) { animation-delay: -.95s; }
.empty-voice .voice-wave i:nth-child(6) { animation-delay: -1.25s; }
.empty-voice .voice-wave i:nth-child(7) { animation-delay: -1.55s; }
@keyframes voice-wave-idle {
  0%, 100% { transform: scaleY(.2); }
  50%      { transform: scaleY(.85); }
}

@media (prefers-reduced-motion: reduce) {
  .voice-orb-lg.is-listening::after,
  .voice-orb-lg.is-thinking::after,
  .empty-voice .voice-wave i { animation: none; }
}

.voice-state { font-size: 1.1rem; font-weight: 600; letter-spacing: var(--ls-heading); }
.voice-hint { color: var(--text-muted); font-size: .9rem; max-width: 34ch; }

/* La trascrizione: quello che ha detto l'utente e quello che sta rispondendo
   LocalMind. Resta a schermo perché a voce non si può rileggere, e perché la
   stessa trascrizione finisce nella chat scritta. */
.voice-transcript {
  width: 100%; max-height: 190px; overflow-y: auto;
  margin-top: 6px; padding-top: 14px; border-top: 1px solid var(--ash);
  text-align: left; font-size: .93rem; display: flex; flex-direction: column; gap: 10px;
}
.voice-transcript:empty { display: none; }
.voice-line { display: flex; gap: 8px; }
.voice-line .who {
  flex-shrink: 0; width: 52px; color: var(--stone);
  font-size: .76rem; font-weight: 600; padding-top: 2px;
}
.voice-line.voice-line-user .what { color: var(--stone); }

.voice-sources {
  width: 100%; text-align: left; font-size: .8rem; color: var(--stone);
  border-top: 1px solid var(--ash); padding-top: 10px;
}
.voice-sources ul { list-style: none; margin-top: 4px; }
.voice-sources li { padding: 1px 0; }

.voice-foot {
  width: 100%; display: flex; justify-content: space-between; gap: 10px;
  border-top: 1px solid var(--ash); padding-top: 10px;
  font-size: .74rem; color: var(--stone);
}
.voice-latency { font-variant-numeric: tabular-nums; font-weight: 600; }

.suggest-list { list-style: none; margin-top: 18px; border-top: 1px solid var(--ash); }
.suggest-list li {
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
  padding: 7px 0; border-bottom: 1px solid var(--ash);
}
.suggest-list li > span { font-size: .84rem; color: var(--stone); }
.suggest-chip {
  background: none; border: none; padding: 0;
  color: var(--accent-text); font-size: .9rem; font-weight: 500; text-align: left;
  border-bottom: 1px solid transparent;
  transition: border-color var(--t);
}
.suggest-chip:hover { border-bottom-color: var(--coral); }

/* ── messaggio utente ── */
.block { animation: rise-in 200ms var(--ease); }
.user-block { display: flex; justify-content: flex-end; }
/* La bolla resta SOLO sui messaggi dell'utente: serve a distinguerli dal
   testo dell'assistente, che è testo semplice sul fondo. */
/* La colonna tiene insieme bolla e chip dell'allegato, entrambi allineati a
   destra: il file resta visibile accanto alla domanda a cui si riferisce. */
.user-block-stack {
  display: flex; flex-direction: column; align-items: flex-end;
  gap: 6px; max-width: 82%; min-width: 0;
}
.user-bubble {
  max-width: 100%;
  background: var(--sand-sunk);
  color: var(--graphite);
  padding: 9px 14px; border-radius: var(--r-panel) var(--r-panel) var(--r-nav) var(--r-panel);
  font-size: .97rem; line-height: 1.6; white-space: pre-wrap; word-break: break-word;
}

.user-attachment {
  display: flex; align-items: center; gap: 9px; max-width: 100%;
  padding: 6px 11px 6px 7px;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--r-panel);
}
.user-attachment-thumb {
  width: 28px; height: 28px; border-radius: var(--r-nav); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; color: var(--stone);
  background: var(--sand-sunk); overflow: hidden;
}
.user-attachment-thumb img { width: 100%; height: 100%; object-fit: cover; }
.user-attachment-meta { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.user-attachment-name {
  font-size: .82rem; color: var(--text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.user-attachment-size { font-size: .72rem; color: var(--text-faint); }

/* ── risposta AI (nessuna bubble) ── */
.ai-block { background: transparent; }
.ai-head {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-bottom: 8px;
}
/* Sotto i 32 px il marchio è `aegis-solid` — vedi brand.js, che sceglie da sé. */
.ai-avatar {
  flex-shrink: 0; display: inline-flex;
}
.ai-title { font-weight: 600; font-size: .9rem; }
.ai-model, .ai-timing, .ai-tokrate { font-size: .76rem; color: var(--text-faint); }
.ai-confidence { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: .76rem; color: var(--text-muted); }
.conf-bar { width: 64px; height: 6px; border-radius: var(--r-nav); background: var(--surface-3); overflow: hidden; }
.conf-fill { height: 100%; border-radius: var(--r-nav); background: var(--coral); transition: width 500ms var(--ease); }
.ai-collapse {
  width: 28px; height: 28px; border-radius: var(--r-control); color: var(--text-faint); font-size: .9rem;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background var(--t), color var(--t);
}
.ai-collapse:hover { background: var(--surface-2); color: var(--text); }

.ai-body { padding-left: 26px; }
.ai-block.collapsed .ai-body { display: none; }

.ai-answer { font-size: 1rem; line-height: 1.75; color: var(--graphite); white-space: pre-wrap; word-break: break-word; }
.ai-answer .citation {
  color: var(--graphite); background: var(--coral-soft);
  border-radius: var(--r-nav); padding: 1px 5px; font-weight: 500; font-size: .88em; white-space: nowrap;
}
.ai-cursor::after {
  content: "▋"; color: var(--coral); margin-left: 1px;
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ── card secondarie dentro la risposta ── */
.ai-sources, .ai-excel-block, .ai-vision-block, .ai-document-block,
.ai-websearch-block, .ai-attachment-block {
  margin-top: 14px; padding: 12px 14px;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r-panel);
}
.ai-excel-head, .ai-vision-head, .ai-websearch-head {
  font-size: .78rem;
  color: var(--text-faint); font-weight: 700; margin-bottom: 9px;
}

.ai-sources-title {
  display: flex; align-items: center; gap: 7px; width: 100%; text-align: left;
  font-size: .78rem; font-weight: 700;
  color: var(--text-faint); font-family: inherit;
  transition: color var(--t);
}
.ai-sources-title:hover { color: var(--text-soft); }
.ai-sources-caret { display: inline-block; transition: transform var(--t); font-size: .8rem; }
.ai-sources:not(.collapsed) .ai-sources-caret { transform: rotate(90deg); }
.ai-sources.collapsed .source-chips { display: none; }
.source-chips { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.source-chip {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--r-control); padding: 8px 12px; font-size: .82rem; color: var(--text-soft);
  cursor: pointer; transition: border-color var(--t), color var(--t);
}
.source-chip:hover { border-color: var(--accent-text); color: var(--accent-text); }
.source-chip .sc-label {
  display: flex; align-items: center; gap: 7px; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.source-chip .sc-score { color: var(--accent-text); font-weight: 600; font-size: .78rem; flex-shrink: 0; }
.source-chip-copy {
  flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: var(--r-nav); font-size: .85rem; line-height: 1;
  color: var(--text-faint); background: transparent;
  transition: background var(--t), color var(--t);
}
.source-chip-copy:hover { background: var(--accent-soft); color: var(--accent-text); }

.ai-excel-block.ai-excel-error, .ai-vision-block.ai-vision-error,
.ai-document-block.ai-document-error, .ai-websearch-block.ai-websearch-error {
  background: var(--error-soft); border-color: var(--ash); color: var(--error); font-size: .9rem;
}
.ai-excel-code-toggle { font-size: .8rem; color: var(--accent-text); margin-bottom: 8px; display: block; font-weight: 500; }
.ai-excel-code {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-control);
  padding: 11px 13px; font-size: .82rem; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  overflow-x: auto; white-space: pre; margin-bottom: 10px; color: var(--text-soft);
}
.ai-excel-code.hidden { display: none; }
.ai-excel-table { font-size: .9rem; color: var(--text-soft); overflow-x: auto; }
.ai-excel-table pre { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .82rem; white-space: pre; }

.ai-vision-thumb {
  display: block; max-width: 220px; max-height: 220px; border-radius: var(--r-control);
  border: 1px solid var(--border); margin-bottom: 10px; object-fit: contain; background: var(--surface);
}
.ai-vision-answer { font-size: .93rem; color: var(--text-soft); }

.ai-document-block { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.ai-document-head { font-size: .93rem; color: var(--text-soft); flex: 1; min-width: 0; }
.ai-document-download-btn, .ai-attachment-save-btn {
  background: var(--coral); color: var(--surface);
  border-radius: var(--r-control); padding: 8px 16px; font-size: .85rem; font-weight: 600;
  transition: filter var(--t), opacity var(--t);
}
.ai-document-download-btn:hover:not(:disabled),
.ai-attachment-save-btn:hover:not(:disabled) { filter: brightness(1.07); }
.ai-document-download-btn:disabled, .ai-attachment-save-btn:disabled { opacity: .6; cursor: default; }

.ai-websearch-empty { font-size: .9rem; color: var(--text-soft); }
.ai-websearch-items { display: flex; flex-direction: column; gap: 8px; }
.ai-websearch-item {
  display: block; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-control); padding: 10px 13px; text-decoration: none;
  transition: border-color var(--t);
}
.ai-websearch-item:hover { border-color: var(--accent-text); }
.ai-websearch-item-title { font-size: .9rem; color: var(--text); font-weight: 600; }
.ai-websearch-item-url { font-size: .77rem; color: var(--text-faint); margin-top: 2px; word-break: break-all; }

.ai-attachment-block { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.ai-attachment-head { font-size: .9rem; color: var(--text-soft); display: flex; align-items: center; gap: 9px; flex-wrap: wrap; flex: 1; }
.ai-attachment-tag {
  font-size: .72rem; color: var(--text-faint);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-control); padding: 3px 10px;
}

/* ── stato "sto pensando" ── */
.thinking-line { display: flex; align-items: center; gap: 11px; color: var(--text-muted); font-size: .93rem; margin-bottom: 16px; }
.thinking-tag { font-size: .78rem; color: var(--text-faint); }
.orbit {
  width: 20px; height: 20px; border-radius: 50%; flex-shrink: 0;
  border: 2.5px solid var(--surface-3); border-top-color: var(--accent-text);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton {
  height: 14px; border-radius: var(--r-control); margin-bottom: 10px;
  background: linear-gradient(90deg, var(--sand) 25%, var(--ash) 50%, var(--sand) 75%);
  background-size: 200% 100%; animation: shimmer 1.3s infinite;
}
.skeleton.w-90 { width: 90%; } .skeleton.w-75 { width: 75%; } .skeleton.w-60 { width: 60%; } .skeleton.w-40 { width: 40%; }
@keyframes shimmer { to { background-position: -200% 0; } }

.error-block {
  background: var(--error-soft); border: 1px solid var(--ash);
  border-radius: var(--r-panel); padding: 14px 17px; color: var(--error); font-size: .93rem;
}

/* ============================================================================
   Barra di input
   ========================================================================== */
.input-dock { padding: 8px clamp(16px, 4vw, 40px) 14px; flex-shrink: 0; }
.input-dock.centered { padding: 0; width: 100%; }
.input-shell {
  max-width: var(--measure); margin: 0 auto;
  background: var(--surface); border: 1px solid var(--ash-strong);
  border-radius: var(--r-panel); padding: 6px;
  transition: border-color var(--t);
}
.input-shell:focus-within { border-color: var(--coral); }
.input-dock.drag-over .input-shell { border-color: var(--coral); }

.input-main { display: flex; align-items: flex-end; gap: 8px; padding: 2px 4px 2px 6px; }
#chat-input {
  flex: 1; background: transparent; border: none; outline: none;
  font-size: 1rem; line-height: 1.55; color: var(--graphite);
  resize: none; min-height: 34px; max-height: 200px; overflow-y: auto; padding: 6px 4px;
}
#chat-input::placeholder { color: var(--text-faint); }

.attach-trigger, .mic-trigger {
  width: 42px; height: 42px; flex-shrink: 0; border-radius: var(--r-nav);
  background: transparent; color: var(--text-muted);
  display: inline-flex; align-items: center; justify-content: center;
  transition: background var(--t), color var(--t); position: relative;
}
.attach-trigger:hover, .mic-trigger:hover { background: var(--surface-2); color: var(--accent-text); }
.mic-trigger:disabled { opacity: .35; cursor: not-allowed; }
.mic-trigger .icon-mic-recording, .mic-trigger .icon-mic-spinner { display: none; }
.mic-trigger.mic-recording { color: var(--surface); background: var(--coral); animation: mic-btn-pulse 1.4s ease-in-out infinite; }
.mic-trigger.mic-recording .icon-mic-idle { display: none; }
.mic-trigger.mic-recording .icon-mic-recording { display: inline-flex; }
@keyframes mic-btn-pulse {
  0%, 100% { }
  50%      { }
}
.mic-trigger.mic-transcribing { color: var(--accent-text); }
.mic-trigger.mic-transcribing .icon-mic-idle { display: none; }
.mic-trigger.mic-transcribing .icon-mic-spinner {
  display: inline-block; width: 18px; height: 18px;
  border: 2px solid var(--border-strong); border-top-color: var(--accent-text);
  border-radius: 50%; animation: spin .7s linear infinite;
}
.mic-trigger.mic-error { color: var(--error); background: var(--error-soft); }

.send-btn {
  width: 44px; height: 44px; flex-shrink: 0; border-radius: var(--r-panel);
  background: var(--coral); color: var(--surface);
  display: inline-flex; align-items: center; justify-content: center;
  transition: filter var(--t), opacity var(--t), background var(--t);
}
.send-btn:hover:not(:disabled) { filter: brightness(1.08); }
.send-btn:disabled { opacity: .4; cursor: not-allowed; }
.send-btn .icon-stop { display: none; }
.send-btn.stop-mode { background: var(--graphite); }
.send-btn.stop-mode .icon-send { display: none; }
.send-btn.stop-mode .icon-stop { display: inline-flex; }

.input-foot { display: flex; justify-content: space-between; gap: 10px; padding: 4px 14px 2px; }
.input-hint { font-size: .76rem; color: var(--text-faint); }
.input-hint.dim { color: var(--text-faint); opacity: .75; }

.attach-preview {
  display: flex; align-items: center; gap: 11px;
  margin: 4px 6px 8px; padding: 9px 12px;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r-panel);
}
.attach-thumb {
  width: 34px; height: 34px; border-radius: var(--r-panel); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; color: var(--stone);
  background: var(--sand-sunk); overflow: hidden;
}
.attach-thumb img { width: 100%; height: 100%; object-fit: cover; }
.attach-meta { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.3; }
.attach-name { font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-size { font-size: .75rem; color: var(--text-faint); }
.attach-remove {
  flex-shrink: 0; width: 28px; height: 28px; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--border); color: var(--text-muted);
  font-size: 1.05rem; line-height: 1; transition: background var(--t), color var(--t), border-color var(--t);
}
.attach-remove:hover { background: var(--error-soft); border-color: var(--ash); color: var(--error); }

.mic-status-bar {
  display: flex; align-items: center; gap: 10px;
  margin: 4px 6px 8px; padding: 8px 14px;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r-panel);
  font-size: .84rem; color: var(--text-muted);
}
/* Onda vocale live — barre generate da app.js (larghezza 3px + gap 3px) */
.mic-wave { display: none; align-items: center; justify-content: space-between; gap: 3px; height: 22px; width: 100%; flex: 1; overflow: hidden; }
.mic-status-bar--voice .mic-wave { display: flex; }
.mic-status-bar--voice #mic-status-text { display: none; }
.mic-wave-bar {
  width: 3px; height: 6px; border-radius: var(--r-control); flex-shrink: 0;
  background: var(--accent); transform: scaleY(1); transform-origin: center;
  transition: background-color .15s ease;
}
.mic-wave-bar.mic-wave-bar-active { background: var(--coral); }

/* ============================================================================
   Pannello contesto (destra)
   ========================================================================== */
.context-panel {
  width: var(--ctx-w); min-width: var(--ctx-w);
  background: var(--sand);
  border-left: 1px solid var(--ash);
  display: flex; flex-direction: column;
  transition: margin-right var(--t);
}
.context-panel.collapsed { margin-right: calc(-1 * var(--ctx-w)); pointer-events: none; }

.ctx-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 10px 0 14px; height: 46px; border-bottom: 1px solid var(--ash); flex-shrink: 0;
}
.ctx-head h3 { font-size: .9rem; font-weight: 600; }
.ctx-body { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.ctx-empty { margin: auto 0; color: var(--stone); font-size: .85rem; line-height: 1.5; padding: 4px; }
.ctx-empty p { font-size: .88rem; }

.ctx-stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.ctx-stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-control); padding: 11px 13px; }
.ctx-stat .cs-val { font-size: 1.25rem; font-weight: 700; }
.ctx-stat .cs-label { font-size: .72rem; color: var(--text-faint); }
.ctx-stat .cs-val.accent { color: var(--accent-text); }
.ctx-stat .cs-val.good { color: var(--success); }

.ctx-section-title { font-size: .76rem; color: var(--text-faint); font-weight: 600; }

.ctx-doc {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-control); padding: 11px 12px; animation: fade-in 180ms var(--ease);
}
.ctx-doc-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.ctx-doc-name { font-size: .88rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.ctx-doc-page { font-size: .74rem; color: var(--text-faint); flex-shrink: 0; }
.ctx-score-row { display: flex; align-items: center; gap: 9px; }
.ctx-score-bar { flex: 1; height: 6px; border-radius: var(--r-nav); background: var(--surface-3); overflow: hidden; }
.ctx-score-fill { height: 100%; border-radius: var(--r-nav); background: var(--coral); }
.ctx-score-num { font-size: .78rem; color: var(--accent-text); font-weight: 600; flex-shrink: 0; min-width: 36px; text-align: right; }
.ctx-chunk-text {
  margin-top: 9px; font-size: .85rem; line-height: 1.55; color: var(--text-muted);
  max-height: 0; overflow: hidden; transition: max-height var(--t);
}
.ctx-doc.open .ctx-chunk-text { max-height: 320px; overflow-y: auto; }
.ctx-raw-toggle { font-size: .8rem; color: var(--accent-text); margin-top: 7px; font-weight: 500; }

.ctx-vision-thumbs { display: flex; flex-wrap: wrap; gap: 10px; margin: 4px 0 16px; }
.ctx-vision-thumb { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.ctx-vision-thumb-label { font-size: .72rem; color: var(--text-faint); }
.ctx-vision-img {
  width: 92px; height: 92px; object-fit: cover; border-radius: var(--r-panel);
  border: 1px solid var(--border); background: var(--surface); cursor: pointer;
}

/* ============================================================================
   Overlay condivisi (explorer / impostazioni / palette / modale)
   ========================================================================== */
.overlay {
  position: fixed; inset: 0; z-index: 60;
  background: color-mix(in srgb, var(--graphite) 42%, transparent);
  display: flex; align-items: center; justify-content: center;
  padding: 16px; animation: fade-in 130ms var(--ease);
}
.palette-overlay { align-items: flex-start; padding-top: 13vh; }

/* ── Gestione documenti ── */
.explorer {
  width: min(1120px, 100%); height: min(760px, 100%);
  background: var(--shell); border-radius: var(--r-panel);
  display: flex; flex-direction: column; overflow: hidden;
  animation: pop-in 180ms var(--ease);
}
.explorer-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--ash); flex-shrink: 0;
}
.explorer-title { display: flex; align-items: flex-start; gap: 10px; color: var(--stone); }
.explorer-title h2 { font-size: 1.05rem; font-weight: 700; color: var(--graphite); }
.explorer-title p { font-size: .84rem; color: var(--stone); margin-top: 1px; }

.explorer-body { flex: 1; display: flex; min-height: 0; }
/* Il pannello laterale dell'explorer è su fondo chiaro, non grafite: la
   sidebar grafite è una sola, quella dell'applicazione. */
.explorer-side {
  width: 210px; flex-shrink: 0; border-right: 1px solid var(--ash);
  padding: 8px; overflow-y: auto; background: var(--sand);
}
.explorer-side-hint { font-size: .8rem; color: var(--text-faint); padding: 12px 10px 0; line-height: 1.5; }

.explorer-main { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 10px 14px; }
.explorer-toolbar { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; margin-bottom: 10px; }
.toolbar-spacer { flex: 1; }
.doc-filter-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.doc-filter-row input {
  min-width: 170px; background: var(--surface); border: 1px solid var(--ash);
  border-radius: var(--r-control); padding: 6px 10px; font-size: .85rem; outline: none;
  transition: border-color var(--t), background var(--t);
}
.doc-filter-row input:focus { border-color: var(--accent-text); background: var(--surface); }

.doc-list {
  flex: 1; min-height: 0; overflow-y: auto;
  display: flex; flex-direction: column; gap: 2px;
  border: 1px solid var(--ash); border-radius: var(--r-panel); padding: 6px;
  background: var(--sand);
}
.explorer-foot-hint { font-size: .8rem; color: var(--text-faint); padding-top: 10px; }

/* ── Gestione email ── */
.email-body-columns { flex: 1; min-height: 0; display: flex; gap: 12px; }
.email-message-list {
  width: 300px; flex-shrink: 0; overflow-y: auto;
  border: 1px solid var(--border); border-radius: var(--r-panel); padding: 8px;
  background: var(--surface-1); display: flex; flex-direction: column; gap: 2px;
}
.email-message-row {
  display: flex; flex-direction: column; gap: 1px; padding: 6px 8px; width: 100%;
  background: none; border: none; text-align: left; font-family: inherit;
  border-radius: var(--r-nav); cursor: pointer; font-size: .86rem; color: var(--graphite);
}
.email-message-row:hover { background: var(--surface-2); }
.email-message-row.active { background: var(--coral-soft); color: var(--graphite); }
.email-message-row .em-subject { font-weight: 600; color: var(--text); }
.email-message-row.active .em-subject { color: var(--graphite); }
.email-message-row .em-meta { font-size: .78rem; color: var(--text-faint); }
.email-message-detail {
  flex: 1; min-width: 0; overflow-y: auto;
  border: 1px solid var(--border); border-radius: var(--r-panel); padding: 16px 18px;
  background: var(--surface-1);
}
.email-account-row {
  display: flex; flex-direction: column; align-items: stretch; gap: 5px;
  padding: 8px 10px; border-radius: var(--r-panel); font-size: .87rem;
  color: var(--graphite); border: 1px solid var(--ash);
}
.email-account-row:hover { background: var(--surface-2); }
.email-account-row.active { background: var(--coral-soft); border-color: var(--coral); }
.email-account-row .em-acc-actions { display: flex; gap: 4px; align-items: center; justify-content: flex-end; }
.email-account-row .em-acc-info {
  display: flex; flex-direction: column; gap: 1px; min-width: 0; width: 100%;
  background: none; border: none; text-align: left; font-family: inherit;
  color: inherit; cursor: pointer; padding: 0;
}
.email-account-row .em-acc-label {
  font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; width: 100%;
}
.email-account-row.active .em-acc-label { color: var(--graphite); }
.email-account-row .em-acc-sub {
  font-size: .76rem; color: var(--text-faint); overflow-wrap: break-word;
  white-space: normal; width: 100%; line-height: 1.35;
}
.email-account-row .em-acc-status.ok { color: var(--green); }
/* Un account scollegato non è un errore rosso: è uno stato spento. */
.email-account-row .em-acc-status.off { color: var(--stone); }
.email-account-row .em-acc-disconnect { font-size: .78rem; padding: 4px 10px; }
.email-oauth-options { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.email-oauth-btn { width: 100%; justify-content: center; font-weight: 600; }
.email-manual-divider {
  font-size: .78rem; color: var(--text-faint); text-align: center;
  margin: 4px 0 14px; padding-top: 12px; border-top: 1px solid var(--border);
}
.email-draft-card {
  border: 1px solid var(--border); border-radius: var(--r-panel); padding: 14px 16px;
  background: var(--surface-1); margin-top: 10px; font-size: .9rem;
}
.email-draft-card .em-draft-field { margin-bottom: 6px; }
.email-draft-card .em-draft-field b { color: var(--text-faint); font-weight: 600; }
.email-draft-actions { display: flex; gap: 8px; margin-top: 10px; }


/* albero documenti */
.doc-list.is-dragging .tree-folder-row, .doc-list.is-dragging .tree-root-row { outline: 1.5px dashed var(--border-strong); outline-offset: -1.5px; }
.tree-root-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; margin-bottom: 6px; border-radius: var(--r-panel); font-size: .74rem;
 font-weight: 700; color: var(--text-faint);
  transition: background var(--t), color var(--t);
}
.tree-root-count { margin-left: auto; background: var(--surface-2); border-radius: var(--r-control); padding: 1px 8px; font-size: .72rem; }
.tree-root-label { font-size: .72rem; font-weight: 700; color: var(--text-faint); padding: 12px 10px 4px; }
.tree-folder { margin-bottom: 4px; }
.tree-folder-row {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 12px; border-radius: var(--r-nav); cursor: pointer;
  color: var(--text); font-size: .93rem; border: 1px solid transparent;
  transition: background var(--t), border-color var(--t);
}
.tree-folder-row:hover { background: var(--surface); border-color: var(--border); }
.tree-folder.kind-system > .tree-folder-row { background: var(--accent-soft); border-color: transparent; }
.tree-folder.kind-system > .tree-folder-row:hover { border-color: var(--accent-text); }
.tree-folder-row.drop-target, .tree-root-row.drop-target {
  background: var(--accent-soft) !important; border-color: var(--accent) !important; color: var(--accent-text); outline: none;
}
.tree-chevron { color: var(--text-faint); font-size: .8rem; width: 14px; flex-shrink: 0; line-height: 1; }
.tree-folder-ico { display: inline-flex; align-items: center; flex-shrink: 0; font-size: 1rem; }
.tree-folder-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.tree-folder-badge {
  font-size: .68rem; font-weight: 600; flex-shrink: 0;
  color: var(--accent-text); background: var(--surface); border: 1px solid var(--accent-soft); border-radius: var(--r-control); padding: 1px 8px;
}
.tree-folder-count { font-size: .74rem; color: var(--text-faint); flex-shrink: 0; background: var(--surface-2); border-radius: var(--r-control); padding: 1px 8px; min-width: 26px; text-align: center; }
.tree-folder-actions, .tree-file-actions { display: flex; gap: 2px; opacity: 0; flex-shrink: 0; transition: opacity var(--t); }
.tree-folder-row:hover .tree-folder-actions, .tree-file:hover .tree-file-actions { opacity: 1; }
.tree-action-btn {
  width: 28px; height: 28px; border-radius: var(--r-control); color: var(--text-faint);
  display: inline-flex; align-items: center; justify-content: center; font-size: .9rem;
  transition: color var(--t), background var(--t);
}
.tree-action-btn:hover { color: var(--accent-text); background: var(--accent-soft); }
.tree-folder-del-btn:hover, .tree-file-del:hover { color: var(--error) !important; background: var(--error-soft) !important; }
.tree-children {
  padding-left: 8px; margin: 2px 0 2px 19px; padding-bottom: 4px;
  display: flex; flex-direction: column; gap: 1px; border-left: 1.5px solid var(--border-strong);
}
.tree-folder-empty { font-size: .78rem; color: var(--text-faint); padding: 8px 12px; font-style: italic; }
/* Righe fitte: è un elenco che si scorre a lungo, non una vetrina. */
.tree-file {
  display: flex; align-items: center; gap: 8px;
  padding: 3px 8px; border-radius: var(--r-nav); cursor: grab;
  transition: background var(--t), opacity var(--t);
}
.tree-file:hover { background: var(--surface); }
.tree-file.dragging { opacity: .45; cursor: grabbing; }
.tree-file input[type="checkbox"], .doc-row input[type="checkbox"] {
  accent-color: var(--coral); width: 15px; height: 15px; flex-shrink: 0; cursor: pointer;
}
.tree-file-ext {
  flex-shrink: 0; font-size: .6rem; font-weight: 700; line-height: 1;
  padding: 3px 4px; border-radius: var(--r-nav); min-width: 30px; text-align: center; color: var(--surface);
}
.ext-pdf, .ext-doc, .ext-xls, .ext-eml, .ext-txt, .ext-img, .ext-other { background: var(--stone); }
.tree-file label { flex: 1; font-size: .875rem; color: var(--graphite); cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-file label:hover { color: var(--accent-text); }
.tree-file-chunks { font-size: .72rem; color: var(--text-faint); flex-shrink: 0; font-variant-numeric: tabular-nums; }
.tree-file-badge {
  font-size: .7rem; color: var(--graphite); flex-shrink: 0; max-width: 140px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  background: var(--accent-soft); border-radius: var(--r-control); padding: 1px 8px;
}
.tree-empty { text-align: center; padding: 36px 16px; color: var(--text-faint); }
.tree-empty-ico { display: block; color: var(--stone); margin-bottom: 6px; }
.tree-empty-title { font-weight: 700; color: var(--text-soft); margin-bottom: 4px; }
.tree-empty-sub { font-size: .84rem; line-height: 1.5; max-width: 420px; margin: 0 auto; }

.upload-progress-wrap {
  margin-bottom: 10px; background: var(--surface-1);
  border: 1px solid var(--border); border-radius: var(--r-control);
  padding: 10px 12px; display: flex; flex-direction: column; gap: 7px;
}
.upload-progress-header { display: flex; align-items: center; gap: 8px; overflow: hidden; }
.upload-spinner {
  flex-shrink: 0; width: 14px; height: 14px;
  border: 2px solid var(--surface-3); border-top-color: var(--accent-text);
  border-radius: 50%; animation: spin 700ms linear infinite; display: inline-block;
}
.upload-current-name { font-size: .85rem; color: var(--text-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.upload-count { flex-shrink: 0; font-size: .8rem; color: var(--text-faint); font-variant-numeric: tabular-nums; }
.upload-bar-track { height: 5px; background: var(--surface-3); border-radius: var(--r-nav); overflow: hidden; }
.upload-bar-fill { height: 100%; background: var(--accent); border-radius: var(--r-nav); width: 0%; transition: width 300ms var(--ease); }
.upload-status { font-size: .85rem; color: var(--text-muted); word-break: break-word; }
.upload-status:not(:empty) { padding-bottom: 10px; }

/* ── Impostazioni ── */
.settings-card {
  width: min(480px, 100%); max-height: 100%;
  background: var(--shell); border-radius: var(--r-panel); display: flex; flex-direction: column; overflow: hidden;
  animation: pop-in 180ms var(--ease);
}
.settings-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--ash);
}
.settings-head h2 { font-size: 1.05rem; font-weight: 700; }
.settings-body { padding: 12px 16px 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
/* Sentence case, non maiuscoletto spaziato. */
.settings-section h3 { font-size: .85rem; color: var(--graphite); font-weight: 700; margin-bottom: 8px; }
.settings-section .nav-head { padding: 0 0 10px; }
.settings-section .nav-head h3 { margin-bottom: 0; }
.settings-account { display: flex; align-items: center; gap: 12px; }
.settings-account-name { font-size: 1rem; font-weight: 600; }
.settings-hint { font-size: .82rem; color: var(--text-faint); margin-top: 10px; line-height: 1.5; }
.settings-hint code { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r-nav); padding: 1px 5px; font-size: .78rem; }

/* ── Impostazioni → modello AI (endpoint OpenAI-compatibile) ── */
.llm-config .field-label { margin-top: 12px; }
.llm-config .field-label:first-child { margin-top: 0; }
.llm-key-hint { font-weight: 500; color: var(--text-faint); font-size: .78rem; }
.llm-config input[type="url"], .llm-config input[type="text"], .llm-config input[type="password"] {
  display: block; width: 100%;
  padding: 7px 10px; border-radius: var(--r-control);
  border: 1px solid var(--ash-strong);
  background: var(--surface);
  font-size: .9rem; outline: none;
  transition: border-color var(--t);
}
.llm-config input:focus { border-color: var(--accent-text); }
.llm-enable-row { display: flex; align-items: center; gap: 9px; margin-top: 14px; font-size: .9rem; color: var(--text-soft); cursor: pointer; }
.llm-enable-row input { accent-color: var(--coral); width: 16px; height: 16px; }

/* ── Vocabolario di dettatura (Impostazioni) ─────────────────────────────── */
.dictation-vocabulary textarea {
  display: block; width: 100%;
  padding: 9px 11px; border-radius: var(--r-control);
  border: 1px solid var(--ash-strong);
  background: var(--surface);
  font-family: inherit; font-size: .9rem; line-height: 1.5;
  outline: none; resize: vertical; min-height: 96px;
  transition: border-color var(--t);
}
.dictation-vocabulary textarea:focus { border-color: var(--accent-text); }
.llm-actions { display: flex; gap: 10px; margin-top: 14px; }
.llm-actions .btn-ghost, .llm-actions .btn-primary { width: auto; flex: 1; padding: 11px 14px; margin: 0; }
.llm-config-status { font-size: .84rem; margin-top: 12px; padding: 9px 12px; border-radius: var(--r-control); background: var(--surface-1); border: 1px solid var(--border); color: var(--text-soft); word-break: break-word; }
.llm-config-status.ok { background: var(--accent-soft); border-color: var(--accent-text); color: var(--accent-text); }
.llm-config-status.error { background: var(--error-soft); border-color: var(--ash); color: var(--error); }
.llm-reset { display: block; width: 100%; margin-top: 10px; padding: 9px; background: transparent; border: none; color: var(--text-faint); font-size: .82rem; text-decoration: underline; cursor: pointer; }
.llm-reset:hover { color: var(--error); }

/* ── Palette ── */
.palette {
  width: min(600px, 100%); background: var(--shell);
  border-radius: var(--r-panel);  overflow: hidden; animation: pop-in 160ms var(--ease);
}
.palette-input-row { display: flex; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.palette-ico { color: var(--accent-text); flex-shrink: 0; }
#palette-input { flex: 1; background: transparent; border: none; outline: none; font-size: 1rem; }
.palette-results { max-height: 52vh; overflow-y: auto; padding: 8px; }
.palette-group-title { font-size: .72rem; color: var(--text-faint); font-weight: 700; padding: 9px 11px 5px; }
.palette-item {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px; width: 100%;
  background: none; border: none; text-align: left; font-family: inherit;
  border-radius: var(--r-nav); cursor: pointer; font-size: .9rem; color: var(--graphite);
  transition: background var(--t);
}
.palette-item:hover, .palette-item.active { background: var(--sand-sunk); }
.palette-item .pi-ico { color: var(--stone); display: inline-flex; align-items: center; flex-shrink: 0; }
.palette-item .pi-sub { margin-left: auto; font-size: .78rem; color: var(--text-faint); flex-shrink: 0; }

/* ── Modale generica ── */
.modal {
  width: min(430px, 100%); background: var(--shell);
  border-radius: var(--r-panel); padding: 26px;  animation: pop-in 160ms var(--ease); max-height: 100%; overflow-y: auto;
}
.modal h3 { font-size: 1.12rem; font-weight: 700; margin-bottom: 6px; }
.modal-desc { color: var(--text-muted); font-size: .9rem; margin-bottom: 18px; }
.modal-body input, .modal-body select {
  width: 100%; background: var(--surface-1); border: 1px solid var(--border-strong);
  border-radius: var(--r-control); padding: 12px 14px; font-size: .95rem; outline: none; margin-bottom: 12px;
}
.modal-body input:focus, .modal-body select:focus { border-color: var(--accent-text); background: var(--surface); }
.modal-body textarea {
  width: 100%; background: var(--surface-1); border: 1px solid var(--border-strong);
  border-radius: var(--r-control); padding: 12px 14px; font-size: .95rem; outline: none;
  margin-bottom: 12px; font-family: inherit; resize: vertical; min-height: 60px;
}
.modal-body textarea:focus { border-color: var(--accent-text); background: var(--surface); }
.modal-body .checks { display: flex; flex-direction: column; gap: 4px; max-height: 260px; overflow-y: auto; }
.modal-body .check-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--r-control); font-size: .9rem; transition: background var(--t); cursor: pointer; }
.modal-body .check-row:hover { background: var(--surface-1); }
.modal-body .modal-warning { color: var(--error); font-size: .88rem; margin-bottom: 10px; }
.modal-body .check-row input { width: auto; margin: 0; accent-color: var(--coral); }
.modal-actions { display: flex; gap: 10px; margin-top: 10px; }
.modal-actions .btn-primary, .modal-actions .btn-ghost { width: auto; flex: 1; margin: 0; }

/* ============================================================================
   Workspace a pagina intera (Sales)
   ----------------------------------------------------------------------------
   Sales non è un overlay sopra la chat ma una pagina a sé: le sue viste
   (kanban a 9 colonne, tabelle a 11 colonne, dettaglio lead a due colonne)
   non entravano nella card .explorer da 1040×720 e venivano tagliate. Qui
   prende tutta la finestra, con una barra in alto per tornare a LocalMind e
   le sezioni come tab orizzontali invece che in una sidebar da 240px —
   spazio che torna tutto al contenuto.
   ========================================================================== */
.workspace-page {
  position: fixed; inset: 0; z-index: 60;
  /* Stesso fondo della pagina principale: passare alla sezione Sales è un
     cambio di pagina, non una finestra sovrapposta. */
  background: var(--sand);
  display: flex; flex-direction: column;
  animation: fade-in 130ms var(--ease);
}
/* La chat sotto non deve scrollare dietro alla pagina Sales. */
body.workspace-open { overflow: hidden; }

.workspace-head {
  flex-shrink: 0;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--ash);
}
.workspace-back {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 11px; border-radius: var(--r-control);
  border: 1px solid var(--ash); background: var(--surface);
  color: var(--graphite); font-size: .85rem; font-weight: 500;
  cursor: pointer; transition: border-color var(--t), background var(--t);
}
.workspace-back:hover { background: var(--sand); border-color: var(--ash-strong); }

.workspace-title { display: flex; align-items: center; gap: 9px; color: var(--stone); min-width: 0; }
.workspace-title h2 { font-size: 1rem; font-weight: 700; color: var(--graphite); }
.workspace-title p { font-size: .8rem; color: var(--stone); margin-top: 1px; }

.workspace-tabs { display: flex; gap: 6px; margin-left: auto; flex-wrap: wrap; }
.ws-tab {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 11px; border-radius: var(--r-nav);
  border: 1px solid transparent; background: transparent;
  color: var(--stone); font-size: .85rem; font-weight: 500;
  cursor: pointer; transition: background var(--t), color var(--t);
}
.ws-tab:hover { color: var(--graphite); background: var(--sand-sunk); }
/* La scheda attiva è grafite pieno: è l'unica sezione in cui ti trovi. */
.ws-tab.active { color: var(--surface); background: var(--graphite); font-weight: 600; }

.workspace-body {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column;
  padding: 12px 16px 16px;
}

@media (max-width: 720px) {
  .workspace-head { padding: 12px 14px; gap: 12px; }
  .workspace-title p { display: none; }
  .workspace-tabs { width: 100%; margin-left: 0; }
  .workspace-body { padding: 14px 14px 18px; }
}

/* ── Pagina a due colonne: sidebar grafite + contenuto ──
   Le sezioni di una pagina di lavoro (Sales, e in futuro le altre) stanno in
   una sidebar a sinistra identica a quella principale — stessa larghezza,
   stesso grafite, stesse voci — non in una fila di schede in alto: chi passa
   da LocalMind al Sales Agent ritrova il menu dove l'ha lasciato. */
.workspace-split { flex-direction: row; }
.workspace-side { flex-shrink: 0; height: 100%; }
.workspace-side .sidebar-top { padding-bottom: 12px; }
.workspace-side .workspace-back { margin: 0 12px 12px; justify-content: flex-start; }
.workspace-back.on-graphite {
  background: var(--graphite-up); border-color: var(--graphite-line); color: var(--surface);
}
.workspace-back.on-graphite:hover { background: var(--graphite-sunk); border-color: var(--sidebar-muted); }
.workspace-side .nav-head { padding-top: 4px; }

.ws-side-nav { display: flex; flex-direction: column; gap: 2px; padding: 0 8px; }
.ws-side-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--r-nav);
  border: none; background: transparent;
  color: var(--sidebar-text); font-size: .9rem; font-weight: 500; text-align: left;
  cursor: pointer; transition: background var(--t), color var(--t);
}
.ws-side-item svg { color: var(--sidebar-muted); flex-shrink: 0; }
.ws-side-item > span:not(.ws-side-badge) { flex: 1; }
.ws-side-item:hover { background: var(--graphite-up); color: var(--surface); }
/* La voce attiva è in rilievo come una conversazione attiva nella sidebar
   principale; l'icona corallo dice a colpo d'occhio dove ti trovi. */
.ws-side-item.active { background: var(--graphite-up); color: var(--surface); font-weight: 600; }
.ws-side-item.active svg { color: var(--coral); }
.ws-side-badge { margin-left: auto; }

.workspace-main { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; }

/* Sotto i 720px la sidebar diventa una barra in testa: le voci si mettono in
   fila e il contenuto prende tutta la larghezza. Il selettore è più specifico
   di `.sidebar` perché la regola mobile della sidebar principale (più in
   basso, position fixed a tutta altezza) non deve valere qui. */
@media (max-width: 720px) {
  .workspace-split { flex-direction: column; }
  .workspace-page .workspace-side {
    position: static; width: 100%; min-width: 0; max-width: none; height: auto;
    margin: 0; flex-shrink: 0;
  }
  .workspace-side .sidebar-top { display: none; }
  .workspace-side .workspace-back { margin: 10px 12px 8px; }
  .workspace-side .nav-head { display: none; }
  .ws-side-nav { flex-direction: row; flex-wrap: wrap; padding: 0 8px 10px; }
  .ws-side-item { padding: 7px 10px; font-size: .85rem; }
  .workspace-main { height: auto; flex: 1; min-height: 0; }
}

/* ============================================================================
   Sales — dashboard / campagne / dettaglio campagna
   ========================================================================== */
.sales-content { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.sales-loading { display: flex; align-items: center; gap: 10px; color: var(--text-muted); font-size: .9rem; padding: 30px 0; justify-content: center; }

/* ── Le metriche in testa alla dashboard ──
   Non una griglia di schede identiche — che è ciò che rendeva illeggibile la
   vecchia testata — ma valori appoggiati sul pannello e separati da un
   divisore verticale da 1px. Uno solo, quello su cui si lavora ogni giorno,
   è un blocco pieno corallo: è l'unico elemento pieno della schermata. */
.metric-strip { display: flex; flex-wrap: wrap; padding: 0; overflow: hidden; }
.metric { flex: 1 1 150px; min-width: 0; padding: 12px 16px; }
.metric + .metric { border-left: 1px solid var(--ash); }
.metric-val { font-size: 1.7rem; font-weight: 600; line-height: 1.05; letter-spacing: var(--ls-heading); }
.metric-label { font-size: .84rem; font-weight: 500; color: var(--graphite); margin-top: 4px; }
.metric-hint { font-size: .76rem; color: var(--stone); margin-top: 1px; line-height: 1.3; }

.metric--primary {
  background: var(--coral); color: var(--graphite);
  border-left: 0;
}
.metric--primary + .metric { border-left: 0; }
.metric--primary .metric-label,
.metric--primary .metric-hint { color: var(--graphite); }
.metric--primary .metric-hint { opacity: .78; }
/* I valori positivi sono verdi. */
.metric--good .metric-val { color: var(--green); }

.kpi-delta { font-size: .8rem; font-weight: 600; }
.delta-up { color: var(--green); }
/* Un delta negativo è pietra con la freccia giù, mai rosso. */
.delta-down { color: var(--stone); }

/* ── Pannelli della dashboard ── */
.sales-panel {
  background: var(--surface); border: 1px solid var(--ash); border-radius: var(--r-panel);
  padding: 12px 16px; min-width: 0; flex-shrink: 0;
}
.sales-panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.sales-panel-head h3 { font-size: .95rem; font-weight: 700; }
.sales-panel-head > span { font-size: .8rem; color: var(--stone); }
.sales-two-col { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 12px; }
@media (max-width: 1000px) { .sales-two-col { grid-template-columns: 1fr; } }

/* ── Imbuto: barra impilata + striscia degli stadi ──
   Scala sequenziale neutra (più avanti = più scuro), definita in tokens.css:
   non è un colore di marchio, è una scala di dati. L'ultimo stadio — la
   trattativa vinta — è l'eccezione corallo; "Chiusi" è fuori percorso. */
.stage-new       { background: var(--stage-1); }
.stage-qualified { background: var(--stage-2); }
.stage-contacted { background: var(--stage-3); }
.stage-replied   { background: var(--stage-4); }
.stage-meeting   { background: var(--stage-5); }
.stage-proposal  { background: var(--stage-6); }
.stage-won       { background: var(--stage-won); }
.stage-closed    { background: var(--stage-closed); }

.stage-bar {
  display: flex; gap: 1px; height: 18px; border-radius: var(--r-nav); overflow: hidden;
  background: var(--ash);
}
.stage-bar.mini { height: 6px; border-radius: var(--r-nav); }
.stage-bar.empty { align-items: center; justify-content: center; font-size: .76rem; color: var(--stone); }
.stage-bar.mini.empty span { display: none; }
.stage-seg {
  flex: 0 1 auto; min-width: 3px;
  display: flex; align-items: center; justify-content: center;
  font-size: .72rem; font-weight: 600; color: var(--graphite);
  font-variant-numeric: tabular-nums;
  transition: flex-basis 260ms var(--ease);
}
/* testo chiaro sui gradini scuri della rampa */
.stage-seg.stage-replied, .stage-seg.stage-meeting, .stage-seg.stage-proposal,
.stage-seg.stage-won, .stage-seg.stage-closed { color: var(--surface); }

/* Gli stadi: valori separati da un divisore, direttamente sul pannello. */
.stage-strip { display: flex; flex-wrap: wrap; margin-top: 10px; }
.stage-cell { flex: 1 1 100px; min-width: 0; padding: 6px 12px; }
.stage-cell + .stage-cell { border-left: 1px solid var(--ash); }
.stage-cell.closed { color: var(--stone); }
.stage-dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.stage-count { font-size: 1.15rem; font-weight: 600; line-height: 1.1; }
.stage-label {
  display: flex; align-items: center; gap: 6px;
  font-size: .78rem; color: var(--stone); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ── Andamento: una serie sola, quindi nessuna legenda ── */
.trend-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.trend-val { font-size: 1.3rem; font-weight: 600; letter-spacing: var(--ls-heading); }
.trend-label { font-size: .82rem; color: var(--stone); }
.trend-empty { font-size: .85rem; color: var(--stone); padding: 10px 0; }
.chart { display: block; width: 100%; height: 110px; }
.chart-grid { stroke: var(--ash); stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart-area { fill: var(--coral-soft); stroke: none; }
.chart-line { fill: none; stroke: var(--coral); stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.chart-axis { display: flex; justify-content: space-between; font-size: .74rem; color: var(--stone); font-variant-numeric: tabular-nums; }

/* ── Righe campagna nella dashboard ── */
.camp-rows { display: flex; flex-direction: column; }
.camp-row {
  display: grid; align-items: center; gap: 10px;
  /* Colonne a larghezza fissa dalla seconda in poi: con `auto` l'intestazione
     e le righe risolvevano larghezze diverse e i numeri non stavano sotto la
     loro etichetta. */
  grid-template-columns: minmax(140px, 1.6fr) 92px minmax(80px, 1fr) repeat(4, 62px) 72px;
  padding: 6px 0; border-top: 1px solid var(--ash);
}
.camp-row:first-child { border-top: 0; }
.camp-row-name { min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.camp-row-name strong { font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.camp-row-name span { font-size: .76rem; color: var(--stone); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.camp-row-bar { min-width: 0; }
/* Colonne numeriche: allineate a destra, cifre a larghezza fissa, intestate
   una volta sola in cima alla tabella. */
.camp-row-num { text-align: right; font-size: .9rem; font-weight: 600; }
.camp-row-head { border-top: 0; padding-bottom: 2px; }
.camp-row .camp-row-open { width: 100%; }
.camp-row .status-pill { justify-content: center; overflow: hidden; }
.camp-row-head span { font-size: .74rem; color: var(--stone); text-align: right; }
@media (max-width: 760px) {
  .camp-row { grid-template-columns: 1fr auto; }
  .camp-row-bar, .camp-row-num { display: none; }
  /* Senza le colonne numeriche l'intestazione non ha più niente da intestare. */
  .camp-row-head { display: none; }
  .camp-row .camp-row-open { width: auto; }
}

.sales-activity-list { display: flex; flex-direction: column; }
.sales-activity-row {
  display: flex; align-items: center; gap: 8px; padding: 6px 0; width: 100%;
  border: none; border-top: 1px solid var(--ash); background: none; text-align: left;
  font-size: .85rem; cursor: pointer; min-width: 0; font-family: inherit; color: inherit;
}
.sales-activity-row:first-child { border-top: 0; }
.sales-activity-row:hover .sa-name { color: var(--accent-text); }
.sales-activity-row .sa-name { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sales-activity-row .sa-meta { color: var(--stone); font-size: .76rem; flex-shrink: 0; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Schede campagna (tab Campagne) ── */
.sales-toolbar-count { margin-left: auto; font-size: .82rem; color: var(--text-faint); }
.camp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 16px; }
.camp-card {
  background: var(--surface); border: 1px solid var(--ash); border-radius: var(--r-panel);
  padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; min-width: 0;
  transition: border-color var(--t);
}
.camp-card:hover { border-color: var(--border-strong); }
.camp-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.camp-card-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-width: 0; }
.camp-card-title h4 { font-size: 1.02rem; font-weight: 700; overflow-wrap: anywhere; }
.camp-card-icons { display: flex; gap: 2px; flex-shrink: 0; }
.camp-card-icons .icon-btn { width: 30px; height: 30px; }
.camp-card-target { font-size: .84rem; color: var(--text-muted); line-height: 1.45; overflow-wrap: anywhere; }
.camp-card-target span { color: var(--text-faint); }
/* Come in testa alla dashboard: valori separati da un divisore verticale da
   1px, appoggiati sulla scheda — non cinque riquadri identici in fila. */
.camp-card-stats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); }
.camp-card-stats div { display: flex; flex-direction: column; padding: 0 10px; line-height: 1.2; min-width: 0; }
.camp-card-stats div + div { border-left: 1px solid var(--ash); }
.camp-card-stats div:first-child { padding-left: 0; }
.camp-card-stats b { font-size: 1rem; font-weight: 600; }
.camp-card-stats span { font-size: .7rem; color: var(--stone); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.camp-card-foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: auto; padding-top: 4px; }
.camp-card-date { margin-left: auto; font-size: .76rem; color: var(--text-faint); }
.btn-small { padding: 5px 11px !important; font-size: .83rem !important; width: auto !important; }

/* ── Calendario (vista settimanale) ── */
.cal-nav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.cal-title { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.cal-count { font-size: .78rem; color: var(--text-faint); white-space: nowrap; }
.cal-account { font-size: .78rem; color: var(--text-faint); margin-right: 6px; }
.cal-mode { display: flex; gap: 4px; margin-right: 4px; }
.cal-mode .chip-btn.on { background: var(--accent-soft); border-color: var(--accent-text); color: var(--accent-text); font-weight: 600; }

/* ── Vista mensile ──
   Sette colonne per settimane intere: le celle fuori dal mese restano per
   non spezzare la griglia, ma sbiadite. Ogni cella mostra al massimo tre
   eventi compatti e poi "+N"; il dettaglio completo sta nel pannello sotto,
   che si apre cliccando il giorno. */
.cal-month { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.cal-month-dow {
  font-size: .7rem; font-weight: 700; color: var(--text-faint);
 text-align: center; padding-bottom: 2px;
}
.cal-cell {
  min-width: 0; min-height: 88px; display: flex; flex-direction: column; gap: 3px; padding: 5px;
  background: var(--sand); border: 1px solid var(--ash); border-radius: var(--r-control);
  text-align: left; font-family: inherit; color: inherit; font-size: inherit;
  transition: border-color var(--t), background var(--t);
}
.cal-cell:disabled { cursor: default; }
.cal-cell.outside { opacity: .42; }
.cal-cell.today { border-color: var(--accent-text); background: var(--accent-soft); }
.cal-cell.has-events { cursor: pointer; }
.cal-cell.has-events:hover { border-color: var(--accent-text); }
.cal-cell.selected { border-color: var(--accent-text); }
.cal-cell-num { font-size: .82rem; font-weight: 700; color: var(--text-soft); flex-shrink: 0; }
.cal-cell.today .cal-cell-num { color: var(--accent-text); }
.cal-cell-events { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cal-chip {
  display: flex; align-items: baseline; gap: 5px; min-width: 0;
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--text-muted);
  border-radius: var(--r-nav); padding: 2px 5px;
}
/* Gli incontri prenotati da LocalMind hanno un link Meet: si distinguono. */
.cal-chip.has-meet { border-left-color: var(--accent-text); }
.cal-chip-time { font-size: .64rem; font-weight: 700; color: var(--text-faint); flex-shrink: 0; font-variant-numeric: tabular-nums; }
.cal-chip-title { font-size: .7rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-chip-more { font-size: .66rem; color: var(--text-faint); padding-left: 4px; }
.cal-daypanel { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 12px; }
.cal-daypanel-head { font-size: .84rem; font-weight: 700; margin-bottom: 9px; }
/* "martedì 22 settembre" → solo la prima lettera maiuscola: capitalize
   maiuscolerebbe anche il mese, che in italiano va minuscolo. */
.cal-daypanel-head::first-letter { text-transform: uppercase; }
.cal-daypanel-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; }

/* ── Vista settimanale ── */
.cal-week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.cal-day {
  min-width: 0; display: flex; flex-direction: column;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r-control);
  min-height: 220px;
}
.cal-day.today { border-color: var(--accent-text); background: var(--accent-soft); }
.cal-day-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 6px;
  padding: 8px 10px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.cal-dow { font-size: .7rem; font-weight: 700; color: var(--text-faint); }
.cal-dnum { font-size: 1rem; font-weight: 700; }
.cal-day.today .cal-dnum, .cal-day.today .cal-dow { color: var(--accent-text); }
.cal-day-body { flex: 1; padding: 7px; display: flex; flex-direction: column; gap: 6px; overflow-y: auto; min-width: 0; }

/* ── Scheda evento (pannello del giorno e vista settimanale) ── */
.cal-event {
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--text-muted);
  border-radius: var(--r-control); padding: 7px 8px; min-width: 0;
}
.cal-event.has-meet { border-left-color: var(--accent-text); }
.cal-event-time { font-size: .7rem; font-weight: 700; color: var(--text-faint); }
.cal-event-title { font-size: .8rem; font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; margin-top: 1px; }
.cal-event-att { font-size: .68rem; color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.cal-event-links { display: flex; gap: 10px; flex-wrap: wrap; }
.cal-event-meet, .cal-event-open {
  display: inline-block; margin-top: 5px; font-size: .7rem; font-weight: 700;
  color: var(--accent-text); text-decoration: none;
}
.cal-event-open { color: var(--text-faint); font-weight: 600; }
.cal-event-meet:hover, .cal-event-open:hover { text-decoration: underline; }
.cal-empty { color: var(--text-faint); font-size: .8rem; text-align: center; padding: 10px 0; }

@media (max-width: 900px) {
  /* Il mese resta a sette colonne (spezzarlo perde il senso della griglia):
     le celle si accorciano e l'orario sparisce dai chip. */
  .cal-cell { min-height: 74px; padding: 4px; }
  .cal-chip-time { display: none; }
  .cal-chip { padding: 1px 4px; }
  .cal-week { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cal-day { min-height: 140px; }
}

/* ── Conversazione con il lead (chat) ──
   Usata sia a tutta finestra (dal calendario) sia nella colonna accanto
   all'anteprima email. Bolle a destra per noi, a sinistra per il cliente. */
.conv { display: flex; flex-direction: column; min-height: 0; height: 100%; }
.conv-head { padding-bottom: 10px; border-bottom: 1px solid var(--border); margin-bottom: 10px; flex-shrink: 0; }
.conv-title { font-size: .95rem; font-weight: 700; }
.conv-sub { font-size: .76rem; color: var(--text-faint); margin-top: 2px; }
.conv-list {
  flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 10px;
  padding-right: 4px;
}
.conv.compact .conv-list { max-height: 460px; }
.conv-msg {
  max-width: 86%; border-radius: var(--r-panel); padding: 9px 12px; min-width: 0;
  border: 1px solid var(--border); background: var(--surface-1);
  animation: fade-in 160ms var(--ease);
}
.conv-msg.in { align-self: flex-start; border-bottom-left-radius: 4px; }
.conv-msg.out {
  align-self: flex-end; border-bottom-right-radius: 4px;
  background: var(--accent-soft); border-color: var(--accent-soft);
}
.conv-msg.is-draft { border-style: dashed; border-color: var(--accent-text); background: var(--shell); }
.conv-meta { display: flex; align-items: baseline; gap: 7px; flex-wrap: wrap; margin-bottom: 3px; }
.conv-who { font-size: .72rem; font-weight: 700; color: var(--text-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.conv-msg.out .conv-who { color: var(--accent-text); }
.conv-when { font-size: .68rem; color: var(--text-faint); margin-left: auto; white-space: nowrap; }
.conv-badge {
  font-size: .64rem; font-weight: 700;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-control); padding: 1px 7px; color: var(--text-muted);
}
.conv-badge.draft { color: var(--accent-text); border-color: var(--accent-text); }
.conv-subject { font-size: .8rem; font-weight: 600; margin-bottom: 3px; overflow-wrap: anywhere; }
.conv-body { font-size: .84rem; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.conv-body.missing { color: var(--text-faint); font-style: italic; font-size: .78rem; }
.conv-loading { display: flex; align-items: center; gap: 8px; color: var(--text-faint); font-size: .85rem; padding: 14px; }

/* Anteprima email: modulo a sinistra, conversazione a destra. */
.modal.modal-wide { width: min(1060px, 100%); }
.email-preview-split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.email-preview-conv {
  min-width: 0; border: 1px solid var(--border); border-radius: var(--r-control);
  background: var(--surface-1); padding: 12px; max-height: 60vh; overflow: hidden;
  display: flex; flex-direction: column;
}
.cal-event-conv {
  margin-top: 5px; font-size: .7rem; font-weight: 700; color: var(--accent-text);
  background: none; padding: 0; text-align: left;
}
.cal-event-conv:hover { text-decoration: underline; }
@media (max-width: 860px) {
  .email-preview-split { grid-template-columns: 1fr; }
  .email-preview-conv { max-height: 320px; }
}

/* ── Centro notifiche ── */
.ws-tab-badge, .ws-side-badge, .foot-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 19px; height: 19px; padding: 0 5px; border-radius: var(--r-control);
  background: var(--error); color: var(--surface); font-size: .68rem; font-weight: 700; line-height: 1;
}
.foot-badge { margin-left: auto; }
.notif-list { display: flex; flex-direction: column; }
.notif-row {
  display: flex; align-items: center; gap: 12px; padding: 13px 0;
  border-top: 1px solid var(--border); min-width: 0;
}
.notif-row:first-child { border-top: 0; }
.notif-icon { font-size: 1.15rem; flex-shrink: 0; width: 26px; text-align: center; }
.notif-body { flex: 1; min-width: 0; }
.notif-title { font-size: .92rem; font-weight: 600; overflow-wrap: anywhere; }
.notif-detail { font-size: .82rem; color: var(--text-muted); margin-top: 2px; overflow-wrap: anywhere; }
.notif-meta { font-size: .74rem; color: var(--text-faint); margin-top: 3px; }
.notif-row .notif-action { flex-shrink: 0; }
.notif-dismiss {
  flex-shrink: 0; width: 28px; height: 28px; font-size: 1.1rem; line-height: 1;
  color: var(--text-faint);
}
.notif-dismiss:hover { color: var(--error); background: var(--error-soft); }
/* Una bozza senza destinatario non è approvabile: l'azione porta al lead. */
.notif-draft_without_recipient .notif-icon { color: var(--error); }
.notif-draft_without_recipient .notif-action { background: var(--surface-2); color: var(--text-soft); }
@media (max-width: 640px) {
  .notif-row { flex-wrap: wrap; }
  .notif-row .notif-action { margin-left: 38px; }
}

/* ── Impostazioni Sales ── */
.settings-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.settings-row select {
  flex: 1; min-width: 240px; max-width: 460px; background: var(--surface-1); border: 1px solid var(--border-strong);
  border-radius: var(--r-control); padding: 10px 12px; font-size: .92rem; outline: none;
}
.settings-row select:focus { border-color: var(--accent-text); background: var(--surface); }
.prompt-phase + .prompt-phase { margin-top: 18px; }
.prompt-phase-title { font-size: .74rem; font-weight: 700; color: var(--text-faint); margin-bottom: 8px; }
.prompt-item { border: 1px solid var(--border); border-radius: var(--r-control); background: var(--surface-1); margin-bottom: 8px; }
.prompt-item[open] { background: var(--shell); }
.prompt-item summary {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; cursor: pointer;
  list-style: none; font-weight: 600; font-size: .92rem;
}
.prompt-item summary::-webkit-details-marker { display: none; }
.prompt-item summary::before { content: "▸"; color: var(--text-faint); font-size: .8rem; transition: transform var(--t); }
.prompt-item[open] summary::before { transform: rotate(90deg); }
.prompt-item-label { flex: 1; }
.prompt-item > .field-hint { padding: 0 14px; }
.prompt-item .field-hint code { background: var(--surface-2); padding: 1px 5px; border-radius: var(--r-nav); font-size: .76rem; }

/* ── Sales → Impostazioni → knowledge base commerciale ── */
.kb-label { display: block; font-size: .8rem; font-weight: 600; margin-bottom: 6px; }
.kb-docs-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 18px 0 8px; }
.kb-doc-list { display: flex; flex-direction: column; gap: 6px; }
.kb-doc-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: var(--r-control); background: var(--surface-1);
}
.kb-doc-icon { display: inline-flex; align-items: center; color: var(--stone); }
.kb-doc-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.kb-doc-name { font-size: .88rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kb-doc-sub { font-size: .74rem; color: var(--text-faint); }
.kb-doc-remove { flex-shrink: 0; }
.kb-empty { padding: 10px; border: 1px dashed var(--border); border-radius: var(--r-control); }
.kb-folder-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 4px; }
.kb-folder-chip {
  display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px; border-radius: var(--r-control); cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-1); font-size: .84rem; user-select: none;
}
.kb-folder-chip input { accent-color: var(--coral); margin: 0; }
.kb-folder-chip.on { border-color: var(--accent-text); background: var(--accent-soft); color: var(--accent-text); }
.kb-folder-chip .kb-folder-n { font-size: .72rem; color: var(--text-faint); }
.kb-doc-folder { font-size: .72rem; color: var(--accent-text); }
.kb-preview { margin-top: 14px; }
.kb-preview summary { cursor: pointer; font-size: .82rem; color: var(--text-faint); }
.kb-preview input[type="text"] {
  flex: 1; min-width: 200px; padding: 7px 10px; border: 1px solid var(--border);
  border-radius: var(--r-control); background: var(--surface-1); font: inherit;
}
.kb-preview-out {
  margin-top: 8px; max-height: 320px; overflow: auto; white-space: pre-wrap; font-size: .76rem;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r-control); padding: 10px;
}
.prompt-text {
  display: block; width: calc(100% - 28px); margin: 10px 14px 0; padding: 12px; box-sizing: border-box;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .8rem; line-height: 1.5;
  background: var(--surface-1); border: 1px solid var(--border-strong); border-radius: var(--r-control);
  resize: vertical; outline: none; color: var(--text);
}
.prompt-text:focus { border-color: var(--accent-text); background: var(--surface); }
.prompt-text[readonly] { color: var(--text-muted); }
.prompt-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 14px 14px; }
.prompt-actions .prompt-msg { margin: 0; }

.sales-empty { text-align: center; padding: 60px 20px; max-width: 460px; margin: 0 auto; }
.sales-empty h3 { font-size: 1.1rem; font-weight: 700; margin-bottom: 6px; }
.sales-empty p { font-size: .9rem; color: var(--text-muted); line-height: 1.5; }

.sales-toolbar { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }

/* ── Banner di avanzamento "cerca aziende + analisi AI" ──────────────────
   Il job gira sul server (vedi app.sales.service.run_discovery_job) e può
   durare minuti: qui si mostra a che punto è, aggiornato dal polling su
   .../discover/status. */
.sales-progress-banner {
  flex-shrink: 0;
  background: var(--surface-1);
  border: 1px solid var(--accent);
  border-radius: var(--r-panel);
  padding: 14px 16px;
  display: flex; flex-direction: column; gap: 10px;
}
.sales-progress-banner .spb-head { display: flex; align-items: center; gap: 11px; }
.sales-progress-banner .spb-texts { display: flex; flex-direction: column; min-width: 0; }
.sales-progress-banner .spb-title { font-size: .92rem; font-weight: 700; color: var(--text); }
.sales-progress-banner .spb-detail {
  font-size: .84rem; color: var(--text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sales-progress-banner .spb-bar {
  height: 7px; border-radius: var(--r-control);
  background: var(--surface-3); overflow: hidden;
}
.sales-progress-banner .spb-fill {
  height: 100%; border-radius: var(--r-control);
  background: var(--coral);
  transition: width 400ms var(--ease);
}
.sales-progress-banner .spb-hint { font-size: .78rem; color: var(--text-faint); }

/* ── Campi ausiliari nelle modali (form campagna) ──
   .check-row è già definita sopra sotto .modal-body (con specificità
   maggiore): qui serve solo la riga di aiuto sotto ai campi. */
.field-hint { font-size: .78rem; color: var(--text-faint); margin: 4px 0 2px; line-height: 1.45; }

.status-pill {
  display: inline-flex; align-items: center; padding: 3px 10px;
  border-radius: var(--r-control); font-size: .74rem; font-weight: 600;
  background: var(--surface-2); color: var(--text-soft); white-space: nowrap;
}
/* Solo gli stati su cui c'è qualcosa da fare prendono colore. Tingere di
   corallo chiaro anche "nuovo", "qualificato" e "contattato" riempiva l'elenco
   di macchie e faceva sparire proprio quelli che chiedono una mossa. */
.status-pill.pill-active, .status-pill.pill-won { background: var(--success-soft); color: var(--graphite); }
.status-pill.pill-replied, .status-pill.pill-interested,
.status-pill.pill-meeting, .status-pill.pill-proposal { background: var(--coral-soft); color: var(--graphite); }
.status-pill.pill-new, .status-pill.pill-qualified, .status-pill.pill-contacted,
.status-pill.pill-researching, .status-pill.pill-paused, .status-pill.pill-draft,
.status-pill.pill-completed, .status-pill.pill-lost,
.status-pill.pill-not_interested { background: var(--sand-sunk); color: var(--stone); }

.data-table { border: 1px solid var(--border); border-radius: var(--r-control); overflow: hidden; background: var(--surface); }
.data-table-scroll { overflow-x: auto; }
.data-table-row {
  display: grid; align-items: center; gap: 8px; padding: 10px 12px; font-size: .85rem;
}
.data-table-row.head {
  background: var(--surface-1); font-weight: 700; font-size: .7rem;
 color: var(--text-faint);
}
.data-table-row:not(.head) + .data-table-row { border-top: 1px solid var(--border); }
.data-table-row:not(.head):hover { background: var(--surface-1); }
.data-table-cell { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.data-table-cell.wrap { white-space: normal; }
.data-table-actions { display: flex; gap: 5px; flex-wrap: wrap; justify-content: flex-end; }
.data-table-actions .icon-btn { width: 30px; height: 30px; }

.sales-campaigns-table { overflow-x: auto; max-width: 100%; }
.sales-campaigns-table .data-table-row {
  /* La colonna azioni ospita 5 controlli ("Cerca e analizza" è il più largo):
     con 230px andavano a capo su due righe. */
  grid-template-columns: minmax(150px,1.6fr) minmax(120px,1.2fr) minmax(90px,.9fr) 70px 70px 90px 90px 80px 90px 100px minmax(330px,2.2fr);
  min-width: 1320px;
}
.sales-leads-table { overflow-x: auto; max-width: 100%; }
.sales-leads-table .data-table-row {
  grid-template-columns: minmax(150px,1.8fr) 70px minmax(100px,1fr) minmax(120px,1.3fr) 150px;
  min-width: 700px;
}

/* Stesso pulsante di "Torna a LocalMind" in testa alla pagina (.workspace-back):
   era una scritta grigia senza bordo, poco visibile e poco cliccabile. In una
   colonna flex va tenuto alla sua larghezza naturale. */
.sales-back-btn { align-self: flex-start; }

/* Lead detail modal */
.lead-detail-container { display: flex; flex-direction: column; gap: 20px; }
.lead-detail-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.lead-detail-header h2 { margin: 0; font-size: 1.4rem; font-weight: 700; }
.lead-company-info { font-size: .88rem; color: var(--text-muted); margin-top: 4px; }
.lead-company-info a { color: var(--accent-text); }
.lead-status-badges { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.lead-actions-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
/* .btn-primary è width:100% di default (nasce per i form): in una barra di
   azioni si prendeva tutta la riga e mandava a capo gli altri pulsanti. */
.lead-actions-bar .btn-primary { width: auto; padding: 10px 18px; }
.lead-actions-bar .btn-soft { padding: 10px 16px; }

/* ── Badge di stato/priorità/punteggio nel dettaglio lead ──
   .priority-pill e .score-pill erano usate dal markup ma non definite: i
   badge finivano a testo nudo in alto a destra, senza sfondo né colore. */
.priority-pill, .score-pill {
  display: inline-flex; align-items: center;
  padding: 4px 11px; border-radius: var(--r-control);
  font-size: .74rem; font-weight: 700; letter-spacing: .03em;
  background: var(--surface-2); color: var(--text-muted);
}
.priority-pill.priority-HIGH { background: var(--coral); color: var(--graphite); }
.priority-pill.priority-MEDIUM { background: var(--sand-sunk); color: var(--stone); }
.priority-pill.priority-LOW { background: var(--sand); color: var(--stone); }
.score-pill { background: var(--accent-soft); color: var(--accent-text); }
/* auto-fit invece di 1fr 1fr: sotto i ~900px le due colonne diventavano
   troppo strette e contatti/ricerca risultavano illeggibili. */
.lead-detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 20px; }
.lead-section { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r-control); padding: 16px; min-width: 0; }
.lead-section .outreach-body, .lead-section .email-body-preview, .lead-section .research-summary {
  /* URL ed email lunghe uscivano dal riquadro invece di andare a capo */
  overflow-wrap: anywhere; white-space: pre-wrap;
}
.lead-contact-item a, .lead-company-info a { overflow-wrap: anywhere; }
.lead-section h3 { margin: 0 0 12px; font-size: .95rem; font-weight: 700; color: var(--text-soft); }
.lead-section.full-width { grid-column: 1 / -1; }

/* Lead contacts */
.lead-contacts-list { display: flex; flex-direction: column; gap: 10px; }
.lead-contact-item { padding: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-control); }
.contact-name { font-weight: 600; }
.contact-role { font-size: .82rem; color: var(--text-muted); margin-top: 2px; }
.contact-email { font-size: .82rem; margin-top: 4px; }
.contact-email a { color: var(--accent-text); }
.contact-phone, .contact-linkedin { font-size: .82rem; margin-top: 2px; }
.contact-phone a, .contact-linkedin a { color: var(--accent-text); }
.contact-source { display: flex; align-items: center; gap: 6px; margin-top: 6px; font-size: .76rem; }
.source-pill { padding: 2px 8px; border-radius: var(--r-control); background: var(--surface-2); }
.confidence { color: var(--text-faint); }

/* Lead research */
.lead-research-list { display: flex; flex-direction: column; gap: 12px; }
.research-item { padding: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-control); }
.research-summary { font-size: .9rem; line-height: 1.5; }
.research-section { margin-top: 8px; font-size: .84rem; }
.research-meta { margin-top: 8px; font-size: .78rem; color: var(--text-faint); }

/* Outreach items */
.lead-outreach-list { display: flex; flex-direction: column; gap: 12px; }
.outreach-item { padding: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-control); }
.outreach-item.sent { border-left: 3px solid var(--success); }
.outreach-item.replied { border-left: 3px solid var(--accent); }
.outreach-item.draft { border-left: 3px solid var(--text-muted); }
.outreach-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.outreach-channel { font-size: .78rem; font-weight: 600; color: var(--text-muted); }
.outreach-status { font-size: .74rem; }
.outreach-recipient { font-size: .82rem; color: var(--text-soft); margin-bottom: 4px; }
.outreach-subject { font-size: .88rem; margin-bottom: 6px; }
.outreach-body { font-size: .84rem; color: var(--text-soft); white-space: pre-wrap; max-height: 120px; overflow-y: auto; }
.outreach-meta { margin-top: 8px; font-size: .76rem; color: var(--text-faint); }

/* Email history */
.lead-email-history-list { display: flex; flex-direction: column; gap: 12px; }
.email-history-item { padding: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-control); }
.email-history-item.sent { border-left: 3px solid var(--accent); }
.email-history-item.received { border-left: 3px solid var(--success); }
.email-history-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.email-direction { font-size: .82rem; font-weight: 600; }
.email-date { font-size: .76rem; color: var(--text-faint); }
.email-subject { font-size: .88rem; margin-bottom: 6px; }
.email-participants { display: flex; gap: 16px; font-size: .8rem; color: var(--text-soft); margin-bottom: 6px; }
.email-body-preview { font-size: .84rem; color: var(--text-muted); padding: 8px; background: var(--surface-1); border-radius: var(--r-control); margin-top: 8px; }
.email-classification { display: flex; gap: 8px; align-items: center; margin-top: 8px; font-size: .76rem; }
.classification-category { font-weight: 600; }
.classification-sentiment { color: var(--text-muted); }
.meeting-interest { color: var(--success); }

/* Classification category colors */
.pill-interested { background: var(--success-soft); color: var(--success); }
.pill-asked_for_meeting { background: var(--success-soft); color: var(--success); }
.pill-asked_for_info { background: var(--accent-soft); color: var(--accent-text); }
.pill-not_now { background: var(--sand-sunk); color: var(--stone); }
.pill-out_of_office { background: var(--surface-2); color: var(--text-muted); }
.pill-wrong_contact { background: var(--surface-2); color: var(--text-muted); }
.pill-unsubscribe { background: var(--sand-sunk); color: var(--stone); }
.pill-not_interested { background: var(--error-soft); color: var(--error); }
.pill-unknown { background: var(--surface-2); color: var(--text-muted); }

.sales-detail-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; flex-shrink: 0; }
.sales-detail-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.sales-detail-head h3 { font-size: 1.05rem; font-weight: 700; }
.sales-detail-head p { font-size: .84rem; color: var(--text-muted); }

.sales-filter-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.sales-filter-chips .chip-btn.active { border-color: var(--accent-text); color: var(--accent-text); background: var(--accent-soft); }

/* Kanban board */
.sales-view-toggle { display: flex; gap: 6px; }
/* La board occupa l'altezza disponibile della pagina invece di una card da
   500px: prima le colonne con più di 3-4 lead venivano tagliate e il resto
   spariva dietro uno scroll interno poco visibile. */
.kanban-board {
  display: flex; gap: 8px;
  overflow-x: auto; overflow-y: hidden;
  flex: 1; min-height: 340px;
  padding-bottom: 10px;
  scrollbar-width: thin;
}
.kanban-column {
  /* Otto colonne che si spartiscono la larghezza ma mai sotto i 200px: a
     167px (tutte a forza in 1400px) titoli e nomi si troncavano. Su un
     monitor da 1920 stanno tutte; sotto, la board scorre in orizzontale. */
  flex: 1 1 220px;
  min-width: 200px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
  /* (il vecchio min-width:0 anti-blowout non serve più: le card hanno
     overflow-wrap e line-clamp, e stava azzerando il floor di 200px) */
  max-height: 100%;
}
.kanban-column.closed { background: transparent; border-style: dashed; }
.kanban-column-header {
  flex-shrink: 0;
  padding: 10px 10px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: .88rem;
  border-radius: var(--r-panel) var(--r-panel) 0 0;
}
.kanban-column-icon { font-size: 1rem; }
.kanban-column-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kanban-column-count { 
  background: var(--text-muted); 
  color: var(--surface); 
  font-size: .72rem; 
  padding: 2px 8px; 
  border-radius: var(--r-control); 
  font-weight: 600;
}
.kanban-column-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 100px;
  min-width: 0;
}
/* inset invece di border: un bordo vero cambierebbe l'altezza della colonna
   e farebbe "saltare" tutta la board mentre si trascina una card. */
.kanban-column-body.drag-over {
  background: var(--accent-soft);
  border-radius: 0 0 var(--r-panel) var(--r-panel);
}
.kanban-empty-column { 
  color: var(--text-faint); 
  font-size: .82rem; 
  text-align: center; 
  padding: 20px 10px; 
}

/* Kanban cards */
.kanban-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-control);
  padding: 10px 11px;
  cursor: pointer;
  min-width: 0;
  transition: transform var(--t);
  border-left: 3px solid var(--text-muted);
}
.kanban-card:focus-visible { outline-offset: 1px; }
.kanban-card:hover { 
}
.kanban-card.dragging { 
  opacity: 0.5; 
  transform: rotate(2deg); 
}
.kanban-card.priority-HIGH { border-left-color: var(--coral); }
.kanban-card.priority-MEDIUM { border-left-color: var(--stone); }
.kanban-card.priority-LOW { border-left-color: var(--ash); }
.kanban-card-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 8px; }
/* Due righe invece di una sola troncata: le ragioni sociali reali ("Avvocato
   Giuseppe Sabbatella - Avvocato Cassazionista specializzato in…") con
   l'ellissi su una riga diventavano indistinguibili tra loro. */
.kanban-card-company {
  background: none; border: none; padding: 0; text-align: left;
  font-family: inherit; color: inherit; cursor: pointer;
  font-weight: 700; font-size: .92rem; line-height: 1.3;
  flex: 1; min-width: 0;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; overflow-wrap: anywhere;
}
.kanban-card-score { 
  background: var(--surface-2); 
  padding: 2px 8px; 
  border-radius: var(--r-control); 
  font-size: .76rem; 
  font-weight: 600; 
  color: var(--text-soft);
}
.kanban-card-body { display: flex; flex-direction: column; gap: 6px; }
.kanban-card-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: .76rem; color: var(--text-muted); min-width: 0; overflow-wrap: anywhere; margin-bottom: 6px; }
.kanban-card-meta .status-pill { padding: 2px 8px; font-size: .68rem; }
.kanban-card-city, .kanban-card-industry { display: inline-flex; align-items: center; gap: 4px; }
.kanban-card-website {
  font-size: .78rem;
  color: var(--accent-text);
  text-decoration: none;
  min-width: 0; max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.kanban-card-website:hover { text-decoration: underline; }
.kanban-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  margin-top: 10px; 
  padding-top: 8px; 
  border-top: 1px solid var(--border); 
  font-size: .76rem;
}
.kanban-card-priority { 
  padding: 2px 8px; 
  border-radius: var(--r-control); 
  font-weight: 600; 
}
.kanban-card-priority.priority-HIGH { background: var(--coral); color: var(--graphite); }
.kanban-card-priority.priority-MEDIUM { background: var(--sand-sunk); color: var(--stone); }
.kanban-card-priority.priority-LOW { background: var(--sand); color: var(--stone); }
.kanban-card-date { color: var(--text-faint); }

/* toast */
/* Il toast è grafite. L'esito lo dice un filo di colore a sinistra: verde se
   è andata, corallo se serve attenzione — non un fondo rosso, che qui
   sarebbe indistinguibile dal corallo del marchio. */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(8px);
  background: var(--graphite); color: var(--surface);
  border-left: 3px solid var(--graphite-up);
  padding: 9px 16px; border-radius: var(--r-control); font-size: .88rem; z-index: 80;
  opacity: 0; transition: opacity var(--t), transform var(--t);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { border-left-color: var(--green-on-dark); }
.toast.error { border-left-color: var(--coral); }

/* ============================================================================
   Animazioni
   ========================================================================== */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pop-in { from { opacity: 0; transform: scale(.98); } to { opacity: 1; transform: scale(1); } }

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

/* ============================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1180px) {
  .context-panel { position: absolute; right: 0; top: 0; bottom: 0; z-index: 20; }
}

@media (max-width: 900px) {
  html { font-size: 16px; }
  #main-view { padding: 0; }
  .app-shell { border-radius: 0; border: none; }
  .sidebar {
    position: absolute; left: 0; top: 0; bottom: 0; z-index: 30;
    width: min(var(--sidebar-w), 84vw); min-width: min(var(--sidebar-w), 84vw);
  }
  .sidebar.collapsed { margin-left: min(calc(-1 * var(--sidebar-w)), -84vw); }
  .context-panel { width: min(var(--ctx-w), 88vw); min-width: min(var(--ctx-w), 88vw); }
  .context-panel.collapsed { margin-right: min(calc(-1 * var(--ctx-w)), -88vw); }
  .overlay { padding: 0; }
  .explorer, .settings-card { border-radius: 0; width: 100%; height: 100%; max-height: 100%; }
  .explorer-side { display: none; }
  .messages { padding-left: 16px; padding-right: 16px; }
  .input-dock { padding-left: 12px; padding-right: 12px; }
  .ai-body { padding-left: 0; }
  .palette-overlay { padding: 0; padding-top: 0; align-items: flex-start; }
  .palette { border-radius: 0; width: 100%; }
  .modal { border-radius: 0; width: 100%; height: 100%; }
}

/* ══════════════════════════════════════════════════════════════════════════
   WhatsApp — pannello di pairing + lista chat/conversazione

   Riusa il guscio .overlay/.explorer del pannello Email: qui ci sono solo le
   parti che quel pannello non ha (il QR di collegamento e le bolle dei
   messaggi). I colori restano quelli del tema LocalMind, non quelli di
   WhatsApp: il pannello deve sembrare parte dell'app, non un'imitazione.
   ══════════════════════════════════════════════════════════════════════════ */

.wa-head-right { display: flex; align-items: center; gap: 10px; }

/* Pastiglia di stato: un colpo d'occhio su collegato / in attesa / errore. */
.wa-state {
  font-size: .78rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--r-control);
  background: var(--surface-2);
  color: var(--text-muted);
  white-space: nowrap;
}
.wa-state.is-connected { background: var(--success-soft); color: var(--success); }
.wa-state.is-waiting   { background: var(--accent-soft);  color: var(--accent-text); }
.wa-state.is-error     { background: var(--error-soft);   color: var(--error); }

/* ── Vista di pairing ──────────────────────────────────────────────────── */
.wa-pairing {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 40px;
  padding: 28px;
  flex-wrap: wrap;
}

.wa-qr-box {
  position: relative;
  width: 280px;
  height: 280px;
  display: grid;
  place-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-panel);
}
.wa-qr { width: 256px; height: 256px; display: none; image-rendering: pixelated; }
.wa-qr.is-ready { display: block; }
.wa-qr-placeholder { position: absolute; font-size: .85rem; color: var(--text-faint); text-align: center; padding: 0 20px; }
.wa-qr.is-ready + .wa-qr-placeholder { display: none; }

.wa-pairing-steps { max-width: 320px; }
.wa-pairing-steps h3 { margin: 0 0 12px; font-size: 1.05rem; color: var(--text); }
.wa-pairing-steps ol { margin: 0 0 16px; padding-left: 20px; color: var(--text-soft); line-height: 1.9; }
.wa-hint { font-size: .82rem; color: var(--text-faint); line-height: 1.6; margin: 0 0 8px; }

/* ── Lista chat ────────────────────────────────────────────────────────── */
.wa-search {
  width: 100%;
  margin: 8px 0 10px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-control);
  background: var(--surface-1);
  font: inherit;
  font-size: .86rem;
  color: var(--text);
}
.wa-search:focus { outline: none; border-color: var(--accent-text); background: var(--surface); }

.wa-chat-list { overflow-y: auto; flex: 1; min-height: 0; }

.wa-chat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  padding: 9px 11px;
  border: 0;
  border-radius: var(--r-control);
  background: transparent;
  text-align: left;
  cursor: pointer;
  font: inherit;
}
.wa-chat:hover { background: var(--surface-2); }
.wa-chat.is-active { background: var(--accent-soft); }
.wa-chat-top { display: flex; align-items: baseline; gap: 8px; }
.wa-chat-name {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  font-size: .9rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.wa-chat-time { font-size: .72rem; color: var(--text-faint); flex-shrink: 0; }
.wa-chat-preview {
  font-size: .8rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.wa-unread {
  flex-shrink: 0;
  min-width: 18px;
  padding: 0 5px;
  border-radius: var(--r-control);
  background: var(--accent);
  color: var(--surface);
  font-size: .7rem;
  font-weight: 700;
  text-align: center;
  line-height: 18px;
}

/* ── Conversazione ─────────────────────────────────────────────────────── */
.wa-main { padding: 0; }

.wa-conv-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
}
.wa-conv-head .wa-conv-sub { font-weight: 400; font-size: .8rem; color: var(--text-faint); }

.wa-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface-1);
}

.wa-msg {
  max-width: min(72%, 560px);
  padding: 8px 12px;
  border-radius: var(--r-panel);
  background: var(--surface);
  border: 1px solid var(--border);
  align-self: flex-start;
}
/* I messaggi inviati stanno a destra, come in ogni client di messaggistica. */
.wa-msg.is-mine { align-self: flex-end; background: var(--accent-soft); border-color: transparent; }
.wa-msg-author { font-size: .74rem; font-weight: 700; color: var(--accent-text); margin-bottom: 2px; }
.wa-msg-text { font-size: .9rem; line-height: 1.5; color: var(--text); white-space: pre-wrap; word-break: break-word; }
.wa-msg-meta { font-size: .68rem; color: var(--text-faint); text-align: right; margin-top: 3px; }
/* Allegati non testuali: il bridge non li scarica, si indica solo il tipo. */
.wa-msg-kind { font-size: .82rem; font-style: italic; color: var(--text-muted); }

.wa-day {
  align-self: center;
  font-size: .72rem;
  color: var(--text-muted);
  background: var(--surface-3);
  padding: 3px 12px;
  border-radius: var(--r-control);
  margin: 6px 0;
}

.wa-composer {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.wa-composer textarea {
  flex: 1;
  resize: none;
  max-height: 120px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-control);
  background: var(--surface-1);
  font: inherit;
  font-size: .9rem;
  color: var(--text);
  line-height: 1.5;
}
.wa-composer textarea:focus { outline: none; border-color: var(--accent-text); background: var(--surface); }

@media (max-width: 900px) {
  .wa-pairing { gap: 24px; }
  .wa-msg { max-width: 86%; }
}

/* LED di stato accanto alla voce WhatsApp in sidebar.
   La tab è sempre visibile (prima compariva solo dopo che la sonda rispondeva,
   quindi appariva secondi dopo Documenti e Sales): il LED dice se l'account è
   collegato senza bisogno di aprire il pannello. */
.conn-led {
  /* `flex: 0 0 8px`, not just flex-shrink: the sidebar button stretches its
     spans with `flex: 1`, which was turning the LED into a long horizontal
     bar. The selector above now excludes it too; this is the belt to that
     braces. */
  flex: 0 0 8px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
  outline: 2px solid color-mix(in srgb, var(--surface) 60%, transparent);
  transition: background .25s ease;
}
.conn-led.is-on  { background: var(--success); }
.conn-led.is-off { background: var(--error); }
/* Pulsa solo mentre sta tentando: un LED che lampeggia sempre è rumore. */
.conn-led.is-pending { background: var(--accent); animation: ledPulse 1.4s ease-in-out infinite; }
@keyframes ledPulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

/* Una tab di una funzione non disponibile resta visibile ma spenta, invece di
   sparire: l'assenza di un pulsante è più confusa di un pulsante inattivo. */
.foot-btn.is-unavailable { opacity: .45; }
.foot-btn.is-unavailable:hover { background: transparent; cursor: default; }

/* ── Allegati nelle bolle ─────────────────────────────────────────────── */
/* Ogni elemento multimediale nasce con dimensioni note (min-height / aspect
   ratio) così la conversazione non "salta" mentre gli allegati si caricano
   uno dopo l'altro. */
.wa-media-img,
.wa-media-video {
  display: block;
  max-width: 100%;
  width: 260px;
  min-height: 120px;
  border-radius: 10px;
  background: var(--surface-2);
  margin-bottom: 4px;
  cursor: zoom-in;
  object-fit: cover;
}
.wa-media-img.is-ready,
.wa-media-video.is-ready {
  min-height: 0;
  height: auto;
  background: transparent;
  /* Il segnaposto è un riquadro fisso e `cover` lo riempie; a file caricato
     la proporzione la detta il contenuto, e `cover` ritaglierebbe. */
  object-fit: contain;
}
.wa-media-video { cursor: default; }

.wa-media-audio {
  display: block;
  width: 240px;
  max-width: 100%;
  height: 38px;
  margin-bottom: 4px;
}

.wa-media-file {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-1);
  font: inherit;
  font-size: .85rem;
  color: var(--text);
  text-align: left;
  cursor: wait;
  margin-bottom: 4px;
}
.wa-media-file.is-ready { cursor: pointer; }
.wa-media-file.is-ready:hover { background: var(--surface-2); }

/* Allegato che il bridge non riesce a scaricare: quasi sempre una chat
   sincronizzata prima che conservasse il protobuf, non un file scaduto. Il
   pulsante chiede a WhatsApp di rimandare quel pezzo di cronologia. */
.wa-media-missing { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.wa-media-retry {
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: var(--r-control);
  background: var(--surface-1);
  font: inherit;
  font-size: .78rem;
  color: var(--accent-text);
}
.wa-media-retry:hover:not(:disabled) { background: var(--surface-2); }
.wa-media-retry:disabled { color: var(--text-muted); cursor: default; }

/* Allegati elencati in una bozza WhatsApp preparata dall'assistente. */
.wa-draft-file {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  margin: 2px 4px 2px 0;
  border: 1px solid var(--border);
  border-radius: var(--r-control);
  background: var(--surface-1);
  font-size: .8rem;
}

/* I link nei messaggi: visibili come link, ma senza gridare. */
.wa-link { color: var(--accent); text-decoration: underline; word-break: break-all; }
.wa-msg.is-mine .wa-link { color: var(--accent); }

/* Immagine a schermo intero al click.

   I limiti dell'immagine sono in unità di viewport, non in percentuale. Una
   percentuale si misura sull'area della griglia, che qui è dimensionata sul
   contenuto — cioè sull'immagine stessa: il browser non può risolvere il
   riferimento circolare, tratta `max-height: 100%` come `none` e lascia la
   foto alla sua dimensione naturale, più alta dello schermo e tagliata sopra
   e sotto. `vw`/`vh` si misurano sulla finestra e non hanno questo problema. */
.wa-lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--graphite) 82%, transparent);
  padding: 56px 24px 24px;
  /* Serve solo quando l'immagine è a grandezza reale (.is-zoom): altrimenti
     entra sempre e non c'è niente da scorrere. */
  overflow: auto;
  overscroll-behavior: contain;
  animation: fade-in 130ms var(--ease);
}
.wa-lightbox img {
  display: block;
  max-width: calc(100vw - 48px);
  max-height: calc(100vh - 80px);
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: var(--r-panel);
  cursor: zoom-in;
}
/* Secondo clic: grandezza reale, con scorrimento. Per leggere il numero su
   una fattura fotografata, adattare alla finestra non basta. */
.wa-lightbox img.is-zoom {
  max-width: none;
  max-height: none;
  cursor: zoom-out;
  /* `margin: auto` centra dentro un contenitore che scorre; `align-items`
     da solo taglierebbe il bordo superiore rendendolo irraggiungibile. */
  margin: auto;
}
.wa-lightbox-bar {
  position: fixed;
  top: 12px;
  right: 16px;
  display: flex;
  gap: 8px;
  z-index: 1;
}
.wa-lightbox-bar button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: var(--r-control);
  border: 1px solid color-mix(in srgb, var(--surface) 35%, transparent);
  background: color-mix(in srgb, var(--graphite) 55%, transparent);
  color: var(--reverse);
}
.wa-lightbox-bar button:hover { background: color-mix(in srgb, var(--graphite) 80%, transparent); }

/* ── Avatar ───────────────────────────────────────────────────────────── */
/* Le iniziali restano visibili sotto: se la foto non c'è (la maggior parte
   delle chat) non resta un buco grigio. */
.wa-avatar {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--surface-3);
  color: var(--text-muted);
  font-size: .8rem;
  font-weight: 700;
  overflow: hidden;
  position: relative;
}
.wa-avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity .2s ease;
}
.wa-avatar img.is-ready { opacity: 1; }
.wa-avatar.is-group { border-radius: 30%; }

.wa-chat { flex-direction: row; align-items: center; gap: 10px; }
.wa-chat-lines { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }

.wa-conv-avatar { width: 34px; height: 34px; font-size: .72rem; }

/* ── Spunte di consegna ───────────────────────────────────────────────── */
.wa-ticks { margin-left: 4px; letter-spacing: -2px; }
.wa-ticks.is-read { color: #3b9ae1; }

/* ── Citazioni ────────────────────────────────────────────────────────── */
.wa-quoted {
  border-left: 3px solid var(--accent);
  padding: 4px 8px;
  margin-bottom: 4px;
  border-radius: 4px;
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  font-size: .8rem;
  color: var(--text-muted);
  max-height: 3.2em;
  overflow: hidden;
}

.wa-msg { position: relative; }
/* L'azione "rispondi" compare al passaggio del mouse, per non occupare
   spazio permanente in ogni bolla. */
.wa-reply-btn {
  position: absolute;
  top: 2px;
  right: 4px;
  border: 0;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  opacity: 0;
  font-size: .95rem;
  padding: 2px 4px;
  border-radius: 6px;
  transition: opacity .15s ease;
}
.wa-msg:hover .wa-reply-btn { opacity: 1; }
.wa-reply-btn:hover { background: var(--surface-2); color: var(--text); }

.wa-reply-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 18px;
  border-top: 1px solid var(--border);
  background: var(--surface-1);
}
.wa-reply-body { flex: 1; min-width: 0; border-left: 3px solid var(--accent); padding-left: 8px; }
.wa-reply-label { display: block; font-size: .7rem; font-weight: 700; color: var(--accent); }
.wa-reply-text {
  display: block;
  font-size: .82rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Anteprima dell'allegato scelto, prima dell'invio. */
.wa-pending-file {
  display: flex;
  align-items: center;
  gap: 8px;
  /* Si possono scegliere più file: vanno a capo invece di schiacciarsi. */
  flex-wrap: wrap;
  padding: 8px 18px;
  border-top: 1px solid var(--border);
  background: var(--accent-soft);
  font-size: .85rem;
  color: var(--text);
}
.wa-pending-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 2px 4px 2px 8px;
  border: 1px solid var(--border);
  border-radius: var(--r-control);
  background: var(--surface);
}
.wa-pending-file .wa-pending-name { min-width: 0; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ============================================================================
   Invio sicuro + importazione lead
   ----------------------------------------------------------------------------
   Nessuna ombra e nessun esadecimale: solo token di tokens.css, come il resto
   dell'applicazione. I tre stati (ok / attenzione / errore) usano verde,
   grafite e corallo — non esiste un rosso separato.
   ========================================================================== */

/* ── Controllo anti-spam nell'anteprima email ── */
.spam-check { margin-top: 10px; }
.spam-head { display: flex; align-items: center; gap: 8px; font-size: .82rem; }
.spam-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--stone); flex-shrink: 0; }
.spam-level-ok .spam-dot { background: var(--green); }
.spam-level-attenzione .spam-dot { background: var(--stone); }
.spam-level-rischio .spam-dot { background: var(--coral); }
.spam-level-ok b { color: var(--green); }
.spam-level-rischio b { color: var(--coral-ink); }
.spam-count {
  font-size: .72rem; color: var(--stone); border: 1px solid var(--ash);
  border-radius: 999px; padding: 0 7px; line-height: 1.5;
}
.spam-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 5px; }
.spam-finding {
  font-size: .78rem; color: var(--stone); padding-left: 12px; position: relative; line-height: 1.45;
}
.spam-finding::before {
  content: ""; position: absolute; left: 0; top: .55em;
  width: 4px; height: 4px; border-radius: 50%; background: var(--ash);
}
.spam-high::before { background: var(--coral); }
.spam-high { color: var(--graphite); }

/* ── Pannello invio sicuro ── */
.send-usage { border: 1px solid var(--ash); border-radius: var(--r-panel); padding: 12px; }
.send-usage-main { display: flex; align-items: baseline; gap: 8px; }
.send-usage-main .num { font-size: 1.5rem; font-weight: 700; }
.send-usage-main span { font-size: .82rem; color: var(--stone); }
.send-usage-bar {
  height: 6px; border-radius: 3px; background: var(--ash); overflow: hidden; margin: 8px 0 6px;
}
.send-usage-fill { height: 100%; background: var(--coral); }

.send-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px; margin: 12px 0;
}
.send-grid label { display: flex; flex-direction: column; gap: 4px; }
.send-grid span { font-size: .75rem; color: var(--stone); }
.send-grid input {
  border: 1px solid var(--ash); border-radius: var(--r-control); padding: 7px 9px;
  background: var(--surface); color: var(--graphite); font: inherit; font-size: .85rem; width: 100%;
}
.send-days { margin: 4px 0 14px; }
.send-days-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.send-day {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  border: 1px solid var(--ash); border-radius: 999px; padding: 4px 11px; font-size: .78rem;
}
.send-day input { display: none; }
.send-day.on { border-color: var(--coral); color: var(--coral-ink); background: var(--coral-soft); }
.send-sub { margin-top: 18px; border-top: 1px solid var(--ash); padding-top: 12px; }

/* ── Diagnostica DNS ── */
.dns-report { margin-top: 10px; display: grid; gap: 8px; }
.dns-check {
  display: flex; gap: 10px; align-items: flex-start;
  border: 1px solid var(--ash); border-radius: var(--r-panel); padding: 10px;
}
.dns-check p { font-size: .78rem; color: var(--stone); margin: 3px 0 0; line-height: 1.45; }
.dns-check b { font-size: .82rem; }
.dns-badge {
  width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center;
  font-size: .72rem; font-weight: 700; flex-shrink: 0; background: var(--ash); color: var(--graphite);
}
.dns-ok .dns-badge { background: var(--success-soft); color: var(--green); }
.dns-warn .dns-badge { background: var(--sand); color: var(--stone); }
.dns-fail .dns-badge { background: var(--coral-soft); color: var(--coral-ink); }
.dns-detail {
  display: block; margin-top: 5px; font-size: .72rem; color: var(--stone);
  background: var(--sand); border-radius: var(--r-nav); padding: 5px 7px; word-break: break-all;
}

/* ── Liste: da non ricontattare, coda di invio ── */
.supp-list, .outbox-list { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 4px; }
.supp-list li, .outbox-list li {
  display: flex; align-items: center; gap: 10px; font-size: .8rem;
  border: 1px solid var(--ash); border-radius: var(--r-panel); padding: 7px 10px;
}
.supp-addr { font-weight: 600; }
.supp-reason, .supp-date, .outbox-when { color: var(--stone); font-size: .75rem; }
.supp-date { margin-left: auto; }
.outbox-list li > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.outbox-subject { color: var(--stone); font-size: .75rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Importazione CSV / Excel ── */
.imp-stats { display: flex; flex-wrap: wrap; gap: 18px; margin-bottom: 10px; }
.imp-stats > div { display: flex; flex-direction: column; }
.imp-stats .num { font-size: 1.25rem; font-weight: 700; line-height: 1.2; }
.imp-stats span { font-size: .73rem; color: var(--stone); }
.imp-section { font-size: .85rem; font-weight: 700; margin: 16px 0 4px; }
.imp-section .field-hint { font-weight: 400; }
.imp-notes { display: flex; align-items: flex-start; gap: 6px; }

.imp-map-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 8px; margin-top: 8px;
}
.imp-map-row { display: flex; flex-direction: column; gap: 3px; }
.imp-map-label { font-size: .74rem; color: var(--stone); }
.imp-map-select {
  border: 1px solid var(--ash); border-radius: var(--r-control); padding: 6px 8px;
  font: inherit; font-size: .82rem; background: var(--surface); color: var(--graphite);
}

.imp-preview-wrap { overflow-x: auto; border: 1px solid var(--ash); border-radius: var(--r-panel); margin-top: 8px; }
.imp-preview { border-collapse: collapse; width: 100%; font-size: .76rem; }
.imp-preview th, .imp-preview td {
  text-align: left; padding: 6px 9px; border-bottom: 1px solid var(--ash); white-space: nowrap;
  max-width: 220px; overflow: hidden; text-overflow: ellipsis;
}
.imp-preview th { color: var(--stone); font-weight: 600; background: var(--sand); }
.imp-preview tr:last-child td { border-bottom: none; }
.imp-row-bad td { color: var(--stone); background: var(--coral-soft); }
.imp-row-note { color: var(--coral-ink); }

.imp-problems { margin-top: 10px; font-size: .78rem; }
.imp-problems summary { cursor: pointer; color: var(--stone); }
.imp-problems ul { margin: 6px 0 0 16px; color: var(--stone); display: grid; gap: 2px; }

.imp-progress { margin-bottom: 14px; }
.imp-bar { height: 8px; border-radius: 4px; background: var(--ash); overflow: hidden; }
.imp-bar-fill { height: 100%; background: var(--coral); transition: width .3s ease; }
