/* Course++ admin panel.
 *
 * An operator tool, not a marketing page. It is read while deciding whether to
 * move money, so the priorities are density, legibility and figures that line
 * up — in that order. No gradients, no icon set, no emoji, no motion beyond a
 * focus ring.
 *
 * The scale below is deliberately the same shape as the extension's
 * src/ui/window.css: four radii, six type steps, colour only through tokens.
 * That file's rule applies here too — no literal px radius and no literal rem
 * font-size in the blocks underneath. If nothing on the scale fits, the design
 * is wrong, not the scale.
 *
 * Body sits at 14px rather than the marketing site's 17px on purpose: this
 * page is a table of numbers, not prose, and the row is the unit of reading.
 * 12px is still the floor, and only metadata is allowed there.
 */

:root {
  color-scheme: light dark;

  /* Colour. Measured against the ground they sit on, not eyeballed:
     AA is 4.5:1 for body text and 3:1 for the boundary of a control. */
  --bg:      #ffffff;
  --raise:   #f6f7f8;  /* panels, table head, dialog */
  --sunk:    #eef0f2;  /* hover row */
  --border:  #d8dce0;  /* hairline (1.5:1, decorative) */
  --border-ui:#8b949c; /* boundary of an input or button — 3.1:1 on bg */
  --text:    #1f272e;  /* 14.8:1 on bg */
  --muted:   #5c666f;  /* 6.4:1 on bg, 6.0:1 on raise */
  --link:    #0b5c8a;  /* 6.6:1 on bg */
  --ok:      #0a6c3d;  /* 5.9:1 */
  --warn:    #8a4200;  /* 6.5:1 */
  --err:     #99202a;  /* 7.2:1 */
  --accent-bg: #14303f; /* primary button ground */
  --accent-fg: #ffffff; /* 13.6:1 on accent-bg */

  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;

  --t-xs: .75rem;     /* 12px — metadata, column heads, mono detail. The floor. */
  --t-sm: .8125rem;   /* 13px — table cells, secondary prose */
  --t-md: .875rem;    /* 14px — BODY */
  --t-lg: 1rem;       /* 16px — section headings */
  --t-xl: 1.25rem;    /* 20px — page title */
  --t-fig: 1.5rem;    /* 24px — the money figures, and nothing else */

  --r-sm: 3px;
  --r-md: 6px;
  --r-lg: 10px;
  --r-pill: 99px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:      #16191c;
    --raise:   #1e2226;
    --sunk:    #262b30;
    --border:  #333a40;
    --border-ui:#79838b;
    --text:    #e8ebed;
    --muted:   #a3acb4;
    --link:    #79bce4;
    --ok:      #5fc98d;
    --warn:    #e2a25f;
    --err:     #f08b93;
    --accent-bg: #d8e2e8;
    --accent-fg: #14303f;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: var(--t-md)/1.5 var(--sans);
}

/* One focus treatment for everything. Visible on both grounds, and never
   removed — this page suspends accounts, and a keyboard operator has to be
   able to see what they are about to press. */
:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 1px;
  border-radius: var(--r-sm);
}

.sr-only, .skip:not(:focus) {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip:focus {
  position: absolute; z-index: 10; left: .5rem; top: .5rem;
  background: var(--bg); color: var(--link); padding: .4rem .6rem;
  border: 1px solid var(--border-ui); border-radius: var(--r-md);
}

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 1.25rem;
  padding: .5rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--raise);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: .5rem; flex: none; }
.mark {
  display: grid; place-items: center; width: 1.75rem; height: 1.75rem;
  background: var(--accent-bg); color: var(--accent-fg);
  border-radius: var(--r-md);
  font-size: var(--t-xs); font-weight: 700; letter-spacing: -.04em;
}
.brand-text { display: flex; align-items: baseline; gap: .5rem; }
.env {
  font-size: var(--t-xs); text-transform: uppercase; letter-spacing: .06em;
  color: var(--warn); border: 1px solid currentColor;
  border-radius: var(--r-pill); padding: 0 .4rem;
}
.env.live { color: var(--err); }

