/* ── Base ── */
:root {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --bg-card: #1e293b;
  --border: #334155;
  --border-hover: #475569;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #8b5cf6;
  --accent-hover: #7c3aed;
  --accent-dim: rgba(139, 92, 246, 0.15);
  --green: #22c55e;
  --green-dim: rgba(34, 197, 94, 0.15);
  --red: #ef4444;
  --red-dim: rgba(239, 68, 68, 0.15);
  --yellow: #eab308;
  --yellow-dim: rgba(234, 179, 8, 0.15);
  --blue: #3b82f6;
  --blue-dim: rgba(59, 130, 246, 0.15);
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Layout ── */
.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: var(--text-primary);
}

.logo-icon {
  width: 32px;
  height: 32px;
  background: var(--accent);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
}

.logo-text {
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
}

.logo-text span {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 0.85rem;
  margin-left: 0.5rem;
}

nav {
  display: flex;
  gap: 0.25rem;
}

nav a {
  color: var(--text-secondary);
  text-decoration: none;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.15s;
}

nav a:hover { color: var(--text-primary); background: var(--bg-tertiary); }
nav a.active { color: var(--accent); background: var(--accent-dim); }

main {
  flex: 1;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem;
}

/* ── Cards ── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 1rem;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
}

/* ── API Key Bar ── */
.api-key-bar {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.api-key-bar label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.api-key-bar input {
  flex: 1;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  color: var(--text-primary);
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.15s;
}

.api-key-bar input:focus { border-color: var(--accent); }
.api-key-bar input::placeholder { color: var(--text-muted); }

.api-key-status {
  font-size: 0.75rem;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  font-weight: 600;
  white-space: nowrap;
}

.api-key-status.connected { background: var(--green-dim); color: var(--green); }
.api-key-status.disconnected { background: var(--bg-tertiary); color: var(--text-muted); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.btn-primary {
  background: var(--accent);
  color: white;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}
.btn-secondary:hover { background: var(--border-hover); }

.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }

/* ── Explorer Layout ── */
.explorer-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 1.5rem;
  align-items: start;
}

.endpoint-list {
  position: sticky;
  top: 72px;
}

.endpoint-category {
  margin-bottom: 1rem;
}

.endpoint-category-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 0 0.75rem;
  margin-bottom: 0.25rem;
}

.endpoint-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
  font-size: 0.85rem;
}

.endpoint-item:hover { background: var(--bg-tertiary); }
.endpoint-item.active { background: var(--accent-dim); color: var(--accent); }

.method-badge {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-family: 'JetBrains Mono', monospace;
  min-width: 36px;
  text-align: center;
}

.method-badge.get { background: var(--green-dim); color: var(--green); }
.method-badge.post { background: var(--blue-dim); color: var(--blue); }

/* ── Explorer Panel ── */
.explorer-panel { min-width: 0; }

.endpoint-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.endpoint-path {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.9rem;
  color: var(--text-secondary);
  background: var(--bg-primary);
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  flex: 1;
  min-width: 200px;
}

.endpoint-description {
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.credit-badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
}

.credit-badge.free { background: var(--green-dim); color: var(--green); }
.credit-badge.paid { background: var(--yellow-dim); color: var(--yellow); }

/* ── Params Form ── */
.params-grid {
  display: grid;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.param-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.param-label {
  min-width: 100px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  font-family: 'JetBrains Mono', monospace;
}

.param-label .required { color: var(--red); margin-left: 2px; }

.param-input {
  flex: 1;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.45rem 0.75rem;
  color: var(--text-primary);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.15s;
}

.param-input:focus { border-color: var(--accent); }
.param-input::placeholder { color: var(--text-muted); }

.param-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
  min-width: 200px;
}

/* ── Response Panel ── */
.response-panel {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.response-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 0.5rem;
}

.response-meta {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.8rem;
}

.status-code {
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
}

.status-code.s2xx { background: var(--green-dim); color: var(--green); }
.status-code.s4xx { background: var(--red-dim); color: var(--red); }
.status-code.s5xx { background: var(--red-dim); color: var(--red); }
.status-code.s429 { background: var(--yellow-dim); color: var(--yellow); }

.response-time { color: var(--text-muted); font-family: 'JetBrains Mono', monospace; }
.response-size { color: var(--text-muted); font-family: 'JetBrains Mono', monospace; }

.response-body {
  padding: 1rem;
  max-height: 600px;
  overflow: auto;
}

.response-body::-webkit-scrollbar { width: 6px; height: 6px; }
.response-body::-webkit-scrollbar-track { background: transparent; }
.response-body::-webkit-scrollbar-thumb { background: var(--bg-tertiary); border-radius: 3px; }

