/* === Variables === */
:root {
  --bg:      #111;
  --bg2:     #1c1c1c;
  --bg3:     #252525;
  --border:  #333;
  --text:    #e8e8e8;
  --muted:   #888;
  --accent:  #1a7fe0;
  --danger:  #c0392b;
  --success: #27ae60;
  --radius:  3px;
  --font:    system-ui, -apple-system, sans-serif;
}

/* === Reset === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body { background: var(--bg); color: var(--text); font-family: var(--font);
       font-size: 15px; line-height: 1.5; min-height: 100%; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
input, select, textarea, button { font-family: inherit; font-size: inherit; }

/* === Nav === */
nav {
  display: flex; align-items: center; justify-content: space-between;
  background: #0a0a0a; border-bottom: 1px solid var(--border);
  padding: 0 16px; height: 48px;
}
.brand { font-size: 17px; font-weight: 700; color: var(--text); }
.nav-right { display: flex; align-items: center; gap: 14px; }
.nav-user { color: var(--muted); font-size: 13px; }

/* === Buttons === */
button, .btn-primary, .btn-secondary, .btn-sm {
  cursor: pointer; border: none; border-radius: var(--radius);
  padding: 8px 14px; font-weight: 600; transition: opacity .15s;
}
button:hover { opacity: .85; }

.btn-primary   { background: var(--accent);  color: #fff; }
.btn-secondary { background: var(--bg3);     color: var(--text); border: 1px solid var(--border); }
.btn-danger    { background: var(--danger);  color: #fff; }
.btn-sm        { padding: 4px 10px; font-size: 12px; background: var(--bg3);
                 border: 1px solid var(--border); color: var(--text); margin: 2px; }
.full-width    { width: 100%; }

/* === Form elements === */
input, select, textarea {
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text); padding: 8px 10px; border-radius: var(--radius);
  width: 100%; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
.field { margin-bottom: 12px; }
.field label { display: block; margin-bottom: 4px; font-size: 13px; color: var(--muted); }
.field-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }

/* === Misc === */
.muted  { color: var(--muted); font-size: 12px; }
.small  { font-size: 12px; }
.alert  { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 12px; }
.alert-error { background: #3a1212; border: 1px solid var(--danger); color: #e87; }

/* === Login page === */
.center-box {
  max-width: 380px; margin: 80px auto 0; padding: 28px;
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
}
.center-box h2 { margin-bottom: 20px; }

/* ══════════════════════════════════════════════════════════════
   VIEW PAGE
══════════════════════════════════════════════════════════════ */
.view-wrap { max-width: 1100px; margin: 0 auto; padding: 12px 12px 40px; }

/* Toolbar */
.toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-bottom: 10px;
}
#camSelect { flex: 1; min-width: 140px; max-width: 260px; font-size: 15px; }

.mode-btns { display: flex; gap: 0; }
.btn-mode  { padding: 8px 18px; background: var(--bg3); border: 1px solid var(--border);
             color: var(--muted); font-weight: 700; letter-spacing: .5px; cursor: pointer; }
.btn-mode:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.btn-mode:last-child  { border-radius: 0 var(--radius) var(--radius) 0; border-left: none; }
.btn-mode.active      { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Player */
.player-box { position: relative; background: #000; width: 100%; }
#player { width: 100%; max-height: 70vh; display: block; }
#live-badge {
  position: absolute; top: 10px; left: 10px;
  background: #e00; color: #fff; font-size: 11px; font-weight: 800;
  padding: 3px 8px; border-radius: 2px; letter-spacing: 1px;
}

/* DVR Panel */
#dvr-panel { margin-top: 12px; }

.dvr-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
#dateSelect { width: auto; min-width: 160px; }

/* Timeline */
.timeline-wrap { background: var(--bg2); border: 1px solid var(--border);
                 border-radius: var(--radius); overflow: hidden; margin-bottom: 10px; }
.timeline-hours {
  display: flex; justify-content: space-between;
  padding: 4px 8px; background: var(--bg3);
  font-size: 11px; color: var(--muted); border-bottom: 1px solid var(--border);
}
.timeline-bar { position: relative; height: 28px; background: var(--bg2); }
.seg-block {
  position: absolute; height: 100%; background: var(--accent);
  opacity: .75; cursor: pointer; transition: opacity .1s;
  min-width: 3px;
}
.seg-block:hover  { opacity: 1; }
.seg-block.active { background: #f80; opacity: 1; }

/* Segment list */
.seg-list { max-height: 200px; overflow-y: auto;
            border: 1px solid var(--border); border-radius: var(--radius); }
.seg-row { display: flex; align-items: center; gap: 10px; padding: 7px 12px;
           border-bottom: 1px solid var(--border); }
.seg-row:last-child { border-bottom: none; }
.seg-row.active { background: var(--bg3); }
.seg-time { font-family: monospace; min-width: 72px; }
.seg-dur  { min-width: 40px; }
.seg-row button { margin-left: auto; }

/* Change PW */
.change-pw-wrap {
  margin-top: 18px; border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px;
}
.change-pw-wrap summary { cursor: pointer; font-size: 14px; }
.change-pw-wrap form { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; align-items: center; }
.change-pw-wrap input { flex: 1; min-width: 160px; }
#pwMsg { font-size: 13px; }

/* Extra HTML zone */
.extra-html { margin-top: 18px; }

/* ══════════════════════════════════════════════════════════════
   ADMIN PAGE
══════════════════════════════════════════════════════════════ */
.admin-wrap { max-width: 1200px; margin: 0 auto; padding: 16px 12px 40px; }
.page-header { display: flex; justify-content: space-between; align-items: center;
               margin-bottom: 14px; }

/* Form panel */
.form-panel {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; margin-bottom: 18px;
}
.form-panel h3 { margin-bottom: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 16px; }
.cam-checks { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 4px; }
.check-label { display: flex; align-items: center; gap: 5px; cursor: pointer; font-size: 14px; }
.check-label input { width: auto; }
.form-actions { display: flex; gap: 10px; margin-top: 14px; }
.form-msg { margin-top: 8px; color: var(--danger); font-size: 13px; }

/* Table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead { background: var(--bg3); }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border);
         vertical-align: middle; white-space: nowrap; }
th { font-size: 12px; text-transform: uppercase; color: var(--muted); letter-spacing: .5px; }
tbody tr:hover { background: var(--bg2); }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.75);
  display: flex; align-items: center; justify-content: center; z-index: 99;
}
.modal-box {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px; text-align: center; max-width: 320px; width: 90%;
}
.modal-box h3 { margin-bottom: 12px; }
.modal-box img { width: 220px; height: 220px; background: #fff; padding: 8px;
                  display: block; margin: 0 auto 10px; }
.qr-url { font-size: 11px; color: var(--muted); word-break: break-all;
           margin-bottom: 14px; }

/* === Responsive === */
@media (max-width: 600px) {
  nav { padding: 0 10px; }
  .admin-wrap, .view-wrap { padding: 8px 8px 30px; }
  th, td { padding: 8px 8px; }
  #player { max-height: 55vw; }
}

/* === DVR permission notice === */
.no-dvr-notice {
  margin-top: 12px; padding: 12px 14px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--muted); font-size: 14px;
}

/* === Permission boxes === */
.perm-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 4px; }
.perm-box {
  flex: 1; min-width: 180px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 12px;
  cursor: pointer; align-items: flex-start; gap: 10px;
}
.perm-box input { margin-top: 3px; }

/* === Segment loading placeholder === */
.seg-loading { padding: 14px; text-align: center; color: var(--muted); }
