/* Darvoza dashboard — dense monitoring UI, dark by default, light supported. */

:root {
  color-scheme: dark light;

  --bg: #0d1117;
  --bg-raised: #151b23;
  --bg-inset: #0a0e14;
  --border: #232c38;
  --border-strong: #2f3a49;

  --text: #e6edf3;
  --text-dim: #8b98a9;
  --text-faint: #5c6a7d;

  --accent: #3b82f6;
  --accent-dim: #1d4ed8;
  --accent-text: #ffffff;

  --ok: #22c55e;
  --ok-bg: rgba(34, 197, 94, 0.12);
  --warn: #f59e0b;
  --warn-bg: rgba(245, 158, 11, 0.12);
  --bad: #ef4444;
  --bad-bg: rgba(239, 68, 68, 0.12);
  --idle: #64748b;
  --idle-bg: rgba(100, 116, 139, 0.12);

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);

  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f8fa;
    --bg-raised: #ffffff;
    --bg-inset: #eef1f5;
    --border: #d8dee6;
    --border-strong: #c2cbd6;
    --text: #1c2128;
    --text-dim: #57606a;
    --text-faint: #8b949e;
    --shadow: 0 1px 3px rgba(16, 22, 26, 0.1);
  }
}

/* Explicit override from the Settings toggle (see app.js initTheme()) - wins
   over the OS preference above regardless of it, since a person who reached
   for the toggle wants THIS, not "whatever their OS happens to be set to".
   Higher specificity than the bare :root inside the media query above
   already guarantees the win; kept listed after it anyway for readability -
   override rules read naturally following the default they override. */
:root[data-theme="light"] {
  --bg: #f6f8fa;
  --bg-raised: #ffffff;
  --bg-inset: #eef1f5;
  --border: #d8dee6;
  --border-strong: #c2cbd6;
  --text: #1c2128;
  --text-dim: #57606a;
  --text-faint: #8b949e;
  --shadow: 0 1px 3px rgba(16, 22, 26, 0.1);
}

:root[data-theme="dark"] {
  --bg: #0d1117;
  --bg-raised: #151b23;
  --bg-inset: #0a0e14;
  --border: #232c38;
  --border-strong: #2f3a49;
  --text: #e6edf3;
  --text-dim: #8b98a9;
  --text-faint: #5c6a7d;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 22px; font-weight: 650; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 15px; font-weight: 600; margin: 0; }
h3 { font-size: 13px; font-weight: 600; margin: 0; }

/* ------------------------------------------------------------------ shell */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 216px;
  flex-shrink: 0;
  background: var(--bg-raised);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.brand-name {
  font-size: 16px; font-weight: 680; letter-spacing: -0.02em;
}
.brand-tenant {
  font-size: 12px; color: var(--text-dim); margin-top: 1px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* The logo is black line art. Rather than ship a second white version to keep
   in sync, invert it in dark mode - it's pure black-on-transparent, so the
   inverse is exactly the white lockup, and there's only ever one file. */
.brand-mark { flex-shrink: 0; }
.brand-mark, .auth-mark { height: auto; }
@media (prefers-color-scheme: dark) {
  .brand-mark, .auth-mark { filter: invert(1); }
}
:root[data-theme="dark"] .brand-mark,
:root[data-theme="dark"] .auth-mark { filter: invert(1); }
:root[data-theme="light"] .brand-mark,
:root[data-theme="light"] .auth-mark { filter: none; }

/* ----------------------------------------------------------- device filter */
/* Scopes every page (Overview, Live, Reports, Cameras) to one or more stores
   at once - see DeviceFilter in app.js. Lives right under the brand so it
   reads as "this is what you're looking at", not just another nav item. */

.device-filter { position: relative; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.device-filter-btn {
  display: flex; align-items: center; gap: 7px; width: 100%;
  padding: 7px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--bg-inset);
  color: var(--text); font-size: 12.5px; font-weight: 600;
  font-family: inherit; cursor: pointer; text-align: left;
  transition: background 0.12s, border-color 0.12s;
}
.device-filter-btn:hover { background: var(--border); }
.device-filter-btn:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.16); }
.device-filter-btn .glyph { flex-shrink: 0; opacity: 0.75; font-size: 13px; line-height: 1; }
.device-filter-btn span:nth-child(2) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-filter-btn .chev { margin-left: auto; color: var(--text-faint); font-size: 10px; flex-shrink: 0; transition: transform 0.12s; }
.device-filter-btn.open .chev { transform: rotate(180deg); }
/* Filtered down to something other than "all" - an accent dot so it reads at
   a glance that you're not looking at the whole company, without having to
   parse the label text every time. */