.tabs { display: flex; gap: .25rem; }
.tab {
  font-size: var(--t-sm); color: var(--muted); text-decoration: none;
  padding: .25rem .55rem; border-radius: var(--r-sm);
}
.tab:hover { color: var(--text); background: var(--sunk); }
.tab[aria-current="page"] {
  color: var(--text); background: var(--sunk); font-weight: 600;
  box-shadow: inset 0 -2px 0 var(--link);
}
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: .6rem; }
.who { font-size: var(--t-xs); color: var(--muted); font-family: var(--mono); }

/* ---------- layout ---------- */
main { padding: 1rem 1rem 4rem; max-width: 78rem; margin: 0 auto; }
.view-head {
  display: flex; align-items: baseline; gap: 1rem; flex-wrap: wrap;
  margin: .25rem 0 .75rem;
}
h1 { font-size: var(--t-xl); margin: 0; line-height: 1.25; }
h2 { font-size: var(--t-lg); margin: 0 0 .4rem; line-height: 1.3; }
h3 {
  font-size: var(--t-xs); margin: 0 0 .4rem; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em; font-weight: 700;
}
p { margin: 0 0 .6rem; }
a { color: var(--link); }
code { font-family: var(--mono); font-size: .95em; }

.card {
  border: 1px solid var(--border); border-radius: var(--r-lg);
  background: var(--raise); padding: .85rem 1rem; margin-bottom: 1rem;
}
.card.narrow { max-width: 30rem; margin: 2rem auto; }
.note { font-size: var(--t-sm); color: var(--muted); max-width: 46rem; }
.hint { font-size: var(--t-xs); color: var(--muted); font-weight: 400; }
.err {
  color: var(--err); font-size: var(--t-sm);
  border-left: 3px solid var(--err); border-radius: 0 var(--r-sm) var(--r-sm) 0;
  padding: .4rem .6rem; background: color-mix(in srgb, var(--err) 8%, transparent);
}
.page-err { margin-top: 1rem; }
.loading { font-size: var(--t-sm); color: var(--muted); }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: .2rem; margin-bottom: .7rem; }
.field-label { font-size: var(--t-sm); font-weight: 600; }
.input {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border-ui); border-radius: var(--r-md);
  padding: .35rem .5rem; min-width: 0;
}
.input.mono { font-family: var(--mono); font-size: var(--t-sm); }
.input:read-only { color: var(--muted); background: var(--raise); }
textarea.input { resize: vertical; }
.row-end { display: flex; gap: .5rem; justify-content: flex-end; align-items: center; }
.search { display: flex; gap: .4rem; margin-left: auto; }
.search .input { width: 20rem; max-width: 50vw; }

.btn {
  font: inherit; font-size: var(--t-sm); cursor: pointer;
  padding: .35rem .8rem; border-radius: var(--r-md);
  border: 1px solid var(--border-ui); background: var(--bg); color: var(--text);
}
.btn:hover:not(:disabled) { background: var(--sunk); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent-bg); color: var(--accent-fg); border-color: var(--accent-bg); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.15); }
.btn.danger { border-color: var(--err); color: var(--err); background: var(--bg); }
.btn.danger:hover:not(:disabled) { background: color-mix(in srgb, var(--err) 12%, transparent); }
.btn.quiet { border-color: transparent; color: var(--muted); }
.btn.quiet:hover { color: var(--text); }

/* ---------- tables ---------- */
/* Wide tables scroll inside their own box. The page must never scroll
   sideways: an operator who has scrolled the window right cannot see the row
   they are acting on. */
