:root {
  color-scheme: light;
  --bg: #f7f9fb;
  --panel: #ffffff;
  --panel-soft: #fbfcfd;
  --text: #0c1b3d;
  --muted: #60708f;
  --faint: #8894a8;
  --line: #d9e0ea;
  --line-strong: #c6d1df;
  --accent: #236a58;
  --accent-dark: #174c40;
  --accent-soft: #e6f2ee;
  --blue: #0d4698;
  --amber: #b36a10;
  --amber-soft: #fff3d2;
  --shadow: 0 8px 24px rgba(18, 31, 56, 0.08);
  --radius: 6px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: 64px 1fr;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) auto minmax(260px, 360px);
  align-items: center;
  gap: 24px;
  height: 64px;
  padding: 0 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(18, 31, 56, 0.02);
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  color: #ffffff;
  background: var(--text);
  border-radius: var(--radius);
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  font-size: 19px;
  line-height: 1.1;
  font-weight: 760;
}

.brand p,
.collection-status span,
.budget-meter span,
.surface-header span {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.collection-status {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  white-space: nowrap;
}

.collection-status strong {
  font-size: 13px;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #2e8f71;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.budget-meter {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.budget-meter strong {
  color: var(--amber);
  font-size: 13px;
}

.meter {
  height: 7px;
  overflow: hidden;
  background: #e7ebf1;
  border-radius: 999px;
}

.meter span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #d99128, #9f610d);
}

.workspace {
  display: grid;
  grid-template-columns: 280px minmax(600px, 1fr) 340px;
  min-height: calc(100vh - 64px);
}

.filters,
.inspector {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 18px 16px;
  overflow: auto;
}

.inspector {
  border-right: 0;
  border-left: 1px solid var(--line);
}

.panel-heading,
.surface-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-heading h2,
.surface-header h2 {
  margin: 0;
  font-size: 12px;
  font-weight: 760;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.ghost-button {
  color: var(--blue);
  background: transparent;
  border: 0;
  padding: 4px 0;
  font-size: 12px;
}

.filter-group {
  padding: 0 0 20px;
}

.filter-group > label {
  display: block;
  margin-bottom: 8px;
  color: var(--text);
  font-size: 12px;
  font-weight: 720;
  text-transform: uppercase;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  outline: 0;
}

input,
select {
  height: 34px;
  padding: 0 10px;
}

textarea {
  min-height: 78px;
  resize: vertical;
  padding: 14px;
  line-height: 1.55;
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.check-row {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  color: #263654;
  font-size: 13px;
}

.check-row input {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
}

.check-row span {
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}

.range-pair {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
}

.range-pair span {
  color: var(--muted);
  font-size: 12px;
}

.live-row {
  margin-top: 8px;
}

.primary,
.secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 36px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 720;
}

.primary {
  color: #ffffff;
  background: linear-gradient(180deg, #2b765f, var(--accent-dark));
  border: 1px solid var(--accent-dark);
}

.secondary {
  color: var(--accent-dark);
  background: var(--panel);
  border: 1px solid var(--line-strong);
}

.full-width {
  width: 100%;
  margin-top: 8px;
}

.search-surface {
  min-width: 0;
  padding: 18px 20px 24px;
  overflow: auto;
}

.search-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 14px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.search-box p {
  grid-column: 1 / -1;
  margin: -2px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.search-controls {
  display: grid;
  grid-template-columns: 1fr;
  align-content: start;
  gap: 8px;
}

.search-controls label {
  color: var(--muted);
  font-size: 12px;
}

.search-button svg {
  width: 17px;
  height: 17px;
  fill: currentColor;
}

.inline-example {
  color: var(--blue);
  background: transparent;
  border: 0;
  padding: 0 5px;
  font-size: 12px;
}

.tabs {
  display: flex;
  margin-top: 18px;
  border-bottom: 1px solid var(--line);
}

.tabs button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 132px;
  height: 44px;
  padding: 0 16px;
  color: #253653;
  background: var(--panel);
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0;
}

.tabs button + button {
  margin-left: -1px;
}

.tabs button.active {
  color: var(--accent-dark);
  box-shadow: inset 0 -3px 0 var(--accent);
}

.tabs span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.result-toolbar {
  display: grid;
  grid-template-columns: auto auto 170px 1fr;
  align-items: center;
  gap: 12px;
  height: 56px;
  color: var(--muted);
}

.result-toolbar input {
  width: auto;
  height: auto;
  margin-right: 6px;
  accent-color: var(--accent);
}

.result-toolbar select {
  height: 32px;
}

#resultCount {
  justify-self: end;
}

.results {
  display: grid;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel);
}

