/* ═══════════════════════════════════════════════════════════
   TJKAPI Dashboard — Design System
   Orange-Blue palette · Dark-first · DM Sans + JetBrains Mono
   ═══════════════════════════════════════════════════════════ */

/* ── Reset ───────────────────────────────────────────────── */

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

/* ── Tokens ──────────────────────────────────────────────── */

:root {
  /* ── Orange (accent) ── */
  --orange-50:  oklch(96% 0.04 60);
  --orange-100: oklch(90% 0.08 55);
  --orange-200: oklch(82% 0.12 50);
  --orange-300: oklch(74% 0.15 45);
  --orange-400: oklch(68% 0.17 40);
  --orange-500: oklch(62% 0.19 38);
  --orange-600: oklch(54% 0.16 35);
  --orange-700: oklch(46% 0.13 33);
  --orange-800: oklch(38% 0.10 30);
  --orange-900: oklch(28% 0.06 28);

  /* ── Blue (brand surface) ── */
  --blue-50:  oklch(96% 0.02 250);
  --blue-100: oklch(90% 0.04 250);
  --blue-200: oklch(82% 0.06 248);
  --blue-300: oklch(72% 0.08 245);
  --blue-400: oklch(62% 0.10 243);
  --blue-500: oklch(52% 0.12 240);
  --blue-600: oklch(42% 0.10 238);
  --blue-700: oklch(32% 0.07 236);
  --blue-800: oklch(22% 0.04 234);
  --blue-900: oklch(14% 0.03 232);
  --blue-950: oklch(10% 0.02 230);

  /* ── Neutrals (blue-tinted) ── */
  --neutral-50:  oklch(97% 0.005 250);
  --neutral-100: oklch(93% 0.005 250);
  --neutral-200: oklch(86% 0.008 248);
  --neutral-300: oklch(76% 0.008 245);
  --neutral-400: oklch(62% 0.008 242);
  --neutral-500: oklch(50% 0.008 240);
  --neutral-600: oklch(40% 0.008 238);
  --neutral-700: oklch(30% 0.008 236);
  --neutral-800: oklch(22% 0.006 234);
  --neutral-900: oklch(15% 0.005 232);
  --neutral-950: oklch(10% 0.005 230);

  /* ── Semantic ── */
  --success: oklch(65% 0.17 145);
  --success-soft: oklch(30% 0.06 145);
  --warning: oklch(75% 0.15 80);
  --warning-soft: oklch(30% 0.06 80);
  --danger: oklch(60% 0.20 20);
  --danger-hover: oklch(55% 0.20 20);
  --danger-soft: oklch(28% 0.07 20);
  --info: oklch(65% 0.12 240);
  --info-soft: oklch(28% 0.05 240);

  /* ── Spacing (4pt base) ── */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;
  --sp-12: 48px;
  --sp-16: 64px;
  --sp-20: 80px;
  --sp-24: 96px;

  /* ── Typography ── */
  --font-sans: "DM Sans", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;

  --text-xs:   clamp(0.6875rem, 0.65rem + 0.1vw, 0.75rem);
  --text-sm:   clamp(0.8125rem, 0.78rem + 0.1vw, 0.875rem);
  --text-base: clamp(0.875rem, 0.85rem + 0.1vw, 1rem);
  --text-lg:   clamp(1.0625rem, 1rem + 0.2vw, 1.25rem);
  --text-xl:   clamp(1.25rem, 1.1rem + 0.4vw, 1.5rem);
  --text-2xl:  clamp(1.5rem, 1.2rem + 0.8vw, 2rem);
  --text-3xl:  clamp(1.875rem, 1.5rem + 1vw, 2.5rem);

  --leading-tight: 1.2;
  --leading-normal: 1.5;
  --leading-relaxed: 1.65;

  --weight-light: 300;
  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;

  /* ── Radius ── */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 10px;
  --radius-xl: 14px;
  --radius-full: 9999px;

  /* ── Shadows (dark mode: lighter surfaces instead) ── */
  --shadow-sm: 0 1px 2px oklch(0% 0 0 / 0.15);
  --shadow-md: 0 2px 8px oklch(0% 0 0 / 0.2);
  --shadow-lg: 0 8px 24px oklch(0% 0 0 / 0.25);

  /* ── Z-index scale ── */
  --z-dropdown: 100;
  --z-sticky: 200;
  --z-overlay: 300;
  --z-modal: 400;
  --z-toast: 500;

  /* ── Transitions ── */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --duration-fast: 120ms;
  --duration-normal: 200ms;
  --duration-slow: 350ms;
}

