@import url('../tokens.css');

/* The root page's language: flat, monochrome, hairline rules. Colour is data only
   (vendor series in the chart, legend and marks); everything else is ink. */

/* Token classes (input → cache read): a monochrome ramp, dark to light on paper. */
:root { --tc-0: #262626; --tc-1: #5C5C5C; --tc-2: #939393; --tc-3: #CFCFCF; }

/* The dot screen behind the boxes and the plot, and the heat map's ink (r g b). */
:root { --dot: #0000000f; --heat-ink: 17 17 17; }

@media (prefers-color-scheme: dark) {
  :root { --tc-0: #EDEDED; --tc-1: #B5B5B5; --tc-2: #7A7A7A; --tc-3: #474747; --dot: #ffffff1a; --heat-ink: 237 237 237; }
}

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

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

body {
  background: var(--bg-app);
  color: var(--text-primary);
  font-family: var(--font-sans);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

a { color: inherit; text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 0.5px; }

/* The root page's focus ring. */
:focus-visible { outline: 2px solid var(--text-primary); outline-offset: 2px; }

/* The root page's layout (style.css .site-wrapper / .site-sidebar), the part a subpage
   needs: from 900px a sticky sidebar beside the column, with root's fluid gutters;
   below, the sidebar stacks on top, short: a small portrait beside name and page. */
.site-wrapper {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  margin: 0 auto;
  max-width: 1200px;
  padding: 0 var(--space-lg);
}

.site-sidebar {
  padding: var(--space-lg) 0 var(--space-md);
  border-bottom: 1px solid var(--border-hairline);
}

.sidebar-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  column-gap: var(--space-md);
}

.sidebar-portrait-link { grid-row: 1 / 3; }

.sidebar-portrait {
  display: block;
  width: 3.5rem;
  height: 3.5rem;
  object-fit: cover;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: var(--bg-subtle);
}

.site-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.site-title a { text-decoration: none; }
.site-title a:hover { text-decoration: underline; }

/* The page's kicker, in root's subtitle handwriting. */
.site-subtitle {
  font-family: var(--font-hand);
  font-size: 0.9rem;
  font-weight: 400;
  line-height: 1.6;
  color: var(--text-secondary);
}

.sidebar-back {
  display: inline-block;
  margin-top: var(--space-md);
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
}

.sidebar-back:hover { text-decoration: underline; }

.sidebar-meta {
  margin-top: var(--space-xs);
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--text-muted);
}

.sidebar-meta:empty { display: none; }

.site-main {
  flex-grow: 1;
  min-width: 0;
  max-width: var(--content-max-width);
  padding: var(--space-lg) 0 var(--space-3xl);
}

@media (min-width: 900px) {
  .site-wrapper {
    --gutter: clamp(36px, 12.791vw - 79.12px, 80px);
    --side-gutter: clamp(24px, 3.4884vw - 7.395px, 36px);
    flex-direction: row;
    max-width: 1244px;
    padding: 0 var(--gutter) 0 var(--side-gutter);
    gap: var(--gutter);
  }
  .site-sidebar {
    width: clamp(240px, 11.628vw + 135.35px, var(--sidebar-width));
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    scrollbar-width: none;
    border-bottom: none;
    border-right: 1px solid var(--border-hairline);
    padding: var(--space-2xl) var(--side-gutter) var(--space-lg) 0;
  }
  .sidebar-header { display: block; }
  .sidebar-portrait { width: 9rem; height: 9rem; margin-bottom: var(--space-md); }
  .site-title { font-size: 1.65rem; margin-bottom: var(--space-xs); }
  .sidebar-back { margin: var(--space-lg) 0 var(--space-md); }
  .sidebar-meta { margin-top: var(--space-sm); }
  .site-main { padding: var(--space-2xl) 0 var(--space-lg); }
}

.note, .status {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: var(--space-sm);
}

.status { margin-top: 0; }
.status.error { color: var(--text-primary); }

.num { font-variant-numeric: tabular-nums; }
.absent { color: var(--text-muted); }

/* Sections: a hairline above, a small uppercase label. */
.block {
  margin-top: var(--space-2xl);
  border-top: 1px solid var(--border-hairline);
  padding-top: var(--space-lg);
}

.block-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-sm);
}

.block-title {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: var(--space-md);
}

/* Tables: root's cv-table look. */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
}

th {
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  text-align: left;
  padding: 0 0 0.4rem;
  border-bottom: 1px solid var(--border-hairline);
}

td {
  padding: 0.6rem 0;
  vertical-align: baseline;
}

th + th, td + td { padding-left: 0.75rem; }
th.r, td.r { text-align: right; }

