/* Apuray Admin — Design tokens */
:root {
  --orange: #FF6B00;
  --orange-600: #E85F00;
  --orange-50: #FFF3E8;
  --orange-100: #FFE4CC;

  /* Neutrals (warm) */
  --bg: #FAFAF9;
  --bg-elev: #FFFFFF;
  --bg-subtle: #F5F5F4;
  --border: #E7E5E4;
  --border-strong: #D6D3D1;
  --fg: #1C1917;
  --fg-muted: #57534E;
  --fg-subtle: #78716C;
  --fg-faint: #A8A29E;

  /* Status */
  --green: #16A34A;
  --green-bg: #DCFCE7;
  --red: #DC2626;
  --red-bg: #FEE2E2;
  --amber: #D97706;
  --amber-bg: #FEF3C7;
  --blue: #2563EB;
  --blue-bg: #DBEAFE;
  --violet: #7C3AED;
  --violet-bg: #EDE9FE;

  --sidebar-w: 220px;
  --header-h: 52px;
  --row-h: 40px;
  --radius: 6px;
  --radius-lg: 10px;

  --shadow-sm: 0 1px 2px rgba(28,25,23,0.04), 0 1px 1px rgba(28,25,23,0.04);
  --shadow-md: 0 4px 12px rgba(28,25,23,0.06), 0 2px 4px rgba(28,25,23,0.04);
  --shadow-lg: 0 24px 48px -12px rgba(28,25,23,0.18), 0 8px 16px -8px rgba(28,25,23,0.08);

  --font-ui: 'Inter', ui-sans-serif, system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', monospace;
}

[data-theme="dark"] {
  --bg: #0C0A09;
  --bg-elev: #1C1917;
  --bg-subtle: #161412;
  --border: #292524;
  --border-strong: #3A3432;
  --fg: #FAFAF9;
  --fg-muted: #D6D3D1;
  --fg-subtle: #A8A29E;
  --fg-faint: #78716C;
  --orange-50: #2B1A0A;
  --orange-100: #3D2410;
  --green-bg: #0F2A17;
  --red-bg: #2A0F0F;
  --amber-bg: #2A1E08;
  --blue-bg: #0F1A2E;
  --violet-bg: #1E1730;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 24px 48px -12px rgba(0,0,0,0.6);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.5;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv02", "cv03", "cv04", "cv11", "ss01";
}
#root { height: 100vh; width: 100vw; overflow: hidden; }

button { font-family: inherit; font-size: inherit; cursor: pointer; border: none; background: none; color: inherit; padding: 0; }
input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
.mono { font-family: var(--font-mono); font-feature-settings: "tnum"; }
.tnum { font-variant-numeric: tabular-nums; }

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--fg-faint); }

/* Layout */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; grid-template-rows: var(--header-h) 1fr; height: 100vh; }
.app.collapsed { grid-template-columns: 56px 1fr; }

/* Sidebar */
.sidebar {
  grid-row: 1 / 3; grid-column: 1;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
  z-index: 10;
}
.sidebar-brand {
  height: var(--header-h);
  display: flex; align-items: center; gap: 10px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.brand-mark {
  width: 24px; height: 24px; border-radius: 6px;
  background: var(--orange);
  display: flex; align-items: center; justify-content: center;
  color: white; font-weight: 700; font-size: 13px;
  flex-shrink: 0;
  box-shadow: inset 0 -1px 0 rgba(0,0,0,0.15);
}
.brand-name {
  font-weight: 600; font-size: 14px;
  letter-spacing: -0.01em;
  display: flex; align-items: baseline; gap: 6px;
}
.brand-env {
  font-size: 10px; font-weight: 500;
  color: var(--fg-subtle);
  background: var(--bg-subtle);
  padding: 2px 5px; border-radius: 4px;
  text-transform: uppercase; letter-spacing: 0.04em;
}

.nav {
  flex: 1; overflow-y: auto;
  padding: 8px;
  display: flex; flex-direction: column; gap: 1px;
}
.nav-section {
  font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--fg-faint);
  padding: 12px 8px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 8px;
  border-radius: 5px;
  color: var(--fg-muted);
  font-size: 13px; font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.1s, color 0.1s;
}
.nav-item:hover { background: var(--bg-subtle); color: var(--fg); }
.nav-item.active { background: var(--orange-50); color: var(--orange-600); }
.nav-item.active svg { color: var(--orange); }
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; color: var(--fg-subtle); }
.nav-item.active svg { color: var(--orange); }
.nav-badge {
  margin-left: auto;
  font-size: 10px;
  background: var(--bg-subtle);
  color: var(--fg-muted);
  padding: 1px 6px; border-radius: 10px;
  font-weight: 600;
}
.nav-item.active .nav-badge { background: var(--orange); color: white; }

