/*
 * RiskVector360 app styles, in the same Vaern visual style as the website (site/src/styles/tokens.css):
 * cream ground, dark olive ink, orange accent, sage top bar; Space Grotesk headings, Alexandria body.
 *
 * Contrast checked against WCAG 2.2 AA (4.5:1 text, 3:1 non-text):
 *   --text on --surface 11.01, --panel 11.7; on --chrome (sage top bar) 7.16 (only --text goes on sage)
 *   --text-muted on --surface 6.01, --surface-2 5.54, --surface-3 5.01, --panel 6.35
 *   --link on --surface 5.60, --surface-2 5.16, --panel 5.92, --info-bg 4.78
 *   --ok-text / --warn-text / --bad-text on --surface >= 6.08, on their -bg >= 5.76
 *   input border (#8a8470) vs --panel 3.67, vs --surface 3.48
 * --accent (#e6653e) is decoration only.
 */
:root {
  --ink-900: #373924;
  --ink-800: #43452e;
  --ink-700: #4f523a;
  --ink-600: #5e604a;
  --accent:      #e6653e;
  --chrome:      #b8cec8;

  --link:       #a4462a;
  --link-hover: #7e3420;

  --surface:       #f9f7ea;
  --surface-2:     #f1eedc;
  --surface-3:     #e8e3cb;
  --panel:         #fffdf6;
  --border:        #dcd6bf;
  --border-strong: #bfb8a0;
  --input-border:  #8a8470;

  --text:        #373924;
  --text-muted:  #5e604a;
  --text-invert: #f9f7ea;

  --ok:      #1aa66b;
  --ok-bg:   #e3f6ed;
  --warn:    #e08a00;
  --warn-bg: #fbecd0;
  --bad:     #d33c3c;
  --bad-bg:  #fbe3e3;
  --info-bg: #f6e1d6;

  /* Text-safe status colours. */
  --ok-text: #0f6b45;
  --warn-text: #7a4600;
  --bad-text: #a82727;

  --focus: #a4462a;

  --radius:    4px;
  --radius-sm: 4px;
  --cut-sm: 18px;

  --font-head: 'Space Grotesk', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  --font-sans: 'Alexandria', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* Self-hosted variable fonts (SIL Open Font License), Latin subset. CSP: font-src 'self'. */
@font-face { font-family: 'Space Grotesk'; font-style: normal; font-weight: 300 700; font-display: swap; src: url('/assets/fonts/space-grotesk-latin-var.woff2') format('woff2'); }
@font-face { font-family: 'Alexandria'; font-style: normal; font-weight: 100 900; font-display: swap; src: url('/assets/fonts/alexandria-latin-var.woff2') format('woff2'); }

/* ===== Base ===== */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; overflow-wrap: break-word; font-family: var(--font-sans); font-size: 16px; font-weight: 300; line-height: 1.55; color: var(--text); background: var(--surface); -webkit-font-smoothing: antialiased; }
strong, b, th { font-weight: 600; }
h1, h2, h3, h4 { font-family: var(--font-head); font-weight: 600; line-height: 1.15; margin: 0 0 .5em; letter-spacing: -.015em; }
h1 { font-size: 2rem; }
h2 { font-size: 1.4rem; margin-top: 1.6em; }
h3 { font-size: 1.1rem; }
h4 { font-size: 1rem; }
p { margin: 0 0 .8em; }
a { color: var(--link); text-decoration: underline; text-underline-offset: 2px; }
a:hover { color: var(--link-hover); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
code, .mono { font-family: var(--font-mono); font-size: .9em; }
.mono { word-break: break-all; }
.muted { color: var(--text-muted); }
.small { font-size: .875rem; }
.nowrap { white-space: nowrap; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.skip-link { position: absolute; left: 12px; top: -60px; z-index: 100; padding: 10px 16px; background: var(--link); color: var(--surface); font-weight: 600; }
.skip-link:focus { top: 12px; color: var(--surface); }
main:focus { outline: none; }

/* Vaern's diagonal corner cut (top-left and bottom-right). Only on boxes without a border. */
.cut-sm, .card, .login { clip-path: polygon(var(--cut-sm) 0, 100% 0, 100% calc(100% - var(--cut-sm)), calc(100% - var(--cut-sm)) 100%, 0 100%, 0 var(--cut-sm)); }

/* ===== Shell (sage top bar, ink text only) ===== */
.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 24px; padding: 10px 24px; background: var(--chrome); color: var(--text); }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); font-family: var(--font-head); font-weight: 700; text-decoration: none; font-size: 1.1rem; letter-spacing: -.02em; }
.brand:hover { color: var(--text); }
.topnav ul { display: flex; flex-wrap: wrap; gap: 4px; list-style: none; margin: 0; padding: 0; }
.topnav a { display: block; padding: 6px 12px; color: var(--text); text-decoration: none; }
.topnav a:hover { background: rgba(55, 57, 36, .08); color: var(--text); text-decoration: underline; }
.topnav a[aria-current="page"] { font-weight: 600; text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 5px; }
.topbar :focus-visible { outline-color: var(--ink-900); }
.account { margin-left: auto; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.account__name { font-size: .9rem; }
.account__role { color: var(--text); }
.account form { margin: 0; }
.account .btn--ghost { color: var(--text); border-color: var(--ink-900); background: transparent; }
.account .btn--ghost:hover { background: rgba(55, 57, 36, .08); color: var(--text); }

main { display: block; max-width: 1160px; margin: 0 auto; padding: 32px 24px 56px; }
.footer { max-width: 1160px; margin: 0 auto; padding: 16px 24px 32px; color: var(--text-muted); font-size: .875rem; border-top: 1px solid var(--border); }
.page-narrow { max-width: 640px; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.page-head h1 { margin: 0; }
.crumbs { margin: 0 0 6px; font-size: .9rem; }
.lead { font-size: 1.05rem; max-width: 70ch; }

/* ===== Components ===== */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 8px 16px; border: 1px solid var(--ink-900); border-radius: var(--radius-sm); background: transparent; color: var(--text); font: inherit; font-weight: 500; text-decoration: none; cursor: pointer; }
.btn:hover { background: var(--surface-3); color: var(--text); }
.btn--primary { background: var(--link); border-color: var(--link); color: var(--surface); }
.btn--primary:hover { background: var(--link-hover); border-color: var(--link-hover); color: var(--surface); }
.btn--ghost { background: transparent; }
.btn--danger { color: var(--bad-text); border-color: var(--bad-text); }
.btn--danger:hover { background: var(--bad-bg); color: var(--bad-text); }
.btn--small { min-height: 32px; padding: 4px 10px; font-size: .875rem; }
.btn--large { min-height: 48px; padding: 12px 22px; font-size: 1.05rem; }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; margin: 20px 0; }
.panel > h2:first-child, .panel > h3:first-child { margin-top: 0; }
.notice { background: var(--warn-bg); color: var(--warn-text); padding: 10px 14px; }
.flash { padding: 12px 16px; margin-bottom: 20px; font-weight: 500; border-left: 4px solid currentColor; }
.flash--ok { background: var(--ok-bg); color: var(--ok-text); }
.flash--warn { background: var(--warn-bg); color: var(--warn-text); }
.empty { color: var(--text-muted); font-style: italic; }
.badge { display: inline-block; padding: 1px 8px; background: var(--surface-3); color: var(--text-muted); font-size: .8rem; font-weight: 500; }
.ref { color: var(--text-muted); font-weight: 600; font-variant-numeric: tabular-nums; }
a .ref { color: inherit; }

