/* ==========================================================================
   Chatbot 2 · pannello di amministrazione
   Variabili di tema (chiaro/scuro), poi layout, componenti, pagine.
   ========================================================================== */

:root {
    color-scheme: light;
    --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;

    --bg: #f5f6fa;
    --surface: #ffffff;
    --surface-2: #f8f9fc;
    --surface-hover: #f3f4fa;
    --panel: var(--surface); /* nome storico */
    --text: #0f172a;
    --muted: #64748b;
    --line: #e4e7ef;
    --line-strong: #cfd4e1;

    --brand: #4f46e5;
    --brand-hover: #4338ca;
    --brand-dark: var(--brand-hover);
    --brand-soft: #eef0ff;
    --brand-text: #4338ca;
    --on-brand: #ffffff;

    --ok: #15803d;
    --ok-soft: #e7f7ee;
    --warn: #b45309;
    --warn-soft: #fff4e0;
    --err: #be123c;
    --err-soft: #ffe9ee;

    --code-bg: #0f172a;
    --code-text: #e2e8f0;

    --radius: 14px;
    --radius-sm: 9px;
    --shadow-sm: 0 1px 2px rgb(15 23 42 / .05);
    --shadow-md: 0 1px 3px rgb(15 23 42 / .06), 0 8px 24px rgb(15 23 42 / .06);
    --ring: 0 0 0 3px rgb(79 70 229 / .22);
    --side-w: 252px;
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0a0e1a;
    --surface: #121829;
    --surface-2: #0f1424;
    --surface-hover: #182036;
    --text: #e6e9f2;
    --muted: #93a0b8;
    --line: #232c45;
    --line-strong: #323d5c;
    --brand: #7c83ff;
    --brand-hover: #9399ff;
    --brand-soft: #1b2145;
    --brand-text: #aab0ff;
    --on-brand: #0a0e1a;
    --ok: #4ade80;
    --ok-soft: #10281c;
    --warn: #fbbf24;
    --warn-soft: #2e2208;
    --err: #fb7185;
    --err-soft: #34121c;
    --code-bg: #070a14;
    --shadow-sm: 0 1px 2px rgb(0 0 0 / .4);
    --shadow-md: 0 1px 3px rgb(0 0 0 / .4), 0 8px 24px rgb(0 0 0 / .35);
    --ring: 0 0 0 3px rgb(124 131 255 / .3);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --bg: #0a0e1a;
        --surface: #121829;
        --surface-2: #0f1424;
        --surface-hover: #182036;
        --text: #e6e9f2;
        --muted: #93a0b8;
        --line: #232c45;
        --line-strong: #323d5c;
        --brand: #7c83ff;
        --brand-hover: #9399ff;
        --brand-soft: #1b2145;
        --brand-text: #aab0ff;
        --on-brand: #0a0e1a;
        --ok: #4ade80;
        --ok-soft: #10281c;
        --warn: #fbbf24;
        --warn-soft: #2e2208;
        --err: #fb7185;
        --err-soft: #34121c;
        --code-bg: #070a14;
        --shadow-sm: 0 1px 2px rgb(0 0 0 / .4);
        --shadow-md: 0 1px 3px rgb(0 0 0 / .4), 0 8px 24px rgb(0 0 0 / .35);
        --ring: 0 0 0 3px rgb(124 131 255 / .3);
    }
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 14.5px/1.55 var(--font); color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--brand-text); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
h1, h2, h3 { letter-spacing: -.015em; line-height: 1.25; }
h2 { font-size: 15px; font-weight: 650; margin: 32px 0 12px; }
::selection { background: var(--brand-soft); color: var(--brand-text); }
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 6px; }
.icon { flex-shrink: 0; vertical-align: -3px; }
.muted { color: var(--muted); }
small.muted, .muted small { font-size: 12.5px; }
code { font-family: var(--mono); font-size: .88em; background: var(--surface-2); border: 1px solid var(--line); padding: 1px 6px; border-radius: 6px; }
pre { font-family: var(--mono); font-size: 12.5px; line-height: 1.6; background: var(--code-bg); color: var(--code-text); padding: 14px 16px; border-radius: 12px; overflow: auto; margin: 0; white-space: pre-wrap; border: 1px solid rgb(255 255 255 / .06); }
pre code { background: none; border: 0; padding: 0; }
pre.preview { max-height: 420px; }

