/*
 * Hercules Client Portal — the surface.
 *
 * `packages/ui/src/tokens.css` positions this front end as "the terminal, softened", and the
 * softening is the whole design brief. The back office is an INSTRUMENT: 13px, dense, a nav rail
 * of thirty-five routes, built for somebody who lives in it. This is a DOCUMENT, read once by
 * somebody who has never seen it, on a phone, deciding whether to trust a broker with their
 * money. So:
 *
 *   type      15px base and a 1.55 line height, against the console's 13/1.45. Body text a
 *             stranger reads carefully is not the same as a column a professional scans.
 *   width     a 560px measure on forms and 900px on the hub. A field that spans a 27-inch monitor
 *             is a field nobody can see the label and the input of at the same time.
 *   radius    12px, against the console's 6 and the dealing terminal's 0. Rounding costs density
 *             and buys approachability, and only one of those matters here.
 *   motion    present but short. A form that animates is a form that feels slow on the fourth
 *             screen; a step that slides in once tells you where you are.
 *
 * FOUR THINGS THIS STYLESHEET DOES THAT ARE NOT DECORATION:
 *
 *   1. NO INLINE STYLE, ANYWHERE. The CSP ships `style-src 'self'` with no `unsafe-inline`, which
 *      blocks the style ATTRIBUTE as well as the tag. A width written with `setAttribute('style',…)`
 *      renders at zero and says nothing. `el()` writes `node.style.cssText`, which is a CSSOM
 *      write governed by `script-src`, so it applies — but everything that can be a class is one.
 *   2. THE FOCUS RING IS NEVER REMOVED. `:focus-visible` is styled up, not away. This is a form
 *      somebody may be completing with a keyboard, a screen reader, or a phone's switch control,
 *      and the single most common accessibility defect in a sign-up flow is an invisible focus.
 *   3. TOUCH TARGETS ARE 44px MINIMUM. Every control, on every breakpoint. The console can put a
 *      24px icon button in a table row because it is used with a mouse; a client tapping "resend
 *      code" on a train cannot.
 *   4. ERRORS ARE NOT COLOUR ALONE. Every invalid field gets a border, an icon and a sentence.
 *      Roughly one man in twelve cannot reliably see the red.
 *
 * `prefers-reduced-motion` is honoured for real: the transitions are removed, not shortened.
 */

:root {
  --bg: #0B0F14;
  --surface: #111823;
  --raised: #18212E;
  --sunken: #070A0E;
  --overlay: rgba(3, 6, 10, .74);

  --line: #243040;
  --line-strong: #35455A;
  --line-subtle: #1A2430;

  --text: #E8EDF4;
  --dim: #A7B4C6;
  --muted: #6E7E93;
  --inverse: #0B0F14;

  --accent: #3D7BFF;
  --accent-hover: #5C92FF;
  --accent-wash: #132441;

  --pos: #2FC08A;  --pos-wash: #0E2A22;
  --neg: #FF5C6C;  --neg-wash: #33161C;
  --warn: #F5A524; --warn-wash: #2E2210;
  --info: #4FB6E8; --info-wash: #0F2733;
  --neutral: #8494A8; --neutral-wash: #182029;

  --focus: #7EA8FF;

  --s1: 2px; --s2: 4px; --s3: 6px; --s4: 8px; --s5: 12px;
  --s6: 16px; --s7: 20px; --s8: 24px; --s9: 32px; --s10: 40px;
  --s11: 48px; --s12: 64px;

  --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-full: 9999px;

  --ui: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --measure: 560px;
  --page: 940px;
  --tap: 44px;

  --elev-1: 0 0 0 1px var(--line);
  --elev-2: 0 0 0 1px var(--line), 0 10px 30px rgba(0, 0, 0, .40);

  --fast: 140ms cubic-bezier(.2, 0, .38, .9);
  --base: 220ms cubic-bezier(.16, 1, .3, 1);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #F6F8FB; --surface: #FFFFFF; --raised: #FFFFFF; --sunken: #EEF2F7;
    --overlay: rgba(14, 22, 32, .45);
    --line: #D8E0EA; --line-strong: #B4C1D2; --line-subtle: #E7ECF3;
    --text: #0E1620; --dim: #455467; --muted: #6B7C91; --inverse: #FFFFFF;
    --accent: #1F5FE0; --accent-hover: #1A52C4; --accent-wash: #E8F0FF;
    --pos: #0F7A54; --pos-wash: #E3F6EE;
    --neg: #C42A3A; --neg-wash: #FDE9EB;
    --warn: #A96B04; --warn-wash: #FDF3E0;
    --info: #1B6E92; --info-wash: #E4F3FA;
    --neutral: #5D6B7E; --neutral-wash: #EEF1F5;
    --focus: #1F5FE0;
    --elev-2: 0 0 0 1px var(--line), 0 8px 24px rgba(20, 34, 54, .10);
  }
}

