/* =========================================================
   Pannello di e-Tore · Gruppo ARMS · redesign 2026
   (dal mock-up approvato, cartella mockup-2026/ tolta il 19/11/2026: si recupera dal commit db67041)
   Token → base → shell → componenti → viste → responsive
   ========================================================= */

/* ---------- 1. TOKEN ---------- */
:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f2f4f7;
  --surface-3: #e9edf2;
  --border: #e4e7ec;
  --border-strong: #d0d6de;
  --text: #0e1623;
  --text-2: #475263;
  --text-3: #667185;

  --primary: #1c529b;
  --primary-hover: #17457f;
  --primary-text: #ffffff;
  --brand-text: #1c529b;
  --brand-soft: #eaf1fb;
  --brand-bar: #9dbbe4;
  --yellow: #fed100;

  --warn-strong: #d97706;
  --bar-active: #1c529b;
  --ok: #10b981;      --ok-text: #047857;   --ok-soft: #e8f8f1;
  --warn: #f59e0b;    --warn-text: #a85a06; --warn-soft: #fef4e2;
  --bad: #ef4444;     --bad-text: #c0262d;  --bad-soft: #fdeceb;
  --idle: #64748b;    --idle-soft: #eef1f5;

  --ring: 0 0 0 3px color-mix(in srgb, var(--primary) 30%, transparent);
  --shadow-pop: 0 24px 60px -20px rgb(15 23 36 / .28), 0 0 0 1px var(--border);
  --shadow-soft: 0 1px 2px rgb(15 23 36 / .04);

  --r-lg: 16px; --r: 12px; --r-sm: 8px;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;
  --sb-w: 252px;
  --topbar-h: 61px;
  --ease: cubic-bezier(.2, .7, .2, 1);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1015;
  --surface: #141920;
  --surface-2: #1a2029;
  --surface-3: #222a35;
  --border: #242c37;
  --border-strong: #333d4b;
  --text: #e9edf3;
  --text-2: #a9b3c2;
  --text-3: #8a95a7;

  --primary: #2f6bc0;
  --warn-strong: #fbbf24;
  --bar-active: #6ea2ea;
  --primary-hover: #3a79d1;
  --brand-text: #8db7f0;
  --brand-soft: rgb(91 147 224 / .14);
  --brand-bar: #3c69a6;

  --ok-text: #3fd59f;   --ok-soft: rgb(16 185 129 / .13);
  --warn-text: #f9bf4a; --warn-soft: rgb(245 158 11 / .13);
  --bad-text: #fb7f7f;  --bad-soft: rgb(239 68 68 / .14);
  --idle-soft: rgb(100 116 139 / .18);

  --shadow-pop: 0 24px 60px -16px rgb(0 0 0 / .6), 0 0 0 1px var(--border-strong);
  --shadow-soft: none;
}

[data-sidebar="collapsed"] { --sb-w: 76px; }

/* ---------- 2. BASE ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { letter-spacing: -.015em; }
a { color: var(--brand-text); text-decoration: none; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 6px; }

.i { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.i--sm { width: 15px; height: 15px; }
.tnum, .num { font-variant-numeric: tabular-nums; }
.num { font-family: var(--mono); letter-spacing: -.03em; }
.muted { color: var(--text-3); font-size: 13px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
.dot--warn { background: var(--warn); } .dot--bad { background: var(--bad); } .dot--idle { background: var(--idle); }
.skip-link { position: absolute; left: 12px; top: -60px; z-index: 100; background: var(--primary); color: #fff; padding: 8px 14px; border-radius: 8px; }
.skip-link:focus { top: 12px; }

.kbd {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 5px;
  font: 500 11px/1 var(--font); color: var(--text-3);
  background: var(--surface); border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px;
}

/* ---------- 3. BOTTONI ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 14px; border-radius: 10px;
  font-weight: 550; font-size: 13.5px; white-space: nowrap;
  border: 1px solid transparent; background: none;
  transition: background .15s, border-color .15s, color .15s, transform .1s;
}
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--primary); color: var(--primary-text); }
.btn--primary:hover { background: var(--primary-hover); }
.btn--ghost { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn--ghost:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn--soft { background: var(--brand-soft); color: var(--brand-text); }
.btn--soft:hover { background: color-mix(in srgb, var(--brand-soft) 60%, var(--primary) 12%); }
.btn--sm { height: 32px; padding: 0 11px; font-size: 13px; border-radius: 8px; }

.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 10px;
  border: 1px solid transparent; background: none; color: var(--text-2);
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.link-quiet { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 550; color: var(--brand-text); }
.link-quiet:hover { text-decoration: underline; text-underline-offset: 3px; }

/* ---------- 4. SHELL ---------- */
.app { display: grid; grid-template-columns: var(--sb-w) minmax(0, 1fr); min-height: 100dvh; transition: grid-template-columns .25s var(--ease); }

.sidebar {
  position: sticky; top: 0; height: 100dvh;
  display: flex; flex-direction: column; gap: 6px;
  padding: 14px 12px;
  border-right: 1px solid var(--border);
  background: var(--surface);
  overflow: hidden;
}
.sidebar__top { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 2px 2px 12px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; color: var(--text); }
.brand__logo { width: 34px; height: 34px; object-fit: contain; border-radius: 9px; background: #fff; padding: 3px; border: 1px solid var(--border); flex: none; }
.brand__text { display: flex; flex-direction: column; line-height: 1.2; white-space: nowrap; }
.brand__text strong { font-size: 14px; font-weight: 650; }
.brand__text span { font-size: 12px; color: var(--text-3); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav__item {
  position: relative; display: flex; align-items: center; gap: 11px;
  height: 40px; padding: 0 11px; border-radius: 10px;
  color: var(--text-2); font-weight: 520; white-space: nowrap;
  border: 0; background: none; width: 100%; text-align: left;
  transition: background .15s, color .15s;
}
.nav__item:hover { background: var(--surface-2); color: var(--text); }
.nav__item[aria-current="page"] { background: var(--brand-soft); color: var(--brand-text); }
.nav__item[aria-current="page"]::before { content: ""; position: absolute; left: -12px; top: 10px; bottom: 10px; width: 3px; border-radius: 0 3px 3px 0; background: var(--primary); }
.nav__label { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.nav__count {
  min-width: 22px; height: 20px; padding: 0 6px; border-radius: 10px;
  display: inline-grid; place-items: center;
  font-size: 11.5px; font-weight: 650; font-variant-numeric: tabular-nums;
  background: var(--surface-3); color: var(--text-2);
}
.nav__count--warn { background: var(--warn-soft); color: var(--warn-text); }
.nav__count:empty { display: none; }
.nav__item--quiet { height: 36px; font-size: 13px; color: var(--text-3); }
.sidebar__spacer { flex: 1; }

.tore-status {
  display: flex; align-items: center; gap: 10px;
  padding: 10px; border-radius: var(--r); border: 1px solid var(--border); background: var(--surface-2);
}
.tore-status img { width: 38px; height: 38px; object-fit: contain; border-radius: 10px; background: var(--surface); flex: none; }
.tore-status__text { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.tore-status__text strong { font-size: 13px; }
.tore-status__text span { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-3); white-space: nowrap; }
.sidebar__foot { display: flex; flex-direction: column; gap: 2px; padding-top: 6px; border-top: 1px solid var(--border); margin-top: 6px; }

/* sidebar ridotta */
[data-sidebar="collapsed"] .brand__text,
[data-sidebar="collapsed"] .nav__label,
[data-sidebar="collapsed"] .tore-status__text { display: none; }
[data-sidebar="collapsed"] .sidebar__top { flex-direction: column; }
[data-sidebar="collapsed"] .nav__item { justify-content: center; padding: 0; }
[data-sidebar="collapsed"] .nav__count { position: absolute; top: 2px; right: 4px; min-width: 18px; height: 16px; font-size: 10px; padding: 0 4px; }
[data-sidebar="collapsed"] .tore-status { justify-content: center; padding: 6px; }

.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px;
  min-height: 60px; padding: 8px 28px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar__back, .topbar__logo { display: none; }
.topbar__title { flex: 1; min-width: 0; }
.topbar__title h1 { font-size: 18px; font-weight: 680; line-height: 1.25; }
.topbar__title p { font-size: 13px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar__tools { display: flex; align-items: center; gap: 10px; }

.period {
  position: relative; display: inline-flex; padding: 3px; gap: 2px;
  border-radius: 11px; background: var(--surface-2); border: 1px solid var(--border);
}
.period button {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 11px; border-radius: 8px; border: 0; background: none;
  font-size: 13px; font-weight: 550; color: var(--text-2); white-space: nowrap;
}
.period button:hover { color: var(--text); }
.period button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgb(15 23 36 / .08), 0 0 0 1px var(--border); }
.popover {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 30;
  display: flex; align-items: flex-end; gap: 10px; padding: 14px;
  background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow-pop);
}
.popover label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-3); font-weight: 550; }
.popover input { height: 34px; padding: 0 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); }

