/* ---------------------------------------------------------------
   Two currencies: money is brass, time is teal.
   Every figure on this site is coloured by which one it belongs to.
   --------------------------------------------------------------- */

:root {
  --paper:      #F1F3F1;
  --paper-2:    #FBFCFB;
  --ink:        #16202B;
  --slate:      #55636E;
  --rule:       #CDD6D1;
  --rule-soft:  #E2E8E4;

  --money:      #9C6528;
  --money-soft: #F0E4D4;
  --time:       #226E66;
  --time-soft:  #DCEAE7;
  --alert:      #97402A;
  --alert-soft: #F6E7E2;
  --sand:       #C39B6B;

  --active-bg:  #16202B;
  --active-fg:  #FBFCFB;
  --btn-bg:     #16202B;
  --btn-fg:     #FBFCFB;
  --btn-hover:  #22303E;

  --display: "Bricolage Grotesque", Georgia, serif;
  --body:    "Public Sans", system-ui, sans-serif;
  --data:    "IBM Plex Mono", ui-monospace, monospace;

  --gap: 1.25rem;
  --radius: 3px;

  color-scheme: light;
}

[data-theme="dark"] {
  --paper:      #10161A;
  --paper-2:    #192126;
  --ink:        #E5EBE7;
  --slate:      #9AA8A4;
  --rule:       #303C43;
  --rule-soft:  #242E34;

  --money:      #D9A05E;
  --money-soft: #33291D;
  --time:       #56B7A9;
  --time-soft:  #1B302D;
  --alert:      #D8785F;
  --alert-soft: #33211C;
  --sand:       #C39B6B;

  --active-bg:  #303C43;
  --active-fg:  #E5EBE7;
  --btn-bg:     #56B7A9;
  --btn-fg:     #10161A;
  --btn-hover:  #6BC6B9;

  color-scheme: dark;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.55;
}

a { color: var(--ink); text-decoration-color: var(--rule); text-underline-offset: 3px; }
a:hover { text-decoration-color: var(--money); }

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

/* ---------------------------------------------------------- layout */

.shell { display: flex; min-height: 100vh; }

.rail {
  width: 232px;
  flex: 0 0 232px;
  border-right: 1px solid var(--rule);
  background: var(--paper-2);
  padding: 1.5rem 1.15rem;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.wordmark {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.2rem;
  line-height: 1.15;
  letter-spacing: -0.02em;
  font-variation-settings: "wdth" 92;
}
.wordmark span { display: block; font-weight: 400; color: var(--slate); font-size: 0.78rem; letter-spacing: 0.04em; text-transform: uppercase; margin-top: 0.35rem; }

.rail nav { display: flex; flex-direction: column; gap: 1px; }
.rail nav a {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0.5rem 0.6rem;
  text-decoration: none;
  border-radius: var(--radius);
  color: var(--slate);
  font-size: 0.92rem;
}
.rail nav a .k { font-family: var(--data); font-size: 0.68rem; opacity: 0.55; }
.rail nav a .ico { display: none; flex: none; }
.rail nav a .ico svg { width: 18px; height: 18px; display: block; }
.rail nav a:hover { background: var(--rule-soft); color: var(--ink); }
.rail nav a[aria-current="page"] { background: var(--active-bg); color: var(--active-fg); }
.rail nav a[aria-current="page"] .k { opacity: 0.7; }

.rail footer { margin-top: auto; font-size: 0.75rem; color: var(--slate); }
.railtools { display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; }
.railmeta { margin: 0.6rem 0 0; }
.brand .mark { display: none; font-family: var(--display); font-weight: 700; font-size: 1.05rem; letter-spacing: -0.02em; }

.icobtn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; flex: none;
  background: transparent; color: var(--slate);
  border: 1px solid var(--rule); border-radius: var(--radius); cursor: pointer;
}
.icobtn:hover { background: var(--rule-soft); color: var(--ink); }
.icobtn svg { width: 14px; height: 14px; }
.icobtn .chev { transition: transform 0.18s ease; }
[data-rail="collapsed"] .icobtn .chev { transform: rotate(180deg); }

/* ---------------------------------------------------------- collapsed rail */

@media (min-width: 1081px) {
  [data-rail="collapsed"] .rail {
    width: 62px; flex: 0 0 62px; padding: 1.5rem 0.55rem; align-items: center;
  }
  [data-rail="collapsed"] .wordmark,
  [data-rail="collapsed"] .rail nav a .label,
  [data-rail="collapsed"] .rail nav a .k,
  [data-rail="collapsed"] .railmeta,
  [data-rail="collapsed"] .theme-toggle .theme-label { display: none; }
  [data-rail="collapsed"] .brand .mark { display: block; text-align: center; }
  [data-rail="collapsed"] .rail nav { width: 100%; }
  [data-rail="collapsed"] .rail nav a { justify-content: center; padding: 0.55rem 0; }
  [data-rail="collapsed"] .rail nav a .ico { display: block; }
  [data-rail="collapsed"] .railtools { flex-direction: column; gap: 0.4rem; }
  [data-rail="collapsed"] .theme-toggle { width: 28px; height: 28px; padding: 0; justify-content: center; }
}
@media (prefers-reduced-motion: no-preference) {
  .rail { transition: width 0.18s ease, flex-basis 0.18s ease; }
}

