/* =====================================================================
 * codex-gateway · control panel styles
 * Aesthetic: terminal-modern. Dark, mono-typed, phosphor-green accent.
 * No designer fonts other than JetBrains Mono. No purple, no rounded
 * cards, no soft pastels — this is a control panel for a developer tool.
 * ===================================================================== */

:root {
  /* Surfaces */
  --bg:            #0a0c10;
  --bg-subtle:     #0e1218;
  --surface:       #11161e;
  --surface-hover: #161c26;

  /* Borders */
  --border:        #1f2733;
  --border-strong: #2a3543;

  /* Text */
  --text:          #e4e7ec;
  --text-dim:      #8590a0;
  --text-faint:    #4a5563;

  /* Accents */
  --accent:        #7ee787;             /* phosphor green */
  --accent-dim:    rgba(126, 231, 135, 0.12);
  --accent-glow:   rgba(126, 231, 135, 0.35);
  --interactive:   #79c0ff;             /* cyan-blue */
  --interactive-h: #a5d6ff;

  /* Semantic */
  --warn:          #f7c948;
  --error:         #ff7b72;
  --error-dim:     rgba(255, 123, 114, 0.1);

  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

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

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

body {
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--text);
  background-color: var(--bg);
  /* Subtle off-axis glow — feels like a CRT but not heavy-handed */
  background-image:
    radial-gradient(ellipse at 10% -10%, rgba(126, 231, 135, 0.04) 0%, transparent 40%),
    radial-gradient(ellipse at 110% 110%, rgba(121, 192, 255, 0.03) 0%, transparent 50%);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-feature-settings: 'calt' 1, 'liga' 1, 'ss02' 1;
}

a {
  color: var(--interactive);
  text-decoration: none;
}
a:hover { color: var(--interactive-h); text-decoration: underline; }

code, pre, .v {
  font-family: var(--font-mono);
  font-feature-settings: 'calt' 0;
}

/* ===== Topbar ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 28px;
  border-bottom: 1px solid var(--border);
  background: rgba(10, 12, 16, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.brand .prompt {
  color: var(--accent);
  font-weight: 800;
  font-size: 16px;
  text-shadow: 0 0 8px var(--accent-glow);
}
.brand-name {
  font-weight: 700;
  font-size: 14px;
  letter-spacing: -0.01em;
}
.version {
  color: var(--text-faint);
  font-size: 11px;
}

/* ===== Status pill ===== */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.status-pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
}
.status-pill[data-state="ok"] {
  border-color: rgba(126, 231, 135, 0.35);
  color: var(--accent);
}
.status-pill[data-state="ok"] .dot {
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
  animation: pulse 2.8s ease-in-out infinite;
}
.status-pill[data-state="err"] {
  border-color: rgba(255, 123, 114, 0.35);
  color: var(--error);
}
.status-pill[data-state="err"] .dot { background: var(--error); }
.status-pill[data-state="warn"] {
  border-color: rgba(247, 201, 72, 0.35);
  color: var(--warn);
}
.status-pill[data-state="warn"] .dot { background: var(--warn); }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.45; transform: scale(0.9); }
}

/* ===== Container ===== */
.container {
  width: 100%;
  max-width: 920px;
  margin: 0 auto;
  padding: 28px 28px 64px;
  flex: 1;
}

/* ===== Panels ===== */
.panel {
  border: 1px solid var(--border);
  background: var(--surface);
  margin-bottom: 18px;
  animation: panel-in 0.4s ease-out backwards;
}
.panel:nth-child(1) { animation-delay: 0.00s; }
.panel:nth-child(2) { animation-delay: 0.04s; }
.panel:nth-child(3) { animation-delay: 0.08s; }
.panel:nth-child(4) { animation-delay: 0.12s; }
.panel:nth-child(5) { animation-delay: 0.16s; }
.panel:nth-child(6) { animation-delay: 0.20s; }

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

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-subtle);
}
.panel-head h2 {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text);
  text-transform: lowercase;
  letter-spacing: 0;
}
.panel-head h2 .muted {
  color: var(--text-faint);
  font-weight: 400;
}
.panel-sub {
  font-size: 11px;
  color: var(--text-faint);
}
.panel-body {
  padding: 18px;
}

