/* Relay Billing. A ledger-like workbench: grey page, white working surface, slate ink, ruled tables.
   The one loud element is the freshness strip; everything else stays quiet. */
@font-face { font-family: "Public Sans"; font-weight: 400; font-display: swap; src: url("fonts/public-sans-400.woff2") format("woff2"); }
@font-face { font-family: "Public Sans"; font-weight: 500; font-display: swap; src: url("fonts/public-sans-500.woff2") format("woff2"); }
@font-face { font-family: "Public Sans"; font-weight: 600; font-display: swap; src: url("fonts/public-sans-600.woff2") format("woff2"); }
@font-face { font-family: "Public Sans"; font-weight: 700; font-display: swap; src: url("fonts/public-sans-700.woff2") format("woff2"); }

:root {
  --page: #EEF1F4;
  --surface: #FFFFFF;
  --ink: #1D2733;
  --ink-soft: #4A5868;
  --rule: #C9D3DD;
  --rule-soft: #E2E8EE;
  --focus: #2F5DA8;
  --new: #2F5DA8;      --new-bg: #E7EEF9;
  --progress: #8A5A00; --progress-bg: #FBF0D9;
  --waiting: #5D4596;  --waiting-bg: #EEE9F7;
  --done: #2F6B47;     --done-bg: #E3F1E8;
  --alert: #B3261E;    --alert-bg: #FBE9E7;
  --radius: 4px;
  --step: 1rem;
  font-family: "Public Sans", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--page);
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
a { color: var(--new); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
h1, h2, h3 { margin: 0 0 .5rem; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; margin-top: 1.25rem; }
.muted { color: var(--ink-soft); }
.fineprint { color: var(--ink-soft); font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.loading, .empty { padding: 2rem var(--step); color: var(--ink-soft); }

/* Header */
.top { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .6rem var(--step); background: var(--ink); color: #fff; }
.brand { display: flex; align-items: baseline; gap: .9rem; }
.brand-name { font-weight: 700; font-size: 1.05rem; }
.tenant, .top select { color: #D5DEE8; font: inherit; }
.top select { background: transparent; border: 1px solid #5A6878; border-radius: var(--radius); padding: .15rem .4rem; }
.who { display: flex; align-items: center; gap: .75rem; font-size: .92rem; }
.role { color: #B9C6D3; }
.top .button-quiet { color: #fff; border-color: #5A6878; }

/* Freshness strip: one tile per business unit, its state readable without color. */
.freshness { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); border-bottom: 1px solid var(--rule); background: var(--surface); }
.freshness-empty { padding: .75rem var(--step); margin: 0; }
.fresh { padding: .7rem var(--step) .75rem; border-left: 6px solid var(--done); }
.fresh + .fresh { border-top: 0; }
.fresh-unit strong { font-size: 1.05rem; }
.fresh-unit span { color: var(--ink-soft); }
.fresh-state { font-weight: 600; margin-top: .1rem; }
.fresh-detail { font-size: .88rem; color: var(--ink-soft); }
.fresh-current { border-left-color: var(--done); }
.fresh-current .fresh-state { color: var(--done); }
.fresh-overdue { border-left-color: var(--progress); background: var(--progress-bg); }
.fresh-overdue .fresh-state { color: var(--progress); }
.fresh-failed_since_last_success { border-left-color: var(--alert); background: var(--alert-bg); }
.fresh-failed_since_last_success .fresh-state { color: var(--alert); }
.fresh-never_run { border-left-color: var(--rule); }
.fresh-error { display: block; color: var(--alert); }

/* Section tabs */
.tabs { display: flex; gap: 0; padding: 0 var(--step); background: var(--surface); border-bottom: 1px solid var(--rule); overflow-x: auto; }
.tab { padding: .7rem .9rem .6rem; color: var(--ink-soft); text-decoration: none; border-bottom: 3px solid transparent; white-space: nowrap; }
.tab:hover { color: var(--ink); }
.tab-active { color: var(--ink); font-weight: 600; border-bottom-color: var(--ink); }

.view { padding: var(--step); }
.view:focus { outline: none; }

/* Filters and counts */
.queue-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: .75rem 1.5rem; margin-bottom: .75rem; }
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .6rem .9rem; }
.field { display: flex; flex-direction: column; gap: .2rem; }
.field-label { font-size: .82rem; color: var(--ink-soft); }
input, select, textarea, .button { font: inherit; color: var(--ink); }
input:not([type=checkbox]), select, textarea { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: .35rem .5rem; min-height: 2.1rem; }
textarea { resize: vertical; }
.counts { display: flex; gap: 1.1rem; margin: 0; font-variant-numeric: tabular-nums; }
.counts span:first-child { font-weight: 600; }

/* Buttons */
.button { display: inline-flex; align-items: center; justify-content: center; min-height: 2.1rem; padding: .35rem .85rem; border-radius: var(--radius); border: 1px solid var(--rule); background: var(--surface); cursor: pointer; text-decoration: none; }
.button:hover { border-color: var(--ink-soft); }
.button[disabled] { opacity: .55; cursor: progress; }
.button-primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.button-primary:hover { background: #33404F; }
.button-quiet { background: transparent; }
.button-small { min-height: 1.7rem; padding: .1rem .5rem; font-size: .88rem; }

/* Tables: ruled like a ledger */
.grid { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--rule); }
.grid th { white-space: nowrap; position: sticky; top: 0; z-index: 1; background: #F6F8FA; text-align: left; font-weight: 600; font-size: .85rem; color: var(--ink-soft); padding: .5rem .65rem; border-bottom: 1px solid var(--rule); }
.grid td { padding: .5rem .65rem; border-bottom: 1px solid var(--rule-soft); vertical-align: top; }
.grid tbody tr { cursor: pointer; }
.grid tbody tr:hover td { background: #F4F7FA; }
.grid tbody tr.row-selected td { background: var(--new-bg); }
.person { font-weight: 600; }
.ident { font-size: .86rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; white-space: nowrap; }
.person { white-space: nowrap; }
.change { font-size: .82rem; color: var(--alert); font-weight: 600; }
.change-quiet { color: var(--ink-soft); font-weight: 400; }
.overdue { color: var(--alert); font-weight: 600; }

/* Status pills: color plus words, never color alone */
.status-cell { display: inline-flex; flex-wrap: wrap; gap: .3rem; }
.pill { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .82rem; font-weight: 600; white-space: nowrap; }
.pill-new { color: var(--new); background: var(--new-bg); }
.pill-in_progress { color: var(--progress); background: var(--progress-bg); }
.pill-waiting { color: var(--waiting); background: var(--waiting-bg); }
.pill-completed { color: var(--done); background: var(--done-bg); }
.pill-reopened { color: var(--alert); background: var(--alert-bg); }
.pill-run-published { color: var(--done); background: var(--done-bg); }
.pill-run-failed { color: var(--alert); background: var(--alert-bg); }
.pill-run-superseded { color: var(--ink-soft); background: var(--rule-soft); }

/* List and case panel side by side */
.split { display: grid; grid-template-columns: 1fr; gap: var(--step); align-items: start; }
.split-open { grid-template-columns: minmax(0, 1.45fr) minmax(340px, 1fr); }
.split-list { overflow-x: auto; }
.panel { position: sticky; top: var(--step); max-height: calc(100vh - 2 * var(--step)); overflow-y: auto; background: var(--surface); border: 1px solid var(--rule); border-top: 4px solid var(--ink); border-radius: var(--radius); padding: var(--step); }
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.panel-head h2 { margin-bottom: .1rem; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 1rem 0; }
.fact { display: contents; }
.fact dt { color: var(--ink-soft); font-size: .88rem; }
.fact dd { margin: 0; }
.facts-compact { font-size: .9rem; }
.actions { border-top: 1px solid var(--rule-soft); padding-top: .9rem; }
.action-buttons { display: flex; flex-wrap: wrap; gap: .5rem; }
.mini-form { display: grid; gap: .6rem; margin-top: .9rem; padding: .9rem; background: #F6F8FA; border: 1px solid var(--rule-soft); border-radius: var(--radius); }
.mini-form h3 { margin: 0; }
.mini-form .button-primary { justify-self: start; }
.check { display: flex; gap: .4rem; align-items: center; font-size: .92rem; }
.history { border-top: 1px solid var(--rule-soft); margin-top: 1rem; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: .5rem 0 .5rem .8rem; border-left: 2px solid var(--rule); }
.timeline li + li { margin-top: .1rem; }
.note { margin: .25rem 0 0; white-space: pre-wrap; }
.plain { padding-left: 1.1rem; margin: .25rem 0; }

/* Runs and uploads */
.block { margin-bottom: 1.75rem; }
.upload { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: var(--step); max-width: 60rem; }
.upload-fields { display: flex; flex-wrap: wrap; gap: .75rem 1.25rem; margin: .75rem 0 1rem; }
.steps { margin: 1rem 0 0; padding-left: 1.3rem; }
.step { padding: .3rem 0; }
.step-label { font-weight: 600; margin-right: .6rem; }
.step-running .step-state { color: var(--progress); }
.step-done .step-state { color: var(--done); }
.step-failed .step-state { color: var(--alert); font-weight: 600; }
.step-extra { margin-top: .25rem; color: var(--ink-soft); }
.errors li { color: var(--alert); }

/* Notices and toast */
.notice { padding: .6rem .8rem; border-radius: var(--radius); background: var(--new-bg); border: 1px solid #C8D6EE; }
.notice-error { background: var(--alert-bg); border-color: #F0C4BF; color: #7D1A14; }
.toast { position: fixed; right: var(--step); bottom: var(--step); max-width: 28rem; padding: .7rem 1rem; border-radius: var(--radius); background: var(--ink); color: #fff; box-shadow: 0 6px 20px rgba(29, 39, 51, .25); }
.toast-error { background: var(--alert); }

/* Sign-in */
.signin { min-height: 100vh; display: grid; place-items: center; padding: var(--step); }
.signin-card { max-width: 30rem; background: var(--surface); border: 1px solid var(--rule); border-top: 6px solid var(--ink); border-radius: var(--radius); padding: 2rem; }
.signin-card p { max-width: 60ch; }
.signin-card .button { margin: .5rem 0 .25rem; }

@media (max-width: 900px) {
  .split-open { grid-template-columns: 1fr; }
  .panel { position: static; max-height: none; }
  .top { flex-wrap: wrap; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
