/* Fragebogen-Pilot – design system "Precision in Service of the Planet".
   Tokens first, then base, layout, components, page patterns. No dark mode by design. */

/* ---------- Fonts (self-hosted, OFL; no requests to third parties) ---------- */
@font-face { font-family: "DM Sans"; font-weight: 300; font-display: swap; src: url("fonts/dm-sans-latin-300-normal.woff2") format("woff2"); }
@font-face { font-family: "DM Sans"; font-weight: 400; font-display: swap; src: url("fonts/dm-sans-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "DM Sans"; font-weight: 500; font-display: swap; src: url("fonts/dm-sans-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "DM Sans"; font-weight: 600; font-display: swap; src: url("fonts/dm-sans-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "DM Sans"; font-weight: 700; font-display: swap; src: url("fonts/dm-sans-latin-700-normal.woff2") format("woff2"); }
@font-face { font-family: "Inter"; font-weight: 400; font-display: swap; src: url("fonts/inter-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Inter"; font-weight: 500; font-display: swap; src: url("fonts/inter-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Inter"; font-weight: 600; font-display: swap; src: url("fonts/inter-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "JetBrains Mono"; font-weight: 400; font-display: swap; src: url("fonts/jetbrains-mono-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "JetBrains Mono"; font-weight: 500; font-display: swap; src: url("fonts/jetbrains-mono-latin-500-normal.woff2") format("woff2"); }

/* ---------- Tokens ---------- */
:root {
  --color-bg: #FAFAFA;
  --color-surface: #FFFFFF;
  --color-surface-alt: #F4F6F4;
  --color-border: #E4E9E4;
  --color-border-strong: #C8D4C8;

  --color-primary: #1A3D2B;
  --color-primary-mid: #2D6A4F;
  --color-accent: #40916C;
  --color-accent-light: #D8EDDF;

  --color-text-primary: #111B17;
  --color-text-body: #374740;
  --color-text-muted: #6B7E74;
  --color-text-inverse: #FFFFFF;

  --color-success: #2D9B60;
  --color-warning: #C88A2B;
  --color-error: #C0392B;
  --color-success-bg: #E3F4EA;
  --color-warning-bg: #FBF1E0;
  --color-error-bg: #F9E5E3;

  /* Document kinds (knowledge base): muted hues away from the traffic-light colours.
     Text on background >= 4.5:1. "document" and "filled_questionnaire" reuse
     neutral and accent-light. */
  --kind-policy-bg: #E4ECF7;       --kind-policy-fg: #1F4A80;
  --kind-report-bg: #EEE8F7;       --kind-report-fg: #53348C;
  --kind-certificate-bg: #DCF0EF;  --kind-certificate-fg: #17605B;
  --kind-initiative-bg: #F8E5EE;   --kind-initiative-fg: #8A2C56;
  --kind-kpi-bg: #F7E7DC;          --kind-kpi-fg: #8A4214;
  --kind-evidence-bg: #E3E8EE;     --kind-evidence-fg: #34465A;

  --font-display: "DM Sans", system-ui, sans-serif;
  --font-body: "Inter", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  --shadow-sm: 0 2px 8px rgba(17, 27, 23, .06);
  --shadow-md: 0 4px 16px rgba(17, 27, 23, .08);
  --shadow-lg: 0 8px 32px rgba(17, 27, 23, .10);
  --shadow-xl: 0 16px 48px rgba(17, 27, 23, .12);

  --transition-fast: 120ms ease;
  --transition-base: 200ms ease;
  --transition-spring: 400ms cubic-bezier(0.34, 1.56, 0.64, 1);

  --sidebar-width: 240px;
  --topbar-height: 64px;
}

@media (prefers-reduced-motion: reduce) {
  :root { --transition-fast: 0ms; --transition-base: 0ms; --transition-spring: 0ms; }
  *, *::before, *::after { animation-duration: 0ms !important; transition-duration: 0ms !important; }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { color-scheme: light; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text-body);
  font: 400 16px/1.6 var(--font-body);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: var(--font-display); color: var(--color-text-primary); margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 40px; font-weight: 700; line-height: 1.15; }
h2 { font-size: 32px; font-weight: 600; line-height: 1.2; }
h3 { font-size: 24px; font-weight: 600; line-height: 1.3; }
p { margin: 0 0 16px; }
a { color: var(--color-accent); text-decoration: none; transition: color var(--transition-base); }
a:hover { color: var(--color-primary-mid); text-decoration: underline; }
small, .caption { font-size: 12px; font-weight: 500; }
.muted { color: var(--color-text-muted); }
.mono { font-family: var(--font-mono); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }
::selection { background: var(--color-accent-light); }

/* ---------- App layout: sidebar 240 + topbar 64 + content ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-width) 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  background: var(--color-primary); color: rgba(255, 255, 255, .75);
  display: flex; flex-direction: column; padding: 24px 16px;
}
.brand {
  display: flex; align-items: center; gap: 12px;
  color: var(--color-text-inverse); font: 600 18px/1.2 var(--font-display);
  padding: 0 12px 32px; text-decoration: none;
}
.brand:hover { color: var(--color-text-inverse); text-decoration: none; }
.brand-mark {
  width: 32px; height: 32px; border-radius: var(--radius-md);
  background: rgba(255, 255, 255, .12); display: grid; place-items: center;
}
.sidebar-nav { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.nav { display: flex; flex-direction: column; gap: 4px; margin: 0; padding: 0; list-style: none; }
.nav-bottom { margin-top: auto; padding-bottom: 16px; }
.nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: var(--radius-md); border-left: 3px solid transparent;
  color: rgba(255, 255, 255, .75); font-weight: 500; font-size: 15px;
  transition: background var(--transition-base), color var(--transition-base);
}
.nav a:hover { background: rgba(255, 255, 255, .08); color: var(--color-text-inverse); text-decoration: none; }
.nav a[aria-current="page"] {
  background: rgba(255, 255, 255, .12); color: var(--color-text-inverse);
  border-left-color: var(--color-accent);
}
.nav svg, .brand svg { flex: none; }
.sidebar-foot { margin-top: auto; padding: 16px 12px 0; border-top: 1px solid rgba(255, 255, 255, .12); font-size: 12px; line-height: 1.5; }
.sidebar-foot strong { color: var(--color-text-inverse); font-weight: 600; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 10; height: var(--topbar-height);
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  background: var(--color-surface); border-bottom: 1px solid var(--color-border);
  padding: 0 64px;
}
.breadcrumb { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--color-text-muted); min-width: 0; }
.breadcrumb a { color: var(--color-text-muted); }
.breadcrumb [aria-current] { color: var(--color-text-primary); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-meta { display: flex; align-items: center; gap: 12px; font-size: 14px; color: var(--color-text-muted); white-space: nowrap; }
.content { padding: 48px 64px 96px; max-width: calc(1200px + 128px); width: 100%; }

/* ---------- Page header ---------- */
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 32px; flex-wrap: wrap; }
.page-header .eyebrow { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--color-text-muted); margin-bottom: 8px; }
.page-header p { color: var(--color-text-muted); margin: 8px 0 0; max-width: 680px; }
.page-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

/* ---------- Buttons (always pill) ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 12px 28px; border-radius: var(--radius-pill);
  font: 600 15px/1 var(--font-body); cursor: pointer; white-space: nowrap;
  border: 1.5px solid transparent; text-decoration: none;
  transition: background var(--transition-base), transform var(--transition-base),
    box-shadow var(--transition-base), color var(--transition-base), border-color var(--transition-base);
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--color-accent); color: var(--color-text-inverse); box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--color-primary-mid); color: var(--color-text-inverse); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-secondary { background: transparent; color: var(--color-primary); border-color: var(--color-primary); }
.btn-secondary:hover { background: var(--color-accent-light); color: var(--color-primary); }
.btn-ghost { background: transparent; color: var(--color-text-body); }
.btn-ghost:hover { background: var(--color-surface-alt); color: var(--color-text-primary); }
.btn-sm { min-height: 36px; padding: 8px 18px; font-size: 14px; }
.btn-block { width: 100%; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-primary[disabled]:hover { background: var(--color-accent); }
.btn svg { flex: none; }

/* ---------- Cards ---------- */
.card {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); padding: 32px;
  transition: box-shadow var(--transition-base), transform var(--transition-base);
}
.card-hover:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.card + .card, .stack > * + * { margin-top: 24px; }
.card-title { font: 600 20px/1.3 var(--font-display); color: var(--color-text-primary); margin: 0 0 8px; }
.card-lead { color: var(--color-text-muted); margin-bottom: 24px; }

/* KPI cards: 4-up row, mono value, caption label, optional progress ring */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 24px; margin-bottom: 48px; }
.kpi { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 24px 28px; }
.kpi-label { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--color-text-muted); }
.kpi-value { font: 500 36px/1.1 var(--font-mono); color: var(--color-primary); margin-top: 8px; font-variant-numeric: tabular-nums; }
.kpi-value .unit { font-size: 18px; color: var(--color-text-muted); margin-left: 2px; }
.kpi-note { font-size: 12px; color: var(--color-text-muted); margin-top: 4px; }
.ring { flex: none; width: 64px; height: 64px; transform: rotate(-90deg); }
.ring-track { stroke: var(--color-surface-alt); }
.ring-value { stroke: var(--color-accent); stroke-linecap: round; transition: stroke-dashoffset 1200ms cubic-bezier(.22, .61, .36, 1); }

/* ---------- Tags / badges ---------- */
.tag {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: var(--radius-pill);
  font: 600 12px/1.4 var(--font-body); white-space: nowrap;
  background: var(--color-accent-light); color: var(--color-primary);
}
.tag-neutral { background: var(--color-surface-alt); color: var(--color-text-body); }
.tag-success { background: var(--color-success-bg); color: #1E6B42; }
.tag-warning { background: var(--color-warning-bg); color: #8A5C14; }
.tag-error { background: var(--color-error-bg); color: #9A2B20; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.dot-green { background: var(--color-success); }
.dot-yellow { background: var(--color-warning); }
.dot-red { background: var(--color-error); }
.lights { display: inline-flex; align-items: center; gap: 12px; font: 500 14px var(--font-mono); color: var(--color-text-body); }
.lights span { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- Inputs ---------- */
label, .label { display: block; font-size: 14px; font-weight: 500; color: var(--color-text-primary); margin-bottom: 8px; }
.field { margin-bottom: 24px; }
.hint { display: block; font-size: 12px; color: var(--color-text-muted); margin-top: 6px; font-weight: 400; }
input[type="text"], input[type="search"], input:not([type]), select, textarea {
  width: 100%; min-height: 44px; padding: 10px 14px;
  font: 400 15px/1.5 var(--font-body); color: var(--color-text-primary);
  background: var(--color-surface); border: 1.5px solid var(--color-border); border-radius: var(--radius-sm);
  transition: border-color var(--transition-base), box-shadow var(--transition-base);
}
select { border-radius: var(--radius-md); appearance: none; padding-right: 40px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%236B7E74' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; }
textarea { resize: vertical; min-height: 88px; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--color-accent); box-shadow: 0 0 0 3px rgba(64, 145, 108, .15);
}
input[readonly], textarea[readonly], select[disabled] { background: var(--color-surface-alt); color: var(--color-text-body); cursor: default; }
.is-invalid, .is-invalid:focus { border-color: var(--color-error); box-shadow: 0 0 0 3px rgba(192, 57, 43, .12); }
.checkbox { display: flex; align-items: center; gap: 10px; font-weight: 400; color: var(--color-text-body); cursor: pointer; }
.checkbox input { width: 18px; height: 18px; accent-color: var(--color-accent); margin: 0; }

/* File drop zone (native input stays usable without JS) */
.dropzone {
  position: relative; display: block; border: 1.5px dashed var(--color-border-strong); border-radius: var(--radius-lg);
  background: var(--color-surface-alt); padding: 32px; text-align: left; cursor: pointer;
  transition: border-color var(--transition-base), background var(--transition-base);
}
.dropzone:hover, .dropzone.is-dragover { border-color: var(--color-accent); background: var(--color-accent-light); }
.dropzone input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.dropzone-inner { display: flex; align-items: center; gap: 16px; pointer-events: none; }
.dropzone-icon { width: 48px; height: 48px; border-radius: var(--radius-md); background: var(--color-surface); display: grid; place-items: center; color: var(--color-primary-mid); flex: none; box-shadow: var(--shadow-sm); }
.dropzone-title { font-weight: 600; color: var(--color-text-primary); }
.dropzone-files { font: 500 13px var(--font-mono); color: var(--color-primary-mid); margin-top: 4px; word-break: break-all; }

/* ---------- Alerts ---------- */
.alert { display: flex; gap: 12px; align-items: flex-start; padding: 16px 20px; border-radius: var(--radius-md); margin-bottom: 24px; font-size: 15px; border: 1px solid transparent; }
.alert svg { flex: none; margin-top: 2px; }
.alert-success { background: var(--color-success-bg); color: #1E4D34; border-color: #C5E6D2; }
.alert-warning { background: var(--color-warning-bg); color: #6B4910; border-color: #F0DDB8; }
.alert-error { background: var(--color-error-bg); color: #7A2219; border-color: #EFC7C2; }
.alert-info { background: var(--color-surface-alt); color: var(--color-text-body); border-color: var(--color-border); }
.alert ul { margin: 8px 0 0; padding-left: 18px; }
.alert p:last-child { margin-bottom: 0; }

/* ---------- Tables ---------- */
.table-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-sm); }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
thead th {
  background: var(--color-surface-alt); color: var(--color-text-muted);
  font: 600 12px/1.4 var(--font-body); text-transform: uppercase; letter-spacing: .06em;
  text-align: left; padding: 14px 20px; border-bottom: 1px solid var(--color-border);
}
tbody td { padding: 20px; border-bottom: 1px solid var(--color-border); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background var(--transition-base); }
tbody tr:hover { background: var(--color-surface-alt); }
td.num, th.num { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.cell-title { font-weight: 600; color: var(--color-text-primary); }
.cell-sub { font-size: 12px; color: var(--color-text-muted); margin-top: 2px; }
.progress { height: 6px; border-radius: var(--radius-pill); background: var(--color-surface-alt); overflow: hidden; min-width: 96px; }
.progress > span { display: block; height: 100%; background: var(--color-accent); border-radius: inherit; transition: width 1200ms cubic-bezier(.22, .61, .36, 1); }
.progress-row { display: flex; align-items: center; gap: 12px; }
.progress-row .mono { font-size: 13px; color: var(--color-text-body); min-width: 42px; text-align: right; }

/* ---------- Tabs / segmented filter ---------- */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; padding: 4px; background: var(--color-surface-alt); border-radius: var(--radius-pill); width: fit-content; margin-bottom: 24px; }
.tabs a {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 16px; border-radius: var(--radius-pill);
  font-size: 14px; font-weight: 500; color: var(--color-text-body); text-decoration: none;
  transition: background var(--transition-base), color var(--transition-base), box-shadow var(--transition-base);
}
.tabs a:hover { color: var(--color-text-primary); background: rgba(255, 255, 255, .6); }
.tabs a[aria-current="page"] { background: var(--color-surface); color: var(--color-primary); box-shadow: var(--shadow-sm); font-weight: 600; }
.tabs .count { font: 500 12px var(--font-mono); color: var(--color-text-muted); }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.toolbar .tabs { margin-bottom: 0; }
.search { display: flex; gap: 8px; min-width: 280px; }

/* ---------- Details / sources ---------- */
details { border-radius: var(--radius-sm); }
details > summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 6px; color: var(--color-primary-mid); font-size: 13px; font-weight: 500; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: ""; width: 6px; height: 6px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(-45deg); transition: transform var(--transition-base); flex: none; }
details[open] > summary::before { transform: rotate(45deg); }
.excerpt { margin: 8px 0 0; padding: 12px 14px; background: var(--color-surface-alt); border-left: 3px solid var(--color-border-strong); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; font-size: 13px; line-height: 1.55; color: var(--color-text-body); white-space: pre-line; }

/* ---------- Review table ---------- */
.legend { display: flex; gap: 24px; flex-wrap: wrap; font-size: 13px; color: var(--color-text-muted); margin-bottom: 24px; }
.legend span { display: inline-flex; align-items: center; gap: 8px; }
.review-table td:nth-child(1) { width: 120px; }
.review-table td:nth-child(2) { width: 32%; }
.review-table td:nth-child(3) { width: 34%; }
.review-row { border-left: 3px solid transparent; }
.review-row.level-green { box-shadow: inset 3px 0 0 var(--color-success); }
.review-row.level-yellow { box-shadow: inset 3px 0 0 var(--color-warning); }
.review-row.level-red { box-shadow: inset 3px 0 0 var(--color-error); }
.review-row.is-approved { background: #FBFDFB; }
.review-row.is-approved:hover { background: var(--color-surface-alt); }
.qref { font: 500 15px var(--font-mono); color: var(--color-primary); }
.qtext { color: var(--color-text-primary); font-weight: 500; }
.qsection { font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--color-text-muted); margin-bottom: 4px; }
.qmeta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.answer-form { display: grid; gap: 10px; }
.answer-form textarea { min-height: 72px; }
.option-list { display: grid; gap: 8px; margin: 0; padding: 10px 12px; border: 1px solid var(--color-border); border-radius: var(--radius-sm); background: var(--color-surface); }
.option-list .checkbox { font-size: 14px; }
.answer-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.field-error { font-size: 13px; color: var(--color-error); margin: 0; }
.missing { font-size: 13px; color: var(--color-text-muted); margin: 0; }
.source + .source { margin-top: 10px; }
.source-name { font-size: 13px; color: var(--color-text-body); line-height: 1.45; }
.rationale { font-size: 13px; color: var(--color-text-muted); margin-top: 12px; }
.notes { margin: 8px 0 0; padding-left: 18px; font-size: 12px; color: var(--color-text-muted); }
.status-stack { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; margin-top: 10px; }

/* ---------- Empty states, steps, job ---------- */
.empty { text-align: left; padding: 48px; }
.empty .card-title { font-size: 24px; }
.steps { list-style: none; padding: 0; margin: 0; display: grid; gap: 16px; counter-reset: step; }
.steps li { display: flex; gap: 16px; align-items: flex-start; counter-increment: step; }
.steps li::before {
  content: counter(step); flex: none; width: 28px; height: 28px; border-radius: 50%;
  background: var(--color-accent-light); color: var(--color-primary); display: grid; place-items: center;
  font: 600 13px var(--font-mono);
}
.steps strong { color: var(--color-text-primary); display: block; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 24px; align-items: start; }
.narrow { max-width: 720px; }
.spinner { width: 40px; height: 40px; border-radius: 50%; border: 3px solid var(--color-accent-light); border-top-color: var(--color-accent); animation: spin 900ms linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.job { display: flex; gap: 24px; align-items: flex-start; }
.job-details { margin: 16px 0 0; padding: 0; list-style: none; font-size: 14px; }
.job-details li { padding: 8px 0; border-top: 1px solid var(--color-border); }
.definition { display: grid; grid-template-columns: max-content 1fr; gap: 8px 24px; font-size: 14px; margin: 0; }
.definition dt { color: var(--color-text-muted); }
.definition dd { margin: 0; color: var(--color-text-primary); }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .content { padding: 32px 32px 64px; }
  .topbar { padding: 0 32px; }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; gap: 8px; padding: 12px 16px; overflow-x: auto; }
  .brand { padding: 0 8px 0 0; font-size: 16px; }
  .brand-text { display: none; }
  .sidebar-nav { flex-direction: row; }
  .nav { flex-direction: row; }
  .nav-bottom { margin-top: 0; padding-bottom: 0; }
  .nav a { padding: 8px 12px; border-left: 0; border-bottom: 3px solid transparent; border-radius: var(--radius-md); white-space: nowrap; }
  .nav a[aria-current="page"] { border-bottom-color: var(--color-accent); }
  .sidebar-foot { display: none; }
  .topbar { padding: 0 16px; height: 56px; }
  .topbar-meta .org { display: none; }
  .content { padding: 24px 16px 64px; }
  h1 { font-size: 30px; }
  .kpis { gap: 12px; margin-bottom: 32px; }
  .kpi { padding: 16px; }
  .kpi-value { font-size: 26px; }
  .ring { width: 44px; height: 44px; }
  .card { padding: 24px; }
  .search { min-width: 0; width: 100%; }
  /* Tables become stacked cards */
  .table-card { background: transparent; border: 0; box-shadow: none; overflow: visible; }
  .stack-table thead { display: none; }
  .stack-table, .stack-table tbody, .stack-table tr, .stack-table td { display: block; width: 100% !important; }
  .stack-table tr { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); margin-bottom: 16px; overflow: hidden; }
  .stack-table td { border-bottom: 0; padding: 12px 20px; }
  .stack-table td:first-child { padding-top: 20px; }
  .stack-table td:last-child { padding-bottom: 20px; }
  .stack-table td[data-label]::before { content: attr(data-label); display: block; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--color-text-muted); margin-bottom: 4px; }
  .stack-table td.num { text-align: left; }
  .review-row .status-stack { flex-direction: row; flex-wrap: wrap; }
}

/* ---------- Fixes from the visual review ---------- */
.kpis > *, .grid-2 > * { margin-top: 0 !important; }   /* grid cells, not a stack */
h1, .cell-title, .qtext, .source-name, .breadcrumb [aria-current] { overflow-wrap: anywhere; }
.page-header > div:first-child { min-width: 0; }
.kpi > div:first-child { min-width: 0; }
@media (max-width: 860px) {
  .sidebar { gap: 4px; padding: 10px 12px; }
  .brand { padding-right: 4px; }
  .brand-mark { width: 28px; height: 28px; }
  .sidebar-nav, .nav { gap: 2px; }
  .nav a { gap: 6px; padding: 8px 10px; font-size: 14px; }
  .nav a svg { display: none; }
  .kpi { flex-wrap: wrap; align-items: flex-start; }
  .kpi-label { font-size: 11px; letter-spacing: .04em; }
  .ring { width: 36px; height: 36px; }
  .page-actions { width: 100%; }
  .page-actions form, .page-actions .btn { flex: 1 1 auto; }
  .page-actions form .btn { width: 100%; }
  .legend { gap: 12px; }
  .tabs { width: 100%; }
}
/* Skip link becomes visible for keyboard users */
a.visually-hidden:focus { position: fixed; top: 12px; left: 12px; width: auto; height: auto; clip: auto; z-index: 100; padding: 12px 20px; background: var(--color-surface); color: var(--color-primary); border-radius: var(--radius-pill); box-shadow: var(--shadow-lg); }
/* Tenant switcher and user in the topbar */
.org-switch select { min-height: 36px; padding: 6px 36px 6px 12px; font-size: 14px; width: auto; }
.topbar-meta form { margin: 0; }
.topbar-meta .user { color: var(--color-text-body); font-weight: 500; }
@media (max-width: 860px) { .topbar-meta .user { display: none; } }

/* ---------- Auth pages (checkout pattern: logo only, centred card max 480px) ---------- */
.auth-page { background: var(--color-surface-alt); min-height: 100vh; display: flex; flex-direction: column; }
.auth-nav { height: 64px; display: flex; align-items: center; padding: 0 32px; }
.auth-brand { display: inline-flex; align-items: center; gap: 12px; font: 600 18px var(--font-display); color: var(--color-primary); }
.auth-brand:hover { color: var(--color-primary); text-decoration: none; }
.auth-brand .brand-mark { background: var(--color-primary); color: var(--color-text-inverse); }
.auth-main { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 48px 16px 96px; }
.auth-card { width: 100%; max-width: 480px; box-shadow: var(--shadow-lg); }
.auth-card .btn-block { margin-top: 8px; }
.auth-title { font-size: 32px; font-weight: 700; margin-bottom: 12px; }
.auth-icon { width: 48px; height: 48px; border-radius: 50%; background: var(--color-accent-light); color: var(--color-primary-mid); display: grid; place-items: center; margin-bottom: 16px; }
.auth-trust { display: flex; gap: 8px; align-items: center; max-width: 480px; margin: 24px 0 0; font-size: 13px; color: var(--color-text-muted); }
.auth-trust svg { flex: none; }
input[type="email"] { width: 100%; min-height: 44px; padding: 10px 14px; font: 400 15px/1.5 var(--font-body); color: var(--color-text-primary); background: var(--color-surface); border: 1.5px solid var(--color-border); border-radius: var(--radius-sm); transition: border-color var(--transition-base), box-shadow var(--transition-base); }
/* Team page */
.section-title { font-size: 24px; margin: 48px 0 16px; }
.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form select { width: auto; min-width: 150px; }
/* Audit log */
input[type="date"] { width: 100%; min-height: 44px; padding: 10px 14px; font: 400 15px/1.5 var(--font-body); color: var(--color-text-primary); background: var(--color-surface); border: 1.5px solid var(--color-border); border-radius: var(--radius-sm); }
.filter-bar { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)) auto; gap: 16px; align-items: end; padding: 24px; margin-bottom: 24px; }
.filter-bar .field { margin-bottom: 0; }
.filter-actions { display: flex; gap: 8px; }
.pager { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.history { margin-top: 10px; }
.timeline { margin: 8px 0 0; padding-left: 18px; font-size: 12px; color: var(--color-text-body); }
.timeline li { margin-bottom: 4px; }
.timeline .mono { color: var(--color-text-muted); }
@media (max-width: 1100px) { .filter-bar { grid-template-columns: 1fr 1fr; } }
@media (max-width: 860px) { .filter-bar { grid-template-columns: 1fr; } }

/* Spacing utilities (8px grid) - replace inline style attributes, which the CSP forbids */
.m-0 { margin: 0; }
.mt-6 { margin-top: 6px; }
.mt-10 { margin-top: 10px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mt-48 { margin-top: 48px; }
.mb-48 { margin-bottom: 48px; }

/* Progress bar widths in 5 % steps (exact value is set by app.js from data-width) */
.progress > span.w-0 { width: 0%; }
.progress > span.w-5 { width: 5%; }
.progress > span.w-10 { width: 10%; }
.progress > span.w-15 { width: 15%; }
.progress > span.w-20 { width: 20%; }
.progress > span.w-25 { width: 25%; }
.progress > span.w-30 { width: 30%; }
.progress > span.w-35 { width: 35%; }
.progress > span.w-40 { width: 40%; }
.progress > span.w-45 { width: 45%; }
.progress > span.w-50 { width: 50%; }
.progress > span.w-55 { width: 55%; }
.progress > span.w-60 { width: 60%; }
.progress > span.w-65 { width: 65%; }
.progress > span.w-70 { width: 70%; }
.progress > span.w-75 { width: 75%; }
.progress > span.w-80 { width: 80%; }
.progress > span.w-85 { width: 85%; }
.progress > span.w-90 { width: 90%; }
.progress > span.w-95 { width: 95%; }
.progress > span.w-100 { width: 100%; }

/* htmx indicator (htmx's own inline <style> is disabled for the CSP) */
.htmx-indicator { opacity: 0; transition: opacity 200ms ease-in; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }

/* ---------- Quality-of-life features (D-022) ---------- */
/* Destructive action: error colour, outline only (the accent stays for interaction). */
.btn-danger { background: transparent; color: var(--color-error); border-color: var(--color-error); }
.btn-danger:hover { background: var(--color-error-bg); color: var(--color-error); }
.due-tag { margin-left: 8px; }
.filter-bar select { min-height: 44px; }
.scope-bar { grid-template-columns: minmax(0, 2fr) minmax(0, 1.5fr) minmax(0, 1fr) auto; }
.scope-bar .btn svg { margin-right: 2px; }

/* Bulk selection in the review table */
.bulk-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; margin-bottom: 24px;
  padding: 16px 20px; background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
}
.bulk-bar .checkbox { margin: 0; font-size: 14px; }
.bulk-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-left: auto; }
.bulk-actions select { width: auto; min-width: 200px; min-height: 36px; padding-top: 6px; padding-bottom: 6px; font-size: 14px; }
.bulk-count { font-size: 13px; color: var(--color-text-muted); }
.bulk-bar .hint { flex-basis: 100%; }
.select-item { display: inline-flex; margin: 0 0 8px; cursor: pointer; }
.select-item input { width: 18px; height: 18px; accent-color: var(--color-accent); margin: 0; }
.review-row.is-selected { background: var(--color-surface-alt); }

