:root {
  --ink: #1b1f23;
  --ink-2: #4a535c;
  --muted: #6b747d;
  --line: #dde1e5;
  --line-soft: #eef0f2;
  --paper: #f6f5f2;
  --card: #ffffff;
  --accent: #c8561a;
  --accent-soft: #f8e7dc;
  --sister: #2d5f9a;
  --bar: #a9b1b8;
  --ok: #2e7d4f;
  --warn: #b3261e;
  --radius: 6px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.5 var(--font); color: var(--ink); background: var(--paper); }
a { color: var(--sister); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
code { overflow-wrap: anywhere; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.topbar { background: var(--ink); color: #fff; }
.topbar__inner { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 24px; min-height: 56px; padding-top: 8px; padding-bottom: 8px; }
.brandmark { color: #fff; text-decoration: none; font-weight: 700; }
.brandmark span { font-weight: 400; color: #c9ced3; margin-left: 8px; }
.nav { display: flex; flex-wrap: wrap; gap: 4px; }
.nav a { color: #e6e9ec; text-decoration: none; padding: 6px 10px; border-radius: var(--radius); }
.nav a:hover { background: #2c3237; }
.nav a[aria-current="page"] { background: #2c3237; color: #fff; box-shadow: inset 0 -2px 0 var(--accent); }
.account { margin-left: auto; display: flex; align-items: center; gap: 14px; font-size: 14px; }
.account form { margin: 0; }
.account a, .linkbtn { color: #c9ced3; }
.linkbtn { background: none; border: 0; padding: 0; font: inherit; text-decoration: underline; cursor: pointer; }

main.wrap { padding-top: 24px; padding-bottom: 32px; }
.page-head { margin-bottom: 20px; }
.eyebrow { margin: 0; color: var(--accent); font-weight: 600; font-size: 13px; letter-spacing: .04em; text-transform: uppercase; }
h1 { margin: 4px 0 0; font-size: 26px; line-height: 1.25; }
h2 { margin: 0 0 4px; font-size: 18px; }
.lede { margin: 6px 0 0; color: var(--ink-2); max-width: 70ch; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; }
.anchored { scroll-margin-top: 16px; }
.panel__sub, .muted { color: var(--muted); }
.panel__sub { margin: 0 0 16px; font-size: 14px; }
.empty { background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); padding: 20px; color: var(--ink-2); }
.provenance { font-size: 13px; color: var(--muted); max-width: 90ch; }
.error { color: var(--warn); }

.periods { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.chip { display: inline-block; padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); color: var(--ink-2); text-decoration: none; font-size: 14px; }
.chip[aria-current="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 20px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.tile__label { margin: 0; color: var(--ink-2); font-size: 13px; }
.tile__value { margin: 2px 0; font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile__note { margin: 0; color: var(--muted); font-size: 13px; }

.scroll { overflow-x: auto; position: relative; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
thead th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; vertical-align: bottom; }
tbody th { font-weight: 500; }
.num { text-align: right; white-space: nowrap; }

/* Sortable column headers (static/js/tables.js). */
th .sort { all: unset; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
th .sort:hover { color: var(--ink); }
th .sort:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
th .sort::after { content: "\2195"; opacity: .35; font-size: 11px; }
th[aria-sort="ascending"] .sort::after { content: "\2191"; opacity: 1; }
th[aria-sort="descending"] .sort::after { content: "\2193"; opacity: 1; }
.tablesearch { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 0 0 12px; }
.tablesearch label { font-size: 14px; font-weight: 600; }
.tablesearch input { padding: 7px 10px; border: 1px solid #b9c0c6; border-radius: 4px; font: inherit; width: 220px; max-width: 100%; }
.tablesearch[hidden] { display: none; }

.ranking th, .ranking td { padding: 3px 8px; border-bottom-color: var(--line-soft); vertical-align: middle; }
.barcell { width: 45%; }
/* Neutral grey marks "everyone else"; every bar's value is printed in its row. */
.bar { display: block; height: 12px; background: var(--bar); border-radius: 0 4px 4px 0; min-width: 2px; }
.ranking__row--client th, .ranking__row--client td { background: var(--accent-soft); font-weight: 700; }
.ranking__row--client .bar { background: var(--accent); }
.ranking__row--sister th { font-weight: 700; }
.ranking__row--sister .bar { background: var(--sister); }

.minibar { display: inline-block; vertical-align: middle; width: 80px; height: 8px; background: var(--line-soft); border-radius: 2px; margin-right: 6px; }
.minibar > span { display: block; height: 100%; background: var(--accent); border-radius: 0 4px 4px 0; }
.minibar--neutral > span { background: var(--bar); }
.trend--up { color: var(--ok); }
.trend--down { color: var(--warn); }
.trend--flat { color: var(--muted); }

.rivals tr.is-client th, .rivals tr.is-client td { background: var(--accent-soft); }
.rivals tbody th { white-space: nowrap; }
.rivals .textcell { min-width: 200px; }
.compact { width: auto; min-width: 320px; }
.fam { text-align: center; width: 48px; }
.dot { color: var(--ink); }
.nodot { color: #c3c8cd; }

.facts { display: grid; grid-template-columns: 180px 1fr; gap: 12px 16px; margin: 0; }
.facts dt { color: var(--muted); font-size: 14px; }
.facts dd { margin: 0; }
.source { display: block; font-size: 13px; color: var(--muted); }

.filters { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 10px; }
.item { padding: 14px 0; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item__meta { margin: 0; font-size: 13px; color: var(--muted); }
.item__title { margin: 4px 0; font-size: 16px; }
.item p { margin: 4px 0; }
.tag { display: inline-block; padding: 1px 6px; border-radius: 4px; background: var(--line-soft); color: var(--ink-2); font-size: 12px; }
.pager { display: flex; gap: 12px; align-items: center; margin-top: 16px; }

.signin { width: 100%; max-width: 400px; margin: 48px auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 28px; }
.signin label { display: block; margin: 14px 0 4px; font-weight: 600; font-size: 14px; }
.signin input[type=text], .signin input[type=password] { width: 100%; padding: 9px 10px; border: 1px solid #b9c0c6; border-radius: 4px; font: inherit; }
button.primary { margin-top: 18px; width: 100%; padding: 10px; background: var(--ink); color: #fff; border: 0; border-radius: 4px; font: inherit; font-weight: 600; cursor: pointer; }
.footer { padding-bottom: 32px; font-size: 13px; color: var(--muted); }

/* Signed-out pages: centre the card on the screen and the footer under it. */
body.signed-out { min-height: 100vh; display: flex; flex-direction: column; }
body.signed-out main.wrap { flex: 1; width: 100%; display: flex; align-items: center; justify-content: center; }
body.signed-out .signin { margin: 24px auto; }
body.signed-out .footer { width: 100%; text-align: center; }

@media (max-width: 640px) {
  h1 { font-size: 22px; }
  .panel { padding: 14px; }
  .tiles { grid-template-columns: 1fr 1fr; gap: 8px; }
  .tile { padding: 10px 12px; }
  .tile__value { font-size: 22px; }
  .compact { min-width: 0; width: 100%; }
  .account { margin-left: 0; }
  .barcell { width: 30%; }
  .facts { grid-template-columns: 1fr; gap: 2px; }
  .facts dd { margin-bottom: 12px; }
  .signin { margin: 24px auto; padding: 20px; }
}

/* ---- Messages (all pages) ---- */
.messages { list-style: none; margin: 0 0 16px; padding: 0; }
.message { padding: 10px 14px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--card); margin-bottom: 8px; }
.message--success { border-color: #b9dcc6; background: #eef7f1; color: #1f5c39; }
.message--error { border-color: #ecc3bf; background: #fdf3f2; color: #8f1f18; }
.message--info, .message--warning { border-color: #c4d5ea; background: #eff4fa; color: #234b79; }

/* ---- Staff area ---- */
.count { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--accent); color: #fff; font-size: 12px; line-height: 20px; text-align: center; font-weight: 600; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tab { padding: 8px 12px; color: var(--ink-2); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.inline-form { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 14px; }
.inline-form select { padding: 6px 8px; border: 1px solid #b9c0c6; border-radius: 4px; font: inherit; background: var(--card); }
form.inline { display: inline; }

.btn { display: inline-block; padding: 7px 14px; border: 1px solid #b9c0c6; border-radius: 4px; background: var(--card); color: var(--ink); font: inherit; font-size: 14px; text-decoration: none; cursor: pointer; line-height: 1.3; }
.btn:hover { border-color: var(--ink-2); }
.btn--primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn--primary:hover { background: #2c3237; }
.btn--ok { border-color: var(--ok); color: var(--ok); }
.btn--warn { border-color: var(--warn); color: var(--warn); }
.btn--small { padding: 3px 9px; font-size: 13px; }
.btn[disabled], fieldset[disabled] .btn { opacity: .5; cursor: not-allowed; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--line-soft); color: var(--ink-2); }
.badge--approved, .badge--succeeded { background: #e3f1e8; color: var(--ok); }
.badge--rejected, .badge--failed { background: #f8e3e1; color: var(--warn); }
.badge--pending, .badge--queued, .badge--partial { background: #fbeedd; color: #8a4b12; }
.badge--running { background: #e1ebf6; color: var(--sister); }

.bulkbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 10px; }
.review .itemcell { min-width: 260px; max-width: 520px; }
.review .sourcecell { max-width: 220px; overflow-wrap: anywhere; font-size: 14px; }
td.actions { white-space: nowrap; }
td.actions .btn, td.actions form { margin: 0 2px 4px 0; }

.form-panel { max-width: 760px; }
fieldset.plain { border: 0; margin: 0; padding: 0; min-width: 0; }
.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.field--check { display: flex; align-items: center; gap: 8px; }
.field--check label { display: inline; font-weight: 500; margin: 0; }
.field input[type=text], .field input[type=email], .field input[type=password], .field input[type=url],
.field input[type=date], .field input[type=number], .field select, .field textarea {
  width: 100%; max-width: 520px; padding: 8px 10px; border: 1px solid #b9c0c6; border-radius: 4px; font: inherit; background: var(--card);
}
.field--error input, .field--error select, .field--error textarea { border-color: var(--warn); }
.help { margin: 4px 0 0; font-size: 13px; color: var(--muted); }
.help ul { margin: 4px 0 0; padding-left: 18px; }
.form-errors { border: 1px solid #ecc3bf; background: #fdf3f2; color: #8f1f18; border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px; }
.form-errors p, .form-errors ul { margin: 4px 0; }
.form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 8px; }

.twocol { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 20px; }
.twocol .panel { margin-bottom: 20px; }
.log { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; line-height: 1.5; background: var(--paper); border: 1px solid var(--line); border-radius: 4px; padding: 12px; max-height: 480px; overflow: auto; margin: 0 0 10px; }