.device-filter-btn.scoped { border-color: var(--accent); background: rgba(59, 130, 246, 0.1); }
.device-filter-btn.scoped .glyph { opacity: 1; color: var(--accent); }
.device-filter-menu {
  position: absolute; top: 100%; left: 14px; right: 14px; margin-top: 4px;
  background: var(--bg-raised); border: 1px solid var(--border-strong);
  border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  padding: 6px; z-index: 50; max-height: 300px; overflow-y: auto;
  animation: df-open 0.1s ease-out;
}
@keyframes df-open { from { opacity: 0; transform: translateY(-3px); } }
.df-label {
  padding: 6px 8px 4px; font-size: 10.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-faint);
}
.df-row {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 8px; border-radius: var(--radius-sm);
  font-size: 13px; cursor: pointer;
}
.df-row:hover { background: var(--bg-inset); }
.df-row input { width: auto; flex-shrink: 0; accent-color: var(--accent); }
.df-row .store-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--idle); flex-shrink: 0; }
.df-row .store-dot.online { background: var(--ok); }
.df-row .pill { margin-left: auto; }
.df-sep { height: 1px; background: var(--border); margin: 4px 2px; }
.df-empty { padding: 10px 8px; font-size: 12.5px; color: var(--text-faint); }

/* Same filter widget, reused per-row in Settings > Stores & access - a plain
   positioning wrapper instead of the sidebar's own padding/border chrome. */
.sa-wrap { position: relative; display: inline-block; }
.sa-wrap .device-filter-btn { width: auto; padding: 5px 9px; font-size: 12px; }
.sa-wrap .device-filter-menu { left: 0; right: auto; width: 230px; top: calc(100% + 4px); }

.nav { padding: 10px 10px; flex: 1; display: flex; flex-direction: column; gap: 1px; }
.nav a {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 10px; border-radius: var(--radius-sm);
  color: var(--text-dim); font-weight: 500; font-size: 13.5px;
}
.nav a:hover { background: var(--bg-inset); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent); color: var(--accent-text); }
.nav a.active .nav-icon { opacity: 1; }
.nav-icon { width: 16px; text-align: center; opacity: 0.7; font-size: 14px; }
.nav-sep { height: 1px; background: var(--border); margin: 8px 10px; }

.sidebar-foot {
  padding: 12px 14px; border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text-dim);
}
.sidebar-foot .who { color: var(--text); overflow: hidden; text-overflow: ellipsis; }
.sidebar-foot .role { text-transform: capitalize; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.content { padding: 22px 26px 60px; max-width: 1500px; width: 100%; }

.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 20px; flex-wrap: wrap;
}
.page-head p.sub { margin: 3px 0 0; color: var(--text-dim); font-size: 13px; }

/* ------------------------------------------------------------- engine bar */

.engine-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 26px; font-size: 13px;
  border-bottom: 1px solid var(--border);
  background: var(--warn-bg); color: var(--text);
}
.engine-bar.ok { background: var(--ok-bg); }
.engine-bar strong { font-weight: 600; }
.engine-bar .spacer { flex: 1; }

/* ------------------------------------------------------------------ cards */