/* ── Response Headers ── */
.response-headers-toggle {
  font-size: 0.8rem;
  color: var(--text-muted);
  cursor: pointer;
  text-decoration: underline;
  text-decoration-style: dotted;
}

.response-headers-toggle:hover { color: var(--text-secondary); }

.response-headers-panel {
  display: none;
  padding: 0.75rem 1rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  color: var(--text-secondary);
  line-height: 1.8;
}

.response-headers-panel.visible { display: block; }

.header-name { color: var(--accent); }

/* ── JSON Viewer ── */
.json-viewer {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.8rem;
  line-height: 1.7;
  white-space: pre;
  margin: 0;
  color: var(--text-primary);
}

.json-key { color: #93c5fd; }
.json-string { color: #86efac; }
.json-number { color: #fde68a; }
.json-bool { color: #c084fc; }
.json-null { color: #94a3b8; font-style: italic; }
.json-brace, .json-bracket { color: var(--text-muted); }
.json-hint { color: var(--text-muted); font-style: italic; }

.json-toggle {
  cursor: pointer;
  user-select: none;
}

.json-toggle:hover .json-arrow { color: var(--accent); }

.json-arrow {
  display: inline-block;
  width: 1em;
  font-size: 0.7em;
  color: var(--text-muted);
  transition: color 0.15s;
}

.json-collapsible.collapsed > *:not(.json-collapse-hint) { display: none; }
.json-collapsible.collapsed { display: inline; }

/* ── Credit Warning Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem;
  max-width: 420px;
  width: 90%;
}

.modal h3 { margin-bottom: 0.75rem; }

.modal p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
}

/* ── Tabs ── */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

.tab {
  padding: 0.5rem 1rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  font-family: inherit;
}

.tab:hover { color: var(--text-secondary); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── Code Block ── */
.code-block {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 1rem;
}

.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

.code-block-lang {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

.code-block pre {
  padding: 1rem;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
  line-height: 1.6;
  overflow-x: auto;
  margin: 0;
  white-space: pre;
  color: var(--text-secondary);
}

/* ── Status Page ── */
.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
}

.status-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
}

.status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.status-dot.up { background: var(--green); box-shadow: 0 0 8px rgba(34, 197, 94, 0.4); }
.status-dot.down { background: var(--red); box-shadow: 0 0 8px rgba(239, 68, 68, 0.4); }
.status-dot.checking { background: var(--yellow); animation: pulse 1.5s infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ── Docs ── */
.docs-section {
  margin-bottom: 2rem;
}

.docs-section h2 {
  font-size: 1.25rem;
  margin-bottom: 0.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.docs-section h3 {
  font-size: 1rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.docs-endpoint {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 1rem;
  overflow: hidden;
}

.docs-endpoint-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem;
  cursor: pointer;
  transition: background 0.15s;
}

.docs-endpoint-header:hover { background: var(--bg-tertiary); }

.docs-endpoint-name {
  font-weight: 600;
  flex: 1;
}

.docs-endpoint-path {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.docs-endpoint-body {
  display: none;
  padding: 1rem;
  border-top: 1px solid var(--border);
}

.docs-endpoint-body.visible { display: block; }

.params-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.params-table th {
  text-align: left;
  padding: 0.5rem 0.75rem;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}

.params-table td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}

.params-table td:first-child {
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-primary);
  font-weight: 500;
}

/* ── Spinner ── */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--bg-tertiary);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Footer ── */
footer {
  padding: 1.5rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
}

footer a { color: var(--accent); text-decoration: none; }
footer a:hover { text-decoration: underline; }

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.3;
}

/* ── Copy button ── */
.copy-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.7rem;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}

.copy-btn:hover { color: var(--text-primary); border-color: var(--border-hover); }
.copy-btn.copied { color: var(--green); border-color: var(--green); }

/* ── Responsive ── */
@media (max-width: 900px) {
  .explorer-layout {
    grid-template-columns: 1fr;
  }
  .endpoint-list {
    position: static;
    display: flex;
    overflow-x: auto;
    gap: 0.5rem;
    padding-bottom: 0.5rem;
  }
  .endpoint-category { margin-bottom: 0; }
  .endpoint-category-label { display: none; }
  .endpoint-item { white-space: nowrap; }
  .param-row { flex-wrap: wrap; }
  .param-desc { min-width: auto; }
  .response-meta { flex-wrap: wrap; }
}

@media (max-width: 640px) {
  header { padding: 0 1rem; }
  nav a { padding: 0.4rem 0.6rem; font-size: 0.8rem; }
  main { padding: 1rem; }
  .api-key-bar { flex-wrap: wrap; }
  .api-key-bar input { min-width: 200px; }
  .endpoint-header { flex-direction: column; align-items: flex-start; }
  .endpoint-path { width: 100%; }
  .modal { padding: 1.5rem; }
}
