/* ═══════════════════════════════════════════════════════════════════════
   TWIZA WP — pagina pubblica dell'assistente (index.html) + backoffice del sito
   (backoffice.html). v1.9.14: nuova interfaccia (mockup twiza-wp-mockup), stesso
   sistema di TWIZA Legal / Fashion / Comm / Quote Generator.

   Tema scuro di default, chiaro con html[data-theme="light"] (chiave 'tw-theme').
   --accent resta il nome che applyWidgetConfig() (app.js) sovrascrive col colore
   scelto dal cliente: tutte le tinte d'accento derivano da lì.
   ═══════════════════════════════════════════════════════════════════════ */
:root {
  --accent: #d81b60;
  --accent-hover: color-mix(in srgb, var(--accent) 88%, #000);
  --accent-soft: color-mix(in srgb, var(--accent) 16%, transparent);
  --accent-text: color-mix(in srgb, var(--accent) 55%, #ffffff);
  --accent-glow: color-mix(in srgb, var(--accent) 30%, transparent);
  --bg: #0a0b18;
  --panel: #10122a;
  --surface: #161937;
  --surface2: #1f2347;
  --border: #272b52;
  --line: #272b52;
  --text: #ecebf6;
  --text-muted: #a8abc9;
  --faint: #8b8eb2;
  --ok: #43d39a; --warn: #f3bd4e; --err: #ff8484; --info: #7fb2ff;
  --radius: 10px;
  --shadow: 0 18px 48px rgba(0,0,0,.5);
  --font: "Titillium Web", "Segoe UI", system-ui, -apple-system, sans-serif;
  /* dashboard del parco (v1.9.0): colori dei DATI, non dell'interfaccia */
  --chart-serie: #3987e5;
  --chart-grid: rgba(255,255,255,0.07);
  --chart-axis: rgba(255,255,255,0.18);
  --stato-buono: #0ca30c; --stato-attesa: #fab219; --stato-serio: #ec835a; --stato-critico: #d03b3b;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --accent-text: color-mix(in srgb, var(--accent) 82%, #000000);
  --bg: #eef0f6; --panel: #ffffff; --surface: #f6f7fb; --surface2: #e9ebf4; --border: #d9dce9; --line: #d9dce9;
  --text: #161831; --text-muted: #50546f; --faint: #62667f;
  --ok: #1f7a55; --warn: #8a5a00; --err: #b03434; --info: #2f5fb3;
  --shadow: 0 18px 48px rgba(20,22,50,.16);
  --chart-grid: rgba(20,22,50,0.08); --chart-axis: rgba(20,22,50,0.22);
  --stato-buono: #117a11; --stato-attesa: #9a6a00; --stato-serio: #b8532c; --stato-critico: #b82e2e;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
/* [hidden] vince sempre, anche su elementi con classi che impostano display. */
[hidden] { display: none !important; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5;
       display: flex; flex-direction: column; }
button, input, select, textarea { font-family: inherit; }
a { color: var(--accent-text); }
select option, optgroup option { background: var(--panel); color: var(--text); }
svg.tw-ic { display: block; flex-shrink: 0; }
:root[data-theme="light"] .tw-moon { display: none; }
:root:not([data-theme="light"]) .tw-sun { display: none; }

/* ---------- elementi comuni ---------- */
.pill { display: inline-flex; align-items: center; height: 22px; padding: 0 9px; border-radius: 6px; font-size: 11.5px;
        font-weight: 600; white-space: nowrap; background: var(--surface2); color: var(--text-muted); }
.pill-accent { background: var(--accent-soft); color: var(--accent-text); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 16px;
       border-radius: 8px; border: 1px solid transparent; background: var(--accent); color: #fff; font-size: 14px;
       font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--accent-hover); }
.tb-btn { display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 12px; border-radius: 8px;
          border: 1px solid transparent; background: transparent; color: var(--text-muted); font-size: 14px; cursor: pointer;
          text-decoration: none; white-space: nowrap; }
.tb-btn:hover { background: var(--surface2); color: var(--text); }
.tb-btn.ico { width: 36px; padding: 0; justify-content: center; }
.tb-btn.outline { border-color: var(--border); color: var(--text); }
.vdiv { width: 1px; height: 22px; background: var(--border); flex-shrink: 0; }
.link { color: var(--accent-text); text-decoration: none; font-size: 14px; }
.btn-link { background: none; border: none; cursor: pointer; padding: 0; font: inherit; }
.who { color: var(--text-muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* pulsanti già usati dal JS (stessi nomi di classe) */
.btn-send { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 16px;
            border-radius: 8px; border: 0; background: var(--accent); color: #fff; font-size: 14px; font-weight: 600; cursor: pointer; }
.btn-send:hover:not(:disabled) { background: var(--accent-hover); }
.btn-send:disabled { opacity: .5; cursor: not-allowed; }
.btn-outline { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px;
               border-radius: 8px; border: 1px solid var(--border); background: transparent; color: var(--text);
               font-size: 13.5px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn-outline:hover:not(:disabled) { background: var(--surface2); }
.btn-outline:disabled { opacity: .5; cursor: not-allowed; }
.btn-danger { display: inline-flex; align-items: center; height: 32px; padding: 0 12px; border-radius: 8px;
              border: 1px solid rgba(224,85,85,.45); background: transparent; color: var(--err); font-size: 13px; cursor: pointer; }
.btn-danger:hover { background: rgba(224,85,85,.12); }

input[type=text], input[type=email], input[type=password], input:not([type]), select, textarea {
  background: var(--surface); border: 1px solid var(--border); color: var(--text); border-radius: 8px;
  padding: 0 12px; height: 40px; font-size: 14px; outline: none; }
textarea { height: auto; padding: 10px 12px; line-height: 1.5; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input::placeholder, textarea::placeholder { color: var(--faint); }
input[type=color] { width: 44px; height: 40px; padding: 3px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; }
input[type=file] { color: var(--text-muted); font-size: 13px; }

/* ---------- barra in alto ---------- */
.topbar { height: 64px; flex-shrink: 0; display: flex; align-items: center; gap: 10px; padding: 0 24px;
          background: var(--panel); border-bottom: 1px solid var(--border); }
.topbar .logo { height: 34px; width: auto; display: block; }
.topbar .sep { color: var(--faint); }
.env-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.tb-spacer { flex: 1; }

/* ═══════════════════ PAGINA PUBBLICA (chat) ═══════════════════ */
.chat-shell { flex: 1; min-height: 0; width: 100%; max-width: 1088px; margin: 0 auto; padding: 22px 24px 16px;
              display: flex; flex-direction: column; gap: 14px; }
/* Avviso IA (Scheda WP v1.1 §4): colori FISSI del tema, mai l'accento del cliente — un
   accento uguale allo sfondo lo renderebbe invisibile, cioe' «meno evidente». */
.ai-notice { display: block; visibility: visible; opacity: 1; margin: 0 0 10px; padding: 8px 12px;
  font-size: 13px; line-height: 1.45; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); }
.messages { flex: 1; min-height: 240px; overflow-y: auto; display: flex; flex-direction: column; gap: 18px; padding: 8px 0; }
.messages > .msg:first-child { margin-top: auto; }
.msg { display: flex; flex-direction: column; align-items: flex-start; }
.msg-user { align-items: flex-end; }
.msg-body { max-width: min(900px, 88%); padding: 16px 20px; border-radius: 14px; border: 1px solid var(--border);
            background: var(--panel); color: var(--text); font-size: 15px; line-height: 1.62; white-space: pre-wrap;
            word-wrap: break-word; animation: twMsgIn .25s ease both; }
.msg-user .msg-body { max-width: min(640px, 80%); padding: 12px 20px; background: var(--accent-soft);
                      border-color: var(--accent); color: var(--text); }
@keyframes twMsgIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.msg-truncated { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 8px; font-size: 12.5px; color: var(--faint); }
.msg-continue-btn { height: 30px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border); background: transparent;
                    color: var(--text); font-size: 13px; cursor: pointer; }
.msg-continue-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent-text); }
.msg-continue-btn:disabled { opacity: .5; cursor: default; }
.msg-typing { display: inline-flex; align-items: center; min-height: 24px; }

/* v1.9.13 — la risposta dell'agente non e' piu' testo con `pre-wrap`: e' HTML reso da
 * `twizaRenderAnswer` (twiza-md.js). Con `pre-wrap` addosso gli interlinea si sommerebbero.
 * Sulla bolla dell'UTENTE `pre-wrap` resta: e' l'unica cosa che gli conserva gli a capo. */
.msg:not(.msg-user) .msg-body { white-space: normal; }
.msg:not(.msg-user) .msg-body p { margin: 0 0 0.6em; }
.msg:not(.msg-user) .msg-body p:last-child { margin-bottom: 0; }
.msg:not(.msg-user) .msg-body ul,
.msg:not(.msg-user) .msg-body ol { margin: 0 0 0.6em; padding-left: 1.25em; }
.msg:not(.msg-user) .msg-body li { margin: 0 0 0.2em; }
.msg:not(.msg-user) .msg-body a { text-decoration: underline; word-break: break-word; }
.msg:not(.msg-user) .msg-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em; padding: 1px 4px; border-radius: 4px;
  background: rgba(127, 127, 127, 0.18);
}
.typing-dots { display: inline-flex; gap: 5px; align-items: center; }
.typing-dots span { width: 7px; height: 7px; border-radius: 50%; background: var(--accent-text); animation: typing-bounce 1.2s infinite ease-in-out both; }
.typing-dots span:nth-child(1) { animation-delay: -.24s; }
.typing-dots span:nth-child(2) { animation-delay: -.12s; }
@keyframes typing-bounce { 0%, 80%, 100% { transform: scale(.6); opacity: .45; } 40% { transform: scale(1); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .typing-dots span, .msg-body { animation: none; } }

.composer { display: flex; align-items: center; gap: 10px; padding: 10px 12px 10px 16px; border-radius: 14px;
            border: 1px solid var(--border); background: var(--panel); }
.composer:focus-within { border-color: var(--accent); }
.composer textarea { flex: 1; min-height: 40px; max-height: 180px; border: 0; background: transparent; padding: 9px 4px;
                     font-size: 15px; resize: none; }
.composer textarea:focus { border: 0; }
.chat-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
             border-top: 1px solid var(--border); padding-top: 12px; }
.kbd-hint { font-size: 12.5px; color: var(--faint); }
.docs-panel { position: relative; }
.docs-panel summary { list-style: none; display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px;
                      border-radius: 999px; border: 1px solid var(--border); color: var(--text-muted); font-size: 13px; cursor: pointer; }
.docs-panel summary::-webkit-details-marker { display: none; }
.docs-panel summary::after { content: ""; width: 7px; height: 7px; border-right: 1.6px solid currentColor; border-bottom: 1.6px solid currentColor;
                             transform: translateY(-2px) rotate(45deg); margin-left: 4px; }
.docs-panel[open] summary { color: var(--text); border-color: var(--accent); }
.docs-panel[open] summary::after { transform: translateY(1px) rotate(-135deg); }
.docs-panel[open] { z-index: 5; }
.docs-pop { position: absolute; left: 0; bottom: calc(100% + 8px); width: min(440px, 86vw); max-height: 340px; overflow: auto;
            padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--panel); box-shadow: var(--shadow); }
.doc-row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.doc-row:last-child { border-bottom: 0; }
.doc-size { color: var(--faint); font-size: 12px; white-space: nowrap; }
.docs-hint { margin: 10px 0 0; font-size: 12.5px; color: var(--faint); }
.docs-hint a { color: var(--accent-text); }
.app-footer { text-align: center; padding: 10px 16px 14px; font-size: 12px; color: var(--faint); }
.app-footer a { color: var(--accent-text); text-decoration: none; }

/* ═══════════════════ ACCESSO (backoffice) ═══════════════════ */
.auth-shell { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px; padding: 32px 16px; }
.auth-brand { display: flex; align-items: center; gap: 10px; }
.auth-brand img { height: 40px; }
.login-card { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 4px; padding: 30px 28px 24px;
              border-radius: 14px; border: 1px solid var(--border); background: var(--panel); box-shadow: var(--shadow); }
.login-card h1 { margin: 0 0 2px; font-size: 22px; }
.login-sub { margin: 0 0 12px; color: var(--text-muted); font-size: 13.5px; line-height: 1.55; }
.login-card label { font-size: 13px; color: var(--text-muted); margin-top: 8px; }
.login-card input { width: 100%; }
.login-card .btn-send { margin-top: 18px; width: 100%; height: 44px; font-size: 15px; }
.login-msg { color: var(--err); font-size: 13px; min-height: 18px; margin-top: 8px; }
.login-foot { margin-top: 6px; text-align: center; font-size: 12.5px; color: var(--faint); }

/* ═══════════════════ BACKOFFICE ═══════════════════ */
body.bo { flex-direction: row; height: 100vh; overflow: hidden; }
body.bo:not(.tw-in) .bo-side, body.bo:not(.tw-in) .bo-top { display: none; }
body.bo:not(.tw-in) .bo-main { overflow: auto; }
.bo-side { width: 264px; flex-shrink: 0; height: 100%; display: flex; flex-direction: column; background: var(--panel);
           border-right: 1px solid var(--border); transition: width .25s cubic-bezier(.2,.8,.2,1); overflow: hidden; }
.sb-top { display: flex; align-items: center; gap: 8px; padding: 14px 14px 10px 16px; }
.sb-top img { height: 34px; width: auto; }
.sb-top .tb-btn { margin-left: auto; }
.tenant-card { display: flex; align-items: center; gap: 12px; margin: 4px 16px 0; padding: 10px 12px; border-radius: 12px;
               border: 1px solid var(--border); background: var(--surface); min-width: 0; }
.tenant-card .av, .bo-avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent); color: #fff; font-weight: 700;
                   font-size: 13px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.tenant-card b { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tenant-card small { display: block; font-size: 12px; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tenant-card > div { min-width: 0; }
.sb-cta { margin: 14px 16px 12px; height: 42px; }
.bo-nav { flex: 1; overflow-y: auto; padding: 4px 10px 12px; border-top: 1px solid var(--border); }
.navsec { font-size: 10.5px; font-weight: 700; letter-spacing: .11em; text-transform: uppercase; color: var(--faint); padding: 14px 12px 6px; }
.navitem { display: flex; width: 100%; align-items: center; gap: 12px; height: 40px; padding: 0 12px; border-radius: 9px; border: 0;
           background: none; color: var(--text-muted); font-size: 14.5px; cursor: pointer; text-align: left; white-space: nowrap; }
.navitem:hover { background: var(--surface2); color: var(--text); }
.navitem.on { background: var(--accent-soft); color: var(--text); font-weight: 600; }
.navitem.on svg { color: var(--accent-text); }
.sb-foot { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--border); font-size: 12px; color: var(--faint); }
.sb-foot span { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body.tw-sb-mini .bo-side { width: 72px; }
body.tw-sb-mini .sb-top img, body.tw-sb-mini .sb-top .pill, body.tw-sb-mini .tenant-card > div, body.tw-sb-mini .navsec,
body.tw-sb-mini .sb-cta span, body.tw-sb-mini .sb-foot span { display: none; }
body.tw-sb-mini .sb-top { padding: 14px 18px 10px; }
body.tw-sb-mini .tenant-card { margin: 4px 12px 0; padding: 8px; justify-content: center; border: 0; background: none; }
body.tw-sb-mini .sb-cta { margin: 10px 12px; padding: 0; }
body.tw-sb-mini .navitem { justify-content: center; padding: 0; font-size: 0; }
body.tw-sb-mini .bo-nav { padding: 4px 12px; }
body.tw-sb-mini .sb-foot { justify-content: center; }

.bo-main { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; }
.bo-top { padding: 0 20px; }
.tb-title { font-size: 15.5px; font-weight: 600; white-space: nowrap; }
.bo-top .burger { display: none; }
.bo-content { flex: 1; overflow-y: auto; padding: 28px 28px 48px; }
.view { display: none; flex-direction: column; gap: 14px; max-width: 1180px; }
.view.on { display: flex; }
.ph { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 8px; }
.ph h1 { margin: 0; font-size: 27px; font-weight: 700; line-height: 1.2; }
.ph p { margin: 8px 0 0; font-size: 14.5px; color: var(--text-muted); }

/* le sezioni esistenti diventano schede */
.bo-section, .bo-card { display: flex; flex-direction: column; gap: 12px; padding: 18px 20px; border-radius: 14px;
                        border: 1px solid var(--border); background: var(--panel); min-width: 0; }
.bo-section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.bo-section-head h2, .bo-card h2 { margin: 0; font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); }
.bo-section h3 { margin: 6px 0 0; font-size: 12px !important; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); }
.bo-section-head form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.bo-section label { color: var(--text-muted); }
.bo-section input[type=text], .bo-section input[type=email], .bo-section select, .bo-section textarea { max-width: 100%; }
.bo-hint { font-size: 13px; color: var(--text-muted); line-height: 1.55; margin: 0; }
.bo-hint strong { color: var(--text); }
.bo-msg { color: var(--text-muted); font-size: 13px; min-height: 0; }
.bo-msg:empty { display: none; }
.bo-msg.bo-msg-ko { color: var(--err); }
.muted, .col-muted { color: var(--text-muted); }
#sys-prompt { width: 100%; min-height: 200px; font-size: 14px; line-height: 1.6; }
#model-select { height: 40px; }

