:root {
  --bg: #071018;
  --surface: #0d1823;
  --surface-2: #122231;
  --surface-3: #172b3d;
  --border: #21384b;
  --text: #eaf2f8;
  --muted: #8ea2b3;
  --accent: #5eead4;
  --accent-2: #38bdf8;
  --good: #4ade80;
  --warn: #facc15;
  --bad: #fb7185;
  --shadow: 0 18px 50px rgba(0,0,0,.28);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 15% 10%, rgba(56,189,248,.09), transparent 30%),
    radial-gradient(circle at 85% 0%, rgba(94,234,212,.08), transparent 26%),
    var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 18px;
  border-right: 1px solid var(--border);
  background: rgba(7,16,24,.88);
  backdrop-filter: blur(16px);
  display: flex;
  flex-direction: column;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 8px 22px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  font-weight: 900;
  color: #06221f;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 26px rgba(94,234,212,.18);
}

.brand-title { font-weight: 800; line-height: 1.1; }
.brand-subtitle { color: var(--muted); font-size: 12px; margin-top: 4px; }

.nav { display: grid; gap: 6px; }

.nav-item {
  border: 0;
  color: var(--muted);
  background: transparent;
  text-align: left;
  padding: 12px 14px;
  border-radius: 12px;
  transition: .18s ease;
}

.nav-item:hover {
  color: var(--text);
  background: rgba(255,255,255,.04);
}

.nav-item.active {
  color: #071018;
  background: linear-gradient(135deg, var(--accent), #8df8ec);
  font-weight: 800;
}

.sidebar-footer { margin-top: auto; padding: 18px 8px 0; }
.tiny-label { font-size: 11px; letter-spacing: .14em; color: var(--muted); }
.lab-pill {
  margin-top: 8px;
  display: inline-flex;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
}

.main { min-width: 0; padding: 26px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar h1 { margin: 0; font-size: clamp(24px, 3vw, 34px); }
.topbar p { margin: 6px 0 0; color: var(--muted); }
.topbar-actions { display: flex; gap: 10px; align-items: center; }

.section { display: none; }
.section.active { display: block; animation: fade .2s ease; }

@keyframes fade {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.card, .stat-card {
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(18,34,49,.92), rgba(13,24,35,.92));
  box-shadow: var(--shadow);
}

.card {
  border-radius: 20px;
  padding: 20px;
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  padding: 26px;
}

.hero h2 { margin: 6px 0 8px; font-size: clamp(26px, 4vw, 40px); }
.hero p { margin: 0; color: var(--muted); max-width: 720px; line-height: 1.6; }
.hero-chip-group { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.eyebrow {
  color: var(--accent);
  font-size: 11px;
  letter-spacing: .15em;
  font-weight: 800;
}

.chip, .status-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.chip {
  padding: 8px 10px;
  color: var(--muted);
  border: 1px solid var(--border);
  background: rgba(255,255,255,.025);
}
.chip.success { color: var(--good); }
.chip.warning { color: var(--warn); }

.status-badge { padding: 8px 10px; border: 1px solid var(--border); }
.status-badge.online { color: var(--good); background: rgba(74,222,128,.08); }
.status-badge.warning { color: var(--warn); background: rgba(250,204,21,.08); }
.status-badge.idle { color: var(--muted); background: rgba(255,255,255,.03); }
.status-badge.live { color: #071018; background: var(--accent); }

.stats-grid {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0,1fr));
  gap: 14px;
}

.stat-card {
  border-radius: 18px;
  padding: 18px;
}

.stat-label { color: var(--muted); font-size: 13px; }
.stat-value { margin-top: 10px; font-size: clamp(28px, 4vw, 38px); font-weight: 900; }
.stat-note { margin-top: 8px; color: var(--muted); font-size: 12px; }

.two-column, .section-grid {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  gap: 18px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}
.card-header h3 { margin: 5px 0 0; font-size: 20px; }

.kv-list { display: grid; }
.kv-list.compact .kv-row { padding: 10px 0; }
.kv-row {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 0;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.kv-row:last-child { border-bottom: 0; }
.kv-row span { color: var(--muted); }
.kv-row strong { text-align: right; overflow-wrap: anywhere; }
.good { color: var(--good); }
.warn { color: var(--warn); }
.bad { color: var(--bad); }

.timeline { display: grid; gap: 12px; }
.timeline-item {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.timeline-item:last-child { border-bottom: 0; }
.timeline-time { color: var(--accent-2); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.timeline-text { color: var(--muted); }

.primary-button, .secondary-button, .danger-button, .text-button, .icon-button {
  border-radius: 12px;
  padding: 11px 14px;
  font-weight: 800;
}

.primary-button {
  border: 0;
  color: #05201d;
  background: linear-gradient(135deg, var(--accent), #8df8ec);
}

.secondary-button {
  border: 1px solid var(--border);
  color: var(--text);
  background: var(--surface-2);
}

.danger-button {
  border: 1px solid rgba(251,113,133,.35);
  color: #ffdbe2;
  background: rgba(251,113,133,.12);
}

.text-button {
  border: 0;
  padding: 6px 0;
  color: var(--accent);
  background: transparent;
}

.icon-button {
  border: 1px solid var(--border);
  color: var(--text);
  background: var(--surface);
}

button:disabled { opacity: .42; cursor: not-allowed; }

.button-row { display: flex; gap: 10px; align-items: center; margin-top: 18px; }
.button-row.wrap { flex-wrap: wrap; }
.button-stack { display: grid; gap: 10px; }

.media-card { min-height: 420px; }
.meter {
  height: 14px;
  border-radius: 999px;
  overflow: hidden;
  background: #08111a;
  border: 1px solid var(--border);
  margin: 20px 0;
}
.meter-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-2), var(--accent), var(--warn));
  transition: width .12s linear;
}

.video-placeholder {
  min-height: 270px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  border: 1px dashed #31506a;
  border-radius: 16px;
  color: var(--muted);
  background:
    linear-gradient(135deg, rgba(56,189,248,.05), transparent),
    #09131d;
  text-align: center;
}
.camera-icon { font-size: 40px; color: var(--accent); }
.video-placeholder.live {
  border-style: solid;
  color: var(--text);
  background:
    radial-gradient(circle at 50% 30%, rgba(94,234,212,.13), transparent 35%),
    #08131d;
}

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td {
  padding: 13px 12px;
  border-bottom: 1px solid rgba(255,255,255,.06);
  text-align: left;
}
th { color: var(--muted); font-size: 12px; letter-spacing: .04em; }
td { vertical-align: top; }
.table-status {
  display: inline-flex;
  padding: 6px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}
.table-status.granted { color: var(--good); background: rgba(74,222,128,.09); }
.table-status.disabled { color: var(--muted); background: rgba(255,255,255,.04); }
.table-status.review { color: var(--warn); background: rgba(250,204,21,.09); }

.result-panel {
  min-height: 250px;
  padding: 16px;
  border-radius: 14px;
  color: var(--muted);
  border: 1px dashed var(--border);
  background: #08121b;
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  line-height: 1.65;
}

.terminal {
  min-height: 250px;
  max-height: 380px;
  overflow: auto;
  padding: 16px;
  color: #bde7f8;
  background: #050b11;
  border: 1px solid #1e3344;
  border-radius: 14px;
  white-space: pre-wrap;
}

.service-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0,1fr));
  gap: 12px;
}
.service-item {
  padding: 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.025);
}
.service-item strong { display: block; }
.service-item span { display: block; margin-top: 7px; color: var(--muted); font-size: 12px; }