/* Assignee of a single question */
.assign { margin-top: 12px; }
.assign-form { display: flex; align-items: center; gap: 8px; }
.assign-form label { margin: 0; font-size: 12px; color: var(--color-text-muted); font-weight: 500; }
.assign-form select { width: auto; max-width: 100%; min-height: 32px; padding: 4px 32px 4px 10px; font-size: 13px; background-position: right 10px center; }

/* Unsaved edits and the question the reviewer moved on to */
.dirty-note { margin: 0; font-size: 12px; font-weight: 600; color: #8A5C14; } /* same as .tag-warning (contrast) */
.review-row.is-dirty { box-shadow: inset 3px 0 0 var(--color-warning); }
.review-row.is-current { background: var(--color-surface-alt); }

/* Evidence passage inside a source excerpt */
mark.evidence { background: var(--color-success-bg); color: var(--color-text-primary); border-radius: 3px; padding: 0 2px; box-decoration-break: clone; -webkit-box-decoration-break: clone; }

/* Questionnaire management */
.manage-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1.5fr) auto; gap: 16px; align-items: start; margin-top: 16px; }
.manage-grid .field { margin-bottom: 0; }
.manage-actions { padding-top: 30px; }
.danger-zone { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; margin-top: 32px; padding-top: 24px; border-top: 1px solid var(--color-border); }
.danger-zone form { display: grid; gap: 12px; justify-items: start; align-content: start; }
.danger-zone .checkbox { margin: 0; }