/* ── Dark theme (default) ────────────────────────────────── */

[data-theme="dark"] {
  --bg-primary: var(--blue-950);
  --bg-secondary: var(--blue-900);
  --bg-tertiary: var(--neutral-800);
  --bg-surface: oklch(13% 0.025 232);
  --bg-surface-raised: oklch(17% 0.025 232);
  --bg-surface-overlay: oklch(20% 0.025 232);

  --text-primary: var(--neutral-100);
  --text-secondary: var(--neutral-300);
  --text-tertiary: var(--neutral-500);
  --text-inverse: var(--neutral-950);

  --border-primary: oklch(25% 0.015 232);
  --border-secondary: oklch(20% 0.01 232);
  --border-focus: var(--orange-500);

  --accent: var(--orange-500);
  --accent-hover: var(--orange-400);
  --accent-soft: oklch(25% 0.06 38);
  --accent-text: var(--orange-300);

  --sidebar-bg: oklch(11% 0.02 230);
  --sidebar-border: oklch(18% 0.015 232);
  --sidebar-active: var(--accent-soft);
  --sidebar-text: var(--neutral-400);
  --sidebar-text-active: var(--orange-300);

  --input-bg: oklch(15% 0.02 232);
  --input-border: oklch(25% 0.015 232);
  --input-focus-border: var(--orange-500);

  --table-header-bg: oklch(12% 0.02 232);
  --table-row-hover: oklch(16% 0.02 232);
  --table-border: oklch(20% 0.01 232);

  --badge-bg: oklch(22% 0.015 232);

  color-scheme: dark;
}

/* ── Light theme ─────────────────────────────────────────── */

[data-theme="light"] {
  --bg-primary: var(--neutral-50);
  --bg-secondary: oklch(99% 0.003 250);
  --bg-tertiary: var(--neutral-100);
  --bg-surface: oklch(100% 0 0);
  --bg-surface-raised: oklch(99% 0.003 250);
  --bg-surface-overlay: oklch(100% 0 0);

  --text-primary: var(--neutral-900);
  --text-secondary: var(--neutral-600);
  --text-tertiary: var(--neutral-400);
  --text-inverse: var(--neutral-50);

  --border-primary: var(--neutral-200);
  --border-secondary: var(--neutral-100);
  --border-focus: var(--orange-500);

  --accent: var(--orange-600);
  --accent-hover: var(--orange-500);
  --accent-soft: oklch(94% 0.04 45);
  --accent-text: var(--orange-700);

  --sidebar-bg: oklch(98% 0.005 250);
  --sidebar-border: var(--neutral-200);
  --sidebar-active: var(--accent-soft);
  --sidebar-text: var(--neutral-500);
  --sidebar-text-active: var(--orange-700);

  --input-bg: oklch(100% 0 0);
  --input-border: var(--neutral-200);
  --input-focus-border: var(--orange-500);

  --table-header-bg: var(--neutral-50);
  --table-row-hover: oklch(97% 0.005 250);
  --table-border: var(--neutral-200);

  --badge-bg: var(--neutral-100);

  color-scheme: light;
}

/* ── Base ────────────────────────────────────────────────── */

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: var(--weight-regular);
  line-height: var(--leading-normal);
  color: var(--text-primary);
  background: var(--bg-primary);
  min-height: 100vh;
}

/* ── Focus ───────────────────────────────────────────────── */

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

/* ── Layout ──────────────────────────────────────────────── */

.layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  margin: var(--sp-4) 0 0 var(--sp-4);
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
}

.sidebar-backdrop {
  display: none;
}

.layout__main {
  padding: var(--sp-8);
  overflow-y: auto;
  max-height: 100vh;
}

/* ── Page Header ─────────────────────────────────────────── */

.page-header {
  margin-bottom: var(--sp-8);
}

.page-header__title {
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  line-height: var(--leading-tight);
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.page-header__subtitle {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-top: var(--sp-1);
}

.page-header__actions {
  display: flex;
  gap: var(--sp-3);
  margin-top: var(--sp-5);
}

/* ── Stat Blocks ─────────────────────────────────────────── */

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--sp-4);
  margin-bottom: var(--sp-8);
}