/* zona di caricamento (stesso <input type=file id=file-input>) */
#upload-form { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.tw-drop { position: relative; flex: 1; min-width: 260px; display: flex; align-items: center; justify-content: center; gap: 10px;
           min-height: 84px; padding: 14px; border-radius: 12px; border: 1.5px dashed var(--border); background: var(--surface);
           color: var(--text-muted); font-size: 13.5px; text-align: center; }
.tw-drop:hover, .tw-drop.over { border-color: var(--accent); color: var(--text); }
.tw-drop.has { border-style: solid; border-color: var(--accent); color: var(--text); }
.tw-drop input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.tw-drop small { display: block; color: var(--faint); font-size: 12px; margin-top: 2px; }
.tw-drop b { color: var(--accent-text); }

/* tabelle generate da backoffice.js */
.bo-table, .ad-tab { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.bo-table th, .ad-tab th { text-align: left; font-size: 11px; letter-spacing: .07em; text-transform: uppercase; color: var(--faint);
                           font-weight: 600; padding: 0 12px 9px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.bo-table td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.bo-table tr:last-child td { border-bottom: 0; }
.bo-table tr:hover td { background: var(--surface); }
.bo-table .col-muted { color: var(--text-muted); font-size: 13px; white-space: nowrap; }
.bo-table .col-action { text-align: right; white-space: nowrap; }
.bo-table a, .bo-table button.btn-link { color: var(--accent-text); font-weight: 600; text-decoration: none; }

/* trascritto sessione */
.bo-msg-row { margin: 0 0 12px; }
.bo-msg-role { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); margin-bottom: 4px; }
.bo-msg-text { padding: 10px 14px; border-radius: 10px; border: 1px solid var(--border); white-space: pre-wrap; word-wrap: break-word; line-height: 1.55; }
.bo-msg-assistant .bo-msg-text { background: var(--surface); }
.bo-msg-user .bo-msg-text { border-color: var(--accent); background: var(--accent-soft); }

/* v1.9.12 — la risposta dell'agente non e' piu' testo con `pre-wrap`: e' HTML reso da
 * `twizaRenderAnswer` (paragrafi, elenchi, link, codice). Con `pre-wrap` addosso gli
 * interlinea si sommerebbero. Il messaggio dell'UTENTE resta testo con escape, e per lui
 * `pre-wrap` serve ancora: e' l'unica cosa che gli conserva gli a capo. */
.bo-msg-assistant .bo-msg-text,
#xplat-ask-out { white-space: normal; }
.bo-msg-assistant .bo-msg-text p,
#xplat-ask-out p { margin: 0 0 0.6em; }
.bo-msg-assistant .bo-msg-text p:last-child,
#xplat-ask-out p:last-child { margin-bottom: 0; }
.bo-msg-assistant .bo-msg-text ul, .bo-msg-assistant .bo-msg-text ol,
#xplat-ask-out ul, #xplat-ask-out ol { margin: 0 0 0.6em; padding-left: 1.25em; }
.bo-msg-assistant .bo-msg-text a,
#xplat-ask-out a { text-decoration: underline; word-break: break-word; }
.bo-msg-assistant .bo-msg-text code,
#xplat-ask-out code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em; padding: 1px 4px; border-radius: 4px;
  background: rgba(127, 127, 127, 0.18);
}
.twiza-code {
  margin: 0 0 0.6em; padding: 8px 10px; border-radius: 6px;
  background: rgba(127, 127, 127, 0.18); overflow-x: auto; white-space: pre;
}
.twiza-code code { background: none; padding: 0; }