/* ---------- Struttura: barra laterale + contenuto ---------- */
.shell { display: flex; min-height: 100vh; }
.side { width: var(--side-w); flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--line); padding: 18px 14px 14px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand-row { display: flex; align-items: center; gap: 11px; padding: 2px 8px 18px; }
.logo { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; color: #fff; background: linear-gradient(135deg, #6366f1, #4338ca 60%, #7c3aed); box-shadow: 0 4px 12px rgb(79 70 229 / .35); flex-shrink: 0; }
.logo.sm { width: 24px; height: 24px; border-radius: 7px; box-shadow: none; }
.brand-text b { display: block; font-size: 15.5px; letter-spacing: -.01em; line-height: 1.2; }
.brand-text small { color: var(--muted); font-size: 12px; }

.side nav { display: flex; flex-direction: column; gap: 2px; }
.side nav a { display: flex; align-items: center; gap: 11px; color: var(--muted); padding: 9px 11px; border-radius: 10px; font-weight: 520; transition: background .12s, color .12s; }
.side nav a .icon { opacity: .85; }
.side nav a:hover { background: var(--surface-hover); color: var(--text); text-decoration: none; }
.side nav a.active { background: var(--brand-soft); color: var(--brand-text); }
.side nav a.active .icon { opacity: 1; }
.nav-title { margin: 18px 11px 6px; font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); opacity: .8; }
.nav-title:first-child { margin-top: 4px; }
.scope-chip { margin: 16px 0 8px; padding: 11px 12px; border: 1px dashed var(--line-strong); border-radius: 12px; background: var(--surface-2); font-size: 12.5px; line-height: 1.35; }
.scope-chip b { display: block; font-size: 14px; }
.scope-chip form { margin-top: 6px; }
.scope-chip button { all: unset; cursor: pointer; color: var(--brand-text); font-size: 12.5px; font-weight: 550; }
.scope-chip button:hover { text-decoration: underline; }

.side-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 650; background: var(--brand-soft); color: var(--brand-text); flex-shrink: 0; }
.side-foot .who { min-width: 0; flex: 1; line-height: 1.25; }
.side-foot .who b { display: block; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-foot .who a { font-size: 12px; color: var(--muted); }
.icon-btn { all: unset; box-sizing: border-box; cursor: pointer; width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; color: var(--muted); }
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }
.icon-btn:focus-visible { box-shadow: var(--ring); }
.theme-toggle .when-dark { display: none; }
:root[data-theme="dark"] .theme-toggle .when-light { display: none; }
:root[data-theme="dark"] .theme-toggle .when-dark { display: inline; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .theme-toggle .when-light { display: none; }
    :root:not([data-theme="light"]) .theme-toggle .when-dark { display: inline; }
}

.main { flex: 1; min-width: 0; padding: 30px 40px 60px; }
.content { max-width: 1240px; margin: 0 auto; }
.topbar, .scrim { display: none; }

/* Intestazione di pagina */
.head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.head h1, .main h1 { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.head > div, .head > span { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.head + p.muted { margin-top: -10px; }
p.muted { max-width: 78ch; }

/* ---------- Card, statistiche ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow-sm); }
.card > :first-child { margin-top: 0; }
.card > :last-child { margin-bottom: 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; margin-bottom: 8px; }
.stat { display: flex; flex-direction: column; gap: 2px; position: relative; padding: 18px 20px; }
.stat b { font-size: 30px; font-weight: 700; letter-spacing: -.03em; line-height: 1.15; }
.stat span { color: var(--muted); font-size: 13px; }
.stat .ico { position: absolute; top: 16px; right: 16px; width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand-text); }
.stat.warn .ico { background: var(--warn-soft); color: var(--warn); }
.stat.bad .ico { background: var(--err-soft); color: var(--err); }
.stat.good .ico { background: var(--ok-soft); color: var(--ok); }
a.stat { color: inherit; }
a.stat:hover { text-decoration: none; border-color: var(--line-strong); box-shadow: var(--shadow-md); }
.empty { color: var(--muted); padding: 34px 24px; text-align: center; border-style: dashed; box-shadow: none; background: transparent; }
.two-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 18px; align-items: start; }

/* ---------- Tabelle ---------- */
table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); }
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 11.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
tbody tr { transition: background .1s; }
tbody tr:hover { background: var(--surface-hover); }
tr:last-child > td { border-bottom: 0; }
table tr.subtotal td { background: var(--surface-2); }
table tr.subtotal:hover td { background: var(--surface-2); }
table.compact td, table.compact th { padding: 8px 12px; font-size: 13.5px; vertical-align: top; }
td.actions { text-align: right; white-space: nowrap; }
td.actions form.inline { display: inline-block; }
td.actions > a, td.actions .link, td.actions button.link { display: inline-block; padding: 4px 10px; margin: 1px 0 1px 2px; border-radius: 8px; font-size: 13px; font-weight: 550; color: var(--brand-text); }
td.actions > a:hover, td.actions .link:hover { background: var(--brand-soft); text-decoration: none; }
td.actions .danger:hover { background: var(--err-soft); }
td code { white-space: nowrap; }
.pager { display: flex; gap: 10px; margin-top: 14px; }
.pager a { padding: 6px 14px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); color: var(--text); font-weight: 520; }
.pager a:hover { background: var(--surface-hover); text-decoration: none; }