.search-trigger {
  display: inline-flex; align-items: center; gap: 8px;
  height: 38px; padding: 0 8px 0 12px; min-width: 220px;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text-3); transition: border-color .15s;
}
.search-trigger:hover { border-color: var(--border-strong); }
.search-trigger__label { flex: 1; text-align: left; font-size: 13px; }

.content { padding: 24px 28px 64px; width: 100%; max-width: 1480px; margin: 0 auto; outline: none; }
.view { display: flex; flex-direction: column; gap: 18px; animation: view-in .28s var(--ease); }
@keyframes view-in { from { opacity: 0; transform: translateY(6px); } }


/* ---------- 5. CARD E PRIMITIVI ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 20px; box-shadow: var(--shadow-soft); min-width: 0;
}
.card__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.card__head--tight { align-items: center; margin-bottom: 12px; }
.card__head h3 { font-size: 15px; font-weight: 650; }
.card--stack { display: flex; flex-direction: column; }
.sep { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }
.grid { display: grid; gap: 18px; }
.grid--chart { grid-template-columns: minmax(0, 1.75fr) minmax(0, 1fr); }
.card--chart { display: flex; flex-direction: column; }
.card--chart .bars { flex: 1 1 auto; height: auto; min-height: calc(var(--h) + 26px); }
.grid--half { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.eyebrow { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 650; color: var(--brand-text); text-transform: uppercase; letter-spacing: .06em; }
.eyebrow__muted { color: var(--text-3); font-weight: 500; text-transform: none; letter-spacing: 0; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 8px; border-radius: 6px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
  background: var(--surface-3); color: var(--text-2);
}
.badge .i { width: 12px; height: 12px; stroke-width: 2.2; }
.badge--ok { background: var(--ok-soft); color: var(--ok-text); }
.badge--warn { background: var(--warn-soft); color: var(--warn-text); }
.badge--bad { background: var(--bad-soft); color: var(--bad-text); }
.badge--brand { background: var(--brand-soft); color: var(--brand-text); }

.delta { display: inline-flex; align-items: center; gap: 2px; font-size: 12px; font-weight: 650; padding: 1px 6px 1px 4px; border-radius: 6px; font-variant-numeric: tabular-nums; }
.delta .i { width: 13px; height: 13px; stroke-width: 2.4; }
.delta--good { color: var(--ok-text); background: var(--ok-soft); }
.delta--bad { color: var(--bad-text); background: var(--bad-soft); }
.delta--flat { color: var(--text-3); background: var(--surface-2); }

/* ---------- 6. RIEPILOGO ---------- */
.brief {
  position: relative; overflow: hidden;
  display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 22px; align-items: start;
  padding: 22px 24px; border-radius: var(--r-lg);
  border: 1px solid var(--border);
  background:
    radial-gradient(120% 140% at 0% 0%, color-mix(in srgb, var(--primary) 9%, transparent) 0%, transparent 55%),
    radial-gradient(80% 120% at 100% 0%, color-mix(in srgb, var(--yellow) 12%, transparent) 0%, transparent 50%),
    var(--surface);
}
.brief__mascot { width: 92px; height: 92px; border-radius: 22px; background: var(--surface-2); border: 1px solid var(--border); display: grid; place-items: center; }
.brief__mascot img { width: 80px; height: 80px; object-fit: contain; }
.brief__body { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.brief__title { font-size: 21px; font-weight: 680; line-height: 1.3; text-wrap: balance; }
.insights { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 8px; }
.insight {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: center;
  padding: 10px 10px 10px 14px; border-radius: var(--r);
  background: color-mix(in srgb, var(--surface) 70%, transparent); border: 1px solid var(--border);
}
.insight__mark { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; }
.insight__mark .i { width: 16px; height: 16px; }
.insight--warn .insight__mark { background: var(--warn-soft); color: var(--warn-text); }
.insight--bad .insight__mark { background: var(--bad-soft); color: var(--bad-text); }
.insight--ok .insight__mark { background: var(--ok-soft); color: var(--ok-text); }
.insight__text strong { display: block; font-weight: 620; font-size: 14px; }
.insight__text span { display: block; font-size: 12.5px; color: var(--text-3); }

.kpis { display: grid; grid-template-columns: minmax(0, 1.5fr) repeat(4, minmax(0, 1fr)); gap: 12px; }
.kpi {
  display: flex; flex-direction: column; gap: 6px; min-width: 0;
  padding: 16px 16px 14px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--border);
  color: var(--text); text-align: left; transition: border-color .15s, transform .15s, box-shadow .15s;
}
a.kpi:hover { border-color: var(--border-strong); transform: translateY(-1px); box-shadow: 0 6px 18px -10px rgb(15 23 36 / .2); }
.kpi__label { display: flex; align-items: center; justify-content: space-between; gap: 6px; font-size: 12.5px; color: var(--text-2); font-weight: 550; }
.kpi__label .i { color: var(--text-3); width: 16px; height: 16px; }
.kpi__value { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.kpi__value .num { font-size: 28px; font-weight: 600; line-height: 1.1; }
.kpi__value .unit { font-size: 15px; color: var(--text-3); font-weight: 600; }
.kpi__foot { font-size: 12px; color: var(--text-3); margin-top: auto; }
/* card «Voti positivi»: la sfumatura segue la percentuale (verde sopra il 50%, rossa sotto) */
.kpi--hero { --tone: var(--idle); grid-row: span 1; padding: 18px; background: linear-gradient(160deg, color-mix(in srgb, var(--tone) 7%, var(--surface)), var(--surface) 60%); }
.kpi--hero.kpi--good { --tone: var(--ok); }
.kpi--hero.kpi--bad { --tone: var(--bad); }
.kpi--hero .kpi__value .num { font-size: 44px; }
.kpi__few { align-self: center; }
.kpi__bar { width: 100%; height: 10px; margin: 4px 0 2px; }
.kpi__bar .seg--ok { background: var(--ok); }
.kpi__bar .seg--bad { background: var(--bad); }

/* barre giornaliere (HTML, così restano accessibili e responsive) */
.bars {
  --h: 200px;
  position: relative; display: flex; align-items: flex-end; gap: 3px;
  height: calc(var(--h) + 26px); padding: 0 0 26px 30px;
}
.bars__grid { position: absolute; inset: 0 0 26px 30px; display: flex; flex-direction: column-reverse; justify-content: space-between; pointer-events: none; }
.bars__grid span { position: relative; border-top: 1px dashed var(--border); height: 0; }
.bars__grid span::before { content: attr(data-v); position: absolute; left: -30px; top: -8px; width: 24px; text-align: right; font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.bar {
  position: relative; flex: 1 1 0; min-width: 4px; height: 100%;
  display: flex; flex-direction: column; justify-content: flex-end;
  border: 0; padding: 0; background: none; border-radius: 6px;
}
.bar__ok, .bar__warn { display: block; width: 100%; transition: background-color .15s; }
.bar__ok { background: var(--brand-bar); border-radius: 0 0 4px 4px; }
.bar__warn { background: var(--warn); border-radius: 4px 4px 0 0; }
.bar__ok:only-child, .bar__stack > :only-child { border-radius: 4px; }
.bar__stack { display: flex; flex-direction: column; width: 100%; }
.bar__stack--zero { height: 2px; border-radius: 2px; background: var(--border-strong); }
.bar[disabled] { cursor: default; }
.bar__x { position: absolute; bottom: -22px; left: 50%; transform: translateX(-50%); font-size: 11px; color: var(--text-3); white-space: nowrap; font-variant-numeric: tabular-nums; }
.bar__stack { transition: opacity .15s; }
.bar.is-active .bar__ok { background: var(--bar-active); }
.bar.is-active .bar__warn { background: var(--warn-strong); }
.bars.has-active .bar:not(.is-active) .bar__stack { opacity: .4; }
.bar--today .bar__x { color: var(--text); font-weight: 650; }
.tip {
  position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%);
  z-index: 3; min-width: 150px; padding: 9px 11px; border-radius: 10px;
  background: var(--text); color: var(--bg); font-size: 12px; line-height: 1.45; text-align: left;
  pointer-events: none; opacity: 0; transition: opacity .12s; white-space: nowrap;
}
.tip b { display: block; font-size: 12.5px; margin-bottom: 2px; }
.tip i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }
.bar.is-active .tip { opacity: 1; }
.tip small { display: block; margin-top: 4px; opacity: .7; }
.bar:first-of-type .tip, .bar:nth-of-type(2) .tip, .bar:nth-of-type(3) .tip { left: 0; transform: none; }
.bar:last-of-type .tip, .bar:nth-last-of-type(2) .tip, .bar:nth-last-of-type(3) .tip { left: auto; right: 0; transform: none; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.sw--brand { background: var(--brand-bar); } .sw--warn { background: var(--warn); }
.sw--ok { background: var(--ok); } .sw--bad { background: var(--bad); } .sw--idle { background: var(--surface-3); border: 1px solid var(--border-strong); }

.stackbar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; gap: 2px; background: var(--surface-2); }
.stackbar span { display: block; height: 100%; transition: flex-grow .4s var(--ease); }
.fb-legend { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 4px; }
.fb-legend li a, .fb-legend li > div {
  display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 10px;
  padding: 7px 8px; margin: 0 -8px; border-radius: 8px; color: var(--text);
}
.fb-legend li a:hover { background: var(--surface-2); }
.fb-legend .num { font-size: 14px; }
.fb-legend .pct { font-size: 12px; color: var(--text-3); width: 38px; text-align: right; }

