/* ==========================================================
   Optics — Realtime Vision Analytics
   Design system + layout + components
   ========================================================== */

:root {
  --bg-0: #07090f;
  --bg-1: #0d111a;
  --bg-2: #131826;
  --bg-3: #1a2033;
  --line: rgba(148, 163, 184, 0.10);
  --line-strong: rgba(148, 163, 184, 0.20);

  --fg-0: #f5f7fb;
  --fg-1: #cbd5e1;
  --fg-2: #94a3b8;
  --fg-3: #64748b;

  --brand-1: #7c3aed;
  --brand-2: #06b6d4;
  --brand-grad: linear-gradient(135deg, #7c3aed 0%, #06b6d4 100%);

  --emerald: #10b981;
  --rose:    #f43f5e;
  --amber:   #f59e0b;
  --indigo:  #6366f1;
  --blue:    #3b82f6;
  --pink:    #ec4899;

  --radius:    14px;
  --radius-sm: 10px;
  --shadow-1: 0 1px 2px rgba(0,0,0,0.25), 0 8px 24px rgba(0,0,0,0.30);
  --shadow-2: 0 1px 2px rgba(0,0,0,0.25), 0 24px 60px rgba(124, 58, 237, 0.18);

  --sidebar-w: 248px;
  --topbar-h: 84px;

  --t: 180ms cubic-bezier(.2,.7,.2,1);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg-0);
  color: var(--fg-0);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Background gradient texture */
body::before {
  content: "";
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(900px 600px at 10% -10%, rgba(124,58,237,.18), transparent 60%),
    radial-gradient(900px 600px at 110% 10%, rgba(6,182,212,.12), transparent 60%);
}

button { font: inherit; cursor: pointer; }
input, select { font: inherit; color: inherit; }
a { color: inherit; }

/* ============== Layout =================================== */
#app {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* ============== Sidebar ================================== */
.sidebar {
  background: linear-gradient(180deg, var(--bg-1), var(--bg-0));
  border-right: 1px solid var(--line);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky; top: 0; height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 10px 14px;
  border-bottom: 1px solid var(--line);
}
.brand__mark {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 12px;
  background: rgba(124,58,237,.10);
  border: 1px solid rgba(124,58,237,.30);
}
.brand__name {
  font-weight: 800;
  letter-spacing: .2px;
  background: var(--brand-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-size: 18px;
}
.brand__sub { color: var(--fg-3); font-size: 11px; letter-spacing: .14em; text-transform: uppercase; }

.nav { display: flex; flex-direction: column; gap: 4px; margin-top: 4px; }
.nav__item {
  appearance: none;
  background: transparent;
  border: 1px solid transparent;
  color: var(--fg-1);
  text-align: left;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; gap: 12px;
  transition: background var(--t), color var(--t), border-color var(--t);
}
.nav__item:hover { background: var(--bg-2); color: var(--fg-0); }
.nav__item.is-active {
  background: linear-gradient(135deg, rgba(124,58,237,.16), rgba(6,182,212,.10));
  color: var(--fg-0);
  border-color: rgba(124,58,237,.35);
}
.nav__item svg { opacity: .9; }

.sidebar__footer { margin-top: auto; display: flex; flex-direction: column; gap: 12px; }
.status-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--fg-1); font-size: 12px;
}
.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 0 0 rgba(245,158,11,.6);
  animation: pulse 1.6s infinite;
}
.status-pill.is-ok .status-dot { background: var(--emerald); box-shadow: 0 0 0 0 rgba(16,185,129,.6); }
.status-pill.is-bad .status-dot { background: var(--rose);    box-shadow: 0 0 0 0 rgba(244,63,94,.6); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255,255,255,.4); }
  70% { box-shadow: 0 0 0 8px rgba(255,255,255,0); }
  100% { box-shadow: 0 0 0 0 rgba(255,255,255,0); }
}
.brand__legal { color: var(--fg-3); font-size: 11px; padding-left: 4px; }

/* ============== Main =================================== */
.main {
  min-width: 0;
  padding: 0 28px 40px;
}

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: linear-gradient(180deg, rgba(7,9,15,.92), rgba(7,9,15,.65));
  backdrop-filter: blur(8px);
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 20px 0 14px;
  margin-bottom: 22px;
  border-bottom: 1px solid var(--line);
}
.topbar__title { margin: 0; font-size: 22px; letter-spacing: .2px; font-weight: 700; }
.topbar__sub { margin: 2px 0 0; color: var(--fg-2); font-size: 13px; }

