:root {
  color-scheme: dark light;
  --bg: #0d1117;
  --panel: #161b22;
  --panel-border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #58a6ff;
  --good: #3fb950;
  --bad: #f85149;
  --warn: #d29922;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace; font-size: 0.92em; }

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px 28px;
  border-bottom: 1px solid var(--panel-border);
  background: var(--panel);
}

.brand { font-weight: 700; font-size: 16px; color: var(--text); }
.nav { display: flex; gap: 18px; flex: 1; flex-wrap: wrap; }
.nav-link { color: var(--muted); padding-bottom: 2px; }
.nav-link[aria-current="page"] { color: var(--text); border-bottom: 2px solid var(--accent); }

.content { flex: 1; padding: 28px; max-width: 1180px; width: 100%; margin: 0 auto; }
.breadcrumbs { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.crumb-separator { padding: 0 4px; }

h1 { font-size: 22px; margin: 0 0 6px; overflow-wrap: anywhere; }
h2 { font-size: 16px; margin: 0 0 12px; display: flex; align-items: center; gap: 6px; }
.muted { color: var(--muted); }
.lede { color: var(--muted); margin: 0 0 22px; overflow-wrap: anywhere; }
.subtle { color: var(--muted); font-size: 12px; font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace; }
.freshness { font-size: 12px; margin-top: 24px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 18px 20px;
  margin-bottom: 20px;
}

.error-panel { border-color: var(--bad); }

.stat-row { display: flex; flex-wrap: wrap; gap: 16px; margin-bottom: 20px; }

.stat-card {
  position: relative;
  flex: 1 1 220px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 16px 18px;
}

.stat-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-size: 26px; font-weight: 600; margin-top: 6px; }
.stat-value.good { color: var(--good); }
.stat-value.bad { color: var(--bad); }
.stat-value.warn { color: var(--warn); }
.stat-note { color: var(--muted); font-size: 12px; margin-top: 6px; }

.info {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid var(--muted);
  color: var(--muted);
  font-size: 11px;
  font-style: italic;
  font-weight: 700;
  cursor: help;
  flex: none;
}

.stat-card .info { position: absolute; top: 12px; right: 12px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--panel-border); vertical-align: top; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
tbody tr:last-child td { border-bottom: none; }
td.numeric, th.numeric { text-align: right; font-variant-numeric: tabular-nums; }

.table-wrap { overflow-x: auto; }

.timestamp { display: flex; flex-direction: column; cursor: help; }
.timestamp-relative { color: var(--text); font-weight: 600; white-space: nowrap; }
.timestamp-precise { color: var(--muted); font-size: 12px; white-space: nowrap; }
.timestamp-unparsed .timestamp-relative { color: var(--warn); font-weight: 600; }

/*
 * A truncated cell is marked as truncated. Without the dotted underline the ellipsis is the only
 * hint that there is more text, and an ellipsis inside prose reads as part of the text itself.
 */
.preview { font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace; font-size: 12.5px; overflow-wrap: anywhere; }
.preview-truncated { cursor: help; border-bottom: 1px dotted var(--panel-border); }

.document-text {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: 12.5px;
  background: var(--bg);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 12px 14px;
  margin: 0;
  max-height: 460px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.empty { color: var(--muted); padding: 18px 0; }
.report-list { margin: 8px 0 0; padding-left: 18px; }
.report-list li { margin-bottom: 4px; }
.report-failure { color: var(--bad); }

.search-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin-bottom: 14px; }
.search-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.search-query { flex: 1 1 420px; }
.search-limit { flex: 0 0 auto; }

input[type="text"], select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 8px 10px;
  font: inherit;
  width: 100%;
}

button {
  font: inherit;
  font-weight: 600;
  border-radius: 6px;
  padding: 8px 14px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

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

.pager { display: flex; align-items: center; gap: 18px; margin-top: 14px; font-size: 13px; }
.pager-position { color: var(--muted); }
.pager-end { color: var(--muted); opacity: 0.45; }

/*
 * The documents-per-bucket chart. Colours come from CSS rather than fill attributes so the chart
 * follows the theme; the geometry stays in SVG attributes because style-src forbids inline styles,
 * so a bar sized by a style attribute would silently render at zero.
 */
.histogram { display: block; max-width: 100%; height: auto; }
.histogram text { dominant-baseline: middle; }
.hist-label { fill: var(--muted); font-size: 12px; }
.hist-count { fill: var(--text); font-size: 12px; font-weight: 600; }
.hist-track { fill: var(--bg); stroke: var(--panel-border); stroke-width: 1; }
.hist-bar { fill: var(--accent); }

.footer {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  padding: 14px 28px;
  border-top: 1px solid var(--panel-border);
  color: var(--muted);
  font-size: 12px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #ffffff;
    --panel: #f6f8fa;
    --panel-border: #d0d7de;
    --text: #1f2328;
    --muted: #656d76;
    --accent: #0969da;
    --good: #1a7f37;
    --bad: #cf222e;
    --warn: #9a6700;
  }
}