.funnel { display: grid; gap: 10px; }
.funnel__row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: center; font-size: 13px; }
.funnel__track { grid-column: 1 / -1; height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.funnel__track span { display: block; height: 100%; border-radius: 4px; background: var(--brand-bar); }
.funnel__row--hit .funnel__track span { background: var(--ok); }
.funnel__note { font-size: 12.5px; color: var(--text-3); }

.rank { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.rank a {
  display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; gap: 4px 12px; align-items: center;
  padding: 9px 8px; margin: 0 -8px; border-radius: 10px; color: var(--text);
}
.rank a:hover { background: var(--surface-2); }
.rank__pos { font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; text-align: center; }
.rank__name { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank__val { font-size: 12.5px; color: var(--text-3); white-space: nowrap; font-variant-numeric: tabular-nums; }
.rank__val b { color: var(--text); font-weight: 650; }
.rank__track { grid-column: 2 / -1; display: flex; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.rank__track span:first-child { background: var(--brand-bar); }
.rank__track span:last-child { background: var(--warn); }

.feed { list-style: none; margin: 0; padding: 0; display: grid; }
.feed a {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: center;
  padding: 10px 8px; margin: 0 -8px; border-radius: 10px; color: var(--text);
}
.feed a:hover { background: var(--surface-2); }
.feed li + li a { border-top: 1px solid var(--border); border-radius: 0; }
.feed li + li a:hover { border-radius: 10px; border-color: transparent; }
.feed__q { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed__meta { font-size: 12px; color: var(--text-3); }
.feed__time { font-size: 12px; color: var(--text-3); white-space: nowrap; font-variant-numeric: tabular-nums; }
.avatar-dot { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; flex: none; }
.avatar-dot .i { width: 16px; height: 16px; }
.avatar-dot--ok { background: var(--ok-soft); color: var(--ok-text); }
.avatar-dot--warn { background: var(--warn-soft); color: var(--warn-text); }
.avatar-dot--bad { background: var(--bad-soft); color: var(--bad-text); }
.avatar-dot--idle { background: var(--idle-soft); color: var(--text-3); }

/* ---------- 7. CHAT ---------- */
.view--split {
  display: grid; grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); gap: 0;
  height: calc(100dvh - var(--topbar-h) - 48px); min-height: 520px;
  border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; background: var(--surface);
}
.inbox { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--border); background: var(--surface); }
.inbox__head { display: flex; flex-direction: column; gap: 10px; padding: 14px; border-bottom: 1px solid var(--border); }
.search {
  display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 8px 0 11px;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-3);
}
.search:focus-within { border-color: var(--primary); box-shadow: var(--ring); background: var(--surface); }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; color: var(--text); font-size: 13.5px; }
.search input::-webkit-search-cancel-button { display: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.content:has(> .view--split:not([hidden])) { padding-bottom: 24px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px; flex: none;
  border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
  font-size: 12.5px; font-weight: 550; color: var(--text-2);
}
.chip:hover { border-color: var(--border-strong); color: var(--text); }
.chip[aria-checked="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip__n { font-size: 11.5px; opacity: .7; font-variant-numeric: tabular-nums; }
.chip .dot { width: 7px; height: 7px; }
.context-pill {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 6px 6px 6px 10px; border-radius: 8px; background: var(--brand-soft); color: var(--brand-text); font-size: 12.5px; font-weight: 550;
}
.context-pill button { border: 0; background: none; color: inherit; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 6px; }
.context-pill button:hover { background: color-mix(in srgb, var(--primary) 14%, transparent); }

.inbox__list { flex: 1; overflow-y: auto; padding: 6px; outline: none; overscroll-behavior: contain; }
.inbox__day { position: sticky; top: -6px; z-index: 1; padding: 10px 10px 6px; font-size: 11.5px; font-weight: 650; color: var(--text-3); text-transform: uppercase; letter-spacing: .05em; background: var(--surface); }
.inbox__hint { display: flex; align-items: center; gap: 4px; padding: 8px 14px; font-size: 11.5px; color: var(--text-3); border-top: 1px solid var(--border); }
.item {
  position: relative; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 11px;
  width: 100%; padding: 11px 10px; border-radius: 10px; border: 0; background: none; text-align: left;
}
.item:hover { background: var(--surface-2); }
.item[aria-selected="true"] { background: var(--brand-soft); }
/* Chat su cui è aperto il menu (tasto destro): resta evidenziata finché il menu è aperto */
.item.is-menu-target { background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--border-strong); }
.item[aria-selected="true"].is-menu-target { background: var(--brand-soft); }
.item[aria-selected="true"]::before { content: ""; position: absolute; left: 0; top: 12px; bottom: 12px; width: 3px; border-radius: 3px; background: var(--primary); }
.item__status { grid-row: span 2; margin-top: 6px; }
.item__top { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.item__q { flex: 1; min-width: 0; font-weight: 580; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item--quiet .item__q { color: var(--text-3); font-weight: 500; font-style: italic; }
.item__time { font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; flex: none; }
.item__meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 12px; color: var(--text-3); min-width: 0; }
.item__meta .fb { display: inline-flex; margin-left: auto; }
.item__meta .fb .i { width: 15px; height: 15px; }
.fb--up { color: var(--ok-text); } .fb--down { color: var(--bad-text); }

.thread { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--bg); }
.thread__head { display: flex; flex-direction: column; gap: 10px; padding: 18px 22px; border-bottom: 1px solid var(--border); background: var(--surface); }
.thread__title { display: flex; align-items: flex-start; gap: 12px; justify-content: space-between; }
.thread__title h2 { font-size: 17px; font-weight: 650; line-height: 1.35; text-wrap: balance; }
.thread__facts { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12.5px; color: var(--text-2); }
.thread__facts span { display: inline-flex; align-items: center; gap: 6px; }
.thread__facts .i { width: 14px; height: 14px; color: var(--text-3); }
.thread__body { flex: 1; overflow-y: auto; padding: 22px; display: flex; flex-direction: column; gap: 14px; overscroll-behavior: contain; }
.sys { align-self: center; display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-3); padding: 4px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); }
.sys .i { width: 13px; height: 13px; }
.msg { display: flex; gap: 10px; max-width: min(640px, 88%); }
.msg--user { align-self: flex-end; flex-direction: row-reverse; }
.msg__av { width: 32px; height: 32px; border-radius: 10px; flex: none; background: var(--surface); border: 1px solid var(--border); display: grid; place-items: center; overflow: hidden; }
.msg__av img { width: 28px; height: 28px; object-fit: contain; }
.msg__av .i { width: 16px; height: 16px; color: var(--text-3); }
.msg__col { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.msg--user .msg__col { align-items: flex-end; }
.bubble { padding: 10px 14px; border-radius: 16px; font-size: 14px; line-height: 1.55; overflow-wrap: anywhere; }
.msg--tore .bubble { background: var(--surface); border: 1px solid var(--border); border-top-left-radius: 6px; }
.msg--user .bubble { background: var(--primary); color: #fff; border-top-right-radius: 6px; }
/* Risposte di e-Tore formattate (formatMessage): stessi elementi del Markdown mostrato nel widget */
.bubble--md p { margin: 0; }
.bubble--md p + p, .bubble--md p + ul, .bubble--md p + ol, .bubble--md ul + p, .bubble--md ol + p { margin-top: 8px; }
.bubble--md ul, .bubble--md ol { margin: 4px 0 0; padding-left: 20px; }
.bubble--md li + li { margin-top: 2px; }
.bubble--md strong { font-weight: 650; }
.bubble--md a { color: var(--brand-text); text-decoration: underline; text-underline-offset: 2px; }
.bubble--md code { font-family: 'JetBrains Mono', ui-monospace, monospace; font-size: .88em; padding: 1px 5px; border-radius: 5px; background: var(--surface-2); }
.msg--fallback .bubble { border-color: color-mix(in srgb, var(--warn) 55%, var(--border)); background: color-mix(in srgb, var(--warn-soft) 70%, var(--surface)); }
.msg__meta { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; font-size: 11.5px; color: var(--text-3); }
.teach-btn {
  display: inline-flex; align-items: center; gap: 5px; height: 26px; padding: 0 9px; border-radius: 7px;
  border: 1px solid var(--border); background: var(--surface); font-size: 12px; font-weight: 600; color: var(--text-2);
  transition: border-color .15s, color .15s;
}
/* «Insegna a e-Tore» è sempre visibile, non solo al passaggio del mouse */
.teach-btn .i { width: 13px; height: 13px; }
.teach-btn:hover { border-color: var(--border-strong); color: var(--text); }
.teach-btn[disabled] { opacity: 1; cursor: default; background: var(--ok-soft); color: var(--ok-text); border-color: transparent; }
.thread__foot { flex: none; padding: 12px 22px; border-top: 1px solid var(--border); background: var(--surface); }
.verdict { display: flex; align-items: center; gap: 12px; }
.verdict__label { display: block; font-size: 11.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); }
.verdict p { font-size: 13px; color: var(--text-2); }
.verdict strong { color: var(--text); }
.verdict q { display: block; margin-top: 2px; font-style: italic; color: var(--text-2); }

.empty { margin: auto; max-width: 340px; padding: 36px 20px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.empty img { width: 96px; height: 96px; object-fit: contain; margin-bottom: 6px; }
.empty__icon { width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center; background: var(--surface-2); color: var(--text-3); margin-bottom: 4px; }
.empty h3 { font-size: 15px; font-weight: 650; }
.empty p { font-size: 13px; color: var(--text-3); }

/* ---------- 8. DA INSEGNARE ---------- */
.gaps-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.tabs { display: inline-flex; gap: 4px; padding: 3px; border-radius: 11px; background: var(--surface-2); border: 1px solid var(--border); overflow-x: auto; max-width: 100%; scrollbar-width: none; }
.tabs button {
  white-space: nowrap;
  display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 12px; flex: none;
  border: 0; border-radius: 8px; background: none; font-size: 13px; font-weight: 550; color: var(--text-2);
}
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgb(15 23 36 / .08), 0 0 0 1px var(--border); }
.tabs .n { font-size: 11.5px; min-width: 20px; height: 18px; border-radius: 9px; padding: 0 6px; display: inline-grid; place-items: center; background: var(--surface-3); color: var(--text-2); font-variant-numeric: tabular-nums; }
.callout {
  display: flex; gap: 12px; align-items: flex-start; padding: 12px 16px; border-radius: var(--r);
  background: var(--brand-soft); color: var(--text-2); font-size: 13px;
}
.callout .i { color: var(--brand-text); margin-top: 1px; }
.callout strong { color: var(--text); }

.gap-list { display: grid; gap: 10px; }
.gap {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 16px; align-items: center;
  padding: 16px 18px; border-radius: var(--r-lg); border: 1px solid var(--border); background: var(--surface);
  transition: border-color .15s;
}
.gap:hover { border-color: var(--border-strong); }
/* Domanda su cui è aperto il menu (tasto destro): resta evidenziata finché il menu è aperto */
.gap.is-menu-target { border-color: var(--border-strong); background: var(--surface-2); }
.gap--done { opacity: .72; }
.gap__count { width: 56px; text-align: center; }
.gap__count .num { display: block; font-size: 24px; font-weight: 600; line-height: 1.1; }
.gap__count span { font-size: 11px; color: var(--text-3); }
.gap__main { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.gap__topic { font-size: 15px; font-weight: 640; }
.gap__ex { font-size: 13px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gap__meta { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--text-3); }
.gap__meta span { display: inline-flex; align-items: center; gap: 5px; }
.gap__meta .i { width: 13px; height: 13px; }
.gap__actions { display: flex; align-items: center; gap: 6px; }
.status-select { position: relative; }
.status-select select {
  appearance: none; height: 34px; padding: 0 30px 0 26px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface); font-size: 13px; font-weight: 600; color: var(--text);
}
.status-select select:hover { border-color: var(--border-strong); }
.status-select .dot { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); pointer-events: none; }
.status-select > .i { position: absolute; right: 9px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--text-3); pointer-events: none; }