/* Workspace cards: filled, no border, with an orange top edge and cut corners. */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; list-style: none; padding: 0; margin: 20px 0; }
.card { background: var(--surface-2); border-top: 3px solid var(--accent); padding: 20px 22px; }
.card__title { font-size: 1.15rem; margin: 0 0 6px; }

.list { list-style: none; padding: 0; margin: 0 0 16px; }
.list__row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list__row form { margin: 0; }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 0 20px; }

/* Tables */
.table-wrap { position: relative; overflow-x: auto; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); margin: 12px 0 20px; }
table { width: 100%; border-collapse: collapse; }
caption { text-align: left; font-family: var(--font-head); font-weight: 600; padding: 12px 14px 0; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
thead th { font-size: .78rem; font-weight: 500; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); background: var(--surface-2); }
tbody tr:last-child > * { border-bottom: 0; }
tbody th { font-weight: 600; }

/* Forms */
.form-grid { display: grid; gap: 16px; max-width: 560px; }
.stack { display: grid; gap: 12px; }
.field { display: grid; gap: 6px; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { font-weight: 600; padding: 0; margin-bottom: 6px; }
label { font-weight: 500; }
.choice { font-weight: 300; display: flex; gap: 8px; align-items: center; }
input:not([type="radio"]):not([type="checkbox"]), select, textarea {
  width: 100%; min-height: 40px; padding: 8px 10px; border: 1px solid var(--input-border); border-radius: var(--radius-sm);
  background: var(--panel); color: var(--text); font: inherit;
}
textarea { min-height: 64px; resize: vertical; }
input[type="radio"] { width: 18px; height: 18px; accent-color: var(--link); margin: 0; flex: none; }
.help { color: var(--text-muted); font-size: .875rem; margin: 0; }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; }
.inline-form select { width: auto; flex: 1 1 220px; min-width: 0; max-width: 100%; }
.form-title { margin: 16px 0 0; }
.disclosure > summary { cursor: pointer; font-weight: 500; color: var(--link); }
.disclosure[open] > summary { margin-bottom: 16px; }

