:root {
  --bg: #000000;
  --bg-soft: #05070b;
  --bg-card: #0a0d11;
  --bg-card-hover: #10151c;
  --bg-input: #020406;
  --bg-header: rgba(0, 0, 0, 0.9);
  --border: #151b23;
  --border-strong: #243140;
  --text: #f7fbff;
  --text-dim: #9aa9ba;
  --text-muted: #66788c;
  --cyan: #2dd4ff;
  --cyan-dim: rgba(45, 212, 255, 0.18);
  --green: #55e6a5;
  --green-dim: rgba(85, 230, 165, 0.15);
  --amber: #ffcc58;
  --amber-dim: rgba(255, 204, 88, 0.14);
  --red: #ff7f88;
  --red-dim: rgba(255, 127, 136, 0.14);
  --purple: #b794ff;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
  --accent-contrast: #02131a;
  --chart-grid: rgba(255, 255, 255, 0.06);
  --tooltip-bg: rgba(8, 11, 16, 0.96);
  --tooltip-border: #243140;
  --theme-toggle-bg: rgba(9, 13, 17, 0.92);
  --theme-toggle-shadow: 0 16px 30px rgba(0, 0, 0, 0.32);
  --radius: 12px;
  --radius-sm: 8px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

[data-theme="light"] {
  --bg: #f5f8fc;
  --bg-soft: #eaf1f8;
  --bg-card: #ffffff;
  --bg-card-hover: #f3f7fb;
  --bg-input: #f8fbff;
  --bg-header: rgba(245, 248, 252, 0.9);
  --border: #d9e3ee;
  --border-strong: #b8c8d8;
  --text: #102033;
  --text-dim: #506579;
  --text-muted: #73879a;
  --cyan: #0ea5c6;
  --cyan-dim: rgba(14, 165, 198, 0.14);
  --green: #059669;
  --green-dim: rgba(5, 150, 105, 0.14);
  --amber: #d97706;
  --amber-dim: rgba(217, 119, 6, 0.14);
  --red: #dc2626;
  --red-dim: rgba(220, 38, 38, 0.12);
  --purple: #7c3aed;
  --shadow: 0 18px 42px rgba(15, 23, 42, 0.08);
  --accent-contrast: #ffffff;
  --chart-grid: rgba(16, 32, 51, 0.08);
  --tooltip-bg: rgba(255, 255, 255, 0.98);
  --tooltip-border: #d9e3ee;
  --theme-toggle-bg: rgba(255, 255, 255, 0.95);
  --theme-toggle-shadow: 0 12px 26px rgba(15, 23, 42, 0.12);
}

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

html { color-scheme: dark; }
html[data-theme="light"] { color-scheme: light; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  background-image:
    radial-gradient(circle at 15% 18%, rgba(45, 212, 255, 0.08), transparent 28%),
    radial-gradient(circle at 82% 12%, rgba(183, 148, 255, 0.08), transparent 30%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-soft) 100%);
}

.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }

.theme-toggle {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 120;
  display: inline-grid;
  place-items: center;
  align-items: center;
  width: 46px;
  min-width: 46px;
  height: 46px;
  min-height: 46px;
  padding: 0;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--theme-toggle-bg);
  color: var(--text);
  box-shadow: var(--theme-toggle-shadow);
  backdrop-filter: blur(14px);
  cursor: pointer;
  transition: border-color 0.16s ease, transform 0.16s ease, background 0.16s ease;
}

.theme-toggle:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.theme-toggle-icon {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: radial-gradient(circle at 35% 35%, var(--amber) 0 40%, transparent 42%),
    var(--cyan-dim);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

[data-theme="light"] .theme-toggle-icon {
  background: radial-gradient(circle at 50% 50%, var(--purple) 0 45%, transparent 47%),
    rgba(124, 58, 237, 0.1);
}

/* Auth Screen */
.auth-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(ellipse at 50% 0%, rgba(45, 212, 255, 0.08) 0%, transparent 62%);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 32px;
  text-align: center;
  box-shadow: var(--shadow);
}

.auth-logo { margin-bottom: 28px; }
.auth-logo svg { margin-bottom: 16px; }
.eyebrow {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--cyan);
  margin-bottom: 8px;
}
.auth-card h1 {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 8px;
}
.auth-sub {
  font-size: 14px;
  color: var(--text-dim);
  line-height: 1.5;
}