/* ---------- Badge, etichette ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 580; line-height: 1.6; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.off { background: var(--err-soft); color: var(--err); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.ok::before, .badge.off::before, .badge.warn::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chip { display: inline-block; font-size: 11.5px; background: var(--brand-soft); color: var(--brand-text); border-radius: 999px; padding: 1px 9px; margin: 6px 4px 0 0; font-weight: 550; }

/* ---------- Pulsanti ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; background: var(--brand); color: var(--on-brand); border: 1px solid transparent; padding: 8px 15px; border-radius: 10px; font: inherit; font-weight: 580; cursor: pointer; box-shadow: var(--shadow-sm); transition: background .12s, border-color .12s, transform .05s; line-height: 1.4; }
.btn:hover { background: var(--brand-hover); text-decoration: none; color: var(--on-brand); }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--line-strong); }
.btn.secondary:hover { background: var(--surface-hover); color: var(--text); }
.btn.danger { background: var(--err); color: #fff; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
button.link { background: none; border: 0; padding: 0; color: var(--brand-text); cursor: pointer; font: inherit; }
button.link:hover { text-decoration: underline; }
button.link.danger, .danger { color: var(--err); }
form.inline { display: inline; }
.head form.inline, .head form.inline .btn { margin: 0; }

/* ---------- Messaggi (flash) ---------- */
.flash { display: flex; align-items: flex-start; gap: 10px; padding: 11px 14px; border-radius: 12px; margin-bottom: 18px; border: 1px solid transparent; font-weight: 520; transition: opacity .2s, transform .2s; }
.flash > .icon { margin-top: 3px; }
.flash > span { flex: 1; }
.flash.success { background: var(--ok-soft); color: var(--ok); }
.flash.error, .flash.danger { background: var(--err-soft); color: var(--err); }
.flash.warning { background: var(--warn-soft); color: var(--warn); }
.flash.leaving { opacity: 0; transform: translateY(-4px); }
.flash-close { all: unset; cursor: pointer; opacity: .6; padding: 3px; border-radius: 6px; display: grid; place-items: center; }
.flash-close:hover { opacity: 1; background: rgb(0 0 0 / .07); }
.card.flash { box-shadow: none; }

/* ---------- Form ---------- */
form .field { margin-bottom: 18px; }
form label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 13.5px; }
form input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="submit"]):not([type="color"]),
select, form select, form textarea, textarea { width: 100%; max-width: 560px; padding: 9px 12px; border: 1px solid var(--line-strong); border-radius: 10px; font: inherit; color: var(--text); background: var(--surface); transition: border-color .12s, box-shadow .12s; }
form textarea, textarea { max-width: 100%; }
select, form select { appearance: none; padding-right: 36px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; }
form input:focus, form select:focus, form textarea:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
form input::placeholder, textarea::placeholder { color: var(--muted); opacity: .7; }
form input[type="color"] { width: 54px; height: 38px; padding: 3px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface); cursor: pointer; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--brand); width: 16px; height: 16px; margin: 0; flex-shrink: 0; }
form .checkbox { display: flex; align-items: center; flex-wrap: wrap; gap: 9px; }
form .checkbox label { display: inline; font-weight: 500; margin: 0; }
form .checkbox .help-text, form .checkbox ul { flex-basis: 100%; margin-left: 25px; margin-top: 0; }
form .choices { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); max-width: 560px; }
form .choice { display: flex; align-items: center; gap: 9px; }
form .choice label { margin: 0; font-weight: 500; }
form .form-text, form .help-text { color: var(--muted); font-size: 12.5px; margin-top: 5px; max-width: 78ch; white-space: pre-line; }
form ul { color: var(--err); padding-left: 0; list-style: none; margin: 5px 0 0; font-size: 13px; font-weight: 520; }
textarea.mono, .mono { font-family: var(--mono); font-size: 12.5px; line-height: 1.6; }
.form-card { max-width: 680px; }
.form-card.wide { max-width: 900px; }
.form-card form > .btn, .form-card form > a.btn { margin-top: 6px; margin-right: 6px; }
.form-card .row { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; margin-bottom: 14px; }
.form-card .row label { margin-bottom: 0; }
.form-card .row input, .form-card .row select { max-width: none; }
.inline-form { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.inline-form input[type="text"] { flex: 1; min-width: 220px; max-width: 460px; }
label.visitor { font-size: 14px; font-weight: 500; display: inline-flex; align-items: center; gap: 7px; margin: 0; }

/* ---------- Filtri a schede ---------- */
.filters { display: inline-flex; flex-wrap: wrap; gap: 3px; padding: 4px; margin: 0 0 18px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; }
.filters a { padding: 6px 13px; border-radius: 9px; color: var(--muted); font-weight: 560; margin: 0; }
.filters a:hover { color: var(--text); text-decoration: none; }
.filters a.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); text-decoration: none; }

