:root {
  color-scheme: light;
  --bg: #f4f6f4;
  --card: #ffffff;
  --text: #1c211c;
  --muted: #5d675e;
  --line: #d9e0d8;
  --accent: #0f6b4c;
  --accent-ink: #ffffff;
  --danger: #a12626;
  --flash: #e7f5ee;
  --error: #fdecec;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

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

header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  min-height: 3.5rem;
  padding: 0.65rem 1.25rem;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

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

nav {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}

nav a {
  color: var(--text);
  text-decoration: none;
}

nav a.active { color: var(--accent); font-weight: 650; }

nav form { display: flex; margin: 0; }

.who {
  color: var(--muted);
  margin-left: 0.25rem;
  padding-left: 0.75rem;
  border-left: 1px solid var(--line);
}

main {
  max-width: 76rem;
  margin: 0 auto;
  padding: 1.25rem;
}

.card, .auth {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem 1.1rem;
}

.auth {
  max-width: 24rem;
  margin: 4rem auto;
}

h1 { font-size: 1.4rem; margin: 0 0 0.75rem; }

h2 { font-size: 1.05rem; margin: 1.4rem 0 0.55rem; }

.card h2:first-child { margin-top: 0; }

p { margin: 0.4rem 0 0.8rem; }

.narrow { max-width: 42rem; }

label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.92rem;
  margin-bottom: 0.75rem;
}

input, select, button {
  font: inherit;
}

input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), select {
  display: block;
  width: 100%;
  max-width: 100%;
  height: 2.25rem;
  min-height: 2.25rem;
  margin: 0;
  padding: 0 0.55rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background-color: #fff;
  line-height: calc(2.25rem - 2px);
  box-sizing: border-box;
}

select {
  -webkit-appearance: none;
  appearance: none;
  padding-right: 1.75rem;
}

label:has(select) { position: relative; }

label:has(select)::after {
  content: "";
  position: absolute;
  right: 0.75rem;
  bottom: 0.85rem;
  width: 0.4rem;
  height: 0.4rem;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  pointer-events: none;
}

input[type="checkbox"], input[type="radio"] {
  width: 1rem;
  height: 1rem;
  margin: 0;
  accent-color: var(--accent);
}

button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.25rem;
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  text-decoration: none;
  cursor: pointer;
  line-height: 1.2;
}

button.secondary, .button.secondary {
  background: #fff;
  color: var(--text);
  border-color: var(--line);
}

button.danger {
  background: #fff;
  color: var(--danger);
  border-color: var(--danger);
}

.row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.filters {
  display: grid;
  grid-template-columns: minmax(0, 16rem) minmax(0, 16rem) auto;
  justify-content: start;
  align-items: end;
  gap: 0.75rem 1rem;
  width: 100%;
  margin-bottom: 1rem;
}

.filters label {
  width: auto;
  max-width: none;
  min-width: 0;
  margin: 0;
}

.filters select,
.filters input {
  width: 100%;
  min-width: 0;
}

.flash, .error {
  padding: 0.6rem 0.75rem;
  border-radius: 6px;
  overflow-wrap: anywhere;
}

.flash { background: var(--flash); }
.error { background: var(--error); color: var(--danger); }

.muted { color: var(--muted); }

.field-hint {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.3;
}
.table-wrap {
  overflow-x: auto;
  margin-top: 0.5rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: transparent;
}

table.metrics { min-width: 62rem; }

.nowrap, .ip, td.labels code { white-space: nowrap; }

th, td {
  text-align: left;
  padding: 0.45rem 0.55rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th { font-size: 0.85rem; color: var(--muted); font-weight: 650; }

.table-wrap > table > thead > tr > th:first-child,
.table-wrap > table > tbody > tr > td:first-child { padding-left: 0.8rem; }

.table-wrap > table > thead > tr > th:last-child,
.table-wrap > table > tbody > tr > td:last-child { padding-right: 0.8rem; }

.table-wrap > table > tbody > tr:last-child > td { border-bottom: 0; }

.type {
  display: inline-block;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  background: var(--flash);
  color: var(--accent);
  font-size: 0.82rem;
}

.metric-help {
  display: block;
  max-width: 22rem;
  color: var(--muted);
  font-size: 0.82rem;
}

table.sample {
  width: auto;
  background: transparent;
}

table.sample th,
table.sample td {
  border: 0;
  padding: 0.05rem 0.55rem 0.05rem 0;
  white-space: nowrap;
  font-weight: 500;
}

table.sample th { color: var(--muted); }

code, pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.88rem;
}