/* impostazioni (aspetto, password) */
.bo-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.bo-grid label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-muted); }
.bo-grid input, .bo-grid select { width: 100%; }
.bo-grid input[type=color] { width: 60px; }

/* utenti del backoffice */
.bo-users { display: flex; flex-direction: column; gap: 8px; }
.bo-user { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--border);
           border-radius: 10px; padding: 10px 12px; }
.bo-user-mail { font-weight: 600; font-size: 14px; }
.bo-user-meta { color: var(--faint); font-size: 12.5px; }
.bo-user-grow { flex: 1; }
.bo-user select, .bo-user input { height: 32px; font-size: 13px; }
.bo-user.is-off { opacity: .55; }
.bo-user-badge { display: inline-flex; align-items: center; height: 22px; padding: 0 9px; border-radius: 6px; font-size: 11.5px; font-weight: 600;
                 background: var(--accent-soft); color: var(--accent-text); }
.bo-user-del { height: 32px; padding: 0 12px; background: transparent; border: 1px solid var(--border); color: var(--text-muted);
               border-radius: 8px; cursor: pointer; font-size: 13px; }
.bo-user-del:hover { border-color: rgba(224,85,85,.55); color: var(--err); }
.bo-tag-bozza { font-size: 11px; font-weight: 600; margin-left: 8px; padding: 2px 8px; border-radius: 6px; background: rgba(243,189,78,.18); color: var(--warn); }
.bo-avviso { margin: 0; padding: 10px 12px; border-radius: 10px; background: rgba(243,189,78,.08); border: 1px solid rgba(243,189,78,.35); }