/* ===== K-V rows ===== */
.kv {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
}
.kv:last-child { border-bottom: none; }
.kv .k {
  color: var(--text-dim);
  font-size: 11.5px;
  width: 130px;
  flex-shrink: 0;
  text-transform: lowercase;
}
.kv .v {
  color: var(--text);
  flex: 1;
  word-break: break-all;
  font-size: 12.5px;
}

/* ===== Copyable code ===== */
.copyable {
  cursor: pointer;
  border-bottom: 1px dotted var(--text-faint);
  transition: color 0.15s, border-color 0.15s;
}
.copyable:hover {
  color: var(--interactive);
  border-bottom-color: var(--interactive);
}
.copyable.copied {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ===== Buttons ===== */
button {
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 500;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  padding: 7px 14px;
  cursor: pointer;
  border-radius: 3px;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  letter-spacing: 0.01em;
}
button:hover {
  background: var(--surface-hover);
  border-color: var(--text-dim);
}
button:focus-visible {
  outline: 2px solid var(--interactive);
  outline-offset: 1px;
}
button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent-dim);
  border-color: rgba(126, 231, 135, 0.4);
  color: var(--accent);
  font-weight: 600;
}
.btn-primary:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
}
.btn-danger {
  border-color: rgba(255, 123, 114, 0.35);
  color: var(--error);
}
.btn-danger:hover {
  background: var(--error-dim);
  border-color: var(--error);
}

/* ===== Inputs ===== */
input[type="text"], input[type="password"], select {
  font-family: var(--font-mono);
  font-size: 12.5px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 7px 12px;
  border-radius: 3px;
  width: 100%;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--interactive);
  box-shadow: 0 0 0 2px rgba(121, 192, 255, 0.15);
}

.api-key-input-wrap {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.api-key-input-wrap input { flex: 1; }

/* Inline select inside panel-sub */
.inline-select {
  width: auto;
  padding: 2px 6px;
  font-size: 11px;
  background: var(--bg-subtle);
  border-color: var(--border);
  color: var(--text-dim);
}

/* ===== Auth section variations ===== */
.auth-pending p { margin-bottom: 8px; }

.user-code-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 28px 20px;
  background: var(--bg);
  border: 1px dashed var(--border-strong);
  margin: 16px 0 12px;
  gap: 10px;
  text-align: center;
}
.user-code {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: 6px;
  color: var(--accent);
  text-shadow: 0 0 14px var(--accent-glow);
  user-select: all;
  font-feature-settings: 'tnum' 1;
  margin: 6px 0;
  position: relative;
  padding-right: 14px;
}
.user-code::after {
  content: '_';
  position: absolute;
  right: -2px;
  color: var(--accent);
  animation: caret-blink 1s steps(2) infinite;
}
@keyframes caret-blink {
  to { opacity: 0; }
}
.verify-url code {
  color: var(--interactive);
  background: var(--surface);
  padding: 3px 8px;
  border-radius: 2px;
  font-size: 13px;
}

.waiting {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
  font-size: 11.5px;
  margin-top: 6px;
}
.spinner {
  display: inline-block;
  width: 11px;
  height: 11px;
  border: 1px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

.auth-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

/* ===== Code examples (collapsible) ===== */
.example {
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.example summary {
  padding: 8px 12px;
  background: var(--bg-subtle);
  cursor: pointer;
  font-size: 12px;
  color: var(--text-dim);
  list-style: none;
  user-select: none;
}
.example summary::-webkit-details-marker { display: none; }
.example summary::before {
  content: '▸ ';
  color: var(--text-faint);
  display: inline-block;
  width: 14px;
  font-size: 10px;
}
.example[open] summary::before {
  content: '▾ ';
}
.example summary:hover { color: var(--text); }
.example pre {
  padding: 14px;
  overflow-x: auto;
  background: var(--bg);
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--text);
}
.example pre code { color: inherit; }

/* ===== Model groups ===== */
.family-group {
  border: 1px solid var(--border);
  margin-bottom: 6px;
  border-radius: 3px;
  overflow: hidden;
}
.family-group summary {
  padding: 9px 14px;
  cursor: pointer;
  background: var(--bg-subtle);
  font-size: 12.5px;
  color: var(--text);
  list-style: none;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 8px;
}
.family-group summary::-webkit-details-marker { display: none; }
.family-group summary::before {
  content: '▸ ';
  color: var(--text-faint);
  width: 14px;
  font-size: 10px;
}
.family-group[open] summary::before { content: '▾ '; }
.family-name { font-weight: 600; }
.family-group .count {
  color: var(--text-faint);
  font-size: 10.5px;
  margin-left: auto;
  font-weight: 400;
}
.model-list {
  list-style: none;
  padding: 8px 14px 10px;
  background: var(--surface);
}
.model-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 3px 0;
  font-size: 12.5px;
}