/* ---------- 9. IMPOSTAZIONI ---------- */
.settings { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 28px; align-items: start; }
.settings__nav { position: sticky; top: calc(var(--topbar-h) + 24px); display: flex; flex-direction: column; gap: 2px; }
.settings__nav a { padding: 8px 12px; border-radius: 8px; color: var(--text-2); font-weight: 520; font-size: 13.5px; }
.settings__nav a:hover { background: var(--surface-2); color: var(--text); }
.settings__nav a.is-active { color: var(--text); background: var(--surface); box-shadow: 0 0 0 1px var(--border); }
.settings__body { display: flex; flex-direction: column; gap: 18px; min-width: 0; max-width: 920px; padding-bottom: 72px; }
.setting { scroll-margin-top: calc(var(--topbar-h) + 20px); }
.setting__head { margin-bottom: 18px; display: flex; flex-direction: column; gap: 4px; }
.setting__head h3 { font-size: 16px; font-weight: 650; }
.setting__split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 300px); gap: 24px; align-items: start; }
.setting__fields { display: flex; flex-direction: column; gap: 4px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.row__label { display: block; font-weight: 600; font-size: 13.5px; color: var(--text); }
.row__help { font-size: 12.5px; color: var(--text-3); margin-top: 2px; }
.field { display: flex; flex-direction: column; gap: 6px; padding-top: 14px; }
.field__top { display: flex; justify-content: space-between; align-items: baseline; }
.field input, .field textarea, .inline-form input {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border-strong); background: var(--surface);
  font-size: 14px; line-height: 1.5; resize: vertical; transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field textarea:focus, .inline-form input:focus, .stepper input:focus { outline: 0; border-color: var(--primary); box-shadow: var(--ring); }
.switch {
  position: relative; width: 44px; height: 26px; flex: none; border-radius: 13px; border: 0; padding: 0;
  background: var(--border-strong); transition: background .2s;
}
.switch span { position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / .25); transition: transform .2s var(--ease); }
.switch[aria-checked="true"] { background: var(--ok); }
.switch[aria-checked="true"] span { transform: translateX(18px); }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--border-strong); border-radius: 10px; overflow: hidden; background: var(--surface); }
.stepper .icon-btn { border-radius: 0; width: 34px; height: 36px; }
.stepper input { width: 48px; height: 36px; border: 0; border-inline: 1px solid var(--border); text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; background: none; -moz-appearance: textfield; }
.stepper input::-webkit-inner-spin-button, .stepper input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