/* ---------- Stato / dettagli ---------- */
.status { margin-bottom: 8px; display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; }
.status .badge { margin-left: 0; }
details.trace { margin-top: 8px; font-size: 13px; }
details.trace summary { cursor: pointer; color: var(--muted); font-weight: 520; }
details.trace ul { margin: 6px 0; padding-left: 18px; }
details > summary { cursor: pointer; }
.toolcall { margin: 8px 0; }
.toolcall pre { margin-top: 4px; font-size: 12px; max-height: 160px; }
.row-meta { color: var(--muted); font-size: 12.5px; }

/* ---------- Chat (prova, conversazioni) ---------- */
.chat { padding: 0; display: flex; flex-direction: column; max-width: 860px; overflow: hidden; }
.chat-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; background: var(--surface-2); }
.chat-bar select { padding: 6px 32px 6px 10px; width: auto; max-width: none; }
.chat-log { height: 480px; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 10px; background: var(--surface-2); }
.chat-log.static { height: auto; max-width: 860px; border: 1px solid var(--line); border-radius: var(--radius); }
.bubble { max-width: 82%; padding: 10px 14px; border-radius: 16px 16px 16px 5px; background: var(--surface); border: 1px solid var(--line); overflow-wrap: anywhere; box-shadow: var(--shadow-sm); }
.bubble.user { align-self: flex-end; background: var(--brand); color: var(--on-brand); border-color: var(--brand); border-radius: 16px 16px 5px 16px; }
.bubble.user a { color: inherit; text-decoration: underline; }
.bubble.error { background: var(--err-soft); border-color: transparent; color: var(--err); }
.bubble.typing .body:empty::after { content: '…'; color: var(--muted); }
.bubble .meta { font-size: 11px; color: var(--muted); margin-top: 4px; }
.bubble.user .meta { color: inherit; opacity: .75; }
.bubble.operator { align-self: flex-start; background: var(--ok-soft); border-color: transparent; }
.bubble .who { font-size: 12px; font-weight: 700; color: var(--ok); margin-bottom: 2px; }
.bubble .rating { margin-top: 6px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.event { align-self: center; font-size: 12px; color: var(--muted); background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 3px 12px; }
.chat-form { display: flex; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--line); align-items: flex-end; background: var(--surface); }
.chat-form textarea { flex: 1; resize: none; }
.chat-form.operator-form { max-width: 860px; border: 1px solid var(--line); border-radius: var(--radius); margin-top: 12px; box-shadow: var(--shadow-sm); }
.chat-form[hidden] { display: none; }
.takeover { margin-bottom: 14px; display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }

/* ---------- Set di test ---------- */
.card.result { margin-bottom: 10px; }
.card.result.fail { border-left: 4px solid var(--err); }
.card.result.pass { border-left: 4px solid var(--ok); }
.card.result .failure { color: var(--err); margin: 4px 0; font-weight: 520; }
.card.result .body { margin: 8px 0; white-space: normal; }

