:root {
  --bg: #0f1115;
  --card: #191c22;
  --card2: #22262e;
  --line: #2c313a;
  --text: #eef0f3;
  --muted: #9aa3ae;
  --accent: #14b8a6;
  --accent2: #5eead4;
  --warn: #f59e0b;
  --bad: #ef4444;
  --radius: 16px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button { font: inherit; color: inherit; cursor: pointer; }
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 14px 10px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.top h1 { flex: 1; margin: 0; font-size: 18px; font-weight: 650; text-align: center; letter-spacing: .3px; }
.icon-btn { width: 40px; height: 40px; border: 0; border-radius: 50%; background: var(--card); display: grid; place-items: center; }
.icon-btn[hidden] { visibility: hidden; display: grid; }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
main { max-width: 1100px; margin: 0 auto; padding: 14px 14px calc(env(safe-area-inset-bottom) + 24px); }

/* Login */
.login { max-width: 340px; margin: 12vh auto 0; text-align: center; }
.login img { width: 72px; }
.login input { width: 100%; padding: 14px; margin: 18px 0 10px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--text); font-size: 16px; }
.btn { border: 0; border-radius: 12px; padding: 12px 18px; background: var(--accent); color: #04211e; font-weight: 650; }
.btn.wide { width: 100%; }
.btn.ghost { background: var(--card2); color: var(--text); }
.btn.danger { background: transparent; color: var(--bad); border: 1px solid var(--line); }
.err { color: var(--bad); min-height: 20px; margin-top: 8px; }

/* Griglia telecamere */
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.tile { background: var(--card); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); text-align: left; padding: 0; }
.tile .meta { display: flex; align-items: center; gap: 8px; padding: 10px 12px; }
.tile .meta b { flex: 1; font-weight: 600; }
.video { position: relative; aspect-ratio: 16 / 9; background: #000; }
.video video { width: 100%; height: 100%; object-fit: contain; display: block; background: #000; }
.video .overlay { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 16px; font-size: 14px; }
.badge { position: absolute; top: 10px; left: 10px; font-size: 12px; font-weight: 650; padding: 3px 8px; border-radius: 999px; background: rgba(0,0,0,.55); }
.badge.live::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--bad); margin-right: 6px; vertical-align: 1px; animation: blink 1.4s infinite; }
@keyframes blink { 50% { opacity: .2; } }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.dot.online { background: #22c55e; } .dot.offline { background: var(--bad); } .dot.privacy { background: var(--warn); }
.small { color: var(--muted); font-size: 13px; }

/* Dettaglio */
.cam-view .video { border-radius: var(--radius); overflow: hidden; }
.toolbar { display: flex; justify-content: space-around; padding: 14px 0; }
.toolbar button { border: 0; background: none; display: grid; justify-items: center; gap: 4px; color: var(--muted); font-size: 12px; }
.toolbar button svg { width: 26px; height: 26px; fill: none; stroke: var(--text); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.toolbar button[hidden] { display: none; }
.toolbar button.on svg { stroke: var(--accent2); }
.panel { background: var(--card); border-radius: var(--radius); padding: 16px; margin-top: 14px; border: 1px solid var(--line); }
.panel h2 { margin: 0 0 12px; font-size: 16px; font-weight: 650; display: flex; align-items: center; gap: 8px; }
.panel h2 .grow { flex: 1; }
.ptz { display: grid; grid-template-columns: repeat(3, 56px); grid-template-rows: repeat(3, 56px); gap: 6px; justify-content: center; }
.ptz button { border: 0; border-radius: 14px; background: var(--card2); }
.ptz button:active { background: var(--accent); color: #04211e; }
.ptz .c { background: transparent; }
.row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.row:first-of-type { border-top: 0; }
.row .grow { flex: 1; }
.switch { width: 50px; height: 30px; border-radius: 999px; border: 0; background: var(--card2); position: relative; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: left .2s; }
.switch.on { background: var(--accent); } .switch.on::after { left: 23px; }

/* Riproduzione */
.days { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; scrollbar-width: none; }
.days button { flex: none; border: 1px solid var(--line); background: var(--card2); border-radius: 12px; padding: 8px 12px; text-align: center; min-width: 64px; }
.days button.sel { background: var(--accent); color: #04211e; border-color: var(--accent); }
.days button small { display: block; font-size: 11px; opacity: .8; }
.timeline { position: relative; height: 44px; background: var(--card2); border-radius: 10px; margin: 14px 0 4px; overflow: hidden; cursor: pointer; }
.timeline .seg { position: absolute; top: 10px; bottom: 10px; background: #3b4451; }
.timeline .seg.motion { background: var(--accent); }
.timeline .mot { position: absolute; top: 2px; height: 6px; background: var(--warn); border-radius: 3px; min-width: 2px; }
.timeline .cursor { position: absolute; top: 0; bottom: 0; width: 2px; background: #fff; }
.hours { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }
.kinds { display: flex; gap: 6px; margin-top: 14px; }
.kinds button { flex: 1; border: 1px solid var(--line); background: var(--card2); border-radius: 10px; padding: 7px 8px; font-size: 13px; }
.kinds button.sel { background: var(--accent); color: #04211e; border-color: var(--accent); }
.clips { display: grid; gap: 8px; margin-top: 14px; }
.clip { display: flex; align-items: center; gap: 10px; background: var(--card2); border: 1px solid transparent; border-radius: 12px; padding: 10px 12px; text-align: left; width: 100%; }
.clip.sel { border-color: var(--accent); }
.clip .t { font-variant-numeric: tabular-nums; font-weight: 600; }
.clip .grow { flex: 1; }
.tag { font-size: 11px; padding: 2px 7px; border-radius: 999px; background: var(--card); color: var(--muted); }
.tag.m { background: rgba(245,158,11,.15); color: var(--warn); }
.tag.c { background: rgba(20,184,166,.15); color: var(--accent2); }
.empty { color: var(--muted); text-align: center; padding: 28px 0; }
.actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

#toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 20px); transform: translateX(-50%) translateY(30px); opacity: 0; background: var(--card2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px; transition: .25s; pointer-events: none; z-index: 10; }
#toast.show { opacity: 1; transform: translateX(-50%); }

@media (min-width: 900px) {
  .cam-layout { display: grid; grid-template-columns: 1fr 340px; gap: 16px; align-items: start; }
  .cam-layout .panel:first-child { margin-top: 0; }
}
