:root {
  --bg: #f7f7f4;
  --panel: #ffffff;
  --ink: #171a18;
  --muted: #626b66;
  --line: #d9ddd7;
  --accent: #12664f;
  --accent-2: #c08a2d;
  --danger: #9a3412;
  --soft: #e8f1ec;
  --shadow: 0 18px 50px rgba(22, 28, 24, .08);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

a { color: inherit; text-decoration: none; }
button, input { font: inherit; }

.topbar {
  min-height: 72px;
  padding: 14px clamp(18px, 4vw, 56px);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  background: rgba(247, 247, 244, .92);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
}

.brand strong, .brand small { display: block; }
.brand strong { font-size: 17px; }
.brand small { color: var(--muted); font-size: 12px; margin-top: 1px; }

.topnav {
  display: flex;
  gap: 18px;
  color: var(--muted);
  font-size: 14px;
}

.topnav a:hover { color: var(--ink); }

main { width: min(1180px, calc(100% - 32px)); margin: 0 auto; }

.hero {
  min-height: calc(100vh - 72px);
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, .65fr);
  gap: clamp(24px, 5vw, 64px);
  align-items: center;
  padding: 52px 0 42px;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 760;
  text-transform: uppercase;
}

h1, h2, p { margin-top: 0; }

h1 {
  max-width: 790px;
  font-size: clamp(40px, 7vw, 76px);
  line-height: .98;
  font-weight: 820;
  margin-bottom: 22px;
}

.lead {
  max-width: 760px;
  color: var(--muted);
  font-size: clamp(17px, 2vw, 21px);
  margin-bottom: 28px;
}

.search-shell {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 16px;
  border-radius: 8px;
}

.search-shell label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 8px;
}

.search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.search-row input {
  width: 100%;
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 16px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

.search-row input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(18, 102, 79, .14);
}

.search-row button, .query-chips button, .ghost {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
}

.search-row button {
  min-width: 132px;
  padding: 0 24px;
  background: var(--accent);
  color: #fff;
  font-weight: 760;
}

.search-row button:hover { background: #0e5743; }

.query-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.query-chips button {
  background: var(--soft);
  color: #24483d;
  padding: 0 12px;
  font-size: 13px;
}

.query-chips button:hover { border-color: rgba(18, 102, 79, .35); }

.corpus-panel {
  border: 1px solid var(--line);
  background: #fbfbf8;
  border-radius: 8px;
  padding: 20px;
}

.corpus-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.corpus-head span { color: var(--muted); }
.corpus-head strong { font-size: 34px; }

.corpus-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 18px 0;
}

.corpus-grid div {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  background: #fff;
}

.corpus-grid dt { color: var(--muted); font-size: 12px; }
.corpus-grid dd { margin: 4px 0 0; font-weight: 780; font-size: 20px; }

.source-map {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.source-map span {
  flex: 1 1 70px;
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 8px;
}

.source-map i { display: none; }

.results-section {
  scroll-margin-top: 88px;
  padding: 28px 0 56px;
  border-top: 1px solid var(--line);
}

.results-toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.results-toolbar h2 { margin: 0; font-size: 28px; }

.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--muted);
  padding: 0 14px;
}

.ghost:hover { color: var(--ink); border-color: #aeb7b1; }

.active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: -4px 0 16px;
}

