:root {
  --bg: #0b0f14;
  --bg-2: #10161d;
  --bg-3: #151c25;
  --border: #1e2733;
  --border-soft: #232e3a;
  --text: #e6edf3;
  --text-dim: #8b98a5;
  --text-faint: #5c6773;
  --accent: #14b8a6;
  --accent-2: #2dd4bf;
  --accent-dim: rgba(20, 184, 166, 0.12);
  --up: #34d399;
  --down: #f87171;
  --warn: #fbbf24;
  --radius: 10px;
  --mono: 'JetBrains Mono', monospace;
  --sans: 'Inter', -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

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

.mono { font-family: var(--mono); }

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

/* ===== Sidebar ===== */
.sidebar {
  width: 220px;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px;
  border-bottom: 1px solid var(--border);
}

.brand-mark {
  width: 34px; height: 34px;
  border-radius: 8px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), #0d9488);
  color: #05201c;
  font-size: 18px;
  font-weight: 700;
  font-family: var(--mono);
}

.brand-text { display: flex; flex-direction: column; line-height: 1.3; }
.brand-name { font-weight: 600; font-size: 14px; }
.brand-sub { font-size: 11px; color: var(--text-faint); }

.nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }
.nav-item:hover { background: var(--bg-3); color: var(--text); }
.nav-item.active { background: var(--accent-dim); color: var(--accent-2); }

.sidebar-foot {
  margin-top: auto;
  padding: 16px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-dim);
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--up); box-shadow: 0 0 0 3px rgba(52, 211, 153, .18); }

/* ===== Main ===== */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
  position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-weight: 600; font-size: 15px; }

.live-pill {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 11px; font-weight: 600; color: var(--text-dim);
  padding: 5px 11px; border: 1px solid var(--border); border-radius: 20px;
}
.pulse { width: 7px; height: 7px; border-radius: 50%; background: var(--up); animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

.content { padding: 24px; max-width: 1200px; width: 100%; }

/* ===== Views ===== */
.view { display: none; }
.view.active { display: block; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ===== Cards ===== */
.card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-head h3 { font-size: 13px; font-weight: 600; color: var(--text); }
.card-head-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.mb-0 { margin-bottom: 0; }

/* ===== KPI ===== */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 16px; }
.kpi-label { font-size: 12px; color: var(--text-dim); margin-bottom: 8px; }
.kpi-value {
  font-family: var(--mono);
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.5px;
  margin-bottom: 6px;
}
.kpi-delta { font-size: 11px; font-family: var(--mono); }
.kpi-delta.up { color: var(--up); }
.kpi-delta.down { color: var(--down); }

/* ===== Grid ===== */
.grid-2col { display: grid; grid-template-columns: 1.6fr 1fr; gap: 16px; margin-bottom: 16px; }

/* ===== Segmented ===== */
.seg { display: flex; background: var(--bg-3); border-radius: 7px; padding: 2px; gap: 2px; }
.seg-btn {
  border: none; background: transparent; color: var(--text-dim);
  font-size: 11px; font-weight: 600; padding: 4px 10px; border-radius: 6px; cursor: pointer;
  font-family: var(--sans);
}
.seg-btn.active { background: var(--accent-dim); color: var(--accent-2); }

/* ===== Bar chart (pure CSS from data) ===== */
.bar-chart { display: flex; align-items: flex-end; gap: 10px; height: 200px; padding-top: 10px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 8px; height: 100%; justify-content: flex-end; }
.bar {
  width: 100%; max-width: 44px;
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  border-radius: 5px 5px 2px 2px;
  min-height: 4px;
  transition: height .4s ease, opacity .15s;
  opacity: .85;
}
.bar-col:hover .bar { opacity: 1; }
.bar-label { font-size: 10px; color: var(--text-faint); font-family: var(--mono); }

/* ===== Model list ===== */
.model-list { display: flex; flex-direction: column; gap: 14px; }
.model-row { display: flex; align-items: center; gap: 12px; }
.model-name { flex: 1; font-size: 12px; font-family: var(--mono); color: var(--text-dim); }
.model-track { flex: 1.4; height: 6px; background: var(--bg-3); border-radius: 3px; overflow: hidden; }
.model-fill { height: 100%; border-radius: 3px; background: var(--accent); }
.model-pct { font-size: 11px; font-family: var(--mono); color: var(--text); width: 48px; text-align: right; }

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left; padding: 10px 14px;
  font-size: 11px; font-weight: 600; color: var(--text-faint);
  text-transform: uppercase; letter-spacing: .04em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td { padding: 12px 14px; border-bottom: 1px solid var(--border-soft); color: var(--text-dim); white-space: nowrap; }
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: var(--bg-3); }
.table .tr { text-align: right; }
.mono-cell { font-family: var(--mono); font-size: 12px; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 20px;
  font-family: var(--mono);
}
.badge.ok { background: rgba(52, 211, 153, .12); color: var(--up); }
.badge.warn { background: rgba(251, 191, 36, .12); color: var(--warn); }
.badge.err { background: rgba(248, 113, 113, .12); color: var(--down); }

