/* The hidden attribute must beat every display:flex/grid/block rule in this file (review 2026-09-27) */
[hidden] { display: none !important; }

/* ------------------------------------------------------------------ */
/* didiaoapi lite console — app.css                                     */
/* Tokens mirror landing.css; app-specific layout on top.              */
/* ------------------------------------------------------------------ */

/* ── token layer ─────────────────────────────────────────────────── */
:root {
  --bg:            #FAF8F2;
  --surface:       #FFFFFF;
  --surface-2:     #F3F1E9;
  --border:        #E0DDD1;
  --border-strong: #C2BFB2;

  --text:   #16140F;
  --text-2: #6B675C;
  --text-3: #9B978B;
  --text-4: #C2BFB2;

  --accent:       #A07E58;
  --accent-tint:  #E6DACB;
  --fawn-deep:    #7A5E3E;
  --danger:       #C4453C;
  --danger-tint:  #FCEEED;
  --success:      #788C5D;
  --success-tint: #E8EDDF;
  --warn:         #C7923E;
  --warn-tint:    #FDF3E3;

  --r-sm:   6px;
  --r-md:   10px;
  --r-lg:   16px;
  --r-pill: 9999px;

  --sh-xs: 0 1px 2px rgba(20,20,19,.04);
  --sh-sm: 0 2px 8px rgba(20,20,19,.06);
  --sh-md: 0 4px 16px rgba(20,20,19,.12);

  --font-sans:  "DM Sans", "Noto Sans SC", ui-sans-serif, system-ui, sans-serif;
  --font-serif: "Source Serif 4", "Noto Serif SC", Georgia, serif;
  --font-mono:  "JetBrains Mono", ui-monospace, Menlo, monospace;

  --seal-inner: #FAF8F2;
  --seal-bg:    #7A5E3E;

  --nav-h: 56px;
}

/* dark theme — toggled via data-theme="dark" on <html> (not prefers-color-scheme) */
[data-theme="dark"] {
  --bg:            #2D271C;
  --surface:       #362F24;
  --surface-2:     #3E372B;
  --border:        #483F33;
  --border-strong: #554C40;
  --text:   #F3EEE2;
  --text-2: #B0A898;
  --text-3: #7F7869;
  --text-4: #554C40;
  --accent:      #A07E58;
  --accent-tint: #473923;
  --danger-tint: #3A1E1B;
  --success-tint:#232C1C;
  --warn-tint:   #3A2D18;
  --sh-xs: 0 1px 2px rgba(0,0,0,.30);
  --sh-sm: 0 2px 8px rgba(0,0,0,.40);
  --sh-md: 0 4px 16px rgba(0,0,0,.50);
  --seal-bg:    #A07E58;
  --seal-inner: #2D271C;
}

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

html {
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: var(--r-sm);
}

/* ── layout ──────────────────────────────────────────────────────── */
.container {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 16px;
}

#view-app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

main.app-main {
  flex: 1;
  padding: 32px 0 64px;
}

/* ── header / nav ────────────────────────────────────────────────── */
.app-header {
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-header .container {
  height: var(--nav-h);
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  flex-shrink: 0;
}

.brand-seal {
  display: block;
  width: 28px;
  height: 28px;
}

.brand-wordmark {
  font-family: var(--font-sans);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

.nav-tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
}
.nav-tabs::-webkit-scrollbar { display: none; }

.nav-tab {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: var(--r-md);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-2);
  white-space: nowrap;
  cursor: pointer;
  border: 1px solid transparent;
  background: transparent;
  transition: color 120ms, background 120ms, border-color 120ms;
}
.nav-tab:hover { color: var(--text); background: var(--surface-2); }
.nav-tab.active {
  color: var(--text);
  background: var(--surface);
  border-color: var(--border);
  box-shadow: var(--sh-xs);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* ── header controls (lang + theme toggles) ─────────────────────── */
.header-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.header-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 4px 9px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: transparent;
  color: var(--text-2);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  cursor: pointer;
  white-space: nowrap;
  transition: color 120ms, border-color 120ms;
}
.header-btn:hover { color: var(--text); border-color: var(--border-strong); }
.header-btn svg { width: 13px; height: 13px; flex-shrink: 0; }

.username-badge {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-3);
  letter-spacing: 0.04em;
  display: none;
}
@media (min-width: 600px) { .username-badge { display: block; } }

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: transparent;
  color: var(--text-2);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: color 120ms, border-color 120ms;
}
.btn-ghost:hover { color: var(--text); border-color: var(--border-strong); }
.btn-ghost svg { width: 14px; height: 14px; flex-shrink: 0; }

/* ── buttons ─────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: var(--font-sans);
  font-size: 15px;
  font-weight: 500;
  line-height: 1;
  padding: 11px 22px;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background 120ms, color 120ms, border-color 120ms, box-shadow 120ms;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #FFF;
  border-color: var(--accent);
}
.btn-primary:hover, .btn-primary:focus-visible {
  background: var(--fawn-deep);
  border-color: var(--fawn-deep);
  box-shadow: var(--sh-sm);
}
.btn-primary:disabled {
  opacity: .5;
  cursor: not-allowed;
}

.btn-secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-secondary:hover, .btn-secondary:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-tint);
}

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

.btn-copy {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition: color 120ms, border-color 120ms, background 120ms;
  white-space: nowrap;
}
.btn-copy:hover { color: var(--text); border-color: var(--border-strong); }
.btn-copy.copied { color: var(--success); border-color: var(--success); background: var(--success-tint); }
.btn-copy svg { width: 14px; height: 14px; }

/* ── forms ───────────────────────────────────────────────────────── */
.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-field label {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-2);
}

