/* ============================================================
   Tesla Platform — Web/API Health Validation
   Modern CSS design system, dark-mode native, oklch palette
   Based on Miton Monitoring design system
   ============================================================ */

@import url('https://rsms.me/inter/inter.css');

/* ---------- Tokens ---------- */
:root {
  color-scheme: dark light;

  /* Surface colors (dark default) */
  --bg: oklch(14% 0.012 270);
  --bg-elevated: oklch(18% 0.014 270);
  --bg-hover: oklch(22% 0.016 270);
  --surface: oklch(20% 0.014 270);
  --surface-2: oklch(24% 0.018 270);
  --border: oklch(28% 0.016 270);
  --border-strong: oklch(36% 0.020 270);

  /* Text */
  --text: oklch(96% 0.005 270);
  --text-muted: oklch(70% 0.012 270);
  --text-subtle: oklch(55% 0.014 270);

  /* Accent — electric cyan/blue for Tesla */
  --accent: oklch(72% 0.16 230);
  --accent-hover: oklch(76% 0.18 230);
  --accent-soft: oklch(26% 0.08 230);
  --accent-text: oklch(85% 0.14 230);

  /* Status colors */
  --success: oklch(72% 0.18 155);
  --success-soft: oklch(26% 0.08 155);
  --success-text: oklch(82% 0.16 155);

  --warning: oklch(80% 0.16 75);
  --warning-soft: oklch(28% 0.08 75);
  --warning-text: oklch(86% 0.15 75);

  --danger: oklch(68% 0.22 25);
  --danger-soft: oklch(28% 0.10 25);
  --danger-text: oklch(80% 0.18 25);

  --info: oklch(72% 0.16 270);
  --info-soft: oklch(26% 0.08 270);
  --info-text: oklch(82% 0.14 270);

  /* Spacing scale */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;

  /* Radius */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  /* Shadows */
  --shadow-sm: 0 1px 2px oklch(0% 0 0 / 0.3);
  --shadow: 0 4px 12px oklch(0% 0 0 / 0.35), 0 1px 3px oklch(0% 0 0 / 0.4);
  --shadow-lg: 0 16px 48px oklch(0% 0 0 / 0.5), 0 4px 12px oklch(0% 0 0 / 0.4);

  /* Layout */
  --sidebar-w: 248px;
  --topbar-h: 64px;

  /* Type */
  --font-sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Consolas, monospace;

  /* Motion */
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --duration: 180ms;
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }

html {
  font-family: var(--font-sans);
  font-feature-settings: 'cv11', 'ss01', 'ss03';
  -webkit-font-smoothing: antialiased;
  text-size-adjust: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  min-height: 100vh;
  overflow-x: hidden;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; background: none; border: none; color: inherit; }
input, select, textarea { font: inherit; color: inherit; }
table { border-collapse: collapse; width: 100%; }

/* ---------- Layout shell ---------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* Background ambient gradient */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 800px 600px at 0% 0%, oklch(60% 0.16 230 / 0.08), transparent 60%),
    radial-gradient(ellipse 600px 500px at 100% 100%, oklch(60% 0.14 190 / 0.05), transparent 60%);
  z-index: 0;
}

/* ---------- Sidebar ---------- */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 10;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-5);
  height: var(--topbar-h);
  border-bottom: 1px solid var(--border);
}

.sidebar__logo {
  width: 32px;
  height: 32px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, oklch(72% 0.16 230), oklch(60% 0.18 190));
  display: grid;
  place-items: center;
  color: white;
  font-weight: 800;
  font-size: 14px;
  box-shadow: 0 4px 12px oklch(60% 0.16 230 / 0.4), inset 0 1px 0 oklch(100% 0 0 / 0.3);
}

.sidebar__title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.sidebar__sub {
  font-size: 12px;
  color: var(--text-subtle);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.sidebar__nav {
  display: flex;
  flex-direction: column;
  padding: var(--space-4) var(--space-3);
  gap: var(--space-1);
  flex: 1;
}

.sidebar__group {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-subtle);
  padding: var(--space-4) var(--space-3) var(--space-2);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 14px;
  transition: all var(--duration) var(--ease);
  position: relative;
  text-decoration: none;
}

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent-text);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: -12px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 18px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}

.nav-item svg {
  width: 18px;
  height: 18px;
  stroke-width: 2;
  flex-shrink: 0;
}

.sidebar__footer {
  padding: var(--space-4);
  border-top: 1px solid var(--border);
}

.sidebar__footer form {
  display: flex;
  align-items: center;
  width: 100%;
}

.sidebar__footer button {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text-subtle);
  font-size: 13px;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  transition: all var(--duration) var(--ease);
  width: 100%;
}

.sidebar__footer button:hover {
  background: var(--bg-hover);
  color: var(--danger-text);
}

/* ---------- Main + topbar ---------- */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
  z-index: 1;
}

.topbar {
  position: sticky;
  top: 0;
  height: var(--topbar-h);
  background: oklch(from var(--bg) l c h / 0.7);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: 0 var(--space-8);
  z-index: 5;
}

.topbar__title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.topbar__actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* ---------- Page content ---------- */
.page {
  padding: var(--space-8);
  width: 100%;
  margin: 0 auto;
}

.page__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--space-8);
  gap: var(--space-4);
}

.page__title {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: var(--space-2);
}