.event-log {
  display: grid;
  gap: 8px;
  max-height: 560px;
  overflow: auto;
}
.event-item {
  display: grid;
  grid-template-columns: 95px 110px 1fr;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid rgba(255,255,255,.06);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
}
.event-time { color: var(--accent-2); }
.event-type { color: var(--accent); font-weight: 800; }
.event-message { color: var(--muted); }

.mobile-only { display: none; }

@media (max-width: 1050px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .service-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
}

@media (max-width: 820px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 280px;
    transform: translateX(-105%);
    transition: transform .2s ease;
    box-shadow: 20px 0 60px rgba(0,0,0,.4);
  }
  .sidebar.open { transform: translateX(0); }
  .main { padding: 18px; }
  .mobile-only { display: inline-flex; }
  .topbar { align-items: flex-start; }
  .topbar-actions { align-items: flex-end; flex-direction: column; }
  .two-column, .section-grid { grid-template-columns: 1fr; }
  .hero { align-items: flex-start; flex-direction: column; }
  .hero-chip-group { justify-content: flex-start; }
}

@media (max-width: 560px) {
  .stats-grid { grid-template-columns: 1fr; }
  .service-grid { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; }
  .topbar-actions { align-items: stretch; width: 100%; }
  .button-row { align-items: stretch; flex-direction: column; }
  .button-row.wrap { flex-direction: row; }
  .event-item { grid-template-columns: 1fr; gap: 4px; }
  .kv-row { align-items: flex-start; flex-direction: column; gap: 5px; }
  .kv-row strong { text-align: left; }
}
