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

:root {
  --bg:        #f8f6f0;
  --surface:   #ffffff;
  --surface-2: #f2efea;
  --border:    #e4dfd5;
  --text:      #1a1a1a;
  --muted:     #7a7060;
  --accent:    #1a6bff;
  --accent-2:  #f5c400;
  --accent-3:  #1a6bff;
  --danger:    #e03150;
  --radius:    14px;
  --mono:      'JetBrains Mono', monospace;
  --sans:      'DM Sans', sans-serif;
  --shadow:    0 2px 12px rgba(0,0,0,0.07), 0 1px 3px rgba(0,0,0,0.05);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.10), 0 2px 8px rgba(0,0,0,0.06);
}

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

body {
  font-family: var(--sans);
  font-size: 15px;
  color: var(--text);
  background-color: var(--bg);
  background-image:
    radial-gradient(ellipse 70% 50% at 15% 10%, rgba(245,196,0,0.18) 0%, transparent 55%),
    radial-gradient(ellipse 50% 40% at 85% 90%, rgba(26,107,255,0.12) 0%, transparent 55%),
    radial-gradient(ellipse 40% 30% at 80% 5%,  rgba(26,107,255,0.07) 0%, transparent 40%);
  min-height: 100vh;
}

/* ── TOPBAR ─────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 2rem;
  height: 64px;
  background: rgba(248,246,240,0.82);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 0.9rem; }

.brand-logo {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.brand h1 {
  font-family: var(--sans);
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.brand p {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 1px;
}

.brand-emphasis {
  font-weight: 600;
}

.top-actions { display: flex; align-items: center; gap: 0.6rem; }

a { color: var(--accent); text-decoration: none; }
.top-actions a {
  font-size: 0.85rem;
  color: var(--muted);
  padding: 0.4rem 0.8rem;
  border-radius: 8px;
  transition: background 0.15s, color 0.15s;
}
.top-actions a:hover { background: var(--surface-2); color: var(--text); }

/* ── LAYOUT ─────────────────────────────────────────── */
main.grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 1.5rem;
  padding: 2rem;
  max-width: 1400px;
  margin: 0 auto;
}

.card {
  grid-column: span 4;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
}
.card.wide { grid-column: span 12; }

#auth-card   { grid-column: span 5; }
#wallet-card { grid-column: span 7; }

@media (max-width: 960px) {
  .card, .card.wide, #auth-card, #wallet-card { grid-column: span 12; }
  main.grid { padding: 1rem; gap: 1rem; }
  .api-key-shell { grid-template-columns: 1fr; }
}

/* ── TYPOGRAPHY ─────────────────────────────────────── */
h2 {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
h2::before {
  content: '';
  display: block;
  width: 16px;
  height: 3px;
  background: var(--accent-2);
  border-radius: 2px;
}

h3 {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 1.8rem 0 0.8rem;
}

.muted { color: var(--muted); }
.tiny  { font-size: 0.8rem; }

/* ── INPUTS & FORMS ─────────────────────────────────── */
.stack { display: grid; gap: 0.65rem; }
.row   { display: flex; gap: 0.65rem; align-items: center; }
.small-row { justify-content: space-between; }

input, select, textarea {
  font-family: var(--sans);
  font-size: 0.92rem;
  width: 100%;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(26,107,255,0.1);
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 0.7; }

label {
  display: grid;
  gap: 0.4rem;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--muted);
}

/* ── BUTTONS ─────────────────────────────────────────── */
button {
  font-family: var(--sans);
  font-size: 0.88rem;
  font-weight: 600;
  border: none;
  border-radius: 10px;
  padding: 0.72rem 1.25rem;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  line-height: 1;
}

