:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-raised: #f9fafb;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --line-strong: #d1d5db;
  --brand: #0f766e;
  --brand-light: rgba(15, 118, 110, 0.1);
  --accent: #ea580c;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --success: #065f46;
  --success-bg: #d1fae5;
  --warning-bg: #fef9c3;
  --warning-ink: #854d0e;
  --radius: 8px;
  --radius-sm: 4px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --transition: 0.2s ease;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface-raised: #242731;
    --ink: #e5e7eb;
    --muted: #9ca3af;
    --line: #2d3140;
    --line-strong: #3b3f51;
    --brand: #2dd4bf;
    --brand-light: rgba(45, 212, 191, 0.1);
    --danger: #f87171;
    --danger-bg: rgba(220, 38, 38, 0.1);
    --success: #34d399;
    --success-bg: rgba(6, 95, 70, 0.2);
    --warning-bg: rgba(133, 77, 14, 0.15);
    --warning-ink: #fbbf24;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
    --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
  }
}

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

body {
  color: var(--ink);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--brand); }

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 40px;
}

.shell {
  max-width: 800px;
  margin: 0 auto;
  padding: 40px 40px;
}
.shell.wide { max-width: 1200px; }

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 40px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 60px;
}
.brand { font-weight: 700; font-size: 1.25rem; letter-spacing: -0.02em; }
.brand span { color: var(--brand); }
nav { display: flex; gap: 24px; font-size: 0.875rem; font-weight: 500; }
nav a { color: var(--muted); }
nav a:hover { color: var(--ink); }

h1, h2, h3 { font-weight: 800; letter-spacing: -0.03em; }
h1 { font-size: 3rem; line-height: 1.1; margin-bottom: 24px; }
h2 { font-size: 1.5rem; margin-bottom: 16px; }

.lede { font-size: 1.25rem; color: var(--muted); margin-bottom: 48px; max-width: 600px; }

.section { margin-bottom: 80px; }
.stack { display: flex; flex-direction: column; gap: 16px; }

/* --- Inputs --- */
input, textarea, select {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.875rem;
  font-family: inherit;
  width: 100%;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-light);
}
textarea { min-height: 100px; resize: vertical; }
select { cursor: pointer; }

label {
  display: block;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 4px;
}

/* --- Buttons --- */
button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all var(--transition);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}
button:hover, .button:hover {
  background: var(--surface-raised);
  border-color: var(--line-strong);
}
button:focus-visible, .button:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}
button.primary, .button.primary {
  background: var(--ink);
  color: var(--bg);
  border-color: transparent;
}
button.primary:hover, .button.primary:hover {
  opacity: 0.9;
}
button.sm {
  font-size: 0.75rem;
  padding: 4px 10px;
}
button.danger {
  color: var(--danger);
  border-color: var(--danger);
}
button.danger:hover {
  background: var(--danger-bg);
}

/* --- Search box --- */
.search-box { position: relative; margin-bottom: 40px; }
.search-box input {
  width: 100%;
  padding: 16px 20px;
  padding-right: 120px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 1.125rem;
}
.search-box input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-light);
}
.search-box button {
  position: absolute;
  right: 8px;
  top: 8px;
  bottom: 8px;
}

/* --- Results --- */
.results { display: flex; flex-direction: column; gap: 16px; }
.result-item {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  animation: fadeUp 0.3s ease both;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.result-item:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow);
}
.result-title {
  font-weight: 600;
  font-size: 1.0625rem;
  color: var(--brand);
  line-height: 1.4;
  text-decoration: none;
}
.result-title:hover { text-decoration: underline; }
.result-url {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 4px;
  word-break: break-all;
  font-family: "SF Mono", "Fira Code", Menlo, Consolas, monospace;
}
.result-snippet {
  font-size: 0.875rem;
  color: var(--muted);
  line-height: 1.6;
  margin-top: 10px;
}
.result-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  flex-wrap: wrap;
}

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

/* --- Status messages --- */
.status-msg { font-size: 0.875rem; margin-bottom: 16px; }
.status-msg.error { color: var(--danger); }
.status-msg.loading { color: var(--muted); }

