:root {
  --brand: #e5484d;
  --bg: #0b0d10;
  --surface: #14171c;
  --surface-2: #1b1f25;
  --line: #262b33;
  --text: #eceef1;
  --muted: #8d949e;
  --ok: #3fb68b;
  --warn: #f0a020;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100dvh;
  padding-bottom: calc(24px + var(--safe-bottom));
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }

/* header */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: rgba(11, 13, 16, .88);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 17px; letter-spacing: -.01em; flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.live { background: var(--ok); box-shadow: 0 0 0 3px rgba(63, 182, 139, .18); }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); display: grid; place-items: center; padding: 0;
}
.icon-btn svg { width: 20px; height: 20px; }
.chip-mute {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 10px;
  border-radius: 99px; background: rgba(240, 160, 32, .14); color: var(--warn);
  border: 1px solid rgba(240, 160, 32, .35); font-size: 13px; font-weight: 600;
}
.chip-mute svg { width: 15px; height: 15px; }

main { max-width: 760px; margin: 0 auto; padding: 14px 14px 0; }

/* banner */
.banner {
  display: flex; gap: 12px; align-items: center;
  padding: 12px 14px; margin-bottom: 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line);
}
.banner p { margin: 0; flex: 1; font-size: 14px; color: var(--muted); }
.banner strong { color: var(--text); display: block; font-size: 14px; }
.btn {
  height: 40px; padding: 0 16px; border-radius: 11px; border: 1px solid var(--line);
  background: var(--surface-2); font-weight: 600; white-space: nowrap;
}
.btn.primary { background: var(--brand); border-color: transparent; color: #fff; }
.btn.block { width: 100%; height: 48px; }
.btn:disabled { opacity: .5; }

/* player */
.player { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 18px; }
.stage { position: relative; aspect-ratio: 16 / 9; background: #000; }
.stage video, .stage img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.stage .state {
  position: absolute; left: 10px; top: 10px; display: inline-flex; align-items: center; gap: 7px;
  padding: 5px 10px; border-radius: 99px; background: rgba(0, 0, 0, .65); font-size: 12px; font-weight: 600;
}
.spinner { width: 12px; height: 12px; border: 2px solid rgba(255,255,255,.25); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.stage .empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 20px; }
.meta { padding: 12px 14px 14px; display: flex; gap: 12px; align-items: flex-start; }
.meta .txt { flex: 1; min-width: 0; }
.meta h2 { margin: 0 0 2px; font-size: 17px; letter-spacing: -.01em; }
.meta .sub { color: var(--muted); font-size: 14px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; flex: none; }
.seg button { border: 0; background: transparent; padding: 7px 11px; font-size: 13px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--surface-2); color: var(--text); }

/* filtri */
.filters { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 8px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filter {
  flex: none; height: 34px; padding: 0 14px; border-radius: 99px; border: 1px solid var(--line);
  background: transparent; color: var(--muted); font-size: 14px; font-weight: 500;
}
.filter.on { background: var(--text); color: var(--bg); border-color: var(--text); }

/* lista */
.day { margin: 18px 4px 8px; font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.list { display: flex; flex-direction: column; gap: 8px; }
.item {
  display: flex; gap: 12px; align-items: center; width: 100%; text-align: left;
  padding: 8px; border-radius: 12px; border: 1px solid transparent; background: var(--surface);
}
.item.sel { border-color: var(--brand); }
.thumb { width: 112px; aspect-ratio: 16 / 9; border-radius: 8px; background: #000 center / cover no-repeat; flex: none; position: relative; }
.thumb .badge { position: absolute; right: 5px; bottom: 5px; padding: 1px 6px; border-radius: 6px; background: rgba(0,0,0,.7); font-size: 11px; font-weight: 600; }
.item .txt { flex: 1; min-width: 0; }
.item .t1 { font-weight: 600; display: flex; align-items: center; gap: 7px; }
.item .t2 { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cat { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.cat-intrusione { background: #e5484d; } .cat-linea { background: #f76b15; } .cat-movimento { background: #3e9bf5; }
.cat-incendio { background: #ff4d00; box-shadow: 0 0 0 3px rgba(255, 77, 0, .25); } .cat-temperatura { background: #f0a020; } .cat-altro { background: #8d949e; }
.more { margin: 16px 0 0; }
.none { text-align: center; color: var(--muted); padding: 40px 20px; }

/* impostazioni */
.page-title { display: flex; align-items: center; gap: 10px; margin: 4px 0 14px; }
.page-title h1 { margin: 0; font-size: 22px; letter-spacing: -.02em; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 14px; overflow: hidden; }
.card h3 { margin: 0; padding: 14px 16px 4px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.card .hint { padding: 0 16px 12px; color: var(--muted); font-size: 13px; margin: 0; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line); min-height: 52px; }
.card h3 + .row, .card .hint + .row { border-top: 0; }
.row .lbl { flex: 1; min-width: 0; }
.row .lbl small { display: block; color: var(--muted); font-size: 13px; }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; border-radius: 99px; background: #3a404a; transition: .2s; }
.switch span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: .2s; }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:disabled + span { opacity: .55; }
.mute-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; padding: 4px 16px 16px; }
input[type=time] { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }

/* login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login form { width: 100%; max-width: 360px; }
.login h1 { font-size: 26px; margin: 0 0 6px; letter-spacing: -.02em; }
.login p { color: var(--muted); margin: 0 0 24px; }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%; height: 50px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); font-size: 16px;
}
.field input:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.err { color: #ff6b6b; font-size: 14px; min-height: 20px; margin: 4px 0 10px; }
.logo { width: 56px; height: 56px; border-radius: 16px; margin-bottom: 18px; }

#toast {
  position: fixed; left: 50%; bottom: calc(20px + var(--safe-bottom)); transform: translateX(-50%) translateY(20px);
  background: #2a2f37; color: var(--text); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  opacity: 0; transition: .25s; pointer-events: none; max-width: 90vw; z-index: 50;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
@media (min-width: 700px) { .thumb { width: 140px; } }
