/* ── Variables ─────────────────────────────────────────────────────────── */
:root {
  color-scheme: light dark;
  --bg:          #f7f3ea;
  --panel:       #fffaf0;
  --text:        #211a12;
  --muted:       #6d6256;
  --border:      #d7cbb9;
  --accent:      #7c2d12;
  --accent-text: #fff8f0;
  --accent-hover:#9c3d18;
  --mark:        #ffe58a;
  --error:       #b42318;
  --error-bg:    #fff0ee;
  --focus:       #1a56db;
  --radius-sm:   10px;
  --radius:      16px;
  --radius-lg:   24px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:          #15120f;
    --panel:       #211b16;
    --text:        #f2eadf;
    --muted:       #b9aa99;
    --border:      #46392f;
    --accent:      #e57b45;
    --accent-text: #211108;
    --accent-hover:#f08c5a;
    --mark:        #6b5214;
    --error:       #f87171;
    --error-bg:    #2d1212;
    --focus:       #60a5fa;
  }
}

/* ── Reset ─────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* ── Focus visible ─────────────────────────────────────────────────────── */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ── Layout ────────────────────────────────────────────────────────────── */
.page-shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 40px 0 80px;
}

/* ── Hero ──────────────────────────────────────────────────────────────── */
.hero { margin-bottom: 32px; }
.eyebrow {
  color: var(--accent);
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  font-size: .85rem;
}
.hero h1 { margin: 4px 0 0; font-size: clamp(2.2rem, 8vw, 4.5rem); line-height: .95; }
.lede { color: var(--muted); max-width: 760px; font-size: 1.05rem; margin: 10px 0 0; }

/* ── Cards & panels ────────────────────────────────────────────────────── */
.search-panel,
.result-card,
.empty-state,
.document-view {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
}

/* ── Query row ─────────────────────────────────────────────────────────── */
.query-label { display: block; margin-bottom: 6px; color: var(--muted); font-size: .9rem; }
.query-row { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; }

/* ── Form controls ─────────────────────────────────────────────────────── */
input,
select,
button,
.button {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text);
  background: var(--bg);
  font: inherit;
  transition: border-color .15s, background .15s;
}

input:hover,
select:hover { border-color: var(--accent); }

button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
  text-decoration: none;
  cursor: pointer;
  font-weight: 600;
  white-space: nowrap;
}

button:hover,
.button:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.button.secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
  font-weight: 400;
}
.button.secondary:hover { border-color: var(--accent); color: var(--accent); background: transparent; }

/* ── Filters ───────────────────────────────────────────────────────────── */
.filters { margin-top: 24px; }
.section-heading { display: flex; align-items: baseline; gap: 12px; margin-bottom: 4px; }
.section-heading h2 { margin: 0; font-size: 1rem; font-weight: 600; }
.section-heading p { margin: 0; color: var(--muted); font-size: .9rem; }
.filter-row {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) 140px minmax(220px, 2fr) auto;
  gap: 10px;
  margin-top: 10px;
  align-items: end;
}
.filter-row span { display: block; margin-bottom: 5px; color: var(--muted); font-size: .85rem; }
.add-filter { margin-top: 12px; }
.load-more { width: 100%; margin-top: 10px; background: transparent; color: var(--accent); border-color: var(--border); }
.load-more:hover { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

/* ── Alerts ────────────────────────────────────────────────────────────── */
.alert {
  margin-top: 18px;
  padding: 14px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--error);
  background: var(--error-bg);
  color: var(--error);
}

/* ── Empty states ──────────────────────────────────────────────────────── */
.empty-state { margin-top: 20px; color: var(--muted); }
.empty-state p { margin: 0 0 6px; }
.empty-state__hint { font-size: .9rem; }

/* ── Results ───────────────────────────────────────────────────────────── */
.results { margin-top: 28px; }
.results h2 { margin: 0 0 16px; font-size: 1.15rem; }
.results-count { color: var(--muted); font-weight: 400; font-size: .9em; }
.result-list { display: grid; gap: 14px; }

.result-card { padding: 18px 22px; }
.result-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.result-header h3 { margin: 0; font-size: 1.1rem; }
.score {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: .85rem;
  white-space: nowrap;
  padding-top: 2px;
}

.meta { display: flex; flex-wrap: wrap; gap: 6px 12px; color: var(--muted); font-size: .9rem; margin-top: 6px; }
.meta span::before { content: "·"; margin-right: 5px; }
.meta span:first-child::before { content: ""; margin-right: 0; }

.window {
  white-space: pre-wrap;
  border-top: 1px solid var(--border);
  margin-top: 12px;
  padding-top: 12px;
  font-size: .95rem;
  line-height: 1.6;
}

mark { background: var(--mark); color: inherit; padding: 1px 3px; border-radius: 4px; }

.actions { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; margin-top: 14px; }
.actions a { color: var(--accent); text-decoration: none; font-size: .9rem; font-weight: 500; }
.actions a:hover { text-decoration: underline; }
.actions code { color: var(--muted); font-size: .8rem; }

/* ── Document view ─────────────────────────────────────────────────────── */
.document-view { padding: clamp(20px, 4vw, 52px); }
.document-header { border-bottom: 1px solid var(--border); padding-bottom: 20px; margin-bottom: 0; }
.document-header h1 { margin: 10px 0 8px; font-size: clamp(1.8rem, 5vw, 3.5rem); line-height: 1.05; }
.back-link { color: var(--accent); text-decoration: none; font-weight: 600; font-size: .9rem; }
.back-link:hover { text-decoration: underline; }

.document-body {
  margin-top: 36px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.1rem;
  line-height: 1.8;
  white-space: pre-wrap;
}

.hit-window {
  background: color-mix(in srgb, var(--mark), transparent 55%);
  outline: 2px solid color-mix(in srgb, var(--accent), transparent 55%);
  border-radius: 3px;
}

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 760px) {
  .query-row { grid-template-columns: 1fr; }
  .filter-row { grid-template-columns: 1fr; }
  .result-header { flex-direction: column; gap: 4px; }
  .score { padding-top: 0; }
}