.preview { margin: 0; display: flex; flex-direction: column; gap: 8px; }
.preview__frame { position: relative; height: 250px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface-2); overflow: hidden; transition: opacity .2s, filter .2s; }
.preview__frame.is-off { opacity: .55; filter: grayscale(1); }
.preview__bar { display: flex; align-items: center; gap: 5px; height: 28px; padding: 0 10px; background: var(--surface); border-bottom: 1px solid var(--border); }
.preview__bar i { width: 7px; height: 7px; border-radius: 50%; background: var(--border-strong); }
.preview__bar span { margin-left: 8px; font-size: 10.5px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.preview__page { padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.ph { height: 8px; border-radius: 4px; background: var(--surface-3); width: 80%; }
.ph--title { height: 14px; width: 55%; }
.ph--short { width: 45%; }
.ph--block { height: 56px; width: 100%; margin-top: 6px; border-radius: 8px; }
/* Anteprima del saluto: copia in scala del widget (UnderdogChatBot-v1.js). Misure, colori,
   tempi e animazioni sono gli stessi del sito: se cambiano lì, vanno cambiati anche qui.
   I colori restano quelli del sito anche nel tema scuro, perché il visitatore li vede così. */
.preview__tools { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.preview__device button { height: 26px; padding: 0 9px; font-size: 12.5px; }
.preview__tools .btn[disabled] { cursor: default; opacity: .5; }
.preview__frame[data-device="mobile"] { width: 255px; max-width: 100%; height: 300px; margin-inline: auto; border-radius: 22px; }
.preview__frame[data-device="mobile"] .preview__bar i { display: none; }
.preview__frame[data-device="mobile"] .preview__bar span { margin-left: 2px; }
.pw {
  --pw-scale: .7;
  position: absolute; right: calc(20px * var(--pw-scale)); bottom: calc(20px * var(--pw-scale));
  width: 60px; height: 60px; transform: scale(var(--pw-scale)); transform-origin: bottom right;
  font-family: 'Inter', system-ui, sans-serif; pointer-events: none;
}
.preview__frame[data-device="mobile"] .pw { --pw-scale: .68; } /* 255 px rappresentano un telefono largo 375 px */
.pw__launcher {
  position: absolute; right: 0; bottom: 0; z-index: 5; width: 60px; height: 60px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #2974B4 0%, #1b5385 100%); box-shadow: 0 10px 25px rgba(41, 116, 180, .4);
}
.pw__launcher svg { width: 30px; height: 30px; fill: #fff; }
.pw__peek {
  position: absolute; right: 0; bottom: 0; z-index: 1; width: 60px; height: 90px;
  opacity: 0; transform: translateY(70px) scale(.85); transform-origin: bottom center;
  transition: transform .6s cubic-bezier(.175, .885, .32, 1.275), opacity .4s ease;
}
.pw__peek img { width: 100%; height: 100%; object-fit: contain; object-position: top center; filter: drop-shadow(0 4px 10px rgba(0, 0, 0, .15)); }
.pw__peek.show { opacity: 1; transform: translateY(-34px) scale(1); }
.pw__peek.greet img { transform-origin: bottom center; animation: pw-wave .5s ease-in-out .65s 2; }
@keyframes pw-wave { 0%, 100% { transform: rotate(0deg); } 25% { transform: rotate(-7deg); } 75% { transform: rotate(6deg); } }
.pw__nudge {
  position: absolute; right: 68px; bottom: 70px; z-index: 2; width: max-content; max-width: 260px;
  padding: 12px 34px 12px 16px; border-radius: 18px 18px 4px 18px; background: #fff;
  border: 1px solid #E5E7EB; box-shadow: 0 10px 25px rgba(0, 0, 0, .12);
  opacity: 0; transform: translateY(8px) scale(.6); transform-origin: bottom right;
  transition: opacity .25s ease, transform .45s cubic-bezier(.175, .885, .32, 1.275);
}
.pw__nudge.show { opacity: 1; transform: translateY(0) scale(1); }
.pw__nudge::after {
  content: ''; position: absolute; right: -6px; bottom: 12px; width: 10px; height: 10px; background: #fff;
  border-top: 1px solid #E5E7EB; border-right: 1px solid #E5E7EB; transform: rotate(45deg);
}
.pw__face { display: none; }
.pw__body { position: relative; min-width: 0; }
.pw__text { display: block; font-size: 14px; line-height: 1.45; font-weight: 500; color: #1F2937; }
.pw__text .pw__rest { visibility: hidden; }
.pw__close {
  position: absolute; top: 6px; right: 8px; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center;
  font-size: 18px; line-height: 1; color: #6B7280;
}
/* Telefono: il pulsante si allarga e mostra il volto di e-Tore con il messaggio */
.preview__frame[data-device="mobile"] .pw__peek { display: none; }
.preview__frame[data-device="mobile"] .pw__nudge {
  right: 0; bottom: 0; z-index: 6; max-width: 335px; min-height: 60px;
  display: flex; align-items: center; gap: 10px; padding: 8px 42px 8px 8px;
  border: 0; border-radius: 30px; background: linear-gradient(135deg, #2974B4 0%, #1b5385 100%);
  box-shadow: 0 10px 25px rgba(41, 116, 180, .4);
  transform: none; clip-path: inset(0 0 0 calc(100% - 60px) round 30px);
  transition: clip-path .5s cubic-bezier(.2, .9, .3, 1.1), opacity .2s ease;
}
.preview__frame[data-device="mobile"] .pw__nudge.show { transform: none; clip-path: inset(0 0 0 0 round 30px); }
.preview__frame[data-device="mobile"] .pw__nudge::after { display: none; }
.preview__frame[data-device="mobile"] .pw__face {
  display: block; flex: none; width: 44px; height: 44px; border-radius: 50%;
  object-fit: cover; object-position: center 8%; background: #fff;
}
.preview__frame[data-device="mobile"] .pw__text { color: #fff; }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.97); } }
.preview__frame[data-device="mobile"] .pw__close { top: 50%; right: 10px; width: 28px; height: 28px; transform: translateY(-50%); color: rgba(255, 255, 255, .85); }

.tokens { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.tokens li { display: inline-flex; align-items: center; gap: 4px; height: 32px; padding: 0 4px 0 11px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); font-family: var(--mono); font-size: 12.5px; }
.tokens button { width: 24px; height: 24px; border: 0; background: none; border-radius: 6px; display: grid; place-items: center; color: var(--text-3); }
.tokens button:hover { background: var(--bad-soft); color: var(--bad-text); }
.tokens .i { width: 14px; height: 14px; }
.inline-form { display: flex; gap: 8px; max-width: 420px; }
.inline-form input { font-family: var(--mono); font-size: 13px; height: 38px; padding: 0 12px; }
.field-error { margin-top: 8px; font-size: 12.5px; color: var(--bad-text); font-weight: 550; }


.savebar {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(calc(-50% + var(--sb-w) / 2)); z-index: 40;
  display: flex; align-items: center; gap: 24px; padding: 10px 10px 10px 18px; border-radius: 14px;
  background: var(--surface); box-shadow: var(--shadow-pop); font-size: 13.5px; font-weight: 550;
  animation: rise .3s var(--ease);
}
.savebar > span { display: inline-flex; align-items: center; gap: 8px; }
.savebar > div { display: flex; gap: 8px; }
@keyframes rise { from { opacity: 0; transform: translate(calc(-50% + var(--sb-w) / 2), 12px); } }

/* ---------- 10. PALETTE + TOAST ---------- */
.palette-backdrop {
  position: fixed; inset: 0; z-index: 60; display: flex; justify-content: center; align-items: flex-start;
  padding: 12vh 16px 16px; background: rgb(10 14 20 / .38); backdrop-filter: blur(3px);
  animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } }
.palette { width: min(620px, 100%); max-height: 70vh; display: flex; flex-direction: column; border-radius: 16px; background: var(--surface); box-shadow: var(--shadow-pop); overflow: hidden; animation: pop .2s var(--ease); }
.palette__input { display: flex; align-items: center; gap: 10px; padding: 0 14px; height: 56px; border-bottom: 1px solid var(--border); color: var(--text-3); }
.palette__input input { flex: 1; border: 0; outline: 0; background: none; font-size: 15.5px; color: var(--text); }
.palette__list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; }
.palette__group { padding: 10px 10px 4px; font-size: 11.5px; font-weight: 650; color: var(--text-3); text-transform: uppercase; letter-spacing: .05em; }
.palette__item { display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 9px; cursor: pointer; }
.palette__item .i { color: var(--text-3); }
.palette__item[aria-selected="true"] { background: var(--brand-soft); }
.palette__item[aria-selected="true"] .i { color: var(--brand-text); }
.palette__item span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette__item small { color: var(--text-3); font-size: 12px; flex: none; }
.palette__empty { padding: 24px; text-align: center; color: var(--text-3); }
.palette__foot { display: flex; gap: 16px; padding: 10px 14px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-3); }
.palette__foot span { display: inline-flex; align-items: center; gap: 4px; }

.toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 70; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 12px; padding: 10px 10px 10px 14px;
  border-radius: 12px; background: var(--text); color: var(--bg); font-size: 13.5px; font-weight: 520;
  box-shadow: 0 16px 40px -12px rgb(0 0 0 / .45); animation: pop .25s var(--ease);
}
.toast .i { color: var(--ok); }
.toast button { border: 0; background: color-mix(in srgb, var(--bg) 16%, transparent); color: var(--bg); padding: 5px 10px; border-radius: 7px; font-weight: 650; font-size: 13px; }
.toast button:hover { background: color-mix(in srgb, var(--bg) 26%, transparent); }

.tabbar { display: none; }

/* ---------- 11. RESPONSIVE ---------- */
@media (max-width: 1280px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kpi--hero { grid-column: span 3; display: grid; grid-template-columns: auto 1fr; grid-template-areas: "label bar" "value bar" "foot bar"; column-gap: 28px; }
  .kpi--hero .kpi__label { grid-area: label; }
  .kpi--hero .kpi__value { grid-area: value; }
  .kpi--hero .kpi__foot { grid-area: foot; }
  .kpi--hero .kpi__bar { grid-area: bar; height: 12px; align-self: center; margin: 0; }
  .kpis .kpi:not(.kpi--hero):last-child { grid-column: span 1; }
}
@media (max-width: 1280px) and (min-width: 861px) {
  .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .kpi--hero { grid-column: span 4; }
}
@media (max-width: 1120px) {
  :root:not([data-sidebar]) { --sb-w: 76px; }
  :root:not([data-sidebar]) .brand__text, :root:not([data-sidebar]) .nav__label, :root:not([data-sidebar]) .tore-status__text { display: none; }
  :root:not([data-sidebar]) .sidebar__top { flex-direction: column; }
  :root:not([data-sidebar]) .nav__item { justify-content: center; padding: 0; }
  :root:not([data-sidebar]) .nav__count { position: absolute; top: 2px; right: 4px; min-width: 18px; height: 16px; font-size: 10px; padding: 0 4px; }
  :root:not([data-sidebar]) .tore-status { justify-content: center; padding: 6px; }
  .grid--chart { grid-template-columns: minmax(0, 1fr); }
  .search-trigger { min-width: 0; }
  .search-trigger__label { display: none; }
  .setting__split { grid-template-columns: minmax(0, 1fr); }
  .settings { grid-template-columns: minmax(0, 1fr); }
  .settings__nav { position: static; flex-direction: row; overflow-x: auto; scrollbar-width: none; }
  .settings__nav a { white-space: nowrap; }
}

@media (max-width: 860px) {
  :root { --topbar-h: 57px; }
  body { font-size: 15px; }
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; }
  .topbar { min-height: 56px; gap: 8px; padding: 8px 12px 8px 16px; padding-top: max(8px, env(safe-area-inset-top)); }
  .topbar__logo { display: block; width: 32px; height: 32px; object-fit: contain; border-radius: 8px; background: #fff; padding: 2px; border: 1px solid var(--border); }
  .topbar__title h1 { font-size: 17px; }
  .topbar__title p { display: none; }
  .topbar__tools { display: contents; }
  .content > .period { display: flex; width: 100%; margin-bottom: 14px; }
  .period button { flex: 1; justify-content: center; height: 34px; }
  .search-trigger { width: 38px; height: 38px; padding: 0; justify-content: center; }
  .search-trigger .kbd { display: none; }
  .icon-btn { width: 38px; height: 38px; }
  .popover { left: 0; right: 0; flex-wrap: wrap; }
  .popover label { flex: 1; }
  .content { padding: 16px 16px calc(88px + env(safe-area-inset-bottom)); }
  .view { gap: 14px; }

  .brief { grid-template-columns: minmax(0, 1fr); padding: 18px; gap: 12px; }
  .brief__mascot { position: absolute; right: 14px; top: 14px; width: 56px; height: 56px; border-radius: 16px; }
  .brief__mascot img { width: 48px; height: 48px; }
  .brief__body .eyebrow { padding-right: 64px; }
  .brief__title { font-size: 18px; padding-right: 64px; }
  .eyebrow__muted { display: none; }
  .insight { grid-template-columns: auto minmax(0, 1fr) auto; padding: 12px; gap: 10px; align-items: start; }
  .insight__go { width: 40px; height: 40px; padding: 0; }
  .insight__go span { display: none; }

  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi--hero { grid-column: span 2; grid-template-columns: 1fr; grid-template-areas: "label" "value" "bar" "foot"; }
  .kpi--hero .kpi__value .num { font-size: 38px; }
  .kpi--hero .kpi__bar { height: 10px; margin: 4px 0 2px; }
  .kpi__value .num { font-size: 24px; }
  .grid--half { grid-template-columns: minmax(0, 1fr); }
  .card { padding: 16px; }
  .bars { --h: 160px; gap: 2px; }
  .bar__x { font-size: 10px; }

  .view--split { display: block; height: auto; min-height: 0; border: 0; border-radius: 0; background: none; overflow: visible; }
  .inbox { border: 1px solid var(--border); border-radius: var(--r-lg); overflow: clip; }
  .inbox__head { border-radius: var(--r-lg) var(--r-lg) 0 0; }
  .chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -14px; padding: 0 14px; }
  .inbox__head { position: sticky; top: var(--topbar-h); z-index: 5; background: var(--surface); }
  .inbox__list { overflow: visible; }
  .inbox__day { position: static; }
  .inbox__hint { display: none; }
  .item { padding: 13px 10px; }
  .thread { display: none; }
  .view--split.is-detail .inbox { display: none; }
  .view--split.is-detail .thread { display: flex; border: 1px solid var(--border); border-radius: var(--r-lg); overflow: clip; }
  .view--split.is-detail .thread { min-height: calc(100dvh - var(--topbar-h) - 16px - 88px - env(safe-area-inset-bottom)); }
  .view--split.is-detail .thread__body { flex: 1 0 auto; }
  /* La regola delle viste divise (padding-bottom: 24px) è più specifica di .content qui sopra:
     senza questa riga la chat finisce sotto la barra in basso (66 px) e il fondo resta coperto. */
  .content:has(> .view--split:not([hidden])) { padding-bottom: calc(88px + env(safe-area-inset-bottom)); }
  /* Il giudizio del cliente sta in fondo alla conversazione, non agganciato sopra i messaggi:
     così non copre risposte, etichette e pulsanti mentre si scorre (in alto c'è già l'etichetta del voto). */
  .thread__foot { padding: 14px 16px; }
  .thread__head { padding: 16px; }
  .thread__body { padding: 16px 12px; overflow: visible; }
  .msg { max-width: 94%; }
  .teach-btn { height: 44px; }
  .is-detail-mode .topbar__back { display: inline-grid; }
  .is-detail-mode .topbar__logo { display: none; }
  .is-detail-mode .period { display: none; }

  .gap { grid-template-columns: auto minmax(0, 1fr); padding: 14px; gap: 12px; }
  .gap__count { width: 44px; }
  .gap__ex { white-space: normal; }
  .gap__actions { grid-column: 1 / -1; flex-wrap: wrap; }
  .gap__actions .status-select { flex: 1; }
  .gap__actions .status-select select { width: 100%; height: 40px; }
  .gap__actions .btn { height: 40px; }
  .gaps-head { flex-direction: column; align-items: stretch; }
  .gaps-head .btn { align-self: flex-end; height: 34px; }
  .tabs { width: 100%; }
  .tabs button { flex: 1 0 auto; justify-content: center; padding: 0 10px; }

  .row { align-items: flex-start; }
  .savebar { left: 12px; right: 12px; bottom: calc(76px + env(safe-area-inset-bottom)); transform: none; justify-content: space-between; gap: 10px; animation: none; }
  .savebar > span { font-size: 13px; }
  .toasts { bottom: calc(84px + env(safe-area-inset-bottom)); width: calc(100% - 32px); }

  .tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    display: grid; grid-template-columns: repeat(4, 1fr);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: saturate(1.4) blur(16px); -webkit-backdrop-filter: saturate(1.4) blur(16px);
    border-top: 1px solid var(--border);
  }
  .tabbar a { position: relative; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 0; min-height: 52px; border-radius: 12px; color: var(--text-3); font-size: 11px; font-weight: 600; }
  .tabbar a .i { width: 22px; height: 22px; }
  .tabbar a[aria-current="page"] { color: var(--brand-text); }
  .tabbar a[aria-current="page"] .i { stroke-width: 2.2; }
  .tabbar__badge { position: absolute; top: 2px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--primary); color: #fff; font-size: 10.5px; font-weight: 700; display: grid; place-items: center; }
  .tabbar__badge--warn { background: var(--warn); color: #2b1a00; }
  .tabbar__badge:empty { display: none; }
}

@media (max-width: 400px) {
  .kpi__value .num { font-size: 22px; }
  .period button { padding: 0 6px; font-size: 12.5px; }
}

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



/* =========================================================
   12. AGGIUNTE PER LA DASHBOARD UFFICIALE
   Accesso, avvisi di stato, sincronizzazione, salvataggi in corso,
   esportazioni e impostazioni tecniche (assenti nel mock-up).
   ========================================================= */

/* ---------- Accesso ---------- */
.login {
  position: relative; min-height: 100dvh; display: grid; place-items: center;
  padding: max(32px, env(safe-area-inset-top)) 16px max(32px, env(safe-area-inset-bottom));
  background:
    radial-gradient(90% 70% at 0% 0%, color-mix(in srgb, var(--primary) 10%, transparent) 0%, transparent 60%),
    radial-gradient(70% 60% at 100% 100%, color-mix(in srgb, var(--yellow) 14%, transparent) 0%, transparent 55%),
    var(--bg);
}
.login__theme { position: absolute; top: max(14px, env(safe-area-inset-top)); right: 14px; }
.login__card {
  width: min(420px, 100%); display: flex; flex-direction: column; gap: 18px;
  padding: 28px; border-radius: 20px; background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow-pop); animation: view-in .3s var(--ease);
}
.login__brand { display: flex; align-items: center; gap: 10px; }
.login__hero { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 16px; align-items: center; }
.login__mascot { width: 76px; height: 76px; border-radius: 20px; background: var(--surface-2); border: 1px solid var(--border); display: grid; place-items: center; }
.login__mascot img { width: 64px; height: 64px; object-fit: contain; }
.login__hero h1 { font-size: 22px; font-weight: 680; margin-bottom: 4px; }
.login__form { display: flex; flex-direction: column; gap: 4px; }
.login__form .field { padding-top: 0; }
.pwd { position: relative; display: block; }
.pwd input { padding-right: 48px; }
.pwd .icon-btn { position: absolute; right: 3px; top: 50%; transform: translateY(-50%); }
.login__submit { width: 100%; height: 44px; margin-top: 10px; font-size: 14.5px; }
.login__or { display: flex; align-items: center; gap: 12px; font-size: 12px; color: var(--text-3); }
.login__or::before, .login__or::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.login__demo { width: 100%; }
.login__foot { text-align: center; font-size: 12px; color: var(--text-3); }

/* ---------- Avvisi di stato ---------- */
.notice {
  display: flex; align-items: center; gap: 12px; margin-bottom: 18px;
  padding: 10px 10px 10px 16px; border-radius: var(--r); border: 1px solid var(--border);
  background: var(--surface); font-size: 13px; color: var(--text-2);
}
.notice p { flex: 1; min-width: 0; }
.notice strong { color: var(--text); }
.notice--demo { background: color-mix(in srgb, var(--yellow) 13%, var(--surface)); border-color: color-mix(in srgb, var(--yellow) 45%, var(--border)); }
.notice--demo > .i { color: #9a7600; }
[data-theme="dark"] .notice--demo { background: color-mix(in srgb, var(--yellow) 7%, var(--surface)); border-color: color-mix(in srgb, var(--yellow) 28%, var(--border)); }
[data-theme="dark"] .notice--demo > .i { color: var(--yellow); }
/* Con un avviso in cima la vista Chat si accorcia: il giudizio resta visibile in fondo al pannello */
@media (min-width: 861px) {
  .content:has(> .notice:not([hidden])) > .view--split { height: calc(100dvh - var(--topbar-h) - 48px - 72px); }
}
.notice--error { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 35%, var(--border)); }
.notice--error > .i { color: var(--bad-text); }

/* ---------- Sincronizzazione e caricamento ---------- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: .45; } }
.sync-btn.is-spinning .i, .i.spin { animation: spin .9s linear infinite; }
.btn[disabled], .icon-btn[disabled] { opacity: .65; cursor: progress; }
.insight--loading .insight__mark { background: var(--surface-3); animation: pulse 1.2s ease-in-out infinite; }

.delta--neutral { color: var(--text-2); background: var(--surface-2); }
.toast--error .i { color: var(--bad); }
.toast--info .i { color: var(--brand-bar); }

/* Il fumetto delle barre esiste solo quando è attivo: da nascosto non deve allargare la pagina
   (la posizione vicino ai bordi la corregge setActiveBar in dashboard.js) */
.tip { display: none; }
.bar.is-active .tip { display: block; }

/* ---------- Chat: segnalazioni ---------- */
.teach-btn.is-busy, .link-btn.is-busy { opacity: 1; cursor: progress; pointer-events: none; color: var(--text-3); }
/* Lo stato si legge, le azioni si premono: arancione solo per gli avvisi, colore delle azioni solo nelle icone */
.i--ok { color: var(--ok); }
.i--brand { color: var(--primary); }
.hint-text { display: inline-flex; align-items: center; gap: 4px; color: var(--warn-text); font-weight: 600; }
.hint-text .i { width: 13px; height: 13px; }
.link-btn { border: 0; background: none; padding: 2px 4px; margin: 0 -4px; border-radius: 6px; font-size: 12px; font-weight: 600; color: var(--text-2); text-decoration: underline; text-underline-offset: 2px; text-decoration-color: var(--border-strong); }
.link-btn:hover { color: var(--text); text-decoration-color: currentColor; }
.msg__decide { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding-top: 8px; border-top: 1px dashed var(--border); }
.msg__ask { flex-basis: 100%; font-size: 12.5px; font-weight: 600; color: var(--text); }
.msg__busy { font-size: 12px; color: var(--text-3); }
.decide-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 11px; border-radius: 8px;
  border: 1px solid var(--border-strong); background: var(--surface); font-size: 12.5px; font-weight: 600; color: var(--text);
}
.decide-btn .i { width: 14px; height: 14px; }
.decide-btn:hover { background: var(--surface-2); }
/* Su telefono: comandi alti 44 px, comodi da toccare */
@media (max-width: 860px) {
  .decide-btn { height: 44px; flex: 1 1 auto; justify-content: center; }
  .link-btn { min-height: 44px; display: inline-flex; align-items: center; padding: 0 8px; margin: 0 -8px; }
}
/* «Forse non sapeva»: suggerimento da controllare, più tenue del «Non sapeva» segnalato dall'operatore */
.badge--hint { background: transparent; color: var(--warn-text); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--warn) 55%, var(--border)); }
.dot--hint { background: transparent; box-shadow: inset 0 0 0 2px var(--warn); }
.inbox__foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 14px; border-top: 1px solid var(--border); }
.inbox__foot .inbox__hint { padding: 0; border-top: 0; }
.inbox__export { border: 0; background: none; padding: 4px 0; font-size: 12px; }