/* colori fissi scritti dal JS negli esiti → token del tema (leggibili anche in chiaro) */
.bo-section [style*="color:#e88"], .bo-section [style*="color: #e88"] { color: var(--err) !important; }
.bo-section [style*="color:#7dd87d"] { color: var(--ok) !important; }
.bo-section [style*="color:#e8c37a"] { color: var(--warn) !important; }
.bo-section [style*="color:#5EC900"] { color: var(--ok) !important; }
.bo-section [style*="color:#f59e0b"] { color: var(--warn) !important; }
.bo-section [style*="border-bottom:1px solid rgba(255,255,255,.06)"] { border-bottom-color: var(--border) !important; }
.bo-section [style*="border:1px solid rgba(125,216,125,.4)"] { border-color: rgba(67,211,154,.45) !important; background: rgba(67,211,154,.06); }
#agency-add-box { border-top-color: var(--border) !important; }
.bo-section code { font-size: 12.5px; padding: 1px 6px; border-radius: 5px; background: var(--surface2); color: var(--text); }

/* stato dell'agente (Knowledge Base) */
#agent-status { padding: 12px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }

/* regole di base (statiche, dalla Guida) */
.rules { display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 0; list-style: none; }
.rules li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
            background: var(--surface); font-size: 13.5px; }