pre {
  max-width: 100%;
  padding: 0.7rem;
  background: #f7f8f7;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow-x: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.rule {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 10.5rem) auto;
  gap: 0.5rem;
  align-items: end;
  margin-bottom: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--line);
}

.rule:last-child { margin-bottom: 0; padding-bottom: 0; border-bottom: 0; }

.rule label { margin: 0; min-width: 0; }

.rule button { justify-self: start; }

.check {
  flex-direction: row;
  align-items: center;
  gap: 0.45rem;
}

.actions { display: flex; gap: 0.4rem; align-items: end; }

.inline { display: flex; gap: 0.4rem; align-items: center; }
.inline label { margin: 0; }
.inline input { width: 12rem; max-width: 100%; }

.danger-zone {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.tabs {
  display: flex;
  gap: 0.25rem;
  margin: 0 0 1rem;
  border-bottom: 1px solid var(--line);
}

.tabs a {
  padding: 0.45rem 0.75rem;
  margin-bottom: -1px;
  border-bottom: 2px solid transparent;
  color: var(--text);
  text-decoration: none;
}

.tabs a.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 650;
}

.query-form {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 10rem) minmax(0, 12rem) minmax(0, 8rem) auto;
  gap: 0.75rem 1rem;
  align-items: end;
  margin-bottom: 1rem;
}

.query-form label,
.query-form fieldset,
.query-form .end-now,
.query-form .run {
  margin: 0;
}

.query-form .span { grid-column: 1 / -1; }

.query-form textarea {
  width: 100%;
  min-height: 5.5rem;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.88rem;
  resize: vertical;
}

.query-form fieldset.display {
  border: 0;
  padding: 0;
  min-width: 0;
}

.query-form fieldset.display legend {
  padding: 0;
  margin-bottom: 0.25rem;
  font-size: 0.92rem;
}

.query-form .end-now,
.query-form .run {
  display: flex;
  align-items: end;
}

.query-chart {
  width: 100%;
  height: 280px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.legend {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0.75rem 0.9rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.legend li {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  margin: 0.25rem 0;
}

.swatch {
  width: 0.85rem;
  height: 0.85rem;
  margin-top: 0.2rem;
  border-radius: 2px;
  flex: 0 0 auto;
}

.swatch.series-0 { background: #1f77b4; }
.swatch.series-1 { background: #ff7f0e; }
.swatch.series-2 { background: #2ca02c; }
.swatch.series-3 { background: #d62728; }
.swatch.series-4 { background: #9467bd; }
.swatch.series-5 { background: #8c564b; }
.swatch.series-6 { background: #e377c2; }
.swatch.series-7 { background: #17becf; }

.query-chart .series-0 { stroke: #1f77b4; }
.query-chart .series-1 { stroke: #ff7f0e; }
.query-chart .series-2 { stroke: #2ca02c; }
.query-chart .series-3 { stroke: #d62728; }
.query-chart .series-4 { stroke: #9467bd; }
.query-chart .series-5 { stroke: #8c564b; }
.query-chart .series-6 { stroke: #e377c2; }
.query-chart .series-7 { stroke: #17becf; }

.query-chart polyline {
  fill: none;
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.query-chart text {
  fill: var(--muted);
  font-size: 11px;
  font-family: ui-sans-serif, system-ui, sans-serif;
}

.doc-layout {
  display: grid;
  grid-template-columns: 14rem minmax(0, 1fr);
  gap: 1.5rem;
  align-items: start;
}

nav.doc-nav {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.15rem;
  position: sticky;
  top: 1rem;
}

nav.doc-nav a {
  padding: 0.35rem 0.6rem;
  border-radius: 6px;
}

nav.doc-nav a.active { background: var(--flash); }

.doc h1 { margin-top: 0; }
.doc h2 { margin: 1.4rem 0 0.4rem; }
.doc p, .doc ul, .doc ol { max-width: 46rem; }
.doc :not(pre) > code {
  padding: 0.05rem 0.3rem;
  background: #f7f8f7;
  border: 1px solid var(--line);
  border-radius: 4px;
}
.doc table { background: var(--card); }
.doc th, .doc td { border: 1px solid var(--line); }

@media (max-width: 700px) {
  header { align-items: flex-start; flex-direction: column; }
  .filters, .query-form, .doc-layout { grid-template-columns: minmax(0, 1fr); }
  nav.doc-nav { position: static; flex-direction: row; flex-wrap: wrap; }
  .rule { grid-template-columns: 1fr; }
  .inline input { width: auto; flex: 1 1 8rem; min-width: 0; }
}