.stat {
  background: var(--bg-surface);
  border: 1px solid var(--border-secondary);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
}

.stat__label {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stat__value {
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
  margin-top: var(--sp-1);
  letter-spacing: -0.02em;
}

.stat__value--accent {
  color: var(--accent-text);
}

.stat__delta {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  margin-top: var(--sp-1);
  font-variant-numeric: tabular-nums;
}

/* ── Buttons ─────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  line-height: 1;
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition:
    background-color var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) var(--ease-out),
    color var(--duration-fast) var(--ease-out),
    opacity var(--duration-fast) var(--ease-out),
    box-shadow var(--duration-fast) var(--ease-out);
  text-decoration: none;
  white-space: nowrap;
  min-height: 44px;
}

.btn:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

.btn--primary {
  background: var(--accent);
  color: var(--text-inverse);
  border-color: var(--accent);
}
.btn--primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn--secondary {
  background: transparent;
  color: var(--text-primary);
  border-color: var(--border-primary);
}
.btn--secondary:hover {
  background: var(--bg-surface-raised);
  border-color: var(--border-focus);
}

.btn--ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}
.btn--ghost:hover {
  color: var(--text-primary);
  background: var(--bg-surface-raised);
}

.btn--danger {
  background: var(--danger);
  color: var(--neutral-50);
  border-color: var(--danger);
}
.btn--danger:hover {
  background: var(--danger-hover);
}

.btn--link {
  background: none;
  border: none;
  color: var(--accent-text);
  padding: 0;
  min-height: auto;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  cursor: pointer;
  transition: color var(--duration-fast);
}
.btn--link:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

.btn--sm {
  font-size: var(--text-xs);
  padding: var(--sp-1) var(--sp-3);
  min-height: 44px;
}

.btn--icon {
  padding: var(--sp-2);
  min-height: 44px;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* ── Inputs ──────────────────────────────────────────────── */

.input-group {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}

.input-group__label {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.input-group__hint {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  line-height: var(--leading-relaxed);
}

.input {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  color: var(--text-primary);
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-md);
  padding: var(--sp-2) var(--sp-3);
  min-height: 44px;
  transition: border-color var(--duration-fast) var(--ease-out);
  width: 100%;
}

.input:focus {
  outline: none;
  border-color: var(--input-focus-border);
  box-shadow: 0 0 0 3px oklch(62% 0.19 38 / 0.15);
}

.input::placeholder {
  color: var(--text-tertiary);
}

.input--mono {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

select.input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23777' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--sp-3) center;
  padding-right: var(--sp-8);
}

/* ── Badges ──────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1-5, 6px);
  font-size: 11px;
  font-weight: var(--weight-semibold);
  padding: 2px var(--sp-2);
  border-radius: 4px;
  line-height: 1.2;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.badge--healthy  { background: var(--success-soft); color: var(--success); border: 1px solid color-mix(in oklch, var(--success), transparent 80%); }
.badge--degraded { background: var(--warning-soft); color: var(--warning); border: 1px solid color-mix(in oklch, var(--warning), transparent 80%); }
.badge--down     { background: var(--danger-soft);  color: var(--danger);  border: 1px solid color-mix(in oklch, var(--danger), transparent 80%); }
.badge--unknown  { background: var(--badge-bg);     color: var(--text-tertiary); border: 1px solid var(--border-secondary); }
.badge--active   { background: var(--success-soft); color: var(--success); }
.badge--inactive { background: var(--badge-bg);     color: var(--text-tertiary); }
.badge--admin    { background: var(--accent-soft);  color: var(--accent-text); border: 1px solid color-mix(in oklch, var(--accent), transparent 80%); }
.badge--user     { background: var(--badge-bg);     color: var(--text-secondary); border: 1px solid var(--border-secondary); }

.badge__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

@keyframes pulse {
  0% { transform: scale(1); opacity: 0.8; }
  50% { transform: scale(1.25); opacity: 1; }
  100% { transform: scale(1); opacity: 0.8; }
}

.badge--healthy .badge__dot {
  animation: pulse 2s infinite ease-in-out;
}

/* ── Provider Health ─────────────────────────────────────── */

.health-header {
  display: grid;
  grid-template-columns: 1fr 100px 80px;
  padding: var(--sp-2) var(--sp-5);
  background: var(--table-header-bg);
  border-bottom: 1px solid var(--border-secondary);
  font-size: 10px;
  font-weight: var(--weight-bold);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.provider-health-row {
  display: grid;
  grid-template-columns: 1fr 100px 80px;
  align-items: center;
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border-secondary);
  transition: background 0.1s ease;
}

.provider-health-row:last-child {
  border-bottom: none;
}

.provider-health-row:hover {
  background: var(--table-row-hover);
}

.provider-health-row__info {
  min-width: 0;
  padding-right: var(--sp-4);
}

.provider-health-row__name-line {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: 2px;
}

.provider-health-row__name {
  font-weight: var(--weight-medium);
  font-size: var(--text-sm);
  color: var(--text-primary);
}

.provider-health-row__type {
  font-family: var(--font-mono);
  font-size: 9px;
  background: var(--blue-900);
  color: var(--blue-300);
  padding: 0 4px;
  border-radius: 3px;
  text-transform: uppercase;
  border: 1px solid var(--blue-800);
  font-weight: var(--weight-bold);
}

.provider-health-row__priority {
  font-size: 10px;
  color: var(--text-tertiary);
  font-weight: var(--weight-semibold);
}

.provider-health-row__url {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0.7;
}

.provider-health-row__last-check {
  font-size: 11px;
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
}

.provider-health-row__status {
  display: flex;
  justify-content: flex-end;
}

.table-container {
  width: 100%;
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-secondary);
  background: var(--bg-surface);
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.data-table th {
  text-align: left;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: var(--sp-3) var(--sp-4);
  background: var(--table-header-bg);
  border-bottom: 1px solid var(--table-border);
  white-space: nowrap;
}

.data-table td {
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--table-border);
  color: var(--text-primary);
}