.rules li svg { color: var(--ok); }

/* anteprima aspetto pubblico */
.tw-aspetto { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 14px; align-items: start; }
.tw-prev { border-radius: 12px; border: 1px solid var(--border); background: var(--bg); padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.tw-prev-head { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13.5px; }
.tw-prev-av { width: 24px; height: 24px; border-radius: 6px; background: var(--tw-prev-accent, var(--accent)); color: #fff; font-size: 11px; font-weight: 700;
              display: flex; align-items: center; justify-content: center; }
.tw-prev-bot { align-self: flex-start; max-width: 88%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--panel); font-size: 13px; }
.tw-prev-me { align-self: flex-end; max-width: 80%; padding: 8px 12px; border-radius: 10px; font-size: 13px;
              border: 1px solid var(--tw-prev-accent, var(--accent)); background: color-mix(in srgb, var(--tw-prev-accent, var(--accent)) 16%, transparent); }
.tw-prev-in { display: flex; align-items: center; justify-content: space-between; height: 36px; padding: 0 12px; border-radius: 8px;
              border: 1px solid var(--border); background: var(--panel); color: var(--faint); font-size: 12.5px; }
.tw-prev-in svg { color: var(--tw-prev-accent, var(--accent)); }

/* ═══════════════════ GUIDA e SESSIONE (finestre) ═══════════════════ */
.guida-btn { display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 12px; border-radius: 8px; border: 0;
             background: transparent; color: var(--text-muted); font-size: 14px; cursor: pointer; }