.auth-card input {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 15px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
  margin-bottom: 12px;
}
.auth-card input:focus { border-color: var(--cyan); }
.auth-card input::placeholder { color: var(--text-muted); }

.auth-card button {
  width: 100%;
  padding: 14px;
  background: var(--cyan);
  color: var(--accent-contrast);
  font-weight: 600;
  font-size: 15px;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: var(--font);
  transition: opacity 0.15s;
}
.auth-card button:hover { opacity: 0.9; }
.auth-card button:active { opacity: 0.8; }

.error {
  margin-top: 12px;
  color: var(--red);
  font-size: 13px;
}

/* Dashboard Header */
.dash-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--bg-header);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 15px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.key-badge {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-card);
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  font-family: monospace;
}

.btn-logout {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  padding: 6px 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: color 0.15s, border-color 0.15s;
}
.btn-logout:hover { color: var(--red); border-color: var(--red); }

.btn-refresh {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  padding: 6px 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: color 0.15s, border-color 0.15s;
  min-width: 44px;
  min-height: 44px;
  justify-content: center;
}
.btn-refresh:hover { color: var(--cyan); border-color: var(--cyan); }

/* Main */
.dash-main {
  max-width: 640px;
  margin: 0 auto;
  padding: 20px 16px 48px;
}

/* Status Card */
.status-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.status-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.status-top h2 { font-size: 18px; font-weight: 600; }

.badge {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 4px 10px;
  border-radius: 20px;
}
.badge-active { background: var(--green-dim); color: var(--green); }
.badge-expired { background: var(--red-dim); color: var(--red); }
.badge-disabled { background: var(--amber-dim); color: var(--amber); }

.status-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  font-size: 13px;
  color: var(--text-dim);
}
.status-meta span { display: flex; align-items: center; gap: 4px; }

/* Usage Cards */
.usage-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.usage-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.usage-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
}
.usage-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.usage-value {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.progress-bar {
  height: 8px;
  background: color-mix(in srgb, var(--border) 75%, transparent);
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 8px;
}
.progress-fill {
  height: 100%;
  border-radius: 99px;
  background: var(--cyan);
  transition: width 0.6s ease;
  width: 0%;
}
.progress-fill.daily { background: var(--purple); }
.progress-fill.warn { background: var(--amber); }
.progress-fill.danger { background: var(--red); }

.usage-footer {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
}

/* Info Cards */
.info-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.info-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  box-shadow: var(--shadow);
}
.info-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.info-value {
  display: block;
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 2px;
  font-variant-numeric: tabular-nums;
}
.info-sub {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
}

/* Chart Card */
.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.chart-card h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text-dim);
}
.chart-wrap {
  position: relative;
  height: 200px;
}

.model-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.section-head h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text-dim);
}

.section-head p {
  font-size: 12px;
  color: var(--text-muted);
}

.model-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-dim);
  font-size: 12px;
  white-space: nowrap;
}

.model-usage-list {
  display: grid;
  gap: 12px;
}

.model-row {
  padding: 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg-input) 82%, transparent);
}

.model-row-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.model-row-top strong {
  font-size: 14px;
  line-height: 1.4;
  word-break: break-word;
}

.model-row-top span {
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.model-row-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin-bottom: 10px;
  color: var(--text-muted);
  font-size: 12px;
}

.model-bar {
  height: 6px;
  border-radius: 999px;
  overflow: hidden;
  background: color-mix(in srgb, var(--border) 78%, transparent);
}

.model-bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--cyan) 0%, var(--purple) 100%);
}

.empty-state {
  font-size: 13px;
  color: var(--text-muted);
}

/* Footer */
.portal-footer {
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  padding-top: 8px;
}

/* Mobile: stack usage cards */
@media (max-width: 520px) {
  .usage-grid { grid-template-columns: 1fr; }
  .info-grid { grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
  .info-card { padding: 12px 8px; }
  .info-value { font-size: 16px; }
  .auth-card { padding: 32px 20px; }
  .dash-main { padding: 16px 12px 40px; }
  .section-head,
  .model-row-top { flex-direction: column; }
  .model-count { align-self: flex-start; }
  .theme-toggle {
    top: 12px;
    right: 12px;
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
  }
}

@media (max-width: 380px) {
  .info-grid { grid-template-columns: 1fr; }
  .header-brand span { display: none; }
}
