/* CDIT Sentinel VMS — matches ui/styles.py (warm eye-comfort theme) */
:root {
  --background: #1f1e1c;
  --panel: #2a2926;
  --panel-border: #3f3d38;
  --text: #d6d2c8;
  --text-dim: #9a968c;
  --accent: #8faa8c;
  --accent-soft: #353833;
  --success: #7dab83;
  --warning: #c9a86a;
  --danger: #c07a6a;
  --online: #7dab83;
  --offline: #a08878;
  --video-bg: #181715;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: "Segoe UI", Calibri, Arial, sans-serif; font-size: 13px; background: var(--background); color: var(--text); min-height: 100vh; }
.hidden { display: none !important; }
a { color: var(--accent); }
label { display: block; color: var(--text-dim); font-size: 12px; margin: 8px 0 4px; }
hr { border: none; border-top: 1px solid var(--panel-border); margin: 12px 0; }

.panelFrame { background: var(--panel); border: 1px solid var(--panel-border); border-radius: 6px; padding: 10px; }
.panel-title { font-weight: bold; color: var(--accent); font-size: 14px; margin-bottom: 8px; }
.page-title { font-size: 22px; font-weight: bold; color: var(--accent); }
.hint { color: var(--text-dim); font-size: 11px; }
.center { text-align: center; }
.error { color: var(--danger); font-size: 12px; margin-top: 8px; }
.full-width { width: 100%; margin-bottom: 4px; }

input, select, textarea {
  background: var(--panel); color: var(--text); border: 1px solid var(--panel-border);
  padding: 6px 8px; border-radius: 4px; font-size: 13px;
}
input[type="date"], input[type="time"] {
  color-scheme: dark;
  min-height: 38px;
  width: 100%;
  cursor: pointer;
}
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator {
  filter: invert(0.75);
  opacity: 1;
  cursor: pointer;
}
label[for] { cursor: pointer; }
.form-input { width: 100%; max-width: 400px; margin-bottom: 8px; }
.form-stack label { margin-top: 6px; }

.btn {
  background: var(--accent-soft); color: var(--text); border: 1px solid var(--panel-border);
  padding: 8px 16px; border-radius: 4px; cursor: pointer; font-size: 13px;
}
.btn:hover { background: var(--accent); color: var(--background); border-color: var(--accent); }
.btn.primary { background: var(--accent-soft); font-weight: normal; }
.btn.layoutBtn { padding: 4px 10px; min-width: 32px; background: var(--panel); }
.btn.layoutBtn.active, .grid-btn.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: var(--accent-soft); }
.btn.toggle.on { color: var(--online); border-color: var(--online); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Login / screens */
.screen { min-height: 100vh; }
#login-screen { position: relative; z-index: 20; }
#app-screen { position: relative; z-index: 1; }
.login-card { max-width: 400px; margin: 10vh auto; padding: 24px; }
.login-card h1 { color: var(--accent); font-size: 20px; margin-bottom: 4px; }
.subtitle { color: var(--text-dim); margin-bottom: 16px; }

/* Top bar */
.topbar { display: flex; align-items: center; gap: 8px; padding: 6px 12px; background: var(--panel); border-bottom: 1px solid var(--panel-border); flex-wrap: wrap; }
.brand { font-weight: bold; color: var(--accent); }
.nav-tabs { display: flex; gap: 2px; flex: 1; flex-wrap: wrap; }
.tab { background: var(--panel); color: var(--text-dim); border: none; padding: 8px 16px; border-radius: 4px 4px 0 0; cursor: pointer; }
.tab.active { background: var(--accent-soft); color: var(--text); }
.topbar-right { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-dim); }
.badge { background: var(--background); border: 1px solid var(--panel-border); padding: 2px 8px; border-radius: 999px; font-size: 11px; }

.content { padding: 8px; }
.page { display: none; }
.page.active { display: block; }