.sidebar-footer {
  padding: 8px; border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.user-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: 6px; cursor: pointer;
}
.user-chip:hover { background: var(--bg-subtle); }
.avatar {
  width: 24px; height: 24px; border-radius: 50%;
  background: linear-gradient(135deg, #FF6B00, #FF9D47);
  color: white; font-weight: 600; font-size: 11px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.user-meta { min-width: 0; }
.user-name { font-weight: 600; font-size: 12px; }
.user-role { font-size: 11px; color: var(--fg-subtle); }

/* Header */
.header {
  grid-row: 1; grid-column: 2;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 16px;
  gap: 12px;
  z-index: 5;
}
.crumbs { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--fg-subtle); }
.crumbs .cur { color: var(--fg); font-weight: 600; }
.crumbs .sep { color: var(--fg-faint); }

.header-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }

.city-selector {
  display: flex; align-items: center; gap: 8px;
  height: 32px; padding: 0 10px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px; font-weight: 500;
  transition: border 0.1s;
}
.city-selector:hover { border-color: var(--border-strong); }
.city-selector .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 2px var(--green-bg); }

.icon-btn {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 6px;
  color: var(--fg-subtle);
  position: relative;
}
.icon-btn:hover { background: var(--bg-subtle); color: var(--fg); }
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn .pulse-dot {
  position: absolute; top: 6px; right: 6px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--orange);
  border: 2px solid var(--bg-elev);
}

.search-box {
  display: flex; align-items: center; gap: 8px;
  height: 32px; padding: 0 10px;
  background: var(--bg-subtle);
  border: 1px solid transparent;
  border-radius: 6px;
  width: 240px;
}
.search-box:focus-within { background: var(--bg-elev); border-color: var(--orange); box-shadow: 0 0 0 3px var(--orange-50); }
.search-box svg { width: 14px; height: 14px; color: var(--fg-subtle); }
.search-box input { border: none; outline: none; background: none; flex: 1; font-size: 13px; min-width: 0; }
.kbd {
  font-family: var(--font-mono); font-size: 10px;
  color: var(--fg-subtle);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
}

/* Main */
.main {
  grid-row: 2; grid-column: 2;
  overflow-y: auto;
  background: var(--bg);
}
.page { padding: 20px 24px; max-width: 1600px; }
.page-dense { padding: 0; height: 100%; }

/* Typography */
h1 { font-size: 20px; font-weight: 600; letter-spacing: -0.01em; margin: 0; }
h2 { font-size: 14px; font-weight: 600; margin: 0; letter-spacing: -0.005em; }
h3 { font-size: 12px; font-weight: 600; margin: 0; color: var(--fg-muted); text-transform: uppercase; letter-spacing: 0.04em; }

/* Cards */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.card-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
}
.card-body { padding: 16px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 12px;
  border-radius: 6px;
  font-size: 13px; font-weight: 500;
  border: 1px solid transparent;
  transition: all 0.1s;
  white-space: nowrap;
}
.btn svg { width: 14px; height: 14px; }
.btn-primary { background: var(--orange); color: white; }
.btn-primary:hover { background: var(--orange-600); }
.btn-secondary { background: var(--bg-elev); border-color: var(--border); color: var(--fg); }
.btn-secondary:hover { background: var(--bg-subtle); border-color: var(--border-strong); }
.btn-ghost { color: var(--fg-muted); }
.btn-ghost:hover { background: var(--bg-subtle); color: var(--fg); }
.btn-sm { height: 26px; padding: 0 8px; font-size: 12px; }
.btn-danger { background: var(--bg-elev); border-color: var(--border); color: var(--red); }
.btn-danger:hover { background: var(--red-bg); border-color: var(--red); }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 7px; border-radius: 4px;
  font-size: 11px; font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
}
.badge-dot { width: 6px; height: 6px; border-radius: 50%; }
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-amber { background: var(--amber-bg); color: var(--amber); }
.badge-blue { background: var(--blue-bg); color: var(--blue); }
.badge-violet { background: var(--violet-bg); color: var(--violet); }
.badge-gray { background: var(--bg-subtle); color: var(--fg-muted); }
.badge-orange { background: var(--orange-50); color: var(--orange-600); }

