:root {
  --bg: #0f172a;
  --card: #1e293b;
  --card2: #273449;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --green: #22c55e;
  --red: #ef4444;
  --orange: #f59e0b;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 14px; }
.error { color: var(--red); min-height: 1.2em; margin: 8px 0 0; }
h2 { font-size: 18px; margin: 20px 4px 10px; }
h3 { font-size: 16px; margin: 0 0 10px; }

.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--safe-top) + 10px) 16px 10px; background: rgba(15, 23, 42, .92); backdrop-filter: blur(12px); }
.topbar h1 { font-size: 24px; margin: 0; }
.bell { position: relative; font-size: 22px; }
.badge { position: absolute; top: -4px; right: -8px; background: var(--red); color: #fff; border-radius: 10px;
  font-size: 11px; padding: 1px 6px; font-weight: 600; }

main { padding: 4px 12px calc(var(--safe-bottom) + 90px); max-width: 960px; margin: 0 auto; }

.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: flex; justify-content: space-around;
  padding: 6px 4px calc(var(--safe-bottom) + 6px); background: rgba(30, 41, 59, .95); backdrop-filter: blur(12px);
  border-top: 1px solid #334155; }
.tabbar a { display: flex; flex-direction: column; align-items: center; font-size: 11px; color: var(--muted); flex: 1; }
.tabbar a span { font-size: 22px; line-height: 28px; }
.tabbar a.active { color: var(--accent); }

.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.grid.wide { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

.btn { border: 0; border-radius: 12px; padding: 12px 16px; font-size: 16px; font-weight: 600; background: var(--card2);
  color: var(--text); cursor: pointer; }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; }
.btn.primary { background: var(--accent); color: #0b1220; }
.btn.green { background: var(--green); color: #052e12; }
.btn.red { background: var(--red); color: #fff; }
.btn.small { padding: 6px 12px; font-size: 14px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn.confirm { background: var(--orange); color: #1f1300; }

input, select, textarea { width: 100%; padding: 12px; border-radius: 12px; border: 1px solid #334155; background: #0b1220;
  color: var(--text); font-size: 16px; margin-bottom: 10px; }
label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 4px; }
label.check { display: flex; align-items: center; gap: 10px; color: var(--text); font-size: 15px; margin: 8px 0; }
label.check input { width: auto; margin: 0; }

.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 360px; text-align: center; }
.login-card .logo { font-size: 48px; }
.login-card h1 { margin: 4px 0 20px; }
.login-card .btn { width: 100%; }

.gate { text-align: center; }
.gate .btn { width: 100%; padding: 22px; font-size: 20px; border-radius: 18px; margin-top: 10px; }
.status-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--muted); margin-right: 6px; }
.status-dot.open { background: var(--orange); }
.status-dot.closed { background: var(--green); }

.tile { background: var(--card); border-radius: var(--radius); padding: 14px; min-height: 96px; display: flex;
  flex-direction: column; justify-content: space-between; cursor: pointer; user-select: none; }
.tile .name { font-size: 14px; font-weight: 600; }
.tile .state { font-size: 13px; color: var(--muted); }
.tile.on { background: #334e2d; }
.tile.on .state { color: #bbf7d0; }
.tile .icon { font-size: 24px; }
.tile .actions { display: flex; gap: 6px; margin-top: 8px; }
.tile.editing { outline: 2px dashed #475569; }
.tile .edit { display: flex; gap: 6px; margin-top: 8px; font-size: 12px; }

.cam { position: relative; border-radius: var(--radius); overflow: hidden; background: #000; aspect-ratio: 16/9; cursor: pointer; }
.cam img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam .label { position: absolute; left: 8px; bottom: 8px; background: rgba(0, 0, 0, .6); padding: 2px 8px; border-radius: 8px; font-size: 13px; }
.live { background: #000; border-radius: var(--radius); overflow: hidden; margin-bottom: 4px; }
.live video-stream, .live video { display: block; width: 100%; aspect-ratio: 16/9; background: #000; }

.player { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 16/9; }
.player video-stream, .player video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.player-status { position: absolute; inset: auto 0 0 0; padding: 10px 14px; background: rgba(0, 0, 0, .65); font-size: 14px; }
.player-bar { margin: 8px 0 12px; flex-wrap: wrap; }
.player-bar .row { gap: 6px; }
.tl-scroll { overflow-x: auto; margin-top: 10px; -webkit-overflow-scrolling: touch; }
.tl { position: relative; height: 64px; background: #0b1220; border-radius: 10px; cursor: pointer; min-width: 100%; }
.tl-seg { position: absolute; top: 8px; height: 30px; background: #2563eb; border-radius: 2px; pointer-events: none; }
.tl-seg.ev { background: var(--orange); top: 8px; height: 30px; }
.tl-tick { position: absolute; top: 0; bottom: 0; border-left: 1px solid #334155; pointer-events: none; }
.tl-tick span { position: absolute; bottom: 4px; left: 3px; font-size: 11px; color: var(--muted); white-space: nowrap; }
.tl-cursor { position: absolute; top: 0; bottom: 0; width: 2px; background: #f8fafc; box-shadow: 0 0 6px #fff; pointer-events: none; }
.lg { display: inline-block; width: 12px; height: 10px; border-radius: 2px; margin: 0 4px 0 10px; vertical-align: middle; }
.lg-rec { background: #2563eb; margin-left: 0; }
.lg-ev { background: var(--orange); }

.list .item { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid #334155; }
.list .item:last-child { border-bottom: 0; }
.list .item .grow { flex: 1; min-width: 0; }
.list .item .title { font-weight: 600; }
.list .item.unread .title::before { content: "● "; color: var(--accent); }
.thumb { width: 96px; height: 54px; object-fit: cover; border-radius: 8px; background: #000; cursor: pointer; }
.plate { font-family: ui-monospace, Menlo, monospace; font-weight: 700; letter-spacing: 1px; background: #f8fafc; color: #0f172a;
  padding: 2px 8px; border-radius: 6px; border-left: 8px solid #2563eb; white-space: nowrap; }
.pill { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 10px; background: var(--card2); color: var(--muted); }
.pill.green { background: #14532d; color: #bbf7d0; }
.pill.red { background: #7f1d1d; color: #fecaca; }
.pill.orange { background: #78350f; color: #fde68a; }

.tabs { display: flex; gap: 6px; margin: 8px 0 12px; overflow-x: auto; }
.tabs a { padding: 8px 14px; border-radius: 12px; background: var(--card); color: var(--muted); white-space: nowrap; }
.tabs a.active { background: var(--accent); color: #0b1220; font-weight: 600; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid #334155; }
th { color: var(--muted); font-weight: 500; }
.scroll-x { overflow-x: auto; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--safe-bottom) + 90px); z-index: 50;
  background: #0b1220; border: 1px solid #334155; padding: 12px 18px; border-radius: 14px; max-width: 90vw; }
.toast.err { border-color: var(--red); }

.modal { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .6); display: flex; align-items: flex-end;
  justify-content: center; }
.modal-body { width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; border-radius: 20px 20px 0 0;
  padding-bottom: calc(var(--safe-bottom) + 20px); margin: 0; }
@media (min-width: 700px) { .modal { align-items: center; } .modal-body { border-radius: 20px; } }
.modal img.full { width: 100%; border-radius: 12px; }

.hint { background: #0c4a6e; border-radius: 12px; padding: 12px; font-size: 14px; margin-bottom: 12px; }