/* Dashboard */
.dash-scroll { max-height: calc(100vh - 70px); overflow-y: auto; padding: 12px 16px; }
.dash-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 12px; }
.kpi-card { min-height: 88px; padding: 12px 8px; }
.kpi-card .k-title { color: var(--text-dim); font-size: 11px; }
.kpi-card .k-val { font-size: 26px; font-weight: bold; margin: 4px 0; }
.kpi-card .k-hint { color: var(--text-dim); font-size: 9px; }
.charts-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.chart-panel { min-height: 280px; padding: 8px; }
.dash-bottom { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.activity-list { list-style: none; font-size: 12px; max-height: 220px; overflow-y: auto; }
.activity-list li { padding: 6px 0; border-bottom: 1px solid var(--panel-border); }
.health-list .health-row { display: flex; justify-content: space-between; padding: 6px 0; }
.health-list .health-name { color: var(--text-dim); }
.health-online { color: var(--online); font-weight: bold; }
.health-warning { color: var(--warning); font-weight: bold; }
.health-dim { color: var(--text-dim); font-weight: bold; }

/* Live */
.live-layout { display: grid; grid-template-columns: 200px 1fr 220px; gap: 8px; min-height: calc(100vh - 80px); }
.sidebar { display: flex; flex-direction: column; overflow: hidden; }
.sidebar-list { list-style: none; overflow-y: auto; flex: 1; font-size: 12px; }
.sidebar-list li, .cam-item { padding: 8px; border-bottom: 1px solid var(--panel-border); cursor: pointer; }
.cam-item.selected { background: var(--accent-soft); border-left: 3px solid var(--accent); }
.toolbar { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.sep { color: var(--panel-border); }
.camera-grid { display: grid; gap: 6px; }
.camera-grid.grid-1 { grid-template-columns: 1fr; }
.camera-grid.grid-2 { grid-template-columns: repeat(2, 1fr); }
.camera-grid.grid-4 { grid-template-columns: repeat(2, 1fr); }
.camera-grid.grid-9 { grid-template-columns: repeat(3, 1fr); }
.camera-grid.grid-16 { grid-template-columns: repeat(4, 1fr); }
.cam-cell { background: var(--video-bg); border: 1px solid var(--panel-border); border-radius: 6px; overflow: hidden; aspect-ratio: 16/9; position: relative; cursor: pointer; }
.cam-cell.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.cam-cell img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; user-select: none; -webkit-user-drag: none; }
.cam-label { position: absolute; bottom: 0; left: 0; right: 0; padding: 4px 8px; background: rgba(0,0,0,0.75); font-size: 11px; display: flex; justify-content: space-between; }
.events-feed .event-item { padding: 6px 8px; border-bottom: 1px solid var(--panel-border); font-size: 11px; }
.events-feed .human { color: var(--online); }
.events-feed .plate { color: var(--warning); }
.events-feed .recording { color: var(--accent); }
.events-feed .upload { color: var(--online); }
.events-feed .upload_fail { color: var(--danger); }

.grid-page-bar {
  display: flex; align-items: center; gap: 8px; margin-bottom: 6px; flex-wrap: wrap;
}
.cam-item.disabled-cam { opacity: 0.55; }
.cam-item .cam-actions { font-size: 10px; margin-top: 4px; }
.cam-item .cam-actions button {
  background: transparent; border: 1px solid var(--panel-border); color: var(--text-dim);
  padding: 2px 6px; border-radius: 3px; cursor: pointer; font-size: 10px;
}

/* Split pages (Events / Playback) */
.split-page { display: grid; grid-template-columns: 1fr 2fr; gap: 8px; min-height: calc(100vh - 80px); }
.split-left, .split-right { display: flex; flex-direction: column; overflow-x: hidden; overflow-y: auto; }
.inner-list { flex: 1; overflow-y: auto; margin: 8px 0; min-height: 200px; background: var(--panel); border: 1px solid var(--panel-border); border-radius: 4px; }
.list-item { padding: 8px; border-bottom: 1px solid var(--panel-border); font-size: 12px; cursor: pointer; white-space: pre-wrap; }
.list-item:hover, .list-item.selected { background: var(--accent-soft); border-left: 3px solid var(--accent); }
.list-item.detection { color: var(--online); }
.list-item.plate { color: var(--warning); }
.list-item.recording { color: var(--accent); }

/* Playback video */
.video-wrap { position: relative; background: var(--video-bg); min-height: 400px; display: flex; align-items: center; justify-content: center; border-radius: 4px; margin-bottom: 8px; }
.playback-video { width: 100%; max-height: 65vh; display: none; object-fit: contain; background: #111; }
.playback-video.active { display: block; }
.video-placeholder { color: var(--text-dim); }
.seek-slider { width: 100%; margin: 4px 0; accent-color: var(--accent); }
.player-controls { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

/* Events detail */
.event-detail-box { background: var(--panel); border: 1px solid var(--panel-border); border-radius: 4px; padding: 10px; min-height: 80px; margin: 8px 0; font-family: inherit; font-size: 12px; white-space: pre-wrap; color: var(--text); }

/* Settings tabs */
.settings-tabbar { display: flex; gap: 2px; margin-bottom: 8px; flex-wrap: wrap; border-bottom: 1px solid var(--panel-border); padding-bottom: 0; }
.stab { background: var(--panel); color: var(--text-dim); border: 1px solid var(--panel-border); border-bottom: none; padding: 8px 16px; border-radius: 4px 4px 0 0; cursor: pointer; }
.stab.active { background: var(--accent-soft); color: var(--text); }
.stab-panel { display: none; padding: 12px; }
.stab-panel.active { display: block; }

/* Camera settings */
.cam-settings-header { display: flex; justify-content: space-between; align-items: center; }
.filter-row { display: flex; gap: 8px; align-items: center; margin: 8px 0; flex-wrap: wrap; }
.cam-split { display: grid; grid-template-columns: 280px 1fr; gap: 8px; min-height: 500px; }
.cam-tree { max-height: 420px; overflow-y: auto; margin: 8px 0; font-size: 12px; }
.tree-loc { color: var(--text-dim); padding: 6px 4px; font-weight: bold; }
.tree-cam { padding: 6px 8px 6px 16px; cursor: pointer; border-bottom: 1px solid var(--panel-border); }
.tree-cam.selected { background: var(--accent-soft); border-left: 3px solid var(--accent); }
.detail-tabs { display: flex; gap: 2px; margin-bottom: 8px; }
.dtab { background: var(--panel); border: 1px solid var(--panel-border); color: var(--text-dim); padding: 6px 12px; cursor: pointer; border-radius: 4px 4px 0 0; }
.dtab.active { background: var(--accent-soft); color: var(--text); }
.dtab-panel { display: none; }
.dtab-panel.active { display: block; }
.url-preview { color: var(--text-dim); font-size: 10px; padding: 6px; white-space: pre-wrap; }
.url-hint { color: var(--warning); font-size: 10px; }

/* AI grid */
.ai-grid-header { display: grid; grid-template-columns: 2fr repeat(4, 1fr); gap: 4px; padding: 8px; text-align: center; font-size: 11px; margin-bottom: 4px; }
.ai-grid-header span:first-child { text-align: left; }
.ai-grid-row { display: grid; grid-template-columns: 2fr repeat(4, 1fr); gap: 4px; padding: 6px 8px; border-bottom: 1px solid var(--panel-border); align-items: center; }
.ai-grid-row input { margin: 0 auto; }
.ai-grid-body { max-height: 400px; overflow-y: auto; }

/* Users */
.guide-box { margin-bottom: 12px; }
.users-split { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.role-detail-box { background: var(--background); padding: 8px; border-radius: 4px; font-size: 10px; color: var(--text-dim); margin: 8px 0; white-space: pre-wrap; }
.role-card { margin-bottom: 12px; padding: 12px; }
.role-card h3 { color: var(--accent); font-size: 14px; }
.role-card p { margin: 4px 0; }
.role-card .perm { color: var(--text-dim); font-size: 11px; padding-left: 8px; }

.btn-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }

.fs-overlay {
  position: fixed; inset: 0; width: 100vw; height: 100vh;
  background: #000; z-index: 99999;
  display: flex; flex-direction: column;
}
.fs-overlay.hidden { display: none !important; }
.fs-topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px; background: rgba(0,0,0,0.85); flex-shrink: 0;
}
.fs-video-wrap {
  flex: 1; display: flex; align-items: center; justify-content: center;
  width: 100%; min-height: 0; background: #000;
}
.fs-overlay img {
  width: 100%; height: 100%; object-fit: contain; display: block;
  image-rendering: auto;
}
.fs-hint {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
  color: rgba(255,255,255,0.55); font-size: 11px; pointer-events: none;
}
.fs-video-wrap { position: relative; }
.fs-label { color: #fff; font-size: 14px; font-weight: bold; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--accent); color: var(--text);
  padding: 12px 20px; border-radius: 6px; z-index: 100000; max-width: 90vw;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5); font-size: 13px;
}
.toast.error { border-color: var(--danger); color: var(--danger); }
.toast.success { border-color: var(--online); color: var(--online); }

@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .charts-row, .dash-bottom, .split-page, .cam-split, .users-split, .live-layout { grid-template-columns: 1fr; }
  .events-sidebar { display: none; }
}
