:root {
  color-scheme: light;
  --bg: #f5f5f5;
  --surface: #fff;
  --text: #191919;
  --muted: #666;
  --border: #d4d4d4;
  --border-dark: #aaa;
  --accent: #17643d;
  --accent-hover: #114b2e;
  --error: #9b241b;
  --error-bg: #fff4f2;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--bg);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
}

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

button,
select {
  cursor: pointer;
}

button:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

a {
  color: var(--accent);
}

.app-shell {
  width: min(920px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

.site-header {
  min-height: 60px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid var(--border);
}

.brand {
  color: var(--text);
  font-size: 16px;
  font-weight: 650;
  text-decoration: none;
}

.site-header nav {
  display: flex;
  gap: 2px;
}

.site-header nav button,
.row-actions button,
.text-button {
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid transparent;
  border-radius: 4px;
  color: #444;
  background: transparent;
}

.site-header nav button:hover,
.site-header nav button.active {
  border-color: var(--border);
  color: var(--text);
  background: var(--surface);
}

.server-state {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #2f8758;
}

.status-dot.offline {
  background: #ba3b30;
}

main {
  flex: 1;
}

.row-actions button {
  border-color: var(--border);
  background: #fafafa;
}

.row-actions button:hover:not(:disabled) {
  border-color: var(--border-dark);
  background: #f1f1f1;
}

.option-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin-top: 12px;
}

.toggle-button {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 34px;
  padding: 0 13px;
  border: 1px solid var(--border-dark);
  border-radius: 4px;
  color: var(--text);
  background: var(--surface);
  font-size: 13px;
}

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

/* A filled mark makes the pressed state readable without relying on colour. */
.toggle-mark {
  width: 13px;
  height: 13px;
  border: 1px solid var(--border-dark);
  border-radius: 3px;
  background: var(--surface);
}

.toggle-button.pressed {
  border-color: var(--accent);
  color: var(--accent);
}

.toggle-button.pressed .toggle-mark {
  border-color: var(--accent);
  background: var(--accent);
  box-shadow: inset 0 0 0 2px var(--surface);
}

.option-help {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.help-text,
.summary-line {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

.semantic-note {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 14px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.semantic-note .text-button {
  flex: 0 0 auto;
  min-height: 0;
  padding: 0;
}

.page-section {
  padding: 30px 0 42px;
}

.page-heading {
  margin-bottom: 18px;
}

.page-heading h1 {
  margin: 0 0 4px;
  font-size: 26px;
  line-height: 1.2;
}

.page-heading p {
  margin: 0;
  color: var(--muted);
}

.panel {
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}

label,
.panel label > span {
  color: #3f3f3f;
  font-size: 12px;
  font-weight: 600;
}

.panel label > span {
  display: block;
  margin-bottom: 6px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border-dark);
  border-radius: 4px;
  outline: 0;
  color: var(--text);
  background: var(--surface);
}

input {
  height: 40px;
  padding: 0 11px;
}

textarea {
  min-height: 104px;
  padding: 10px 11px;
  resize: vertical;
  line-height: 1.45;
}

textarea.expanded {
  min-height: 280px;
}

select {
  height: 38px;
  padding: 0 9px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgb(23 100 61 / 12%);
}

textarea.over-limit {
  border-color: var(--error);
  box-shadow: 0 0 0 2px rgb(155 36 27 / 12%);
}

.query-editor-wrap {
  min-width: 0;
}

.query-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.query-meta > span {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.query-meta > span.over-limit {
  color: var(--error);
  font-weight: 600;
}

.query-meta .expand-query {
  min-height: 28px;
  padding: 0 4px;
  color: var(--accent);
  font-size: 12px;
}

.query-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-top: 6px;
}

.query-row .primary {
  align-self: start;
}

button.primary {
  min-width: 96px;
  min-height: 40px;
  padding: 0 15px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: #fff;
  background: var(--accent);
  font-weight: 600;
}

button.primary:hover:not(:disabled) {
  border-color: var(--accent-hover);
  background: var(--accent-hover);
}

.form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(180px, 0.55fr);
  gap: 12px;
  margin-top: 15px;
}

.working {
  margin: -20px 0 28px;
  color: var(--muted);
}

.search-progress,
.job-status-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.search-progress button,
.job-status-heading button {
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--border-dark);
  border-radius: 4px;
  background: var(--surface);
}

.job-status {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1px solid #b9c9bf;
  border-radius: 5px;
  background: #f5faf7;
  font-size: 12px;
}

.job-status.failed {
  border-color: #e0b0aa;
  color: var(--error);
  background: var(--error-bg);
}

.job-status.complete {
  border-color: #a8cab5;
}

.job-status.cancelled {
  border-color: var(--border-dark);
  background: #f7f7f7;
}

.job-progress {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 11px;
}

.job-progress progress {
  width: 100%;
  height: 7px;
  accent-color: var(--accent);
}

.data-panel h2,
.section-heading h2 {
  margin: 0;
  font-size: 17px;
}

.download-grid {
  display: grid;
  grid-template-columns: minmax(170px, 0.7fr) minmax(220px, 1fr) auto;
  align-items: end;
  gap: 10px;
  margin-top: 14px;
}

.collections-section {
  margin-top: 28px;
}

.section-heading {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border-dark);
}