/* --- Grid / Features --- */
.grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 32px; }
.feature h3 { font-size: 1rem; margin-bottom: 8px; }
.feature p { font-size: 0.875rem; color: var(--muted); }

/* --- Code --- */
pre, code {
  font-family: "SF Mono", "Fira Code", "Fira Mono", Menlo, Consolas, monospace;
}
pre {
  background: var(--surface-raised);
  padding: 20px;
  border-radius: var(--radius);
  font-size: 0.8125rem;
  overflow: auto;
  border: 1px solid var(--line);
  color: var(--ink);
}

/* --- Pills / Badges --- */
.pill {
  display: inline-flex;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.6875rem;
  font-weight: 600;
  background: var(--surface-raised);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.pill.success { background: var(--success-bg); color: var(--success); }
.pill.danger  { background: var(--danger-bg);  color: var(--danger); }
.pill.warn    { background: var(--warning-bg);  color: var(--warning-ink); }
.pill.get     { background: var(--success-bg); color: var(--success); font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 0.625rem; }
.pill.post    { background: rgba(59,130,246,0.1); color: #3b82f6; font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 0.625rem; }

/* --- Docs layout --- */
.docs-layout {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 48px;
  align-items: start;
}
.docs-sidebar {
  position: sticky;
  top: 24px;
}
.docs-sidebar-title {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 12px;
}
.docs-nav {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.docs-nav a {
  display: block;
  padding: 6px 12px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--muted);
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}
.docs-nav a:hover {
  color: var(--ink);
  background: var(--surface-raised);
}
.docs-nav a.active {
  color: var(--brand);
  background: var(--brand-light);
}
.docs-main h2 {
  padding-top: 32px;
  margin-top: 0;
}
.docs-main h2:first-child { padding-top: 0; }
.endpoint-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  margin: 16px 0 32px;
}
.endpoint-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--surface-raised);
  border-bottom: 1px solid var(--line);
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.875rem;
  font-weight: 600;
}
.endpoint-body {
  padding: 20px;
}
.endpoint-body h3 {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin: 20px 0 8px;
}
.endpoint-body h3:first-child { margin-top: 0; }
.endpoint-body pre {
  margin: 0;
}
.docs-section {
  padding-bottom: 32px;
  margin-bottom: 32px;
  border-bottom: 1px solid var(--line);
}
.docs-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}
@media (max-width: 768px) {
  .docs-layout {
    grid-template-columns: 1fr;
    gap: 24px;
  }
  .docs-sidebar {
    position: static;
    border-bottom: 1px solid var(--line);
    padding-bottom: 16px;
  }
  .docs-nav {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 4px;
  }
}

/* --- Confidence bar --- */
.confidence-bar {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--muted);
}
.confidence-bar .track {
  width: 60px;
  height: 6px;
  background: var(--line);
  border-radius: 3px;
  overflow: hidden;
}
.confidence-bar .fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.4s ease;
}
.conf-high  { background: var(--success); }
.conf-med   { background: #f59e0b; }
.conf-low   { background: var(--danger); }

/* --- Cards --- */
.card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  transition: box-shadow var(--transition);
}
.card:hover { box-shadow: var(--shadow); }
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
  gap: 8px;
}
.card-title {
  font-weight: 600;
  font-size: 0.875rem;
  word-break: break-all;
}
.card-subtitle {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 8px;
  word-break: break-all;
}
.card-actions {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

/* --- Tabs --- */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--line);
  margin-bottom: 24px;
}
.tab {
  padding: 10px 20px;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border: none;
  background: none;
  border-bottom: 2px solid transparent;
  transition: all var(--transition);
}
.tab:hover { color: var(--ink); }
.tab.active {
  color: var(--ink);
  border-bottom-color: var(--brand);
}
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadeUp 0.2s ease; }