/* ---------- Da insegnare ---------- */
button.gap__ex {
  display: block; width: 100%; padding: 0; border: 0; background: none; text-align: left; cursor: pointer;
  font-size: 13px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
button.gap__ex[aria-expanded="true"] { white-space: normal; }
.gap__ex-label { color: var(--text-3); }
.status-select.is-busy { opacity: .6; }
.status-select select[disabled] { cursor: progress; }

/* ---------- Impostazioni: accesso, dati, parte tecnica ---------- */
.btn--danger { color: var(--bad-text); }
.btn--danger:hover { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 35%, var(--border)); }
.data-actions { display: flex; flex-wrap: wrap; gap: 8px; }
/* Uscita dal pannello dentro «Dati»: serve solo su telefono, dove la barra laterale non c'è */
.data-logout { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); }
@media (min-width: 861px) { .data-logout { display: none; } }

@media (max-width: 860px) {
  /* campi a 16 px: iOS non ingrandisce la pagina al tocco */
  .field input, .field textarea, .inline-form input, .search input, .palette__input input { font-size: 16px; }
  .notice { flex-wrap: wrap; margin-bottom: 14px; }
  .notice .btn { margin-left: auto; }
  .is-detail-mode .notice--demo { display: none; }
  .inbox__foot { justify-content: center; padding: 12px 14px; }
  button.gap__ex:not([aria-expanded="true"]) { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; white-space: normal; }
  .login__card { padding: 22px 18px; }
}