.data-table tr:hover td {
  background: var(--table-row-hover);
}

.data-table__actions {
  display: flex;
  gap: var(--sp-1);
  justify-content: flex-end;
}

/* ── Section ─────────────────────────────────────────────── */

.section {
  background: var(--bg-surface);
  border: 1px solid var(--border-secondary);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.section__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border-secondary);
}

.section__title {
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
}

.section__body {
  padding: var(--sp-5);
}

.section__body--flush {
  padding: 0;
}

.section__footer {
  padding: var(--sp-3) var(--sp-5);
  border-top: 1px solid var(--border-secondary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

/* ── Modal (overlay) ─────────────────────────────────────── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: oklch(0% 0 0 / 0.6);
  z-index: var(--z-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-6);
  opacity: 0;
  animation: fadeIn var(--duration-normal) var(--ease-out) forwards;
}

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
  transform: translateY(12px) scale(0.97);
  animation: modalIn var(--duration-slow) var(--ease-out) forwards;
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-5) var(--sp-6);
  border-bottom: 1px solid var(--border-secondary);
}

.modal__title {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
}

.modal__close {
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: var(--sp-1);
  font-size: var(--text-xl);
  line-height: 1;
  transition: color var(--duration-fast);
}
.modal__close:hover { color: var(--text-primary); }

.modal__body {
  padding: var(--sp-6);
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
}

.modal__footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-6);
  border-top: 1px solid var(--border-secondary);
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
}

/* ── Toast ───────────────────────────────────────────────── */

.toast-container {
  position: fixed;
  top: var(--sp-6);
  right: var(--sp-6);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  pointer-events: none;
}

.toast {
  background: var(--bg-surface-raised);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  padding: var(--sp-3) var(--sp-5);
  font-size: var(--text-sm);
  color: var(--text-primary);
  pointer-events: auto;
  max-width: 380px;
  transform: translateX(120%);
  animation: toastIn var(--duration-slow) var(--ease-out) forwards;
}

.toast--success { border: 1px solid var(--success); background: oklch(30% 0.06 145 / 0.15); }
.toast--error   { border: 1px solid var(--danger); background: oklch(28% 0.07 20 / 0.15); }
.toast--warning { border: 1px solid var(--warning); background: oklch(30% 0.06 80 / 0.15); }
.toast--info    { border: 1px solid var(--info); background: oklch(28% 0.05 240 / 0.15); }

.toast-exit {
  animation: toastOut var(--duration-normal) var(--ease-in-out) forwards;
}

/* ── Login Page ──────────────────────────────────────────── */

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--sp-6);
  background: var(--bg-primary);
}

.login-card {
  width: 100%;
  max-width: 380px;
}