.text-button {
  min-height: 30px;
  padding-right: 0;
  color: var(--accent);
}

.collection-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.collection-info h3 {
  margin: 0 0 4px;
  font-size: 14px;
}

.collection-info p {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
}

.collection-info .collection-warning {
  margin-top: 5px;
  color: #8a5b13;
}

.row-actions {
  display: flex;
  gap: 5px;
}

.row-actions button {
  min-height: 32px;
  padding: 0 9px;
  font-size: 12px;
}

.alert {
  margin: -24px 0 32px;
  padding: 10px 12px;
  border: 1px solid #e0b0aa;
  border-radius: 5px;
  color: var(--error);
  background: var(--error-bg);
  font-size: 13px;
}

.results-section {
  margin: -8px 0 48px;
}

.results-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-dark);
}

.results-heading h2 {
  margin: 0;
  font-size: 17px;
}

.results-heading p {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
}

.result-card {
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}

.result-title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}

.result-card h3 {
  margin: 0;
  font-size: 15px;
  line-height: 1.35;
}

.result-card h3 a {
  color: var(--text);
  text-decoration: none;
}

.result-card h3 a:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* The author reads as part of the heading but should not compete with it. */
.byline {
  color: var(--muted);
  font-weight: 400;
}

.result-score {
  flex: 0 0 auto;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
}

.result-date {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.excerpt {
  margin: 10px 0 0;
  color: #3f3f3f;
  line-height: 1.55;
}

.empty-note {
  margin: 0;
  padding: 28px 0;
  color: var(--muted);
}

footer {
  min-height: 50px;
  display: flex;
  align-items: center;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
}

@media (max-width: 700px) {
  .download-grid {
    grid-template-columns: 1fr 1fr;
  }

  .download-grid .primary {
    grid-column: 1 / -1;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 24px, 920px);
  }

  .site-header {
    min-height: 56px;
    grid-template-columns: 1fr auto;
  }

  .server-state {
    display: none;
  }

  .page-section {
    padding-top: 24px;
  }

  .panel {
    padding: 14px;
  }

  .query-row,
  .form-grid,
  .download-grid,
  .collection-row {
    grid-template-columns: 1fr;
  }

  .download-grid .primary {
    grid-column: auto;
  }

  .query-row .primary,
  .download-grid .primary {
    width: 100%;
  }

  .collection-row {
    gap: 10px;
  }

  .row-actions {
    width: 100%;
  }

  .row-actions button {
    flex: 1;
  }

  .job-status,
  .results-heading {
    grid-template-columns: 1fr;
  }

  .results-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }
}