/* Scores */
.score { display: inline-flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.score meter { width: 96px; height: 10px; }
.score__band { font-size: .8rem; font-weight: 500; padding: 1px 8px; }
.score--ok .score__band { background: var(--ok-bg); color: var(--ok-text); }
.score--warn .score__band { background: var(--warn-bg); color: var(--warn-text); }
.score--bad .score__band { background: var(--bad-bg); color: var(--bad-text); }
.score--none .score__band { background: var(--surface-3); color: var(--text-muted); }
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin: 16px 0 24px; }
.summary__item { background: var(--surface-2); padding: 16px 18px; display: grid; gap: 6px; border-left: 3px solid var(--accent); }
.summary__label { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); font-weight: 500; }
.summary__item strong { font-family: var(--font-head); font-size: 1.4rem; }

/* Questions */
.scale { background: var(--panel); border: 1px solid var(--border); padding: 12px 16px; margin: 16px 0; }
.scale summary { cursor: pointer; font-weight: 500; color: var(--link); }
.scale__list { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 12px 0 0; }
.scale__list dt { font-weight: 600; }
.scale__list dd { margin: 0; }
.question { background: var(--panel); border: 1px solid var(--border); padding: 20px 22px; margin: 0 0 16px; }
.question legend { display: grid; gap: 2px; float: left; width: 100%; margin-bottom: 12px; }
.question legend + * { clear: both; }
.question__ref { font-size: .85rem; color: var(--text-muted); font-weight: 600; }
.question__title { font-family: var(--font-head); font-size: 1.1rem; }
.question__text { font-weight: 300; }
.answers { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; }
.answer { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; min-height: 40px; border: 1px solid var(--border-strong); font-weight: 400; cursor: pointer; background: var(--panel); }
.answer:hover { border-color: var(--link); }
.answer:has(input:checked) { border-color: var(--link); background: var(--info-bg); box-shadow: inset 0 0 0 1px var(--link); font-weight: 500; }
.answer:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.answer input:focus-visible { outline: none; }
.guidance { margin: 0 0 10px; }
.guidance summary { cursor: pointer; color: var(--link); font-weight: 500; }
.guidance[open] { background: var(--surface-2); padding: 8px 12px; }
.notes-label { display: block; font-size: .9rem; margin-bottom: 4px; }
fieldset:disabled .answer { cursor: default; opacity: 1; color: var(--text-muted); }
.form-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 8px; position: sticky; bottom: 0; background: var(--surface); padding: 12px 0; border-top: 1px solid var(--border); }

/* Login */
.login { max-width: 460px; margin: 8vh auto 0; text-align: center; background: var(--surface-2); border-top: 4px solid var(--accent); padding: 40px 32px; }
.login img { margin-bottom: 12px; }
.login .btn--large { margin: 12px 0 20px; }
.dev-note { background: var(--surface-3); padding: 8px 12px; }

