:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #16181d;
  --muted: #646b78;
  --border: #e1e4ea;
  --accent: #e5352b;
  --accent-ink: #ffffff;
  --accent-2: #2f6fde;
  --ok: #138a4a;
  --ok-bg: #e3f5ea;
  --bad: #c62828;
  --bad-bg: #fdecec;
  --idle: #2f6fde;
  --idle-bg: #e8f0fd;
  --warn-bg: #fff6e0;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --surface: #171a21; --surface-2: #1f232c; --text: #e8eaee; --muted: #9aa2b1; --border: #2a2f3a;
    --ok: #4cc685; --ok-bg: #12301f; --bad: #ff6b6b; --bad-bg: #3a1717; --idle: #6c9cff; --idle-bg: #172340; --warn-bg: #352a10;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14.5px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
html.modal-open { overflow: hidden; }
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; margin: 0; line-height: 1.25; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 10px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.muted { color: var(--muted); }
.small, small { font-size: 12.5px; }
td small, .cell-cam small { display: block; color: var(--muted); }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 13px; }
.ok { color: var(--ok); } .bad { color: var(--bad); }
.nowrap { white-space: nowrap; }
.ellipsis { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grow { flex: 1; }
.mt { margin-top: 20px; }
.boot { padding: 40px; color: var(--muted); }

/* Struttura */
.shell { display: grid; grid-template-columns: 228px 1fr; min-height: 100vh; }
.topbar { display: none; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 2px; padding: 16px 12px; background: var(--surface); border-right: 1px solid var(--border); overflow-y: auto; }
.brand { font-weight: 750; font-size: 17px; letter-spacing: -.01em; }
.brand-side { padding: 6px 10px 18px; }
.brand-side::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); margin-right: 8px; box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 25%, transparent); }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text); font-weight: 500; }
.nav-item:hover { background: var(--surface-2); text-decoration: none; }
.nav-item.is-active { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); }
.nav-icon { width: 18px; text-align: center; opacity: .8; }
.nav-count { margin-left: auto; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--bad); color: #fff; font-size: 12px; text-align: center; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 6px; padding: 12px 10px 0; border-top: 1px solid var(--border); }
.content { min-width: 0; padding: 28px clamp(16px, 3vw, 40px) 60px; }
.page { max-width: 1240px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head h1 .muted { font-weight: 400; font-size: 18px; }
.head-status { display: flex; align-items: center; gap: 10px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .topbar { display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 20; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); }
  .sidebar { position: fixed; z-index: 30; top: 0; left: 0; width: 260px; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgba(0, 0, 0, .25); }
  .nav-open .sidebar { transform: none; }
  .content { padding: 18px 16px 50px; }
}