.page__subtitle {
  color: var(--text-muted);
  font-size: 15px;
}

/* ---------- Stats ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-8);
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  position: relative;
  overflow: hidden;
  transition: all var(--duration) var(--ease);
}

.stat:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
}

.stat__icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  margin-bottom: var(--space-4);
}

.stat__icon svg { width: 20px; height: 20px; stroke-width: 2; }
.stat__icon--accent { background: var(--accent-soft); color: var(--accent-text); }
.stat__icon--success { background: var(--success-soft); color: var(--success-text); }
.stat__icon--warning { background: var(--warning-soft); color: var(--warning-text); }
.stat__icon--danger { background: var(--danger-soft); color: var(--danger-text); }
.stat__icon--info { background: var(--info-soft); color: var(--info-text); }

.stat__label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: var(--space-2);
}

.stat__value {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-feature-settings: 'tnum';
  line-height: 1.1;
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  transition: all var(--duration) var(--ease);
}

.card--hover:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}

.card__title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.card__sub {
  font-size: 13px;
  color: var(--text-subtle);
}

/* ---------- Tables ---------- */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.table {
  font-size: 14px;
}

.table thead th {
  background: var(--surface-2);
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table tbody td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.table tbody tr:last-child td { border-bottom: none; }

.table tbody tr {
  transition: background var(--duration) var(--ease);
}

.table tbody tr:hover {
  background: var(--bg-hover);
}

.table .mono { font-family: var(--font-mono); font-size: 13px; color: var(--text-muted); }
.table .num { font-feature-settings: 'tnum'; font-variant-numeric: tabular-nums; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.badge--success { background: var(--success-soft); color: var(--success-text); }
.badge--warning { background: var(--warning-soft); color: var(--warning-text); }
.badge--danger { background: var(--danger-soft); color: var(--danger-text); }
.badge--info { background: var(--info-soft); color: var(--info-text); }
.badge--accent { background: var(--accent-soft); color: var(--accent-text); }
.badge--muted { background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }

.badge .pulse {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 currentColor; }
  70% { box-shadow: 0 0 0 6px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  transition: all var(--duration) var(--ease);
  cursor: pointer;
  text-decoration: none;
}

.btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

.btn svg { width: 16px; height: 16px; }

.btn--primary {
  background: linear-gradient(180deg, oklch(76% 0.16 230), oklch(68% 0.16 230));
  border-color: oklch(60% 0.16 230);
  color: white;
  box-shadow: 0 1px 0 oklch(100% 0 0 / 0.2) inset, 0 2px 8px oklch(60% 0.16 230 / 0.3);
}

.btn--primary:hover {
  background: linear-gradient(180deg, oklch(80% 0.16 230), oklch(72% 0.16 230));
  transform: translateY(-1px);
  box-shadow: 0 1px 0 oklch(100% 0 0 / 0.2) inset, 0 4px 14px oklch(60% 0.16 230 / 0.4);
}

.btn--success {
  background: var(--success-soft);
  border-color: oklch(40% 0.10 155);
  color: var(--success-text);
}

.btn--danger {
  background: var(--danger-soft);
  border-color: oklch(40% 0.12 25);
  color: var(--danger-text);
}

.btn--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}

.btn--ghost:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.btn--sm { padding: 7px 12px; font-size: 13px; }

/* ---------- Forms ---------- */
.form-group { margin-bottom: var(--space-5); }

.label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: var(--space-2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.input, .select {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text);
  transition: all var(--duration) var(--ease);
}

.input:focus, .select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px oklch(60% 0.16 230 / 0.2);
}

.input--sm { padding: 7px 10px; font-size: 13px; }
.select--sm { padding: 7px 10px; font-size: 13px; }

.checkbox {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ---------- Alerts ---------- */
.alert {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  font-size: 14px;
  margin-bottom: var(--space-4);
}

.alert--success { background: var(--success-soft); color: var(--success-text); border: 1px solid oklch(40% 0.10 155); }
.alert--danger { background: var(--danger-soft); color: var(--danger-text); border: 1px solid oklch(40% 0.10 25); }

/* ---------- Login ---------- */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--space-4);
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--space-10);
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
}

.login-card__title {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  text-align: center;
  margin-bottom: var(--space-2);
}

.login-card__sub {
  font-size: 14px;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: var(--space-8);
}

/* ---------- Misc ---------- */
.section-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: var(--space-4);
}

.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.mt-4 { margin-top: var(--space-4); }
.mt-8 { margin-top: var(--space-8); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-8 { margin-bottom: var(--space-8); }

.text-muted { color: var(--text-muted); }
.text-subtle { color: var(--text-subtle); }
.text-success { color: var(--success-text); }
.text-warning { color: var(--warning-text); }
.text-danger { color: var(--danger-text); }
.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.font-mono { font-family: var(--font-mono); }
.tnum { font-feature-settings: 'tnum'; font-variant-numeric: tabular-nums; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

/* Table row status highlight */
.table tbody tr.row--danger td { background: oklch(from var(--danger-soft) l c h / 0.3); }
.table tbody tr.row--warning td { background: oklch(from var(--warning-soft) l c h / 0.3); }

/* Mobile */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .page { padding: var(--space-4); }
  .topbar { padding: 0 var(--space-4); }
  .stats { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 600px) {
  .stats { grid-template-columns: 1fr; }
}