.range-picker {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  padding: 8px 10px;
  border-radius: 12px;
}
.range-picker label {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--fg-2); font-size: 12px;
}
.range-picker input[type="datetime-local"] {
  background: var(--bg-3);
  border: 1px solid var(--line);
  color: var(--fg-0);
  padding: 6px 8px;
  border-radius: 8px;
  outline: none;
  color-scheme: dark;
}
.range-picker input:focus { border-color: rgba(124,58,237,.5); }

.btn {
  appearance: none; border: none;
  padding: 9px 14px;
  border-radius: 10px;
  font-weight: 600; letter-spacing: .2px;
  transition: transform var(--t), background var(--t), color var(--t), box-shadow var(--t);
  display: inline-flex; align-items: center; gap: 8px;
}
.btn:active { transform: translateY(1px); }
.btn--primary {
  background: var(--brand-grad);
  color: white;
  box-shadow: 0 4px 16px rgba(124,58,237,.35);
}
.btn--primary:hover { box-shadow: 0 6px 22px rgba(124,58,237,.55); }
.btn--ghost {
  background: transparent;
  color: var(--fg-1);
  border: 1px solid var(--line-strong);
}
.btn--ghost:hover { background: var(--bg-3); color: var(--fg-0); }
.btn--danger {
  background: rgba(244,63,94,.08);
  color: #fda4af;
  border: 1px solid rgba(244,63,94,.35);
}
.btn--danger:hover { background: rgba(244,63,94,.18); color: #fff; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* Pages */
.page { display: block; }
.page.is-hidden { display: none; }

/* ============== KPI cards ================================ */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}
.kpi {
  position: relative;
  background: linear-gradient(180deg, var(--bg-2), var(--bg-1));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 18px 22px;
  overflow: hidden;
  transition: transform var(--t), border-color var(--t);
}
.kpi:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.kpi__label { color: var(--fg-2); font-size: 12px; letter-spacing: .12em; text-transform: uppercase; font-weight: 600; }
.kpi__value {
  margin-top: 8px;
  font-size: 36px;
  font-weight: 700;
  letter-spacing: -.5px;
  font-variant-numeric: tabular-nums;
}
.kpi__trend { color: var(--fg-3); font-size: 12px; margin-top: 4px; }
.kpi__bar {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--c), transparent);
}

