/* Reli Store — shared across the report page and the settings page.
   Series palette validated for CVD separation in both modes (ΔE 10.1 / 10.3). */

:root {
  --paper:      #EEF1F4;
  --panel:      #E3E8ED;
  --ink:        #16202B;
  --muted:      #5A6B7A;
  --rule:       #C3CCD5;
  --hairline:   #D5DCE2;
  --slow:       #B4341F;
  --fast:       #00806B;
  --grid:       rgba(22, 32, 43, 0.045);

  --measure:    68ch;
  --step:       clamp(1.6rem, 3.6vw, 2.4rem);
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper:    #131A21;
    --panel:    #1B242D;
    --ink:      #DCE3E9;
    --muted:    #8497A6;
    --rule:     #2C3A45;
    --hairline: #25313B;
    --slow:     #D9573C;
    --fast:     #10A98C;
    --grid:     rgba(220, 227, 233, 0.04);
  }
}

*, *::before, *::after { box-sizing: border-box; }

/* Author `display` rules below beat the UA's [hidden] rule, so any element
   given a display here would keep its box while hidden. Settle it once. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background-color: var(--paper);
  /* Fine measurement grid, like plotting paper. */
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 22px 22px, 22px 22px;
  color: var(--ink);
  font-family: Archivo, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  font-variant-numeric: tabular-nums;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.018em; }
p { margin: 0; }

a { color: inherit; text-decoration-color: var(--rule); text-underline-offset: 2px; }
a:hover { text-decoration-color: currentColor; }

:focus-visible { outline: 2px solid var(--slow); outline-offset: 2px; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------------------------------------------------------------- header -- */

.bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 2rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem clamp(1.25rem, 4vw, 3rem);
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
}

.brand {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  font-size: 1.0625rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  text-decoration: none;
}

/* Two stacked bars: a shelf. Quiet enough not to read as a logo cliché. */
.brand-mark {
  width: 15px;
  height: 15px;
  flex: none;
  border-top: 3px solid var(--slow);
  border-bottom: 3px solid var(--ink);
}

.bar-nav { display: flex; gap: 1.25rem; align-items: center; }
.bar-here { color: var(--muted); font-size: 0.875rem; }

.button-quiet {
  padding: 0.4rem 0.9rem;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
}

.button-quiet:hover { border-color: var(--ink); }

.bar-counts {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  margin: 0;
  font-size: 0.8125rem;
}

.bar-counts div { display: flex; gap: 0.4rem; align-items: baseline; }
.bar-counts dt { color: var(--muted); }
.bar-counts dd { margin: 0; font-weight: 600; }

/* ------------------------------------------------------------------ main -- */

main {
  max-width: 1080px;
  margin: 0 auto;
  padding: clamp(2rem, 5vw, 3.5rem) clamp(1.25rem, 4vw, 3rem) 6rem;
  display: grid;
  gap: clamp(1.75rem, 4vw, 2.75rem);
}

.store-head { display: grid; gap: 0.7rem; }

.store-head h1 {
  max-width: 30ch;
  font-size: var(--step);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.03em;
  text-wrap: balance;
}

.lede { max-width: var(--measure); color: var(--muted); }

.panel { border: 1px solid var(--rule); background: var(--panel); }

.panel-error { padding: 1.5rem; display: grid; gap: 0.5rem; }
.panel-error h2 { font-size: 1.0625rem; color: var(--slow); }
.panel-error p { max-width: var(--measure); font-size: 0.9375rem; }

/* ------------------------------------------------- store: figures & load -- */

.figures {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1px;
  margin: 0;
  border: 1px solid var(--rule);
  background: var(--rule);
}

.figures div { padding: 1rem 1.25rem; background: var(--panel); }
.figures dt { color: var(--muted); font-size: 0.8125rem; }

.figures dd {
  margin: 0.15rem 0 0;
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

#loading { padding: 1.25rem 1.5rem; display: grid; gap: 0.75rem; }

.loading-line {
  height: 3px;
  overflow: hidden;
  background: var(--rule);
}

.loading-fill {
  display: block;
  width: 35%;
  height: 100%;
  background: var(--slow);
  animation: sweep 1.15s ease-in-out infinite;
}

@keyframes sweep {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(386%); }
}

