:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #1d2330;
  --muted: #6b7280;
  --line: #e2e5ea;
  --accent: #c8102e;
  --accent-text: #ffffff;
  --accent-soft: #fbe8eb;
  --mine: #1d2330;
  --mine-text: #ffffff;
  --theirs: #eef0f3;
  --auto: #eef6ee;
  --auto-line: #bcdcbc;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --ok: #15803d;
  --note: #fff7d6;
  --note-line: #f0d77a;
  --online: #16a34a;
  --open-bg: #dcfce7;
  --open-text: #166534;
  --ai: #eef3ff;
  --ai-line: #b9cbf5;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --grid: #e8eaee;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 16px rgba(0, 0, 0, .05);
  color-scheme: light;
}
/* Tema scuro: segue il sistema (data-theme assente) oppure la scelta
   dell'utente salvata da theme.js (data-theme="light" | "dark") */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
  --bg: #14171c; --panel: #1c2027; --text: #e7e9ee; --muted: #9aa1ad; --line: #2d333d;
  --accent: #ef4a61; --accent-soft: #3a1f25; --mine: #e7e9ee; --mine-text: #14171c;
  --theirs: #262b34; --auto: #1f2c22; --auto-line: #2f5a37; --warn: #f5b454; --warn-soft: #3a2f18;
  --ok: #4ade80; --note: #3a3219; --note-line: #6b5a1e; --online: #4ade80;
  --open-bg: #173524; --open-text: #4ade80; --ai: #1d2740; --ai-line: #34508a;
  --series-1: #3987e5; --series-2: #d95926; --grid: #2a2f38; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14171c; --panel: #1c2027; --text: #e7e9ee; --muted: #9aa1ad; --line: #2d333d;
  --accent: #ef4a61; --accent-soft: #3a1f25; --mine: #e7e9ee; --mine-text: #14171c;
  --theirs: #262b34; --auto: #1f2c22; --auto-line: #2f5a37; --warn: #f5b454; --warn-soft: #3a2f18;
  --ok: #4ade80; --note: #3a3219; --note-line: #6b5a1e; --online: #4ade80;
  --open-bg: #173524; --open-text: #4ade80; --ai: #1d2740; --ai-line: #34508a;
  --series-1: #3987e5; --series-2: #d95926; --grid: #2a2f38; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
h1 { font-size: 1.35rem; margin: 0 0 .25rem; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }

button, .btn {
  font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--text);
  border-radius: 8px; padding: .45rem .8rem; cursor: pointer; text-decoration: none; display: inline-block;
}
button:hover, .btn:hover { border-color: var(--muted); }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.danger { color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
input, textarea, select {
  font: inherit; color: var(--text); background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; padding: .5rem .65rem; width: 100%;
}
input:focus, textarea:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type=checkbox], input[type=radio] { width: auto; margin: 0; }
.spacer { flex: 1; }
label { display: block; font-size: .85rem; color: var(--muted); margin: .6rem 0 .2rem; }
label.inline { display: flex; align-items: center; gap: .4rem; color: var(--text); font-size: .9rem; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; }
.center-wrap { max-width: 440px; margin: 8vh auto; padding: 0 16px; }
.error { color: var(--accent); font-size: .9rem; min-height: 1.2em; margin-top: .5rem; }
.badge { display: inline-block; font-size: .72rem; padding: .1rem .45rem; border-radius: 999px; background: var(--theirs); color: var(--muted); vertical-align: middle; }
.badge.open { background: var(--open-bg); color: var(--open-text); }
.badge.scheduled { background: var(--warn-soft); color: var(--warn); }
.badge.closed { background: var(--theirs); color: var(--muted); }
.badge.wait { background: var(--accent); color: var(--accent-text); }

/* ── Elenco stanze (home) ── */
.room-list { list-style: none; padding: 0; margin: 1rem 0 0; display: grid; gap: .6rem; }
.room-list a { display: block; padding: .8rem 1rem; border: 1px solid var(--line); border-radius: 10px; color: var(--text); text-decoration: none; }
.room-list a:hover { border-color: var(--accent); }