.login-card__brand {
  margin-bottom: var(--sp-8);
}

.login-card__logo {
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
  color: var(--text-primary);
  letter-spacing: -0.03em;
}

.login-card__logo span {
  color: var(--accent-text);
}

.login-card__tagline {
  font-size: var(--text-sm);
  color: var(--text-tertiary);
  margin-top: var(--sp-1);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
}

.login-form .btn--primary {
  margin-top: var(--sp-2);
  min-height: 44px;
  justify-content: center;
}

.login-card__footer {
  margin-top: var(--sp-6);
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  text-align: center;
}

.login-card__footer a {
  color: var(--accent-text);
  text-decoration: none;
}
.login-card__footer a:hover {
  text-decoration: underline;
}

/* ── Sidebar ─────────────────────────────────────────────── */

.sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  height: 100vh;
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar__brand {
  padding: var(--sp-5) var(--sp-5);
  border-bottom: 1px solid var(--sidebar-border);
}

.sidebar__logo {
  font-size: var(--text-base);
  font-weight: var(--weight-bold);
  color: var(--text-primary);
  letter-spacing: -0.03em;
  text-decoration: none;
}

.sidebar__logo span {
  color: var(--accent-text);
}

.sidebar__version {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-top: 2px;
}

.sidebar__nav {
  flex: 1;
  padding: var(--sp-3) var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar__section-label {
  font-size: 0.6875rem;
  font-weight: var(--weight-semibold);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: var(--sp-4) var(--sp-3) var(--sp-2);
}

.sidebar__link {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-md);
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  transition:
    color var(--duration-fast) var(--ease-out),
    background var(--duration-fast) var(--ease-out);
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.sidebar__link:hover {
  color: var(--text-primary);
  background: var(--bg-surface-raised);
}

.sidebar__link--active {
  color: var(--sidebar-text-active);
  background: var(--sidebar-active);
}

.sidebar__link svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.7;
}

.sidebar__link--active svg {
  opacity: 1;
}

.sidebar__footer {
  padding: var(--sp-4) var(--sp-3);
  border-top: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}

.sidebar__user {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.sidebar__avatar {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  background: var(--accent-soft);
  color: var(--accent-text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  flex-shrink: 0;
}

/* ── Code / Mono blocks ──────────────────────────────────── */

.code-block {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  background: var(--bg-tertiary);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-md);
  overflow-x: auto;
  color: var(--text-secondary);
  border: 1px solid var(--border-secondary);
}

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

/* ── Copy button ─────────────────────────────────────────── */

.copy-area {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-md);
  padding: 0 var(--sp-3);
  min-height: 44px;
}

.copy-area__text {
  flex: 1;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  user-select: all;
}

.copy-area__btn {
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 0;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--duration-fast);
  flex-shrink: 0;
}
.copy-area__btn:hover { color: var(--accent-text); }

/* ── Chart area ──────────────────────────────────────────── */

.chart-container {
  position: relative;
  width: 100%;
  height: 200px;
}

.chart-container canvas {
  width: 100% !important;
  height: 100% !important;
}

/* ── Empty State ─────────────────────────────────────────── */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--sp-12) var(--sp-6);
  text-align: center;
  color: var(--text-tertiary);
  border: 1px dashed var(--border-primary);
  border-radius: var(--radius-lg);
  background: var(--bg-surface-raised);
}

.empty-state__icon {
  width: 48px;
  height: 48px;
  margin-bottom: var(--sp-4);
  color: var(--text-tertiary);
  opacity: 0.5;
}

.empty-state__title {
  font-size: var(--text-lg);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
  margin-bottom: var(--sp-1);
}

.empty-state__text {
  font-size: var(--text-sm);
  max-width: 45ch;
  margin: 0 auto;
  line-height: var(--leading-relaxed);
}

.empty-state .btn {
  margin-top: var(--sp-5);
}

/* ── Pagination ──────────────────────────────────────────── */