* { box-sizing: border-box; }

/*
 * `[hidden]` has to win.
 *
 * The attribute's default rule is `display: none`, and ANY later `display` declaration on a
 * matching selector beats it on specificity — `.acct { display: flex }` renders a hidden element.
 * That is not a theoretical concern: it is why the sign-out button appeared on the sign-in page
 * and why an empty error marker sat under every field on first paint. One rule, at the top,
 * rather than remembering `display: none` on each of them.
 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--ui);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

body { min-height: 100vh; display: flex; flex-direction: column; }

/* Every figure is tabular so a decimal point does not wander between rows. */
.mono, .num, .amount, code { font-family: var(--mono); font-variant-numeric: tabular-nums; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* ── The shell ───────────────────────────────────────────────────────────── */

.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: var(--s6);
  padding: 0 var(--s6);
  height: 60px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line-subtle);
}

.brand {
  display: flex; align-items: center; gap: var(--s4);
  font-weight: 620; letter-spacing: .04em; font-size: 14px;
}
.brand .mark {
  width: 26px; height: 26px; border-radius: 7px;
  background: linear-gradient(140deg, var(--accent), #7B4DFF);
  display: grid; place-items: center; color: #fff; font-size: 13px; font-weight: 700;
}
.brand .sub { color: var(--muted); font-weight: 450; letter-spacing: 0; }

.top .spacer { margin-left: auto; }

.acct {
  display: flex; align-items: center; gap: var(--s4);
  font-size: 13px; color: var(--dim);
}

main { flex: 1; width: 100%; }

.page {
  width: 100%; max-width: var(--page); margin: 0 auto;
  padding: var(--s9) var(--s6) var(--s12);
}
.page.narrow { max-width: var(--measure); }

.page > h1 {
  font-size: 26px; line-height: 1.25; letter-spacing: -.015em;
  margin: 0 0 var(--s4);
  font-weight: 640;
}
.page > .lede {
  margin: 0 0 var(--s8);
  color: var(--dim); font-size: 15px; max-width: 62ch;
}

h2 { font-size: 18px; margin: 0 0 var(--s4); font-weight: 600; letter-spacing: -.01em; }
h3 { font-size: 14px; margin: 0 0 var(--s3); font-weight: 600; letter-spacing: .01em; }

.stack { display: flex; flex-direction: column; gap: var(--s6); }
.stack.tight { gap: var(--s4); }
.row { display: flex; align-items: center; gap: var(--s5); flex-wrap: wrap; }
.grid { display: grid; gap: var(--s5); }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 720px) { .grid.c2, .grid.c3 { grid-template-columns: 1fr; } }

/* ── Cards ───────────────────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--s7);
}
.card.flush { padding: 0; overflow: hidden; }
.card h2, .card h3 { margin-top: 0; }
.card .sub { color: var(--muted); font-size: 13px; margin: 0 0 var(--s5); }

.tile {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: var(--s6);
}
.tile .k { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.tile .v { font-size: 22px; font-weight: 620; margin-top: var(--s2); font-variant-numeric: tabular-nums; }
.tile .m { color: var(--dim); font-size: 12.5px; margin-top: var(--s2); }

/* ── Progress ────────────────────────────────────────────────────────────── */