.guida-btn:hover { background: var(--surface2); color: var(--text); }
.guida-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.guida-btn-icon { display: inline-flex; }
.guida-overlay { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 20px; }
.guida-backdrop { position: absolute; inset: 0; background: rgba(5,6,16,.62); }
:root[data-theme="light"] .guida-backdrop { background: rgba(22,24,49,.35); }
.guida-modal { position: relative; width: 100%; max-width: 760px; max-height: 86vh; display: flex; flex-direction: column;
               background: var(--panel); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.guida-modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.guida-modal-head h2 { margin: 0; font-size: 17px; font-weight: 700; }
.guida-close { width: 36px; height: 36px; border-radius: 8px; border: 0; background: none; color: var(--text-muted); font-size: 24px; line-height: 1; cursor: pointer; }
.guida-close:hover { background: var(--surface2); color: var(--text); }
.guida-tabs { display: flex; gap: 4px; padding: 0 20px; border-bottom: 1px solid var(--border); }
.guida-tab { height: 42px; padding: 0 12px; border: 0; border-bottom: 2px solid transparent; background: none; color: var(--text-muted);
             font-size: 14px; cursor: pointer; margin-bottom: -1px; }
.guida-tab:hover { color: var(--text); }
.guida-tab.is-active { color: var(--accent-text); border-bottom-color: var(--accent); font-weight: 600; }
.guida-body { overflow-y: auto; padding: 18px 22px 24px; font-size: 14px; line-height: 1.62; color: var(--text-muted); }
.guida-panel[hidden] { display: none; }
.guida-panel:focus { outline: none; }
.guida-lead { color: var(--text-muted); margin-top: 0; }
.guida-panel h3 { margin: 20px 0 6px; font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); }
.guida-panel h3:first-of-type { margin-top: 8px; }
.guida-panel p { margin: 8px 0; }
.guida-panel ul, .guida-panel ol { margin: 8px 0; padding-left: 22px; }
.guida-panel li { margin: 4px 0; }
.guida-panel strong { color: var(--text); }
.guida-panel code, .guida-panel kbd { font-size: 12.5px; padding: 1px 6px; border-radius: 5px; background: var(--surface2); color: var(--text); font-family: inherit; }
.guida-note { color: var(--faint); font-size: 13px; border-left: 2px solid var(--border); padding-left: 12px; }