.loading-text { color: var(--muted); font-size: 0.875rem; }

@media (prefers-reduced-motion: reduce) {
  .loading-fill { width: 100%; animation: none; }
}

/* ---------------------------------------------------------- store: table -- */

/* Six columns do not fit a phone. Let the table scroll rather than stretching
   the whole page, and keep it keyboard-reachable. */
.table-wrap { overflow-x: auto; }
.table-wrap:focus-visible { outline: 2px solid var(--slow); outline-offset: 2px; }

table { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }

th, td {
  padding: 0.68rem 0.9rem;
  text-align: left;
  border-bottom: 1px solid var(--hairline);
  vertical-align: baseline;
}

th {
  border-bottom: 1px solid var(--rule);
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 500;
}

th:first-child, td:first-child { padding-left: 0; }
th:last-child, td:last-child { padding-right: 0; }

.num { text-align: right; }
.rank { width: 3.5rem; color: var(--muted); }
tbody tr:hover { background: var(--panel); }

td.name { font-weight: 500; }

td.name .sub {
  display: block;
  color: var(--muted);
  font-weight: 400;
  font-size: 0.8125rem;
}

td.value { font-weight: 600; }

.store-foot {
  display: grid;
  gap: 0.35rem;
  padding-top: 0.5rem;
  color: var(--muted);
  font-size: 0.875rem;
}

.store-foot p { max-width: var(--measure); }

/* -------------------------------------------------------------- settings -- */

.admin-section { display: grid; gap: 1rem; }
.section-head { display: grid; gap: 0.35rem; }
.section-head h2 { font-size: 1.0625rem; }
.section-head p { max-width: var(--measure); color: var(--muted); font-size: 0.875rem; }

.controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.75rem 2.5rem;
  align-items: start;
  padding: 1.5rem;
}

.control { min-width: 0; margin: 0; padding: 0; border: 0; }

.control legend {
  padding: 0;
  margin-bottom: 0.55rem;
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 500;
}

.control-note {
  margin-top: 0.5rem;
  max-width: 46ch;
  color: var(--muted);
  font-size: 0.8125rem;
  line-height: 1.45;
}

.segmented { display: flex; border: 1px solid var(--rule); background: var(--paper); }
.segmented label { position: relative; }

.segmented input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.segmented span {
  display: block;
  padding: 0.5rem 0.9rem;
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}

.segmented label + label span { border-left: 1px solid var(--rule); }
.segmented input:checked + span { background: var(--ink); color: var(--paper); }
.segmented input:focus-visible + span { outline: 2px solid var(--slow); outline-offset: 1px; }

.slider { display: flex; gap: 0.9rem; align-items: center; }

.slider input[type="range"] {
  flex: 1 1 auto;
  min-width: 110px;
  max-width: 240px;
  accent-color: var(--ink);
}

.slider output { min-width: 5.5ch; font-size: 0.875rem; font-weight: 600; }

/* Tick marks from the datalist. Chrome draws them; other browsers ignore the
   list attribute, which costs nothing. */
.slider input[type="range"] { block-size: 1.25rem; }

.control-estimate { font-variant-numeric: tabular-nums; }

/* A latency high enough to make the report page look hung. */
.control-estimate.is-warning { color: var(--slow); font-weight: 500; }

.control-save { display: grid; gap: 0; justify-items: start; align-self: end; }

button {
  padding: 0.55rem 1.4rem;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
}

button:hover:not(:disabled) { background: var(--slow); border-color: var(--slow); }
button:disabled { cursor: progress; opacity: 0.45; }

/* ----------------------------------------------------------------- trace -- */

.trace-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.5rem;
  align-items: center;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--rule);
}

.trace-bar .control-note { margin-top: 0; flex: 1 1 auto; }
.trace { margin: 0; padding: 1.5rem; display: grid; gap: 1.1rem; }
.trace-plot { position: relative; }

#canvas { display: block; width: 100%; height: auto; }