/* primary */
button:not(.ghost):not(.text-btn):not(.danger-btn):not(.tab) {
  background: var(--accent);
  color: #fff;
}
button:not(.ghost):not(.text-btn):not(.danger-btn):not(.tab):hover {
  background: #0055e0;
  box-shadow: 0 4px 16px rgba(26,107,255,0.3);
  transform: translateY(-1px);
}
button:not(.ghost):not(.text-btn):not(.danger-btn):not(.tab):disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* ghost */
button.ghost {
  background: var(--surface-2);
  color: var(--text);
  border: 1.5px solid var(--border);
}
button.ghost:hover {
  border-color: #c8c0b0;
  background: #ece9e2;
}

/* text */
button.text-btn {
  background: transparent;
  color: var(--muted);
  padding: 0.35rem 0;
  font-size: 0.82rem;
  font-weight: 500;
}
button.text-btn:hover { color: var(--accent); }
button.danger { color: var(--danger) !important; }

/* ── AUTH CARD ───────────────────────────────────────── */
#auth-card {
  display: flex;
  flex-direction: column;
}

#signed-out-view { width: 100%; }

#signed-in-view {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.1rem;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: 12px;
}

.user-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-2) 0%, var(--accent) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
}

.user-email {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
  word-break: break-all;
}

/* ── WALLET CARD ─────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

.stat-grid article {
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1rem;
}

.stat-grid span {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.stat-grid strong {
  font-family: var(--mono);
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

/* ── NOTICES ─────────────────────────────────────────── */
#notice-list.stack { gap: 0.75rem; }

.notice {
  padding: 1rem 1.1rem;
  border-radius: 10px;
  border: 1.5px solid rgba(26,107,255,0.2);
  background: rgba(26,107,255,0.04);
}
.notice strong {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  display: block;
  margin-bottom: 0.4rem;
}
.notice p { color: var(--muted); margin: 0; font-size: 0.88rem; line-height: 1.55; }
.notice.warning { border-color: rgba(245,196,0,0.4); background: rgba(245,196,0,0.06); }
.notice.warning strong { color: #b08a00; }
.notice.error { border-color: rgba(224,49,80,0.2); background: rgba(224,49,80,0.04); }
.notice.error strong { color: var(--danger); }

/* ── API KEYS ─────────────────────────────────────────── */
.api-key-shell {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(280px, 0.9fr);
  gap: 1rem;
  align-items: start;
}

.api-key-form,
.api-key-reveal {
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 1.1rem;
}

.api-key-reveal {
  min-height: 100%;
}

.api-key-reveal h3 {
  margin: 0 0 0.5rem;
}

.api-key-secret {
  font-family: var(--mono);
  font-size: 0.78rem;
  white-space: pre-wrap;
  word-break: break-all;
  padding: 0.9rem;
  margin: 0.9rem 0;
  border-radius: 10px;
  background: rgba(255,255,255,0.5);
  border: 1px solid var(--border);
}

.api-key-list {
  margin-top: 1rem;
  display: grid;
  gap: 0.75rem;
}

.api-key-row {
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.1rem;
}

.api-key-row-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
}

.api-key-row-title {
  min-width: 0;
}

.api-key-name {
  font-weight: 600;
  color: var(--text);
}

.api-key-prefix,
.api-key-meta {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
}

.api-key-meta {
  margin-top: 0.7rem;
  display: flex;
  gap: 0.9rem;
  flex-wrap: wrap;
}

.api-key-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.35rem 0.6rem;
  border-radius: 999px;
  border: 1px solid transparent;
}

.api-key-badge.is-active {
  color: #0f766e;
  background: rgba(20, 184, 166, 0.12);
  border-color: rgba(20, 184, 166, 0.24);
}

.api-key-badge.is-expired {
  color: #b45309;
  background: rgba(245, 158, 11, 0.12);
  border-color: rgba(245, 158, 11, 0.24);
}

.api-key-badge.is-revoked {
  color: var(--danger);
  background: rgba(224,49,80,0.08);
  border-color: rgba(224,49,80,0.18);
}

.api-key-actions {
  margin-top: 0.9rem;
  display: flex;
  justify-content: flex-end;
}

/* ── CREDIT PACKS ────────────────────────────────────── */
.pack-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.pack {
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}
.pack:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 16px rgba(26,107,255,0.1);
  transform: translateY(-2px);
}