.panel {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 18px;
  overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.panel-head .spacer { flex: 1; }
.panel-body { padding: 16px; }
.panel-body.flush { padding: 0; }

.grid { display: grid; gap: 14px; }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.grid.cards { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.grid.cams { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }

.stat {
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
}
.stat-num { font-size: 27px; font-weight: 660; letter-spacing: -0.02em; line-height: 1.1; }
.stat-label { font-size: 12px; color: var(--text-dim); margin-top: 3px; }
.stat-sub { font-size: 11.5px; color: var(--text-faint); margin-top: 6px; }

/* ----------------------------------------------------------------- pills */

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 20px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
  background: var(--idle-bg); color: var(--idle);
}
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.accent { background: rgba(59, 130, 246, 0.14); color: var(--accent); }

.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.dot.pulse { animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* ---------------------------------------------------------------- tables */

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th {
  text-align: left; font-weight: 600; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-faint); padding: 9px 16px;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
td { padding: 10px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg-inset); }
td.num { font-variant-numeric: tabular-nums; }
td.right, th.right { text-align: right; }

/* --------------------------------------------------------------- controls */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--bg-inset);
  color: var(--text); font-size: 13px; font-weight: 550;
  font-family: inherit; cursor: pointer; white-space: nowrap;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover:not(:disabled) { background: var(--border); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover:not(:disabled) { background: var(--accent-dim); }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn.danger:hover:not(:disabled) { background: var(--bad-bg); }
.btn.sm { padding: 4px 9px; font-size: 12px; }

input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="url"], select, textarea {
  width: 100%; padding: 8px 11px;
  background: var(--bg-inset); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font-size: 13.5px; font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.16);
}
input[type="file"] { font-size: 13px; color: var(--text-dim); width: 100%; }
label.field { display: block; margin-bottom: 12px; }
label.field > span {
  display: block; font-size: 12px; font-weight: 600;
  color: var(--text-dim); margin-bottom: 4px;
}
label.field .hint { font-weight: 400; color: var(--text-faint); font-size: 11.5px; }
label.check {
  display: flex; align-items: center; gap: 7px; font-size: 13px; cursor: pointer;
  margin-bottom: 8px;
}
label.check input { width: auto; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-actions { display: flex; gap: 8px; align-items: center; margin-top: 4px; }

/* ---------------------------------------------------------------- video */

.cam-card {
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
}
.cam-video {
  position: relative; aspect-ratio: 16 / 9;
  background: var(--bg-inset); display: flex;
  align-items: center; justify-content: center; overflow: hidden;
}
.cam-video img { width: 100%; height: 100%; object-fit: contain; display: block; }
.cam-video .placeholder {
  color: var(--text-faint); font-size: 13px; text-align: center;
  padding: 20px; line-height: 1.6;
}
.cam-video .badge {
  position: absolute; top: 8px; left: 8px;
  background: rgba(0, 0, 0, 0.72); color: #fff;
  padding: 3px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 600;
  display: flex; align-items: center; gap: 5px;
}
.cam-video .fps {
  position: absolute; bottom: 8px; right: 8px;
  background: rgba(0, 0, 0, 0.72); color: #fff;
  padding: 2px 7px; border-radius: 4px;
  font-size: 10.5px; font-family: var(--mono);
}
.cam-meta {
  padding: 10px 13px; display: flex;
  align-items: center; gap: 9px; flex-wrap: wrap;
}
.cam-meta .label { font-weight: 600; font-size: 13.5px; }
.cam-meta .spacer { flex: 1; }

/* --------------------------------------------------------------- ledger */

.ledger-row {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 16px; border-bottom: 1px solid var(--border);
}
.ledger-row:last-child { border-bottom: none; }
.ledger-row:hover { background: var(--bg-inset); }
.ledger-thumb {
  width: 42px; height: 42px; border-radius: var(--radius-sm);
  object-fit: cover; background: var(--bg-inset); flex-shrink: 0;
  border: 1px solid var(--border);
}
.ledger-thumb.empty {
  display: flex; align-items: center; justify-content: center;
  color: var(--text-faint); font-size: 15px;
}
.ledger-main { flex: 1; min-width: 0; }
.ledger-name { font-weight: 600; }
.ledger-detail { font-size: 12px; color: var(--text-dim); }
.ledger-time {
  font-size: 12px; color: var(--text-faint);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}

/* -------------------------------------------------------------- avatars */

.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  object-fit: cover; background: var(--bg-inset);
  border: 1px solid var(--border); flex-shrink: 0;
}
.avatar.lg { width: 60px; height: 60px; }
.avatar.initials {
  display: flex; align-items: center; justify-content: center;
  font-weight: 650; font-size: 13px; color: var(--text-dim);
}
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
.photo-tile { position: relative; }
.photo-tile img {
  width: 100%; aspect-ratio: 1; object-fit: cover;
  border-radius: var(--radius-sm); border: 1px solid var(--border); display: block;
}
.photo-tile .src {
  position: absolute; bottom: 4px; left: 4px;
  background: rgba(0, 0, 0, 0.75); color: #fff;
  font-size: 9.5px; padding: 1px 5px; border-radius: 3px;
}
.photo-tile .rm {
  position: absolute; top: 4px; right: 4px;
  background: rgba(0, 0, 0, 0.75); color: #fff; border: none;
  width: 20px; height: 20px; border-radius: 50%;
  cursor: pointer; font-size: 12px; line-height: 1;
  opacity: 0; transition: opacity 0.12s;
}
.photo-tile:hover .rm { opacity: 1; }

