/* ── CamurrIA — design system portato da CentralinoGoldAdvisor ─────────────
   Stessa lingua grafica del Centralino (variabili, topbar, pannelli, bolle);
   qui il CHIARO è il tema di riferimento e l'accento è il verde del marchio
   CamurrIA (più WhatsApp, meno teal). Lo scuro è la controparte, col toggle. */

:root,
:root[data-theme='light'] {
  color-scheme: light;
  --accent: #16a34a;
  --accent-soft: rgba(22, 163, 74, 0.12);
  --accent-ink: #ffffff;

  --bg-page: #eef1f0;
  --surface: #ffffff;
  --surface-2: #f5f7f6;
  --surface-3: #eaeeec;
  --border: rgba(11, 20, 14, 0.1);
  --border-strong: rgba(11, 20, 14, 0.2);

  --text: #0e1912;
  --text-2: #5a6e60;
  --text-muted: #8a9d90;

  --bubble-in: #ffffff;
  --bubble-out: #d5f4de;
  --bubble-border: rgba(11, 20, 14, 0.09);
  --bubble-shadow: 0 1px 2px rgba(11, 20, 14, 0.07);
  --chat-bg: #e7eeea;
  --chat-dot: rgba(11, 20, 14, 0.055);
  --badge: #16a34a;
  --danger: #d03b3b;
  --warn-bg: #fff3cd;
  --warn-text: #664d03;
  --shadow: rgba(0, 0, 0, 0.14);

  --tick-read: #2a8fc7;
  --attesa: #c98500;
  --stella: #d9a417;
  --danger-bg: #b3261e;
  --su-danger: #ffffff;
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --accent: #3ddc74;
  --accent-soft: rgba(61, 220, 116, 0.14);
  --accent-ink: #04120a;

  --bg-page: #050a07;
  --surface: #0c1410;
  --surface-2: #111c15;
  --surface-3: #16241b;
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.14);

  --text: #e6f0e9;
  --text-2: #8a9d90;
  --text-muted: #64786b;

  --bubble-in: #18261d;
  --bubble-out: #11532c;
  --bubble-border: rgba(255, 255, 255, 0.075);
  --bubble-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  --chat-bg: #070d09;
  --chat-dot: rgba(255, 255, 255, 0.035);
  --badge: var(--accent);
  --danger: #ff6b6b;
  --warn-bg: rgba(250, 178, 25, 0.12);
  --warn-text: #f0c04a;
  --shadow: rgba(0, 0, 0, 0.5);

  --tick-read: #53bdeb;
  --attesa: #eda100;
  --stella: #f5c451;
  --danger-bg: #7f1d1d;
  --su-danger: #ffffff;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
/* La pagina non scorre mai: scorrono i riquadri interni. */
html, body { height: 100%; overflow: hidden; }
body {
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
  font-size: 14.5px;
  color: var(--text);
  background: var(--bg-page);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; cursor: pointer; color: inherit; background: none; border: none; }
input, textarea, select { font: inherit; color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

.hidden { display: none !important; }
.muted { opacity: 0.7; }
.mono { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ── Guscio: barra in alto + pannelli ───────────────────────────────────── */

.app { height: 100%; display: flex; flex-direction: column; }

.topbar {
  flex: none;
  height: 62px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 20px;
  padding: 0 22px;
  border-bottom: 1px solid var(--border);
}
.me { display: flex; align-items: center; gap: 12px; justify-self: start; }
.me-name { font-weight: 600; font-size: 15.5px; }
.avatar {
  width: 42px;
  height: 42px;
  flex: none;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 17px;
  text-transform: uppercase;
}
.topnav { display: flex; align-items: center; gap: 6px; justify-self: center; }
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 84px;
  padding: 6px 10px;
  border-radius: 10px;
  color: var(--text-2);
  font-size: 12.5px;
  transition: color .15s, background .15s;
}
.nav-item:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.nav-on { color: var(--accent); background: var(--accent-soft); }
.topbar-azioni { justify-self: end; display: flex; align-items: center; gap: 2px; }
.theme-btn {
  color: var(--text-2);
  padding: 9px;
  border-radius: 9px;
  display: grid;
  place-items: center;
}
.theme-btn:hover { color: var(--text); background: var(--surface-2); }

/* Il logo è verde+navy su fondo bianco: sul chiaro il bianco sparisce col
   multiply; sullo scuro sta su un chip bianco arrotondato. */
.brand-logo {
  height: 40px;
  width: auto;
  display: block;
  padding-right: 14px;
  margin-right: 4px;
  border-right: 1px solid var(--border);
  mix-blend-mode: multiply;
}
:root[data-theme='dark'] .brand-logo {
  mix-blend-mode: normal;
  background: #fff;
  border-radius: 10px;
  padding: 2px 6px;
  border-right: none;
  margin-right: 10px;
}

.workspace {
  flex: 1;
  min-height: 0;              /* indispensabile: senza, i pannelli crescono
                                 all'infinito e a scorrere sarebbe la pagina */
  display: grid;
  grid-template-columns: minmax(290px, 29%) 1fr;
  gap: 14px;
  padding: 14px 16px 16px;
}
.workspace-full { grid-template-columns: 1fr; }
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
}
/* Contenuto scorrevole delle pagine non-chat. */
.stack { flex: 1; min-height: 0; overflow-y: auto; padding: 20px 22px 26px; }
.stack > h2 { font-size: 17px; margin: 22px 0 10px; }
.stack > h2:first-child { margin-top: 0; }