/* ============== Card grid =============================== */
.card-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}
.card {
  background: linear-gradient(180deg, var(--bg-2), var(--bg-1));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.card--span-2 { grid-column: span 2; }
.card--span-3 { grid-column: span 3; }

.card__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.card__head h3 { margin: 0; font-size: 14px; font-weight: 600; letter-spacing: .2px; }
.card__sub { color: var(--fg-3); font-size: 12px; }
.card__actions { display: flex; gap: 8px; }
.card__body { padding: 14px 18px; }

.chart-wrap { position: relative; height: 280px; }
.card--span-2 .chart-wrap { height: 320px; }
.card--span-3 .chart-wrap { height: 360px; }

/* ============== Table ==================================== */
.table-wrap { padding: 0; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
.table thead th {
  text-align: left;
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--fg-3);
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.02);
  position: sticky; top: 0;
}
.table tbody td {
  padding: 11px 18px;
  border-bottom: 1px solid var(--line);
  color: var(--fg-1);
  font-size: 13px;
}
.table tbody tr:hover td { background: rgba(255,255,255,.02); color: var(--fg-0); }
.tag {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600;
}
.tag--ok  { background: rgba(16,185,129,.12); color: #6ee7b7; border: 1px solid rgba(16,185,129,.35); }
.tag--no  { background: rgba(100,116,139,.16); color: var(--fg-2); border: 1px solid var(--line-strong); }

/* ============== Live page ================================ */
.form-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 14px;
  align-items: end;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field--full { grid-column: 1 / -1; }
.field--actions { grid-column: 1 / -1; display: flex; align-items: center; gap: 14px; }
.field span { color: var(--fg-2); font-size: 12px; letter-spacing: .04em; }
.field input[type="text"],
.field input[type="file"],
.field select {
  background: var(--bg-3);
  border: 1px solid var(--line-strong);
  color: var(--fg-0);
  padding: 10px 12px;
  border-radius: 10px;
  outline: none;
  transition: border-color var(--t), box-shadow var(--t);
}
.field input[type="text"]:focus,
.field select:focus {
  border-color: rgba(124,58,237,.6);
  box-shadow: 0 0 0 3px rgba(124,58,237,.2);
}
.form-msg { color: var(--fg-2); font-size: 13px; }
.form-msg.is-error { color: #fda4af; }
.form-msg.is-ok { color: #6ee7b7; }

.quick-sources {
  margin-top: 16px;
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
  color: var(--fg-3); font-size: 12px;
}
.quick-sources__label { letter-spacing: .12em; text-transform: uppercase; }
.chip {
  background: var(--bg-3);
  border: 1px solid var(--line-strong);
  padding: 6px 10px;
  border-radius: 999px;
  color: var(--fg-1);
  font-size: 12px;
}
.chip:hover { color: white; border-color: rgba(124,58,237,.5); }

.live-grid {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.live-tile {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.live-tile__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.live-tile__title { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.live-mode-badge {
  font-size: 10px; letter-spacing: .14em; text-transform: uppercase;
  padding: 2px 8px; border-radius: 999px;
  background: rgba(124,58,237,.16);
  color: #c4b5fd;
  border: 1px solid rgba(124,58,237,.35);
}
.live-tile__source { color: var(--fg-3); font-size: 11px; font-family: 'JetBrains Mono', monospace; max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.live-tile__video {
  position: relative;
  background: #000;
  aspect-ratio: 16 / 9;
  display: grid;
  place-items: center;
}
.live-tile__video img {
  width: 100%; height: 100%;
  object-fit: contain;
}
.live-placeholder { color: var(--fg-3); font-size: 13px; padding: 18px; text-align: center; }
.live-overlay {
  position: absolute; top: 10px; left: 10px;
  display: flex; align-items: center; gap: 8px;
  padding: 4px 8px;
  background: rgba(0,0,0,.55);
  border-radius: 999px;
  font-size: 11px; color: #fef2f2;
}
.live-overlay__dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--rose);
  animation: pulse 1.6s infinite;
}

.live-tile__stats {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 0;
  border-top: 1px solid var(--line);
}
.live-stat {
  padding: 10px 12px;
  border-right: 1px solid var(--line);
  text-align: left;
}
.live-stat:last-child { border-right: none; }
.live-stat__label { color: var(--fg-3); font-size: 10px; letter-spacing: .12em; text-transform: uppercase; }
.live-stat__value { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }

.live-tile__foot {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px;
  background: var(--bg-2);
  border-top: 1px solid var(--line);
}

/* ============== Video gallery ============================ */
.video-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
.video-card {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color var(--t), transform var(--t);
}
.video-card:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.video-card video {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  display: block;
  outline: none;
}
.video-card__head {
  padding: 12px 14px 4px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
}
.video-card__title { font-weight: 600; font-size: 14px; }
.video-card__mode {
  font-size: 10px; letter-spacing: .14em; text-transform: uppercase;
  padding: 2px 8px; border-radius: 999px;
  background: rgba(6,182,212,.12);
  color: #67e8f9;
  border: 1px solid rgba(6,182,212,.30);
}
.video-card__meta {
  padding: 0 14px 8px;
  color: var(--fg-3); font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  display: flex; justify-content: space-between;
}
.video-card__foot {
  padding: 10px 14px;
  background: var(--bg-2);
  border-top: 1px solid var(--line);
  display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end;
}
.video-empty {
  color: var(--fg-3); padding: 20px; text-align: center;
  grid-column: 1 / -1;
}

@media (max-width: 1180px) { .video-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 700px)  { .video-grid { grid-template-columns: 1fr; } }

/* ============== Toast ==================================== */
.toast {
  position: fixed;
  right: 22px; bottom: 22px;
  background: var(--bg-2);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 13px;
  color: var(--fg-0);
  box-shadow: var(--shadow-1);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity var(--t), transform var(--t);
  z-index: 100;
  max-width: 380px;
}
.toast.is-visible { opacity: 1; transform: translateY(0); }
.toast.is-error { border-color: rgba(244,63,94,.5); }
.toast.is-ok { border-color: rgba(16,185,129,.5); }

/* ============== Responsive =============================== */
@media (max-width: 1180px) {
  .card-grid { grid-template-columns: repeat(2, 1fr); }
  .card--span-2, .card--span-3 { grid-column: span 2; }
  .live-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 880px) {
  #app { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .topbar { flex-direction: column; align-items: stretch; gap: 10px; }
  .range-picker { flex-wrap: wrap; }
  .form-grid { grid-template-columns: 1fr; }
}
