/* Camera Dashboard — Dark Theme */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0d1117;
  --surface:   #161b22;
  --surface2:  #21262d;
  --border:    #30363d;
  --border2:   #21262d;
  --text:      #e6edf3;
  --muted:     #8b949e;
  --dim:       #484f58;
  --accent:    #58a6ff;
  --accent-bg: #0d419d;
  --green:     #3fb950;
  --red:       #f85149;
  --yellow:    #d29922;
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* ── Login ─────────────────────────────────────────────────────────── */
.login-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 1rem;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2.5rem 2rem;
  width: 100%; max-width: 340px;
  text-align: center;
}
.login-logo { font-size: 2.5rem; margin-bottom: 0.5rem; }
.login-card h1 { font-size: 1.3rem; font-weight: 600; margin-bottom: 1.75rem; color: var(--text); }
.login-card input {
  display: block; width: 100%;
  padding: 0.6rem 0.875rem;
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  color: var(--text); font-size: 1rem; margin-bottom: 0.875rem;
  transition: border-color 0.15s;
}
.login-card input:focus { outline: none; border-color: var(--accent); }
.login-card button {
  display: block; width: 100%; padding: 0.65rem;
  background: #238636; color: #fff; border: none; border-radius: 6px;
  font-size: 0.95rem; font-weight: 500; cursor: pointer; transition: background 0.15s;
}
.login-card button:hover:not(:disabled) { background: #2ea043; }
.login-card button:disabled { opacity: 0.6; cursor: default; }
.error { color: var(--red); font-size: 0.85rem; margin-top: 0.75rem; }

/* ── Nav ───────────────────────────────────────────────────────────── */
.app { display: flex; flex-direction: column; min-height: 100vh; }

nav {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1.25rem; height: 52px; flex-shrink: 0;
  background: var(--surface); border-bottom: 1px solid var(--border2);
}
.logo { font-weight: 700; font-size: 1rem; color: var(--accent); }
.nav-links { display: flex; gap: 0.25rem; align-items: center; }
.nav-links a {
  color: var(--muted); text-decoration: none; cursor: pointer;
  padding: 0.35rem 0.75rem; border-radius: 6px; font-size: 0.875rem; font-weight: 500;
  transition: color 0.12s, background 0.12s;
}
.nav-links a:hover { color: var(--text); background: var(--surface2); }
.nav-links a.active { color: var(--text); background: var(--surface2); }
.nav-links a.logout { color: var(--red); }
.nav-links a.logout:hover { background: rgba(248,81,73,0.1); }

/* ── Dashboard ─────────────────────────────────────────────────────── */
.dashboard { padding: 1.25rem; flex: 1; }
.cameras-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 300px));
  gap: 1rem;
}
.camera-card {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 8px; overflow: hidden; cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}
.camera-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.thumb-wrap {
  position: relative; aspect-ratio: 16/9;
  background: #000; display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.thumb-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; }
.no-thumb { color: var(--dim); font-size: 0.8rem; }
.cam-label {
  padding: 0.625rem 0.875rem;
  display: flex; justify-content: space-between; align-items: center; gap: 0.5rem;
}
.cam-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cam-last-seen { display: block; font-size: 0.7rem; color: var(--muted); margin-top: 1px; }
.cam-serial { font-size: 0.7rem; color: var(--dim); font-family: monospace; flex-shrink: 0; }

/* ── Camera Detail ─────────────────────────────────────────────────── */
.camera-detail { display: flex; flex-direction: column; flex: 1; overflow: hidden; }
.detail-header {
  display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;
  padding: 0.5rem 1.25rem; flex-shrink: 0;
  background: var(--surface); border-bottom: 1px solid var(--border2);
}
.detail-header h2 { font-size: 1rem; font-weight: 600; flex: 1; }
.back-btn {
  background: none; border: 1px solid var(--border); border-radius: 6px;
  color: var(--muted); padding: 0.3rem 0.75rem; cursor: pointer; font-size: 0.8rem;
  transition: color 0.12s, border-color 0.12s; flex-shrink: 0;
}
.back-btn:hover { color: var(--text); border-color: var(--accent); }

.detail-controls {
  display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap;
}
.detail-controls select,
.detail-controls input[type="time"] {
  padding: 0.3rem 0.5rem;
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  color: var(--text); font-size: 0.8rem;
}
.detail-controls select:focus,
.detail-controls input[type="time"]:focus { outline: none; border-color: var(--accent); }
.filter-label { font-size: 0.75rem; color: var(--muted); }
.btn-small {
  padding: 0.3rem 0.6rem; border-radius: 6px; cursor: pointer; font-size: 0.75rem;
  border: 1px solid var(--border); background: var(--surface2); color: var(--muted);
  transition: color 0.12s;
}
.btn-small:hover { color: var(--text); }
.btn-small.btn-active { color: var(--accent); border-color: var(--accent-bg); }

/* Camera main layout */
.camera-main {
  display: flex; flex-direction: column; flex: 1; overflow: hidden; background: #000;
}

/* Player area */
.player-area {
  flex: 1; display: flex; align-items: center; justify-content: center;
  background: #000; min-height: 0; overflow: hidden;
}
.video-player {
  width: 100%; height: 100%; max-height: 100%; object-fit: contain; display: block;
}
.player-placeholder {
  color: var(--dim); font-size: 0.9rem; text-align: center; padding: 2rem;
}

/* Jump countdown banner */
.jump-banner {
  display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;
  padding: 0.5rem 1.25rem;
  background: rgba(210,153,34,0.12); border-top: 1px solid rgba(210,153,34,0.3);
  font-size: 0.85rem; color: var(--text); flex-shrink: 0;
}
.jump-countdown {
  font-weight: 700; color: var(--yellow); font-variant-numeric: tabular-nums;
  min-width: 2ch;
}
.jump-cancel {
  color: var(--muted); text-decoration: underline; cursor: pointer; margin-left: auto;
}
.jump-cancel:hover { color: var(--text); }

/* Timeline section */
.timeline-section {
  flex-shrink: 0; background: var(--surface); border-top: 1px solid var(--border2);
  padding: 0.75rem 1.25rem 0.625rem;
  display: flex; flex-direction: column; gap: 0.5rem;
}

.timeline-wrap { display: flex; flex-direction: column; gap: 4px; }

.timeline-bar {
  position: relative; height: 28px; cursor: ew-resize; user-select: none;
  background: var(--surface2); border-radius: 4px; overflow: hidden;
  cursor: crosshair; border: 1px solid var(--border2);
}
.timeline-bar:hover { border-color: var(--border); }

.tl-seg {
  position: absolute; top: 0; bottom: 0;
  background: var(--green); opacity: 0.75;
  transition: opacity 0.1s;
  min-width: 2px;
}
.tl-seg:hover { opacity: 1; }
.tl-seg-motion { background: var(--yellow); }
.tl-seg-active { opacity: 1; outline: 1px solid #fff; }

.tl-playhead {
  position: absolute; top: 0; bottom: 0; width: 2px;
  background: #fff; pointer-events: none; z-index: 2;
}

.tl-labels {
  position: relative; height: 14px;
}
.tl-label {
  position: absolute; transform: translateX(-50%);
  font-size: 0.65rem; color: var(--dim); white-space: nowrap; pointer-events: none;
}

.tl-footer {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; min-height: 28px;
}
.tl-msg { font-size: 0.8rem; color: var(--muted); flex-shrink: 0; }
.now-playing { font-size: 0.75rem; color: var(--dim); font-family: monospace; flex-shrink: 0; }
.btn-trash {
  background: none; border: 1px solid transparent; color: var(--dim);
  border-radius: 6px; padding: 0.45rem 1rem; cursor: pointer; font-size: 0.85rem;
}
.btn-trash:hover:not(:disabled) { color: var(--red); border-color: rgba(248,81,73,0.3); }

/* Motion event markers row */
.tl-markers-row {
  position: relative; height: 10px;
}
.tl-event-marker {
  position: absolute; top: 0; width: 8px; height: 8px;
  background: var(--yellow); border-radius: 50%;
  transform: translateX(-50%); cursor: pointer;
  opacity: 0.85; transition: opacity 0.1s, transform 0.1s;
}
.tl-event-marker:hover { opacity: 1; transform: translateX(-50%) scale(1.4); }

/* Motion events collapsible panel */
.motion-events-section {
  border-top: 1px solid var(--border2); padding-top: 0.5rem;
}
.motion-events-toggle {
  background: none; border: none; color: var(--muted);
  font-size: 0.8rem; cursor: pointer; padding: 0.25rem 0;
  width: 100%; text-align: left;
}
.motion-events-toggle:hover { color: var(--text); }
.motion-events-list {
  display: flex; flex-wrap: wrap; gap: 0.5rem;
  padding: 0.5rem 0; max-height: 200px; overflow-y: auto;
}
.motion-event-card {
  display: flex; align-items: center; gap: 0.5rem;
  background: var(--surface2); border: 1px solid var(--border2);
  border-radius: 6px; padding: 0.375rem 0.5rem;
  cursor: pointer; transition: border-color 0.1s, background 0.1s;
  min-width: 160px; max-width: 200px;
}
.motion-event-card:hover { background: var(--surface); border-color: var(--border); }
.motion-event-card.active { border-color: var(--yellow); background: rgba(210,153,34,0.1); }
.mev-thumb {
  width: 56px; height: 36px; flex-shrink: 0;
  background: var(--bg); border-radius: 3px; overflow: hidden;
}
.mev-thumb img { width: 100%; height: 100%; object-fit: cover; }
.mev-thumb-placeholder {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; color: var(--dim);
}
.mev-info { display: flex; flex-direction: column; gap: 0.1rem; min-width: 0; }
.mev-time { font-family: monospace; font-size: 0.75rem; color: var(--text); white-space: nowrap; }
.mev-dur  { font-size: 0.7rem; color: var(--dim); }

/* Video info overlay */
.player-area { position: relative; }
.video-info-overlay {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,0.78); backdrop-filter: blur(4px);
  padding: 0.5rem 0.875rem; display: flex; flex-direction: column; gap: 0.2rem;
  pointer-events: none;
}
.vi-row {
  display: flex; justify-content: space-between; gap: 1rem;
  font-size: 0.75rem; font-family: monospace;
}
.vi-row span:first-child { color: var(--dim); }
.vi-row span:last-child  { color: var(--text); }
.vi-key span:last-child  { color: var(--muted); font-size: 0.65rem; word-break: break-all; text-align: right; }

/* Active-outline state for info/download buttons */
.btn-active-outline { color: var(--accent) !important; border-color: var(--accent) !important; }

/* Download panel */
.download-panel {
  border-top: 1px solid var(--border2); padding-top: 0.5rem;
  display: flex; flex-direction: column; gap: 0.375rem;
}
.dp-header {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 0.8rem; color: var(--muted);
}
.dp-close {
  background: none; border: none; color: var(--dim); cursor: pointer;
  font-size: 0.85rem; padding: 0.1rem 0.3rem; border-radius: 4px;
}
.dp-close:hover { color: var(--text); }
.dp-list {
  display: flex; flex-direction: column; gap: 0.25rem;
  max-height: 220px; overflow-y: auto;
}
.dp-item {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.3rem 0.4rem; border-radius: 5px; cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.1s, border-color 0.1s;
}
.dp-item:hover { background: var(--surface2); }
.dp-item.selected { background: rgba(88,166,255,0.07); border-color: rgba(88,166,255,0.2); }
.dp-item.current  { border-color: rgba(63,185,80,0.35); }
.dp-item input[type="checkbox"] { flex-shrink: 0; accent-color: var(--accent); cursor: pointer; }
.dp-thumb {
  width: 64px; height: 40px; flex-shrink: 0;
  background: var(--bg); border-radius: 3px; overflow: hidden;
}
.dp-thumb img { width: 100%; height: 100%; object-fit: cover; }
.dp-thumb-ph {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; color: var(--dim);
}
.dp-meta { display: flex; flex-direction: column; gap: 0.1rem; flex: 1; min-width: 0; }
.dp-time { font-family: monospace; font-size: 0.75rem; color: var(--text); white-space: nowrap; }
.dp-size { font-size: 0.7rem; color: var(--dim); }
.dp-now  { font-size: 0.7rem; color: var(--green); flex-shrink: 0; }
.dp-footer {
  display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; padding-top: 0.125rem;
}
.dp-btn {
  padding: 0.35rem 0.875rem; border-radius: 6px; cursor: pointer; font-size: 0.8rem;
  border: 1px solid var(--accent-bg); background: rgba(88,166,255,0.1); color: var(--accent);
  transition: background 0.12s;
}
.dp-btn:hover:not(:disabled) { background: rgba(88,166,255,0.18); }
.dp-btn:disabled { opacity: 0.5; cursor: default; }
.dp-msg { font-size: 0.8rem; color: var(--green); }

/* ── Trash ───────────────────────────────────────────────────────── */
.trash-view { flex: 1; overflow-y: auto; }
.trash-list { padding: 0.5rem 1.25rem; display: flex; flex-direction: column; gap: 0.5rem; max-width: 720px; }
.trash-item {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  background: var(--surface); border: 1px solid var(--border2); border-radius: 6px;
  padding: 0.625rem 1rem;
}
.trash-item-info { display: flex; flex-direction: column; gap: 0.15rem; min-width: 0; }
.trash-item-key { font-family: monospace; font-size: 0.85rem; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trash-item-path { font-size: 0.7rem; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trash-item-date { font-size: 0.75rem; color: var(--muted); }
.trash-item-actions { display: flex; gap: 0.5rem; flex-shrink: 0; }
.btn-restore {
  padding: 0.35rem 0.75rem; border-radius: 6px; cursor: pointer; font-size: 0.8rem;
  border: 1px solid var(--border); background: var(--surface2); color: var(--text);
}
.btn-restore:hover { border-color: var(--accent); color: var(--accent); }
.btn-delete-forever {
  padding: 0.35rem 0.75rem; border-radius: 6px; cursor: pointer; font-size: 0.8rem;
  border: 1px solid transparent; background: rgba(248,81,73,0.1); color: var(--red);
}
.btn-delete-forever:hover { background: rgba(248,81,73,0.2); }

/* Player */
.player-panel {
  flex: 1; display: flex; flex-direction: column; gap: 0.875rem;
  padding: 1rem; background: #000; overflow-y: auto;
}
.player-panel.placeholder {
  align-items: center; justify-content: center; color: var(--dim);
  background: var(--bg); font-size: 0.9rem;
}
.video-player { width: 100%; aspect-ratio: 16/9; max-height: calc(100vh - 200px); object-fit: contain; background: #000; border-radius: 4px; }
.player-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.player-actions button {
  padding: 0.45rem 1rem; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 0.85rem; transition: background 0.12s;
}
.player-actions button:hover:not(:disabled) { background: var(--surface2); }
.player-actions button:disabled { opacity: 0.5; cursor: default; }
.mark-msg { font-size: 0.85rem; padding: 0.25rem 0; }
.mark-msg.success { color: var(--green); }
.mark-msg.error   { color: var(--red); }

/* ── Events ──────────────────────────────────────────────────────── */
.events-view { display: flex; flex-direction: column; flex: 1; overflow: hidden; }
.page-header {
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
  padding: 0.875rem 1.25rem; border-bottom: 1px solid var(--border2);
  background: var(--surface); flex-shrink: 0;
}
.page-header h2 { font-size: 1rem; font-weight: 600; }
.events-filters { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.events-filters select, .events-filters input {
  padding: 0.4rem 0.7rem;
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  color: var(--text); font-size: 0.875rem;
}
.events-body {
  display: flex; flex: 1; overflow: hidden; gap: 0;
}
.events-list {
  width: 320px; min-width: 280px; flex-shrink: 0;
  border-right: 1px solid var(--border2); overflow-y: auto; padding: 0.5rem 0;
}
.event-item {
  padding: 0.625rem 1rem; cursor: pointer; border-bottom: 1px solid var(--border2);
  transition: background 0.1s;
}
.event-item:hover { background: var(--surface); }
.event-item.active { background: var(--accent-bg); }
.ev-cam { font-weight: 500; color: var(--accent); font-size: 0.875rem; }
.ev-time { color: var(--muted); font-family: monospace; font-size: 0.8rem; }
.ev-size { color: var(--dim); font-size: 0.75rem; }
.event-player {
  flex: 1; padding: 1rem; display: flex; flex-direction: column;
  gap: 0.875rem; background: #000; overflow-y: auto;
}

/* ── Settings ────────────────────────────────────────────────────── */
.settings-view { flex: 1; padding: 1.5rem; overflow-y: auto; max-width: 640px; }
.settings-view h2 { font-size: 1.1rem; font-weight: 600; margin-bottom: 1.5rem; }
.settings-view section { margin-bottom: 2rem; }
.settings-view h3 {
  font-size: 0.75rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--dim); margin-bottom: 0.5rem;
}
.section-note { font-size: 0.8rem; color: var(--dim); margin-bottom: 0.875rem; }
.name-rows { display: flex; flex-direction: column; gap: 0.5rem; }
.name-row { display: flex; align-items: center; gap: 0.75rem; }
.serial-badge {
  font-family: monospace; font-size: 0.75rem; color: var(--muted);
  background: var(--surface2); padding: 0.2rem 0.5rem; border-radius: 4px;
  min-width: 175px;
}
.name-row input {
  flex: 1; padding: 0.4rem 0.7rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
  color: var(--text); font-size: 0.875rem; transition: border-color 0.12s;
}
.name-row input:focus { outline: none; border-color: var(--accent); }
.rename-ok { color: var(--green); font-size: 0.85rem; }
.retention-table {
  background: var(--surface); border: 1px solid var(--border2);
  border-radius: 8px; overflow: hidden;
}
.ret-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.625rem 1rem; border-bottom: 1px solid var(--border2); font-size: 0.875rem;
}
.ret-row:last-child { border-bottom: none; }
.ret-row span:first-child { color: var(--muted); }
.ret-row em { color: var(--dim); font-style: normal; }
.ret-val { font-weight: 500; color: var(--text); }

/* Delete camera button in settings */
.btn-delete-cam {
  background: none; border: 1px solid transparent;
  color: var(--dim); border-radius: 6px; padding: 0.3rem 0.5rem;
  cursor: pointer; font-size: 0.85rem; flex-shrink: 0;
  transition: color 0.12s, border-color 0.12s;
}
.btn-delete-cam:hover { color: var(--red); border-color: rgba(248,81,73,0.3); }

/* Confirmation modal */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.7); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.modal-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 2rem 1.75rem;
  width: 100%; max-width: 400px; text-align: center;
  box-shadow: 0 24px 64px rgba(0,0,0,0.6);
}
.modal-danger-icon { font-size: 2.5rem; margin-bottom: 0.75rem; }
.modal-card h2 { font-size: 1.15rem; font-weight: 700; margin-bottom: 1rem; color: var(--text); }
.modal-warning {
  font-size: 0.875rem; color: var(--muted); line-height: 1.6;
  margin-bottom: 0.625rem;
}
.modal-warning strong { color: var(--text); }
.modal-cam-name {
  font-size: 1rem; font-weight: 600; color: var(--red);
  margin: 1rem 0 0.25rem;
}
.modal-cam-serial {
  font-family: monospace; font-size: 0.75rem; color: var(--dim); margin-bottom: 1.5rem;
}
.modal-actions { display: flex; gap: 0.75rem; justify-content: center; }
.btn-modal-cancel {
  padding: 0.55rem 1.25rem; border-radius: 8px; cursor: pointer; font-size: 0.875rem;
  border: 1px solid var(--border); background: var(--surface2); color: var(--text);
  transition: background 0.12s;
}
.btn-modal-cancel:hover:not(:disabled) { background: var(--border); }
.btn-modal-cancel:disabled { opacity: 0.5; cursor: default; }
.btn-modal-danger {
  padding: 0.55rem 1.25rem; border-radius: 8px; cursor: pointer; font-size: 0.875rem;
  border: 1px solid rgba(248,81,73,0.4); background: rgba(248,81,73,0.15); color: var(--red);
  font-weight: 600; transition: background 0.12s;
}
.btn-modal-danger:hover:not(:disabled) { background: rgba(248,81,73,0.28); }
.btn-modal-danger:disabled { opacity: 0.5; cursor: default; }

/* ── Shared helpers ──────────────────────────────────────────────── */
.no-data, .empty-state {
  color: var(--dim); font-size: 0.875rem; padding: 1.25rem;
}
.empty-state { max-width: 480px; line-height: 1.7; }
.loading { color: var(--accent); font-size: 0.85rem; padding: 1rem; }
.panel > .loading, .panel > .no-data { padding: 0.75rem 0.875rem; }

/* Scrollbars */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }
