/* ============================================================
   Token Relay Hub · Admin Dashboard Design System
   SaaS console · dark sidebar · dense · functional
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* ===== Design Tokens ===== */
:root {
  /* Brand — Indigo */
  --brand-50: #EEF2FF;
  --brand-100: #E0E7FF;
  --brand-200: #C7D2FE;
  --brand-300: #A5B4FC;
  --brand-400: #818CF8;
  --brand-500: #6366F1;
  --brand-600: #4F46E5;
  --brand-700: #4338CA;
  --brand-800: #3730A3;
  --brand-900: #312E81;

  /* Neutral — warm gray */
  --n-0: #FFFFFF;
  --n-25: #FEFCFD;
  --n-50: #FAFAF9;
  --n-100: #F4F4F5;
  --n-200: #E4E4E7;
  --n-300: #D4D4D8;
  --n-400: #A1A1AA;
  --n-500: #71717A;
  --n-600: #52525B;
  --n-700: #3F3F46;
  --n-800: #27272A;
  --n-900: #18181B;
  --n-950: #09090B;

  /* Semantic */
  --success-50: #ECFDF5;
  --success-100: #D1FAE5;
  --success-500: #10B981;
  --success-600: #059669;
  --success-700: #047857;

  --warning-50: #FFFBEB;
  --warning-100: #FEF3C7;
  --warning-500: #F59E0B;
  --warning-600: #D97706;

  --error-50: #FEF2F2;
  --error-100: #FEE2E2;
  --error-500: #EF4444;
  --error-600: #DC2626;

  --info-50: #EFF6FF;
  --info-500: #3B82F6;
  --info-600: #2563EB;

  /* Accent — for provider badges */
  --purple-50: #F5F3FF;
  --purple-500: #8B5CF6;
  --purple-600: #7C3AED;
  --orange-50: #FFF7ED;
  --orange-500: #F97316;
  --orange-600: #EA580C;

  /* Typography */
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft YaHei', sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', Consolas, monospace;

  /* Radius */
  --r-xs: 4px;
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-xl: 16px;

  /* Shadows */
  --shadow-xs: 0 1px 2px 0 rgba(0,0,0,0.04);
  --shadow-sm: 0 1px 3px 0 rgba(0,0,0,0.06), 0 1px 2px 0 rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.1), 0 8px 10px -6px rgba(0,0,0,0.06);

  /* Transitions */
  --t-fast: 120ms ease;
  --t-normal: 220ms ease;
  --t-slow: 400ms ease;

  /* Layout */
  --sidebar-w: 240px;
  --content-max: 1400px;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-sans);
  background: var(--n-50);
  color: var(--n-900);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand-600); text-decoration: none; transition: color var(--t-fast); }
a:hover { color: var(--brand-700); text-decoration: underline; }
code, .mono { font-family: var(--font-mono); font-size: 0.92em; }

/* ===== Login Page ===== */
body.login-page {
  background: var(--n-950);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  position: relative;
  overflow: hidden;
}

body.login-page::before {
  content: '';
  position: absolute;
  top: -20%;
  right: -10%;
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, rgba(79,70,229,0.25), transparent 70%);
  pointer-events: none;
}

body.login-page::after {
  content: '';
  position: absolute;
  bottom: -20%;
  left: -10%;
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, rgba(139,92,246,0.18), transparent 70%);
  pointer-events: none;
}

.login-card {
  background: var(--n-0);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 420px;
  padding: 40px;
  position: relative;
  z-index: 1;
}

.login-card .login-brand {
  font-weight: 800;
  font-size: 18px;
  color: var(--n-900);
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  letter-spacing: -0.02em;
}

.login-card .login-mark {
  width: 36px;
  height: 36px;
  border-radius: var(--r-md);
  background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 18px;
  box-shadow: 0 4px 12px rgba(79,70,229,0.3);
}

.login-card h1 {
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  margin: 20px 0 4px;
  letter-spacing: -0.02em;
}

.login-card .muted {
  text-align: center;
  color: var(--n-500);
  font-size: 13px;
  margin-bottom: 28px;
}

/* ===== App Shell ===== */
.app-shell { display: flex; min-height: 100vh; }

/* ===== Sidebar (dark) ===== */
.sidebar {
  width: var(--sidebar-w);
  background: var(--n-950);
  padding: 20px 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
  z-index: 20;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-brand {
  padding: 0 20px 16px;
  font-weight: 800;
  font-size: 16px;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 10px;
  letter-spacing: -0.02em;
}

.sidebar-brand .brand-mark {
  width: 28px;
  height: 28px;
  border-radius: var(--r-sm);
  background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.sidebar-label {
  padding: 10px 20px 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--n-500);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  color: var(--n-400);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  margin: 1px 8px;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: all var(--t-fast);
}

.sidebar-item span:first-child { font-size: 15px; width: 20px; text-align: center; flex-shrink: 0; }

.sidebar-item:hover {
  color: #fff;
  background: rgba(255,255,255,0.06);
  text-decoration: none;
}

.sidebar-item.active {
  color: #fff;
  background: var(--brand-600);
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(79,70,229,0.3);
}

.sidebar-footer {
  margin-top: auto;
  padding: 16px 20px 12px;
  font-size: 12px;
  color: var(--n-500);
  border-top: 1px solid var(--n-800);
}

.sidebar-footer .admin-info {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.sidebar-footer .admin-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-400), var(--brand-600));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}

.sidebar-footer a { color: var(--n-400); }
.sidebar-footer a:hover { color: #fff; text-decoration: none; }

/* ===== Main Content ===== */
.app-main {
  flex: 1;
  margin-left: var(--sidebar-w);
  padding: 28px 32px 48px;
  min-width: 0;
}

/* Mobile topbar */
.mobile-topbar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 52px;
  background: var(--n-0);
  border-bottom: 1px solid var(--n-200);
  z-index: 15;
  padding: 0 16px;
  align-items: center;
  gap: 12px;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(9,9,11,0.5);
  z-index: 19;
}

@media(max-width: 860px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform var(--t-normal);
    box-shadow: var(--shadow-xl);
  }
  .sidebar.open { transform: translateX(0); }
  .app-main { margin-left: 0; padding: 60px 16px 40px; }
  .mobile-topbar { display: flex; }
}

/* ===== Page Header ===== */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.page-header h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--n-900);
}

.page-header h2 { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }

.page-header .muted,
.muted {
  color: var(--n-500);
  font-size: 13px;
  margin-top: 2px;
}

/* ===== Stats Grid ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

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

.stat-card {
  background: var(--n-0);
  border-radius: var(--r-lg);
  padding: 18px 20px;
  border: 1px solid var(--n-200);
  box-shadow: var(--shadow-xs);
  transition: box-shadow var(--t-normal);
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--brand-500);
  opacity: 0;
  transition: opacity var(--t-normal);
}

.stat-card:hover { box-shadow: var(--shadow-md); }
.stat-card:hover::before { opacity: 1; }

.stat-label {
  font-size: 12px;
  color: var(--n-500);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.stat-value {
  font-size: 26px;
  font-weight: 700;
  margin-top: 4px;
  letter-spacing: -0.03em;
  color: var(--n-900);
}

.stat-note {
  font-size: 12px;
  color: var(--n-400);
  margin-top: 4px;
}

.stat-note a { color: var(--brand-600); font-weight: 600; }

.stat-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--r-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  margin-bottom: 10px;
}

.stat-icon.blue { background: var(--info-50); }
.stat-icon.green { background: var(--success-50); }
.stat-icon.amber { background: var(--warning-50); }
.stat-icon.purple { background: var(--purple-50); }
.stat-icon.red { background: var(--error-50); }

.stat-delta { font-size: 12px; color: var(--n-400); margin-top: 4px; }

/* ===== Panels ===== */
.panel {
  background: var(--n-0);
  border-radius: var(--r-lg);
  border: 1px solid var(--n-200);
  box-shadow: var(--shadow-xs);
  margin-bottom: 20px;
  overflow: hidden;
}

.panel-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--n-100);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.panel-header h2,
.panel-header h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--n-900);
}

.panel-header .muted { margin: 0; }

.panel-body { padding: 0; }

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }

th {
  background: var(--n-50);
  padding: 10px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--n-500);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--n-200);
  white-space: nowrap;
}

td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--n-100);
  font-size: 13px;
  color: var(--n-700);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tbody tr { transition: background var(--t-fast); }
tbody tr:hover td { background: var(--n-50); }

td .muted { font-size: 12px; }
td.mono, td .mono { font-family: var(--font-mono); font-size: 12px; color: var(--n-600); }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--t-fast);
  white-space: nowrap;
  text-decoration: none;
  line-height: 1.4;
}

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

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

.btn-primary {
  background: var(--brand-600);
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: var(--brand-700);
  box-shadow: 0 2px 8px rgba(79,70,229,0.25);
  text-decoration: none;
  color: #fff;
}

.btn-secondary {
  background: var(--n-0);
  color: var(--n-700);
  border-color: var(--n-300);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--n-50);
  border-color: var(--n-400);
  text-decoration: none;
  color: var(--n-900);
}

.btn-danger {
  background: var(--error-500);
  color: #fff;
}
.btn-danger:hover:not(:disabled) {
  background: var(--error-600);
  box-shadow: 0 2px 8px rgba(239,68,68,0.25);
  text-decoration: none;
  color: #fff;
}

.btn-warning {
  background: var(--warning-500);
  color: #fff;
}
.btn-warning:hover:not(:disabled) {
  background: var(--warning-600);
  text-decoration: none;
  color: #fff;
}

.btn-ghost {
  background: transparent;
  color: var(--n-500);
  border-color: transparent;
}
.btn-ghost:hover:not(:disabled) {
  background: var(--n-100);
  color: var(--n-800);
  text-decoration: none;
}

.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-icon { padding: 6px 10px; font-size: 16px; min-width: 32px; }

/* ===== Forms ===== */
.form-grid { display: grid; gap: 16px; }

.field { display: grid; gap: 5px; }

.field label {
  font-size: 13px;
  font-weight: 600;
  color: var(--n-700);
}

.field .muted { margin: 0; }

.input, .select {
  width: 100%;
  padding: 9px 13px;
  border: 1px solid var(--n-300);
  border-radius: var(--r-sm);
  font-size: 13px;
  transition: all var(--t-fast);
  outline: none;
  background: var(--n-0);
  color: var(--n-900);
}

.input:focus, .select:focus {
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
}

.input:disabled { background: var(--n-50); color: var(--n-400); cursor: not-allowed; }

.select { cursor: pointer; }

textarea.input { resize: vertical; min-height: 80px; }

/* ===== Alerts ===== */
.alert {
  padding: 10px 14px;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 500;
  display: none;
}

.alert.show { display: block; }
.alert.error { background: var(--error-50); color: var(--error-600); border: 1px solid var(--error-100); }
.alert.success { background: var(--success-50); color: var(--success-600); border: 1px solid var(--success-100); }

/* ===== Badges ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-success { background: var(--success-50); color: var(--success-600); }
.badge-warning { background: var(--warning-50); color: var(--warning-600); }
.badge-danger { background: var(--error-50); color: var(--error-600); }
.badge-neutral { background: var(--n-100); color: var(--n-600); }
.badge-codex { background: var(--purple-50); color: var(--purple-600); }
.badge-claude { background: var(--orange-50); color: var(--orange-600); }

.badge-dot::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  display: inline-block;
  flex-shrink: 0;
}

/* ===== Modal ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(9,9,11,0.5);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  backdrop-filter: blur(2px);
}

.modal-backdrop.open { display: flex; }

.modal {
  background: var(--n-0);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 480px;
  animation: modalSlideUp var(--t-normal);
}

@keyframes modalSlideUp {
  from { opacity: 0; transform: translateY(16px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  padding: 20px 24px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 { font-size: 17px; font-weight: 700; }

.modal-body { padding: 20px 24px; }

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--n-100);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ===== Pagination ===== */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 16px;
}

.pagination .btn { min-width: 36px; }

/* ===== Search ===== */
.search-input {
  width: 240px;
  padding: 8px 13px;
  border: 1px solid var(--n-300);
  border-radius: var(--r-sm);
  font-size: 13px;
  outline: none;
  background: var(--n-0);
  transition: all var(--t-fast);
}

.search-input:focus { border-color: var(--brand-500); box-shadow: 0 0 0 3px rgba(79,70,229,0.1); }

/* ===== Toolbar ===== */
.toolbar {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.toolbar .field { min-width: 140px; }

/* ===== Chart ===== */
.chart-box { padding: 20px 24px; }
.chart-box canvas { max-height: 260px; }

/* ===== Empty State ===== */
.empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--n-400);
}

.empty-icon { font-size: 36px; margin-bottom: 8px; opacity: 0.6; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 200;
  background: var(--n-900);
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toastIn var(--t-normal);
}

.toast.success { background: var(--success-600); }
.toast.error { background: var(--error-600); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ===== Price Cards (shared with customer) ===== */
.price-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media(max-width: 700px) { .price-row { grid-template-columns: 1fr; } }

.price-card {
  border: 1px solid var(--n-200);
  border-radius: var(--r-lg);
  padding: 24px;
  text-align: center;
  background: var(--n-0);
  position: relative;
  transition: all var(--t-normal);
}

.price-card.popular {
  border-color: var(--brand-400);
  border-width: 2px;
}

.popular-tag {
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--brand-600);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 12px;
  border-radius: 20px;
  white-space: nowrap;
}

.price-plan { font-size: 13px; font-weight: 600; color: var(--n-500); }
.price-amount { font-size: 34px; font-weight: 800; margin: 8px 0; letter-spacing: -0.03em; }
.price-desc { font-size: 13px; color: var(--n-500); margin-bottom: 16px; line-height: 1.5; }

/* ===== Text Utilities ===== */
.text-link { color: var(--brand-600); font-weight: 600; font-size: 13px; cursor: pointer; }
.text-link:hover { color: var(--brand-700); }
.text-danger { color: var(--error-500); font-weight: 600; font-size: 13px; cursor: pointer; }

/* ===== Progress Bar ===== */
.progress {
  width: 80px;
  height: 4px;
  background: var(--n-200);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 4px;
}

.progress span {
  display: block;
  height: 100%;
  background: var(--brand-500);
  border-radius: 2px;
  transition: width var(--t-normal);
}

/* ===== Doc Grid ===== */
.doc-grid {
  display: grid;
  gap: 20px;
  grid-template-columns: 1fr;
}

@media(min-width: 900px) {
  .doc-grid { grid-template-columns: 1fr 1fr; }
}

.code-block {
  background: var(--n-950);
  color: #E2E8F0;
  padding: 16px 20px;
  border-radius: var(--r-md);
  font-size: 12px;
  line-height: 1.7;
  overflow-x: auto;
  font-family: var(--font-mono);
}

/* ===== Action Cell ===== */
td .actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--n-300); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--n-400); }

.sidebar::-webkit-scrollbar-thumb { background: var(--n-700); }
.sidebar::-webkit-scrollbar-thumb:hover { background: var(--n-600); }
