/* Danescor Profiling Service — demo page (PRD 15).
   System font stack only (no web fonts: the page must work offline), colour tokens with light and
   dark schemes via prefers-color-scheme, visible focus states, responsive down to 360 px. */

/* ------------------------------------------------------------------------------------- tokens */
:root {
  color-scheme: light dark;

  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", "Cascadia Code", "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #eef2f6;
  --border: #dde3ea;
  --border-strong: #c3ccd7;
  --text: #16202b;
  --text-muted: #566474;
  --text-faint: #7d8a99;

  --brand: #12305a;
  --brand-2: #1c4a85;
  --on-brand: #ffffff;
  --accent: #0b63c5;
  --accent-strong: #0a539f;
  --accent-soft: #e5effb;
  --on-accent: #ffffff;
  --highlight: #5cc8d6;

  --ok: #17784a;
  --ok-soft: #e1f3e9;
  --warn: #8f5a00;
  --warn-soft: #fcf1d8;
  --warn-strong: #c27c00;
  --danger: #b42318;
  --danger-soft: #fde7e5;
  --info: #2f55c4;
  --info-soft: #e7ecfd;
  --neutral: #4c5a69;
  --neutral-soft: #edf0f4;

  /* Provenance sources (PRD 12): one stable colour per source. */
  --src-input: #475569;
  --src-apollo: #6d28d9;
  --src-companies-house: #047857;
  --src-creditsafe: #0e7490;
  --src-llm: #b45309;
  --src-derived: #4338ca;
  --src-estimate: #be185d;
  --src-human: #1d4ed8;
  --src-existing: #64748b;

  --code-bg: #f6f8fb;
  --j-key: #0b4f9c;
  --j-str: #0a7a43;
  --j-num: #a14b00;
  --j-bool: #8a2bb5;
  --j-null: #7d8a99;

  --focus: #2b7de9;
  --radius: 12px;
  --radius-sm: 7px;
  --shadow-sm: 0 1px 2px rgba(16, 32, 54, 0.06);
  --shadow: 0 1px 3px rgba(16, 32, 54, 0.08), 0 6px 18px rgba(16, 32, 54, 0.06);
  --shadow-lg: 0 12px 40px rgba(10, 22, 40, 0.22);
  --gap: 16px;
  --nav-h: 48px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d131b;
    --surface: #141c26;
    --surface-2: #18212d;
    --surface-3: #1f2a37;
    --border: #2a3644;
    --border-strong: #3a4859;
    --text: #e4eaf1;
    --text-muted: #a2afbe;
    --text-faint: #7b8898;

    --brand: #0f2645;
    --brand-2: #1a3e6e;
    --accent: #4d9bf0;
    --accent-strong: #79b4f5;
    --accent-soft: #15304f;
    --on-accent: #06121f;

    --ok: #55c98b;
    --ok-soft: #113726;
    --warn: #f0b54c;
    --warn-soft: #3a2a0c;
    --warn-strong: #f0b54c;
    --danger: #ff8a7f;
    --danger-soft: #431714;
    --info: #8fa7ff;
    --info-soft: #1b2650;
    --neutral: #aab6c4;
    --neutral-soft: #222d3a;

    --src-input: #a3b1c2;
    --src-apollo: #b79cff;
    --src-companies-house: #4fd1a5;
    --src-creditsafe: #5ccfe6;
    --src-llm: #f6b25e;
    --src-derived: #a5b4fc;
    --src-estimate: #f9a8d4;
    --src-human: #93c5fd;
    --src-existing: #a3b1c2;

    --code-bg: #0f161f;
    --j-key: #8cc4ff;
    --j-str: #7fd6a2;
    --j-num: #f5b375;
    --j-bool: #d7a6f5;
    --j-null: #8492a3;

    --focus: #6aa8ff;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.45), 0 8px 24px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.6);
  }
}

/* --------------------------------------------------------------------------------------- base */
*, *::before, *::after { box-sizing: border-box; }

/* Components set display (flex, grid, inline-flex), which would otherwise override the attribute. */
[hidden] { display: none !important; }

html { scroll-padding-top: calc(var(--nav-h) + 12px); -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  overflow-x: hidden;
}

h1, h2, h3, h4, h5, h6 { margin: 0; line-height: 1.25; }
p { margin: 0; }
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-strong); }
code, pre, .mono { font-family: var(--font-mono); font-size: 0.86em; }
img { max-width: 100%; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline-offset: 0; }

.sr-only {
  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: -48px; z-index: 100;
  background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: var(--radius-sm); box-shadow: var(--shadow);
}
.skip-link:focus { top: 12px; }