.progress {
  display: flex; align-items: center; gap: var(--s5);
  padding: var(--s6) var(--s7);
  background: var(--raised); border: 1px solid var(--line); border-radius: var(--r-md);
}
.bar { flex: 1; height: 8px; border-radius: var(--r-full); background: var(--sunken); overflow: hidden; }
.bar > span {
  display: block; height: 100%; border-radius: var(--r-full);
  background: linear-gradient(90deg, var(--accent), #7B4DFF);
  transition: width var(--base);
}
.progress .pct { font-variant-numeric: tabular-nums; font-weight: 620; min-width: 3.5ch; text-align: right; }

/* The step list. A checklist, not a wizard: every step says what it is and what it costs. */
.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.steps li { border-bottom: 1px solid var(--line-subtle); }
.steps li:last-child { border-bottom: 0; }

.step {
  display: grid; grid-template-columns: 30px 1fr auto; align-items: start;
  gap: var(--s5); width: 100%; text-align: left;
  padding: var(--s6) var(--s7);
  background: none; border: 0; color: inherit; font: inherit;
  min-height: var(--tap); cursor: pointer;
  transition: background var(--fast);
}
.step:hover:not([disabled]) { background: var(--raised); }
.step[disabled] { cursor: default; opacity: .55; }
.step .dot {
  width: 26px; height: 26px; border-radius: var(--r-full);
  display: grid; place-items: center; font-size: 13px; font-weight: 700;
  border: 1.5px solid var(--line-strong); color: var(--muted);
  margin-top: 1px;
}
.step.done .dot { background: var(--pos-wash); border-color: var(--pos); color: var(--pos); }
.step.waived .dot { background: var(--warn-wash); border-color: var(--warn); color: var(--warn); }
.step.current .dot { background: var(--accent-wash); border-color: var(--accent); color: var(--accent); }
/* Both are spans inside a span, so they need an explicit block or the title and the description
 * run together into one sentence — "Create your accountEmail address, a password and…". */
.step .t { display: block; font-weight: 560; }
.step .d { display: block; color: var(--muted); font-size: 13px; margin-top: var(--s1); line-height: 1.45; }
.step .meta { color: var(--muted); font-size: 12.5px; white-space: nowrap; text-align: right; }
.step.current { background: color-mix(in srgb, var(--accent-wash) 55%, transparent); }

/* ── Forms ───────────────────────────────────────────────────────────────── */

form { display: flex; flex-direction: column; gap: var(--s6); }

.field { display: flex; flex-direction: column; gap: var(--s3); }
.field > label { font-size: 13.5px; font-weight: 550; }
.field .hint { color: var(--muted); font-size: 12.5px; }

.input, select.input, textarea.input {
  width: 100%;
  min-height: var(--tap);
  padding: var(--s4) var(--s5);
  background: var(--sunken);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--text);
  font: inherit;
  transition: border-color var(--fast), background var(--fast);
}
.input:hover, select.input:hover { border-color: var(--line-strong); }
.input:focus, select.input:focus, textarea.input:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
textarea.input { min-height: 96px; resize: vertical; }
.input::placeholder { color: var(--muted); }

/* An invalid field is a border, an icon and a sentence — never colour alone. */
.field.bad .input { border-color: var(--neg); background: color-mix(in srgb, var(--neg-wash) 40%, var(--sunken)); }
.field .err {
  display: flex; align-items: flex-start; gap: var(--s3);
  color: var(--neg); font-size: 13px;
}
.field .err::before { content: "▲"; font-size: 11px; line-height: 1.5; }

fieldset { border: 0; margin: 0; padding: 0; }
legend { font-size: 13.5px; font-weight: 550; padding: 0 0 var(--s3); }

