:root {
  --bg: #0b0f17;
  --surface: #131a26;
  --surface-2: #1a2333;
  --border: #253147;
  --text: #e6edf7;
  --muted: #8b9bb4;
  --accent: #38bdf8;
  --accent-2: #22c55e;
  --warn: #f59e0b;
  --crit: #ef4444;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 700;
  font-size: 1.15rem;
}

.pulse-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent-2);
  box-shadow: 0 0 10px var(--accent-2);
}

.badge {
  font-size: 0.7rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: rgba(245, 158, 11, 0.2);
  color: var(--warn);
  border: 1px solid var(--warn);
}

.nav-tabs { display: flex; gap: 0.4rem; }
.tab-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 0.45rem 0.9rem;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
}
.tab-btn.active {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}

.container {
  max-width: 1260px;
  margin: 0 auto;
  padding: 1.25rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem;
  margin-bottom: 1rem;
}

.auth-card {
  max-width: 520px;
  margin: 4rem auto;
  text-align: center;
  padding: 2rem;
}
.signin-hero { display: flex; justify-content: center; margin-top: 1.25rem; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 0.65rem; }

.select, input, textarea {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
  font: inherit;
}
.select-sm { padding: 0.3rem 0.55rem; font-size: 0.85rem; }

.btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.9rem;
  cursor: pointer;
  font-weight: 600;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); color: #05131f; border-color: var(--accent); }
.btn-danger { background: rgba(239, 68, 68, 0.15); color: #fca5a5; border-color: var(--crit); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.82rem; }

.pill {
  font-size: 0.76rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.pill-ok { background: rgba(34, 197, 94, 0.15); color: #86efac; border-color: var(--accent-2); }
.pill-warn { background: rgba(245, 158, 11, 0.18); color: #fcd34d; border-color: var(--warn); }
.pill-crit { background: rgba(239, 68, 68, 0.18); color: #fca5a5; border-color: var(--crit); }
.pill-offline { color: var(--muted); }

.summary-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}
.summary-bar h2 { margin: 0 0 0.2rem; }
.odo-box { text-align: right; }
.odo-box strong { display: block; font-size: 1.5rem; color: var(--accent); }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(185px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1rem;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
}
.kpi-card.warn { border-color: var(--warn); }
.kpi-card.crit { border-color: var(--crit); background: rgba(239, 68, 68, 0.08); }
.kpi-label { font-size: 0.78rem; color: var(--muted); margin-bottom: 0.35rem; }
.kpi-value { font-size: 1.45rem; font-weight: 700; }
.kpi-unit { font-size: 0.85rem; color: var(--muted); margin-left: 0.2rem; }

.alerts-stack { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 1rem; }
.alert-item {
  padding: 0.7rem 1rem;
  border-radius: 10px;
  font-weight: 600;
  border: 1px solid var(--warn);
  background: rgba(245, 158, 11, 0.14);
  color: #fde68a;
}
.alert-item.critical {
  border-color: var(--crit);
  background: rgba(239, 68, 68, 0.16);
  color: #fecaca;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}
.section-header h3 { margin: 0; }
.subhead { margin: 1.1rem 0 0.5rem; font-size: 0.95rem; color: var(--muted); }

.dpf-bars { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.meter-label { display: flex; justify-content: space-between; font-size: 0.88rem; margin-bottom: 0.35rem; }
.progress { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent-2); transition: width 0.3s ease; }
.progress-fill.warn { background: var(--warn); }
.progress-fill.crit { background: var(--crit); }

.two-col {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 1rem;
}

.chart-box { min-height: 210px; display: flex; align-items: center; justify-content: center; }
.chart-box svg { width: 100%; height: 210px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { text-align: left; padding: 0.55rem 0.65rem; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; }

.dtc-list { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.dtc-chip {
  padding: 0.4rem 0.7rem;
  border-radius: 8px;
  background: rgba(239, 68, 68, 0.16);
  border: 1px solid var(--crit);
  color: #fecaca;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85rem;
}

.form-grid { display: flex; flex-direction: column; gap: 0.7rem; }
.form-grid label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.85rem; color: var(--muted); }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 0.6rem; }
.checks-row { display: flex; flex-wrap: wrap; gap: 1rem; padding: 0.35rem 0; }
.check { flex-direction: row !important; align-items: center; gap: 0.4rem !important; color: var(--text) !important; }
.code-input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.78rem; }
.form-actions { display: flex; gap: 0.6rem; }

.key-box {
  margin-top: 1rem;
  padding: 0.9rem;
  border-radius: 10px;
  background: rgba(56, 189, 248, 0.1);
  border: 1px solid var(--accent);
}
.key-box pre { margin: 0.5rem 0 0; overflow-x: auto; font-size: 0.8rem; }

.admin-list { display: flex; flex-direction: column; gap: 0.55rem; }
.admin-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.8rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.admin-item-actions { display: flex; gap: 0.4rem; flex-shrink: 0; }

@media (max-width: 640px) {
  .topbar { padding: 0.75rem 1rem; }
  .two-col { grid-template-columns: 1fr; }
}
