/* Aspetto delle app SMAI (CTA, smai-push, poc-call-test): primario #1E73B6, grigi slate,
   Source Sans 3, sidebar a binario e header bianchi. Token e cornice copiati da
   poc_codec_streaming_testing_hardware (server/CallTest.Web/wwwroot/css/shell.css), che li prende da
   smai-push; qui senza Bootstrap, riportati alle classi di questa interfaccia. */

/* Source Sans 3, variabile 200-900, solo latino: Fontsource 5.3.1, licenza OFL 1.1 in fonts/OFL.txt */
@font-face {
  font-family: "Source Sans 3";
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
  src: url("fonts/source-sans-3-latin-wght-normal.woff2") format("woff2");
}

:root {
  color-scheme: light;
  --font: "Source Sans 3", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-subtle: #f8fafc;
  --surface-hover: #f1f5f9;
  --text: #334155;
  --text-strong: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --border-hover: #94a3b8;
  --accent: #1e73b6;
  --accent-soft: #e8f1f8;
  --accent-soft-strong: #d2e3f0;
  --accent-ink: #0c2e49;
  --accent-ink-soft: #15507f;
  --accent-fill: #1e73b6;
  --accent-fill-hover: #1a629b;
  --accent-fill-active: #15507f;
  --focus: #1e73b6;
  --danger: #b91c1c;
  --danger-strong: #ef4444;
  --danger-border: #fecaca;
  --danger-soft: #fee2e2;
  --success: #15803d;
  --success-dot: #22c55e;
  --success-soft: #dcfce7;
  --success-border: #bbf7d0;
  --warning: #c2410c;
  --warning-dot: #f59e0b;
  --warning-soft: #ffedd5;
  --warning-border: #fed7aa;
  --neutral-badge: #475569;
  --neutral-badge-soft: #f1f5f9;
  --shell-border: #e8e8e9;
  --shell-text: #434952;
  --shell-icon: #8a8d93;
  --shell-strong: #141b27;
  --field-shadow: 0 1px 2px 0 rgba(18, 18, 23, .05);
  --card-shadow: 0 1px 2px 0 rgba(0, 0, 0, .05);
  --overlay-shadow: 0 4px 6px -1px rgba(0, 0, 0, .1), 0 2px 4px -2px rgba(0, 0, 0, .1);
  --drawer-shadow: 0 20px 25px -5px rgba(0, 0, 0, .1), 0 8px 10px -6px rgba(0, 0, 0, .1);
  --backdrop: rgba(0, 0, 0, .4);
  --radius-sm: 6px;
  --radius-md: 8px;
  --sidebar-w: 72px;
  --header-h: 70px;
}

/* Il tema lo decide lo script in testa alla pagina (data-theme sulla radice). */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1120;
  --surface: #0f172a;
  --surface-subtle: #131d31;
  --surface-hover: #1e293b;
  --text: #e2e8f0;
  --text-strong: #f8fafc;
  --text-muted: #94a3b8;
  --border: #243045;
  --border-strong: #334155;
  --border-hover: #475569;
  --accent: #78abd3;
  --accent-soft: rgba(30, 115, 182, .18);
  --accent-soft-strong: rgba(30, 115, 182, .34);
  --accent-ink: #d2e3f0;
  --accent-ink-soft: #a5c7e2;
  --focus: #78abd3;
  --danger: #fca5a5;
  --danger-strong: #f87171;
  --danger-border: rgba(239, 68, 68, .4);
  --danger-soft: rgba(239, 68, 68, .16);
  --success: #4ade80;
  --success-soft: rgba(34, 197, 94, .16);
  --success-border: rgba(34, 197, 94, .35);
  --warning: #fdba74;
  --warning-soft: rgba(249, 115, 22, .16);
  --warning-border: rgba(249, 115, 22, .35);
  --neutral-badge: #cbd5e1;
  --neutral-badge-soft: #1e293b;
  --shell-border: #1e293b;
  --shell-text: #cbd5e1;
  --shell-icon: #64748b;
  --shell-strong: #f1f5f9;
  --field-shadow: none;
  --card-shadow: 0 1px 2px 0 rgba(0, 0, 0, .4);
  --overlay-shadow: 0 4px 6px -1px rgba(0, 0, 0, .5), 0 2px 4px -2px rgba(0, 0, 0, .5);
  --drawer-shadow: 0 20px 25px -5px rgba(0, 0, 0, .6), 0 8px 10px -6px rgba(0, 0, 0, .6);
  --backdrop: rgba(0, 0, 0, .6);
}

