:root {
  --bg: #0b101b;
  --surface: #121826;
  --surface-2: #182032;
  --border: rgba(148, 163, 184, 0.14);
  --border-strong: rgba(148, 163, 184, 0.28);
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-faint: #64748b;
  --accent: #38bdf8;
  --accent-bg: rgba(56, 189, 248, 0.12);
  --ok: #10b981;
  --ok-bg: rgba(16, 185, 129, 0.12);
  --warn: #f59e0b;
  --warn-bg: rgba(245, 158, 11, 0.12);
  --danger: #f43f5e;
  --danger-bg: rgba(244, 63, 94, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 8px 24px rgba(2, 6, 23, 0.35);
  --font-sans: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

[data-theme="light"] {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: rgba(15, 23, 42, 0.10);
  --border-strong: rgba(15, 23, 42, 0.22);
  --text: #0f172a;
  --text-muted: #475569;
  --text-faint: #64748b;
  --accent: #0284c7;
  --accent-bg: rgba(2, 132, 199, 0.10);
  --ok: #059669;
  --ok-bg: rgba(5, 150, 105, 0.10);
  --warn: #d97706;
  --warn-bg: rgba(217, 119, 6, 0.10);
  --danger: #e11d48;
  --danger-bg: rgba(225, 29, 72, 0.10);
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 4px 16px rgba(15, 23, 42, 0.05);
}

*, *::before, *::after { box-sizing: border-box; }
html { font-size: 16px; }
body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Login Gate */
.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
}
.brand-mark {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--text);
}
.brand-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--accent-bg);
  border: 1px solid rgba(56, 189, 248, 0.25);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}
.auth-title {
  margin: 20px 0 4px;
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.auth-sub {
  margin: 0 0 24px;
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* Top Command Bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1380px;
  margin: 0 auto;
  min-height: 64px;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.topbar-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Container & Layout */
.container {
  max-width: 1380px;
  margin: 0 auto;
  padding: 24px 20px 48px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Buttons & Inputs (44px touch targets) */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}
.btn:hover:not(:disabled) { border-color: var(--border-strong); background: color-mix(in srgb, var(--surface-2) 80%, var(--text) 6%); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: #06121e;
}
.btn-primary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 88%, #ffffff); border-color: transparent; }
.btn-danger-ghost { color: var(--danger); }
.btn-danger-ghost:hover:not(:disabled) { background: var(--danger-bg); border-color: rgba(244, 63, 94, 0.35); }
.btn-icon { width: 44px; padding: 0; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-size: 0.8125rem; font-weight: 600; color: var(--text-muted); }
.input {
  width: 100%;
  min-height: 44px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 0.875rem;
}
.input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-bg); }

/* Badges & Status Pills */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
}
.pill-ok { background: var(--ok-bg); color: var(--ok); border-color: rgba(16, 185, 129, 0.25); }
.pill-warn { background: var(--warn-bg); color: var(--warn); border-color: rgba(245, 158, 11, 0.25); }
.pill-danger { background: var(--danger-bg); color: var(--danger); border-color: rgba(244, 63, 94, 0.25); }
.pill-info { background: var(--accent-bg); color: var(--accent); border-color: rgba(56, 189, 248, 0.25); }
.pill-neutral { background: var(--surface-2); color: var(--text-muted); border-color: var(--border); }

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

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.kpi-card {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.kpi-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.kpi-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.kpi-value {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
}
.kpi-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
.meter {
  width: 100%;
  height: 7px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
  border: 1px solid var(--border);
}
.meter-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.35s ease;
}
.meter-fill.warn { background: var(--warn); }
.meter-fill.danger { background: var(--danger); }
.meter-fill.ok { background: var(--ok); }

/* Charts + Services Split */
.mid-grid {
  display: grid;
  grid-template-columns: 1.25fr 1fr;
  gap: 16px;
}
.section-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.section-title {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-body { padding: 16px 20px; }

.chart-wrap {
  width: 100%;
  height: 170px;
  position: relative;
}
.chart-svg { width: 100%; height: 100%; display: block; overflow: visible; }

/* Services Grid */
.services-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.svc-item {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}
.svc-name { font-size: 0.8125rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.svc-unit { font-size: 0.7rem; color: var(--text-faint); }

/* Tabs */
.tabs-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.tabs-list {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.tab-btn {
  min-height: 44px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.tab-btn:hover { color: var(--text); background: var(--surface-2); }
.tab-btn[aria-selected="true"] {
  background: var(--accent-bg);
  color: var(--accent);
  border-color: rgba(56, 189, 248, 0.25);
}

/* Tables */
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.8125rem; }
th {
  text-align: left;
  padding: 12px 16px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
.truncate-cmd {
  max-width: 420px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

/* Alerts / States */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 0.8125rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.alert-danger { background: var(--danger-bg); border-color: rgba(244, 63, 94, 0.3); color: var(--danger); }
.alert-ok { background: var(--ok-bg); border-color: rgba(16, 185, 129, 0.3); color: var(--ok); }
.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.7);
  backdrop-filter: blur(4px);
  display: none;
  place-items: center;
  padding: 16px;
  z-index: 60;
}
.modal-backdrop.open { display: grid; }
.modal-card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

/* Responsive Breakpoints (1024px & 390px) */
@media (max-width: 1080px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .mid-grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .services-grid { grid-template-columns: 1fr; }
  .topbar-inner { padding: 10px 14px; }
  .container { padding: 16px 14px 36px; gap: 16px; }
  .auth-card { padding: 24px 18px; }
  .hide-sm { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .dot-pulse { animation: none; }
  .meter-fill, .btn { transition: none; }
}
