/* ────────────────────────────────────────────────────────────────────────────
   Dahua Web Player — Dark Theme CSS
   ──────────────────────────────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-0:       #0d0f14;
  --bg-1:       #13161e;
  --bg-2:       #1a1e28;
  --bg-3:       #222636;
  --border:     #2a2f40;
  --text-0:     #e8eaf0;
  --text-1:     #9aa0b8;
  --text-2:     #5c6480;
  --accent:     #3d82f6;
  --accent-h:   #5b97ff;
  --success:    #22c55e;
  --warning:    #f59e0b;
  --danger:     #ef4444;
  --normal-seg: #3d82f6;
  --motion-seg: #f59e0b;
  --alarm-seg:  #ef4444;
  --radius:     8px;
  --radius-sm:  5px;
  --sidebar-w:  220px;
  --topbar-h:   52px;
  --controls-h: 56px;
  --timeline-h: 64px;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 13px;
  background: var(--bg-0);
  color: var(--text-0);
  height: 100vh;
  overflow: hidden;
}

/* ── Screen switching ────────────────────────────────────────────────────── */
.screen { display: none; }
.screen.active { display: flex; }

/* ── Login screen ────────────────────────────────────────────────────────── */
#screen-login {
  height: 100vh;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 30%, #1a2040 0%, var(--bg-0) 70%);
}

.login-box {
  width: 380px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 36px 32px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.5);
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 32px;
  color: var(--accent);
}
.login-logo h1 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-0);
}

.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-1);
  margin-bottom: 6px;
}
.field input, input[type="date"], select {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-0);
  font-size: 13px;
  outline: none;
  transition: border-color .15s;
}
.field input:focus, input[type="date"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(61,130,246,0.2);
}

.field-group { display: flex; gap: 10px; }
.field-group .field { flex: 1; }
.field-port { flex: 0 0 90px !important; }

.btn-primary {
  width: 100%;
  margin-top: 8px;
  padding: 11px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .1s;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-primary:hover { background: var(--accent-h); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-spinner { display: inline-block; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.error-msg {
  margin-top: 12px;
  padding: 9px 12px;
  background: rgba(239,68,68,0.12);
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: var(--radius-sm);
  color: #fca5a5;
  font-size: 12px;
}

/* ── Player screen layout ────────────────────────────────────────────────── */
#screen-player {
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.topbar {
  height: var(--topbar-h);
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
  gap: 12px;
}
.topbar-left { display: flex; align-items: center; gap: 10px; color: var(--accent); }
.topbar-title { font-weight: 600; font-size: 14px; color: var(--text-0); }
.topbar-device {
  font-size: 11px;
  color: var(--text-2);
  padding: 3px 8px;
  background: var(--bg-3);
  border-radius: 20px;
  border: 1px solid var(--border);
}
.topbar-right { display: flex; gap: 8px; }

.btn-icon {
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-1);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.btn-icon:hover { background: var(--bg-3); color: var(--text-0); }

.player-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Sidebar ────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}
.sidebar-header {
  padding: 12px 14px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-2);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 7px;
}

.camera-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  padding: 6px;
}
.camera-list li {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .1s;
  color: var(--text-1);
  font-size: 13px;
}
.camera-list li:hover { background: var(--bg-3); color: var(--text-0); }
.camera-list li.active {
  background: rgba(61,130,246,0.15);
  color: var(--accent);
  border: 1px solid rgba(61,130,246,0.25);
}
.cam-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-2);
  flex-shrink: 0;
}
.camera-list li.active .cam-dot { background: var(--accent); box-shadow: 0 0 6px var(--accent); }

/* ── Main panel ─────────────────────────────────────────────────────────── */
.main-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-0);
}

/* ── Video ──────────────────────────────────────────────────────────────── */
.video-wrapper {
  flex: 1;
  position: relative;
  background: #000;
  overflow: hidden;
}
#video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.video-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(13,15,20,0.85);
  pointer-events: none;
  transition: opacity .3s;
}
.video-overlay.hidden { opacity: 0; }
.overlay-content {
  text-align: center;
  color: var(--text-2);
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.overlay-content p { font-size: 13px; }

.video-status {
  position: absolute;
  top: 10px; left: 12px;
  background: rgba(0,0,0,0.65);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-size: 11px;
  color: var(--text-1);
  backdrop-filter: blur(4px);
}

/* ── Controls bar ───────────────────────────────────────────────────────── */
.controls-bar {
  height: var(--controls-h);
  background: var(--bg-2);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  flex-shrink: 0;
}

.ctrl-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-2);
}

.ctrl-date-group {
  display: flex; align-items: center; gap: 8px;
}
.inp-date {
  width: auto;
  color-scheme: dark;
  padding: 7px 10px;
}

.btn-secondary {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 12px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-1);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.btn-secondary:hover { background: var(--border); color: var(--text-0); }
.btn-sm { padding: 5px 10px; }

.ctrl-btn-group { display: flex; align-items: center; gap: 8px; }

.btn-control {
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-0);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.btn-control:hover:not(:disabled) { background: var(--accent); border-color: var(--accent); }
.btn-control:disabled { opacity: 0.35; cursor: not-allowed; }

.speed-group { display: flex; align-items: center; gap: 7px; }
.sel-speed {
  width: auto;
  padding: 6px 8px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-0);
  font-size: 12px;
  cursor: pointer;
}
.sel-speed:disabled { opacity: 0.35; cursor: not-allowed; }

.ctrl-time {
  margin-left: auto;
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-0);
  letter-spacing: 0.04em;
  font-family: 'Courier New', monospace;
}

/* ── Timeline ───────────────────────────────────────────────────────────── */
.timeline-section {
  flex-shrink: 0;
  background: var(--bg-1);
  border-top: 1px solid var(--border);
  padding: 10px 16px 12px;
}
.timeline-labels {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--text-2);
  margin-bottom: 4px;
  font-variant-numeric: tabular-nums;
}
.timeline-track-wrapper {
  position: relative;
  height: 24px;
  display: flex;
  align-items: center;
}
.timeline-canvas {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  left: 0;
  width: 100%;
  pointer-events: none;
  border-radius: 4px;
}
.timeline-range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 24px;
  background: transparent;
  cursor: pointer;
  position: relative;
  z-index: 2;
}
.timeline-range:disabled { cursor: not-allowed; opacity: 0.5; }
.timeline-range::-webkit-slider-runnable-track {
  height: 8px;
  background: transparent;
  border-radius: 4px;
}
.timeline-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  margin-top: -4px;
  box-shadow: 0 0 6px rgba(61,130,246,0.6);
  transition: transform .1s;
}
.timeline-range::-webkit-slider-thumb:hover { transform: scale(1.2); }
.timeline-range::-moz-range-track {
  height: 8px; background: transparent;
}
.timeline-range::-moz-range-thumb {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  box-shadow: 0 0 6px rgba(61,130,246,0.6);
}

.timeline-cursor-label {
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-2);
  text-align: center;
}

/* ── Utilities ──────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-2); }