/* ── Chat utente ── */
.chat-page { display: flex; flex-direction: column; height: 100%; max-width: 760px; margin: 0 auto; background: var(--panel); border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
.chat-head { padding: .8rem 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.chat-head .title { font-weight: 600; }
.messages { flex: 1; overflow-y: auto; padding: 1rem 16px; display: flex; flex-direction: column; gap: .55rem; }
.msg { max-width: 82%; padding: .55rem .8rem; border-radius: 14px; background: var(--theirs); overflow-wrap: anywhere; }
.msg .meta { font-size: .72rem; color: var(--muted); margin-bottom: .15rem; }
.msg.mine { align-self: flex-end; background: var(--mine); color: var(--mine-text); border-bottom-right-radius: 4px; }
.msg.mine .meta { color: inherit; opacity: .7; }
.msg.theirs { align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.auto { background: var(--auto); border: 1px solid var(--auto-line); }
.msg ul { margin: .25rem 0; padding-left: 1.2rem; }
.msg code { font-family: ui-monospace, monospace; font-size: .9em; background: rgba(127, 127, 127, .18); padding: 0 .25rem; border-radius: 4px; }
.msg.mine a { color: inherit; }
.system-note { align-self: center; font-size: .8rem; color: var(--muted); text-align: center; padding: .3rem .8rem; }
.composer { border-top: 1px solid var(--line); padding: .7rem 16px; display: flex; gap: .5rem; align-items: flex-end; }
.composer textarea { resize: none; min-height: 42px; max-height: 160px; }
.composer-error { padding: 0 16px; }
.banner { padding: .6rem 16px; background: var(--warn-soft); color: var(--warn); font-size: .9rem; }

/* ── Console ── */
/* colonna: avvisi e barra prendono lo spazio che serve, la scheda aperta il resto (anche con un avviso in cima) */
.console { display: flex; flex-direction: column; height: 100%; }
.console > .view { flex: 1 1 auto; }
.topbar { min-width: 0; display: flex; align-items: center; gap: .75rem; padding: .6rem 16px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.topbar .brand { font-weight: 700; }
.tabs { display: flex; gap: .15rem; flex: 0 1 auto; min-width: 0; max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { border: none; background: none; padding: .45rem .6rem; white-space: nowrap; flex: none; border-radius: 8px; color: var(--muted); }
.tabs button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
/* con tutte le schede (amministratore generale) la barra resta su una riga anche a 1280 px */
@media (max-width: 1440px) { .presence-words { display: none; } }
.view { min-height: 0; overflow: hidden; }
.view.scroll { overflow-y: auto; padding: 1rem 16px; }

.chat-grid { display: grid; grid-template-columns: 250px 280px 1fr; height: 100%; min-height: 0; }
.col { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: var(--panel); }
.col:last-child { border-right: none; background: var(--bg); }
.col-head { padding: .7rem .9rem; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: .5rem; font-weight: 600; }
.col-body { overflow-y: auto; flex: 1; min-height: 0; }
.list-item { padding: .6rem .9rem; border-bottom: 1px solid var(--line); cursor: pointer; display: flex; gap: .55rem; align-items: flex-start; }
.list-item:hover { background: var(--theirs); }
.list-item.active { background: var(--accent-soft); }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item.blocked .name { text-decoration: line-through; color: var(--muted); }
.list-item .sub { font-size: .78rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.feed { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: .55rem; min-height: 0; }
.feed .msg { max-width: 88%; background: var(--panel); border: 1px solid var(--line); }
.feed .msg.user { align-self: flex-start; cursor: pointer; }
.feed .msg.user:hover { border-color: var(--accent); }
.feed .msg.operator { align-self: flex-end; background: var(--mine); color: var(--mine-text); border-color: var(--mine); }
.feed .msg.operator .meta { color: inherit; opacity: .75; }
.feed .msg.operator a { color: inherit; }
.feed .msg.auto { align-self: flex-end; background: var(--auto); border-color: var(--auto-line); }
.feed-head { padding: .6rem 1rem; border-bottom: 1px solid var(--line); background: var(--panel); display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.feed-head .grow { flex: 1; }

.reply { border-top: 1px solid var(--line); background: var(--panel); padding: .6rem 1rem; }
.reply-target { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; font-size: .88rem; margin-bottom: .45rem; }
.reply-target label.inline { margin: 0; }
.toolbar { display: flex; gap: .25rem; flex-wrap: wrap; margin-bottom: .4rem; }
.toolbar button { padding: .25rem .55rem; min-width: 2rem; }
.toolbar select { width: auto; padding: .25rem .4rem; }
.reply textarea { min-height: 70px; resize: vertical; }
.reply-actions { display: flex; justify-content: space-between; align-items: center; margin-top: .45rem; gap: .5rem; }
.preview { font-size: .85rem; border: 1px dashed var(--line); border-radius: 8px; padding: .4rem .6rem; margin-top: .4rem; }

table.data { width: 100%; border-collapse: collapse; background: var(--panel); }
table.data th, table.data td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; font-size: .9rem; }
table.data th { color: var(--muted); font-weight: 600; font-size: .8rem; }
table.data td.actions { white-space: nowrap; }
table.data td.actions button, table.data td.actions .btn { padding: .25rem .5rem; font-size: .82rem; margin: 0 .15rem .25rem 0; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 1rem; }
.section { max-width: 1100px; margin: 0 auto 1.25rem; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-top: .8rem; }
.linkbox { font-family: ui-monospace, monospace; font-size: .8rem; }
.table-wrap { overflow-x: auto; }

@media (max-width: 900px) {
  .chat-grid { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; overflow-y: auto; }
  .col { border-right: none; border-bottom: 1px solid var(--line); max-height: 220px; }
  .col:last-child { max-height: none; min-height: 480px; }
}

/* ── Presenza, coda, "sta scrivendo" ── */
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); opacity: .45; vertical-align: middle; }
.dot.on, .presence.online .dot { background: var(--online); opacity: 1; box-shadow: 0 0 0 3px rgba(22, 163, 74, .18); }
.presence { color: var(--muted); }
.presence.online { color: var(--text); }
.chat-head .presence { margin-top: .15rem; }
.pinned { padding: .55rem 16px; background: var(--accent-soft); border-bottom: 1px solid var(--line); font-size: .9rem; }
.pinned::before { content: "📌 "; }
.queue { padding: .45rem 16px; font-size: .85rem; color: var(--muted); border-bottom: 1px solid var(--line); background: var(--panel); }
.queue::before { content: "⏳ "; }
.typing { padding: .25rem 16px; font-size: .8rem; color: var(--muted); display: flex; align-items: center; gap: .2rem; }
.typing > span:not([id]) { width: 5px; height: 5px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing > span:nth-child(2) { animation-delay: .2s; }
.typing > span:nth-child(3) { animation-delay: .4s; margin-right: .3rem; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .typing > span:not([id]) { animation: none; } }
.typing-sub { font-style: italic; color: var(--ok) !important; }

/* ── Valutazione ── */
.rating-card { align-self: center; width: min(100%, 360px); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; background: var(--panel); text-align: center; margin: .5rem auto; }
.rating-card input { margin-top: .4rem; }
.rating-card .row { justify-content: center; margin-top: .5rem; }
.stars { display: flex; justify-content: center; gap: .2rem; margin: .4rem 0; }
.star { font-size: 1.6rem; line-height: 1; border: none; background: none; color: var(--line); padding: .1rem .2rem; }
.star.on, .star:hover { color: #f59e0b; }
.stars-static { color: #f59e0b; letter-spacing: 1px; }

/* ── Console: tag, note, conferme di lettura ── */
select.compact { width: auto; padding: .25rem .4rem; font-size: .82rem; }
.tags { display: flex; gap: .25rem; flex-wrap: wrap; margin-top: .2rem; }
.tag { font-size: .7rem; padding: .05rem .4rem; border-radius: 999px; background: var(--theirs); color: var(--muted); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.badge.timer { font-variant-numeric: tabular-nums; }
.feed .msg.note { align-self: flex-end; background: var(--note); border-color: var(--note-line); color: var(--text); }
.feed .msg.note .meta::before { content: "📝 "; }
.feed .system-note { background: var(--panel); border: 1px dashed var(--line); border-radius: 999px; }
.messages .system-note { background: var(--theirs); border-radius: 999px; }
.receipt { font-size: .7rem; opacity: .75; text-align: right; margin-top: .15rem; }
.person-bar { padding: .4rem 1rem; font-size: .8rem; color: var(--muted); border-bottom: 1px solid var(--line); background: var(--panel); display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }
.person-bar .sep { opacity: .5; }
.reply.note-mode { background: var(--note); }
.reply.note-mode textarea { border-color: var(--note-line); }

/* ── Monitor ── */
.monitor-head { margin: 0 0 .75rem; }
.grow-h { flex: 1; margin: 0; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: .75rem; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; box-shadow: var(--shadow); }
.kpi-label { font-size: .78rem; color: var(--muted); }
.kpi-value { font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; margin: .15rem 0; }
.kpi-note { font-size: .78rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kpi.alert { border-color: var(--accent); }
.kpi.alert .kpi-value { color: var(--accent); }
.monitor-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 1rem; }
.monitor-grid .card { min-width: 0; }
.legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .82rem; color: var(--muted); margin-bottom: .4rem; }
.legend-item { display: inline-flex; align-items: center; gap: .35rem; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: .3rem; vertical-align: middle; }
.swatch.s1, .bar.s1 { background: var(--series-1); fill: var(--series-1); }
.swatch.s2, .bar.s2 { background: var(--series-2); fill: var(--series-2); }
.chart svg { width: 100%; height: auto; display: block; }
.chart line.grid { stroke: var(--grid); stroke-width: 1; }
.chart line.axis { stroke: var(--muted); stroke-width: 1; opacity: .5; }
.chart text.tick { fill: var(--muted); font-size: 11px; }
.chart rect.hit { fill: transparent; }
.chart rect.hit:hover { fill: var(--text); fill-opacity: .05; }
.tooltip { position: fixed; z-index: 10; pointer-events: none; background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: .45rem .6rem; font-size: .8rem; box-shadow: 0 4px 16px rgba(0, 0, 0, .15); }
.tip-title { font-weight: 600; margin-bottom: .2rem; }
.rating-row, .violation-row { padding: .45rem 0; border-bottom: 1px solid var(--line); }
.rating-row:last-child, .violation-row:last-child { border-bottom: none; }
details summary { cursor: pointer; color: var(--muted); margin-top: .6rem; }

/* ── Dialog impostazioni ── */
dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--text); padding: 1.25rem; width: min(680px, calc(100vw - 32px)); max-height: calc(100vh - 32px); }
dialog::backdrop { background: rgba(0, 0, 0, .4); }

@media (max-width: 600px) {
  .monitor-grid { grid-template-columns: 1fr; }
}

/* ── Tema chiaro/scuro e assistente AI (v2) ── */
.theme-toggle { width: 2.1rem; height: 2.1rem; padding: 0; border-radius: 50%; font-size: 1rem; line-height: 1; display: inline-flex; align-items: center; justify-content: center; }
/* Angolo in alto a destra: logo (su fondo bianco, leggibile anche col tema scuro) e tema */
.corner { position: fixed; top: 10px; right: 16px; z-index: 20; display: flex; align-items: center; gap: .5rem; }
.corner .theme-toggle { box-shadow: var(--shadow); }
.lang-pick { width: auto; padding: .3rem .4rem; font-size: .8rem; font-weight: 600; border-radius: 8px; box-shadow: var(--shadow); }
/* logo: trasparente per default; sfondo bianco su scelta (sempre, o solo con il tema scuro) */
.brand-logo { display: block; height: 40px; width: auto; max-width: 150px; object-fit: contain; border-radius: 8px; }
.brand-logo.bg-white { background: #fff; padding: 4px 8px; box-shadow: var(--shadow); }
:root[data-theme="dark"] .brand-logo.bg-dark { background: #fff; padding: 4px 8px; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .brand-logo.bg-dark { background: #fff; padding: 4px 8px; }
}
/* nero solo con il tema chiaro (loghi bianchi) */
:root[data-theme="light"] .brand-logo.bg-light { background: #111; padding: 4px 8px; }
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .brand-logo.bg-light { background: #111; padding: 4px 8px; }
}
.topbar .brand-logo { height: 32px; max-width: 110px; }
.topbar .brand-logo.bg-white { padding: 3px 6px; box-shadow: none; border: 1px solid var(--line); }
/* barra della console su una riga: il nome dell'utente si accorcia (intero al passaggio del mouse) */
#whoami { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* schermi medi: il nome dell'utente resta nel suggerimento del pulsante Esci */
@media (max-width: 1440px) { #whoami { display: none; } }
.brand-logo.hidden { display: none; }
.update-banner { background: var(--warn-soft); color: var(--warn); padding: .5rem 16px; font-size: .85rem; border-bottom: 1px solid var(--line); }
.ai-diag { margin-top: .4rem; }
.ai-diag .error { margin: .2rem 0 0; }
.steps { margin: .3rem 0; padding-left: 1.2rem; }
#categoryForm { margin-top: 1rem; border-top: 1px solid var(--line); padding-top: .6rem; }
.cost-tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .6rem; margin: .4rem 0 .6rem; }
.cost-tile { border: 1px solid var(--line); border-radius: 8px; padding: .55rem .75rem; }
.cost-tile .label { font-size: .78rem; color: var(--muted); }
.cost-tile .value { font-size: 1.45rem; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; line-height: 1.25; }
.cost-tile .sub { font-size: .75rem; color: var(--muted); }
.cost-sim .compact-num { width: 6.5rem; }
@media (max-width: 600px) { .cost-tiles { grid-template-columns: 1fr; } }
.org-thumb { display: block; height: 22px; width: auto; max-width: 90px; object-fit: contain; margin-bottom: .2rem; }
.org-logo { margin-top: .8rem; padding-top: .4rem; border-top: 1px solid var(--line); }
.logo-preview { height: 48px; width: auto; max-width: 260px; object-fit: contain; padding: 4px 8px; border-radius: 8px; border: 1px dashed var(--line); }
.logo-preview.bg-white { background: #fff; }
:root[data-theme="dark"] .logo-preview.bg-dark { background: #fff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .logo-preview.bg-dark { background: #fff; } }
:root[data-theme="light"] .logo-preview.bg-light { background: #111; }
@media (prefers-color-scheme: light) { :root:not([data-theme="dark"]) .logo-preview.bg-light { background: #111; } }
/* spazio per l'angolo: l'intestazione della chat e i riquadri non ci finiscono sotto */
.chat-page .chat-head { padding-right: 270px; }
.center-wrap { padding-top: 64px; }
@media (max-width: 600px) {
  .corner { gap: .35rem; right: 10px; }
  .corner .brand-logo { height: 28px; max-width: 72px; }
  .chat-page .chat-head { padding-right: 178px; }
  /* solo la campanella: il testo resta per i lettori di schermo */
  .notify-btn .notify-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .notify-btn { padding: .3rem .5rem; flex: none; }
}
.privacy { margin-top: .9rem; font-size: .75rem; }
.msg.ai { background: var(--ai); border: 1px solid var(--ai-line); }
.msg.ai .meta::before, .feed .msg.ai .meta::before, .feed .msg.draft .meta::before { content: "✦ "; }
.feed .msg.ai { align-self: flex-end; background: var(--ai); border-color: var(--ai-line); color: var(--text); }
.feed .msg.draft { align-self: flex-end; background: var(--panel); border: 1px dashed var(--ai-line); color: var(--text); width: min(88%, 560px); }
.feed .msg.draft.done { opacity: .6; }
.draft-info { font-size: .75rem; color: var(--muted); margin-top: .35rem; }
.draft-actions { display: flex; gap: .35rem; flex-wrap: wrap; margin-top: .45rem; }
.draft-actions button { padding: .2rem .55rem; font-size: .8rem; }
.conf { font-size: .7rem; padding: .05rem .4rem; border-radius: 999px; background: var(--theirs); color: var(--muted); }
.conf.high { background: var(--open-bg); color: var(--open-text); }
.conf.low { background: var(--warn-soft); color: var(--warn); }
.conf.ext { background: var(--ai-line); color: var(--text); }

/* Scheda informazioni utente (passaggio del mouse) */
.info-card { position: fixed; z-index: 30; width: 320px; max-width: calc(100vw - 16px); background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 28px rgba(0, 0, 0, .18); padding: .75rem .9rem; font-size: .82rem; pointer-events: none; }
.info-card h3 { margin: 0 0 .1rem; font-size: .95rem; }
.info-card dl { display: grid; grid-template-columns: 1.4rem 1fr; gap: .3rem .4rem; margin: .5rem 0 0; }
.info-card dt { text-align: center; }
.info-card dd { margin: 0; overflow-wrap: anywhere; }
.info-card .sub { color: var(--muted); font-size: .75rem; }
.info-btn { padding: .05rem .45rem; font-size: .75rem; border-radius: 999px; }
.name[data-info], .msg.user .meta { cursor: help; }

/* Conoscenza AI */
.k-status { font-size: .72rem; padding: .05rem .45rem; border-radius: 999px; background: var(--theirs); color: var(--muted); white-space: nowrap; }
.k-status.pending { background: var(--warn-soft); color: var(--warn); }
.k-status.approved { background: var(--open-bg); color: var(--open-text); }
.ai-status { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.tab-count { display: inline-block; min-width: 1.2rem; padding: 0 .3rem; margin-left: .25rem; border-radius: 999px; background: var(--accent); color: var(--accent-text); font-size: .7rem; line-height: 1.2rem; text-align: center; }
textarea.inline-edit { min-height: 60px; font-size: .85rem; }

/* ── Richiesta via email (fuori orario / senza operatori) ── */
.offline-box { border-top: 1px solid var(--line); padding: .7rem 16px .8rem; background: var(--panel); max-height: 60%; overflow-y: auto; }
.offline-box .offline-title { margin: 0 0 .2rem; font-weight: 600; }
.offline-box p { margin: 0 0 .4rem; }
.offline-box label { margin-top: .4rem; }
.offline-box .consent { display: flex; gap: .4rem; align-items: flex-start; margin-top: .5rem; color: var(--muted); }
.offline-box .consent input { width: auto; margin-top: .15rem; }
.offline-box .row { margin-top: .5rem; }
.offline-switch { padding: .3rem 16px 0; margin-top: 0; }
.link-btn { background: none; border: 0; padding: .2rem 0; color: var(--accent); text-decoration: underline; cursor: pointer; font-size: .85rem; box-shadow: none; }

/* ── Chat dentro il widget di un sito (iframe) ── */
.embed .corner { display: none; }
.embed .chat-page { max-width: none; border: 0; }
.embed .chat-page .chat-head { padding-right: 16px; }
.embed #roomName { display: none; }
.embed .center-wrap { margin: 0 auto; padding: 16px; max-width: none; }
.embed .center-wrap .card { box-shadow: none; border: 0; padding: 0; }
.embed #joinTitle { font-size: 1.15rem; }

/* ── Console: impostazioni raggruppate, orario, widget ── */
.settings-group { border: 1px solid var(--line); border-radius: 8px; padding: .3rem .8rem .7rem; margin-top: .8rem; }
.settings-group > summary { cursor: pointer; font-weight: 600; padding: .3rem 0; }
.settings-group .checks { margin-top: .5rem; }
.hours-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .3rem 1rem; margin-top: .4rem; }
.hours-row { display: flex; align-items: center; gap: .5rem; margin: 0; }
.hours-row span { width: 6.5rem; flex: none; font-size: .85rem; }
.dim { opacity: .45; }
textarea.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .8rem; }
.smtp-secure { margin-top: 1.9rem; }
.pre-wrap { white-space: pre-wrap; max-width: 28rem; }
.nowrap { white-space: nowrap; }
.k-status.rejected { background: var(--warn-soft); color: var(--accent); }
@media (max-width: 700px) { .hours-grid { grid-template-columns: 1fr; } }

/* ── Assistente al lavoro (ricerca web in tempo reale) ── */
.ai-live { border-top: 1px dashed var(--ai-line); background: var(--ai); padding: .5rem 16px; max-height: 40%; overflow-y: auto; }
.ai-live-item + .ai-live-item { margin-top: .5rem; }
.ai-live-text { margin-top: .3rem; font-size: .9rem; opacity: .85; }
.spinner { display: inline-block; width: .8em; height: .8em; border: 2px solid var(--ai-line); border-top-color: var(--text); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -.1em; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

/* ── Avatar dello staff (foto o iniziali) ── */
.avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; flex: none; display: inline-flex; align-items: center; justify-content: center; vertical-align: middle; }
.avatar.initials { background: var(--ai-line); color: var(--text); font-size: .72rem; font-weight: 700; }
.avatar-lg { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; border: 1px solid var(--line); }
.avatar-btn { padding: 0; border: 0; background: none; border-radius: 50%; width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center; box-shadow: none; }
.avatar-btn .avatar { width: 32px; height: 32px; }
#whoami { cursor: pointer; }
.staff-head { display: flex; gap: .5rem; align-items: flex-start; margin-bottom: .2rem; }
.staff-head .meta { margin: 0; }
.staff-desc { font-size: .78rem; color: var(--muted); max-width: 32rem; }
.pw-form { margin-top: 1rem; padding-top: .6rem; border-top: 1px solid var(--line); }
#magicForm h1 { margin-top: 0; }
/* modulo utenti in modalità modifica: ben distinto dalla creazione */
#staffFormCard.editing { outline: 2px solid var(--accent); outline-offset: -2px; }
.edit-banner { background: var(--warn-soft); color: var(--warn); padding: .45rem .7rem; border-radius: 6px; font-size: .85rem; margin: .3rem 0 .6rem; }

/* Impostazioni generali: indice delle sezioni */
.subnav { display: flex; flex-wrap: wrap; gap: .4rem; margin: 0 0 .8rem; }
.subnav a { padding: .25rem .65rem; border: 1px solid var(--line); border-radius: 999px; font-size: .85rem; text-decoration: none; color: inherit; }
.subnav a:hover { background: var(--line); }
/* Organizzazioni di un utente */
.org-picks { border: 1px solid var(--line); border-radius: 8px; padding: .4rem .75rem .6rem; margin: .6rem 0; }
.org-picks legend { font-size: .85rem; padding: 0 .3rem; }
.org-checks { display: flex; flex-wrap: wrap; gap: .3rem 1.1rem; }

/* Traduzione automatica dei messaggi */
.translated-text { white-space: pre-wrap; }
.translation-note { font-size: .75rem; opacity: .75; margin-top: .25rem; }
.translation-note summary { cursor: pointer; }
.translation-note .link-btn { font-size: inherit; padding: 0; color: inherit; text-decoration: underline; }
.translation { margin-top: .3rem; padding-top: .3rem; border-top: 1px dashed currentColor; opacity: .85; }

/* Limiti di spesa AI */
.budget { border: 1px solid var(--line); border-radius: 8px; padding: .55rem .75rem; margin: .5rem 0; }
.budget.suspended { border-color: var(--danger, #c0392b); }
.budget-fields { flex-wrap: wrap; }
.budget-fields .grow { flex: 1 1 14rem; display: flex; align-items: center; gap: .3rem; }
.budget-fields .grow input { flex: 1; }
.budget-bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; margin: .35rem 0; }
.budget-bar span { display: block; height: 100%; background: var(--accent); }
.budget-bar span.warn { background: #e0a100; }
.budget-bar span.over { background: #c0392b; }
.budget-fields label { white-space: nowrap; display: flex; align-items: center; gap: .3rem; }
.budget-fields input[type="number"] { width: 6.5rem; }

/* Radar dell'umore */
.tag.mood-impatient { background: #fff4d6; color: #8a5a00; }
.tag.mood-upset { background: #ffe1e1; color: #a11; }
.list-item.upset { box-shadow: inset 3px 0 0 #e5484d; }
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 50; display: flex; flex-direction: column; gap: .5rem; max-width: min(420px, calc(100vw - 32px)); }
.toast { display: flex; align-items: center; gap: .6rem; background: var(--panel); color: var(--text); border: 1px solid var(--line); border-left: 4px solid #e5484d; border-radius: 10px; padding: .6rem .7rem; box-shadow: var(--shadow); font-size: .9rem; animation: toast-in .25s ease-out; }
.toast span { flex: 1; }
@keyframes toast-in { from { transform: translateY(12px); opacity: 0; } }

/* Foto in chat */
.attach-btn { flex: none; font-size: 1.15rem; padding: .35rem .55rem; }
.chat-photo-link { display: block; margin-top: .3rem; }
.chat-photo { display: block; max-width: min(260px, 100%); max-height: 260px; border-radius: 8px; object-fit: cover; background: rgba(0,0,0,.05); min-width: 60px; min-height: 40px; }
.chat-page.dropping .messages { outline: 3px dashed var(--accent); outline-offset: -8px; }

.tag.ok { background: #dcfce7; color: #166534; }

/* Vendite: dettagli dell'ordine sotto la riga */
.detail-row > td { background: var(--bg); }
.order-detail { display: grid; gap: .6rem; padding: .3rem 0; }
.order-detail .row { flex-wrap: wrap; }
.order-events { margin: 0; padding-left: 1.1rem; max-height: 9rem; overflow: auto; }
#shopKeys { gap: .5rem; flex-wrap: wrap; }