/* --- Tables --- */
.table { width: 100%; border-collapse: collapse; }
.table th {
  padding: 8px 12px;
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  text-align: left;
  border-bottom: 1px solid var(--line);
  font-weight: 600;
}
.table td {
  padding: 10px 12px;
  font-size: 0.8125rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.table tr:last-child td { border-bottom: none; }
.table .mono { font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 0.75rem; }

/* --- Alert / Flash --- */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  margin-bottom: 16px;
}
.alert.error   { background: var(--danger-bg); color: var(--danger); }
.alert.success { background: var(--success-bg); color: var(--success); }
.alert.warn    { background: var(--warning-bg); color: var(--warning-ink); }

/* --- Layout helpers --- */
.two-col { display: grid; grid-template-columns: 1fr 2fr; gap: 40px; }
.card-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.gap-sm { gap: 8px; }
.mb-0 { margin-bottom: 0; }
.mt-lg { margin-top: 40px; }
.hidden { display: none; }

/* --- Settings toggle --- */
.settings-wrap { margin-bottom: 24px; }
.settings-toggle {
  font-size: 0.75rem;
  padding: 4px 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.settings-toggle:hover { color: var(--ink); border-color: var(--line-strong); }
.settings-panel {
  margin-top: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

/* --- Pagination --- */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 4px;
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}
.page-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  padding: 0 10px;
  border-radius: var(--radius);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--ink);
  text-decoration: none;
  transition: all var(--transition);
}
.page-link:hover { background: var(--surface-raised); }
.page-link.active {
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  pointer-events: none;
}
.page-ellipsis {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  font-size: 0.8125rem;
  color: var(--muted);
}

/* --- Empty state --- */
.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
  font-size: 0.875rem;
}

.footer {
  margin-top: 120px;
  padding: 40px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.875rem;
}

[hidden] { display: none !important; }

/* --- Spinner --- */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid var(--line);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

@media (max-width: 768px) {
  .two-col { grid-template-columns: 1fr; }
  .card-grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  h1 { font-size: 2.25rem; }
  .grid { grid-template-columns: 1fr; }
  header { padding: 16px 20px; margin-bottom: 32px; }
  .shell { padding: 24px 20px; }
  .footer { padding: 24px 20px; }
  .tabs { overflow-x: auto; }
  .admin-overview { grid-template-columns: 1fr; }
}

/* --- Admin overview --- */
.admin-overview {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 28px;
}
.overview-section {
  padding: 16px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-raised);
}
.overview-title {
  font-size: 0.625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.overview-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
}
.overview-stat {
  display: flex;
  align-items: baseline;
  gap: 5px;
}
.overview-value {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1;
}
.overview-value.brand { color: var(--brand); }
.overview-value.ok    { color: var(--success); }
.overview-value.warn  { color: #f59e0b; }
.overview-value.bad   { color: var(--danger); }
.overview-label {
  font-size: 0.6875rem;
  color: var(--muted);
}
@media (max-width: 640px) {
  .admin-overview { grid-template-columns: 1fr; }
}

/* --- Progress bar --- */
.progress-track {
  width: 100%;
  height: 8px;
  background: var(--line);
  border-radius: 4px;
  overflow: hidden;
  display: flex;
}
.progress-fill {
  height: 100%;
  transition: width 0.4s ease;
}
.progress-fill.ok   { background: var(--success); }
.progress-fill.warn { background: #f59e0b; }
.progress-fill.bad  { background: var(--danger); }

/* --- Tab hints --- */
.tab-hint {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 16px;
}

/* --- Scrollable table wrapper --- */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* --- Admin table helpers --- */
.url-mono {
  font-size: 0.6875rem;
  color: var(--muted);
  font-family: "SF Mono", "Fira Code", Menlo, Consolas, monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- Crawl job row highlight --- */
.table tr.row-processing { background: var(--warning-bg); }
.table tr.row-failed     { background: var(--danger-bg); }

/* --- Better card layout --- */
.card .card-url {
  font-size: 0.6875rem;
  font-family: "SF Mono", "Fira Code", Menlo, Consolas, monospace;
  color: var(--muted);
  word-break: break-all;
  margin-top: 2px;
}
.card .card-time {
  font-size: 0.6875rem;
  color: var(--muted);
  margin-top: 8px;
}
.card .fetch-status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.6875rem;
  color: var(--muted);
  margin-top: 4px;
}