/* ===== Buttons & inputs ===== */
.btn {
  border: 1px solid var(--border);
  background: var(--bg-3); color: var(--text);
  font-size: 13px; font-weight: 500; padding: 8px 14px; border-radius: 8px;
  cursor: pointer; font-family: var(--sans);
  transition: background .15s, border-color .15s;
}
.btn:hover { border-color: var(--border-soft); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #05201c; font-weight: 600; }
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn-ghost { background: transparent; }

.input {
  background: var(--bg-3); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 9px 12px; font-size: 13px; font-family: var(--sans);
  width: 100%;
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }

.filters { display: flex; gap: 10px; margin-bottom: 16px; }
.filters .input { flex: 1; max-width: 260px; }
.filters select.input { width: auto; }

.field { margin-bottom: 18px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--text-dim); margin-bottom: 7px; }
.input-row { display: flex; gap: 10px; }
.hint { font-size: 11px; color: var(--text-faint); margin-top: 6px; }

.link { color: var(--accent-2); text-decoration: none; font-size: 12px; font-weight: 500; }
.link:hover { text-decoration: underline; }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: none; align-items: center; justify-content: center; z-index: 100;
  backdrop-filter: blur(2px);
}
.modal-overlay.show { display: flex; }
.modal { background: var(--bg-2); border: 1px solid var(--border); border-radius: 12px; width: 420px; max-width: 92vw; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 14px; font-weight: 600; }
.modal-close { background: none; border: none; color: var(--text-dim); font-size: 22px; cursor: pointer; line-height: 1; }
.modal-body { padding: 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); }

/* ===== Bottom nav (mobile app shell) ===== */
.bottom-nav {
  display: none;
  position: fixed; left: 0; right: 0; bottom: 0;
  background: var(--bg-2);
  border-top: 1px solid var(--border);
  z-index: 50;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  backdrop-filter: blur(8px);
}
.bottom-nav .bn-inner { display: grid; grid-template-columns: repeat(4, 1fr); }
.bn-item {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 9px 4px 7px; color: var(--text-faint); text-decoration: none;
  font-size: 10px; font-weight: 500;
}
.bn-item svg { width: 21px; height: 21px; }
.bn-item.active { color: var(--accent-2); }

/* FAB (floating action button) */
.fab {
  display: none;
  position: fixed; right: 18px; bottom: calc(74px + env(safe-area-inset-bottom, 0px));
  width: 56px; height: 56px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  color: #05201c; border: none; cursor: pointer;
  z-index: 60;
  box-shadow: 0 8px 24px rgba(20, 184, 166, .35);
  display: none;
  align-items: center; justify-content: center;
}
.fab svg { width: 26px; height: 26px; }
.fab:active { transform: scale(.94); }

/* Card list (mobile replacement for tables) */
.card-list { display: none; flex-direction: column; gap: 12px; }
.card-item {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px;
}
.card-item .ci-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 7px; }
.card-item .ci-row:last-child { margin-bottom: 0; }
.ci-label { font-size: 11px; color: var(--text-faint); }
.ci-val { font-size: 13px; color: var(--text); font-family: var(--mono); }

/* ===== Responsive: mobile app mode ===== */
@media (max-width: 760px) {
  body { padding-bottom: 74px; }

  /* hide desktop sidebar */
  .sidebar { display: none; }

  /* topbar becomes app header */
  .topbar { position: sticky; height: 52px; padding: 0 18px; }
  .topbar-title { font-size: 16px; font-weight: 700; }
  .live-pill { font-size: 10px; padding: 4px 9px; }

  .content { padding: 16px; }

  /* KPI 2 col */
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .kpi-value { font-size: 22px; }
  .kpi { padding: 14px; }

  .grid-2col { grid-template-columns: 1fr; gap: 12px; }

  /* tables -> card list */
  .table-wrap { display: none; }
  .card-list { display: flex; }

  /* show bottom nav + FAB */
  .bottom-nav { display: block; }
  .fab { display: flex; }

  /* modal as bottom sheet */
  .modal-overlay { align-items: flex-end; }
  .modal { width: 100%; max-width: 100%; border-radius: 16px 16px 0 0; }

  .filters { flex-wrap: wrap; }
  .filters .input { max-width: 100%; flex: 1 1 100%; }
}