.badge {
  display: inline-block;
  padding: 1px 7px;
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 9.5px;
  border-radius: 2px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}
.badge-low      { background: rgba(141, 168, 199, 0.15); color: #8da8c7; }
.badge-medium   { background: rgba(126, 231, 135, 0.15); color: #7ee787; }
.badge-high     { background: rgba(247, 201, 72, 0.15);  color: #f7c948; }
.badge-minimal  { background: rgba(118, 118, 130, 0.15); color: var(--text-dim); }
.badge-default  { background: rgba(74, 85, 99, 0.15);    color: var(--text-faint); }
.badge-web      { background: rgba(121, 192, 255, 0.13); color: #79c0ff; text-transform: none; letter-spacing: 0; }

/* ===== Usage stats ===== */
.usage-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}
.usage-stat {
  padding: 12px 14px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 3px;
}
.usage-stat-label {
  font-size: 10.5px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.usage-stat-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin-top: 4px;
  font-feature-settings: 'tnum' 1;
}
.usage-stat-sub {
  font-size: 10.5px;
  color: var(--text-faint);
  margin-top: 2px;
}

.usage-bars {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 56px;
  margin: 6px 0 12px;
  padding: 0;
}
.usage-bar {
  flex: 1;
  background: var(--accent-dim);
  border-top: 2px solid var(--accent);
  min-height: 2px;
  transition: background 0.15s;
  position: relative;
}
.usage-bar:hover { background: rgba(126, 231, 135, 0.25); }
.usage-bar-empty {
  border-top: 1px dashed var(--border-strong);
  background: none;
}

.section-label {
  display: block;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin: 16px 0 6px;
}

.model-usage-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.model-usage-row:last-child { border-bottom: none; }
.model-usage-row code { flex: 1; word-break: break-all; }
.model-usage-row .meta {
  color: var(--text-dim);
  font-size: 11px;
  white-space: nowrap;
}

/* ===== Helpers ===== */
.dim   { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.small { font-size: 11px; }
.lead  { margin-bottom: 12px; }

/* ===== Footer ===== */
footer {
  padding: 20px 28px;
  text-align: center;
  font-size: 10.5px;
  color: var(--text-faint);
  border-top: 1px solid var(--border);
  letter-spacing: 0.02em;
}
footer a { color: var(--text-dim); }
footer a:hover { color: var(--interactive); }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 22px;
  right: 22px;
  padding: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 3px;
  font-size: 11.5px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 100;
  max-width: 320px;
  word-break: break-word;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
}
.toast.error {
  border-color: var(--error);
  color: var(--error);
}

/* ===== Responsive ===== */
@media (max-width: 720px) {
  .container { padding: 18px 14px 48px; }
  .topbar    { padding: 12px 14px; }
  .panel-head, .panel-body { padding-left: 14px; padding-right: 14px; }
  .kv { flex-direction: column; align-items: flex-start; gap: 2px; }
  .kv .k { width: auto; }
  .usage-grid { grid-template-columns: 1fr 1fr; }
  .user-code { font-size: 26px; letter-spacing: 4px; }
  .api-key-input-wrap { flex-wrap: wrap; }
  .api-key-input-wrap input { flex: 1 1 100%; }
}