.pagination {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.pagination__info {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
}

/* ── Utility ─────────────────────────────────────────────── */

.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--sp-2); }
.gap-3 { gap: var(--sp-3); }
.gap-4 { gap: var(--sp-4); }
.mt-4 { margin-top: var(--sp-4); }
.mt-6 { margin-top: var(--sp-6); }
.text-secondary { color: var(--text-secondary); }
.text-sm { font-size: var(--text-sm); }
.font-mono { font-family: var(--font-mono); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Animations ──────────────────────────────────────────── */

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes modalIn {
  from { transform: translateY(12px) scale(0.97); opacity: 0; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}

@keyframes toastIn {
  from { transform: translateX(120%); }
  to   { transform: translateX(0); }
}

@keyframes toastOut {
  from { transform: translateX(0); opacity: 1; }
  to   { transform: translateX(120%); opacity: 0; }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border-primary);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

/* ── Page transition ─────────────────────────────────────── */

.page-enter {
  animation: pageIn var(--duration-slow) var(--ease-out);
}

@keyframes pageIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Utilities ───────────────────────────────────────────── */

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar__user-meta {
  min-width: 0;
}

.sidebar__user-name {
  font-weight: var(--weight-medium);
  color: var(--text-primary);
  overflow-wrap: anywhere;
}

.sidebar__user-role {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  overflow-wrap: anywhere;
}

/* ── Responsive ──────────────────────────────────────────── */

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

  .sidebar-toggle {
    position: sticky;
    top: var(--sp-4);
    left: var(--sp-4);
    z-index: calc(var(--z-overlay) + 1);
    display: inline-flex;
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: oklch(0% 0 0 / 0.45);
    z-index: var(--z-overlay);
    border: 0;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--duration-fast) var(--ease-out);
    display: block;
  }

  .sidebar-backdrop--open {
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar {
    position: fixed;
    left: -260px;
    width: 240px;
    z-index: var(--z-overlay);
    transition: left var(--duration-slow) var(--ease-out);
  }

  .sidebar--open {
    left: 0;
  }

  .layout__main {
    padding: var(--sp-5);
  }

  .stats-row {
    grid-template-columns: 1fr 1fr;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

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

/* ── Reduced motion ──────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .loading-spinner {
    animation: none;
    border-top-color: var(--border-primary);
    opacity: 0.8;
  }

  .page-enter,
  .modal-backdrop,
  .modal,
  .toast,
  .toast-exit {
    animation: none !important;
  }
}

/* ═══════════════════════════════════════════════════════════
   PLAYGROUND
   ═══════════════════════════════════════════════════════════ */

.playground-page {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--sp-16));
}

.playground-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: var(--sp-5);
  flex: 1;
  min-height: 0;
}

/* ── Controls sidebar ─────────────────────────────────────── */

.playground-controls {
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow-y: auto;
  padding-right: var(--sp-1);
}

/* ── Slider ───────────────────────────────────────────────── */

.playground-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: var(--radius-full);
  background: var(--border-primary);
  outline: none;
  cursor: pointer;
  transition: background var(--duration-fast);
}

.playground-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--bg-primary);
  box-shadow: 0 0 0 1px var(--accent);
  transition: transform var(--duration-fast) var(--ease-out);
}

.playground-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

.playground-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--bg-primary);
  box-shadow: 0 0 0 1px var(--accent);
}

.playground-slider-labels {
  display: flex;
  justify-content: space-between;
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-top: var(--sp-1);
}

.playground-param-val {
  font-family: var(--font-mono);
  color: var(--accent-text);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  margin-left: var(--sp-2);
}

/* ── Toggle ───────────────────────────────────────────────── */

.playground-toggle {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  cursor: pointer;
  user-select: none;
}

.playground-toggle input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.playground-toggle__track {
  position: relative;
  width: 36px;
  height: 20px;
  border-radius: var(--radius-full);
  background: var(--border-primary);
  flex-shrink: 0;
  transition: background var(--duration-fast) var(--ease-out);
}

.playground-toggle__track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text-tertiary);
  transition: transform var(--duration-fast) var(--ease-out), background var(--duration-fast) var(--ease-out);
}

.playground-toggle input:checked + .playground-toggle__track {
  background: var(--accent-soft);
  border: 1px solid color-mix(in oklch, var(--accent), transparent 60%);
}

.playground-toggle input:checked + .playground-toggle__track::after {
  transform: translateX(16px);
  background: var(--accent);
}

