/* KJo CCTV — "Midnight Control Room" design system
   Intentionally dark-only: a night-monitoring surveillance aesthetic. */
:root {
  color-scheme: dark;
  --bg: #0a0e13;
  --bg-2: #0d1219;
  --surface: rgba(255, 255, 255, 0.045);
  --surface-2: rgba(255, 255, 255, 0.07);
  --surface-solid: #121a24;
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #e8eef6;
  --muted: #8496a9;
  --faint: #566374;
  --accent: #2dd4bf;
  --accent-2: #22d3ee;
  --accent-ink: #052b28;
  --live: #fb5673;
  --online: #34d399;
  --warn: #fbbf24;
  --shadow: 0 18px 50px -12px rgba(0, 0, 0, 0.7);
  --radius: 18px;
  --radius-sm: 12px;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100dvh;
  /* ambient control-room glow */
  background-image:
    radial-gradient(1100px 520px at 85% -10%, rgba(45, 212, 191, 0.10), transparent 60%),
    radial-gradient(900px 500px at -5% 0%, rgba(34, 211, 238, 0.06), transparent 55%);
  background-attachment: fixed;
}
a { color: var(--accent); text-decoration: none; }
button { font-family: inherit; }
::selection { background: rgba(45, 212, 191, 0.3); }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 10px 16px; border-radius: 11px; font-size: 13.5px; font-weight: 600;
  cursor: pointer; transition: transform .12s ease, background .15s, border-color .15s, box-shadow .15s;
  display: inline-flex; align-items: center; gap: 7px; -webkit-user-select: none; user-select: none;
}
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn:active { transform: scale(.97); }
.btn.small { padding: 7px 12px; font-size: 12.5px; border-radius: 9px; }
.btn.danger { color: var(--live); border-color: rgba(251, 86, 115, 0.28); }
.btn.danger:hover { background: rgba(251, 86, 115, 0.1); }
.btn.primary {
  color: var(--accent-ink); border: none; font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 22px -8px rgba(45, 212, 191, 0.6);
}
.btn.primary:hover { box-shadow: 0 10px 28px -6px rgba(45, 212, 191, 0.75); }
.btn.ghost { background: transparent; }
.btn .ic { width: 16px; height: 16px; display: block; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- login ---------- */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 22px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 24px; padding: 34px 28px; backdrop-filter: blur(20px) saturate(1.2);
  box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.login-card::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 3px;
  background: linear-gradient(90deg, transparent, var(--accent), var(--accent-2), transparent);
}
.brand-mark { display: flex; align-items: center; gap: 11px; margin-bottom: 26px; }
.brand-logo {
  width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; flex: none;
  background: linear-gradient(135deg, rgba(45, 212, 191, 0.2), rgba(34, 211, 238, 0.12));
  border: 1px solid rgba(45, 212, 191, 0.35);
}
.brand-logo svg { width: 22px; height: 22px; }
.brand-text .t { font-weight: 800; font-size: 16px; letter-spacing: -0.3px; line-height: 1; }
.brand-text .s { font-size: 11px; color: var(--muted); letter-spacing: 0.4px; text-transform: uppercase; margin-top: 4px; }
.login-card h1 { font-size: 21px; margin: 0 0 6px; letter-spacing: -0.4px; }
.login-card .lead { color: var(--muted); font-size: 13.5px; margin: 0 0 22px; }
.field { margin-bottom: 15px; }
.field label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 7px; text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; }
.field input {
  width: 100%; padding: 13px 14px; border-radius: 12px; border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.28); color: var(--text); font-size: 15px; transition: border-color .15s, background .15s;
}
.field input:focus { outline: none; border-color: var(--accent); background: rgba(0, 0, 0, 0.4); }
.login-card .btn.primary { width: 100%; padding: 14px; font-size: 15px; justify-content: center; margin-top: 6px; }
.err { color: var(--live); font-size: 13px; min-height: 18px; margin: 10px 0 0; }

/* ---------- app shell ---------- */
.appbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 12px;
  padding: 12px 18px; border-bottom: 1px solid var(--border);
  background: rgba(10, 14, 19, 0.72); backdrop-filter: blur(18px) saturate(1.3);
}
.appbar .brand-logo { width: 34px; height: 34px; border-radius: 10px; }
.appbar .brand-logo svg { width: 18px; height: 18px; }
.appbar .title { font-weight: 800; letter-spacing: -0.3px; font-size: 15px; }
.appbar .spacer { flex: 1; }
.statuspill {
  display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted);
  background: var(--surface); border: 1px solid var(--border); padding: 6px 11px; border-radius: 20px;
  font-variant-numeric: tabular-nums;
}
.statuspill .clock { font-family: var(--mono); color: var(--text); font-size: 11.5px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; flex: none;
  font-weight: 700; font-size: 13px; color: var(--accent-ink); cursor: pointer;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
/* desktop nav pills (hidden on mobile) */
.navpills { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--border); padding: 4px; border-radius: 13px; }
.navpills button {
  border: none; background: transparent; color: var(--muted); font-weight: 600; font-size: 13px;
  padding: 8px 15px; border-radius: 9px; cursor: pointer; display: inline-flex; align-items: center; gap: 7px; transition: .15s;
}
.navpills button .ic { width: 16px; height: 16px; }
.navpills button.active { background: var(--surface-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--border); }
.navpills button:hover:not(.active) { color: var(--text); }