/* ---------- Menu della chat ed eliminazione ---------- */
/* Pressione lunga su telefono: niente menu del sistema né selezione del testo */
.item { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
.ctx-menu {
  position: fixed; z-index: 65; min-width: 200px; padding: 5px;
  border-radius: 12px; background: var(--surface); box-shadow: var(--shadow-pop);
  animation: pop .12s var(--ease);
}
.ctx-menu__item {
  display: flex; align-items: center; gap: 10px; width: 100%; height: 38px; padding: 0 11px;
  border: 0; border-radius: 8px; background: none; text-align: left;
  font-size: 13.5px; font-weight: 600; color: var(--text);
}
.ctx-menu__item .i { width: 16px; height: 16px; }
.ctx-menu__item:hover, .ctx-menu__item:focus-visible { background: var(--surface-2); outline: none; }
.ctx-menu__item--danger { color: var(--bad-text); }
.ctx-menu__item--danger:hover, .ctx-menu__item--danger:focus-visible { background: var(--bad-soft); }

.confirm-backdrop { align-items: center; padding: 16px; }
.confirm {
  width: min(420px, 100%); padding: 22px 22px 18px; border-radius: 16px;
  background: var(--surface); box-shadow: var(--shadow-pop); animation: pop .2s var(--ease);
}
.confirm__icon { display: grid; place-items: center; width: 40px; height: 40px; margin-bottom: 12px; border-radius: 12px; background: var(--bad-soft); color: var(--bad-text); }
.confirm__icon .i { width: 20px; height: 20px; }
.confirm h3 { margin: 0 0 8px; font-size: 17px; font-weight: 650; }
.confirm p { margin: 0; font-size: 14px; line-height: 1.55; color: var(--text-2); }
.confirm__chat { color: var(--text); font-weight: 600; overflow-wrap: anywhere; }
.confirm__actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.btn--destroy { background: var(--bad); color: #fff; }
.btn--destroy:hover { background: color-mix(in srgb, var(--bad) 85%, #000); }
.confirm .btn:disabled { opacity: .65; cursor: progress; }
@media (max-width: 860px) {
  .ctx-menu__item { height: 44px; }
  .confirm__actions .btn { flex: 1; height: 44px; }
}