/* Knowledge base: usage, inline edit, document management */
.usage { margin-top: 8px; font-size: 12px; color: var(--color-text-muted); }
.usage .mono { font-size: 12px; }
.usage .tag { padding: 2px 8px; font-size: 11px; }
.edit-entry { margin-top: 10px; }

/* Row actions as round icon buttons (replace, delete) */
.row-actions { display: flex; justify-content: flex-end; align-items: center; gap: 6px; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: var(--radius-pill);
  border: 0; background: transparent; padding: 0; cursor: pointer;
  color: var(--color-text-muted); transition: background var(--transition-fast), color var(--transition-fast);
}
.icon-btn:hover { background: var(--color-surface-alt); color: var(--color-text-body); }
.icon-btn:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }
.icon-btn-danger { color: var(--color-error); }
.icon-btn-danger:hover { background: var(--color-error-bg); color: var(--color-error); }
.form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 24px; }

/* Modal: the replace/delete form over a blurred page (native <dialog>, opened by app.js) */
.modal {
  width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 64px); overflow: auto;
  padding: 40px; border: 0; border-radius: var(--radius-lg);
  background: var(--color-surface); color: var(--color-text-body); box-shadow: var(--shadow-xl);
}
.modal::backdrop { background: rgba(17, 27, 23, .32); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.modal[open] { animation: modal-in var(--transition-base); }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.modal-close { position: absolute; top: 16px; right: 16px; }
.modal-file { font-weight: 600; color: var(--color-text-primary); display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 12px; word-break: break-word; }
.modal-page { max-width: 640px; }
.modal-wide { width: min(880px, calc(100vw - 32px)); }

/* Document details (modal) */
.doc-detail .card-title { padding-right: 40px; overflow-wrap: anywhere; }
.doc-detail-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin: 0 0 20px; font-size: 13px; color: var(--color-text-muted); }
.doc-section { margin-top: 28px; }
.doc-section h3 { font-size: 16px; margin-bottom: 6px; }
.entry-group { margin-top: 12px; }
.entry-group > summary { margin-bottom: 8px; }
.entry-list, .usage-list, .chunk-list { list-style: none; margin: 0; padding: 0; }
.entry-list li { display: grid; gap: 2px; padding: 10px 0; border-top: 1px solid var(--color-border); font-size: 14px; }
.entry-q { font-weight: 600; color: var(--color-text-primary); }
.entry-a { color: var(--color-text-body); }
.usage-list li { padding: 6px 0; font-size: 14px; }
.chunks > summary { font-size: 15px; font-weight: 600; color: var(--color-text-primary); }
.chunk-search { margin: 12px 0; }
.chunk-list li { display: grid; gap: 4px; padding: 12px 0; border-top: 1px solid var(--color-border); }
.chunk-list li:first-child { border-top: 0; }
.chunk-loc { font-family: var(--font-mono); font-size: 12px; color: var(--color-text-muted); }
.chunk-text { font-size: 13px; white-space: pre-line; overflow-wrap: anywhere; }
.readability-tag { margin-left: 8px; padding: 2px 8px; font-size: 11px; text-decoration: none; }
body.has-modal { overflow: hidden; }
@media (max-width: 860px) { .modal { padding: 24px; } }