/* Report */
.report-actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: flex-end; margin-bottom: 16px; }
.report { background: var(--panel); border: 1px solid var(--border); padding: 36px; }
.report__head { border-bottom: 3px solid var(--ink-900); padding-bottom: 12px; margin-bottom: 8px; }
.report__kicker { display: inline-flex; align-items: center; gap: 8px; text-transform: uppercase; letter-spacing: .12em; font-size: .78rem; font-weight: 500; color: var(--text); margin: 0 0 6px; }
.report__kicker::before { content: ''; width: .55rem; height: .55rem; background: var(--accent); flex: none; }
.chart { margin: 8px 0 0; }
.chart svg { display: block; max-width: 760px; height: auto; }
.chart__label, .chart__value, .chart__tick { font-family: var(--font-sans); font-size: 12px; fill: var(--text); }
.chart__tick { fill: var(--text-muted); }
.chart__grid { stroke: var(--border); stroke-width: 1; }
.chart__bar--ok { fill: var(--ok); }
.chart__bar--warn { fill: var(--warn); }
.chart__bar--bad { fill: var(--bad); }
.gaps { padding-left: 1.4em; }
.gap { margin-bottom: 18px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.gap h3 { margin-bottom: 4px; }
.gap__meta { color: var(--text-muted); font-size: .9rem; }
.report__foot { margin-top: 24px; border-top: 1px solid var(--border); padding-top: 12px; }
.attribution { margin-top: 24px; }

@media (max-width: 640px) {
  main { padding: 20px 16px 40px; }
  .topbar { padding: 10px 16px; }
  .account { margin-left: 0; }
  .report { padding: 18px; }
  .question { padding: 14px; }
  .scale__list { grid-template-columns: 1fr; }
  .scale__list dd { margin-bottom: 6px; }
  :root { --cut-sm: 14px; }
}

@media print {
  .topbar, .footer, .skip-link, .no-print, .flash { display: none !important; }
  body { background: #fff; font-size: 11pt; }
  main { max-width: none; padding: 0; }
  .report { border: 0; padding: 0; background: #fff; }
  .table-wrap { overflow: visible; border: 0; }
  .card, .login { clip-path: none; }
  .page-break { break-before: page; }
  .gap, tr { break-inside: avoid; }
  a { color: inherit; text-decoration: none; }
}

@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }

/* Remediation plan */
.count { color: var(--text-muted); font-weight: 400; }
.action-source { display: block; font-weight: 400; }
.due--late { color: var(--bad-text); }
.prio { display: inline-block; padding: 1px 8px; font-size: .85rem; font-weight: 600; background: var(--surface-3); color: var(--text); }
.prio--high { background: var(--bad-bg); color: var(--bad-text); }
.prio--medium { background: var(--warn-bg); color: var(--warn-text); }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px 20px; margin: 16px 0 24px; padding: 16px 20px; background: var(--panel); border: 1px solid var(--border); }
.facts dt { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); }
.facts dd { margin: 2px 0 0; font-weight: 500; }
.facts__wide { grid-column: 1 / -1; }
.prewrap { white-space: pre-line; max-width: 75ch; }
.updates { list-style: none; padding: 0; margin: 0 0 20px; max-width: 75ch; }
.update { border-left: 3px solid var(--border-strong); padding: 4px 0 4px 14px; margin-bottom: 14px; }
.update__meta { margin: 0 0 4px; }
.update p:last-child { margin-bottom: 0; }
.form-narrow { max-width: 560px; }
.form-buttons { display: flex; flex-wrap: wrap; gap: 12px; }
.input-date { max-width: 220px; }
.panel--tight { padding: 12px 16px; }
.danger-zone { margin-top: 32px; padding-top: 16px; border-top: 1px solid var(--border); }
.planned { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border); }
.planned__title { margin: 0; font-weight: 600; }
.planned__list { list-style: none; padding: 0; margin: 0; flex: 1 1 240px; }
.status-form select { flex: 0 1 240px; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.inline-form .select-role { flex: 0 1 170px; }

/* Audit log */
.tabs ul { display: flex; flex-wrap: wrap; gap: 4px; list-style: none; margin: 0 0 16px; padding: 0; border-bottom: 1px solid var(--border); }
.tabs a { display: block; padding: 8px 14px; color: var(--text); text-decoration: none; border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tabs a:hover { text-decoration: underline; }
.tabs a[aria-current="page"] { font-weight: 600; border-bottom-color: var(--link); }
.filter-form { margin: 8px 0 4px; }
.filter-form select { flex: 0 1 260px; }
.change { min-width: 200px; }
.note-change summary { cursor: pointer; color: var(--link); font-size: .9rem; }
.note-change p { margin: 4px 0 0; }
.label-like { font-weight: 500; }