.pack strong { font-size: 0.95rem; font-weight: 600; color: var(--text); }
.pack .credit-amount {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--accent);
  font-weight: 500;
}
.pack .muted { font-size: 0.8rem; margin-bottom: 0.65rem; }
.pack button { width: 100%; font-size: 0.8rem; padding: 0.6rem 0.75rem; }

.rate-list {
  list-style: none;
  padding: 0;
  display: grid;
  gap: 0.5rem;
}
.rate-list li {
  font-size: 0.88rem;
  color: var(--muted);
  padding: 0.65rem 0.9rem;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  line-height: 1.4;
}
.rate-list li::before { content: '→  '; color: var(--accent-2); font-weight: 700; }

/* ── MODELS ──────────────────────────────────────────── */
.models-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}

.model-card {
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 1.1rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  transition: border-color 0.15s, transform 0.15s;
}
.model-card:hover { border-color: #c8c0b0; transform: translateY(-1px); }
.model-card img {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.model-card strong { font-size: 0.9rem; font-weight: 600; display: block; }
.model-card p {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--accent);
  margin: 3px 0 0;
  font-weight: 500;
}

/* ── PLAYGROUND ──────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 0.35rem;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  width: fit-content;
  margin-bottom: 1.25rem;
}

.tab {
  background: transparent;
  color: var(--muted);
  border-radius: 7px;
  padding: 0.45rem 1rem;
  font-size: 0.85rem;
  font-weight: 500;
  border: none;
}
.tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  font-weight: 600;
}
.tab:hover:not(.active) { color: var(--text); }

.tab-panel { display: none; flex-direction: column; gap: 0.85rem; }
.tab-panel.active { display: flex; }

.output {
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.75;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  padding: 1rem;
  min-height: 110px;
  overflow: auto;
  color: var(--text);
  white-space: pre-wrap;
}

.media-output { display: contents; }
.media-output img,
.media-output video,
.media-output audio {
  max-width: 100%;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  display: block;
}

/* ── LEDGER ──────────────────────────────────────────── */
.ledger {
  display: grid;
  gap: 0.5rem;
  border-radius: var(--radius);
  overflow: hidden;
}

.ledger-header {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr 1.4fr;
  padding: 0.6rem 1rem;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: 8px;
}
.ledger-header span {
  font-size: 0.67rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.ledger-row {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr 1.4fr;
  padding: 0.85rem 1rem;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  transition: background 0.12s;
}
.ledger-row:hover { background: var(--surface-2); }
.ledger-row > div { font-size: 0.88rem; line-height: 1.4; }
.ledger-row strong { font-weight: 600; }
.ledger-row .muted.tiny { font-family: var(--mono); font-size: 0.75rem; }

/* ── LOCKED PLACEHOLDER ──────────────────────────────── */
.locked-overlay {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  min-height: 100px;
  color: var(--muted);
  font-size: 0.88rem;
  background: var(--surface-2);
  border: 1.5px dashed var(--border);
  border-radius: 10px;
  padding: 1.5rem;
}
.locked-overlay::before {
  content: '🔒';
  font-size: 1.3rem;
  opacity: 0.5;
}

/* ── SIGN-OUT BUTTON ─────────────────────────────────── */
#logout-btn {
  font-size: 0.82rem;
  padding: 0.45rem 0.9rem;
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--muted);
  font-weight: 500;
}
#logout-btn:hover { border-color: var(--danger); color: var(--danger); }

/* ── YELLOW ACCENT DECORATION ────────────────────────── */
.card:nth-child(1) { border-top: 3px solid var(--accent-2); }
.card:nth-child(2) { border-top: 3px solid var(--accent); }

@media (max-width: 680px) {
  .stat-grid { grid-template-columns: 1fr; }
  .ledger-header, .ledger-row { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .brand-emphasis {
    display: none !important;
  }

  .topbar {
    padding: 0 1rem;
  }

  .brand-logo {
    width: 32px;
    height: 32px;
  }
}