/* views */
main { padding: 18px; padding-bottom: 110px; max-width: 1240px; margin: 0 auto; }
.view { animation: fadein .32s ease; }
.view-head { display: flex; align-items: center; gap: 12px; margin: 4px 2px 18px; }
.view-head h2 { font-size: 20px; margin: 0; letter-spacing: -0.4px; }
.view-head .sub { color: var(--muted); font-size: 13px; }
.view-head .spacer { flex: 1; }

/* ---------- camera grid ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 16px; }
.cam {
  position: relative; border-radius: var(--radius); overflow: hidden; background: #000;
  border: 1px solid var(--border); box-shadow: var(--shadow);
  transition: transform .18s ease, border-color .18s, box-shadow .18s;
}
.cam:hover { transform: translateY(-3px); border-color: rgba(45, 212, 191, 0.4); box-shadow: 0 22px 55px -12px rgba(0,0,0,.8), 0 0 0 1px rgba(45,212,191,.15); }
.cam video, .cam .ph { width: 100%; aspect-ratio: 16 / 9; display: block; object-fit: cover; background: #05080c; }
.cam .scrim { position: absolute; left: 0; right: 0; bottom: 0; height: 74px; background: linear-gradient(transparent, rgba(0,0,0,.72)); pointer-events: none; }
.cam .name { position: absolute; left: 13px; bottom: 12px; font-weight: 700; font-size: 14px; letter-spacing: -0.2px; text-shadow: 0 1px 6px rgba(0,0,0,.6); }
.cam .ts { position: absolute; right: 13px; bottom: 13px; font-family: var(--mono); font-size: 11px; color: rgba(255,255,255,.82); text-shadow: 0 1px 6px rgba(0,0,0,.7); font-variant-numeric: tabular-nums; }
.badge {
  position: absolute; left: 12px; top: 12px; display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 9px 4px 8px; border-radius: 20px; font-size: 10.5px; font-weight: 800; letter-spacing: 0.6px;
  background: rgba(0, 0, 0, 0.5); backdrop-filter: blur(6px); border: 1px solid rgba(255,255,255,.14); text-transform: uppercase;
}
.badge .d { width: 7px; height: 7px; border-radius: 50%; background: var(--live); box-shadow: 0 0 0 0 rgba(251,86,115,.6); animation: pulse 2s infinite; }
.badge.off .d { background: var(--faint); animation: none; }
.badge.off { color: var(--muted); }
.cam .expand {
  position: absolute; right: 11px; top: 11px; width: 32px; height: 32px; border-radius: 9px; border: 1px solid rgba(255,255,255,.16);
  background: rgba(0,0,0,.45); backdrop-filter: blur(6px); display: grid; place-items: center; cursor: pointer; opacity: 0; transition: opacity .15s, background .15s;
}
.cam:hover .expand { opacity: 1; }
.cam .expand:hover { background: rgba(0,0,0,.7); }
.cam .expand svg { width: 15px; height: 15px; }
.cam video { will-change: transform; transition: transform .08s linear; touch-action: pan-y; }
.cam.zoomed video { transition: none; }
.cam .zreset {
  position: absolute; left: 12px; top: 12px; display: none; align-items: center; gap: 5px;
  padding: 5px 10px; border-radius: 20px; border: 1px solid rgba(255,255,255,.16); cursor: pointer;
  background: rgba(0,0,0,.55); backdrop-filter: blur(6px); color: #fff; font-size: 11px; font-weight: 700; z-index: 2;
}
.cam.zoomed .zreset { display: inline-flex; }
.cam.zoomed .badge { opacity: 0; }
/* skeleton */
.cam.loading .ph { background: linear-gradient(100deg, #0a1017 30%, #131c26 50%, #0a1017 70%); background-size: 220% 100%; animation: shimmer 1.5s infinite; }
.empty { grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 70px 20px; border: 1px dashed var(--border); border-radius: var(--radius); background: var(--surface); }
.empty .big { font-size: 15px; color: var(--text); font-weight: 600; margin-bottom: 6px; }

/* ---------- playback ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; backdrop-filter: blur(14px); box-shadow: var(--shadow); }
.pb-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; align-items: end; }
.ctl label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; }
select, input[type="datetime-local"] {
  width: 100%; padding: 11px 13px; border-radius: 11px; border: 1px solid var(--border);
  background: rgba(0,0,0,.28); color: var(--text); font-size: 14px; font-family: inherit;
}
select:focus, input:focus { outline: none; border-color: var(--accent); }
.segment { display: inline-flex; background: rgba(0,0,0,.28); border: 1px solid var(--border); border-radius: 11px; padding: 3px; gap: 2px; }
.segment button { border: none; background: transparent; color: var(--muted); font-weight: 600; font-size: 12.5px; padding: 8px 12px; border-radius: 8px; cursor: pointer; transition: .12s; font-variant-numeric: tabular-nums; }
.segment button.on { background: var(--surface-2); color: var(--text); }
.chiprow { display: flex; flex-wrap: wrap; gap: 7px; }
.chiprow button { border: 1px solid var(--border); background: var(--surface); color: var(--muted); font-weight: 600; font-size: 12px; padding: 7px 12px; border-radius: 20px; cursor: pointer; transition: .12s; }
.chiprow button:hover { color: var(--text); border-color: var(--border-strong); }
.pb-player { margin-top: 16px; }
.pb-player .cam { max-width: 940px; }
.pb-player .pbmeta { display: flex; align-items: center; gap: 10px; margin: 0 2px 10px; color: var(--muted); font-size: 13px; }
.pb-player .pbmeta .mono { font-family: var(--mono); color: var(--text); font-variant-numeric: tabular-nums; }

/* ---------- admin ---------- */
.users { display: grid; gap: 12px; }
.urow {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--border);
}
.urow .ua { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; font-weight: 800; font-size: 15px; color: #fff; flex: none; }
.urow .uinfo { min-width: 0; flex: 1; }
.urow .uname { font-weight: 700; font-size: 14.5px; letter-spacing: -0.2px; }
.urow .ucams { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.urow .uact { display: flex; gap: 7px; }
.role { font-size: 10px; font-weight: 800; letter-spacing: 0.6px; text-transform: uppercase; padding: 3px 8px; border-radius: 6px; }
.role.admin { color: var(--accent); background: rgba(45,212,191,.12); }
.role.user { color: var(--muted); background: var(--surface-2); }
.chip { display: inline-block; padding: 3px 9px; border-radius: 7px; background: var(--surface-2); border: 1px solid var(--border); font-size: 11px; color: var(--text); }
.chip.all { color: var(--accent); border-color: rgba(45,212,191,.3); background: rgba(45,212,191,.08); }

/* ---------- modal / sheet ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(3,6,10,.66); backdrop-filter: blur(4px); display: none; align-items: center; justify-content: center; padding: 16px; z-index: 60; }
.modal-bg.show { display: flex; animation: fadein .2s; }
.modal { background: var(--surface-solid); border: 1px solid var(--border-strong); border-radius: 22px; padding: 24px; width: 100%; max-width: 440px; box-shadow: var(--shadow); animation: pop .24s cubic-bezier(.2,.9,.3,1.3); }
.modal h3 { margin: 0 0 18px; font-size: 17px; letter-spacing: -0.3px; }
.cam-checks { display: grid; gap: 4px; }
.cam-checks label { display: flex; align-items: center; gap: 10px; padding: 9px 11px; font-size: 14px; border-radius: 10px; cursor: pointer; border: 1px solid transparent; }
.cam-checks label:hover { background: var(--surface); }
.cam-checks input { accent-color: var(--accent); width: 17px; height: 17px; }
.modal .field input { background: rgba(0,0,0,.3); }
.modal-row { display: flex; gap: 10px; margin-top: 20px; }
.modal-row .btn { flex: 1; justify-content: center; padding: 12px; }

/* ---------- bottom nav (mobile) ---------- */
.tabbar { display: none; }
@media (max-width: 720px) {
  .navpills { display: none; }
  .appbar .statuspill { display: none; }
  .grid { grid-template-columns: 1fr; gap: 13px; }
  .tabbar {
    display: flex; position: fixed; left: 12px; right: 12px; bottom: 12px; z-index: 40;
    background: rgba(14, 20, 28, 0.82); backdrop-filter: blur(22px) saturate(1.3);
    border: 1px solid var(--border-strong); border-radius: 20px; padding: 8px; gap: 4px;
    box-shadow: var(--shadow); justify-content: space-around;
  }
  .tabbar button {
    flex: 1; border: none; background: transparent; color: var(--muted); cursor: pointer;
    display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 7px 4px 5px; border-radius: 13px;
    font-size: 10.5px; font-weight: 600; transition: color .15s, background .15s;
  }
  .tabbar button .ic { width: 21px; height: 21px; }
  .tabbar button.active { color: var(--accent); background: rgba(45,212,191,.1); }
  main { padding: 14px; padding-bottom: 96px; }
  .view-head h2 { font-size: 18px; }
  .urow { flex-wrap: wrap; }
}

/* ---------- motion ---------- */
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(251,86,115,.55); } 70% { box-shadow: 0 0 0 7px rgba(251,86,115,0); } 100% { box-shadow: 0 0 0 0 rgba(251,86,115,0); } }
@keyframes shimmer { to { background-position: -220% 0; } }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: scale(.94); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