/* Tables */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table thead th {
  text-align: left;
  font-weight: 500; font-size: 11px;
  color: var(--fg-subtle);
  text-transform: uppercase; letter-spacing: 0.04em;
  padding: 8px 12px;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0;
  white-space: nowrap;
}
.table tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  white-space: nowrap;
}
.table tbody tr { cursor: pointer; transition: background 0.08s; }
.table tbody tr:hover { background: var(--bg-subtle); }
.table tbody tr.selected { background: var(--orange-50); }
.table tbody tr.selected td:first-child { box-shadow: inset 3px 0 0 var(--orange); }

/* Metric cards */
.metric-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.metric {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  display: flex; flex-direction: column; gap: 4px;
  position: relative; overflow: hidden;
}
.metric-label {
  font-size: 11px; color: var(--fg-subtle);
  text-transform: uppercase; letter-spacing: 0.04em;
  font-weight: 600;
}
.metric-value {
  font-size: 22px; font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.metric-delta {
  font-size: 11px; font-weight: 600;
  display: flex; align-items: center; gap: 3px;
}
.metric-delta.up { color: var(--green); }
.metric-delta.down { color: var(--red); }
.metric-spark { height: 32px; margin-top: 6px; }

/* Filter bar */
.filters {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
  flex-wrap: wrap;
}
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  height: 28px; padding: 0 10px;
  border-radius: 14px;
  font-size: 12px; font-weight: 500;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--fg-muted);
  cursor: pointer;
}
.chip:hover { border-color: var(--border-strong); color: var(--fg); }
.chip.active { background: var(--fg); color: var(--bg-elev); border-color: var(--fg); }
.chip svg { width: 12px; height: 12px; }

.seg {
  display: inline-flex;
  background: var(--bg-subtle);
  padding: 2px;
  border-radius: 6px;
  border: 1px solid var(--border);
}
.seg button {
  padding: 4px 10px; border-radius: 4px;
  font-size: 12px; font-weight: 500;
  color: var(--fg-muted);
}
.seg button.active { background: var(--bg-elev); color: var(--fg); box-shadow: var(--shadow-sm); }

/* Status row styles */
.id-cell { font-family: var(--font-mono); font-size: 12px; color: var(--fg-muted); }
.strong { font-weight: 600; color: var(--fg); }
.muted { color: var(--fg-subtle); }
.faint { color: var(--fg-faint); }

/* Detail panel (slide-in) */
.drawer-backdrop {
  position: fixed; inset: 0;
  background: rgba(12, 10, 9, 0.35);
  z-index: 50;
  animation: fadeIn 0.15s ease;
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: 560px; max-width: 90vw;
  background: var(--bg-elev);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  z-index: 51;
  display: flex; flex-direction: column;
  animation: slideIn 0.2s cubic-bezier(0.32, 0.72, 0, 1);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideIn { from { transform: translateX(100%); } to { transform: translateX(0); } }
.drawer-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
  flex-shrink: 0;
}
.drawer-body { flex: 1; overflow-y: auto; padding: 20px; }
.drawer-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px;
  flex-shrink: 0;
}

/* Map page */
.map-layout {
  display: grid;
  grid-template-columns: 320px 1fr 360px;
  height: 100%;
}
.map-sidebar-left, .map-sidebar-right {
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}
.map-sidebar-right { border-right: none; border-left: 1px solid var(--border); }
.map-stage {
  position: relative;
  background: var(--bg-subtle);
  overflow: hidden;
}

/* Service type pill */
.service-pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 6px 2px 4px;
  border-radius: 4px;
  font-size: 11px; font-weight: 600;
  background: var(--bg-subtle);
  color: var(--fg-muted);
}
.service-pill .icon-sq {
  width: 14px; height: 14px; border-radius: 3px;
  display: flex; align-items: center; justify-content: center;
}
.service-pill .icon-sq svg { width: 10px; height: 10px; color: white; }

/* Toggle switch */
.switch {
  width: 30px; height: 18px;
  background: var(--border-strong);
  border-radius: 10px;
  position: relative;
  cursor: pointer;
  transition: background 0.15s;
  flex-shrink: 0;
}
.switch::after {
  content: ''; position: absolute;
  top: 2px; left: 2px;
  width: 14px; height: 14px;
  background: white;
  border-radius: 50%;
  transition: transform 0.15s;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.switch.on { background: var(--orange); }
.switch.on::after { transform: translateX(12px); }

/* Popover */
.popover {
  position: absolute;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  padding: 4px;
  z-index: 30;
  min-width: 220px;
}
.pop-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px;
  border-radius: 5px;
  font-size: 13px;
  cursor: pointer;
}
.pop-item:hover { background: var(--bg-subtle); }
.pop-item.active { background: var(--orange-50); color: var(--orange-600); }
.pop-item .dot { width: 7px; height: 7px; border-radius: 50%; }