.date-col {
  width: 92px;
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.title-col { font-weight: 500; }

.detail-col {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: right;
}

tfoot td {
  border-top: 1px solid var(--border-medium);
  font-weight: 500;
}

.sources caption {
  text-align: left;
  font-size: 0.8rem;
  color: var(--text-muted);
  padding-bottom: var(--space-sm);
}

/* Estimates: hairline-boxed, flat. */
.estimates {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border-top: 1px solid var(--border-hairline);
  border-left: 1px solid var(--border-hairline);
}

.estimate {
  border-right: 1px solid var(--border-hairline);
  border-bottom: 1px solid var(--border-hairline);
  padding: 12px 14px 0;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background-image: radial-gradient(circle, var(--dot) 0.8px, transparent 0.9px);
  background-size: 8px 8px;
}

.estimate .label { font-size: 0.75rem; color: var(--text-muted); }
.estimate .row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
/* The headline number in the site's handwriting. */
.estimate .value { font-family: var(--font-hand); font-size: 1.25rem; line-height: 1.6; }
.estimate .day { font-size: 0.8rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.estimate .sub { font-size: 0.75rem; color: var(--text-muted); min-height: 1.2em; }
.estimate svg { display: block; width: 100%; height: 64px; margin-top: 8px; }

/* "paid ≈" in the Total box opens the per-plan split over what follows. */
.paid { display: inline-block; position: relative; }
.paid-toggle {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}
.paid-toggle:hover, .paid.is-open .paid-toggle { color: var(--text-primary); }
.plan-pop {
  display: none;
  position: absolute;
  z-index: 10;
  top: 100%;
  left: -15px;
  width: max-content;
  max-width: min(26rem, calc(100vw - 32px));
  padding: 8px 14px 10px;
  background: var(--bg-app);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-card);
  color: var(--text-primary);
  cursor: auto;
}
.paid.is-open .plan-pop { display: block; }
.plans caption { text-align: left; font-size: 0.75rem; color: var(--text-muted); padding-bottom: 4px; }
.plans td { padding-block: 0.25rem; white-space: nowrap; }
.plans :is(td, th) + :is(td, th) { padding-left: 0.9rem; }
.plans .plan { color: var(--text-muted); white-space: normal; }
.estimate .plans .mark { display: inline-block; width: 12px; height: 12px; margin: 0 4px 0 0; vertical-align: -1px; }

/* Chart */
.tabs { display: flex; gap: 4px; margin-bottom: var(--space-md); }

.tabs button {
  font: inherit;
  font-size: 0.75rem;
  color: var(--text-muted);
  background: none;
  border: 1px solid transparent;
  padding: 2px 8px;
  cursor: pointer;
}

.tabs button:hover { color: var(--text-primary); background: var(--bg-hover); }
.tabs button[aria-pressed="true"] { color: var(--text-primary); border-color: var(--border-strong); font-weight: 600; }

.chart { margin: 0; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid line { stroke: var(--border-hairline); }
.chart .axis { stroke: var(--border-medium); }
.chart .asof { fill: var(--border-hairline); }
.chart text { fill: var(--text-muted); font-size: 10.5px; font-family: var(--font-sans); }

.legend {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 20px;
  margin-top: var(--space-md);
  font-size: 0.8rem;
}

.legend li { display: flex; align-items: baseline; gap: 6px; }
.legend .amount { color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* Vendor marks and the small in-cell graphics. */
.mark { width: 12px; height: 12px; flex: none; align-self: center; vertical-align: -1px; }
.marks { display: inline-flex; gap: 4px; margin-right: 6px; vertical-align: -1px; }
.swatch { width: 10px; height: 10px; flex: none; align-self: center; }

.bar { display: block; height: 2px; margin: 4px 0 0 auto; background: var(--text-primary); }
.mix { display: flex; height: 4px; width: 64px; margin: 4px 0 0 auto; }
.mix span { display: block; height: 100%; }

.models { display: block; font-weight: 400; font-size: 0.75rem; color: var(--text-muted); }

.badge {
  display: inline-block;
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  line-height: 1.5;
  padding: 0 6px;
  border: 1px solid var(--border-medium);
  border-radius: 999px;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* Only an absent figure or a failed source is marked out, and in ink, not a hue. */
.badge.unavailable, .badge.error { border-color: var(--border-strong); border-style: dashed; color: var(--text-primary); }

.more {
  font: inherit;
  font-size: 0.8rem;
  margin-top: var(--space-md);
  background: none;
  border: 1px solid var(--border-medium);
  padding: 4px 10px;
  color: var(--text-primary);
  cursor: pointer;
}

.more:hover { background: var(--bg-hover); }

/* Time scrub zones: the boxes, the plot and the table. A sideways drag scrubs; vertical
   panning stays the page's. */
.scrub { touch-action: pan-y; cursor: ew-resize; overscroll-behavior-x: contain; }
.scrub:focus-visible { outline-offset: 4px; }

/* The heat map: a dot screen masked over a gradient that meets each neighbour's ink at
   the shared edge; the count sits on a label of the page colour. */
td.heat { position: relative; }
td.heat::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to right, rgb(var(--heat-ink) / var(--al)), rgb(var(--heat-ink) / var(--a)) 35%, rgb(var(--heat-ink) / var(--a)) 65%, rgb(var(--heat-ink) / var(--ar)));
  -webkit-mask: radial-gradient(circle, #000 var(--dot-r), transparent calc(var(--dot-r) + 0.4px)) 0 0 / 6px 6px;
  mask: radial-gradient(circle, #000 var(--dot-r), transparent calc(var(--dot-r) + 0.4px)) 0 0 / 6px 6px;
}
td.heat span { position: relative; background: var(--bg-app); padding: 0 0.2em; border-radius: 3px; }
th.heat-col, td.heat-col { white-space: nowrap; }

/* Sources, notices and method */
.provenance {
  margin-top: var(--space-2xl);
  border-top: 1px solid var(--border-hairline);
  padding-top: var(--space-sm);
  font-size: 0.875rem;
}

.provenance summary { cursor: pointer; color: var(--text-muted); font-size: 0.8rem; padding: 4px 0; }
.provenance h3 { font-size: 0.75rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-muted); margin: var(--space-xl) 0 var(--space-sm); }
.provenance p { font-size: 0.8rem; color: var(--text-secondary); margin-top: 6px; max-width: 44rem; }
.notices { list-style: none; font-size: 0.8rem; color: var(--text-secondary); }
.notices li { padding: 6px 0; border-bottom: 1px solid var(--border-hairline); overflow-wrap: anywhere; }
.notices code { font-family: var(--font-mono); font-weight: 600; color: var(--text-primary); }
.notices .level { color: var(--text-muted); }
.sources td { overflow-wrap: anywhere; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; font-size: 0.8rem; }
.facts dt { color: var(--text-muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }

/* The token-class columns fold away on narrow screens; the mix bar under Tokens carries their shares. */
@media (max-width: 700px) { .heat-col { display: none; } }

/* Beside the heat columns, one line per row, so scrubbing never jumps: names shorten
   with an ellipsis (the full list on hover). */
@media (min-width: 701px) {
  .periods .title-col { width: 34%; max-width: 0; }
  .periods .title-col, .periods .models { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}

@media (max-width: 550px) {
  .periods tr, .sources tr { display: flex; flex-wrap: wrap; align-items: baseline; padding: 0.5rem 0; border-bottom: 1px solid var(--border-hairline); }
  .periods thead, .sources thead { display: none; }
  .periods td, .sources td { padding: 1px 0; }
  td + td { padding-left: 0; }
  .periods .date-col { width: auto; flex: 0 0 100%; }
  .periods .title-col { flex: 1 1 100%; }
  .periods td.r, .periods td.detail-col.num, .sources td.r { flex: 1 1 0; text-align: left; }
  .sources td:first-child { flex: 1 1 100%; }
  td[data-label]::before { content: attr(data-label); display: block; font-size: 0.68rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-muted); }
  .bar, .mix { margin-left: 0; }
  tfoot tr { border-top: 1px solid var(--border-medium); }
  tfoot td { border-top: 0; }
  .estimates { grid-template-columns: minmax(0, 1fr); }
}

@media (prefers-reduced-motion: no-preference) {
  .tabs button, .more { transition: var(--transition-fast); }
}

/* Desktop is a dashboard: one screen, no page scroll, so the wheel anywhere is the time
   scrub (usage.js repeats the query); boxes and chart take their height, the table the
   rest, showing the rows that fit from the as-of day down. 1100px: below it the column
   beside the sidebar gets too narrow for four boxes in a row. */
@media (min-width: 1100px) and (min-height: 640px) {
  html, body { height: 100%; overflow: hidden; }
  .site-main { height: 100vh; display: flex; flex-direction: column; padding: var(--space-lg) 0 var(--space-sm); }
  #report:not([hidden]) { flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; }
  #report > * { flex: none; }
  .estimates { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); }
  .estimate svg { height: 40px; }
  .block { margin-top: var(--space-md); padding-top: var(--space-sm); }
  #report > .table-block { flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; }
  #table-scrub { flex: 1 1 0; min-height: 0; overflow: hidden; }
  .periods td { padding-block: 0.35rem; }
  .periods tfoot td { position: sticky; bottom: 0; background: var(--bg-app); }
  .provenance { margin-top: var(--space-xs); }
  .provenance[open] { max-height: 40vh; overflow: auto; }
}