main { flex: 1; min-width: 0; padding: 2rem 2.25rem 5rem; }
/* Prose keeps a readable measure; tables and charts take the whole window. */
h1, .lede, .note, p { max-width: 78ch; }
h1 { max-width: 24ch; }
.lede { max-width: 70ch; }
.tablewrap, .chartbox, .grid, form.stack, fieldset { max-width: none; }

/* ---------------------------------------------------------- type */

h1 {
  font-family: var(--display);
  font-size: clamp(1.7rem, 3vw, 2.3rem);
  line-height: 1.08;
  letter-spacing: -0.025em;
  font-variation-settings: "wdth" 88;
  margin: 0 0 0.4rem;
  max-width: 22ch;
}

h2 {
  font-family: var(--display);
  font-size: 1.15rem;
  letter-spacing: -0.01em;
  margin: 2.4rem 0 0.75rem;
  font-variation-settings: "wdth" 92;
}

h3 { font-size: 0.95rem; margin: 0 0 0.5rem; }

.lede { color: var(--slate); max-width: 68ch; margin: 0 0 1.75rem; }

.eyebrow {
  font-family: var(--data);
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--slate);
  margin: 0 0 0.6rem;
}

.note { font-size: 0.82rem; color: var(--slate); max-width: 74ch; }

/* the two currencies */
.money { color: var(--money); }
.time  { color: var(--time); }
.alert { color: var(--alert); }

.num { font-family: var(--data); font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------- cards */

.grid { display: grid; gap: var(--gap); }
/* auto-fit never makes more tracks than there are items, so these stay
   semantic while reflowing on narrow screens and filling an ultrawide one. */
.grid.two   { grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); }
.grid.four  { grid-template-columns: repeat(auto-fit, minmax(min(100%, 250px), 1fr)); }

.card {
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem;
}
.card.flush { padding: 0; overflow: hidden; }

.stat { display: flex; flex-direction: column; gap: 0.1rem; }
.stat .label { font-size: 0.78rem; color: var(--slate); }
.stat .value { font-family: var(--data); font-size: 1.5rem; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.stat .sub { font-size: 0.76rem; color: var(--slate); }

.swatch { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 0.4rem; vertical-align: 1px; }

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

.tablewrap { overflow-x: auto; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--paper-2); }

table { border-collapse: collapse; width: 100%; font-size: 0.86rem; }
th, td { padding: 0.5rem 0.75rem; text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; position: sticky; left: 0; background: var(--paper-2); }
thead th {
  font-family: var(--data);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--slate);
  font-weight: 500;
  border-bottom: 1px solid var(--rule);
  vertical-align: bottom;
}
tbody td { border-bottom: 1px solid var(--rule-soft); font-family: var(--data); font-variant-numeric: tabular-nums; }
tbody td:first-child { font-family: var(--body); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.rule-top td { border-top: 1px solid var(--rule); }
tbody tr.emphasis td { font-weight: 600; background: var(--rule-soft); }
tbody tr.emphasis td:first-child { background: var(--rule-soft); }
tr.baseline td:first-child::after {
  content: "baseline";
  font-family: var(--data);
  font-size: 0.6rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--slate);
  margin-left: 0.5rem;
}

/* ---------------------------------------------------------- forms */

form.stack { display: flex; flex-direction: column; gap: 1.25rem; }

fieldset {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1rem 1.15rem 1.15rem;
  background: var(--paper-2);
  margin: 0;
}
legend {
  font-family: var(--data);
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--slate);
  padding: 0 0.4rem;
}

.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 0.85rem; }

label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.78rem; color: var(--slate); }
label .hint { font-size: 0.7rem; color: var(--slate); opacity: 0.85; }

input[type="text"], input[type="number"], input[type="time"], input[type="password"], select, textarea {
  font-family: var(--data);
  font-size: 0.86rem;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 0.4rem 0.5rem;
  width: 100%;
}
textarea { font-size: 0.78rem; line-height: 1.5; min-height: 320px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--time); background: var(--paper-2); }

label.check { flex-direction: row; align-items: center; gap: 0.5rem; font-size: 0.85rem; color: var(--ink); }
label.check input { width: auto; }

.btn {
  font-family: var(--body);
  font-size: 0.86rem;
  font-weight: 600;
  border: 1px solid var(--btn-bg);
  background: var(--btn-bg);
  color: var(--btn-fg);
  padding: 0.5rem 1.05rem;
  border-radius: var(--radius);
  cursor: pointer;
}
.btn:hover { background: var(--btn-hover); border-color: var(--btn-hover); }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--rule); }
.btn.ghost:hover { background: var(--rule-soft); }
.btn.danger { background: transparent; color: var(--alert); border-color: var(--rule); }
.btn.danger:hover { background: var(--alert-soft); }

