/* Value Harvester. One stylesheet; colours are custom properties with a dark theme. */
:root {
  color-scheme: light dark;
  --bg: #f5f6f8; --surface: #ffffff; --raised: #eef0f4; --line: #d5d9e0;
  --text: #15181d; --muted: #555e6b;
  --accent: #0b5cad; --accent-text: #ffffff; --accent-soft: #dbe9f8;
  --red: #b3261e; --red-soft: #fbe4e2; --green: #17692f; --amber: #8a5300;
  --grid: #e3e6eb; --series-2: #7a8594; --series-3: #a15c00; --series-4: #6b4fa8; --band: rgba(11, 92, 173, 0.14);
  --radius: 8px; --gap: 16px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px; line-height: 1.5;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216; --surface: #171b21; --raised: #1f242c; --line: #343b46;
    --text: #e8ebf0; --muted: #a7b0bd;
    --accent: #7ab8ff; --accent-text: #08121d; --accent-soft: #1d3147;
    --red: #ff9189; --red-soft: #3d1c1a; --green: #77d695; --amber: #f0b45a;
    --grid: #272d36; --series-2: #8d98a8; --series-3: #e0a458; --series-4: #b39df0; --band: rgba(122, 184, 255, 0.16);
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
main { max-width: 1120px; margin: 0 auto; padding: var(--gap) var(--gap) 96px; }
h1 { font-size: 1.5rem; margin: 8px 0 4px; }
h2 { font-size: 1.15rem; margin: 0 0 8px; }
h3 { font-size: 1rem; margin: 16px 0 6px; }
p { margin: 0 0 8px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.num { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.neg, .over { color: var(--red); }
.pos { color: var(--green); }
.hidden, [hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
.noscript { margin: var(--gap); padding: 12px; background: var(--red-soft); color: var(--red); border: 1px solid var(--red); border-radius: var(--radius); }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 8px; top: 8px; background: var(--surface); padding: 8px; z-index: 20; }

/* Navigation: a top bar on a computer, a bottom bar on a phone. */
#nav { background: var(--surface); border-bottom: 1px solid var(--line); }
#nav nav { max-width: 1120px; margin: 0 auto; padding: 0 var(--gap); display: flex; align-items: center; gap: 4px; }
#nav .brand { font-weight: 700; margin-right: auto; padding: 12px 0; }
#nav a { color: var(--text); text-decoration: none; padding: 12px 12px; border-bottom: 3px solid transparent; min-height: 44px; display: inline-flex; align-items: center; }
#nav a[aria-current="page"] { border-bottom-color: var(--accent); color: var(--accent); font-weight: 600; }
@media (max-width: 640px) {
  #nav { position: fixed; bottom: 0; left: 0; right: 0; border-top: 1px solid var(--line); border-bottom: 0; z-index: 10; }
  #nav nav { padding: 0; gap: 0; }
  #nav .brand { display: none; }
  #nav a { flex: 1; justify-content: center; padding: 10px 2px; font-size: 0.8125rem; border-bottom: 0; border-top: 3px solid transparent; }
  #nav a[aria-current="page"] { border-top-color: var(--accent); }
}

/* Surfaces */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--gap); margin: 0 0 var(--gap); min-width: 0; }
.card.action { border-left: 6px solid var(--accent); }
.card.invalid { opacity: 0.72; border-left-color: var(--muted); }
.grid { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.grid > .card { margin: 0; }
.stats { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin: 12px 0 var(--gap); }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.stat b { display: block; font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.banner { padding: 12px; border-radius: var(--radius); margin: 0 0 var(--gap); border: 1px solid var(--line); background: var(--raised); }
.banner.red { background: var(--red-soft); border-color: var(--red); color: var(--red); font-weight: 600; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row.spread { justify-content: space-between; }
.section { margin: 24px 0 8px; }
dl.facts { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin: 8px 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

/* Status: always a word, colour is extra. */
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; border: 1px solid currentColor; font-size: 0.8125rem; font-weight: 600; white-space: nowrap; }
.badge.buy_due { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.badge.armed { color: var(--amber); }
.badge.waiting, .badge.draft, .badge.retired { color: var(--muted); }
.badge.fully_invested, .badge.live { color: var(--green); }
.badge.no_data, .badge.bad { color: var(--red); }

/* Buttons and forms */
button, .button { font: inherit; min-height: 44px; padding: 8px 16px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
button.primary, .button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--red); border-color: var(--red); }
button.link { border: 0; background: none; color: var(--accent); padding: 4px; min-height: 32px; text-decoration: underline; }
button:disabled { opacity: 0.55; cursor: not-allowed; }
button[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); font-weight: 600; }
label, legend { font-weight: 600; display: block; margin-bottom: 4px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin: 0 0 var(--gap); min-width: 0; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--muted); border-radius: 6px; padding: 8px 10px; min-height: 44px; width: 100%; max-width: 100%; }
td > a, li > a { display: inline-block; min-width: 24px; padding: 2px 0; }
input[type="checkbox"], input[type="radio"] { width: 24px; height: 24px; min-height: 0; flex: none; margin: 0 6px 0 0; vertical-align: middle; accent-color: var(--accent); }
textarea { min-height: 96px; }
.field { margin: 0 0 12px; min-width: 0; }
.field .hint { color: var(--muted); font-size: 0.875rem; margin: 2px 0 0; }
.field .error, .form-error { color: var(--red); font-size: 0.9375rem; font-weight: 600; margin: 4px 0 0; }
.field.bad input, .field.bad select, .field.bad textarea { border-color: var(--red); border-width: 2px; }
.choice { display: inline-flex; align-items: center; font-weight: 400; margin: 0 16px 0 0; min-height: 44px; }
.fields { display: grid; gap: 0 12px; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.inline-row { display: grid; gap: 8px; grid-template-columns: 2fr 1fr 1fr auto; align-items: end; margin-bottom: 8px; }
.inline-row.two { grid-template-columns: 1fr 1fr auto; }
.inline-row label { font-weight: 400; font-size: 0.875rem; color: var(--muted); }
dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 0; width: min(640px, calc(100vw - 16px)); max-height: calc(100vh - 16px); }
dialog::backdrop { background: rgba(0, 0, 0, 0.55); }
dialog form, dialog .dialog-body { padding: var(--gap); }
dialog h2 { margin-bottom: 12px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* Tables */
.table-wrap { overflow-x: auto; max-width: 100%; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: 0.875rem; font-weight: 600; white-space: nowrap; }
td.right, th.right { text-align: right; }
tfoot td { font-weight: 700; border-top: 2px solid var(--line); }
tr.voided td { color: var(--muted); text-decoration: line-through; }
tr.voided td.keep { text-decoration: none; }

/* Category bars: plain HTML and CSS (10.6) */
.bars { display: grid; gap: 8px; margin: 8px 0; }
.bar-row { display: grid; grid-template-columns: minmax(96px, 30%) 1fr auto; gap: 8px; align-items: center; font-size: 0.9375rem; }
.bar-row .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { position: relative; height: 16px; background: var(--raised); border-radius: 3px; }
.bar .fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent); border-radius: 3px; min-width: 2px; }
.bar-row.over .fill { background: var(--red); }
.bar .limit { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--text); }
.bar-row .value { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Charts */
figure { margin: 0 0 var(--gap); min-width: 0; }
figcaption { color: var(--muted); font-size: 0.9375rem; margin-top: 6px; }
.chart { width: 100%; min-width: 0; }
.chart .uplot { font-family: inherit; display: flex; flex-direction: column; width: 100%; }
.chart .u-legend { order: -1; text-align: left; font-size: 0.8125rem; margin: 0 0 4px; color: var(--text); display: block; max-width: 100%; white-space: normal; }
.chart .u-legend tbody { display: block; }
.chart .u-legend .u-series { display: inline-block; max-width: 100%; }
.chart .u-legend .u-series th, .chart .u-legend .u-series td { display: inline; white-space: normal; }
.chart .u-legend .no-legend { display: none; }
.chart { overflow: hidden; }
.chart .u-legend th { font-weight: 400; color: var(--text); border: 0; padding: 0; }
.chart .u-legend td { border: 0; padding: 0; }
.chart .u-legend .u-series { padding: 0 10px 0 0; }
.chart .u-legend .u-marker { border-radius: 2px; }
.chart .u-select { background: var(--band); }
.spark .u-legend { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.signin { max-width: 420px; margin: 8vh auto 0; }
.pre { white-space: pre-wrap; font-family: ui-monospace, Consolas, monospace; font-size: 0.875rem; }
@media (max-width: 480px) {
  main { padding: 12px 12px 96px; }
  .inline-row { grid-template-columns: 1fr 1fr; }
  .inline-row.two { grid-template-columns: 1fr 1fr; }
  th, td { padding: 6px 6px; }
}
