/* PJG Mission Control: design system.
   Brand: pjgfinancial.co.uk. Monochrome ink on paper, JetBrains Mono throughout,
   "//" section labels, ledger rows. A black left rail carries the logo and navigation. */

@font-face {
  font-family: "JetBrains Mono";
  src: url("fonts/jetbrains-mono-latin.woff2") format("woff2");
  font-weight: 100 800;
  font-style: normal;
  font-display: swap;
}

:root {
  --ink: #000000;
  --ink-2: #363636;
  --ink-3: #7c7c7c;
  --line: #e7e7e7;
  --line-2: #d4d4d4;
  --paper: #ffffff;
  --wash: #f6f6f5;
  --rail: #0a0a0a;
  --rail-ink: #f2f2f2;
  --rail-dim: #8a8a8a;
  --rail-line: #222222;
  --rail-hover: #1a1a1a;

  --crit: #c4320a;   --crit-bg: #fdeee9;
  --high: #b54708;   --high-bg: #fdf3e7;
  --med: #8a6a00;    --med-bg: #faf5e1;
  --low: #5b6170;    --low-bg: #f0f1f3;
  --ok: #067647;     --ok-bg: #e7f6ee;
  --info: #1d4ed8;   --info-bg: #eaf0fe;

  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --radius: 6px;
  --rail-w: 248px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 8px 24px rgba(0, 0, 0, .06);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 400 13.5px/1.6 var(--mono); -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 2px; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.label { font-size: 11px; font-weight: 500; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); }
.label .slash, .slash { color: var(--ink); }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------------------------------------------------------------- logo */
.logo { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; }
.logo svg { width: 28px; height: 28px; flex: none; }
.logo .word { font-weight: 700; font-size: 15px; letter-spacing: -.01em; white-space: nowrap; }
.logo .word .thin { font-weight: 400; opacity: .72; }

/* ---------------------------------------------------------------- auth screens */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.auth-side { background: var(--rail); color: var(--rail-ink); padding: 40px clamp(24px, 5vw, 64px); display: flex; flex-direction: column; justify-content: space-between; gap: 32px; }
.auth-side .prompt { font-size: 13px; color: var(--rail-dim); }
.auth-side .prompt b { color: var(--rail-ink); font-weight: 500; }
.auth-side h1 { font-size: clamp(26px, 3.4vw, 40px); line-height: 1.15; letter-spacing: -.02em; margin: 16px 0 0; max-width: 18ch; font-weight: 700; }
.auth-side .caret { display: inline-block; width: .58ch; height: 1em; background: var(--rail-ink); margin-left: .1em; vertical-align: -.12em; animation: blink 1.05s steps(1, end) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.auth-side dl { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; font-size: 12px; color: var(--rail-dim); }
.auth-side dt { letter-spacing: .1em; }
.auth-side dd { margin: 0; color: var(--rail-ink); }
.auth-main { display: flex; align-items: center; justify-content: center; padding: 40px 24px; }
.auth-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 18px; }
.auth-card h2 { margin: 0; font-size: 22px; letter-spacing: -.01em; }
.auth-card p { margin: 0; color: var(--ink-2); }
.auth-card .links { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-size: 12.5px; }
.auth-card .links button { all: unset; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; color: var(--ink-2); }
.auth-card .links button:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.qr { width: 180px; height: 180px; border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; background: #fff; }
.secret { font-size: 12px; word-break: break-all; background: var(--wash); padding: 8px 10px; border-radius: var(--radius); }
.code-input { font-size: 22px; letter-spacing: .4em; text-align: center; }
@media (max-width: 820px) {
  .auth { grid-template-columns: minmax(0, 1fr); }
  .auth-side { padding-block: 28px; }
  .auth-side h1 { font-size: 24px; }
  .auth-side dl { display: none; }
}

/* ---------------------------------------------------------------- shell */
.shell { display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr); min-height: 100vh; background: linear-gradient(to right, var(--rail) var(--rail-w), var(--paper) var(--rail-w)); }
.rail { background: var(--rail); color: var(--rail-ink); position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; overflow-y: auto; }
.rail-head { padding: 20px 18px 18px; border-bottom: 1px solid var(--rail-line); }
.rail-head .env { margin-top: 8px; font-size: 11px; color: var(--rail-dim); letter-spacing: .08em; }
.nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav .group { margin: 16px 8px 6px; font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--rail-dim); }
.nav .group::before { content: "// "; color: var(--rail-ink); }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 5px; text-decoration: none; color: var(--rail-dim); font-size: 13px; }
.nav a:hover { background: var(--rail-hover); color: var(--rail-ink); }
.nav a[aria-current="page"] { background: var(--rail-ink); color: var(--rail); font-weight: 600; }
.nav a svg { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.6; }
.nav a .count { margin-left: auto; font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--rail-line); color: var(--rail-ink); }
.nav a .count.alert { background: var(--crit); color: #fff; }
.nav a[aria-current="page"] .count { background: var(--rail); color: var(--rail-ink); }
.rail-foot { border-top: 1px solid var(--rail-line); padding: 14px 18px 18px; display: flex; flex-direction: column; gap: 10px; font-size: 12px; }
.rail-foot .who { color: var(--rail-ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail-foot .role { color: var(--rail-dim); }
.rail-foot button { all: unset; cursor: pointer; color: var(--rail-dim); text-decoration: underline; text-underline-offset: 3px; }
.rail-foot button:hover { color: var(--rail-ink); }
.rail-foot button:focus-visible { outline: 2px solid var(--rail-ink); outline-offset: 2px; }

.main { min-width: 0; background: var(--paper); }
.topbar { display: none; }
.page { padding: 28px clamp(16px, 3.4vw, 44px) 64px; max-width: 1400px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px 24px; flex-wrap: wrap; padding-bottom: 20px; margin-bottom: 22px; border-bottom: 1px solid var(--line); }
.page-head h1 { margin: 6px 0 0; font-size: clamp(22px, 2.4vw, 30px); letter-spacing: -.02em; line-height: 1.15; font-weight: 700; text-wrap: balance; }
.page-head .sub { margin: 8px 0 0; color: var(--ink-2); max-width: 72ch; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.section { margin-top: 30px; }
.section > .label { display: block; margin-bottom: 12px; }

@media (max-width: 960px) {
  .shell { grid-template-columns: minmax(0, 1fr); background: var(--paper); }
  .rail { position: fixed; inset: 0 auto 0 0; width: min(var(--rail-w), 86vw); z-index: 40; transform: translateX(-100%); transition: transform .18s ease; }
  .rail.open { transform: none; }
  .topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; background: var(--rail); color: var(--rail-ink); position: sticky; top: 0; z-index: 30; }
  .topbar button { all: unset; cursor: pointer; padding: 6px 10px; border: 1px solid var(--rail-line); border-radius: 5px; font-size: 12px; }
  .scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 35; }
}

/* ---------------------------------------------------------------- building blocks */
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; min-width: 0; }
.card.wash { background: var(--wash); border-color: transparent; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr)); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.kpi { padding: 16px 18px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); margin: 0 -1px -1px 0; display: flex; flex-direction: column; gap: 6px; text-decoration: none; min-width: 0; }
a.kpi:hover { background: var(--wash); }
.kpi .n { font-size: 32px; font-weight: 700; letter-spacing: -.03em; line-height: 1; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); }
.kpi .d { font-size: 12px; color: var(--ink-2); }
.c-critical { color: var(--crit); } .c-high { color: var(--high); } .c-medium { color: var(--med); } .c-low { color: var(--low); } .c-ok { color: var(--ok); } .c-info { color: var(--info); }

