/*
  Ledger, the Meridian Provisions theme.

  A printed financial report: warm paper, hairline rules doing the separating rather than
  boxes or shadows, serif headings over a sans body, and colour used only where it carries
  meaning. The series palette is not hand-picked, it was validated for lightness band,
  chroma floor, CVD separation, normal-vision separation and surface contrast, in both
  modes independently. Do not substitute a colour here without re-validating.
*/

:root {
  --paper:        #FBF9F4;
  --paper-2:      #F4F0E6;
  --paper-3:      #EDE8DA;
  --ink:          #1C1917;
  --ink-2:        #57534E;
  --ink-3:        #8A8178;
  --rule:         #E5DFD3;
  --rule-strong:  #D3CABA;

  /* Series slots, fixed order. Never cycled, never reassigned by rank. */
  --s1: #B5502C;   /* oxblood */
  --s2: #1A5FB4;   /* blue    */
  --s3: #96690A;   /* ochre   */
  --s4: #0A7D5E;   /* teal    */

  /* Polarity. Direction and label always carry the meaning too, never colour alone. */
  --neg: #B5502C;
  --pos: #0A7D5E;
  --neutral: #57534E;

  --font-serif: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  --font-sans:  'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  --measure: 1120px;
  --gap: 2rem;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper:       #16140F;
    --paper-2:     #201D16;
    --paper-3:     #2A261D;
    --ink:         #F5F1E8;
    --ink-2:       #B8B0A0;
    --ink-3:       #857E70;
    --rule:        #332E25;
    --rule-strong: #463F33;
    --s1: #CB7645;
    --s2: #5A90D4;
    --s3: #AE8A2A;
    --s4: #1F9C79;
    --neg: #CB7645;
    --pos: #1F9C79;
    --neutral: #B8B0A0;
  }
}

:root[data-theme="dark"] {
  --paper:       #16140F;
  --paper-2:     #201D16;
  --paper-3:     #2A261D;
  --ink:         #F5F1E8;
  --ink-2:       #B8B0A0;
  --ink-3:       #857E70;
  --rule:        #332E25;
  --rule-strong: #463F33;
  --s1: #CB7645;
  --s2: #5A90D4;
  --s3: #AE8A2A;
  --s4: #1F9C79;
  --neg: #CB7645;
  --pos: #1F9C79;
  --neutral: #B8B0A0;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: var(--measure); margin: 0 auto; padding: 0 2rem; }

/* ---------------------------------------------------------------- masthead */

.masthead {
  border-bottom: 1px solid var(--rule-strong);
  padding: 2.5rem 0 1.5rem;
  margin-bottom: 3rem;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 2rem;
  flex-wrap: wrap;
}
.masthead h1 {
  font-family: var(--font-serif);
  font-size: 2rem;
  font-weight: 600;
  margin: 0 0 0.25rem;
  letter-spacing: -0.015em;
}
.masthead .sub { color: var(--ink-2); font-size: 0.95rem; margin: 0; }
.masthead .meta {
  text-align: right;
  font-size: 0.8rem;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
  line-height: 1.5;
}

/*
  Data freshness. State is carried by the label text as well as the dot colour, never by
  colour alone, so it survives colour-vision differences and a greyscale print.
*/
.freshness {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 500;
  color: var(--ink-2);
  margin-bottom: 0.15rem;
}
.fresh-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); flex: none; }
.freshness.is-current { color: var(--pos); }
.freshness.is-current .fresh-dot { background: var(--pos); }
.freshness.is-lagging { color: var(--s3); }
.freshness.is-lagging .fresh-dot { background: var(--s3); }
.freshness.is-stale { color: var(--neg); }
.freshness.is-stale .fresh-dot { background: var(--neg); }

.theme-toggle {
  background: none;
  border: 1px solid var(--rule-strong);
  border-radius: 4px;
  color: var(--ink-2);
  font: inherit;
  font-size: 0.78rem;
  padding: 0.3rem 0.7rem;
  cursor: pointer;
  margin-top: 0.5rem;
}
.theme-toggle:hover { border-color: var(--ink-3); color: var(--ink); }

/* ---------------------------------------------------------------- sections */

section { margin: 0 0 4.5rem; scroll-margin-top: 1rem; }

.section-head {
  border-top: 2px solid var(--ink);
  padding-top: 0.85rem;
  margin-bottom: 1.75rem;
}
.section-num {
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}
.section-head h2 {
  font-family: var(--font-serif);
  font-size: 1.55rem;
  font-weight: 600;
  margin: 0.15rem 0 0.5rem;
  letter-spacing: -0.01em;
}
.lede { color: var(--ink-2); max-width: 62ch; margin: 0; font-size: 1rem; }

/* ---------------------------------------------------------------- figures */