.tooltip {
  position: absolute;
  z-index: 3;
  min-width: 190px;
  max-width: 340px;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--ink);
  background: var(--paper);
  box-shadow: 0 6px 18px rgba(8, 14, 20, 0.18);
  font-size: 0.8125rem;
  line-height: 1.45;
  pointer-events: none;
}

.tooltip .tip-head {
  display: flex;
  gap: 0.5rem;
  justify-content: space-between;
  font-weight: 600;
}

.tooltip .tip-sql {
  margin-top: 0.45rem;
  padding-top: 0.45rem;
  border-top: 1px solid var(--hairline);
  color: var(--muted);
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.75rem;
  line-height: 1.45;
  word-break: break-word;
}

.key { display: flex; flex-wrap: wrap; gap: 0.5rem 2rem; margin: 0; font-size: 0.8125rem; }
.key-item { display: grid; gap: 0.1rem; }
.key dt { display: flex; gap: 0.45rem; align-items: center; font-weight: 500; }
.key dd { margin: 0; color: var(--muted); }

.swatch { width: 10px; height: 10px; flex: none; }
.swatch-slow { background: var(--slow); }
.swatch-fast { background: var(--fast); }
.key-depth dt { color: var(--muted); font-weight: 400; }

.readout-wrap { border-top: 1px solid var(--rule); }

.readout-for {
  padding: 0.75rem 1.5rem 0;
  color: var(--muted);
  font-size: 0.8125rem;
}

.readout {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1px;
  margin: 0.75rem 0 0;
  background: var(--rule);
}

.readout div { padding: 1.1rem 1.5rem; background: var(--panel); }
.readout dt { color: var(--muted); font-size: 0.8125rem; }

.readout dd {
  margin: 0.15rem 0 0;
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.readout dd .unit { font-size: 0.8125rem; font-weight: 500; color: var(--muted); }

/* --------------------------------------------------------------- compare -- */

.bars { display: grid; gap: 0.75rem; }

.bar-row {
  display: grid;
  grid-template-columns: minmax(9rem, auto) 1fr auto;
  gap: 1rem;
  align-items: center;
  font-size: 0.875rem;
}

.bar-row .bar-label { display: flex; gap: 0.5rem; align-items: center; font-weight: 500; }
.bar-row .bar-track { height: 26px; background: var(--panel); }

.bar-row .bar-fill {
  height: 100%;
  min-width: 3px; /* a 21 ms bar beside a 4.5 s one still has to be visible */
  border-radius: 0 4px 4px 0;
  transition: width 420ms cubic-bezier(0.2, 0.7, 0.3, 1);
}

.bar-row[data-series="n+1"] .bar-fill {
  background-color: var(--slow);
  /* Texture doubles as identity where hue is unavailable. */
  background-image: repeating-linear-gradient(
    135deg, rgba(255, 255, 255, 0.22) 0 2px, transparent 2px 6px);
}

.bar-row[data-series="efficient"] .bar-fill { background: var(--fast); }
.bar-row .bar-value { font-weight: 600; font-size: 0.9375rem; }

.compare-note { max-width: var(--measure); color: var(--muted); font-size: 0.875rem; }

/* ------------------------------------------------------------ responsive -- */

@media (max-width: 760px) {
  .figures dd, .readout dd { font-size: 1.3125rem; }
  .bar-row { grid-template-columns: 1fr auto; }
  .bar-row .bar-track { grid-column: 1 / -1; order: 3; }
  td.name .sub { display: none; }
  .rank { width: 2.5rem; }
}

/* On a phone, drop the two columns a shopper is least likely to scan for,
   so the rest fits without sideways scrolling. */
@media (max-width: 560px) {
  .col-city, .col-last { display: none; }
  th, td { padding: 0.6rem 0.55rem; }
}

@media (prefers-reduced-motion: reduce) {
  .bar-row .bar-fill { transition: none; }
}

@media (forced-colors: active) {
  .panel, .segmented, .tooltip, .bar-row .bar-track, .figures { border: 1px solid CanvasText; }
  .bar-row .bar-fill { background: CanvasText !important; }
}