/* ═══════════════════ v1.9.0 (AO1) — Dashboard del parco ═══════════════════ */
.ad-kpi { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 4px; }
.ad-kpi .ad-tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.ad-kpi .ad-num { font-size: 26px; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }
.ad-kpi .ad-lab { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.ad-kpi .ad-note { font-size: 12px; color: var(--faint); margin-top: 4px; }
.ad-fig { margin: 0; padding: 14px 16px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); }
.ad-fig figcaption { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; margin-bottom: 8px; font-size: 13.5px; }
.ad-fig .ad-sub { font-size: 12px; color: var(--faint); }
.ad-plot { position: relative; }
.ad-plot svg { display: block; width: 100%; height: auto; overflow: visible; }
.ad-plot text { fill: var(--text-muted); font-size: 10px; }
.ad-plot .ad-val { fill: var(--text); font-size: 10px; font-variant-numeric: tabular-nums; }
.ad-hit { fill: transparent; cursor: pointer; }
.ad-hit:hover + .ad-mark, .ad-hit:focus + .ad-mark { filter: brightness(1.25); }
.ad-tip { position: absolute; pointer-events: none; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 6px 9px;
          font-size: 12px; color: var(--text); white-space: nowrap; box-shadow: var(--shadow); transform: translate(-50%, -115%); opacity: 0; transition: opacity .08s; }