/* ------------------------------------------------------------ utilities */

.empty {
  padding: 34px 20px; text-align: center;
  color: var(--text-faint); font-size: 13px; line-height: 1.7;
}
.empty .big { font-size: 26px; display: block; margin-bottom: 8px; opacity: 0.55; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.dim { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.small { font-size: 12px; }
.row { display: flex; align-items: center; gap: 9px; }
.wrap { flex-wrap: wrap; }
.mt { margin-top: 14px; }
.mb { margin-bottom: 14px; }
.nowrap { white-space: nowrap; }

.code-box {
  font-family: var(--mono); font-size: 17px; font-weight: 600;
  letter-spacing: 0.06em; padding: 11px 15px;
  background: var(--bg-inset); border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm); text-align: center; user-select: all;
}

.callout {
  padding: 11px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg-inset);
  font-size: 13px; line-height: 1.6;
}
.callout.warn { border-color: var(--warn); background: var(--warn-bg); }
.callout.bad { border-color: var(--bad); background: var(--bad-bg); }
.callout.ok { border-color: var(--ok); background: var(--ok-bg); }

pre.snippet {
  background: var(--bg-inset); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 11px 13px;
  font-family: var(--mono); font-size: 12px;
  overflow-x: auto; margin: 8px 0 0; line-height: 1.6;
}

/* --------------------------------------------------------------- modal */

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 100;
}
.modal {
  background: var(--bg-raised); border: 1px solid var(--border-strong);
  border-radius: var(--radius); box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  width: 100%; max-width: 460px; max-height: 90vh; overflow-y: auto;
}
.modal-head {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
}
.modal-head .spacer { flex: 1; }
.modal-body { padding: 18px; }
.modal-foot {
  padding: 13px 18px; border-top: 1px solid var(--border);
  display: flex; gap: 8px; justify-content: flex-end;
}

/* --------------------------------------------------------------- toast */

#toasts {
  position: fixed; bottom: 18px; right: 18px;
  display: flex; flex-direction: column; gap: 8px; z-index: 200;
}
.toast {
  background: var(--bg-raised); border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm); box-shadow: var(--shadow);
  padding: 10px 14px; font-size: 13px; max-width: 380px;
  animation: slide-in 0.16s ease-out;
}
.toast.bad { border-left-color: var(--bad); }
.toast.ok { border-left-color: var(--ok); }
@keyframes slide-in { from { opacity: 0; transform: translateX(12px); } }

/* ---------------------------------------------------------------- auth */

.auth-wrap {
  min-height: 100vh; display: flex;
  align-items: center; justify-content: center; padding: 20px;
}
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px;
}
.auth-mark { display: block; margin-bottom: 6px; }
.auth-sub { color: var(--text-dim); font-size: 13px; margin: 0 0 20px; }
.auth-foot { margin-top: 16px; text-align: center; font-size: 13px; color: var(--text-dim); }

/* ---------------------------------------------------------------- chart */

.spark { display: flex; align-items: flex-end; gap: 3px; height: 56px; }
.spark-bar { flex: 1; background: var(--accent); border-radius: 2px 2px 0 0; min-height: 2px; opacity: 0.8; }
.spark-bar:hover { opacity: 1; }

@media (max-width: 820px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; overflow-x: auto; }
  .brand { border-bottom: none; border-right: 1px solid var(--border); white-space: nowrap; }
  .device-filter { border-bottom: none; border-right: 1px solid var(--border); padding: 8px 10px; flex-shrink: 0; }
  .device-filter-btn { width: auto; max-width: 160px; }
  .device-filter-menu { left: 10px; right: auto; width: 220px; }
  .nav { flex-direction: row; padding: 8px; }
  .nav-sep, .sidebar-foot { display: none; }
  .content { padding: 16px; }
  .engine-bar { padding: 9px 16px; }
  .form-row { grid-template-columns: 1fr; }
}
