:root {
  --bg0: #0B0F17; --bg1: #111827; --bg2: #1C2433; --bg3: #263042; --line: #2A3445;
  --text: #E5E7EB; --muted: #9CA3AF; --dim: #6B7280;
  --accent: #3B82F6; --accent-soft: #1E3A5F; --green: #22C55E; --amber: #F59E0B; --red: #EF4444;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg0); color: var(--text); font: 14px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
input, select {
  width: 100%; background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
label { display: block; color: var(--muted); font-size: 12px; margin: 12px 0 0; }
label > input, label > select { margin-top: 5px; color: var(--text); font-size: 14px; }
button {
  background: var(--bg3); border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; cursor: pointer;
}
button:hover { border-color: var(--accent); }
a.button { display: inline-block; padding: 8px 16px; border-radius: 8px; text-decoration: none; }
a.button.primary { background: var(--accent); color: #fff; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.ghost { background: transparent; }
button.danger { color: #FCA5A5; }
button:disabled { opacity: .5; cursor: default; }
.card { background: var(--bg1); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { background: #3B1418; border: 1px solid var(--red); color: #FCA5A5; border-radius: 8px; padding: 8px 10px; margin-top: 12px; }
.brand { font-weight: 700; letter-spacing: .5px; }
.brand span { color: var(--accent); }

/* kirish */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); }
.login-card .brand { font-size: 20px; margin-bottom: 8px; }
.login-card button { width: 100%; margin-top: 18px; padding: 10px; }
.apk-link { display: block; text-align: center; margin-top: 14px; color: var(--accent); font-size: 13px; text-decoration: none; }

/* yuqori panel */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  background: var(--bg1); border-bottom: 1px solid var(--line); padding: 10px 16px;
}
#tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
#tabs button { background: transparent; border-color: transparent; color: var(--muted); white-space: nowrap; }
#tabs button.active { background: var(--bg2); color: #fff; border-color: var(--line); }
.me { display: flex; align-items: center; gap: 10px; color: var(--muted); }
main { padding: 16px; max-width: 1200px; margin: 0 auto; }

/* ro'yxatlar */
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input { max-width: 280px; }
.toolbar .spacer { flex: 1; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--bg2); }
.badge { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 10px; background: var(--bg3); color: var(--muted); margin: 1px 2px 1px 0; }
.badge.on { background: var(--accent-soft); color: #BFDBFE; }
.badge.off { background: #3B1418; color: #FCA5A5; }
.table-wrap { overflow-x: auto; }

/* kameralar (oddiy foydalanuvchi) */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.cam { background: var(--bg1); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.cam b { display: block; }

/* jonli setka */
.segment { display: inline-flex; background: var(--bg1); border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
.segment button { background: transparent; border: 0; padding: 5px 12px; color: var(--muted); }
.segment button.active { background: var(--bg3); color: #fff; }
.toolbar button.ghost:disabled { opacity: .3; }
.live-grid { display: grid; grid-template-columns: repeat(var(--cols, 2), 1fr); gap: 6px; }
.tile { position: relative; aspect-ratio: 16 / 9; background: #05070B; border-radius: 8px; overflow: hidden; cursor: pointer; }
.tile nvr-video, .tile video, .tile img { display: block; width: 100%; height: 100%; object-fit: contain; }
.tile-label {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 8px 5px; font-size: 12px; font-weight: 600;
  background: linear-gradient(transparent, rgba(0, 0, 0, .75)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tile-status { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 12px; text-align: center; padding: 8px; pointer-events: none; }
.viewer { position: fixed; inset: 0; z-index: 20; background: #000; display: flex; flex-direction: column; }
.viewer-bar { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--bg1); padding-top: max(8px, env(safe-area-inset-top)); }
.viewer-bar b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.viewer-bar .spacer { flex: 1; }
.viewer-bar > button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.viewer-bar button.icon { padding: 6px 10px; }
.viewer-bar select.quality { width: auto; padding: 6px 8px; }
.viewer-bar button.icon.active { background: var(--bg3); border-color: var(--line); }
.viewer-bar button.icon.live { background: #DC2626; border-color: #DC2626; animation: talk-pulse 1.2s infinite; }
@keyframes talk-pulse { 50% { box-shadow: 0 0 0 6px rgba(220, 38, 38, .25); } }
.talk-bar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: #3F1D1D; border-top: 1px solid #7F1D1D; }
.talk-bar[data-state="error"] { background: var(--bg1); border-color: var(--line); }
.talk-bar[data-state="error"] .talk-dot, .talk-bar[data-state="error"] .talk-meter, .talk-bar[data-state="error"] button { display: none; }
.talk-dot { width: 10px; height: 10px; border-radius: 50%; background: #EF4444; flex: none; animation: talk-pulse 1.2s infinite; }
#talk-text { flex: 1; min-width: 0; }
.talk-meter { width: 70px; height: 6px; background: rgba(255,255,255,.12); border-radius: 3px; overflow: hidden; flex: none; }
#talk-meter { display: block; height: 100%; width: 0; background: #22C55E; transition: width .08s; }
.viewer-video { position: relative; flex: 1; min-height: 0; }
.viewer-video nvr-video, .viewer-video video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; }
.viewer-status { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); pointer-events: none; }
.viewer:fullscreen .viewer-bar, .viewer:fullscreen .archive { opacity: .85; }

/* arxiv */
.archive { background: var(--bg1); border-top: 1px solid var(--line); padding: 10px 12px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
.archive-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.archive-row input { width: auto; padding: 6px 8px; }
.archive-row .spacer { flex: 1; }
.arc-clock { font-size: 20px; font-variant-numeric: tabular-nums; letter-spacing: .5px; }
.arc-buttons { justify-content: center; margin-top: 4px; }
.arc-buttons button { min-width: 52px; padding: 8px 6px; }
.timeline {
  position: relative; height: 52px; margin: 10px 0 6px; background: var(--bg2); border-radius: 6px; overflow: hidden;
  cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none;
}
.timeline.dragging { cursor: grabbing; background: var(--bg3); }
.tl-segs span { position: absolute; top: 6px; height: 22px; background: #2563EB; border-radius: 2px; }
.tl-future { position: absolute; top: 0; bottom: 0; right: 0; background: repeating-linear-gradient(135deg, transparent 0 6px, rgba(255,255,255,.05) 6px 12px); pointer-events: none; }
.tl-cursor { position: absolute; left: 50%; top: 0; bottom: 16px; width: 2px; margin-left: -1px; background: #F59E0B; box-shadow: 0 0 0 1px rgba(0,0,0,.4); pointer-events: none; }
.tl-hours span { position: absolute; bottom: 1px; transform: translateX(-50%); font-size: 10px; color: var(--dim); white-space: nowrap; pointer-events: none; }
.tl-hours span::before { content: ""; position: absolute; left: 50%; top: -8px; height: 5px; border-left: 1px solid var(--dim); }
.tl-hours span.day { color: var(--text); font-weight: 600; }
#arc-zoom button { padding: 4px 12px; font-size: 16px; line-height: 1; }
.segment button[hidden] { display: none; }
@media (max-width: 640px) {
  /* Tor ekran: 1-qator — yopish va kamera nomi, 2-qator — boshqaruv. */
  .viewer-bar { flex-wrap: wrap; row-gap: 6px; gap: 6px; }
  .viewer-bar b { flex: 1 1 calc(100% - 60px); font-size: 14px; }
  .viewer-bar .spacer { display: none; }
  .viewer-bar .segment button { padding: 5px 10px; }
  .viewer-bar select.quality { flex: 1; min-width: 0; }
  .viewer-bar button.icon { padding: 6px 9px; }
  .arc-clock { font-size: 17px; }
  .arc-buttons button { min-width: 0; flex: 1; padding: 9px 2px; font-size: 13px; }
}

/* oyna */
dialog { background: var(--bg1); color: var(--text); border: 1px solid var(--line); border-radius: 12px; padding: 0; width: min(640px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog form { padding: 18px; max-height: calc(100vh - 40px); overflow-y: auto; }
dialog h2 { margin: 0 0 4px; font-size: 17px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; position: sticky; bottom: -18px; background: var(--bg1); padding: 10px 0 0; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.checks { display: grid; gap: 4px; margin-top: 8px; }
.check { display: flex; gap: 10px; align-items: flex-start; color: var(--text); font-size: 14px; margin: 0; padding: 6px 4px; border-radius: 6px; cursor: pointer; }
.check:hover { background: var(--bg2); }
.check input { width: 18px; height: 18px; margin: 1px 0 0; flex: none; accent-color: var(--accent); }
.camlist { max-height: 300px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; padding: 4px; margin-top: 8px; }
.camlist .check small { display: block; color: var(--dim); }
.section-title { margin: 18px 0 0; font-weight: 600; }

@media (max-width: 640px) {
  .row { grid-template-columns: 1fr; }
  main { padding: 12px; }
  .topbar { gap: 8px; }
  .topbar .brand { flex: 1; }
  #tabs { order: 3; flex-basis: 100%; }
  #me-name { display: none; }
  .hide-sm { display: none; }
}
