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

:root {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --border: #e0e0e0;
  --text: #1a1a1a;
  --muted: #666;
  --green: #22c55e;
  --yellow: #f59e0b;
  --red: #ef4444;
  --blue: #3b82f6;
  --blue-dark: #2563eb;
  --nav-bg: #111827;
  --nav-text: #f9fafb;
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* ── Nav ── */
nav {
  background: var(--nav-bg);
  color: var(--nav-text);
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 24px;
  height: 52px;
  position: sticky;
  top: 0;
  z-index: 100;
}
nav .brand { color: #fff; font-weight: 700; font-size: 15px; text-decoration: none; white-space: nowrap; }
nav .nav-links { display: flex; gap: 4px; flex: 1; }
nav .nav-links a {
  color: rgba(255,255,255,0.7);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 13px;
  transition: background 0.15s, color 0.15s;
}
nav .nav-links a:hover { color: #fff; background: rgba(255,255,255,0.1); }
nav .nav-user { display: flex; align-items: center; gap: 8px; margin-left: auto; }
nav .nav-username { color: rgba(255,255,255,0.8); font-size: 13px; }
.badge-admin {
  background: #7c3aed; color: #fff;
  font-size: 10px; font-weight: 700;
  padding: 2px 6px; border-radius: 10px;
  text-transform: uppercase; letter-spacing: 0.05em;
}
.btn-logout {
  background: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.8);
  border: 1px solid rgba(255,255,255,0.2);
  padding: 4px 10px; border-radius: 6px;
  cursor: pointer; font-size: 12px;
  transition: background 0.15s;
}
.btn-logout:hover { background: rgba(255,255,255,0.2); color: #fff; }

/* ── Main ── */
main { max-width: 1400px; margin: 0 auto; padding: 28px 24px; }

/* ── Login ── */
body.login-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: var(--nav-bg);
}
.login-box {
  background: var(--surface);
  border-radius: 12px;
  padding: 40px;
  width: 100%; max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-title {
  font-size: 20px; font-weight: 700;
  text-align: center; margin-bottom: 28px; color: var(--text);
}
.login-form { display: flex; flex-direction: column; gap: 16px; }

/* ── Page header ── */
.page-header {
  display: flex; align-items: center; gap: 16px;
  margin-bottom: 20px;
}
.page-header h2 { font-size: 18px; font-weight: 600; }
.page-header .meta { color: var(--muted); font-size: 13px; margin-left: auto; }
.back-link { color: var(--blue); text-decoration: none; font-size: 13px; }
.back-link:hover { text-decoration: underline; }

/* ── Alerts ── */
.alert {
  padding: 12px 16px; border-radius: 8px;
  margin-bottom: 20px; font-size: 13px;
}
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #86efac; }

/* ── Queue bar ── */
.queue-bar {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 20px;
}
.queue-stat { font-weight: 600; font-size: 13px; padding: 4px 12px; border-radius: 20px; }
.queue-stat.active   { background: #fef9c3; color: #92400e; }
.queue-stat.waiting  { background: #dbeafe; color: #1e40af; }
.queue-stat.completed { background: #dcfce7; color: #166534; }
.queue-stat.failed   { background: #fee2e2; color: #991b1b; }
.queue-link { margin-left: auto; font-size: 13px; color: var(--blue); text-decoration: none; }

/* ── Table ── */
table {
  width: 100%; border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px; overflow: hidden;
}
th {
  background: #f9fafb; text-align: left;
  padding: 10px 12px;
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted); border-bottom: 1px solid var(--border);
}
td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafafa; }
.row-active td { background: #fefce8 !important; }
.truncate { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 40px; }
.muted { color: var(--muted); }
.action-cell { white-space: nowrap; display: flex; gap: 6px; align-items: center; }

/* ── Status badges ── */
.status {
  display: inline-block; padding: 2px 8px;
  border-radius: 12px; font-size: 11px;
  font-weight: 600; text-transform: uppercase;
}
.status-complete  { background: #dcfce7; color: #166534; }
.status-pending   { background: #dbeafe; color: #1e40af; }
.status-active    { background: #fef9c3; color: #92400e; }
.status-error, .status-failed { background: #fee2e2; color: #991b1b; }
.status-timeout   { background: #ffe4e6; color: #9f1239; }
.status-user      { background: #e0e7ff; color: #3730a3; }
.status-admin     { background: #ede9fe; color: #5b21b6; }

/* ── Buttons ── */
.btn-primary {
  background: var(--blue); color: #fff;
  border: none; padding: 8px 16px;
  border-radius: 6px; cursor: pointer;
  font-size: 13px; font-weight: 600;
  text-decoration: none; display: inline-block;
  transition: background 0.15s;
}
.btn-primary:hover { background: var(--blue-dark); }
.btn-block { width: 100%; text-align: center; padding: 10px; }

.btn-secondary {
  background: #f3f4f6; color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 16px; border-radius: 6px;
  cursor: pointer; font-size: 13px; font-weight: 500;
  text-decoration: none; display: inline-block;
  transition: background 0.15s;
}
.btn-secondary:hover { background: #e5e7eb; }

.btn-sm {
  padding: 4px 10px; border-radius: 5px;
  font-size: 12px; font-weight: 600;
  border: none; cursor: pointer;
  text-decoration: none; display: inline-block;
}
.btn-warn { background: #fef3c7; color: #92400e; }
.btn-warn:hover { background: #fde68a; }
.btn-danger { background: #fee2e2; color: #991b1b; }
.btn-danger:hover { background: #fca5a5; }
.btn-retry { background: var(--yellow); color: #fff; border: none; padding: 4px 10px; border-radius: 4px; cursor: pointer; font-size: 12px; font-weight: 600; }
.btn-retry:hover { background: #d97706; }

.btn-page {
  display: inline-block; padding: 6px 14px;
  background: var(--blue); color: #fff;
  border-radius: 6px; text-decoration: none;
  font-size: 13px; margin-right: 8px;
}
.btn-page:hover { background: var(--blue-dark); }

.inline-form { display: inline; }

/* ── Fields & forms ── */
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 13px; font-weight: 500; color: var(--text); }
.field input, .field select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px; font-size: 14px;
  background: #fff; width: 100%;
  transition: border-color 0.15s;
}
.field input:focus, .field select:focus {
  outline: none; border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
}
.field-checkbox { flex-direction: row; align-items: center; }
.field-checkbox input { width: auto; margin-right: 8px; }
.required { color: var(--red); }
.stacked-form { display: flex; flex-direction: column; gap: 16px; }
.form-actions { display: flex; gap: 10px; align-items: center; padding-top: 8px; }

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px; padding: 24px;
}
.card h3 { font-size: 15px; font-weight: 600; margin-bottom: 16px; }
.card-header { margin-bottom: 16px; }
.card-header h3 { margin-bottom: 4px; }
.form-card { max-width: 480px; }
.mt { margin-top: 24px; }
.mt-sm { margin-top: 14px; }

/* ── Two-col layout ── */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 0; }
@media (max-width: 700px) { .two-col { grid-template-columns: 1fr; } }

/* ── Info list (profile) ── */
.info-list { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; }
.info-list dt { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; display: flex; align-items: center; }
.info-list dd { font-size: 14px; }

/* ── API Key reveal ── */
.key-reveal { margin-bottom: 16px; }
.key-value {
  display: block; margin-top: 8px;
  background: #111827; color: #86efac;
  padding: 10px 14px; border-radius: 6px;
  font-size: 13px; word-break: break-all;
  font-family: monospace;
}

/* ── Inline key form ── */
.inline-key-form { display: flex; gap: 10px; align-items: center; }
.inline-key-form input {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px; font-size: 14px;
  flex: 1; max-width: 280px;
}
.inline-key-form input:focus {
  outline: none; border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
}

/* ── Transcript ── */
.transcript-header { margin-bottom: 20px; }
.transcript-header .back-link { display: inline-block; margin-bottom: 8px; }
.transcript-header h2 { margin-bottom: 6px; }
.transcript-header .meta { display: flex; gap: 16px; align-items: center; color: var(--muted); font-size: 13px; }
.method-badge { background: #dbeafe; color: #1e40af; padding: 2px 8px; border-radius: 12px; font-size: 11px; font-weight: 600; }
.transcript-body {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 24px;
  max-height: 75vh; overflow-y: auto;
}
.cue { margin-bottom: 10px; line-height: 1.6; }
.ts { font-family: monospace; color: var(--muted); font-size: 12px; margin-right: 8px; }

/* ── Pagination ── */
.pagination { margin-top: 16px; }

/* ── Misc ── */
.error-msg { color: var(--red); font-size: 12px; max-width: 300px; }
code { background: #f3f4f6; padding: 2px 5px; border-radius: 4px; font-size: 12px; font-family: monospace; }
.null-val { color: #aaa; font-style: italic; font-size: 11px; }
.section-title { font-size: 14px; font-weight: 600; margin: 24px 0 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.card-header-row { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 16px; }
.mb { margin-bottom: 20px; }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 500;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.modal-overlay[hidden] { display: none; }
.modal-box {
  background: var(--surface);
  border-radius: 12px;
  width: 100%; max-width: 720px;
  max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: 0 24px 80px rgba(0,0,0,0.3);
  overflow: hidden;
}
.modal-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h3 { font-size: 16px; font-weight: 600; margin-bottom: 2px; }
.modal-meta { font-size: 12px; color: var(--muted); }
.modal-close {
  background: none; border: none; font-size: 18px; cursor: pointer;
  color: var(--muted); padding: 2px 6px; border-radius: 4px;
  line-height: 1; margin-left: 12px; flex-shrink: 0;
}
.modal-close:hover { background: #f3f4f6; color: var(--text); }
.modal-body {
  overflow-y: auto; padding: 20px 24px;
  flex: 1;
}
.modal-loading { text-align: center; color: var(--muted); padding: 40px; }
.modal-box-lg { max-width: 860px; }
.modal-box-sm { max-width: 420px; }
.modal-footer { display: flex; align-items: center; gap: 10px; padding-top: 20px; border-top: 1px solid var(--border); margin-top: 20px; }
.save-status { font-size: 12px; color: var(--muted); }
.delete-label { font-family: monospace; font-size: 13px; background: #f3f4f6; padding: 6px 10px; border-radius: 6px; margin: 10px 0; word-break: break-all; }

/* ── DB Modal form ── */
.db-modal-form { display: flex; flex-direction: column; }
.db-field { display: grid; grid-template-columns: 180px 1fr; gap: 8px 16px; align-items: start; padding: 10px 0; border-bottom: 1px solid var(--border); }
.db-field:last-child { border-bottom: none; }
.db-field-label { font-size: 12px; padding-top: 8px; line-height: 1.5; }
.db-field-label strong { display: block; }
.col-type { color: var(--muted); font-size: 11px; font-family: monospace; }
.pk-badge { background: #fef3c7; color: #92400e; font-size: 10px; font-weight: 700; padding: 1px 5px; border-radius: 4px; text-transform: uppercase; }
.pk-input { background: #f9fafb; color: var(--muted); }
.db-field input[type="text"], .db-field textarea {
  width: 100%; padding: 7px 10px;
  border: 1px solid var(--border); border-radius: 6px;
  font-size: 13px; font-family: inherit;
}
.db-field input:focus, .db-field textarea:focus {
  outline: none; border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
}
.db-field input:disabled, .db-field textarea:disabled { background: #f9fafb; color: var(--muted); cursor: default; }
.bool-wrap { display: flex; align-items: center; gap: 8px; padding-top: 6px; }
.bool-wrap input { width: 16px; height: 16px; cursor: pointer; }

/* ── Database Admin ── */
.db-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 20px;
  align-items: start;
}
@media (max-width: 700px) { .db-layout { grid-template-columns: 1fr; } }

.db-sidebar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  position: sticky;
  top: 72px;
}
.sidebar-title {
  padding: 10px 14px;
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted);
  background: #f9fafb;
  border-bottom: 1px solid var(--border);
}
.sidebar-link {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 14px;
  text-decoration: none;
  color: var(--text);
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
}
.sidebar-link:last-child { border-bottom: none; }
.sidebar-link:hover { background: #f3f4f6; }
.sidebar-link.active { background: #eff6ff; color: var(--blue); font-weight: 600; }
.row-count { font-size: 11px; color: var(--muted); background: #f3f4f6; padding: 1px 6px; border-radius: 10px; }

.db-main { min-width: 0; }

.sql-form { display: flex; flex-direction: column; gap: 10px; }
.sql-input {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 8px;
  font-family: 'SF Mono', 'Fira Code', monospace; font-size: 13px;
  resize: vertical; background: #1e1e2e; color: #cdd6f4;
  line-height: 1.6;
}
.sql-input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(59,130,246,0.1); }
.sql-actions { display: flex; align-items: center; gap: 14px; }
.sql-results-meta { font-size: 12px; color: var(--muted); margin-bottom: 10px; }

.table-scroll { overflow-x: auto; border-radius: 8px; border: 1px solid var(--border); }
.table-scroll table { border: none; border-radius: 0; min-width: 600px; }
.db-cell { font-size: 12px; font-family: monospace; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.db-textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font-family: monospace; font-size: 13px; resize: vertical; }

/* ── API Test page ── */
.api-example { margin-bottom: 16px; }
.api-label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 6px; }
.api-code { display: block; background: #1e1e2e; color: #89dceb; padding: 10px 14px; border-radius: 6px; font-size: 13px; font-family: monospace; }
.api-pre { background: #1e1e2e; color: #cdd6f4; padding: 12px 14px; border-radius: 6px; font-size: 12px; font-family: monospace; white-space: pre; overflow-x: auto; line-height: 1.7; }

/* ── Nav extras ── */
.nav-divider { width: 1px; background: rgba(255,255,255,0.15); margin: 0 4px; align-self: stretch; }
.btn-profile {
  color: rgba(255,255,255,0.8); font-size: 12px;
  text-decoration: none; padding: 4px 10px;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 6px; transition: background 0.15s;
}
.btn-profile:hover { background: rgba(255,255,255,0.1); color: #fff; }

/* ── Manual ── */
.manual-layout {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 24px;
  align-items: start;
}
@media (max-width: 700px) { .manual-layout { grid-template-columns: 1fr; } }

.manual-toc {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  position: sticky;
  top: 72px;
}
.manual-toc .sidebar-link { font-size: 12px; padding: 8px 14px; }

.manual-content { min-width: 0; }
.manual-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px;
  margin-bottom: 20px;
}
.manual-section h3 {
  font-size: 17px; font-weight: 700;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.manual-section h4 { font-size: 13px; font-weight: 600; margin: 20px 0 8px; }
.manual-section p { margin-bottom: 12px; line-height: 1.7; font-size: 14px; }
.manual-section ul, .manual-section ol { margin: 0 0 12px 20px; line-height: 1.9; font-size: 14px; }
.manual-section li { margin-bottom: 2px; }

.manual-callout {
  background: #eff6ff; border-left: 4px solid var(--blue);
  padding: 12px 16px; border-radius: 0 8px 8px 0;
  font-size: 13px; margin: 16px 0; line-height: 1.6;
}
.manual-callout.warning {
  background: #fefce8; border-left-color: var(--yellow); color: #713f12;
}
.manual-table {
  width: 100%; border-collapse: collapse;
  font-size: 13px; margin: 12px 0;
  border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
}
.manual-table th {
  background: #f9fafb; padding: 8px 12px;
  text-align: left; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted); border-bottom: 1px solid var(--border);
}
.manual-table td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.manual-table tr:last-child td { border-bottom: none; }

/* ── Regression Tests ── */
.test-toolbar {
  display: flex; align-items: center; gap: 20px;
  margin-bottom: 24px;
}
.test-summary {
  display: flex; align-items: center; gap: 14px;
  font-size: 13px; font-weight: 600;
}
.test-summary.hidden { display: none; }
.sum-pass { color: #166534; background: #dcfce7; padding: 4px 12px; border-radius: 20px; }
.sum-fail { color: #991b1b; background: #fee2e2; padding: 4px 12px; border-radius: 20px; }
.sum-time { color: var(--muted); font-weight: 400; }

.test-group { margin-bottom: 24px; }
.test-group-title {
  font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); margin-bottom: 8px;
}
.test-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.test-row {
  display: grid;
  grid-template-columns: 28px 1fr 1fr auto auto;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
  font-size: 13px;
}
.test-row:last-child { border-bottom: none; }
.test-row.pass { background: #f0fdf4; }
.test-row.fail { background: #fff5f5; }
.test-row.running { background: #fffbeb; }

.test-indicator {
  font-size: 16px; text-align: center;
  width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; flex-shrink: 0;
  font-weight: 700;
}
.test-indicator.pass { color: #166534; }
.test-indicator.fail { color: #991b1b; }
.test-indicator.running { color: #92400e; }

.test-name { font-size: 13px; }
.test-msg  { font-size: 11px; color: #991b1b; font-family: monospace; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.test-time { font-size: 11px; color: var(--muted); white-space: nowrap; text-align: right; }