.filter-chip {
  min-height: 32px;
  border: 1px solid rgba(18, 102, 79, .24);
  border-radius: 6px;
  background: var(--soft);
  color: #24483d;
  padding: 0 9px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.filter-chip span {
  color: var(--muted);
}

.filter-chip:hover {
  border-color: rgba(18, 102, 79, .42);
}

.workbench {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.facets {
  position: sticky;
  top: 92px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 14px;
}

.facet-group + .facet-group {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.facet-group h3 {
  font-size: 13px;
  margin: 0 0 8px;
  color: var(--muted);
  text-transform: uppercase;
}

.facet-group button {
  width: 100%;
  min-height: 36px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  padding: 0 8px;
  text-align: left;
}

.facet-group button:hover, .facet-group button.active { background: var(--soft); }
.facet-group small { color: var(--muted); }

.results-list {
  display: grid;
  gap: 10px;
}

.result {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 16px;
}

.result-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
}

.result h3 {
  font-size: 18px;
  line-height: 1.25;
  margin: 0 0 8px;
}

.result h3 a:hover { color: var(--accent); }

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.badge {
  border: 1px solid var(--line);
  border-radius: 999px;
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  padding: 0 8px;
  font-size: 12px;
  color: var(--muted);
  background: #fff;
}

.badge.source { color: var(--accent); border-color: rgba(18, 102, 79, .28); }
.badge.status { color: #365f52; border-color: rgba(18, 102, 79, .32); background: var(--soft); }
.badge.warn { color: var(--danger); border-color: rgba(154, 52, 18, .25); background: #fff7ed; }
.badge.danger { color: #8b1d1d; border-color: rgba(139, 29, 29, .26); background: #fff1f1; }

.snippet {
  color: #303632;
  margin: 0;
  font-size: 15px;
}

.relation-note {
  margin: 10px 0 0;
  border-left: 3px solid rgba(18, 102, 79, .28);
  padding-left: 10px;
  color: var(--muted);
  font-size: 13px;
}

.relation-note span {
  color: #3e4641;
  font-weight: 720;
}

mark {
  background: #f5d483;
  color: inherit;
  padding: 0 2px;
  border-radius: 3px;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.result-actions a, .result-actions button {
  min-height: 34px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.result-actions a:hover, .result-actions button:hover { color: var(--ink); border-color: #aeb7b1; }

.empty-state {
  border-top: 1px solid var(--line);
  padding: 40px 0;
}

.empty-state h2 { font-size: 26px; margin-bottom: 8px; }
.empty-state p { color: var(--muted); max-width: 680px; }

.info-band {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  border-top: 1px solid var(--line);
  padding: 44px 0;
}

.info-band h2, .method h2 { font-size: 24px; margin-bottom: 8px; }
.info-band p, .method p { color: var(--muted); margin-bottom: 0; }

.method {
  border-top: 1px solid var(--line);
  padding: 36px 0 64px;
  max-width: 780px;
}

.loading {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 18px;
  color: var(--muted);
}

@media (max-width: 900px) {
  .topnav { display: none; }
  .hero {
    min-height: auto;
    grid-template-columns: 1fr;
    padding-top: 34px;
  }
  .workbench {
    grid-template-columns: 1fr;
  }
  .facets {
    position: static;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    overflow-x: visible;
    padding: 10px;
  }
  .facet-group {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    min-width: 0;
  }
  .facet-group + .facet-group {
    margin-top: 0;
    padding-top: 0;
    padding-left: 8px;
    border-top: 0;
    border-left: 1px solid var(--line);
  }
  .facet-group h3 {
    margin: 0 2px 0 0;
    font-size: 11px;
  }
  .facet-group button {
    width: auto;
    min-height: 34px;
    gap: 8px;
    border: 1px solid var(--line);
    background: #fff;
    white-space: nowrap;
  }
  .info-band {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  main { width: min(100% - 24px, 1180px); }
  .topbar { padding: 12px; min-height: 64px; }
  .brand small { display: none; }
  h1 { font-size: 38px; }
  .search-row { grid-template-columns: 1fr; }
  .search-row button { min-width: 0; width: 100%; }
  .corpus-grid { grid-template-columns: 1fr; }
  .source-map { grid-template-columns: 1fr; }
  .source-map i { display: none; }
  .results-toolbar { align-items: start; flex-direction: column; }
  .results-toolbar h2 { font-size: 26px; }
  .result-head { display: block; }
  .result { padding: 14px; }
}