.ledger { margin: 0; display: grid; grid-template-columns: max-content minmax(0, 1fr); border-top: 1px solid var(--line); }
.ledger dt, .ledger dd { margin: 0; padding: 10px 0; border-bottom: 1px solid var(--line); }
.ledger dt { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); padding-right: 24px; }
.ledger dd { overflow-wrap: anywhere; }

/* chips + badges */
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 500; letter-spacing: .06em; text-transform: uppercase; padding: 3px 8px; border-radius: 4px; background: var(--wash); color: var(--ink-2); white-space: nowrap; }
.chip.critical { background: var(--crit-bg); color: var(--crit); }
.chip.high { background: var(--high-bg); color: var(--high); }
.chip.medium { background: var(--med-bg); color: var(--med); }
.chip.low { background: var(--low-bg); color: var(--low); }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.info { background: var(--info-bg); color: var(--info); }
.chip.ink { background: var(--ink); color: var(--paper); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: currentColor; flex: none; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; border: 1px solid var(--ink); background: var(--ink); color: var(--paper); border-radius: var(--radius); padding: 9px 14px; font-size: 13px; font-weight: 600; line-height: 1.2; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--ink-2); border-color: var(--ink-2); }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line-2); }
.btn.ghost:hover { background: var(--wash); }
.btn.danger { background: var(--crit); border-color: var(--crit); color: #fff; }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.linkbtn { all: unset; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.linkbtn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* forms */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .field > .label { font-size: 11px; font-weight: 500; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); }
.field .hint { font-size: 12px; color: var(--ink-3); }
.field .err { font-size: 12px; color: var(--crit); }
.input, .select, .textarea { width: 100%; border: 1px solid var(--line-2); border-radius: var(--radius); padding: 9px 11px; background: var(--paper); font-size: 13.5px; }
.input:focus, .select:focus, .textarea:focus { outline: 2px solid var(--ink); outline-offset: 0; border-color: var(--ink); }
.textarea { min-height: 96px; resize: vertical; }
.row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 160px), 1fr)); }
.check { display: flex; align-items: flex-start; gap: 10px; }
.check input { margin-top: 3px; }