/* Document kind badges; for editors the badge itself is the <select> */
.kind-document { background: var(--color-surface-alt); color: var(--color-text-body); }
.kind-filled_questionnaire { background: var(--color-accent-light); color: var(--color-primary); }
.kind-policy { background: var(--kind-policy-bg); color: var(--kind-policy-fg); }
.kind-report { background: var(--kind-report-bg); color: var(--kind-report-fg); }
.kind-certificate { background: var(--kind-certificate-bg); color: var(--kind-certificate-fg); }
.kind-initiative { background: var(--kind-initiative-bg); color: var(--kind-initiative-fg); }
.kind-kpi { background: var(--kind-kpi-bg); color: var(--kind-kpi-fg); }
.kind-evidence { background: var(--kind-evidence-bg); color: var(--kind-evidence-fg); }
.kind-form { display: flex; align-items: center; gap: 8px; margin: 0; }
select.kind-select {
  width: auto; min-height: 0; padding: 4px 28px 4px 12px; border: 0;
  field-sizing: content; /* as wide as the chosen kind, where supported */
  border-radius: var(--radius-pill); font: 600 12px/1.4 var(--font-body);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%236B7E74' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center;
  transition: box-shadow var(--transition-fast);
}
select.kind-select:hover { box-shadow: 0 0 0 2px var(--color-border-strong); }
select.kind-select:focus { box-shadow: 0 0 0 3px rgba(64, 145, 108, .25); }