.ad-tip.on { opacity: 1; }
.ad-tip b { font-variant-numeric: tabular-nums; }
.ad-badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 600; padding: 1px 8px; border-radius: 6px;
            border: 1px solid currentColor; white-space: nowrap; }
.ad-badge.b-buono { color: var(--stato-buono); } .ad-badge.b-attesa { color: var(--stato-attesa); }
.ad-badge.b-serio { color: var(--stato-serio); } .ad-badge.b-critico { color: var(--stato-critico); }
.ad-tab th { white-space: normal; }
.ad-tab td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.ad-tab td.num { text-align: right; font-variant-numeric: tabular-nums; }
.ad-tab tr:hover td { background: var(--surface); }
#sec-agency-dash { min-width: 0; }
.ad-wrap { overflow-x: auto; max-width: 100%; }
.ad-tab .ad-sito a { display: inline-block; max-width: 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom;
                     color: var(--text); font-weight: 600; text-decoration: underline; text-decoration-color: var(--faint); text-underline-offset: 2px; }
.ad-tab .ad-sito a:hover { text-decoration-color: var(--text); }
.ad-tab .ad-stato { display: flex; flex-wrap: wrap; gap: 4px; max-width: 150px; }
.ad-tab .ad-badge { white-space: normal; }
.ad-tab .ad-quando { white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ═══════════════════ schermi stretti ═══════════════════ */
@media (max-width: 900px) {
  .bo-side { position: fixed; z-index: 60; left: 0; top: 0; bottom: 0; transform: translateX(-100%); transition: transform .25s; box-shadow: var(--shadow); }
  body.tw-sb-open .bo-side { transform: none; }
  body.tw-sb-mini .bo-side { width: 264px; }
  .bo-top .burger { display: inline-flex; }
  .bo-top .tw-sbt, .bo-top .tb-hide-sm { display: none; }
  .bo-content { padding: 20px 16px 40px; }
  .tw-aspetto { grid-template-columns: minmax(0, 1fr); }
  .ph { flex-direction: column; }
}
@media (max-width: 620px) {
  .topbar { padding: 0 14px; gap: 6px; }
  .chat-top .sep, .chat-top .pill, .chat-top .guida-btn-label, .chat-top .vdiv { display: none; }
  .chat-shell { padding: 14px 12px 10px; }
  .msg-body { max-width: 100%; }
  .kbd-hint { display: none; }
  .guida-modal { max-height: 92vh; }
  .guida-body { padding: 16px; }
}

/* stati (pallini e pill) usati dal backoffice */
.tw-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; vertical-align: 1px; background: var(--faint); }
.tw-dot.ok { background: var(--ok); } .tw-dot.warn { background: var(--warn); } .tw-dot.err { background: var(--err); }
.pill-ok { background: rgba(67,211,154,.18); color: var(--ok); }
.pill-warn { background: rgba(243,189,78,.18); color: var(--warn); }
.pill-err { background: rgba(224,85,85,.18); color: var(--err); }
.pill-info { background: rgba(127,178,255,.18); color: var(--info); }
.bo-table .pill { height: 20px; font-size: 11px; margin-left: 4px; vertical-align: 1px; }
.bo-section > button, .bo-section > .btn-outline { align-self: flex-start; }
#xplat-ask-q { display: block; width: 100%; }
#xplat-ask-box, #agency-add-box { display: flex; flex-direction: column; gap: 6px; }
#xplat-ask-box > button, #agency-add-box > button { align-self: flex-start; margin-top: 4px !important; }
#xplat-ask-box label, #agency-add-box label { margin: 6px 0 0 !important; }
#xplat-ask-box > *, #agency-add-box > * { margin-bottom: 0 !important; }
#sessions-table, #docs-table, #xplat-shares, #xplat-siblings { overflow-x: auto; max-width: 100%; }