.muted { color: var(--text-muted); }
.small { font-size: 0.82rem; }
.break { overflow-wrap: anywhere; word-break: normal; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.error-text { color: var(--danger); }
.dot { color: var(--text-faint); }

.stack { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.stack--tight { gap: 8px; }

/* ------------------------------------------------------------------------------------- header */
.app-header {
  background: linear-gradient(120deg, var(--brand) 0%, var(--brand-2) 100%);
  color: var(--on-brand);
}

.app-header__inner {
  max-width: 1480px; margin: 0 auto;
  padding: 16px 24px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 16px 24px;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand__mark { width: 40px; height: 40px; flex: none; border-radius: 9px; box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.18); }
.brand__name { font-size: 1.15rem; font-weight: 700; letter-spacing: 0.01em; }
.brand__tagline { font-size: 0.82rem; opacity: 0.82; }

.env { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-start; }
.app-header .badge { box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.12); }
.app-header .badge--neutral { background: rgba(255, 255, 255, 0.12); color: #e9eff7; border-color: transparent; }
.app-header .badge--ok { background: #d9f2e4; color: #0d5c37; border-color: transparent; }
.app-header .badge--info { background: #dfe8ff; color: #1f3c99; border-color: transparent; }
.app-header .badge--warn { background: #fdeccb; color: #7a4b00; border-color: transparent; }
.app-header .badge--danger { background: #ffdcd8; color: #9a1b12; border-color: transparent; }

.header-tools { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; justify-content: flex-end; }
.api-key { display: flex; align-items: center; gap: 8px; }
.api-key__label { font-size: 0.8rem; font-weight: 600; opacity: 0.9; white-space: nowrap; }
.api-key__control { display: flex; gap: 4px; }
.api-key .input { width: 200px; background: rgba(255, 255, 255, 0.96); color: #16202b; border-color: transparent; }
.api-key .input.is-invalid { box-shadow: 0 0 0 2px #ff8a7f; }
.api-key .btn--ghost { color: var(--on-brand); border-color: rgba(255, 255, 255, 0.35); }
.api-key .btn--ghost:hover { background: rgba(255, 255, 255, 0.12); }
.doc-links { display: flex; gap: 12px; }
.doc-links a { color: var(--on-brand); font-size: 0.86rem; font-weight: 600; text-decoration: none; padding: 4px 2px; border-bottom: 1px solid rgba(255, 255, 255, 0.4); }
.doc-links a:hover { border-bottom-color: var(--on-brand); color: var(--on-brand); }
.app-header :focus-visible { outline-color: #9cc9ff; }

.section-nav {
  position: sticky; top: 0; z-index: 30;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.section-nav ul {
  position: relative; list-style: none; margin: 0 auto; padding: 0 16px;
  max-width: 1480px; height: var(--nav-h);
  display: flex; gap: 4px; align-items: center;
  overflow-x: auto; scrollbar-width: none;
}
.section-nav ul::-webkit-scrollbar { display: none; }
.section-nav a {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: 999px;
  color: var(--text-muted); text-decoration: none; font-weight: 600; font-size: 0.88rem; white-space: nowrap;
}
.section-nav a:hover { background: var(--surface-3); color: var(--text); }
.section-nav__num {
  display: inline-grid; place-items: center;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent-strong); font-size: 0.75rem; font-weight: 700;
}
body.is-live .section-nav { border-bottom: 2px solid var(--danger); }

.noscript { max-width: 900px; margin: 24px auto; padding: 16px; background: var(--warn-soft); border-radius: var(--radius); }

/* ------------------------------------------------------------------------------------- layout */
.layout {
  max-width: 1480px; margin: 0 auto;
  padding: 24px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 24px;
  align-items: start;
}
.layout:focus { outline: none; }
.layout__main { display: flex; flex-direction: column; gap: 40px; min-width: 0; }
.layout__side {
  position: sticky; top: calc(var(--nav-h) + 16px);
  display: flex; flex-direction: column; gap: 24px;
  max-height: calc(100vh - var(--nav-h) - 32px); overflow-y: auto;
  padding-bottom: 8px; min-width: 0;
}

.section { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.section__header { display: flex; gap: 14px; align-items: flex-start; }
.section__header--compact { align-items: center; gap: 10px; }
.section__num {
  flex: none; display: grid; place-items: center;
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--brand); color: var(--on-brand); font-weight: 700; font-size: 1rem;
}
.section__header--compact .section__num { width: 28px; height: 28px; font-size: 0.9rem; border-radius: 8px; }
.section__title { font-size: 1.35rem; font-weight: 700; }
.section--side .section__title { font-size: 1.05rem; }
.section__lede { color: var(--text-muted); margin-top: 4px; max-width: 72ch; }
.section__action { margin-left: auto; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 18px;
  min-width: 0;
}

.app-footer { max-width: 1480px; margin: 0 auto; padding: 8px 24px 40px; color: var(--text-faint); font-size: 0.82rem; }

/* -------------------------------------------------------------------------------------- forms */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field--inline { flex-direction: row; align-items: center; gap: 8px; }
.field__label { font-size: 0.82rem; font-weight: 600; color: var(--text-muted); }
.field__optional { font-weight: 500; color: var(--text-faint); font-size: 0.75rem; margin-left: 4px; }

.input {
  font: inherit; font-size: 0.92rem;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 8px 10px; min-height: 38px; width: 100%; min-width: 0;
}
.input::placeholder { color: var(--text-faint); }
.input:hover { border-color: var(--text-faint); }
.input:focus { border-color: var(--focus); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 30%, transparent); }
.input.is-invalid, .input[aria-invalid="true"] { border-color: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 18%, transparent); }
.input:disabled { opacity: 0.6; cursor: not-allowed; }
.input--mono { font-family: var(--font-mono); font-size: 0.86rem; }
.input--narrow { width: 7.5rem; }
.input--select { width: auto; max-width: 100%; padding-right: 28px; cursor: pointer; }
.input--search { width: 220px; }
.input--group { width: auto; }

.btn {
  font: inherit; font-size: 0.9rem; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 7px 16px;
  border-radius: var(--radius-sm); border: 1px solid transparent;
  cursor: pointer; white-space: nowrap;
  transition: background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn--primary { background: var(--accent); color: var(--on-accent); }
.btn--primary:hover:not(:disabled) { background: var(--accent-strong); }
.btn--secondary { background: var(--surface-3); color: var(--text); border-color: var(--border-strong); }
.btn--secondary:hover:not(:disabled) { background: var(--border); }
.btn--ghost { background: transparent; color: var(--text); border-color: var(--border-strong); }
.btn--ghost:hover:not(:disabled) { background: var(--surface-3); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--danger:hover:not(:disabled) { filter: brightness(0.92); }
.btn--small { min-height: 30px; padding: 4px 10px; font-size: 0.82rem; }
.btn--large { min-height: 42px; padding: 9px 24px; font-size: 1rem; }
.btn.is-busy { cursor: progress; }
.btn.is-busy::before {
  content: ""; width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin 0.8s linear infinite;
}

.checkbox { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 0.88rem; cursor: pointer; }

.status-line { font-size: 0.86rem; color: var(--text-muted); min-height: 1.3em; }
.status-line--error { color: var(--danger); font-weight: 600; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0; }
.toolbar--end { justify-content: flex-end; }
.toolbar__spacer { flex: 1 1 auto; }

.segmented { display: inline-flex; background: var(--surface-3); border-radius: 999px; padding: 3px; gap: 2px; }
.segmented--wrap { flex-wrap: wrap; border-radius: 12px; }
.segmented__item {
  font: inherit; font-size: 0.8rem; font-weight: 600;
  border: none; background: transparent; color: var(--text-muted);
  padding: 4px 12px; border-radius: 999px; cursor: pointer; white-space: nowrap;
}
.segmented__item[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.segmented__item:hover { color: var(--text); }

/* switch: a checkbox styled as a toggle (keyboard and screen readers get a native checkbox, role=switch) */
.switch {
  appearance: none; -webkit-appearance: none;
  flex: none; position: relative; margin: 2px 0 0;
  width: 38px; height: 22px; border-radius: 999px;
  background: var(--border-strong); cursor: pointer;
  transition: background-color 0.15s ease;
}
.switch::before {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s ease;
}
.switch:checked { background: var(--accent); }
.switch:checked::before { transform: translateX(16px); }

.toggle { display: flex; gap: 12px; align-items: flex-start; padding: 8px 0; }
.toggle__label { display: flex; flex-direction: column; gap: 1px; cursor: pointer; min-width: 0; }
.toggle__name { display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: 0.92rem; }
.toggle__hint { color: var(--text-muted); font-size: 0.8rem; }
.toggle--prominent { padding: 10px 12px; border-radius: var(--radius-sm); background: var(--info-soft); margin-bottom: 8px; }
.toggle--prominent .toggle__name { font-size: 1rem; }
body.is-live .toggle--prominent { background: var(--danger-soft); }
.field--web-mode { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field--web-mode .input--select { width: 100%; }

.providers { border: none; margin: 0; padding: 0; }
.providers__legend { font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-faint); padding: 0; margin: 6px 0 2px; }
.providers__list { display: flex; flex-direction: column; }
.providers__list .toggle + .toggle { border-top: 1px solid var(--border); }

.note { margin-top: 10px; font-size: 0.8rem; color: var(--text-muted); }
.note--danger { color: var(--danger); font-weight: 600; }

/* --------------------------------------------------------------------------- badges and chips */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px; border-radius: 999px;
  font-size: 0.74rem; font-weight: 650; line-height: 1.5;
  border: 1px solid transparent; white-space: nowrap;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis;
}
.badge--ok { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.badge--warn { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn-strong) 30%, transparent); }
.badge--danger { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.badge--info { background: var(--info-soft); color: var(--info); border-color: color-mix(in srgb, var(--info) 25%, transparent); }
.badge--neutral { background: var(--neutral-soft); color: var(--neutral); border-color: var(--border); }
.badge--accent { background: var(--accent-soft); color: var(--accent-strong); }
.badge--code { font-family: var(--font-mono); font-weight: 600; font-size: 0.72rem; }
.badge__count { opacity: 0.8; font-weight: 700; }
.badge-row { display: inline-flex; flex-wrap: wrap; gap: 4px; align-items: center; }

.chip {
  display: inline-flex; align-items: center;
  padding: 1px 8px; border-radius: 6px;
  background: var(--surface-3); color: var(--text-muted);
  font-size: 0.78rem; border: 1px solid var(--border);
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip--mono { font-family: var(--font-mono); font-size: 0.74rem; }
.chip--sample { color: var(--text); background: var(--surface-2); max-width: 16rem; }
.chip--robots { background: var(--warn-soft); color: var(--warn); }
.chip--button { cursor: pointer; font: inherit; font-size: 0.8rem; color: var(--accent-strong); background: var(--accent-soft); border-color: transparent; padding: 3px 10px; }
.chip--button:hover { border-color: var(--accent); }
.chip-row { display: inline-flex; flex-wrap: wrap; gap: 4px; max-width: 100%; min-width: 0; }
.chip-button { border: none; background: none; padding: 0; cursor: pointer; border-radius: 999px; }
.chip-button.is-active .badge { box-shadow: 0 0 0 2px var(--accent); }

/* provenance source badge */
.src {
  --c: var(--src-input);
  display: inline-flex; align-items: center; gap: 5px;
  padding: 1px 8px 1px 6px; border-radius: 6px;
  font-size: 0.74rem; font-weight: 650; white-space: nowrap;
  color: var(--c);
  background: color-mix(in srgb, var(--c) 11%, transparent);
  border: 1px solid color-mix(in srgb, var(--c) 30%, transparent);
}
.src::before { content: ""; width: 7px; height: 7px; border-radius: 2px; background: var(--c); }
.src--input { --c: var(--src-input); }
.src--apollo { --c: var(--src-apollo); }
.src--companies-house { --c: var(--src-companies-house); }
.src--creditsafe { --c: var(--src-creditsafe); }
.src--llm { --c: var(--src-llm); }
.src--derived { --c: var(--src-derived); }
.src--estimate { --c: var(--src-estimate); }
.src--human { --c: var(--src-human); }
.src--existing { --c: var(--src-existing); }

/* column-mapping source chip */
.msrc {
  --c: var(--src-existing);
  display: inline-flex; padding: 1px 8px; border-radius: 999px;
  font-size: 0.74rem; font-weight: 650; white-space: nowrap;
  color: var(--c); background: color-mix(in srgb, var(--c) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--c) 30%, transparent);
}
.msrc--dictionary { --c: var(--src-companies-house); }
.msrc--known-out-of-contract { --c: var(--src-existing); }
.msrc--llm { --c: var(--src-llm); }
.msrc--cache { --c: var(--src-creditsafe); }
.msrc--user { --c: var(--src-human); }
.msrc--none { --c: var(--danger); }

/* confidence */
.conf { display: inline-flex; padding: 1px 7px; border-radius: 6px; font-size: 0.74rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.conf--ok { color: var(--ok); background: var(--ok-soft); }
.conf--low { color: var(--warn); background: var(--warn-soft); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--warn-strong) 45%, transparent); }

.meter { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.meter__track { position: relative; width: 64px; height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.meter__fill { position: absolute; inset: 0 auto 0 0; width: var(--v, 0%); background: var(--ok); border-radius: inherit; }
.meter__value { font-size: 0.8rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.meter--low .meter__fill { background: var(--warn-strong); }
.meter--low .meter__value { color: var(--warn); }

/* ------------------------------------------------------------------------------ notices, misc */
.notice {
  border-radius: var(--radius-sm); padding: 10px 14px;
  border: 1px solid var(--border); background: var(--surface-2); font-size: 0.9rem;
}
.notice--ok { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
.notice--warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn-strong) 35%, transparent); }
.notice--danger { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.notice--info { background: var(--info-soft); border-color: color-mix(in srgb, var(--info) 25%, transparent); }
.notice .plain-list { margin-top: 6px; }

.empty { color: var(--text-muted); font-size: 0.88rem; font-style: italic; }
.explain { color: var(--text-muted); font-size: 0.88rem; }
.explain--danger { color: var(--danger); }
.mini-title { font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 8px; }

.plain-list { margin: 0; padding-left: 18px; }
.plain-list li + li { margin-top: 2px; }
.plain-list--numbered { padding-left: 22px; }
.plain-list--numbered li { padding-left: 4px; }

.legend { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.legend__item { display: inline-flex; align-items: center; }

.kv { display: grid; grid-template-columns: minmax(8rem, max-content) minmax(0, 1fr); gap: 4px 16px; margin: 0; font-size: 0.9rem; }
.kv dt { color: var(--text-muted); font-size: 0.84rem; }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.fact-row { display: flex; flex-wrap: wrap; gap: 10px 26px; }
.fact { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.fact__label { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-faint); }
.fact__value { font-size: 0.92rem; overflow-wrap: anywhere; }

.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 12px 0; }
.tiles--row { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin: 0; }
.tile { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px; min-width: 0; }
.tile__label { display: block; font-size: 0.72rem; color: var(--text-faint); font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; }
.tile__value { display: block; font-size: 1.05rem; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.tile--accent { grid-column: 1 / -1; background: var(--accent-soft); border-color: transparent; }
.tile--accent .tile__value { font-size: 1.6rem; color: var(--accent-strong); }
.usage__scope-title { font-weight: 600; font-size: 0.88rem; margin-top: 10px; overflow-wrap: anywhere; }

.loading { display: flex; align-items: center; gap: 12px; color: var(--text-muted); }
.spinner {
  width: 18px; height: 18px; flex: none; border-radius: 50%;
  border: 2.5px solid var(--accent); border-right-color: transparent;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------------------------------ tables */
.table-wrap { position: relative; overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); max-width: 100%; }
.table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.table th, .table td { padding: 8px 10px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
.table thead th {
  background: var(--surface-2); color: var(--text-muted);
  font-size: 0.74rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  white-space: nowrap; position: sticky; top: 0; z-index: 1;
}
.table tbody tr:last-child > * { border-bottom: none; }
.table tbody tr:hover > * { background: color-mix(in srgb, var(--surface-3) 55%, transparent); }
.table th.num, .table td.num { text-align: right; }
.table tbody th { font-weight: 500; }
.table__empty { color: var(--text-muted); font-style: italic; text-align: center !important; padding: 16px !important; }
.table-wrap--compact .table th, .table-wrap--compact .table td { padding: 6px 8px; }
.table-wrap--compact .table { font-size: 0.8rem; }

.cell-stack { display: flex; flex-direction: column; gap: 3px; align-items: flex-start; min-width: 0; }
.num > .cell-stack { align-items: flex-end; }

.row--low > * { background: color-mix(in srgb, var(--warn-soft) 70%, transparent); }
.row--low > :first-child { box-shadow: inset 3px 0 0 var(--warn-strong); }
.row--edited > :first-child { box-shadow: inset 3px 0 0 var(--src-human); }
.row--pinned > * { background: color-mix(in srgb, var(--ok-soft) 70%, transparent); }
.row--robots > * { background: color-mix(in srgb, var(--warn-soft) 40%, transparent); }

/* ------------------------------------------------------------------------- code and JSON views */
.code {
  position: relative; margin: 0; padding: 12px 14px;
  background: var(--code-bg); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-family: var(--font-mono); font-size: 0.8rem; line-height: 1.55;
  max-height: 420px; overflow: auto;
  white-space: pre-wrap; overflow-wrap: anywhere; tab-size: 2;
}
.code--tall { max-height: 640px; }
.code--json { white-space: pre; overflow-wrap: normal; }
.j-key { color: var(--j-key); }
.j-str { color: var(--j-str); }
.j-num { color: var(--j-num); }
.j-bool { color: var(--j-bool); font-weight: 600; }
.j-null { color: var(--j-null); font-style: italic; }

.code-input {
  display: block; width: 100%; min-height: 260px; margin: 12px 0 0;
  padding: 12px 14px; resize: vertical;
  font-family: var(--font-mono); font-size: 0.82rem; line-height: 1.55;
  color: var(--text); background: var(--code-bg);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  tab-size: 2; white-space: pre; overflow-wrap: normal;
}
.code-input:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 30%, transparent); }
.contract-actions { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; margin-top: 12px; }
.contract-result:not(:empty) { margin-top: 16px; display: flex; flex-direction: column; gap: 12px; }

/* ------------------------------------------------------------------------------ disclosures */
.disclosure { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); min-width: 0; }
.disclosure__summary {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; cursor: pointer; list-style: none;
  font-weight: 600; font-size: 0.88rem; border-radius: var(--radius-sm);
}
.disclosure__summary::-webkit-details-marker { display: none; }
.disclosure__summary::before {
  content: ""; flex: none; width: 7px; height: 7px;
  border-right: 2px solid var(--text-muted); border-bottom: 2px solid var(--text-muted);
  transform: rotate(-45deg); transition: transform 0.15s ease; margin-right: 2px;
}
.disclosure[open] > .disclosure__summary::before { transform: rotate(45deg); }
.disclosure__summary:hover { background: var(--surface-2); }
.disclosure__title { min-width: 0; overflow-wrap: anywhere; }
.disclosure__meta { margin-left: auto; color: var(--text-faint); font-size: 0.78rem; font-weight: 600; white-space: nowrap; }
.disclosure__body { padding: 4px 12px 12px; min-width: 0; }
.disclosure--inline { border: none; background: transparent; }
.disclosure--inline > .disclosure__summary { padding: 2px 0; font-size: 0.8rem; color: var(--accent); }
.disclosure--inline > .disclosure__body { padding: 4px 0 0; }

/* ------------------------------------------------------------------------- section 1: input */
.single-form { display: flex; flex-direction: column; gap: 14px; }
.single-form__fields { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1.3fr) minmax(0, 0.9fr) auto; gap: 12px; align-items: end; }
.single-form__footer { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 16px; }
.examples { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.examples__label { font-size: 0.8rem; color: var(--text-faint); font-weight: 600; }

.result:empty { display: none; }

/* ------------------------------------------------------------------------- section 1: result */
.chain-result { display: flex; flex-direction: column; gap: 18px; min-width: 0; }

.result-summary {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; display: flex; flex-direction: column; gap: 16px;
  border-top: 4px solid var(--accent);
}
.result-summary__head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 12px; }
.result-summary__title { min-width: 0; }
.result-summary__name { font-size: 1.6rem; font-weight: 750; overflow-wrap: anywhere; }
.result-summary__meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 4px; color: var(--text-muted); font-size: 0.88rem; }
.result-summary__verdict .badge { font-size: 0.86rem; padding: 5px 14px; }
.result-summary__issues { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }

.stage-strip { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.stage { position: relative; min-width: 0; }
.stage__button {
  width: 100%; display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 4px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-muted);
  font: inherit; font-size: 0.76rem; font-weight: 650; cursor: pointer; min-width: 0;
}
.stage__button:disabled { cursor: default; }
.stage__button:hover:not(:disabled) { border-color: var(--accent); }
.stage__icon {
  display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  font-size: 0.85rem; font-weight: 800; background: var(--neutral-soft); color: var(--neutral);
}
.stage__label { text-align: center; line-height: 1.2; overflow-wrap: anywhere; }
.stage--done .stage__icon { background: var(--ok); color: #fff; }
.stage--done .stage__button { color: var(--text); }
.stage--warn .stage__icon { background: var(--warn-strong); color: #fff; }
.stage--warn .stage__button { color: var(--text); border-color: color-mix(in srgb, var(--warn-strong) 45%, transparent); }
.stage--error .stage__icon { background: var(--danger); color: #fff; }
.stage--error .stage__button { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.stage--off .stage__button { opacity: 0.6; border-style: dashed; }

.chain { display: flex; flex-direction: column; }
.step { display: grid; grid-template-columns: 40px minmax(0, 1fr); gap: 0 14px; }
.step__rail { position: relative; display: flex; justify-content: center; }
.step__rail::before { content: ""; position: absolute; top: 34px; bottom: 0; width: 2px; background: var(--border); }
.step:last-child .step__rail::before { display: none; }
.step__marker {
  position: relative; z-index: 1;
  display: grid; place-items: center; width: 32px; height: 32px; margin-top: 14px;
  border-radius: 50%; background: var(--surface); color: var(--accent-strong);
  border: 2px solid var(--accent); font-weight: 750; font-size: 0.92rem;
}
.step__content {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); padding: 16px 18px; margin-bottom: 14px; min-width: 0;
}
.step__header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.step__title { font-size: 1.08rem; font-weight: 700; }
.step__lede { color: var(--text-muted); font-size: 0.86rem; margin: 4px 0 12px; max-width: 80ch; }
.step__body { min-width: 0; }

.subcard { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); min-width: 0; }
.subcard__header { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.subcard__title { font-size: 0.95rem; font-weight: 700; }
.subcard__body { padding: 12px 14px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.subcard .table-wrap, .subcard .disclosure { background: var(--surface); }

.reasons { margin: 0; padding-left: 16px; font-size: 0.8rem; }
.reasons li + li { margin-top: 1px; }

.score { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.score__track { position: relative; width: 90px; height: 8px; background: var(--surface-3); border-radius: 999px; }
.score__fill { position: absolute; inset: 0 auto 0 0; width: var(--v, 0%); border-radius: inherit; background: var(--text-faint); }
.score--pass .score__fill { background: var(--ok); }
.score__threshold { position: absolute; top: -3px; bottom: -3px; left: var(--t, 60%); width: 2px; background: var(--text); opacity: 0.6; }
.score__value { font-weight: 750; font-variant-numeric: tabular-nums; }

.answer { display: flex; flex-direction: column; gap: 14px; }
.answer__block { display: flex; flex-direction: column; gap: 6px; }
.answer__label { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 0.86rem; }
.quote {
  margin: 0; padding: 10px 14px; border-left: 3px solid var(--src-llm);
  background: color-mix(in srgb, var(--src-llm) 7%, var(--surface)); border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  overflow-wrap: anywhere;
}
.quote--evidence { border-left-color: var(--text-faint); background: var(--surface-2); font-style: italic; }
.evidence { margin: 0; display: flex; flex-direction: column; gap: 4px; }

/* mapped profile */
.field-table .group-row th {
  background: var(--surface-3); color: var(--text-muted);
  font-size: 0.72rem; font-weight: 750; text-transform: uppercase; letter-spacing: 0.06em; padding: 6px 10px;
}
.field-name { min-width: 10rem; }
.field-name__label { display: block; font-weight: 600; }
.field-name__path { display: block; color: var(--text-faint); font-size: 0.72rem; }
.value { overflow-wrap: anywhere; }
.value--long { margin: 0; max-width: 60ch; line-height: 1.55; }
.value--dropped { text-decoration: line-through; text-decoration-color: var(--warn-strong); color: var(--text-muted); }
.field-table tr.is-empty .field-name__label { color: var(--text-muted); font-weight: 500; }
.field-table.hide-empty tr.is-empty { display: none; }
.field-table td:nth-child(2) { min-width: 12rem; }
.field-table td:nth-child(3) { min-width: 11.5rem; }
.field-table td:nth-child(4) { min-width: 10rem; }
.alt-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.alt-list li { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.profile-section { min-width: 0; }

/* issues */
.issue-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.issue { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 12px; background: var(--surface-2); }
.issue__head { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.issue__detail { margin-top: 4px; font-size: 0.88rem; overflow-wrap: anywhere; }

/* timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline__item { display: grid; grid-template-columns: 5.5rem 16px minmax(0, 1fr); gap: 10px; align-items: start; padding: 4px 0; position: relative; }
.timeline__item::after { content: ""; position: absolute; left: calc(5.5rem + 10px + 7px); top: 18px; bottom: -6px; width: 2px; background: var(--border); }
.timeline__item:last-child::after { display: none; }
.timeline__time { font-family: var(--font-mono); font-size: 0.78rem; color: var(--text-muted); text-align: right; padding-top: 1px; }
.timeline__dot { width: 12px; height: 12px; margin: 4px 2px; border-radius: 50%; background: var(--accent); position: relative; z-index: 1; box-shadow: 0 0 0 3px var(--surface); }
.timeline__body { display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline; font-size: 0.88rem; min-width: 0; }
.timeline__message { overflow-wrap: anywhere; }

/* ------------------------------------------------------------------------------- section 2 */
.stepper { list-style: none; margin: 0; padding: 0; display: flex; gap: 8px; flex-wrap: wrap; counter-reset: none; }
.stepper__item {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 14px 6px 6px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border);
  font-size: 0.86rem; font-weight: 600; color: var(--text-muted);
}
.stepper__dot { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--surface-3); font-size: 0.78rem; font-weight: 750; }
.stepper__item[data-state="current"] { border-color: var(--accent); color: var(--text); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent); }
.stepper__item[data-state="current"] .stepper__dot { background: var(--accent); color: var(--on-accent); }
.stepper__item[data-state="done"] { color: var(--text); }
.stepper__item[data-state="done"] .stepper__dot { background: var(--ok); color: #fff; }
.stepper__item[data-state="ready"] .stepper__dot { background: var(--accent-soft); color: var(--accent-strong); }

.upload-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.upload { display: flex; flex-direction: column; gap: 12px; }
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 112px; padding: 16px; text-align: center; cursor: pointer;
  border: 2px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface-2);
  transition: border-color 0.12s ease, background-color 0.12s ease;
}
.dropzone:hover, .dropzone.is-dragover { border-color: var(--accent); background: var(--accent-soft); }
.dropzone:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
.dropzone.has-file { border-style: solid; border-color: var(--accent); }
.dropzone__title { font-weight: 700; }
.dropzone__hint { font-size: 0.82rem; color: var(--text-muted); overflow-wrap: anywhere; }
.upload__row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
.upload__row .field--inline .input { width: 12rem; }
.open-batch { display: flex; flex-direction: column; gap: 6px; }
.open-batch__row { display: flex; gap: 6px; }
.open-batch__row .input { flex: 1 1 auto; width: 100%; }

.batch-panel { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.panel-title { font-size: 1.05rem; font-weight: 700; }

.map-summary { display: flex; flex-direction: column; gap: 8px; }
.mapping-table { max-height: 640px; overflow: auto; }
.mapping-table .table { min-width: 1000px; }
.mapping-table td:last-child { min-width: 13rem; }
.map-column { min-width: 12rem; max-width: 18rem; }
.map-column__name { display: block; font-weight: 600; }
.map-column__annotation { display: block; margin-top: 4px; color: var(--text-muted); font-style: italic; overflow-wrap: anywhere; }
.map-target { min-width: 15rem; }
.map-target__controls { display: flex; flex-wrap: wrap; gap: 6px; }
.map-target__controls .input--select { max-width: 15rem; }
.map-target__controls .input--group { max-width: 7.5rem; }
.map-target__desc { display: block; margin-top: 4px; }
.row--note .map-target__desc { font-style: italic; }

.fin-panel { border: 1px solid color-mix(in srgb, var(--warn-strong) 40%, transparent); border-radius: var(--radius-sm); background: var(--warn-soft); padding: 12px 14px; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.fin-panel__legend { font-weight: 700; padding: 0 6px; }
.fin-panel__grid { display: flex; flex-wrap: wrap; gap: 12px 20px; }
.fin-panel .input { background: var(--surface); }

.run-card { display: flex; flex-direction: column; gap: 16px; }
.run-card__controls { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; }
.run-card__settings { flex: 1 1 14rem; font-size: 0.86rem; color: var(--text-muted); }
.run-card__buttons { display: flex; gap: 8px; }
.progress-area:empty { display: none; }
.progress-area { display: flex; flex-direction: column; gap: 10px; border-top: 1px solid var(--border); padding-top: 14px; }
.progress-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.progress-head__file { font-weight: 600; }
.live-dot { display: inline-flex; align-items: center; gap: 6px; font-size: 0.78rem; font-weight: 700; color: var(--ok); text-transform: uppercase; letter-spacing: 0.05em; }
.live-dot::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.25; } }
.progress { height: 10px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.progress__fill { display: block; height: 100%; width: var(--v, 0%); background: linear-gradient(90deg, var(--accent), var(--highlight)); border-radius: inherit; transition: width 0.4s ease; }
.count-chips { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.count-chip { display: inline-flex; align-items: center; gap: 5px; color: var(--text-muted); }
.stage-bars { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 6px 28px; }
.stage-bar { display: grid; grid-template-columns: 8.5rem minmax(0, 1fr) 4.5rem; align-items: center; gap: 8px; font-size: 0.82rem; }
.stage-bar__track { height: 6px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.stage-bar__fill { display: block; height: 100%; width: var(--v, 0%); background: var(--accent); border-radius: inherit; }
.stage-bar__value { font-variant-numeric: tabular-nums; color: var(--text-muted); text-align: right; }

.exception-chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.rows-table { max-height: 620px; overflow: auto; }
.rows-table .table { min-width: 760px; }
.row-company { min-width: 12rem; }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions .btn + .btn { margin-left: 4px; }
.export-result:not(:empty) { display: flex; flex-direction: column; gap: 10px; }

/* ----------------------------------------------------------------------------------- drawer */
.drawer {
  padding: 0; border: none; margin: 0 0 0 auto;
  width: min(1040px, 100vw); max-width: 100vw;
  height: 100vh; height: 100dvh; max-height: 100vh; max-height: 100dvh;
  background: var(--bg); color: var(--text);
  box-shadow: var(--shadow-lg);
}
.drawer[open] { display: flex; flex-direction: column; animation: slide-in 0.18s ease-out; }
.drawer::backdrop { background: rgba(8, 16, 28, 0.5); }
@keyframes slide-in { from { transform: translateX(32px); opacity: 0.6; } }
.drawer__header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.drawer__title { font-size: 1.15rem; font-weight: 700; overflow-wrap: anywhere; min-width: 0; }
.drawer__actions { display: flex; gap: 8px; flex: none; }
.drawer__body { position: relative; flex: 1 1 auto; overflow-y: auto; padding: 18px 20px 40px; display: flex; flex-direction: column; gap: 16px; }
.drawer__meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.drawer__inputs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.drawer__panel { min-width: 0; }
.drawer__panel .table-wrap { max-height: 320px; overflow: auto; }

/* ----------------------------------------------------------------------------------- toasts */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 12px 10px 14px; border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
  border: 1px solid var(--border); border-left: 4px solid var(--info);
  font-size: 0.88rem; animation: toast-in 0.18s ease-out;
}
.toast--ok { border-left-color: var(--ok); }
.toast--warn { border-left-color: var(--warn-strong); }
.toast--danger { border-left-color: var(--danger); }
.toast__text { flex: 1 1 auto; overflow-wrap: anywhere; }
.toast__close { border: none; background: none; color: var(--text-muted); font-size: 1.1rem; line-height: 1; cursor: pointer; padding: 0 2px; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* ------------------------------------------------------------------------------- responsive */
@media (max-width: 1180px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .layout__side { position: static; order: -1; max-height: none; overflow: visible; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
  .app-header__inner { grid-template-columns: 1fr auto; }
  .env { grid-column: 1 / -1; grid-row: 2; }
}

@media (max-width: 900px) {
  .single-form__fields { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .single-form__actions { grid-column: 1 / -1; }
  .single-form__actions .btn { width: 100%; }
  .upload-grid { grid-template-columns: minmax(0, 1fr); }
  .stage-strip { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .drawer__inputs { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 720px) {
  body { font-size: 14.5px; }
  .layout { padding: 16px; gap: 20px; }
  .layout__main { gap: 32px; }
  .layout__side { grid-template-columns: minmax(0, 1fr); }
  .app-header__inner { grid-template-columns: minmax(0, 1fr); padding: 14px 16px; }
  .env { grid-row: auto; }
  .header-tools { justify-content: flex-start; }
  .api-key { flex-wrap: wrap; width: 100%; }
  .api-key__control { flex: 1 1 auto; }
  .api-key .input { width: 100%; }
  .section__title { font-size: 1.2rem; }
  .card { padding: 14px; }
  .single-form__fields { grid-template-columns: minmax(0, 1fr); }
  .result-summary { padding: 16px; }
  .result-summary__name { font-size: 1.35rem; }
  .step { grid-template-columns: 28px minmax(0, 1fr); gap: 0 8px; }
  .step__marker { width: 26px; height: 26px; font-size: 0.8rem; }
  .step__rail::before { top: 30px; }
  .step__content { padding: 12px; }
  .kv { grid-template-columns: minmax(0, 1fr); gap: 0; }
  /* Data tables keep readable columns and scroll inside their wrapper instead of squeezing. */
  .table-wrap:not(.table-wrap--compact) > .table { min-width: 34rem; }
  .drawer__panel .table-wrap > .table { min-width: 0; }
  .kv dd { margin-bottom: 6px; }
  .input--search { width: 100%; }
  .timeline__item { grid-template-columns: 4.5rem 16px minmax(0, 1fr); }
  .timeline__item::after { left: calc(4.5rem + 10px + 7px); }
  .stage-bar { grid-template-columns: 6.5rem minmax(0, 1fr) auto; }
  .drawer__header { padding: 12px 14px; flex-wrap: wrap; }
  .drawer__body { padding: 14px 14px 32px; }
  .app-footer { padding: 8px 16px 32px; }
}

@media (max-width: 420px) {
  .stage-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .tiles--row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field--inline { flex-direction: column; align-items: stretch; }
  .upload__row .field--inline .input { width: 100%; }
  .upload__row .btn { width: 100%; }
  .run-card__buttons, .run-card__buttons .btn { width: 100%; }
  .contract-actions .btn { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}

@media print {
  .app-header, .section-nav, .layout__side, .toasts, .single-form, .toolbar { display: none !important; }
  .layout { display: block; }
}

/* Danescor profile (Data Requirement layout): the main output on the single-company view. */
.danescor-profile { border-left: 4px solid var(--accent); }
.danescor-profile .toolbar { align-items: center; }
.danescor-profile .table-wrap { max-height: 70vh; }
.row--empty > * { color: var(--text-muted); }