/* Document name: looks like text, becomes a field on click (Enter/leaving saves, Esc reverts) */
.name-form { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin: 0; }
.name-box {
  display: inline-flex; align-items: baseline; max-width: 100%;
  margin-left: -8px; padding: 2px 6px; border: 1.5px solid transparent; border-radius: var(--radius-sm);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.name-box:hover { border-color: var(--color-border); }
.name-box:focus-within { border-color: var(--color-accent); background: var(--color-surface); box-shadow: 0 0 0 3px rgba(64, 145, 108, .15); }
input.name-input, input.name-input:focus {
  width: auto; max-width: 100%; min-height: 0; field-sizing: content; min-width: 4ch;
  padding: 0; border: 0; border-radius: 0; box-shadow: none; outline: none;
  background: transparent; font: 600 15px/1.5 var(--font-body); color: var(--color-text-primary);
  cursor: text;
}
.name-suffix { flex: none; white-space: nowrap; overflow-wrap: normal; font: 600 15px/1.5 var(--font-body); color: var(--color-text-muted); }
.name-box { min-width: 0; flex-wrap: wrap; }
input.name-input { flex: none; }

/* Document table: every cell centred vertically; kind, sections and date also
   horizontally (on wide screens; stacked cards stay left-aligned) */
.doc-table tbody td { vertical-align: middle; }
@media (min-width: 861px) {
  .doc-table .cell-center { text-align: center; }
  .doc-table .cell-center .kind-form { justify-content: center; }
}

@media (max-width: 1100px) {
  .scope-bar, .manage-grid { grid-template-columns: 1fr 1fr; }
  .manage-actions { padding-top: 0; }
}
@media (max-width: 860px) {
  .scope-bar, .manage-grid, .danger-zone { grid-template-columns: 1fr; }
  .bulk-actions { margin-left: 0; width: 100%; }
  .bulk-actions select { flex: 1 1 100%; }
  .row-actions { justify-content: flex-start; }
}