.divider { height: 1px; background: var(--border); margin: 4px 0; }

/* Progress */
.progress-track { height: 4px; background: var(--bg-subtle); border-radius: 2px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--orange); transition: width 0.3s; }

/* Tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); }
.tab {
  padding: 10px 14px;
  font-size: 13px; font-weight: 500;
  color: var(--fg-subtle);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab:hover { color: var(--fg); }
.tab.active { color: var(--fg); border-bottom-color: var(--orange); }

/* KV list */
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 4px 16px; font-size: 13px; }
.kv dt { color: var(--fg-subtle); padding: 6px 0; }
.kv dd { margin: 0; padding: 6px 0; color: var(--fg); }

/* Timeline */
.timeline { position: relative; padding-left: 24px; }
.timeline::before {
  content: ''; position: absolute;
  left: 7px; top: 6px; bottom: 6px;
  width: 1px; background: var(--border);
}
.tl-item { position: relative; padding-bottom: 14px; }
.tl-item::before {
  content: ''; position: absolute;
  left: -24px; top: 4px;
  width: 15px; height: 15px;
  border-radius: 50%;
  background: var(--bg-elev);
  border: 2px solid var(--border);
}
.tl-item.done::before { background: var(--green); border-color: var(--green); }
.tl-item.current::before { background: var(--orange); border-color: var(--orange); box-shadow: 0 0 0 4px var(--orange-50); }
.tl-title { font-weight: 600; font-size: 13px; }
.tl-meta { font-size: 12px; color: var(--fg-subtle); margin-top: 2px; }

/* Tweaks panel */
.tweaks-panel {
  position: fixed; right: 20px; bottom: 20px;
  width: 280px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  z-index: 100;
  overflow: hidden;
}
.tweaks-head {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.tweaks-body { padding: 12px 14px; display: flex; flex-direction: column; gap: 14px; }
.tweak-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.tweak-row label { font-size: 12px; color: var(--fg-muted); font-weight: 500; }

/* Utility */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 4px; } .gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; }
.mt-1 { margin-top: 4px; } .mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; } .mt-6 { margin-top: 24px; }
.mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 12px; } .mb-4 { margin-bottom: 16px; }
.grow { flex: 1; }
.text-xs { font-size: 11px; } .text-sm { font-size: 12px; } .text-base { font-size: 13px; } .text-lg { font-size: 15px; }
.font-semibold { font-weight: 600; }
.text-muted { color: var(--fg-subtle); }
.text-faint { color: var(--fg-faint); }

/* Density */
[data-density="comfortable"] {
  --row-h: 48px;
}
[data-density="comfortable"] .table tbody td { padding: 14px 14px; }
[data-density="comfortable"] .metric { padding: 18px 20px; }
[data-density="comfortable"] .metric-value { font-size: 26px; }

/* ========== Additions for full pages ========== */

/* Generic side drawer (inline within page, not fixed) */
.drawer-side {
  border-left: 1px solid var(--border);
  background: var(--bg-elev);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.drawer-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

/* KV row variant: <div class="kv"><span>k</span><span>v</span></div> */
div.kv {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  font-size: 12px;
  border-bottom: 1px dashed var(--border);
}
div.kv > span:first-child { color: var(--fg-muted); }
div.kv > span:last-child { color: var(--fg); font-weight: 500; text-align: right; }
div.kv:last-child { border-bottom: none; }

/* Section title within drawers */
.section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 16px 0 8px;
}

/* Mini stat card */
.stat-mini {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-subtle);
}

/* Feature flags matrix */
.table-ff th,
.table-ff td { border-right: 1px solid var(--border); }
.table-ff th:last-child,
.table-ff td:last-child { border-right: none; }
.ff-cell {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-mono);
}
.ff-on { background: color-mix(in oklch, var(--green) 20%, transparent); color: var(--green); }
.ff-ramp { background: color-mix(in oklch, var(--amber) 22%, transparent); color: var(--amber); }
.ff-off { background: var(--bg-subtle); color: var(--fg-faint); }

/* Ensure tables inside drawer-body don't overflow */
.drawer-body .section-title:first-child { margin-top: 0; }