.hero {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  flex-wrap: wrap;
  margin: 2rem 0 0.5rem;
}
.hero-value {
  /* Sans, not the serif, a display serif on the hero reads as decoration.
     Proportional figures: tabular at this size makes the number look loose. */
  font-family: var(--font-sans);
  font-size: 4rem;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.03em;
  color: var(--neg);
}
.hero-label { color: var(--ink-2); font-size: 1.05rem; max-width: 30ch; }

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 0;
  margin: 2rem 0;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}
.tile { padding: 1.1rem 1.5rem 1.1rem 0; border-right: 1px solid var(--rule); }
.tile:last-child { border-right: none; }
.tile-label {
  font-size: 0.76rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 0.35rem;
}
.tile-value { font-size: 1.6rem; font-weight: 600; line-height: 1.15; letter-spacing: -0.02em; }
.tile-delta { font-size: 0.85rem; color: var(--ink-2); margin-top: 0.15rem; }
.tile-delta .up   { color: var(--pos); }
.tile-delta .down { color: var(--neg); }

/* ---------------------------------------------------------------- charts */

.figure { margin: 2rem 0; }
.figure-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; margin-bottom: 0.2rem; }
.figure-title { font-family: var(--font-serif); font-size: 1.05rem; font-weight: 600; margin: 0; }
.figure-note { color: var(--ink-3); font-size: 0.83rem; margin: 0 0 1rem; max-width: 70ch; }

.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }

.legend { display: flex; gap: 1.25rem; flex-wrap: wrap; margin: 0.5rem 0 0.9rem; font-size: 0.84rem; color: var(--ink-2); }
.legend-item { display: inline-flex; align-items: center; gap: 0.42rem; }
.legend-key { width: 11px; height: 11px; border-radius: 2px; flex: none; }
.legend-key.line { height: 2px; width: 16px; border-radius: 1px; }

.tbl-toggle {
  background: none;
  border: none;
  border-bottom: 1px solid var(--rule-strong);
  color: var(--ink-3);
  font: inherit;
  font-size: 0.78rem;
  padding: 0 0 1px;
  cursor: pointer;
}
.tbl-toggle:hover { color: var(--ink); border-color: var(--ink-3); }

/* ---------------------------------------------------------------- tables */

table { border-collapse: collapse; width: 100%; font-size: 0.87rem; margin: 0.75rem 0 0; }
caption { text-align: left; color: var(--ink-3); font-size: 0.8rem; padding-bottom: 0.5rem; }
th, td { padding: 0.5rem 0.9rem 0.5rem 0; text-align: left; border-bottom: 1px solid var(--rule); }
th {
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-3);
  font-weight: 500;
  border-bottom: 1px solid var(--rule-strong);
  white-space: nowrap;
}
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.total td { border-top: 1px solid var(--rule-strong); border-bottom: none; font-weight: 600; }
.neg { color: var(--neg); }
.pos { color: var(--pos); }
.muted { color: var(--ink-3); }

.data-table[hidden] { display: none; }

/* ---------------------------------------------------------------- tooltip */

.tip {
  position: fixed;
  pointer-events: none;
  z-index: 40;
  background: var(--paper);
  border: 1px solid var(--rule-strong);
  border-radius: 4px;
  padding: 0.55rem 0.75rem;
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--ink);
  box-shadow: 0 2px 10px rgb(28 25 23 / 0.08);
  max-width: 260px;
  opacity: 0;
  transition: opacity 0.1s;
}
.tip[data-show] { opacity: 1; }
.tip b { font-weight: 600; }
.tip .tip-row { display: flex; justify-content: space-between; gap: 1.25rem; }
.tip .tip-row span:last-child { font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- states */

.loading { padding: 5rem 0; text-align: center; color: var(--ink-3); }
.err {
  border-left: 3px solid var(--neg);
  border-radius: 0;
  padding: 0.85rem 1.1rem;
  background: var(--paper-2);
  color: var(--ink);
  margin: 2rem 0;
}

footer {
  border-top: 1px solid var(--rule-strong);
  margin-top: 4rem;
  padding: 1.75rem 0 4rem;
  color: var(--ink-3);
  font-size: 0.82rem;
}
footer p { margin: 0 0 0.5rem; max-width: 75ch; }
.badge {
  display: inline-block;
  border: 1px solid var(--rule-strong);
  border-radius: 3px;
  padding: 0.1rem 0.45rem;
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-2);
}

@media (max-width: 720px) {
  .wrap { padding: 0 1rem; }
  .hero-value { font-size: 2.75rem; }
  .tile { border-right: none; border-bottom: 1px solid var(--rule); }
  .tiles { border-bottom: none; }
  .masthead .meta { text-align: left; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