/* ---------- Accesso ---------- */
.login { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); }
.login-art { position: relative; overflow: hidden; color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: space-between; background: radial-gradient(1200px 600px at 10% 0%, #6366f1 0%, transparent 60%), radial-gradient(900px 600px at 100% 100%, #7c3aed 0%, transparent 55%), #1e1b4b; }
.login-art .brand-row { padding: 0; }
.login-art .brand-text small { color: rgb(255 255 255 / .7); }
.login-art h2 { font-size: 34px; line-height: 1.15; letter-spacing: -.03em; margin: 0 0 14px; font-weight: 720; max-width: 15ch; }
.login-art p { margin: 0; color: rgb(255 255 255 / .78); max-width: 42ch; font-size: 15.5px; }
.login-art ul { list-style: none; padding: 0; margin: 28px 0 0; display: grid; gap: 10px; color: rgb(255 255 255 / .85); }
.login-art li { display: flex; gap: 10px; align-items: center; }
.login-art li .icon { background: rgb(255 255 255 / .14); padding: 5px; border-radius: 8px; width: 28px; height: 28px; }
.login-panel { display: grid; place-items: center; padding: 32px 20px; background: var(--bg); }
.login-box { width: 100%; max-width: 380px; }
.login-box h1 { margin: 0 0 6px; font-size: 26px; font-weight: 720; letter-spacing: -.025em; }
.login-box > p { margin: 0 0 26px; color: var(--muted); }
.login-box .btn { width: 100%; padding: 11px 16px; }
.login-box input { max-width: none !important; }

/* ---------- Adattamento agli schermi stretti ---------- */
@media (max-width: 960px) {
    .login { grid-template-columns: 1fr; }
    .login-art { display: none; }
    .shell { flex-direction: column; }
    .topbar { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 30; padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--line); }
    .brand-mini { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: -.01em; }
    .side { position: fixed; z-index: 50; left: 0; top: 0; bottom: 0; height: auto; transform: translateX(-102%); transition: transform .2s ease; box-shadow: var(--shadow-md); width: min(84vw, 300px); }
    .nav-open .side { transform: none; }
    .scrim { position: fixed; inset: 0; z-index: 40; background: rgb(15 23 42 / .45); }
    .nav-open .scrim { display: block; }
    .main { padding: 20px 16px 48px; }
    table { display: block; overflow-x: auto; white-space: nowrap; }
    .bubble { max-width: 92%; }
    .stat b { font-size: 26px; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; }
}

/* ---------- Form a sezioni (impostazioni) ---------- */
form.settings { max-width: 1020px; }
.settings-section { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 28px; padding: 26px 0; border-top: 1px solid var(--line); }
.settings-section:first-of-type { border-top: 0; padding-top: 4px; }
.settings-intro h2 { margin: 0 0 6px; font-size: 15px; }
.settings-intro p { margin: 0; font-size: 13px; }
.settings-section .card form .field:last-child, .settings-section .card .field:last-child { margin-bottom: 0; }
.form-actions { position: sticky; bottom: 0; display: flex; gap: 10px; padding: 14px 0; margin-top: 8px; background: linear-gradient(to top, var(--bg) 70%, transparent); z-index: 5; }
@media (max-width: 960px) {
    .settings-section { grid-template-columns: 1fr; gap: 12px; }
}
table.list { white-space: normal; display: table; }
table.list td:first-child { overflow-wrap: anywhere; }

/* ---------- Righe cliccabili, schede, intestazione di un elemento, zona pericolosa ---------- */
tr.clickable { cursor: pointer; }
tr.clickable:focus-visible { outline: none; box-shadow: inset 3px 0 0 var(--brand); }
td a.row-title { color: var(--text); font-weight: 600; }
td a.row-title:hover { color: var(--brand-text); text-decoration: none; }
td.chev { width: 40px; text-align: right; color: var(--muted); opacity: .6; transition: transform .12s, opacity .12s; }
tr.clickable:hover td.chev { opacity: 1; color: var(--brand-text); }
tr.clickable:hover td.chev .icon { transform: translateX(2px); }
td.chev .icon { transition: transform .12s; }
tr.clickable td form, tr.clickable td button { cursor: auto; }

.entity-head { margin-bottom: 4px; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--text); text-decoration: none; }
.entity-title { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.entity-avatar { width: 46px; height: 46px; border-radius: 13px; display: grid; place-items: center; font-weight: 700; font-size: 19px; color: #fff; background: linear-gradient(135deg, #6366f1, #4338ca 60%, #7c3aed); flex-shrink: 0; }
.entity-title h1 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -.02em; line-height: 1.2; }
.entity-title h1 small { font-size: 14px; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.entity-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.entity-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.tabbar { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin: 18px 0 26px; overflow-x: auto; scrollbar-width: none; }
.tabbar::-webkit-scrollbar { display: none; }
.tabbar a, .tabbar button { all: unset; box-sizing: border-box; cursor: pointer; padding: 10px 14px; color: var(--muted); font-weight: 560; white-space: nowrap; border-bottom: 2px solid transparent; margin-bottom: -1px; border-radius: 8px 8px 0 0; transition: color .12s, background .12s; }
.tabbar a:hover, .tabbar button:hover { color: var(--text); background: var(--surface-hover); text-decoration: none; }
.tabbar a.active, .tabbar button.active { color: var(--brand-text); border-bottom-color: var(--brand); }
.tabbar a:focus-visible, .tabbar button:focus-visible { box-shadow: var(--ring); }
.tabbar .count { margin-left: 6px; font-size: 11.5px; background: var(--surface-2); border: 1px solid var(--line); padding: 0 7px; border-radius: 999px; color: var(--muted); }
[hidden] { display: none !important; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; margin: -6px 0 14px; }
h2.sub { margin-top: 0; font-size: 17px; }

.danger-zone { margin-top: 40px; padding: 16px 20px; border: 1px solid color-mix(in srgb, var(--err) 35%, var(--line)); border-radius: var(--radius); display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; background: color-mix(in srgb, var(--err-soft) 45%, transparent); max-width: 900px; }
.danger-zone p { margin: 2px 0 0; font-size: 13px; }
.btn.danger-btn { color: var(--err); border-color: color-mix(in srgb, var(--err) 45%, var(--line)); background: var(--surface); }
.btn.danger-btn:hover { background: var(--err); color: #fff; border-color: var(--err); }

.summary { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.summary .card h3 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 650; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-weight: 520; overflow-wrap: anywhere; }

/* Schede dentro una pagina (stesso documento): a pillola, per distinguerle dalle schede principali dell'elemento */
[data-controller="tabs"] > .tabbar { display: inline-flex; gap: 3px; padding: 4px; margin: 0 0 20px !important; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); max-width: 100%; }
[data-controller="tabs"] > .tabbar button { border-bottom: 0; margin: 0; padding: 7px 14px; border-radius: 9px; }
[data-controller="tabs"] > .tabbar button:hover { background: transparent; color: var(--text); }
[data-controller="tabs"] > .tabbar button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* ---------- Anteprima del widget nel form del chatbot ---------- */
.wp { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.wp-title { display: block; font-size: 13px; margin-bottom: 10px; }
.wp-stage { background: repeating-linear-gradient(45deg, var(--surface-2), var(--surface-2) 10px, var(--surface) 10px, var(--surface) 20px); border: 1px solid var(--line); border-radius: 12px; padding: 16px; display: flex; flex-direction: column; gap: 14px; max-width: 420px; }
.wp-panel { background: #fff; color: #1f2937; border-radius: 16px; overflow: hidden; box-shadow: 0 8px 24px rgb(0 0 0 / .18); font-size: 13px; }
.wp-head { display: flex; align-items: center; gap: 10px; padding: 11px 13px; }
.wp-av, .wp-lav { position: relative; display: block; width: 34px; height: 34px; flex: 0 0 34px; }
.wp-av img, .wp-av .ini, .wp-lav img, .wp-lav .ini { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; display: grid; place-items: center; background: rgb(127 127 127 / .3); font-weight: 700; }
.wp .onl { position: absolute; right: -1px; bottom: 0; width: 10px; height: 10px; border-radius: 50%; background: #22c55e; border: 2px solid #fff; }
.wp-who { flex: 1; min-width: 0; line-height: 1.25; }
.wp-who b { display: block; font-size: 13.5px; }
.wp-who small { display: block; font-size: 11px; opacity: .9; }
.wp-x { font-size: 20px; opacity: .8; }
.wp-log { background: #f3f4f6; padding: 11px; display: flex; flex-direction: column; gap: 7px; }
.wp-msg { max-width: 82%; padding: 7px 10px; background: #fff; border: 1px solid #e5e7eb; align-self: flex-start; }
.wp-msg.user { align-self: flex-end; border: 0; }
.wp-send { display: flex; gap: 6px; padding: 8px; background: #fff; border-top: 1px solid #e5e7eb; }
.wp-input { flex: 1; display: flex; align-items: center; gap: 6px; border: 1px solid #d1d5db; border-radius: 18px; padding: 3px 3px 3px 9px; color: #9ca3af; font-size: 12px; }
.wp-clip { font-size: 12px; filter: grayscale(1); opacity: .7; }
.wp-ph { flex: 1; }
.wp-btn { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.wp-foot { font-size: 10px; color: #9ca3af; text-align: center; padding: 0 8px 7px; background: #fff; }
.wp-foot u { color: #6b7280; }
.wp-launcher-row { display: flex; }
.wp-launcher { display: inline-flex; align-items: center; justify-content: center; gap: 9px; width: 48px; height: 48px; box-shadow: 0 5px 16px rgb(0 0 0 / .25); font-weight: 600; font-size: 13px; }
.wp-launcher.pill { width: auto; height: 50px; padding: 0 16px 0 7px; white-space: nowrap; }
.entity-avatar.img { background: var(--surface-2); padding: 0; overflow: hidden; }
.entity-avatar.img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.bubble .attachments { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0; }
.bubble .attachments img { display: block; max-width: 180px; max-height: 140px; border-radius: 8px; border: 1px solid rgb(0 0 0 / .1); background: #fff; }
.bubble .attachments .file { display: inline-block; padding: 6px 10px; border-radius: 8px; background: rgb(255 255 255 / .85); color: #1f2937; text-decoration: none; font-size: 13px; }
.thumb-avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; vertical-align: -8px; margin-right: 8px; }

/* ---- Scelta dell'azienda (utenti in più aziende) ---- */
.choose-tenant { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: var(--bg); }
.choose-box { width: 100%; max-width: 440px; }
.choose-box .brand-row { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; }
.choose-box h1 { margin: 0 0 6px; font-size: 24px; letter-spacing: -.02em; }
.tenant-choices { list-style: none; margin: 22px 0 0; padding: 0; display: grid; gap: 10px; }
.tenant-choices button { width: 100%; display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--text); cursor: pointer; text-align: left; font: inherit; transition: border-color .15s, box-shadow .15s; }
.tenant-choices button:hover, .tenant-choices button:focus-visible { border-color: var(--brand); box-shadow: 0 4px 14px rgb(0 0 0 / .08); outline: none; }
.tc-initial { flex: 0 0 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: var(--brand); color: var(--on-brand); font-weight: 700; }
.tc-text { flex: 1; display: flex; flex-direction: column; }
.tc-text small { color: var(--muted); }
.choose-logout { margin-top: 26px; text-align: center; }

/* ---- Aziende e permessi di un utente ---- */
.memberships { margin: 18px 0; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); }
.memberships .group-label { font-weight: 600; display: block; margin-bottom: 2px; }
.membership-item { border: 1px solid var(--line); border-radius: 10px; background: var(--surface); padding: 10px 12px; margin: 10px 0; }
.membership-head { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.membership-head .field { flex: 1 1 200px; margin: 0; }
.membership-perms summary { cursor: pointer; font-size: 13px; color: var(--muted); margin-top: 8px; }
.perm-grid > div { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 4px 14px; margin: 8px 0; }
.perm-grid label { font-weight: 400; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.link.danger { color: var(--danger, #dc2626); background: none; border: 0; cursor: pointer; padding: 8px 0; }
.chip-inline { display: inline-block; margin: 1px 8px 1px 0; white-space: nowrap; }

/* ---- Pannello conversazioni (stile WhatsApp Web): pagina d'arrivo di chi lavora per un'azienda ---- */
.inbox { height: 100vh; height: 100dvh; display: grid; grid-template-columns: minmax(300px, 400px) 1fr; background: var(--bg); color: var(--text); }
.inbox-side { display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-right: 1px solid var(--line); }
.inbox-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.inbox-tenant { display: flex; align-items: center; gap: 10px; min-width: 0; }
.inbox-tenant b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inbox-tenant a, .inbox-tenant small { font-size: 12px; }
.tc-initial.sm { flex: 0 0 34px; width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--brand); color: var(--on-brand); font-weight: 700; }
.inbox-actions { display: flex; gap: 2px; }
.inbox-search { padding: 10px 12px 6px; }
.inbox-search input { width: 100%; padding: 9px 12px 9px 36px; border: 1px solid var(--line); border-radius: 10px; font: inherit; font-size: 14px; color: var(--text); background: var(--surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") no-repeat 12px center; outline: none; transition: border-color .12s, box-shadow .12s; }
.inbox-search input:focus { border-color: var(--brand); box-shadow: var(--ring); background-color: var(--surface); }
.inbox-search input::placeholder { color: var(--muted); opacity: .8; }
.inbox-filters { display: flex; flex-wrap: nowrap; gap: 5px; padding: 4px 12px 10px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.inbox-filters::-webkit-scrollbar { display: none; }
.inbox-filters button { flex: 0 0 auto; white-space: nowrap; border: 1px solid var(--line); background: var(--surface); color: var(--muted); border-radius: 999px; padding: 4px 9px; font: inherit; font-size: 12.5px; cursor: pointer; }
.inbox-filters button[aria-pressed="true"] { background: var(--brand-soft); color: var(--brand-text, var(--brand)); border-color: transparent; font-weight: 600; }
.inbox-filters .count { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--warn, #d97706); color: #fff; font-size: 11px; font-weight: 700; }
.inbox-list { display: block; flex: 1; min-height: 0; overflow-y: auto; }
.inbox-empty { padding: 24px 16px; text-align: center; }
.chat-tiles { list-style: none; margin: 0; padding: 0; }
.chat-tile { display: flex; gap: 12px; padding: 11px 14px; text-decoration: none; color: inherit; border-bottom: 1px solid var(--line); }
.chat-tile:hover { background: var(--surface-hover); }
.chat-tile.active { background: var(--brand-soft); }
.ct-avatar { position: relative; flex: 0 0 44px; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); border: 1px solid var(--line); font-weight: 700; color: var(--muted); }
.ct-avatar.whatsapp { background: #dcfce7; color: #15803d; border-color: #bbf7d0; }
.ct-online { position: absolute; right: 0; bottom: 1px; width: 11px; height: 11px; border-radius: 50%; background: #22c55e; border: 2px solid var(--surface); }
.ct-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.ct-line { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.ct-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ct-time { color: var(--muted); font-size: 12px; }
.ct-last { flex: 1; min-width: 0; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ct-last b { color: var(--text); font-weight: 600; }
.ct-badges { display: flex; flex-wrap: wrap; gap: 4px; }
.ct-badges .badge { font-size: 11px; padding: 1px 7px; }
.badge.lead { background: #e0e7ff; color: #3730a3; }
.badge.warn { background: var(--warn-soft); color: #b45309; }
.inbox-main { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--surface-2); }
.inbox-main > turbo-frame { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.inbox-placeholder { margin: auto; text-align: center; max-width: 420px; padding: 24px; color: var(--muted); }
.inbox-placeholder svg { opacity: .35; }
.pane { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.pane-head { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.pane-title { flex: 1; min-width: 0; }
.pane-title b { margin-right: 6px; }
.pane-back { display: none; }
.pane-body { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 12px 16px 14px; gap: 10px; }
.pane-body > p.muted { margin: 0; font-size: 13px; }
.pane-body > [data-controller="live-conversation"] { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; }
.pane-body .card.takeover { padding: 10px 14px; margin: 0; }
.pane-body .chat-log.static { flex: 1; min-height: 0; overflow-y: auto; max-width: none; height: auto; }
.pane-body .operator-form { margin: 0; }

@media (max-width: 760px) {
    .inbox { grid-template-columns: 1fr; }
    .inbox.has-chat .inbox-side { display: none; }
    .inbox:not(.has-chat) .inbox-main { display: none; }
    .pane-back { display: inline-grid; }
}

/* ---- Allegati dell'operatore ---- */
.operator-form { flex-wrap: wrap; }
.op-files { flex: 1 0 100%; display: flex; flex-wrap: wrap; gap: 6px; }
.op-files:empty { display: none; }
.op-chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 4px 3px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); font-size: 12.5px; }
.op-chip button { all: unset; cursor: pointer; width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); }
.op-clip { align-self: center; font-size: 18px; }

/* ---- Non letti, argomento, archiviate, riassunto ---- */
.chat-tile.unread .ct-name, .chat-tile.unread .ct-last { color: var(--text); font-weight: 700; }
.chat-tile.unread .ct-time { color: #16a34a; font-weight: 600; }
.ct-unread { flex: 0 0 auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: #16a34a; color: #fff; font-size: 11.5px; font-weight: 700; display: inline-grid; place-items: center; }
.ct-who { font-size: 12px; color: var(--muted); margin-right: 2px; max-width: 160px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inbox-more { text-align: center; padding: 12px; margin: 0; }
.inbox-archived-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; background: var(--surface-2); border-bottom: 1px solid var(--line); }
.pane-title small { display: block; }
.pane-summary { margin: 0; padding: 8px 16px; background: var(--brand-soft); border-bottom: 1px solid var(--line); font-size: 13.5px; }
.pane-summary summary { cursor: pointer; font-weight: 600; }
.pane-summary p { margin: 6px 0; }