/* Elementi */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.card-head h2 { margin: 0; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row-gap { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 18px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; text-decoration: none; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-danger { color: var(--bad); }
.btn-small { padding: 5px 10px; font-size: 13px; }
.icon-btn { width: 32px; height: 32px; display: inline-grid; place-items: center; border: 0; border-radius: 8px; background: transparent; color: var(--text); cursor: pointer; font-size: 16px; }
.icon-btn:hover { background: var(--surface-2); }
:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }

input, select, textarea { width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent-2); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-2) 20%, transparent); }
input[type=checkbox], input[type=radio], input[type=range], input[type=color] { width: auto; padding: 0; box-shadow: none; }
input[type=color] { width: 40px; height: 32px; border: 1px solid var(--border); }
input:disabled, select:disabled, textarea:disabled { opacity: .6; }
textarea { resize: vertical; }
.search { max-width: 360px; }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field-label { font-weight: 600; font-size: 13px; }
.field-hint { color: var(--muted); font-size: 12.5px; }
.field-error { color: var(--bad); font-size: 13px; margin: 0; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 18px; }
.form-grid .wide { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }
.form-foot { display: flex; gap: 10px; align-items: center; padding-top: 16px; margin-top: 8px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.copy-row { display: flex; gap: 8px; align-items: center; }
.copy-row input { flex: 1; min-width: 0; }
.prefix-input { display: flex; align-items: center; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.prefix-input span { padding: 0 2px 0 10px; color: var(--muted); }
.prefix-input input { border: 0; padding-left: 2px; }
.prefix-input:focus-within { border-color: var(--accent-2); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-2) 20%, transparent); }
.prefix-input input:focus { box-shadow: none; }
label.inline { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
label.inline input { width: auto; }
.inline-check { display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px 14px; padding: 10px; border: 1px solid var(--border); border-radius: 8px; max-height: 220px; overflow: auto; }

.toggle { display: flex; align-items: flex-start; gap: 12px; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle-track { flex: none; width: 38px; height: 22px; margin-top: 1px; border-radius: 11px; background: var(--border); position: relative; transition: background .15s; }
.toggle-thumb { position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0, 0, 0, .3); }
.toggle input:checked + .toggle-track { background: var(--ok); }
.toggle input:checked + .toggle-track .toggle-thumb { transform: translateX(16px); }
.toggle input:focus-visible + .toggle-track { outline: 2px solid var(--accent-2); outline-offset: 2px; }
.toggle-text { display: flex; flex-direction: column; }
.toggle-text span { font-weight: 550; }
.toggle-text small { color: var(--muted); }
.toggle.is-disabled { opacity: .55; cursor: default; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin: -4px 0 18px; overflow-x: auto; }
.tabs button { padding: 9px 14px; border: 0; border-bottom: 2px solid transparent; background: none; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.tabs button.is-on { color: var(--text); border-bottom-color: var(--accent); }
.page > .tabs { margin: 0; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; flex-wrap: wrap; }
.seg button { padding: 6px 12px; border: 0; background: var(--surface); color: var(--text); font: inherit; font-size: 13px; cursor: pointer; border-right: 1px solid var(--border); }
.seg button:last-child { border-right: 0; }
.seg button.is-on { background: var(--text); color: var(--surface); }
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; padding: 12px 14px; }
.filters select { width: auto; min-width: 200px; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 20px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.badge i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-bad { background: var(--bad-bg); color: var(--bad); }
.badge-idle { background: var(--idle-bg); color: var(--idle); }
.badge-muted { background: var(--surface-2); color: var(--muted); }
.badge-ok i { animation: pulse 2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.notice { padding: 10px 14px; border-radius: 8px; background: var(--warn-bg); margin: 0; }
.notice-bad { background: var(--bad-bg); }
.error-box { padding: 14px; border-radius: 8px; background: var(--bad-bg); color: var(--bad); }
.empty { display: flex; flex-direction: column; gap: 6px; padding: 40px 20px; text-align: center; border: 1px dashed var(--border); border-radius: var(--radius); color: var(--muted); }
.empty strong { color: var(--text); font-size: 16px; }
.loading { display: grid; place-items: center; padding: 60px; }
.loading span { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Tabelle */
.table-wrap { overflow-x: auto; }
.table-wrap.card { padding: 0; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { text-align: right; white-space: nowrap; }
.table tr.is-dim td { opacity: .55; }
.cell-cam { display: flex; align-items: center; gap: 10px; color: var(--text); }
.mini-thumb { flex: none; width: 64px; height: 36px; border-radius: 5px; background: var(--surface-2) center / cover; }
.thumb { width: 80px; height: 30px; object-fit: contain; border-radius: 4px; background: var(--surface-2); }
.thumb-video { display: inline-grid; place-items: center; width: 80px; height: 30px; border-radius: 4px; background: var(--surface-2); color: var(--muted); }

/* Cruscotto */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.kpi { display: flex; flex-direction: column; gap: 4px; padding: 16px 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.kpi span { color: var(--muted); font-size: 13px; }
.kpi strong { font-size: 28px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi strong small { font-size: 16px; color: var(--muted); font-weight: 500; }
.kpi > small { color: var(--muted); }
.kpi-bad strong { color: var(--bad); }
.cam-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.cam-card { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; color: var(--text); box-shadow: var(--shadow); transition: transform .12s, box-shadow .12s; }
.cam-card:hover { text-decoration: none; transform: translateY(-1px); box-shadow: 0 4px 14px rgba(0, 0, 0, .1); }
.cam-thumb { position: relative; aspect-ratio: 16 / 9; background: #111 center / cover; display: grid; place-items: center; color: #777; font-size: 12px; }
.cam-viewers { position: absolute; right: 8px; top: 8px; padding: 2px 8px; border-radius: 4px; background: rgba(0, 0, 0, .65); color: #fff; font-size: 12px; }
.cam-meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 12px 2px; }
.cam-meta strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cam-sub { padding: 0 12px 10px; }
.system { text-align: center; }

/* Editor camera */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 18px; align-items: start; }
.editor-side { display: flex; flex-direction: column; gap: 18px; position: sticky; top: 18px; }
.editor-side .card { display: flex; flex-direction: column; gap: 12px; }
.editor-side h3 { margin: 0; }
@media (max-width: 1100px) { .editor { grid-template-columns: 1fr; } .editor-side { position: static; } }
.preview { position: relative; aspect-ratio: 16 / 9; border-radius: 8px; overflow: hidden; background: #000; }
.preview iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.snap { width: 100%; border-radius: 6px; }
.test-result { padding: 12px 14px; border-radius: 8px; display: flex; flex-direction: column; gap: 8px; }
.test-result.ok { background: var(--ok-bg); color: var(--ok); }
.test-result.bad { background: var(--bad-bg); color: var(--bad); }
.test-result img { max-width: 360px; width: 100%; border-radius: 6px; }
.test-result ul { margin: 0; padding-left: 18px; color: var(--text); }

.upload { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.upload-preview { width: 160px; height: 90px; object-fit: contain; border-radius: 6px; background: repeating-conic-gradient(var(--surface-2) 0 25%, var(--surface) 0 50%) 0 0 / 16px 16px; border: 1px solid var(--border); }
.upload-empty { display: grid; place-items: center; color: var(--muted); font-size: 12px; }
.upload-actions { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }

.pos-picker { display: grid; grid-template-columns: repeat(3, 38px); grid-template-rows: repeat(3, 26px); gap: 4px; padding: 6px; border: 1px solid var(--border); border-radius: 8px; width: max-content; background: #1b1e25; }
.pos-picker button { border: 1px solid #3a3f4b; border-radius: 4px; background: #262a33; color: #aab; cursor: pointer; font-size: 13px; }
.pos-picker button.is-on { background: var(--accent); border-color: var(--accent); color: #fff; }

.day-picker { display: inline-flex; gap: 3px; }
.day-picker button { width: 30px; height: 30px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; }
.day-picker button.is-on { background: var(--text); color: var(--surface); border-color: var(--text); }
.schedule { display: flex; flex-direction: column; gap: 10px; }
.schedule-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 8px; border: 1px solid var(--border); border-radius: 8px; }
.schedule-row input[type=time] { width: auto; }

/* Sponsor */
.sponsor { display: flex; flex-direction: column; gap: 12px; }
.sponsor-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.sponsor-head h2 { margin: 0 0 2px; display: flex; gap: 8px; align-items: center; }

/* Grafici */
.chart { position: relative; padding-top: 4px; }
.chart svg { width: 100%; height: calc(100% - 24px); display: block; overflow: visible; }
.chart rect:hover { opacity: .75; }
.chart-grid { stroke: var(--border); stroke-width: .3; vector-effect: non-scaling-stroke; }
.chart-labels { display: flex; height: 20px; margin-top: 4px; }
.chart-labels span { font-size: 11px; color: var(--muted); text-align: center; white-space: nowrap; overflow: visible; }
.chart-max { position: absolute; top: 0; left: 0; font-size: 11px; color: var(--muted); background: var(--surface); padding-right: 4px; }
.chart-empty { padding: 40px; text-align: center; color: var(--muted); }
.bars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.bars li { display: grid; grid-template-columns: 130px 1fr 60px; gap: 10px; align-items: center; font-size: 13.5px; }
.bars b { text-align: right; font-variant-numeric: tabular-nums; }
.bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent-2); border-radius: 4px; }

/* Modali e notifiche */
.modal-back { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; background: rgba(10, 12, 16, .55); }
.modal { width: min(560px, 100%); max-height: calc(100vh - 40px); display: flex; flex-direction: column; background: var(--surface); border-radius: 12px; box-shadow: 0 20px 60px rgba(0, 0, 0, .35); }
.modal-wide { width: min(820px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px 10px; }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-body { padding: 8px 18px 18px; overflow-y: auto; }
.modal-foot { display: flex; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); }
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 60; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 36px)); }
.toast { padding: 11px 16px; border-radius: 8px; background: var(--text); color: var(--surface); box-shadow: 0 6px 20px rgba(0, 0, 0, .25); animation: in .2s; }
.toast-error { background: var(--bad); color: #fff; }
@keyframes in { from { transform: translateY(8px); opacity: 0; } }

/* Accesso */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login { width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; padding: 28px; }
.login h1 { font-size: 22px; }

/* Report stampabile */
.report { max-width: 900px; margin: 0 auto; padding: 30px 24px 60px; display: flex; flex-direction: column; gap: 22px; }
.report-tools { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.report-head h1 { font-size: 30px; }
.report-head p { margin: 2px 0; }
.report section h2 { margin-bottom: 8px; }
@media print {
  .no-print { display: none !important; }
  :root { --bg: #fff; --surface: #fff; --text: #000; --muted: #555; --border: #ccc; --shadow: none; color-scheme: light; }
  .report { padding: 0; }
  .kpi, .card { break-inside: avoid; }
  .chart rect { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}

/* Richieste */
.lead { display: flex; flex-direction: column; gap: 10px; }
.lead-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.lead-msg { margin: 0; padding: 10px 12px; border-radius: 8px; background: var(--surface-2); white-space: pre-wrap; }