.result-row {
  appearance: none;
  display: grid;
  grid-template-columns: 30px 1fr 86px 92px;
  gap: 14px;
  padding: 14px 16px;
  color: inherit;
  border-left: 4px solid transparent;
  border-top: 0;
  border-right: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: var(--panel);
  text-align: left;
}

.result-row:last-child {
  border-bottom: 0;
}

.result-row:hover,
.result-row.active {
  border-left-color: var(--accent);
  background: #fbfdfc;
}

.row-index {
  color: var(--muted);
  font-weight: 720;
  text-align: right;
}

.result-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px;
}

.result-title strong {
  color: var(--blue);
  font-size: 15px;
}

.pill {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 7px;
  color: var(--accent-dark);
  background: var(--accent-soft);
  border: 1px solid #bdd9cf;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 760;
  text-transform: uppercase;
}

.result-meta,
.s3-link {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.snippet {
  display: block;
  max-width: 760px;
  margin: 8px 0;
  color: #22324f;
  line-height: 1.55;
}

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

.metric {
  display: grid;
  align-content: start;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}

.metric strong {
  color: var(--accent-dark);
  font-size: 18px;
}

.empty-state {
  padding: 48px 24px;
  color: var(--muted);
  text-align: center;
}

.selected-card h3 {
  margin: 0 0 8px;
  color: var(--blue);
  font-size: 20px;
}

.selected-card .meta-line {
  margin: 0 0 6px;
  color: #273754;
}

.inspector-tabs {
  display: flex;
  gap: 18px;
  margin: 20px 0 16px;
  border-bottom: 1px solid var(--line);
}

.inspector-tabs button {
  height: 34px;
  padding: 0;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-bottom: 3px solid transparent;
  font-size: 13px;
  font-weight: 720;
}

.inspector-tabs button.active {
  color: var(--accent-dark);
  border-bottom-color: var(--accent);
}

.detail-list {
  display: grid;
  gap: 12px;
}

.detail-list div {
  display: grid;
  grid-template-columns: 116px 1fr;
  gap: 12px;
}

.detail-list dt {
  color: var(--muted);
  font-size: 12px;
}

.detail-list dd {
  margin: 0;
  color: #22324f;
  font-size: 12px;
  line-height: 1.45;
  word-break: break-word;
}

.source-link {
  color: var(--blue);
  text-decoration: none;
}

.source-link:hover {
  text-decoration: underline;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 1180px) {
  .topbar {
    grid-template-columns: 1fr;
    height: auto;
    padding: 14px 18px;
  }

  .workspace {
    grid-template-columns: 240px minmax(0, 1fr);
  }

  .inspector {
    grid-column: 1 / -1;
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}

@media (max-width: 820px) {
  .workspace {
    display: flex;
    flex-direction: column;
  }

  .filters,
  .inspector,
  .search-surface {
    border: 0;
    border-bottom: 1px solid var(--line);
  }

  .search-surface {
    order: 1;
  }

  .filters {
    order: 2;
  }

  .inspector {
    order: 3;
  }

  .search-box,
  .result-row,
  .result-toolbar {
    grid-template-columns: 1fr;
  }

  .collection-status {
    flex-wrap: wrap;
    white-space: normal;
  }

  .tabs {
    overflow-x: auto;
  }

  .tabs button {
    flex: 1 0 118px;
    min-width: 0;
    padding: 0 12px;
  }

  .range-pair {
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  }

  #resultCount {
    justify-self: start;
  }
}