/* Pannelli con testata/corpo/piede: la PAGINA non scorre mai, scorre al
   massimo il corpo del singolo pannello (stessa regola del Centralino). */
.panel-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
}
.panel-title { font-weight: 600; font-size: 15px; }
.panel-body { flex: 1; min-height: 0; overflow-y: auto; padding: 12px 14px; }
.panel-foot { flex: none; padding: 10px 14px; border-top: 1px solid var(--border); }

/* Griglie delle pagine a pannelli. `.col` impila pannelli in una cella:
   auto = altezza naturale, fill = si divide lo spazio che resta. */
.workspace-canale { grid-template-columns: minmax(360px, 4fr) 6fr; }
.workspace-2col { grid-template-columns: 1fr 1fr; }
.col { display: flex; flex-direction: column; gap: 14px; min-height: 0; min-width: 0; }
.col .panel.auto { flex: none; }
.col .panel.fill { flex: 1; }

/* ── Avvisi (flash) ─────────────────────────────────────────────────────── */

.flash-zone { flex: none; }
.flash {
  padding: 10px 22px;
  font-size: 13.5px;
  text-align: center;
  border-bottom: 1px solid var(--border);
}
.flash-success { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.flash-error { background: var(--danger-bg); color: var(--su-danger); }
.flash-warning, .flash-info { background: var(--warn-bg); color: var(--warn-text); }

/* ── Login ──────────────────────────────────────────────────────────────── */

.login-page {
  height: 100%;
  display: grid;
  place-items: center;
  background:
    radial-gradient(900px 500px at 50% 110%, var(--accent-soft), transparent 70%),
    var(--bg-page);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 38px 40px;
  border-radius: 16px;
  box-shadow: 0 20px 50px var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(380px, 92vw);
}
.login-card h1 { font-size: 27px; letter-spacing: -0.4px; }
.login-sub { color: var(--text-2); margin-bottom: 6px; }
.login-card input {
  padding: 12px 14px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  border-radius: 10px;
  outline: none;
}
.login-card input:focus { border-color: var(--accent); }
.login-card button[type='submit'] {
  padding: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 10px;
  font-weight: 700;
}
.login-error { color: var(--danger); font-size: 13px; }
.login-brand { display: grid; place-items: center; margin-bottom: 4px; }
.login-brand img { height: 84px; width: auto; mix-blend-mode: multiply; }
:root[data-theme='dark'] .login-brand img {
  mix-blend-mode: normal;
  background: #fff;
  border-radius: 12px;
  padding: 6px 12px;
}

/* ── Campi modulo ───────────────────────────────────────────────────────── */

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field label { color: var(--text-2); font-size: 12.5px; }
.field input, .field select, .field textarea, .rubrica-search {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 13px;
  outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus,
.rubrica-search:focus { border-color: var(--accent); }
.field textarea { resize: vertical; }
.form-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.form-row .field { flex: none; }
.form-row .field.grow { flex: 1; min-width: 180px; }
.hint { color: var(--text-muted); font-size: 12.5px; }

.mini-btn { background: var(--accent); color: var(--accent-ink); border-radius: 9px; padding: 8px 13px; font-size: 13px; font-weight: 700; }
.mini-btn.ghost { background: transparent; color: var(--text-2); border: 1px solid var(--border-strong); font-weight: 500; }
.mini-btn.ghost:hover { color: var(--text); border-color: var(--accent); }
.mini-btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); font-weight: 500; }
.mini-btn.danger:hover { background: var(--danger); color: var(--su-danger); }
.mini-btn:disabled { opacity: 0.45; cursor: default; }