.form-field input,
.form-field select,
.form-field textarea {
  font-family: var(--font-sans);
  font-size: 15px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 10px 14px;
  width: 100%;
  transition: border-color 120ms, box-shadow 120ms;
  appearance: none;
  -webkit-appearance: none;
}
.form-field input::placeholder { color: var(--text-4); }
.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-tint);
}

.form-field select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%239B978B' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 12px;
  padding-right: 36px;
}

.form-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.form-row .form-field { flex: 1; min-width: 160px; }

.form-hint {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

/* ── alerts ──────────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--r-md);
  font-size: 14px;
  display: none;
}
.alert.visible { display: block; }
.alert-error   { background: var(--danger-tint);  color: var(--danger);  border: 1px solid var(--danger);  }
.alert-success { background: var(--success-tint); color: var(--success); border: 1px solid var(--success); }
.alert-info    { background: var(--accent-tint);  color: var(--fawn-deep); border: 1px solid var(--accent); }

/* ── page sections ───────────────────────────────────────────────── */
.page-section {
  margin-bottom: 40px;
}

.section-heading {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 16px;
  font-variant-numeric: tabular-nums;
}

/* ── stat tiles ──────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 40px;
}
@media (max-width: 480px) { .stats-grid { grid-template-columns: 1fr; } }

.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 24px 20px;
}

.stat-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 10px;
  font-variant-numeric: tabular-nums;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 30px;
  font-weight: 500;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.stat-sub {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  margin-top: 6px;
  line-height: 1.4;
}

/* ── log table ───────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
}

.log-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.log-table th {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-3);
  text-align: left;
  padding: 12px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.log-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-2);
  vertical-align: middle;
}
.log-table tr:last-child td { border-bottom: none; }

.log-table .td-mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}
.log-table .td-model {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text);
}

.empty-row td {
  text-align: center;
  color: var(--text-3);
  padding: 32px 14px;
  font-family: var(--font-mono);
  font-size: 12px;
}

/* ── key cards ───────────────────────────────────────────────────── */
.key-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 8px;
}

.key-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.key-card-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.key-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.key-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.key-status {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: var(--r-pill);
}
.key-status-active { background: var(--success-tint); color: var(--success); }
.key-status-disabled { background: var(--surface-2); color: var(--text-3); }
.key-status-expired { background: var(--danger-tint); color: var(--danger); }
.key-status-exhausted { background: var(--warn-tint); color: var(--warn); }

.key-card-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ── create key form ─────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 24px;
}

.card-title {
  font-family: var(--font-serif);
  font-weight: 300;
  font-size: 18px;
  color: var(--text);
  margin-bottom: 20px;
  letter-spacing: -0.01em;
}

.create-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* newly-created key highlight */
.new-key-display {
  background: var(--success-tint);
  border: 1px solid var(--success);
  border-radius: var(--r-md);
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.new-key-value {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text);
  word-break: break-all;
  font-variant-numeric: tabular-nums;
}

/* ── topup ───────────────────────────────────────────────────────── */
.topup-balance {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 28px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 6px;
}
.topup-balance-sub {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  margin-bottom: 28px;
}

.topup-email-note {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 16px 18px;
  font-size: 14px;
  color: var(--text-2);
  line-height: 1.6;
}
.topup-email-note a {
  color: var(--accent);
  text-decoration: none;
  font-family: var(--font-mono);
  font-size: 13px;
  border-bottom: 1px solid transparent;
}
.topup-email-note a:hover { border-bottom-color: var(--accent); }

/* ── install ─────────────────────────────────────────────────────── */
.snippet-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
  margin-bottom: 20px;
}

.snippet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}

.snippet-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-3);
}

.snippet-body {
  padding: 16px;
  overflow-x: auto;
}

.snippet-body pre {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.65;
  color: var(--text);
  white-space: pre;
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.snippet-body pre .key-placeholder {
  color: var(--accent);
  font-weight: 500;
}

.snippet-note {
  font-size: 13px;
  color: var(--text-3);
  padding: 8px 16px 14px;
  font-family: var(--font-mono);
  font-size: 12px;
}

.model-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.model-pill {
  font-family: var(--font-mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  padding: 3px 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  color: var(--text-2);
  background: var(--surface);
}

/* ── login view ──────────────────────────────────────────────────── */
#view-login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
}

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

.login-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 32px;
}

.login-brand svg { width: 36px; height: 36px; }

.login-brand-name {
  font-family: var(--font-sans);
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

.login-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-title {
  font-family: var(--font-serif);
  font-weight: 300;
  font-size: 22px;
  color: var(--text);
  letter-spacing: -0.01em;
  margin-bottom: 4px;
}

.login-links {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-top: 4px;
}
.login-links a {
  color: var(--text-3);
  text-decoration: none;
}
.login-links a:hover { color: var(--accent); }

/* ── spinner ─────────────────────────────────────────────────────── */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── footer ──────────────────────────────────────────────────────── */
.app-footer {
  border-top: 1px solid var(--border);
  padding: 24px 0;
}

.app-footer .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.footer-copy {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-3);
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}

.footer-email {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 120ms;
}
.footer-email:hover { border-bottom-color: var(--accent); }

/* ── loading overlay ─────────────────────────────────────────────── */
#loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 1;
  transition: opacity 200ms;
}
#loading-overlay.fade-out { opacity: 0; pointer-events: none; }
#loading-overlay.hidden { display: none; }

/* ── responsive ──────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .app-header .container { gap: 8px; }
  .brand-wordmark { display: none; }
  .nav-tab { padding: 6px 9px; font-size: 13px; }
  main.app-main { padding: 20px 0 48px; }
  .stats-grid { gap: 10px; }
  .stat-tile { padding: 18px 16px; }
  .stat-value { font-size: 24px; }
  .card { padding: 18px 16px; }
  .login-form { padding: 22px 18px; }
}