.choice {
  display: flex; align-items: flex-start; gap: var(--s5);
  min-height: var(--tap);
  padding: var(--s5) var(--s6);
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--sunken);
  cursor: pointer;
  transition: border-color var(--fast), background var(--fast);
}
.choice:hover { border-color: var(--line-strong); }
.choice input { margin-top: 4px; accent-color: var(--accent); width: 18px; height: 18px; flex: none; }
.choice .t { font-weight: 520; }
.choice .d { color: var(--muted); font-size: 12.5px; }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-wash); }

.choices { display: flex; flex-direction: column; gap: var(--s4); }

/* The password meter. Four segments, and a label — a bar alone says nothing. */
.meter { display: flex; gap: var(--s2); margin-top: var(--s2); }
.meter i { flex: 1; height: 4px; border-radius: var(--r-full); background: var(--line); }
.meter.s1 i:nth-child(-n+1) { background: var(--neg); }
.meter.s2 i:nth-child(-n+2) { background: var(--warn); }
.meter.s3 i:nth-child(-n+3) { background: var(--info); }
.meter.s4 i { background: var(--pos); }

/* ── Buttons ─────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s3);
  min-height: var(--tap); padding: 0 var(--s7);
  border-radius: var(--r-sm); border: 1px solid var(--line-strong);
  background: var(--raised); color: var(--text);
  font: inherit; font-weight: 560; cursor: pointer;
  transition: background var(--fast), border-color var(--fast), transform var(--fast);
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { background: none; border-color: transparent; color: var(--dim); }
.btn.ghost:hover:not(:disabled) { background: var(--raised); color: var(--text); }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 0 var(--s5); font-size: 13.5px; }
.btn.danger { border-color: var(--neg); color: var(--neg); }
.btn.danger:hover:not(:disabled) { background: var(--neg-wash); }

.btn-row { display: flex; gap: var(--s4); flex-wrap: wrap; }

/* ── Notices ─────────────────────────────────────────────────────────────── */

.notice {
  display: flex; gap: var(--s5); align-items: flex-start;
  padding: var(--s6); border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--raised);
  font-size: 14px;
}
.notice .ico { font-size: 13px; line-height: 1.5; flex: none; }
.notice strong { display: block; margin-bottom: var(--s2); }
.notice.info { border-color: var(--info); background: var(--info-wash); }
.notice.info .ico { color: var(--info); }
.notice.pos { border-color: var(--pos); background: var(--pos-wash); }
.notice.pos .ico { color: var(--pos); }
.notice.warn { border-color: var(--warn); background: var(--warn-wash); }
.notice.warn .ico { color: var(--warn); }
.notice.neg { border-color: var(--neg); background: var(--neg-wash); }
.notice.neg .ico { color: var(--neg); }

/* The statutory risk warning. Deliberately not dismissible and deliberately not styled down. */
.risk-warning {
  border: 1px solid var(--warn); background: var(--warn-wash);
  border-radius: var(--r-sm); padding: var(--s6);
  font-size: 13.5px; line-height: 1.5;
}
.risk-warning b { display: block; margin-bottom: var(--s2); }