.tablewrap {
  border: 1px solid var(--border); border-radius: var(--r-lg);
  overflow-x: auto; background: var(--bg);
}
table.grid { border-collapse: collapse; width: 100%; font-size: var(--t-sm); }
table.grid th, table.grid td {
  text-align: left; padding: .4rem .6rem;
  border-bottom: 1px solid var(--border); vertical-align: top;
}
table.grid thead th {
  position: sticky; top: 0; background: var(--raise);
  font-size: var(--t-xs); text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); white-space: nowrap; z-index: 1;
}
table.grid tbody tr:last-child td { border-bottom: 0; }
table.grid tbody tr:hover { background: var(--sunk); }
/* Money and counts are read by comparison down a column, so they are right
   aligned and set in tabular figures — proportional digits make a column of
   numbers ragged and slow to scan. */
.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.mono, .mono { font-family: var(--mono); }
.rowlink { color: var(--link); text-decoration: none; font-weight: 600; }
.rowlink:hover { text-decoration: underline; }
.sub { display: block; font-size: var(--t-xs); color: var(--muted); font-family: var(--mono); }
.empty { padding: 1.5rem; text-align: center; color: var(--muted); font-size: var(--t-sm); }
.more { margin-top: .6rem; display: flex; gap: .6rem; align-items: center; font-size: var(--t-sm); color: var(--muted); }
.back { display: inline-block; font-size: var(--t-sm); margin-bottom: .6rem; }

/* ---------- status pills ---------- */
.pill {
  display: inline-block; font-size: var(--t-xs); padding: 0 .4rem;
  border-radius: var(--r-pill); border: 1px solid currentColor; white-space: nowrap;
}
.pill.active { color: var(--ok); }
.pill.suspended, .pill.past_due, .pill.unpaid { color: var(--warn); }
.pill.deleted, .pill.terminated, .pill.canceled { color: var(--err); }
.pill.neutral { color: var(--muted); }
/* Nexus statuses, in their own words and their own colours. */
.pill.nx-now { color: var(--err); font-weight: 700; }
.pill.nx-crossed { color: var(--err); }
.pill.nx-approaching { color: var(--warn); }
.pill.nx-monitoring { color: var(--muted); }

/* ---------- the money report ----------
 * The one block on this page with a rule of its own: realised margin and
 * unrealised liability are ALWAYS rendered side by side, in the same type
 * size, in that order. Unspent purchased credit is money held for the buyer,
 * and a panel that shows revenue minus cost on its own reads as profit that
 * has not been earned yet. Do not "simplify" this into a single figure.
 */
.money { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: 1px;
         background: var(--border); border: 1px solid var(--border);
         border-radius: var(--r-lg); overflow: hidden; margin-bottom: .5rem; }
.fig { background: var(--raise); padding: .6rem .75rem; }
.fig-label { display: block; font-size: var(--t-xs); color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.fig-val { display: block; font-size: var(--t-fig); font-variant-numeric: tabular-nums; line-height: 1.2; margin-top: .1rem; }
.fig-val.neg { color: var(--err); }
.fig-note { display: block; font-size: var(--t-xs); color: var(--muted); margin-top: .15rem; }
.fig.liability { box-shadow: inset 3px 0 0 var(--warn); }
.fig.margin { box-shadow: inset 3px 0 0 var(--ok); }
.fig.unknown .fig-val { color: var(--muted); }
.money-caption {
  font-size: var(--t-sm); color: var(--muted); margin: 0 0 1rem;
  display: flex; gap: .4rem; align-items: baseline;
}
.money-caption strong { color: var(--warn); font-weight: 700; }

/* ---------- account detail ---------- */
/* 16rem, not 19rem: at 19 the fourth fact card wrapped to a row of its own
   and left two thirds of a screen blank between the facts and the actions
   below them. Four fit across at the 78rem page width; three at a laptop
   width; one on a phone. */
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: 1rem; align-items: start; }
dl.kv { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: .15rem .6rem; font-size: var(--t-sm); }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; font-family: var(--mono); font-size: var(--t-xs); overflow-wrap: anywhere; }
.actions { display: flex; flex-direction: column; gap: .5rem; }
.adjust-row { display: flex; gap: .4rem; flex-wrap: wrap; align-items: flex-end; }
.adjust-row .field { margin-bottom: 0; }
.adjust-row .input { width: 8rem; }
.danger-zone { border-color: var(--err); }
.danger-zone h2 { color: var(--err); }