.playground-toggle__label {
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

/* ── Textareas ────────────────────────────────────────────── */

.playground-textarea {
  resize: none;
  border-radius: 0;
  border: none;
  background: transparent;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
  padding: var(--sp-4);
  width: 100%;
  color: var(--text-primary);
  min-height: 0;
}

.playground-textarea:focus {
  outline: none;
  border-color: transparent;
  box-shadow: none;
}

.playground-textarea--system {
  border-top: 1px solid var(--border-secondary);
}

.playground-textarea--user {
  flex: 1;
  min-height: 44px;
  max-height: 180px;
  overflow-y: auto;
  border-right: 1px solid var(--border-secondary);
  border-radius: 0;
}

/* ── Chat panel layout ────────────────────────────────────── */

.playground-chat {
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border: 1px solid var(--border-secondary);
  border-radius: var(--radius-lg);
  overflow: hidden;
  min-height: 0;
}

/* ── Messages area ────────────────────────────────────────── */

.playground-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  scroll-behavior: smooth;
}

/* ── Welcome state ────────────────────────────────────────── */

.playground-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--sp-12) var(--sp-6);
  flex: 1;
  margin: auto;
  max-width: 360px;
}

.playground-welcome__icon {
  width: 48px;
  height: 48px;
  color: var(--text-tertiary);
  opacity: 0.4;
  margin-bottom: var(--sp-4);
}

.playground-welcome__icon svg {
  width: 100%;
  height: 100%;
}

.playground-welcome__text {
  font-size: var(--text-base);
  color: var(--text-secondary);
  font-weight: var(--weight-medium);
  margin-bottom: var(--sp-2);
}

.playground-welcome__hint {
  font-size: var(--text-sm);
  color: var(--text-tertiary);
  line-height: var(--leading-relaxed);
}

/* ── Message bubbles ──────────────────────────────────────── */

.playground-msg {
  display: flex;
  animation: pageIn var(--duration-normal) var(--ease-out);
}

.playground-msg--user {
  justify-content: flex-end;
}

.playground-msg--assistant {
  justify-content: flex-start;
}

.playground-msg__bubble {
  max-width: 82%;
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}

.playground-msg--user .playground-msg__bubble {
  align-items: flex-end;
}

.playground-msg__role {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  padding: 0 var(--sp-1);
}

.playground-msg__content {
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
  word-break: break-word;
  white-space: pre-wrap;
}

.playground-msg--user .playground-msg__content {
  background: var(--accent-soft);
  color: var(--text-primary);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-sm) var(--radius-lg);
  border: 1px solid color-mix(in oklch, var(--accent), transparent 70%);
}

.playground-msg--assistant .playground-msg__content {
  background: var(--bg-surface-raised);
  color: var(--text-primary);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) var(--radius-sm);
  border: 1px solid var(--border-secondary);
}

.playground-msg__content--streaming {
  position: relative;
}

.playground-msg__content--error {
  background: var(--danger-soft) !important;
  border-color: color-mix(in oklch, var(--danger), transparent 60%) !important;
  color: var(--danger) !important;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

.playground-msg__meta {
  font-size: 10px;
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
  padding: 0 var(--sp-1);
}

/* ── Code in responses ────────────────────────────────────── */

.playground-code-block {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-secondary);
  border-radius: var(--radius-md);
  padding: var(--sp-3) var(--sp-4);
  overflow-x: auto;
  margin: var(--sp-2) 0;
  white-space: pre;
}

.playground-inline-code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--bg-tertiary);
  padding: 1px 5px;
  border-radius: 3px;
}

/* ── Streaming cursor ─────────────────────────────────────── */

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

.playground-cursor {
  display: inline-block;
  width: 2px;
  height: 1.1em;
  background: var(--accent);
  border-radius: 1px;
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 0.8s step-end infinite;
}

/* ── Input bar ────────────────────────────────────────────── */

.playground-input-bar {
  display: flex;
  align-items: flex-end;
  border-top: 1px solid var(--border-secondary);
  background: var(--bg-surface);
}

.playground-input-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3);
  flex-shrink: 0;
}

/* ── Status bar ───────────────────────────────────────────── */

.playground-status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-2) var(--sp-4);
  border-top: 1px solid var(--border-secondary);
  background: var(--table-header-bg);
  min-height: 32px;
}

.playground-status-bar__text {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
}

.playground-status-bar__text--error {
  color: var(--danger);
}

.playground-status-bar__stats {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

/* ── Responsive ───────────────────────────────────────────── */

@media (max-width: 900px) {
  .playground-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .playground-page {
    height: auto;
  }

  .playground-chat {
    min-height: 500px;
  }

  .playground-msg__bubble {
    max-width: 92%;
  }
}