/* ── Card e tabelle ─────────────────────────────────────────────────────── */

.card { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; position: relative; margin-bottom: 12px; }
.card-title { font-weight: 600; margin-bottom: 12px; }
.card-title-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.card-title-row .card-title { margin-bottom: 0; }
.card-empty { color: var(--text-muted); font-size: 13.5px; padding: 12px 0; }

.log-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.log-table th { text-align: left; color: var(--text-2); font-weight: 600; padding: 7px 10px; border-bottom: 1px solid var(--border); }
.log-table td { padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.log-table tr:last-child td { border-bottom: none; }
.log-body { max-width: 420px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* nei pannelli affiancati la colonna messaggio si stringe: niente
   scorrimento orizzontale della tabella */
.workspace-2col .log-body { max-width: 200px; }
.table-scroll { overflow-x: auto; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 6px 15px;
  font-size: 13px;
  color: var(--text-2);
}
.chip b { color: var(--text); font-variant-numeric: tabular-nums; }
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.picker-badge {
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
}

/* Righe stile rubrica (destinatari). */
.contact-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 7px 12px;
  margin-top: 6px;
}
.contact-row:first-child { margin-top: 0; }
.contact-row .avatar { width: 34px; height: 34px; font-size: 14px; }
.contact-main { flex: 1; min-width: 0; }
.contact-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-phone { color: var(--text-2); font-size: 13px; }
.contact-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.row-off { opacity: 0.5; }

/* ── Pannello WhatsApp (numeri collegati) ───────────────────────────────── */

.wa-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 10px; align-items: start; }
.wa-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  text-align: center;
}
.wa-status { display: inline-flex; align-items: center; gap: 9px; font-weight: 600; font-size: 15px; margin-bottom: 8px; flex-wrap: wrap; justify-content: center; }
.wa-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--text-muted); flex: none; }
.stato-connected .wa-dot { background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.stato-qr .wa-dot, .stato-connecting .wa-dot { background: var(--attesa); }
.stato-disconnected .wa-dot { background: var(--danger); }
.wa-me { color: var(--text-2); font-weight: 400; }
.wa-instr { color: var(--text-2); font-size: 13px; line-height: 1.5; margin: 8px 0; }
.wa-qr { width: 200px; height: 200px; border-radius: 12px; background: #fff; padding: 8px; margin: 6px auto; display: block; }
.wa-hint { color: var(--text-muted); font-size: 12px; margin-top: 6px; }
.wa-azioni { display: flex; gap: 8px; justify-content: center; margin-top: 10px; flex-wrap: wrap; }
.wa-titolo { font-weight: 600; font-size: 15px; margin-bottom: 4px; }

/* Pallini di stato riusati fuori dalle card (tab dei numeri in chat). */
.st-dot { display: inline-block; width: 8px; height: 8px; border-radius: 999px; background: var(--text-muted); flex: none; }
.st-dot.open { background: var(--accent); }
.st-dot.needs_qr, .st-dot.connecting { background: var(--attesa); }
.st-dot.banned { background: var(--danger); }

/* ── Colonna chat: ricerca, filtri, elenco ──────────────────────────────── */

.search-box {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px;
  padding: 8px 9px 8px 13px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 11px;
  color: var(--text-muted);
}
.search-box:focus-within { border-color: var(--accent); }
.search-box input { flex: 1; min-width: 0; background: none; border: none; outline: none; }

.filtri { flex: none; display: flex; gap: 6px; padding: 0 12px 10px; flex-wrap: wrap; }
.filtro {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-2);
  font-size: 12.5px;
}
.filtro:hover { color: var(--text); }
.filtro-on { background: var(--accent-soft); border-color: transparent; color: var(--accent); font-weight: 700; }

.chat-list { flex: 1; min-height: 0; overflow-y: auto; padding: 0 8px 10px; }
.list-empty { padding: 12px 12px; color: var(--text-2); font-size: 13px; }
.chat-item {
  width: 100%;
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 11px;
  text-align: left;
}
.chat-item:hover { background: var(--surface-2); }
.chat-item.active { background: var(--surface-3); }
.chat-item .avatar { width: 38px; height: 38px; font-size: 15px; }
.chat-item-body { flex: 1; min-width: 0; }
.chat-item-top, .chat-item-bottom { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.chat-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.chat-time { color: var(--text-muted); font-size: 11.5px; flex: none; }
.chat-preview { color: var(--text-2); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.chat-via { color: var(--text-muted); font-size: 10.5px; margin-top: 1px; }
.badge {
  flex: none;
  background: var(--badge);
  color: var(--accent-ink);
  border-radius: 999px;
  min-width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  font-size: 11.5px;
  font-weight: 700;
  padding: 0 6px;
}
.pin-btn { flex: none; cursor: pointer; user-select: none; font-size: 15px; line-height: 1; color: var(--border-strong); }
.pin-btn:hover { color: var(--stella); }
.pin-btn.on { color: var(--stella); }

.chatlist-empty { display: grid; place-items: center; gap: 8px; padding: 22% 20px; text-align: center; }
.empty-circle {
  width: 78px;
  height: 78px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  color: var(--text-2);
  margin-bottom: 6px;
}
.empty-title { font-weight: 600; }
.empty-sub { color: var(--text-2); font-size: 13px; }

/* ── Conversazione ──────────────────────────────────────────────────────── */

.empty-state {
  flex: 1;
  min-height: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 6px;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.empty-state::after {
  content: '';
  position: absolute;
  right: -10%;
  bottom: -30%;
  width: 70%;
  height: 70%;
  background: radial-gradient(circle at 70% 80%, var(--accent-soft), transparent 65%);
  pointer-events: none;
}
.empty-halo { position: relative; display: grid; place-items: center; margin-bottom: 26px; color: var(--accent); }
.ring { position: absolute; border-radius: 50%; border: 1px solid var(--border); }
.ring-1 { width: 108px; height: 108px; }
.ring-2 { width: 158px; height: 158px; opacity: .55; }
.empty-state h2 { font-size: 42px; font-weight: 600; letter-spacing: -1px; }
.empty-state p { color: var(--text-2); }

.conversation { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.conv-header {
  flex: none;
  padding: 11px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}
.conv-header .avatar { width: 38px; height: 38px; font-size: 15px; }
.conv-name { font-weight: 600; }
.conv-phone { color: var(--text-2); font-size: 12.5px; }
.conv-who { min-width: 0; flex: 1; text-align: left; }
/* L'identità in testata è un pulsante: apre la scheda del contatto. */
.conv-id {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  padding: 4px 8px;
  margin: -4px -8px;
  border-radius: 10px;
  min-width: 0;
  flex: 1;
}
.conv-id:hover { background: var(--surface-2); }

/* ── Scheda contatto (finestra sovrapposta) ─────────────────────────────── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.55);
  display: grid;
  place-items: center;
  padding: 24px;
  backdrop-filter: blur(2px);
}
.profile-card {
  position: relative;
  width: min(400px, 100%);
  max-height: 100%;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 26px 26px 22px;
  box-shadow: 0 24px 60px var(--shadow);
}
.modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  color: var(--text-2);
  font-size: 15px;
  padding: 6px 8px;
  border-radius: 8px;
}
.modal-close:hover { color: var(--text); background: var(--surface-2); }
.profile-head { display: grid; justify-items: center; gap: 4px; text-align: center; }
.profile-avatar { width: 72px; height: 72px; font-size: 28px; margin-bottom: 6px; }
.profile-name { font-size: 19px; font-weight: 600; }
.profile-phone { color: var(--text-2); font-size: 13.5px; }
.profile-alias { color: var(--text-muted); font-size: 12.5px; }
.profile-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 18px 0 14px;
}
.pstat {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 12px 8px;
  display: grid;
  justify-items: center;
  gap: 2px;
}
.pstat-v { font-size: 21px; font-weight: 600; }
.pstat-l { color: var(--text-2); font-size: 12px; }
.profile-rows { display: flex; flex-direction: column; gap: 9px; font-size: 13.5px; }
.profile-rows > div { display: flex; justify-content: space-between; gap: 14px; }
.profile-rows dt { color: var(--text-2); flex: none; }
.profile-rows dd { text-align: right; }
.profile-actions { display: flex; gap: 8px; margin-top: 18px; }
.profile-actions .mini-btn { flex: 1; text-align: center; }

/* Selettore destinatari (dai Preset): elenco spuntabile dalla rubrica. */
.pick-list {
  max-height: 320px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 4px;
}
.pick-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 10px;
  cursor: pointer;
}
.pick-row:hover { background: var(--surface-2); }
.pick-row input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; flex: none; }
.pick-row .contact-main { display: flex; flex-direction: column; min-width: 0; flex: 1; }

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px 7%;
  display: flex;
  flex-direction: column;
  gap: 3px;
  background-color: var(--chat-bg);
  background-image: radial-gradient(var(--chat-dot) 1.2px, transparent 1.2px);
  background-size: 22px 22px;
}
.bubble-row { display: flex; }
.bubble-row.out { justify-content: flex-end; }
.bubble {
  max-width: 66%;
  background: var(--bubble-in);
  border: 1px solid var(--bubble-border);
  box-shadow: var(--bubble-shadow);
  border-radius: 12px;
  padding: 8px 11px 8px;
}
.bubble-row.out .bubble { background: var(--bubble-out); }
.bubble.failed { outline: 1px solid var(--danger); }
.bubble-text { white-space: pre-wrap; word-wrap: break-word; line-height: 1.42; }
.bubble-media { max-width: 300px; max-height: 340px; border-radius: 9px; display: block; margin-bottom: 5px; }
.bubble-meta { display: flex; gap: 6px; justify-content: flex-end; align-items: center; color: var(--text-muted); font-size: 11px; margin-top: 3px; }
.ticks { letter-spacing: -2px; }
.ticks.failed { color: var(--danger); letter-spacing: 0; }

.composer {
  flex: none;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  position: relative;
}
.composer textarea {
  flex: 1;
  resize: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 12px 14px;
  outline: none;
  max-height: 130px;
}
.composer textarea:focus { border-color: var(--accent); }
.composer button[type='submit'] {
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 11px;
  padding: 12px 20px;
  font-weight: 700;
}
.torna { display: none; }

/* Schermi stretti: le pagine a pannelli tornano a una colonna che scorre
   (dentro il workspace, la pagina resta ferma). */

/* ── Il pannello di destra ──────────────────────────────────────────────
   Ci finisce dentro una sezione intera (Invia, Preset, Numeri…), quindi si
   comporta come si comportava un pannello: testa ferma, corpo che scorre,
   piede fermo. */

.sezione { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* Due colonne affiancate DENTRO una sezione (preset+programmazioni,
   compositore+cronologia). Sotto i 900px si impilano: vedi in fondo. */
.due-colonne {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}
.colonna { min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.colonna-testa {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
}
.colonna-corpo { min-width: 0; }
.due-colonne .log-body { max-width: 220px; }

/* ── Avvisi in cima ─────────────────────────────────────────────────────
   Stanno fuori dai pannelli perché riguardano tutto il programma: se
   WhatsApp è scollegato non conta in che sezione ti trovi. */

#avvisi { flex: none; }
.avviso {
  margin: 0 16px 10px;
  padding: 10px 14px;
  border-radius: 11px;
  font-size: 13.5px;
  line-height: 1.5;
  border: 1px solid transparent;
}
#avvisi .avviso:first-child { margin-top: 12px; }
.avviso a { color: inherit; font-weight: 600; }
.avviso-grave {
  background: var(--danger-bg); color: var(--su-danger);
}
.avviso-attesa {
  background: var(--warn-bg); color: var(--warn-text);
  border-color: rgba(0, 0, 0, 0.06);
}
.sezione .avviso { margin: 0 0 12px; }

/* ── Linguette Attive / Archiviate ──────────────────────────────────── */

.tabs { flex: none; display: flex; gap: 4px; padding: 0 12px 8px; }
.tab {
  flex: 1;
  padding: 7px 10px;
  border-radius: 9px;
  font-size: 13px;
  color: var(--text-2);
  border: 1px solid transparent;
  background: none;
}
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab-on {
  background: var(--accent-soft); color: var(--accent); font-weight: 700;
}

/* ── Fondo della colonna di sinistra ───────────────────────────────── */

.sidebar-foot {
  flex: none;
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
}
.sidebar-foot input {
  flex: 1; min-width: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 10px;
  color: var(--text);
  font-size: 13px;
}
.sidebar-foot input:focus { border-color: var(--accent); outline: none; }

/* ── Chi aspetta una risposta ───────────────────────────────────────── */

.chat-attesa { border-left: 3px solid var(--attesa); }
.attesa-da {
  flex: none;
  color: var(--attesa);
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ── Testa della conversazione ──────────────────────────────────────── */

.conv-azioni { flex: none; display: flex; gap: 6px; align-items: center; }
.conv-azioni .mini-btn { display: inline-flex; align-items: center; gap: 6px; }

/* ── Scrittura: emoji, graffetta, allegato ──────────────────────────── */

.composer-zona { flex: none; position: relative; }
.composer-btn {
  flex: none;
  display: grid; place-items: center;
  width: 38px; height: 38px;
  border-radius: 10px;
  color: var(--text-muted);
  background: none;
}
.composer-btn:hover { color: var(--accent); background: var(--surface-2); }
.allegato-scelto {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 13px;
}
.allegato-nome {
  flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--text-2);
}
.emoji-pannello {
  position: absolute;
  bottom: 100%;
  left: 12px;
  width: min(320px, calc(100% - 24px));
  max-height: 210px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(34px, 1fr));
  gap: 2px;
  padding: 8px;
  margin-bottom: 6px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  box-shadow: 0 12px 28px var(--shadow);
  z-index: 20;
}
.emoji {
  font-size: 19px; line-height: 1;
  padding: 5px; border-radius: 7px; background: none;
}
.emoji:hover { background: var(--surface-2); }

/* ── Bolle: video, vocali, documenti ────────────────────────────────── */

.bubble-audio { width: 240px; max-width: 100%; margin-bottom: 5px; display: block; }
.bubble-file {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 11px; margin-bottom: 5px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  color: inherit;
  text-decoration: none;
}
.bubble-file:hover { border-color: var(--accent); }
.bubble-file-icona { font-size: 19px; flex: none; }
.bubble-file-nome {
  min-width: 0; flex: 1;
  font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ── Statistiche ────────────────────────────────────────────────────────
   Due serie sole, e i colori sono passati dal controllo che misura quanto
   restano distinguibili a chi non vede bene i colori. Il verde è quello del
   marchio (gli invii, cioè noi), il blu è chi scrive a noi. Non basta il
   colore: c'è la legenda, la tabella coi numeri esatti e lo stacco fra i
   due segmenti della barra. */

.serie-inviati { --serie: #16a34a; }
.serie-ricevuti { --serie: #2563eb; }
:root[data-theme='dark'] .serie-inviati { --serie: #27a85c; }
:root[data-theme='dark'] .serie-ricevuti { --serie: #5a8df0; }

.kpi-griglia {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 22px;
}
.kpi {
  display: flex; flex-direction: column; gap: 3px;
  padding: 14px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.kpi-v { font-size: 25px; font-weight: 600; letter-spacing: -0.5px; }
.kpi-l { color: var(--text-2); font-size: 12.5px; }
.kpi-allarme { border-color: var(--danger); }
.kpi-allarme .kpi-v { color: var(--danger); }

.grafico-blocco { margin-bottom: 26px; }
.grafico-blocco h3 { font-size: 15px; font-weight: 600; margin-bottom: 10px; }
.grafico-testa {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; flex-wrap: wrap; margin-bottom: 10px;
}
.grafico-testa h3 { margin-bottom: 0; }
.legenda { display: flex; gap: 14px; color: var(--text-2); font-size: 12.5px; }
.legenda-voce { display: inline-flex; align-items: center; gap: 6px; }
.tacca {
  width: 11px; height: 11px; border-radius: 3px;
  background: var(--serie); flex: none;
}

.grafico {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 170px;
  padding: 10px 2px 0;
  border-bottom: 1px solid var(--border);
}
.barra-colonna {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  height: 100%;
  position: relative;
}
.barra {
  flex: 1; width: 100%; max-width: 22px;
  display: flex; flex-direction: column; justify-content: flex-end;
  /* lo stacco fra i due segmenti: senza, una barra tutta ricevuti e una
     mezza e mezza si leggono uguali da lontano */
  gap: 2px;
}
.segmento {
  display: block; width: 100%;
  background: var(--serie);
  min-height: 2px;
}
/* solo il segmento in cima è arrotondato: quello sotto poggia sulla base */
.barra .segmento:first-child { border-radius: 4px 4px 0 0; }
.barra-giorno {
  flex: none;
  color: var(--text-muted);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}
/* il riquadro col dettaglio del giorno, senza una riga di JavaScript */
.barra-colonna::after {
  content: attr(data-etichetta);
  position: absolute;
  bottom: calc(100% - 8px);
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 9px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  box-shadow: 0 8px 20px var(--shadow);
  color: var(--text);
  font-size: 12px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity .12s;
  z-index: 5;
}
.barra-colonna:hover::after { opacity: 1; }
.grafico-nota { margin-top: 8px; }
.tabella-dati { margin-top: 12px; }
.tabella-dati summary {
  cursor: pointer; color: var(--text-2); font-size: 13px; padding: 4px 0;
}
.tabella-dati summary:hover { color: var(--text); }

.chip-btn { cursor: pointer; text-decoration: none; }
.chip-btn:hover { border-color: var(--accent); color: var(--text); }
.chip-on { background: var(--accent-soft); color: var(--accent); font-weight: 700; }

/* ── Manuale ────────────────────────────────────────────────────────── */

.manuale-card {
  position: relative;
  width: min(620px, 94vw);
  max-height: 86vh;
  overflow-y: auto;
  padding: 26px 30px 30px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 24px 60px var(--shadow);
}
.manuale-card h2 { font-size: 21px; margin-bottom: 4px; }
.manuale-corpo { margin-top: 14px; }
.man-voce { padding: 14px 0; border-bottom: 1px solid var(--border); }
.man-voce:last-child { border-bottom: none; }
.man-voce h3 { font-size: 14.5px; font-weight: 600; margin-bottom: 5px; }
.man-voce p { color: var(--text-2); font-size: 13.5px; line-height: 1.6; }

/* ── La finestra che cancella un numero ─────────────────────────────── */

.danger-title { font-size: 19px; color: var(--danger); margin-bottom: 8px; }
#elimina-numero-modal .wa-instr { margin-bottom: 14px; }


/* ── Camurrie ───────────────────────────────────────────────────────────
   Qualcuno che deve una risposta. La scheda deve dire in un colpo d'occhio
   tre cose: chi è, cosa gli si sta chiedendo, e a che punto è l'assedio. */

.due-colonne-strette { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); }

.modulo-camurria { display: flex; flex-direction: column; gap: 12px; }
.modulo-camurria .field label { font-weight: 600; color: var(--text); }
.modulo-camurria .hint { font-weight: 400; }

.spunta {
  display: flex; align-items: center; gap: 9px;
  font-size: 13.5px; color: var(--text-2); cursor: pointer;
}
.spunta input { accent-color: var(--accent); width: 16px; height: 16px; }

.camurria {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border-strong);
  border-radius: 12px;
  padding: 13px 15px;
  margin-bottom: 10px;
}
.camurria.stato-aperta { border-left-color: var(--accent); }
.camurria.in-ritardo { border-left-color: var(--danger); }
.camurria.stato-risposto { border-left-color: var(--accent); opacity: .75; }
.camurria.stato-arresa, .camurria.stato-scaduta { border-left-color: var(--attesa); opacity: .75; }
.camurria.stato-chiusa { opacity: .6; }

.camurria-testa { display: flex; align-items: center; gap: 10px; margin-bottom: 9px; }
.camurria-testa .avatar { width: 34px; height: 34px; font-size: 14px; flex: none; }
.camurria-chi { flex: 1; min-width: 0; }
.camurria-nome {
  font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.camurria-numero { color: var(--text-2); font-size: 12.5px; }

.pastiglia {
  flex: none;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  background: var(--surface-3);
  color: var(--text-2);
}
.p-aperta { background: var(--accent-soft); color: var(--accent); }
.p-risposto { background: var(--accent-soft); color: var(--accent); }
.p-arresa, .p-scaduta { background: var(--warn-bg); color: var(--warn-text); }

.camurria-oggetto { font-size: 14px; line-height: 1.45; margin-bottom: 8px; }
.camurria-righe {
  display: flex; flex-wrap: wrap; gap: 6px 16px;
  color: var(--text-2); font-size: 12.5px;
}
.camurria-righe b { color: var(--text); }
.camurria-righe .scaduto { color: var(--danger); font-weight: 600; }
.camurria-esito {
  margin-top: 8px; padding: 7px 10px;
  background: var(--surface); border-radius: 8px;
  color: var(--text-2); font-size: 13px;
}
.camurria-azioni {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  margin-top: 11px;
}
/* La chiusura su una riga sua: schiacciata accanto agli altri pulsanti il
   campo diventava largo tre parole e il suggerimento si tagliava. */
.camurria-chiudi { display: flex; gap: 8px; align-items: center; margin-top: 11px; }
.camurria-chiudi input {
  flex: 1; min-width: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 9px; padding: 8px 11px; color: var(--text); font-size: 13px;
}
.camurria-chiudi input:focus { border-color: var(--accent); outline: none; }
.camurria-righe .in-scadenza { color: var(--attesa); font-weight: 600; }

.chip-allarme { border-color: var(--danger); color: var(--danger); }
.chip-allarme b { color: var(--danger); }

@media (max-width: 900px) {
  .workspace-canale, .workspace-2col { display: flex; flex-direction: column; overflow-y: auto; }
  .due-colonne, .due-colonne-strette { grid-template-columns: 1fr; }
  .due-colonne .log-body { max-width: none; }
  .workspace-canale .panel, .workspace-2col .panel { flex: none; overflow: visible; }
  .workspace-canale .panel-body, .workspace-2col .panel-body { overflow: visible; }
  .workspace-canale .col { display: contents; }
}

/* ── Cellulare ──────────────────────────────────────────────────────────── */

@media (max-width: 720px) {
  html, body { height: 100dvh; }

  .topbar {
    height: auto;
    min-height: 54px;
    padding: 7px 10px;
    gap: 8px;
    grid-template-columns: auto minmax(0, 1fr) auto;
  }
  .brand-logo, .me-name { display: none; }
  .me { gap: 8px; }
  .me .avatar { width: 34px; height: 34px; font-size: 14px; }
  .topnav { overflow-x: auto; gap: 2px; justify-self: stretch; scrollbar-width: none; }
  .topnav::-webkit-scrollbar { display: none; }
  .nav-item { min-width: 46px; padding: 5px 4px; gap: 2px; font-size: 9.5px; }
  .nav-item svg { width: 19px; height: 19px; }
  .theme-btn { padding: 7px; }

  .workspace { grid-template-columns: 1fr; gap: 0; padding: 8px; }
  .workspace .sidebar { display: none; }
  .workspace.mostra-elenco .sidebar { display: flex; }
  .workspace.mostra-elenco .main { display: none; }

  .stack { padding: 14px; }
  .conv-header { padding: 9px 10px; gap: 8px; }
  .conv-header .avatar { width: 34px; height: 34px; font-size: 14px; }
  .torna {
    display: grid;
    place-items: center;
    flex: none;
    width: 34px;
    height: 34px;
    border-radius: 9px;
    color: var(--text-2);
    font-size: 19px;
  }
  .torna:hover { background: var(--surface-2); color: var(--text); }

  .messages { padding: 14px 10px; }
  .bubble { max-width: 86%; }
  .composer { padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); }
  .composer button[type='submit'] { padding: 12px 16px; }
  /* 16px esatti: sotto questa misura iOS ingrandisce la pagina al primo tocco. */
  .composer textarea, .search-box input, .field input, .rubrica-search { font-size: 16px; }

  .wa-qr { width: 220px; height: 220px; }
  .contact-row { flex-wrap: wrap; }
  .contact-actions { width: 100%; justify-content: flex-end; }
  .log-body { max-width: 200px; }
  .kpi-griglia { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
  /* sul telefono il titolo e i pulsanti del periodo si accavallavano:
     vanno uno sotto l'altro */
  .panel-head { flex-direction: column; align-items: flex-start; gap: 8px; }
  .grafico { height: 130px; }
  .barra-giorno { display: none; }
  .avviso { margin: 0 8px 8px; }
  .manuale-card { padding: 22px 18px 26px; }
  .sidebar-foot input { font-size: 16px; }
  .camurria-azioni { flex-direction: column; align-items: stretch; }
  .camurria-azioni form { width: 100%; }
  .camurria-chiudi { flex-direction: column; align-items: stretch; }
}