/* ---------- dialog ---------- */
dialog {
  border: 1px solid var(--border-ui); border-radius: var(--r-lg);
  background: var(--raise); color: var(--text);
  padding: 1rem; max-width: 34rem; width: calc(100vw - 2rem);
  font: var(--t-md)/1.5 var(--sans);
}
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h2 { font-size: var(--t-lg); }
.confirm-line { font-size: var(--t-md); margin-bottom: .5rem; }
.confirm-count {
  font-size: var(--t-sm); font-family: var(--mono);
  border: 1px solid var(--border); border-radius: var(--r-md);
  padding: .45rem .6rem; background: var(--bg); margin-bottom: .6rem;
}
.confirm-count div { display: flex; justify-content: space-between; gap: 1rem; }
.confirm-warn {
  font-size: var(--t-sm); border-left: 3px solid var(--warn);
  background: color-mix(in srgb, var(--warn) 9%, transparent);
  border-radius: 0 var(--r-sm) var(--r-sm) 0; padding: .45rem .6rem; margin-bottom: .6rem;
}

/* ---------- nexus ---------- */
.bar { display: block; height: .4rem; border-radius: var(--r-pill); background: var(--sunk); overflow: hidden; min-width: 4rem; }
.bar > i { display: block; height: 100%; background: var(--ok); }
.bar.approaching > i { background: var(--warn); }
.bar.crossed > i, .bar.obligation_immediate > i { background: var(--err); }

@media (max-width: 40rem) {
  .topbar { flex-wrap: wrap; gap: .5rem; }
  .search .input { width: 100%; }
  .search { width: 100%; margin-left: 0; }
}

/* ---------- the pair ----------
 * `.money` on its own is auto-fit and will happily stack. The PAIR must not:
 * realised margin and unrealised liability are two halves of one reading, and
 * the moment they land one above the other the second one can be scrolled
 * past. Two columns at every width, and the figures step down rather than the
 * layout breaking apart.
 */
.money.pair { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.money.pair .fig { padding: .75rem .85rem; }
/* The pair is the headline; the supporting figures are the workings. Same
   figure size WITHIN the pair — that is the rule — one step down outside it. */
.money:not(.pair) .fig-val { font-size: var(--t-lg); }

/* ---------- the content guard ----------
 * Deliberately louder than an ordinary error. It does not mean a request
 * failed; it means the product's "no transcripts, anywhere" promise may have
 * stopped being true, and this page refused to be where that shows up. */
.guard {
  border: 1px solid var(--err);
  border-left-width: 4px;
  border-radius: var(--r-md);
  background: color-mix(in srgb, var(--err) 10%, transparent);
  color: var(--text);
  font-size: var(--t-sm);
  padding: .5rem .7rem;
  margin: 0 0 1rem;
}
.guard code { color: var(--err); overflow-wrap: anywhere; }

/* A negative figure in a table reads as a negative figure, not as red alarm
   text — clawbacks and debits are the normal case in a ledger. */
td.neg { color: var(--err); }

.confirm-count strong { font-variant-numeric: tabular-nums; }
select.input { padding-right: .3rem; }
.adjust-row .field { min-width: 0; }

@media (max-width: 34rem) {
  /* Still two columns. The number gets smaller; the comparison survives. */
  .money.pair .fig-val { font-size: var(--t-lg); }
  .money.pair .fig { padding: .5rem .55rem; }
  /* One column for the supporting figures. Three tiles in a two-wide grid
     leave a fourth cell empty, and an empty cell on a money panel reads as a
     figure that failed to load. */
  .money:not(.pair) { grid-template-columns: 1fr; }
  /* The caption is one sentence, not a label and a column. */
  .money-caption { flex-direction: column; gap: .1rem; }
}