/* filters */
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }
.toolbar .select, .toolbar .input { width: auto; min-width: 150px; padding: 7px 10px; font-size: 12.5px; }
.seg { display: inline-flex; max-width: 100%; border: 1px solid var(--line-2); border-radius: var(--radius); overflow-x: auto; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg button { all: unset; flex: none; white-space: nowrap; cursor: pointer; padding: 6px 12px; font-size: 12px; color: var(--ink-2); border-right: 1px solid var(--line-2); }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.seg button:focus-visible { outline: 2px solid var(--ink); outline-offset: -2px; }

/* tables */
.table-wrap { border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
table.table { border-collapse: collapse; width: 100%; min-width: 640px; }
.table th, .table td { padding: 10px 14px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); font-size: 13px; }
.table th { font-size: 10.5px; font-weight: 500; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); background: var(--wash); white-space: nowrap; position: sticky; top: 0; }
.table th.sortable { cursor: pointer; user-select: none; }
.table th.sortable:hover { color: var(--ink); }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover td { background: var(--wash); }
.table td.right, .table th.right { text-align: right; }
.table .sub { display: block; font-size: 11.5px; color: var(--ink-3); margin-top: 2px; }

/* list items (findings, records, changes) */
.items { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--radius); }
.item { display: grid; grid-template-columns: 92px minmax(0, 1fr) auto; gap: 14px; padding: 14px 16px; border-bottom: 1px solid var(--line); align-items: start; }
.item:last-child { border-bottom: 0; }
.item.clickable { cursor: pointer; }
.item.clickable:hover { background: var(--wash); }
.item > .chip { white-space: normal; justify-content: center; text-align: center; }
.item .kicker { font-size: 11.5px; color: var(--ink-3); margin: 0 0 3px; }
.item h3 { margin: 0; font-size: 14px; font-weight: 600; line-height: 1.4; overflow-wrap: anywhere; }
.item .meta { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 6px; font-size: 12px; color: var(--ink-3); }
.item .meta .ref { color: var(--ink-2); }
.overdue { color: var(--crit) !important; font-weight: 600; }
@media (max-width: 720px) { .item { grid-template-columns: minmax(0, 1fr); gap: 8px; } }

/* diffs */
.diff { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; font-size: 12.5px; }
.diff div { padding: 4px 10px 4px 28px; position: relative; overflow-wrap: anywhere; }
.diff .add { background: var(--ok-bg); color: var(--ok); }
.diff .del { background: var(--crit-bg); color: var(--crit); text-decoration: line-through; text-decoration-thickness: 1px; }
.diff .add::before, .diff .del::before { position: absolute; left: 10px; text-decoration: none; }
.diff .add::before { content: "+"; } .diff .del::before { content: "-"; }

/* bars */
.bar { height: 6px; background: var(--wash); border-radius: 3px; overflow: hidden; min-width: 80px; }
.bar i { display: block; height: 100%; background: var(--ink); }

/* hourly chart */
.hours { display: flex; align-items: flex-end; gap: 3px; height: 96px; padding-top: 6px; border-bottom: 1px solid var(--line-2); }
.hours i { flex: 1; min-height: 1px; background: var(--ink); border-radius: 2px 2px 0 0; }
.hours i.zero { background: var(--line); }
.hours-axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--ink-3); margin-top: 6px; }
.delta { font-size: 11.5px; margin-left: 6px; white-space: nowrap; }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 10px; font-size: 13px; color: var(--ink-2); }
.steps b { color: var(--ink); }
.steps code { font-size: 12px; background: var(--wash); padding: 1px 5px; border-radius: 4px; overflow-wrap: anywhere; }

/* empty / error / loading */
.empty { border: 1px dashed var(--line-2); border-radius: var(--radius); padding: 36px 20px; text-align: center; color: var(--ink-2); }
.empty b { display: block; color: var(--ink); font-size: 15px; margin-bottom: 6px; }
.empty .btn { margin-top: 14px; }
.error-box { border: 1px solid var(--crit); background: var(--crit-bg); color: var(--crit); border-radius: var(--radius); padding: 12px 14px; font-size: 13px; }
.note { background: var(--wash); border-radius: var(--radius); padding: 12px 14px; font-size: 12.5px; color: var(--ink-2); }
.skeleton { border-radius: var(--radius); background: linear-gradient(90deg, var(--wash), #efefee, var(--wash)); background-size: 200% 100%; animation: sk 1.2s linear infinite; height: 14px; }
@keyframes sk { to { background-position: -200% 0; } }

/* drawer + modal */
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 50; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100%); background: var(--paper); z-index: 51; display: flex; flex-direction: column; box-shadow: var(--shadow); border-left: 1px solid var(--line); }
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { margin: 4px 0 0; font-size: 18px; line-height: 1.3; letter-spacing: -.01em; overflow-wrap: anywhere; }
.drawer-body { padding: 18px 20px 28px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 16px; }
.drawer-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.modal { position: fixed; z-index: 52; left: 50%; top: 18vh; transform: translateX(-50%); width: min(440px, calc(100% - 32px)); background: var(--paper); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.modal h2 { margin: 0; font-size: 17px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; }
.toast { position: fixed; z-index: 60; left: 50%; bottom: 22px; transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: var(--radius); font-size: 13px; max-width: calc(100% - 32px); box-shadow: var(--shadow); }
.toast.error { background: var(--crit); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
