:root {
  --bg: #0e1116; --panel: #161b22; --panel-2: #1d232c; --line: #2a313c;
  --text: #e6e9ee; --muted: #8b95a3; --accent: #3d8bfd; --accent-2: #2f6fd1;
  --ok: #2fbf71; --warn: #f2a93b; --bad: #ef5a5a; --radius: 12px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, 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); text-decoration: none; }
h1, h2, h3 { margin: 0 0 12px; font-weight: 600; }
h1 { font-size: 22px; } h2 { font-size: 18px; } h3 { font-size: 15px; }
.muted { color: var(--muted); } .small { font-size: 13px; }
.center { display: grid; place-items: center; min-height: 60vh; }
.error { color: var(--bad); }

/* layout */
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px; padding: 10px 20px;
  padding-top: max(10px, var(--safe-area-inset-top, env(safe-area-inset-top))); background: rgba(14,17,22,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; letter-spacing: .2px; display: flex; align-items: center; gap: 8px; }
.brand .logo { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); display: grid; place-items: center; font-size: 12px; color: #fff; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { color: var(--muted); padding: 8px 12px; border-radius: 8px; }
.nav a.on { color: var(--text); background: var(--panel-2); }
main { padding: 20px; max-width: 1400px; margin: 0 auto; padding-bottom: 100px; }
@media (max-width: 720px) {
  .top { backdrop-filter: none; -webkit-backdrop-filter: none; background: var(--bg); padding: 10px 16px; padding-top: max(10px, var(--safe-area-inset-top, env(safe-area-inset-top))); }
  .nav { position: fixed; bottom: 0; left: 0; right: 0; justify-content: space-around; background: var(--panel);
    border-top: 1px solid var(--line); padding: 6px 4px max(6px, var(--safe-area-inset-bottom, env(safe-area-inset-bottom))); }
  .nav a { font-size: 12px; padding: 6px 8px; text-align: center; flex: 1; }
  .top .spacer { flex: 1; }
  main { padding: 16px; padding-bottom: 110px; }
}

/* controls */
button, .btn { font: inherit; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); padding: 9px 14px;
  border-radius: 9px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .btn:hover { border-color: #3a4350; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-2); }
button.danger { color: var(--bad); }
button.link { background: none; border: none; color: var(--muted); padding: 6px; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 9px;
  padding: 9px 11px; width: 100%; min-width: 0; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label { display: grid; gap: 5px; font-size: 13px; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); }
label.check input { width: auto; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; align-items: end; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar h1 { margin: 0; flex: 1; }

/* login */
.login { max-width: 380px; margin: 12vh auto 0; padding: 0 20px; }
.login .card { padding: 28px; display: grid; gap: 14px; }

/* camera grid */
.site-h { display: flex; align-items: center; gap: 8px; margin: 22px 0 10px; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .6px; }
.site-h:first-of-type { margin-top: 0; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.online { background: var(--ok); } .dot.offline { background: var(--bad); }
.cams { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.tile { position: relative; border-radius: var(--radius); overflow: hidden; background: #000; border: 1px solid var(--line); aspect-ratio: 16/9; display: block; color: var(--text); }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; transition: opacity .3s; }
.tile img.broken { opacity: 0; }
.tile .nosig { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 13px; z-index: 0; }
.tile img { position: relative; z-index: 1; }
.tile .cap { position: absolute; z-index: 2; left: 0; right: 0; bottom: 0; padding: 22px 12px 9px; display: flex; align-items: center; gap: 8px;
  background: linear-gradient(transparent, rgba(0,0,0,.8)); font-weight: 500; }
.tile .cap span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bell { z-index: 3; background: rgba(0,0,0,.45); border: none; padding: 5px 8px; border-radius: 8px; font-size: 14px; }

/* players */
.player { background: #000; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.player video { width: 100%; display: block; max-height: 75vh; background: #000; aspect-ratio: 16/9; }
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 3px 9px; border-radius: 99px; background: var(--panel-2); border: 1px solid var(--line); }
.badge.live { color: #fff; background: var(--bad); border-color: var(--bad); }

/* events list */
.events { display: grid; gap: 10px; }
.event { display: flex; gap: 12px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; color: var(--text); }
.event img, .event .ph { width: 120px; aspect-ratio: 16/9; object-fit: cover; border-radius: 8px; background: #000; flex-shrink: 0; }
.event .ph { display: grid; place-items: center; color: var(--muted); font-size: 22px; }
.event .t { font-weight: 600; }
.event .meta { flex: 1; min-width: 0; }
@media (max-width: 480px) { .event img, .event .ph { width: 96px; } }

/* admin */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.table-wrap { overflow-x: auto; }
details summary { cursor: pointer; color: var(--accent); margin: 8px 0; }
.cam-row { display: grid; grid-template-columns: 60px 1fr 110px auto auto; gap: 8px; align-items: center; margin-bottom: 6px; }
@media (max-width: 560px) { .cam-row { grid-template-columns: 40px 1fr 90px; } .cam-row button { grid-column: span 1; } }
.hint { background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; font-size: 13px; color: var(--muted); }

.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--line);
  padding: 10px 16px; border-radius: 10px; z-index: 100; box-shadow: 0 6px 24px rgba(0,0,0,.4); max-width: 90vw; }
.toast.err { border-color: var(--bad); color: #ffb4b4; }

/* phone app */
.native { -webkit-tap-highlight-color: transparent; }
.native body { overscroll-behavior-y: none; -webkit-user-select: none; user-select: none; }
.native input, .native select, .native textarea { -webkit-user-select: text; user-select: text; font-size: 16px; }