/* ── Base ── */
* { box-sizing: border-box; }
html { font-size: 16px; }
body { margin: 0; font: 400 1rem/1.5 var(--font); background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
h1, h2, h3 { color: var(--text-strong); font-weight: 600; margin: 0; }
h1 { font-size: 1.375rem; }
h2 { font-size: 1.125rem; }
h3 { font-size: 1rem; }
a { color: var(--accent); }
code, .mono { font-family: var(--mono); font-size: .85em; }
code { padding: .05rem .35rem; border-radius: 4px; background: var(--surface-hover); color: var(--text-strong); overflow-wrap: anywhere; }
.tenue { color: var(--text-muted); }
.piccolo-testo { font-size: .875rem; }
.spazio { flex: 1; }
.spaziato { margin-top: 1.25rem; }
.errore { color: var(--danger); }
.pieno { width: 100%; }
.senza-margine { margin-top: 0; margin-bottom: 0; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 1.25rem; height: 1.25rem; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }

/* ── Cornice: sidebar a binario e header, come la shell delle app SMAI ── */
.shell { display: flex; min-height: 100vh; }
.shell-sidebar { position: fixed; inset: 0 auto 0 0; z-index: 40; display: flex; flex-direction: column; width: var(--sidebar-w); border-right: 1px solid var(--shell-border); background: var(--surface); }
.shell-brand { display: flex; flex: none; align-items: center; justify-content: center; height: var(--header-h); box-shadow: inset 0 -1px 0 var(--shell-border); }
.shell-brand-mark { width: 40px; height: 40px; border-radius: var(--radius-md); }
.shell-nav { display: flex; flex-direction: column; align-items: center; gap: .5rem; padding: 1rem 0; }
.shell-nav-item { position: relative; display: flex; align-items: center; justify-content: center; width: 49px; height: 44px; border: 0; border-radius: var(--radius-md); background: transparent; color: var(--shell-text); cursor: pointer; transition: background-color .2s, color .2s; }
.shell-nav-item .icon { width: 22px; height: 22px; color: var(--shell-icon); }
.shell-nav-item:hover { background: var(--surface-hover); }
.shell-nav-item:hover .icon { color: var(--shell-text); }
.shell-nav-item.is-active { background: var(--accent-soft); }
.shell-nav-item.is-active .icon { color: var(--accent); }
.shell-nav-item.is-active::before { content: ""; position: absolute; top: 10px; bottom: 10px; left: -11px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.shell-nav-item:focus-visible, .shell-btn:focus-visible { outline: 1px solid var(--focus); outline-offset: 2px; }
.shell-main { display: flex; flex: 1; flex-direction: column; min-width: 0; margin-left: var(--sidebar-w); }
.shell-header { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: .75rem; height: var(--header-h); padding: 0 1.25rem 0 1rem; background: var(--surface); box-shadow: inset 0 -1px 0 var(--shell-border); }
.shell-page-icon { display: grid; flex: none; place-items: center; width: 40px; height: 40px; border: 1px solid var(--shell-border); border-radius: var(--radius-md); color: var(--shell-text); }
.shell-title { color: var(--shell-strong); font-size: 1.125rem; font-weight: 600; white-space: nowrap; }
.shell-product { color: var(--text-muted); font-size: .9rem; white-space: nowrap; }
.shell-product::before { content: "/"; margin-right: .75rem; color: var(--border-strong); }
.shell-btn { display: inline-flex; align-items: center; justify-content: center; width: 36px; min-height: 36px; padding: 0; border: 1px solid transparent; border-radius: 2rem; background: transparent; color: var(--shell-text); cursor: pointer; }
.shell-btn:hover { background: var(--surface-hover); }
.theme-toggle { margin-left: auto; }
.shell-user { display: flex; align-items: center; gap: .75rem; height: 40px; padding-left: 1rem; border-left: 1px solid var(--shell-border); }
.shell-user form { margin: 0; }
.avatar { display: grid; flex: none; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: var(--accent-soft-strong); color: var(--accent-ink-soft); font-size: .8rem; font-weight: 700; }
.user-text { display: grid; line-height: 1.25; }
.user-name { color: var(--shell-strong); font-size: .9rem; font-weight: 600; }
.user-role { display: flex; align-items: center; gap: .35rem; color: var(--text-muted); font-size: .68rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.user-role::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--success-dot); }
.shell-content { flex: 1; min-width: 0; padding: 1.25rem; }
.shell-footer { display: flex; flex-wrap: wrap; gap: .25rem .5rem; padding: .6rem 1.25rem; border-top: 1px solid var(--border); color: var(--text-muted); font-size: .8rem; }

/* Stato del collegamento in diretta: etichetta come p-tag */
.pillola { display: inline-flex; align-items: center; gap: .35rem; padding: .15rem .5rem; border-radius: var(--radius-sm); background: var(--neutral-badge-soft); color: var(--neutral-badge); font-size: .8rem; font-weight: 700; white-space: nowrap; }
.pillola::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pillola.ok { background: var(--success-soft); color: var(--success); }
.pillola.ko { background: var(--danger-soft); color: var(--danger); }

/* ── Pulsanti: pieno il primario, contornati gli altri, come PrimeNG Aura ── */
button, .bottone { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 36px; padding: .45rem .75rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: transparent; color: var(--text-muted); font: 500 .95rem var(--font); text-decoration: none; cursor: pointer; transition: background-color .15s, color .15s, border-color .15s; }
button:hover, .bottone:hover { background: var(--surface-subtle); color: var(--text); }
button:focus-visible, .bottone:focus-visible { outline: none; box-shadow: 0 0 0 .2rem rgba(30, 115, 182, .3); }
button.primario { border-color: var(--accent-fill); background: var(--accent-fill); color: #fff; }
button.primario:hover { border-color: var(--accent-fill-hover); background: var(--accent-fill-hover); color: #fff; }
button.pericolo { border-color: var(--danger-border); color: var(--danger-strong); }
button.pericolo:hover { background: var(--danger-soft); color: var(--danger); }
button.piccolo, .bottone.piccolo { min-height: 32px; padding: .3rem .625rem; font-size: .875rem; }

/* ── Campi: bordo slate, etichetta piccola in maiuscolo ── */
input, select { width: 100%; min-height: 36px; padding: .375rem .75rem; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font: 400 1rem var(--font); box-shadow: var(--field-shadow); }
input:hover, select:hover { border-color: var(--border-hover); }
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 .2rem rgba(30, 115, 182, .3); }
input[type="checkbox"] { width: 1rem; min-height: 0; height: 1rem; padding: 0; accent-color: var(--accent-fill); box-shadow: none; }
label { display: block; color: var(--text-muted); font-size: .75rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
label > input, label > select { margin-top: .3rem; letter-spacing: normal; text-transform: none; }

/* ── Riquadri, come .card della CTA: bordo sottile, ombra appena visibile, testata grigio chiaro ── */
.scheda { margin-bottom: 1rem; padding: 1rem; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); box-shadow: var(--card-shadow); }
.scheda > h3:first-child { margin: -1rem -1rem 1rem; padding: .55rem 1rem; border-bottom: 1px solid var(--border); border-radius: calc(var(--radius-md) - 1px) calc(var(--radius-md) - 1px) 0 0; background: var(--surface-subtle); color: var(--text-strong); font-size: 1rem; font-weight: 600; }

/* ── Disposizione della pagina degli orologi ── */
.layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.laterale { position: sticky; top: calc(var(--header-h) + 1.25rem); }
.laterale .scheda { margin-bottom: 1rem; }
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .laterale { position: static; }
}
.colonna { display: flex; flex-direction: column; }
.griglia-due { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 1rem; }
@media (max-width: 1200px) { .griglia-due { grid-template-columns: 1fr; } }
.azioni { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
/* Riga di conferma di un modulo: pulsanti a destra, staccati dall'ultimo campo come i campi fra loro
   e un po' di più (la conferma chiude il modulo, non è un altro campo). */
.azioni.conferma { justify-content: flex-end; margin-top: 1.25rem; }
.in-linea { display: flex; align-items: center; gap: .5rem; }
.in-linea input:not([type="checkbox"]) { flex: 1; }
.bottoni { display: flex; flex-wrap: wrap; gap: .4rem; }

/* Elenco degli orologi, come le voci della sidebar */
.orologio { display: block; width: 100%; margin-bottom: .5rem; padding: .6rem .75rem; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); color: var(--text); text-align: left; }
.orologio:hover { border-color: var(--border-hover); background: var(--surface-subtle); }
.orologio.selezionato { border-color: var(--accent-soft-strong); background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.orologio .riga { display: flex; justify-content: space-between; gap: .5rem; }
.orologio strong { color: var(--text-strong); font-weight: 600; }
.punto { display: inline-block; width: 8px; height: 8px; margin-right: .4rem; border-radius: 50%; background: var(--border-hover); vertical-align: middle; }
.punto.on { background: var(--success-dot); }
.rifiutato { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .5rem 0; border-bottom: 1px solid var(--border); }
.rifiutato:last-child { border-bottom: 0; }

/* Testata dell'orologio selezionato */
.testata-orologio { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; }
.testata-orologio h1 { font-size: 1.375rem; }

/* Schede, come nav-tabs */
.schede { display: flex; gap: .25rem; margin-bottom: 1rem; border-bottom: 1px solid var(--border); }
.schede button { min-height: 40px; margin-bottom: -1px; border: 1px solid transparent; border-radius: var(--radius-sm) var(--radius-sm) 0 0; background: transparent; color: var(--text-muted); font-weight: 600; }
.schede button:hover { background: transparent; color: var(--text); }
.schede button.attiva { border-color: var(--border) var(--border) var(--surface); background: var(--surface); color: var(--accent); }

#mappa { height: 440px; border-radius: var(--radius-sm); }

.voce { padding: .4rem 0; border-bottom: 1px solid var(--border); }
.voce:last-child { border-bottom: 0; }
.etichetta-allarme { color: var(--danger-strong); font-weight: 700; }

/* ── Tabella del traffico, come il datatable della CTA: intestazione azzurra in maiuscolo, righe alterne ── */
table.traffico { width: 100%; margin-top: .75rem; border: 1px solid var(--border); border-collapse: separate; border-spacing: 0; border-radius: var(--radius-md); overflow: hidden; table-layout: fixed; font-size: .95rem; }
table.traffico th { padding: .5rem .75rem; border-bottom: 1px solid var(--accent-soft-strong); background: var(--accent-soft); color: var(--accent-ink); font-size: .8rem; font-weight: 600; letter-spacing: .03em; text-align: left; text-transform: uppercase; }
table.traffico th:nth-child(1) { width: 160px; }
table.traffico th:nth-child(2) { width: 90px; }
table.traffico th:nth-child(3) { width: 120px; }
table.traffico td { padding: .4rem .75rem; border-bottom: 1px solid var(--border); vertical-align: top; }
table.traffico tbody tr:last-child td { border-bottom: 0; }
table.traffico tr.riga { cursor: pointer; }
table.traffico tr.riga:hover td { background: var(--surface-hover); }
table.traffico td.testo { font-family: var(--mono); font-size: .8rem; word-break: break-all; color: var(--text-strong); }
tr.allarme td { background: var(--danger-soft) !important; }
.dir { display: inline-block; padding: .1rem .4rem; border-radius: var(--radius-sm); font-size: .75rem; font-weight: 700; }
.dir-in { background: var(--success-soft); color: var(--success); }
.dir-out { background: var(--accent-soft); color: var(--accent-ink-soft); }
.dir-scarto, .dir-rifiutato { background: var(--warning-soft); color: var(--warning); }
.nota { display: block; color: var(--warning); font-family: var(--font); font-size: .8rem; }
pre.dettaglio { margin: 0; padding: .6rem .75rem; border-radius: var(--radius-sm); background: var(--surface-hover); color: var(--text-strong); font: .8rem/1.45 var(--mono); white-space: pre-wrap; word-break: break-all; }

/* Parola di stato: 32 caselle, accese in primario (stato) o rosso (allarmi) */
.bit { display: grid; grid-template-columns: repeat(16, 1fr); gap: 2px; max-width: 560px; margin: .5rem 0; }
.bit div { padding: 3px 0; border-radius: 3px; background: var(--surface-hover); color: var(--text-muted); font: 10px var(--mono); text-align: center; }
.bit div.acceso { background: var(--accent-fill); color: #fff; }
.bit div.acceso.alto { background: var(--danger-strong); }

/* Coda dei comandi, con lo stato come p-tag */
.coda-riga { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: .5rem; padding: .45rem 0; border-bottom: 1px solid var(--border); }
.coda-riga:last-child { border-bottom: 0; }
.stato-comando { padding: .1rem .4rem; border-radius: var(--radius-sm); font-size: .75rem; font-weight: 700; white-space: nowrap; }
.stato-confermato { background: var(--success-soft); color: var(--success); }
.stato-inviato { background: var(--accent-soft); color: var(--accent-ink-soft); }
.stato-in_attesa { background: var(--neutral-badge-soft); color: var(--neutral-badge); }
.stato-senza_risposta, .stato-errore { background: var(--warning-soft); color: var(--warning); }
.stato-annullato { background: var(--neutral-badge-soft); color: var(--text-muted); text-decoration: line-through; }

/* Profilo di configurazione */
.profilo { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem 1rem; }
.profilo .largo { grid-column: 1 / -1; }

/* ── Finestre ── */
dialog { width: calc(100% - 32px); max-width: 640px; padding: 0; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); color: var(--text); box-shadow: var(--drawer-shadow); }
dialog::backdrop { background: var(--backdrop); }
.dialogo { display: flex; flex-direction: column; gap: .75rem; padding: 1.25rem; }
.dialogo label { margin-top: .5rem; }
.passo { padding-top: .75rem; border-top: 1px solid var(--border); }
.passo h3 { margin-bottom: .25rem; color: var(--text-strong); }
.passo p { margin: .25rem 0; }
.nota-passo { padding: .5rem .75rem; border-radius: var(--radius-sm); background: var(--accent-soft); color: var(--accent-ink-soft); font-size: .875rem; }
.registrato { padding: .5rem .75rem; border-radius: var(--radius-sm); background: var(--success-soft); color: var(--success); font-weight: 600; }
.spinto { margin-left: auto; }
.sms { display: flex; align-items: center; gap: .5rem; margin: .4rem 0 .1rem; }
.sms code { flex: 1; padding: .4rem .6rem; font-size: .875rem; word-break: break-all; }
.spunta { display: flex; align-items: center; gap: .4rem; color: var(--text); font-size: .9rem; font-weight: 400; letter-spacing: normal; text-transform: none; white-space: nowrap; }

/* ── Pagina di accesso ── */
.pagina-accesso .shell-main { margin-left: 0; }
.accesso { display: flex; align-items: flex-start; justify-content: center; padding-top: 4rem; }
.accesso form { display: flex; flex-direction: column; gap: 1rem; width: 100%; max-width: 380px; }

/* Leaflet nel tema scuro: la mappa resta chiara, i controlli si adeguano */
:root[data-theme="dark"] .leaflet-bar a { background: var(--surface); color: var(--text); border-color: var(--border); }
:root[data-theme="dark"] .leaflet-popup-content-wrapper, :root[data-theme="dark"] .leaflet-popup-tip { background: var(--surface); color: var(--text); }

/* Sotto i 768 px la sidebar sparisce: c'è una sola sezione */
@media (max-width: 767px) {
  .shell-sidebar { display: none; }
  .shell-main { margin-left: 0; }
  .shell-page-icon, .shell-product, .user-text { display: none; }
  .shell-header { gap: .5rem; padding: 0 .75rem; }
  .shell-content { padding: 1rem .75rem; }
  .profilo { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; }
}

/* ── Orologi virtuali ── */
.filtri { display: flex; gap: .5rem; margin-bottom: .75rem; }
.filtri select { width: auto; }
#elenco-orologi { max-height: calc(100vh - 360px); min-height: 120px; overflow-y: auto; margin-bottom: .75rem; padding-right: 2px; }
.tag { display: inline-block; margin-left: .25rem; padding: 0 .35rem; border-radius: 4px; font-size: .7rem; font-weight: 700; letter-spacing: .02em; vertical-align: middle; }
.tag-virtuale { background: var(--warning-soft); color: var(--warning); }
.pillola.attesa { background: var(--warning-soft); color: var(--warning); }
.griglia-virtuali { display: grid; grid-template-columns: minmax(320px, 1fr) minmax(0, 2fr); gap: 1rem; align-items: start; }
@media (max-width: 1100px) { .griglia-virtuali { grid-template-columns: 1fr; } }
.spaziato-piccolo { margin-top: .75rem; }
.simulato { padding: .75rem 0; border-bottom: 1px solid var(--border); }
.simulato:first-child { padding-top: 0; }
.simulato:last-child { border-bottom: 0; padding-bottom: 0; }
.riga-simulato { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .25rem; }
.bottoni.eventi { margin-top: .5rem; }
pre.registro { margin-top: .5rem; max-height: 240px; overflow: auto; }
