/* ---------- Token ---------- */
:root, :root[data-theme="light"] {
  color-scheme: light;
  --page: #f4f4f1; --surface: #fcfcfb; --surface-2: #f3f2ee; --surface-3: #eceae5;
  --ink: #0b0b0b; --ink-2: #52514e; --muted: #898781;
  --grid: #e1e0d9; --axis: #c3c2b7; --ring: rgba(11, 11, 11, .10);
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
  --pos: #2a78d6; --neg: #e34948; --mid: #e6e5e0;
  --up: #006300; --down: #c0392f;
  --good: #0ca30c; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --accent: #2a78d6; --accent-ink: #ffffff; --accent-soft: rgba(42, 120, 214, .12);
  --glow-1: rgba(42, 120, 214, .16); --glow-2: rgba(235, 104, 52, .10);
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 8px 24px rgba(0, 0, 0, .06);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #222220; --surface-3: #2c2c2a;
  --ink: #ffffff; --ink-2: #c3c2b7; --muted: #898781;
  --grid: #2c2c2a; --axis: #383835; --ring: rgba(255, 255, 255, .10);
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --pos: #3987e5; --neg: #e66767; --mid: #383835;
  --up: #0ca30c; --down: #e66767;
  --accent: #3987e5; --accent-ink: #ffffff; --accent-soft: rgba(57, 135, 229, .16);
  --glow-1: rgba(57, 135, 229, .22); --glow-2: rgba(217, 89, 38, .12);
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 32px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { background: var(--page); color: var(--ink); font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
svg { display: block; }
code { font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; }
.muted { color: var(--muted); } .ink2 { color: var(--ink-2); }
.up { color: var(--up); } .down { color: var(--down); }
.num { font-variant-numeric: tabular-nums; }
kbd { font: 11px ui-monospace, Menlo, monospace; padding: 1px 6px; border-radius: 5px; border: 1px solid var(--ring); background: var(--surface-2); color: var(--ink-2); }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 20px; padding: 20px 14px; border-right: 1px solid var(--ring); background: var(--surface); }
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 8px; }
.logo { width: 32px; height: 32px; border-radius: 9px; background: linear-gradient(135deg, var(--s1), var(--s7)); display: grid; place-items: center; box-shadow: 0 6px 18px var(--glow-1); }
.logo svg { width: 20px; height: 20px; fill: none; stroke: #fff; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.brand-txt { font-size: 16px; letter-spacing: -.01em; } .brand-txt b { font-weight: 700; margin-left: 1px; }
#nav { display: grid; gap: 2px; }
#nav a { display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 8px; color: var(--ink-2); transition: background .15s, color .15s; position: relative; }
#nav a svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#nav a:hover { background: var(--surface-2); color: var(--ink); }
#nav a.on { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
#nav a.on::before { content: ""; position: absolute; left: -14px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.side-foot { margin-top: auto; display: flex; gap: 8px; align-items: center; font-size: 12px; padding: 0 8px; }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); position: relative; flex: none; }
.pulse.ok { background: var(--good); } .pulse.warn { background: var(--warning); } .pulse.bad { background: var(--critical); }
.pulse.ok::after { content: ""; position: absolute; inset: -4px; border-radius: 50%; border: 2px solid var(--good); opacity: 0; animation: ping 2.4s infinite; }
@keyframes ping { 0% { transform: scale(.6); opacity: .7; } 80%, 100% { transform: scale(1.6); opacity: 0; } }

.main { min-width: 0; }
.top { position: sticky; top: 0; z-index: 20; display: flex; gap: 12px; align-items: center; padding: 12px 28px; background: color-mix(in srgb, var(--page) 78%, transparent); backdrop-filter: blur(14px) saturate(1.4); -webkit-backdrop-filter: blur(14px) saturate(1.4); border-bottom: 1px solid var(--ring); }
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--ring); }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; cursor: pointer; color: var(--ink-2); display: flex; gap: 8px; align-items: center; white-space: nowrap; transition: background .2s, color .2s; }
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.flag { font: 700 10px ui-monospace, Menlo, monospace; padding: 2px 5px; border-radius: 4px; background: var(--surface-3); color: var(--ink-2); }
.seg button[aria-pressed="true"] .flag { background: var(--accent); color: var(--accent-ink); }
.search { margin-left: auto; display: flex; align-items: center; gap: 10px; min-width: 300px; padding: 7px 10px; border-radius: 9px; border: 1px solid var(--ring); background: var(--surface); color: var(--muted); cursor: pointer; transition: border-color .2s, box-shadow .2s; }
.search:hover { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.search svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; }
.search span { flex: 1; text-align: left; }
.icon-btn { width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center; border: 1px solid var(--ring); background: var(--surface); cursor: pointer; color: var(--ink-2); }
.icon-btn:hover { color: var(--ink); border-color: var(--accent); }
.icon-btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.view { padding: 24px 28px 64px; max-width: 1480px; animation: enter .45s cubic-bezier(.2, .7, .2, 1); }
@keyframes enter { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Componenti ---------- */
.hero { position: relative; padding: 4px 0 18px; }
.hero::before { content: ""; position: absolute; z-index: -1; inset: -60px -40px auto -40px; height: 260px; background: radial-gradient(600px 200px at 15% 30%, var(--glow-1), transparent 70%), radial-gradient(500px 180px at 70% 0%, var(--glow-2), transparent 70%); pointer-events: none; }
.hero h1 { font-size: 28px; letter-spacing: -.02em; margin: 0; font-weight: 700; }
.hero p { margin: 4px 0 0; color: var(--ink-2); }
.eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }

.grid { display: grid; gap: 16px; }
.g-kpi { grid-template-columns: repeat(auto-fit, minmax(176px, 1fr)); }
.g-2 { grid-template-columns: 2fr 1fr; } .g-2e { grid-template-columns: 1fr 1fr; } .g-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 1100px) { .g-2, .g-2e, .g-3 { grid-template-columns: 1fr; } }
.card { background: var(--surface); border: 1px solid var(--ring); border-radius: 14px; padding: 18px; min-width: 0; box-shadow: var(--shadow); position: relative; }
.card.flat { box-shadow: none; }
.card h2 { font-size: 15px; margin: 0; font-weight: 650; letter-spacing: -.005em; }
.card .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.card-head { display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.card-head .tools { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.kpi { padding: 16px 18px; transition: transform .2s, border-color .2s; }
.kpi:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--accent) 40%, var(--ring)); }
.kpi .lbl { color: var(--muted); font-size: 12px; display: flex; gap: 6px; align-items: center; }
.kpi .val { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; line-height: 1.15; }
.kpi .hint { font-size: 12px; color: var(--ink-2); margin-top: 4px; }
.kpi .bar2 { display: flex; height: 6px; border-radius: 3px; overflow: hidden; margin-top: 10px; gap: 2px; }
.kpi .bar2 i { display: block; height: 100%; border-radius: 3px; transition: width 1s cubic-bezier(.2, .7, .2, 1); }

.chips { display: inline-flex; gap: 2px; padding: 3px; border-radius: 9px; background: var(--surface-2); border: 1px solid var(--ring); }
.chips button { border: 0; background: transparent; padding: 4px 10px; border-radius: 6px; font-size: 12px; cursor: pointer; color: var(--ink-2); }
.chips button:hover { color: var(--ink); }
.chips button.on { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }
.btn { border: 1px solid var(--ring); background: var(--surface); padding: 7px 14px; border-radius: 9px; cursor: pointer; display: inline-flex; gap: 8px; align-items: center; transition: border-color .15s, transform .1s; }
.btn:hover { border-color: var(--accent); } .btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .5; cursor: default; }
select.sel, input.inp { border: 1px solid var(--ring); background: var(--surface); padding: 6px 10px; border-radius: 8px; }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; border: 1px solid var(--ring); color: var(--ink-2); background: var(--surface-2); }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.good { color: var(--up); } .badge.warn { color: var(--warning); } .badge.bad { color: var(--critical); } .badge.info { color: var(--accent); }