.actions { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }

.sticky-actions {
  position: sticky;
  bottom: 0;
  background: linear-gradient(to top, var(--paper) 62%, transparent);
  padding: 1rem 0 0.6rem;
  z-index: 5;
}

.flash {
  border-left: 3px solid var(--time);
  background: var(--time-soft);
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
}
.flash.bad { border-left-color: var(--alert); background: var(--alert-soft); }

/* ---------------------------------------------------------- job card */

.job {
  border: 1px solid var(--rule);
  border-left: 4px solid var(--jobcolour, var(--slate));
  border-radius: var(--radius);
  background: var(--paper-2);
  margin-bottom: var(--gap);
}
.job > summary {
  cursor: pointer;
  padding: 0.9rem 1.15rem;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  list-style: none;
}
.job > summary::-webkit-details-marker { display: none; }
.job > summary::before { content: "▸"; color: var(--slate); margin-right: 0.5rem; font-size: 0.75rem; }
.job[open] > summary::before { content: "▾"; }
.job > summary strong { font-size: 0.98rem; }
.job > summary .meta { font-family: var(--data); font-size: 0.76rem; color: var(--slate); }
.job .body { padding: 0 1.15rem 1.15rem; display: flex; flex-direction: column; gap: 1rem; }

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

.chartbox { background: var(--paper-2); border: 1px solid var(--rule); border-radius: var(--radius); padding: 0.6rem; }
.chart { width: 100%; height: 400px; }
.chart.short { height: 300px; }

.legendrow { display: flex; flex-wrap: wrap; gap: 1rem; font-size: 0.8rem; color: var(--slate); margin-top: 0.5rem; }

/* ---------------------------------------------------------- login */

.login-page { display: grid; place-items: center; min-height: 100vh; padding: 1.5rem; }
.login-card { width: 100%; max-width: 340px; }

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

@media (max-width: 1080px) {
  .shell { flex-direction: column; }
  .rail {
    width: auto; flex: none; height: auto; position: static;
    border-right: 0; border-bottom: 1px solid var(--rule);
    flex-direction: row; align-items: center; gap: 1rem; overflow-x: auto;
    padding: 0.85rem 1rem;
  }
  .rail nav { flex-direction: row; gap: 0.25rem; }
  .rail nav a .k { display: none; }
  .rail nav a .ico { display: block; }
  .rail nav a .label { display: none; }
  .rail nav a { padding: 0.45rem 0.6rem; }
  .rail footer { margin: 0; }
  .railmeta { display: none; }
  .brand .mark { display: none; }
  .wordmark { font-size: 1rem; }
  .wordmark span { display: none; }
  main { padding: 1.25rem 1rem 4rem; }
  main { padding: 1.25rem 1rem 4rem; }
  .grid.two, .grid.three, .grid.four { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: no-preference) {
  .card, .job { animation: rise 0.32s ease both; }
  @keyframes rise { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }
}


/* ---------------------------------------------------------- theme toggle */

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--body);
  font-size: 0.75rem;
  color: var(--slate);
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 0.3rem 0.55rem;
  cursor: pointer;
}
.theme-toggle:hover { background: var(--rule-soft); color: var(--ink); }
.theme-toggle svg { width: 13px; height: 13px; flex: none; }
.theme-toggle .sun { display: none; }
[data-theme="dark"] .theme-toggle .sun { display: block; }
[data-theme="dark"] .theme-toggle .moon { display: none; }

html, body { transition: background-color 0.18s ease, color 0.18s ease; }
@media (prefers-reduced-motion: reduce) {
  html, body { transition: none; }
}


/* ---------------------------------------------------------- summary matrix */

.matrix thead th { text-align: right; }
.matrix thead th:first-child { text-align: left; }
.matrix .tag {
  display: inline-block; margin-left: 0.35rem; font-size: 0.58rem; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--slate); border: 1px solid var(--rule);
  border-radius: 2px; padding: 0 0.25rem;
}
td.metric { position: relative; }
td.metric::before {
  content: ""; position: absolute; right: 0; top: 5px; bottom: 5px;
  width: var(--pct, 0%); background: var(--time-soft); border-radius: 2px;
}
td.metric .v { position: relative; }
td.metric.best { font-weight: 600; color: var(--time); }
td.metric.best::before { background: var(--time-soft); box-shadow: inset 0 0 0 1px var(--time); }

.hair { border: 0; border-top: 1px solid var(--rule-soft); margin: 0.9rem 0; }
.stat .of { font-size: 0.9rem; color: var(--slate); }

.linkcard { display: block; text-decoration: none; }
.linkcard:hover { border-color: var(--time); }
.linkcard .eyebrow { color: var(--time); }