.badge {
  display: inline-flex; align-items: center; gap: var(--s2);
  padding: 2px var(--s4); border-radius: var(--r-full);
  font-size: 11.5px; font-weight: 600; letter-spacing: .02em;
  background: var(--neutral-wash); color: var(--neutral);
  border: 1px solid color-mix(in srgb, var(--neutral) 40%, transparent);
}
.badge.pos { background: var(--pos-wash); color: var(--pos); border-color: color-mix(in srgb, var(--pos) 40%, transparent); }
.badge.warn { background: var(--warn-wash); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.badge.neg { background: var(--neg-wash); color: var(--neg); border-color: color-mix(in srgb, var(--neg) 40%, transparent); }
.badge.info { background: var(--info-wash); color: var(--info); border-color: color-mix(in srgb, var(--info) 40%, transparent); }

/* ── The code input ──────────────────────────────────────────────────────── */

.code-input {
  display: flex; gap: var(--s4); justify-content: flex-start;
}
.code-input input {
  width: 52px; height: 60px;
  text-align: center; font-family: var(--mono); font-size: 22px;
  background: var(--sunken); border: 1px solid var(--line); border-radius: var(--r-sm);
  color: var(--text);
}
.code-input input:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
@media (max-width: 420px) {
  .code-input { gap: var(--s3); }
  .code-input input { width: 44px; height: 52px; font-size: 19px; }
}

/* ── Documents and uploads ───────────────────────────────────────────────── */

.drop {
  border: 1.5px dashed var(--line-strong); border-radius: var(--r-md);
  padding: var(--s10) var(--s6); text-align: center;
  background: var(--sunken);
  transition: border-color var(--fast), background var(--fast);
}
.drop.over { border-color: var(--accent); background: var(--accent-wash); }
.drop .t { font-weight: 560; }
.drop .d { color: var(--muted); font-size: 13px; margin-top: var(--s2); }

.doc-list { display: flex; flex-direction: column; gap: var(--s4); }
.doc {
  display: flex; align-items: center; gap: var(--s5);
  padding: var(--s5) var(--s6);
  border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--sunken);
}
.doc .t { font-weight: 520; flex: 1; }

/* ── Tables (the few there are) ──────────────────────────────────────────── */

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th {
  text-align: left; font-weight: 600; color: var(--muted);
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em;
  padding: var(--s4) var(--s6); border-bottom: 1px solid var(--line);
}
td { padding: var(--s5) var(--s6); border-bottom: 1px solid var(--line-subtle); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

dl.kv { display: grid; grid-template-columns: minmax(140px, auto) 1fr; gap: var(--s3) var(--s6); margin: 0; }
dl.kv dt { color: var(--muted); font-size: 13px; }
dl.kv dd { margin: 0; font-size: 13.5px; }

/* ── Toast ───────────────────────────────────────────────────────────────── */

.toast-wrap {
  position: fixed; left: 50%; bottom: var(--s7); transform: translateX(-50%);
  display: flex; flex-direction: column; gap: var(--s4); z-index: 60;
  width: min(520px, calc(100vw - 2 * var(--s6)));
}
.toast {
  display: flex; gap: var(--s5); align-items: flex-start;
  padding: var(--s5) var(--s6);
  border-radius: var(--r-sm); border: 1px solid var(--line);
  background: var(--raised); box-shadow: var(--elev-2);
  font-size: 13.5px;
  animation: rise var(--base);
}
.toast.pos { border-color: var(--pos); }
.toast.neg { border-color: var(--neg); }
.toast strong { display: block; }
.toast .body { color: var(--dim); }

@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ── Auth pages ──────────────────────────────────────────────────────────── */

.auth {
  min-height: calc(100vh - 60px);
  display: grid; place-items: center; padding: var(--s8) var(--s6) var(--s12);
}
.auth .card { width: 100%; max-width: 440px; }
.auth .switch { text-align: center; color: var(--muted); font-size: 13.5px; margin-top: var(--s6); }

/* ── Footer ──────────────────────────────────────────────────────────────── */

.foot {
  border-top: 1px solid var(--line-subtle);
  padding: var(--s7) var(--s6);
  color: var(--muted); font-size: 12.5px;
}
.foot .inner { max-width: var(--page); margin: 0 auto; display: flex; flex-wrap: wrap; gap: var(--s6); }

/* ── Utilities ───────────────────────────────────────────────────────────── */

.muted { color: var(--muted); }
.dim { color: var(--dim); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.center { text-align: center; }
.spacer { margin-left: auto; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.spinner {
  width: 16px; height: 16px; border-radius: var(--r-full);
  border: 2px solid var(--line-strong); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  /* Removed, not shortened. A 1ms animation still triggers vestibular symptoms in some people. */
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