table.t { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.t th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--ring); white-space: nowrap; }
table.t td { padding: 9px 10px; border-bottom: 1px solid var(--ring); white-space: nowrap; }
table.t tr:last-child td { border-bottom: 0; }
table.t.wrap td { white-space: normal; }
table.t tbody tr { transition: background .12s; }
table.t tbody tr:hover { background: var(--surface-2); }
table.t .r { text-align: right; }
table.t tr.click { cursor: pointer; }
.scroll { overflow: auto; }
.tkr { font: 600 12px ui-monospace, Menlo, monospace; padding: 2px 6px; border-radius: 5px; background: var(--surface-2); border: 1px solid var(--ring); cursor: pointer; }
.tkr:hover { border-color: var(--accent); color: var(--accent); }
.empty { color: var(--muted); padding: 28px 0; text-align: center; }
.note { font-size: 12px; color: var(--muted); }
.callout { border: 1px solid var(--ring); border-left: 3px solid var(--accent); background: var(--surface-2); padding: 10px 14px; border-radius: 8px; font-size: 13px; color: var(--ink-2); }
.callout.warn { border-left-color: var(--warning); } .callout.bad { border-left-color: var(--critical); } .callout.good { border-left-color: var(--good); }

/* skeleton */
.sk { border-radius: 8px; background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: sk 1.4s infinite; }
@keyframes sk { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ---------- Grafici ---------- */
.chart { position: relative; width: 100%; }
.chart svg text { font-size: 11px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.chart .gl { stroke: var(--grid); stroke-width: 1; }
.chart .base { stroke: var(--axis); stroke-width: 1; }
.chart .ln { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .draw { animation: draw 1.4s cubic-bezier(.3, .6, .2, 1) forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
.chart .area { animation: fadeFrom 1s .5s backwards; }
@keyframes fadein { to { opacity: 1; } }
@keyframes fadeFrom { from { opacity: 0; } }
.chart .cross { stroke: var(--ink-2); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.chart .lbl-end { font-size: 11px; font-weight: 600; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); margin-bottom: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 3px; border-radius: 2px; display: inline-block; }
.legend i.sq { width: 10px; height: 10px; border-radius: 3px; }
.tm-cell { transition: opacity .2s, filter .2s; cursor: pointer; }
.tm-cell:hover { filter: brightness(1.12); }
.tm-in { animation: tmin .6s cubic-bezier(.2, .7, .2, 1) backwards; transform-box: fill-box; transform-origin: center; }
@keyframes tmin { from { opacity: 0; transform: scale(.85); } }
.sc-pt { transition: transform .8s cubic-bezier(.3, .7, .2, 1), opacity .3s; cursor: pointer; }
.sc-pt circle { transition: r .2s; }
.sc-pt:hover circle { r: 8; }
.grow-y, .grow-x, .grow-xr { transform-box: fill-box; animation: 1s cubic-bezier(.2, .7, .2, 1) backwards; }
.grow-y { transform-origin: center bottom; animation-name: growY; }
.grow-x { transform-origin: left center; animation-name: growX; }
.grow-xr { transform-origin: right center; animation-name: growX; }
@keyframes growY { from { transform: scaleY(0); } }
@keyframes growX { from { transform: scaleX(0); } }
.hm-cell { transition: opacity .15s; }
.hm-cell:hover { stroke: var(--ink); stroke-width: 1.5; }
.gauge-arc { transition: stroke-dashoffset 1.4s cubic-bezier(.2, .7, .2, 1); }

.tip { position: fixed; z-index: 100; pointer-events: none; min-width: 120px; padding: 8px 11px; border-radius: 9px; font-size: 12px; background: var(--surface); border: 1px solid var(--ring); box-shadow: var(--shadow); opacity: 0; transform: translateY(4px); transition: opacity .12s, transform .12s; }
.tip.on { opacity: 1; transform: none; }
.tip .tt { font-weight: 600; margin-bottom: 4px; color: var(--ink); }
.tip .tr { display: flex; gap: 10px; justify-content: space-between; align-items: center; color: var(--ink-2); }
.tip .tr b { color: var(--ink); font-variant-numeric: tabular-nums; }
.tip .sw { display: inline-block; width: 10px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }

/* ---------- Drawer, palette, modale, toast ---------- */
.drawer-back { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .35); opacity: 0; pointer-events: none; transition: opacity .25s; }
.drawer-back.on { opacity: 1; pointer-events: auto; }
.drawer { position: fixed; z-index: 41; top: 0; right: 0; bottom: 0; width: min(620px, 100vw); background: var(--surface); border-left: 1px solid var(--ring); box-shadow: -20px 0 60px rgba(0, 0, 0, .25); transform: translateX(105%); transition: transform .35s cubic-bezier(.2, .7, .2, 1); overflow-y: auto; padding: 24px; }
.drawer.on { transform: none; }
.drawer-x { position: absolute; top: 16px; right: 16px; }
.palette-back, .modal-back { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, .4); backdrop-filter: blur(4px); display: grid; place-items: start center; padding-top: 12vh; animation: fadeFrom .15s; }
.palette, .modal { width: min(640px, calc(100vw - 32px)); background: var(--surface); border: 1px solid var(--ring); border-radius: 14px; box-shadow: 0 30px 80px rgba(0, 0, 0, .45); overflow: hidden; animation: pop .2s cubic-bezier(.2, .7, .2, 1); }
@keyframes pop { from { transform: scale(.97) translateY(-6px); opacity: 0; } }
.palette input { width: 100%; border: 0; border-bottom: 1px solid var(--ring); background: transparent; padding: 18px 20px; font-size: 16px; outline: none; }
.palette-list { max-height: 50vh; overflow-y: auto; padding: 6px; }
.palette-item { display: flex; gap: 12px; align-items: center; padding: 9px 12px; border-radius: 8px; cursor: pointer; }
.palette-item.on { background: var(--accent-soft); }
.palette-item .k { font-size: 11px; color: var(--muted); margin-left: auto; }
.palette-sec { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 10px 12px 4px; }
.palette-foot { padding: 10px 16px; border-top: 1px solid var(--ring); font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.modal { padding: 22px; }
.modal h3 { margin: 0 0 14px; font-size: 18px; }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.form label.full { grid-column: 1 / -1; }
.form input, .form select { border: 1px solid var(--ring); background: var(--surface-2); padding: 8px 10px; border-radius: 8px; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
.toasts { position: fixed; z-index: 90; bottom: 100px; right: 20px; display: grid; gap: 8px; }
.toast { background: var(--surface); border: 1px solid var(--ring); border-left: 3px solid var(--accent); border-radius: 10px; padding: 10px 14px; box-shadow: var(--shadow); min-width: 260px; animation: pop .25s; font-size: 13px; }
.toast.bad { border-left-color: var(--critical); } .toast.good { border-left-color: var(--good); }
.progress { height: 4px; border-radius: 2px; background: var(--surface-3); overflow: hidden; }
.progress i { display: block; height: 100%; background: linear-gradient(90deg, var(--s1), var(--s7)); transition: width .4s; }

/* ---------- Varie ---------- */
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.sp { flex: 1; }
.mv { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--ring); }
.mv:last-child { border-bottom: 0; }
.mv .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.pcard { cursor: pointer; transition: transform .2s, border-color .2s; }
.pcard:hover { transform: translateY(-3px); border-color: color-mix(in srgb, var(--accent) 45%, var(--ring)); }
.timeline { display: grid; gap: 0; }
.tl-item { display: grid; grid-template-columns: 110px 1fr; gap: 14px; padding: 10px 0; border-bottom: 1px solid var(--ring); }
.tl-item:last-child { border-bottom: 0; }
.pill { display: inline-block; font: 600 11px ui-monospace, Menlo, monospace; padding: 2px 6px; border-radius: 5px; margin: 2px 4px 2px 0; }
.pill.in { background: color-mix(in srgb, var(--up) 14%, transparent); color: var(--up); }
.pill.out { background: color-mix(in srgb, var(--down) 14%, transparent); color: var(--down); }
.svc { display: flex; gap: 12px; align-items: center; }
.svc .pulse { width: 10px; height: 10px; }
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; overflow-x: auto; padding: 10px; }
  .side .brand-txt, .side-foot, #nav a span { display: none; }
  #nav { display: flex; }
  .top { flex-wrap: wrap; padding: 10px 16px; }
  .search { min-width: 0; flex: 1; }
  .seg button { padding: 6px 8px; font-size: 12px; }
  .view { padding: 16px; }
  .g-kpi { grid-template-columns: 1fr 1fr; }
  .kpi .val { font-size: 21px; }
  #nav a.on::before { display: none; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } .chart .ln.draw { stroke-dashoffset: 0 !important; } }

/* pillola di probabilità */
.prob { display: inline-flex; align-items: center; gap: 8px; }
.prob b { min-width: 34px; text-align: right; font-variant-numeric: tabular-nums; }
.pbar { width: 56px; height: 8px; border-radius: 4px; background: var(--surface-2); position: relative; overflow: hidden; border: 1px solid var(--ring); }
.pbar i { position: absolute; top: 0; bottom: 0; border-radius: 3px; }
.pbar::after { content: ""; position: absolute; left: 50%; top: -1px; bottom: -1px; width: 1px; background: var(--axis); }
.prob.dim { opacity: .45; }

/* ---------- Accessi ---------- */
.user-box { margin-top: auto; display: flex; align-items: center; gap: 6px; padding: 8px; border-top: 1px solid var(--ring); }
.user-box + .side-foot { margin-top: 0; }
.user-chip { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; padding: 4px; border-radius: 8px; }
.user-chip:hover { background: var(--surface-2); }
.user-chip b { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip .note { display: block; font-size: 11px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-weight: 700; flex: none; }
.user-box .icon-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--page); }
.login { width: min(400px, 100%); padding: 28px; }
.login h2 { margin: 0 0 16px; font-size: 20px; }
.fld { display: grid; gap: 5px; margin-bottom: 12px; font-size: 12px; color: var(--muted); }
.fld input, .fld select, .fld textarea { border: 1px solid var(--ring); background: var(--surface-2); padding: 9px 11px; border-radius: 8px; font-size: 14px; color: var(--ink); }
.fld input:focus, .fld select:focus, .fld textarea:focus, .chat-input textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.secret { font: 600 16px ui-monospace, Menlo, monospace; padding: 12px; border-radius: 8px; background: var(--surface-2); border: 1px dashed var(--accent); text-align: center; user-select: all; letter-spacing: .04em; }
.t select.sel { padding: 3px 6px; font-size: 12px; }

/* ---------- Agente ---------- */
.agent { display: grid; grid-template-columns: 250px 1fr; gap: 16px; height: calc(100vh - 150px); min-height: 480px; }
.agent .convs { overflow: auto; padding: 10px; }
.agent .convs a { display: block; padding: 8px 10px; border-radius: 8px; font-size: 13px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.agent .convs a:hover { background: var(--surface-2); color: var(--ink); }
.agent .convs a.on { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
.chat { display: flex; flex-direction: column; min-height: 0; padding: 0; overflow: hidden; }
.chat-log { flex: 1; overflow: auto; padding: 20px 22px; display: flex; flex-direction: column; gap: 16px; }
.msg { max-width: 860px; line-height: 1.55; }
.msg.user { align-self: flex-end; background: var(--accent-soft); padding: 10px 14px; border-radius: 14px 14px 4px 14px; max-width: 75%; white-space: pre-wrap; }
.msg.bot { align-self: stretch; }
.msg.bot p { margin: 0 0 10px; } .msg.bot ul, .msg.bot ol { margin: 0 0 10px; padding-left: 22px; }
.msg.bot h1, .msg.bot h2, .msg.bot h3, .msg.bot h4 { font-size: 15px; margin: 14px 0 6px; }
.msg.bot table { border-collapse: collapse; margin: 8px 0 12px; font-size: 13px; display: block; overflow-x: auto; }
.msg.bot th, .msg.bot td { border-bottom: 1px solid var(--ring); padding: 6px 10px; text-align: left; }
.msg.bot th { color: var(--muted); font-weight: 600; font-size: 12px; }
.msg.bot code { font: 12px ui-monospace, Menlo, monospace; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 4px; }
.steps { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.steps span { font-size: 11px; color: var(--muted); border: 1px solid var(--ring); border-radius: 999px; padding: 2px 9px; }
.steps span.live { color: var(--accent); border-color: var(--accent); }
.proposal { border: 1px solid var(--accent); border-radius: 12px; padding: 14px; margin: 6px 0; background: var(--surface-2); max-width: 760px; }
.proposal .row { gap: 8px; margin-top: 10px; }
.chat-input { border-top: 1px solid var(--ring); padding: 12px; display: flex; gap: 10px; align-items: flex-end; }
.chat-input textarea { flex: 1; resize: none; min-height: 44px; max-height: 200px; border: 1px solid var(--ring); background: var(--surface-2); border-radius: 10px; padding: 11px 12px; font: inherit; color: var(--ink); }
.suggest { display: flex; flex-wrap: wrap; gap: 8px; }
.suggest button { border: 1px solid var(--ring); background: var(--surface); border-radius: 10px; padding: 8px 12px; font-size: 13px; cursor: pointer; text-align: left; color: var(--ink-2); }
.suggest button:hover { border-color: var(--accent); color: var(--ink); }
.cursor::after { content: "▍"; animation: blink 1s steps(2) infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }
@media (max-width: 900px) { .agent { grid-template-columns: 1fr; height: auto; } .agent .convs { max-height: 160px; } .chat { height: 70vh; } }
.kpi-v { font-size: 26px; font-weight: 700; margin-top: 6px; letter-spacing: -.01em; }
body[data-role="lettore"] [data-need="analista"], body:not([data-role="admin"]) [data-need="admin"] { display: none !important; }

/* ---------- Agente flottante ---------- */
.agent-fab { position: fixed; right: 24px; bottom: 22px; z-index: 70; width: 64px; height: 64px; border-radius: 50%; padding: 0; border: 2px solid var(--accent); background: var(--surface); cursor: pointer; box-shadow: 0 8px 24px rgba(0, 0, 0, .35), 0 0 0 4px var(--accent-soft); transition: transform .15s, box-shadow .2s; }
.agent-fab img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }
.agent-fab:hover { transform: translateY(-2px) scale(1.04); box-shadow: 0 12px 28px rgba(0, 0, 0, .4), 0 0 0 6px var(--accent-soft); }
.agent-fab.on { box-shadow: 0 0 0 3px var(--accent), 0 8px 24px rgba(0, 0, 0, .35); }
.agent-fab-dot { position: absolute; right: 2px; bottom: 4px; width: 13px; height: 13px; border-radius: 50%; background: var(--good, #2bb673); border: 2px solid var(--surface); }
.agent-fab:not(.on)::after { content: ""; position: absolute; inset: -6px; border-radius: 50%; border: 2px solid var(--accent); opacity: 0; animation: fabPulse 3.2s ease-out infinite; pointer-events: none; }
@keyframes fabPulse { 0% { transform: scale(.9); opacity: .55; } 70%, 100% { transform: scale(1.35); opacity: 0; } }
.agent-panel { position: fixed; right: 24px; bottom: 98px; z-index: 71; width: min(920px, calc(100vw - 48px)); height: min(1000px, calc(100vh - 120px)); display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--ring); border-radius: 16px; box-shadow: 0 24px 60px rgba(0, 0, 0, .45); overflow: hidden; transform-origin: bottom right; animation: panelIn .22s cubic-bezier(.2, .9, .3, 1.1); }
.agent-panel[hidden] { display: none; }
@keyframes panelIn { from { opacity: 0; transform: translateY(12px) scale(.94); } to { opacity: 1; transform: none; } }
.agent-head { display: flex; align-items: center; gap: 10px; padding: 10px 10px 10px 14px; border-bottom: 1px solid var(--ring); background: linear-gradient(180deg, var(--accent-soft), transparent); }
.agent-head-av { width: 38px; height: 38px; border-radius: 50%; border: 2px solid var(--accent); object-fit: cover; }
.agent-head-txt { flex: 1; min-width: 0; display: grid; }
.agent-head-txt b { font-size: 15px; }
.agent-head-txt .note { font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.agent-head-tools { display: flex; gap: 2px; }
.agent-head-tools .icon-btn { width: 32px; height: 32px; }
.agent-head-tools svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.agent-hist { max-height: 260px; overflow: auto; border-bottom: 1px solid var(--ring); padding: 6px; background: var(--surface-2); }
.agent-hist button { display: flex; justify-content: space-between; gap: 10px; width: 100%; border: 0; background: transparent; padding: 8px 10px; border-radius: 8px; cursor: pointer; text-align: left; font-size: 13px; color: var(--ink-2); }
.agent-hist button span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agent-hist button:hover, .agent-hist button.on { background: var(--surface); color: var(--ink); }
.agent-body { flex: 1; min-height: 0; display: flex; }
.agent-body.chat { flex-direction: column; }
.agent-panel .chat-log { padding: 14px; gap: 12px; }
.agent-panel .msg { font-size: 13.5px; }
.agent-panel .msg.user { max-width: 85%; }
.agent-panel .proposal { padding: 12px; }
.agent-panel .proposal .row { flex-wrap: wrap; }
.agent-panel .chat-input { padding: 10px; }
.agent-panel .chat-input .btn { width: 40px; height: 40px; justify-content: center; padding: 0; font-size: 18px; border-radius: 50%; }
.msg.bot { display: flex; gap: 10px; align-items: flex-start; }
.msg-av { width: 28px; height: 28px; border-radius: 50%; flex: none; border: 1px solid var(--ring); margin-top: 2px; }
.msg-main { flex: 1; min-width: 0; }
.chat-empty { margin: auto; text-align: center; max-width: 640px; padding: 8px; }
.chat-empty h3 { margin: 10px 0 6px; font-size: 17px; }
.chat-empty .suggest { justify-content: center; margin-top: 14px; }
.agent-hero { width: 96px; height: 96px; border-radius: 50%; border: 3px solid var(--accent); box-shadow: 0 0 0 6px var(--accent-soft); object-fit: cover; }
.agent-panel .agent-hero { width: 76px; height: 76px; }
.agent-panel .suggest button { font-size: 12.5px; padding: 7px 10px; }
#apChat { padding: 0; }
@media (max-width: 900px) { .agent-fab { right: 16px; bottom: 16px; width: 56px; height: 56px; } .agent-panel { right: 16px; bottom: 84px; } }
@media (prefers-reduced-motion: reduce) { .agent-fab::after, .agent-panel { animation: none !important; } }
