/* Components — tokens only. Each appears in /styleguide. */
h1, h2, h3 { font-family: var(--font-display); font-weight: 700; line-height: 1.2; }

/* Layout helpers */
.stack { display: flex; flex-direction: column; gap: var(--space-4); }
.row { display: flex; gap: var(--space-4); flex-wrap: wrap; }
.row-tight { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.row-between { display: flex; gap: var(--space-3); flex-wrap: wrap; align-items: center; justify-content: space-between; }
.page { max-width: var(--content-max); margin: 0 auto; padding: var(--space-4); }
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-3); padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-surface); background: var(--color-bg);
}
.app-header .brand { font-family: var(--font-display); font-weight: 700; font-size: var(--text-lg); }
.app-header.is-flush { border: 0; padding: 0; }

/* Buttons */
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  padding: 0 var(--space-4); border-radius: var(--radius-sm); border: 1px solid transparent;
  background: var(--color-surface); color: var(--color-text); cursor: pointer;
  font-weight: 600; transition: background var(--duration-fast) var(--ease);
}
.button:hover { background: color-mix(in srgb, var(--color-surface) 80%, var(--color-text) 8%); }
.button-primary { background: var(--color-primary); color: var(--color-on-primary, white); }
.button-primary:hover { background: color-mix(in srgb, var(--color-primary) 88%, black 12%); }
.button-danger { background: transparent; color: var(--color-danger); border-color: color-mix(in srgb, var(--color-danger) 40%, transparent); }
.button-danger:hover { background: color-mix(in srgb, var(--color-danger) 12%, transparent); }
.button:disabled { opacity: 0.5; cursor: not-allowed; }
.button[data-busy="true"]::after {
  content: ""; width: 0.8em; height: 0.8em; border: var(--border-emphasis) solid currentColor;
  border-right-color: transparent; border-radius: 50%; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Fields */
.field { display: flex; flex-direction: column; gap: var(--space-1); }
.field > span { font-size: var(--text-sm); color: var(--color-text-muted); }
.field input, .field select {
  min-height: var(--touch-target); padding: 0 var(--space-3);
  border: 1px solid color-mix(in srgb, var(--color-text) 20%, transparent);
  border-radius: var(--radius-sm); background: var(--color-bg); color: var(--color-text);
}
.field[data-error="true"] input, .field[data-error="true"] select { border-color: var(--color-danger); }
.error { color: var(--color-danger); font-size: var(--text-sm); }
.notice {
  font-size: var(--text-sm); color: var(--color-text-muted);
  background: var(--color-surface); border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
}

/* Card */
.card { background: var(--color-bg); border: 1px solid var(--color-surface); border-radius: var(--radius-md); padding: var(--space-4); box-shadow: var(--shadow-1); }

/* Status badge */
.badge { display: inline-block; padding: 0 var(--space-2); border-radius: var(--radius-sm); font-size: var(--text-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.badge[data-status="draft"]    { background: var(--color-surface); color: var(--color-text-muted); }
.badge[data-status="submitted"]{ background: color-mix(in srgb, var(--color-warning) 18%, var(--color-bg)); color: var(--color-warning); }
.badge[data-status="approved"] { background: color-mix(in srgb, var(--color-success) 18%, var(--color-bg)); color: var(--color-success); }
.badge[data-status="rejected"] { background: color-mix(in srgb, var(--color-danger) 18%, var(--color-bg)); color: var(--color-danger); }

/* Assessment list rows (cards on mobile) */
.list { list-style: none; padding: 0; display: grid; gap: var(--space-3); }
.list-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); text-decoration: none; color: inherit; }
.list-item { display: flex; align-items: center; gap: var(--space-3); }
.list-item .list-row { flex: 1; }
.list-delete { flex: none; }

/* SAIL display (signature) */
.sail-card { max-width: var(--panel-width); }
.sail { text-align: center; }
.sail .sail-label { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.08em; color: var(--color-text-muted); }
.sail .sail-value { font-family: var(--font-display); font-size: var(--text-2xl); font-weight: 800; line-height: 1; }
.sail-ramp { display: flex; gap: var(--space-1); margin: var(--space-2) 0; }
.sail-ramp span { flex: 1; height: var(--ramp-height); border-radius: var(--radius-xs); }
.sail-ramp span[data-active="true"] { outline: var(--border-emphasis) solid var(--color-primary); outline-offset: 1px; }

/* Determination chips */
.determinations { display: grid; gap: var(--space-2); }
.det { display: flex; justify-content: space-between; gap: var(--space-3); padding: var(--space-2) 0; border-bottom: 1px solid var(--color-surface); }
.det .det-value { font-variant-numeric: tabular-nums; font-weight: 600; }
.det[data-state="pending"] .det-value,
.det[data-state="out_of_scope"] .det-value { color: var(--color-text-muted); font-weight: 400; font-style: italic; }

/* Save-state indicator */
.save-state { font-size: var(--text-sm); display: inline-flex; align-items: center; gap: var(--space-2); }
.save-state[data-state="saved"]   { color: var(--color-success); }
.save-state[data-state="unsaved"] { color: var(--color-warning); }
.save-state[data-state="saving"]  { color: var(--color-text-muted); }
.save-state[data-state="error"]   { color: var(--color-danger); }

/* Empty state */
.empty { text-align: center; color: var(--color-text-muted); padding: var(--space-12) var(--space-4); }

/* Auth screen */
.auth { max-width: var(--auth-width); margin: var(--space-12) auto; padding: var(--space-4); }

/* Detail two-column (stacks on mobile, form first) */
.detail-grid { display: grid; gap: var(--space-6); }
@media (min-width: 768px) { .detail-grid { grid-template-columns: 1fr var(--panel-width); align-items: start; } }

/* Stepper rail */
.wizard { display: grid; gap: var(--space-4); }
/* Let grid children shrink below their content width so the rail's overflow-x:auto
   clips+scrolls internally instead of forcing page-level horizontal overflow on mobile. */
.wizard > * { min-width: 0; }
/* 3-column wizard only once rail (14rem) + panel (20rem) + a usable content/map
   column fit (--bp-tablet-landscape, 1024px). Below this the wizard stacks
   single-column so the map gets full width (iPad portrait at 768px was being
   squeezed to a ~190px middle column). CSS vars can't be used in @media, so the
   1024/1023px literals must track --bp-tablet-landscape in tokens.css. */
@media (min-width: 1024px) { .wizard { grid-template-columns: var(--rail-width) 1fr var(--panel-width); align-items: start; } }
.rail { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: var(--space-1); }
.rail-item {
  display: flex; align-items: center; gap: var(--space-2);
  min-height: var(--touch-target); padding: 0 var(--space-3);
  border-radius: var(--radius-sm); text-decoration: none; color: inherit;
  background: none; border: 0; width: 100%; cursor: pointer; text-align: left;
  font: inherit;
}
.rail-item:hover { background: var(--color-surface); }
.rail-item[aria-current="true"] { background: var(--color-surface); outline: var(--border-emphasis) solid var(--color-primary); outline-offset: -2px; }
.rail-dot { width: var(--dot-size); height: var(--dot-size); border-radius: 50%; flex: none; border: var(--border-emphasis) solid var(--color-text-muted); }
.rail-dot[data-state="done"]           { background: var(--color-success); border-color: var(--color-success); }
.rail-dot[data-state="needs_input"]    { background: var(--color-bg); border-color: var(--color-warning); }
.rail-dot[data-state="pending"]        { background: var(--color-bg); border-color: var(--color-text-muted); }
.rail-dot[data-state="derived"]        { background: var(--color-text-muted); border-color: var(--color-text-muted); }
.rail-dot[data-state="out_of_scope"]   { background: var(--color-bg); border-color: var(--color-danger); }
.rail-dot[data-state="needs_authority"]{ background: var(--color-warning); border-color: var(--color-warning); }
.rail-label { font-size: var(--text-sm); }
.rail-num { font-variant-numeric: tabular-nums; color: var(--color-text-muted); font-size: var(--text-xs); }
@media (max-width: 1023px) {
  .rail { flex-direction: row; overflow-x: auto; gap: var(--space-2); padding-bottom: var(--space-1); }
  .rail-item { width: auto; white-space: nowrap; }
}

/* Step frame */
.step-frame { display: flex; flex-direction: column; gap: var(--space-3); }
.step-frame-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; }
.status-chip { font-size: var(--text-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; padding: 0 var(--space-2); border-radius: var(--radius-sm); }
.status-chip[data-status="ok"]                        { background: color-mix(in srgb, var(--color-success) 18%, var(--color-bg)); color: var(--color-success); }
.status-chip[data-status="pending"]                   { background: var(--color-surface); color: var(--color-text-muted); }
.status-chip[data-status="out_of_scope"]              { background: color-mix(in srgb, var(--color-danger) 18%, var(--color-bg)); color: var(--color-danger); }
.status-chip[data-status="needs_authority_decision"]  { background: color-mix(in srgb, var(--color-warning) 18%, var(--color-bg)); color: var(--color-warning); }
.step-notes { font-size: var(--text-sm); color: var(--color-text-muted); margin: 0; padding-left: var(--space-4); }
.step-refs { font-size: var(--text-xs); color: var(--color-text-muted); }

/* Per-step Main Body reference: ? button + native <dialog> modal (spec 020) */
.ref-help {
  width: var(--space-6); height: var(--space-6); border-radius: 50%;
  border: 1px solid color-mix(in srgb, var(--color-text) 20%, transparent);
  background: var(--color-surface); color: var(--color-text-muted);
  font-weight: 700; cursor: pointer; line-height: 1; flex: 0 0 auto;
  margin-right: auto; /* keep ? next to the title; push the status chip to the right */
}
.ref-help:hover { color: var(--color-primary); }
.ref-modal {
  margin: auto; /* centre in the viewport — the global reset zeroes dialog margin */
  max-width: min(90vw, 42rem);
  border: 1px solid color-mix(in srgb, var(--color-text) 20%, transparent);
  border-radius: var(--radius-md);
  padding: var(--space-6); color: var(--color-text); background: var(--color-bg);
  box-shadow: var(--shadow-1);
}
.ref-modal::backdrop { background: rgb(0 0 0 / 0.4); }
.ref-modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--space-3); }
.ref-modal-head h3 { margin: 0; font-size: var(--text-lg); }
.ref-modal-close {
  border: none; background: none; cursor: pointer; color: var(--color-text-muted);
  font-size: var(--text-xl); line-height: 1; padding: 0; flex: 0 0 auto;
}
.ref-modal-close:hover { color: var(--color-text); }
.ref-modal-body { margin-top: var(--space-4); max-height: 60vh; overflow-y: auto; }
.ref-modal-body h4 { margin: var(--space-4) 0 var(--space-2); font-size: var(--text-sm); text-transform: uppercase; letter-spacing: 0.04em; color: var(--color-text-muted); }
.ref-modal-body p { margin: 0 0 var(--space-2); font-size: var(--text-sm); }

/* Bool toggle */
.toggle { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); min-height: var(--touch-target); }
.toggle > span { font-size: var(--text-sm); }
.toggle input { width: var(--checkbox-size); height: var(--checkbox-size); }

/* Field help text */
.field-help { font-size: var(--text-xs); color: var(--color-text-muted); }

/* OSO checklist */
.oso-group { margin: 0 0 var(--space-3); }
.oso-group h4 { font-size: var(--text-sm); margin: 0 0 var(--space-1); }
.oso-list { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--space-1); }
.oso-row { display: flex; justify-content: space-between; gap: var(--space-3); padding: var(--space-1) 0; border-bottom: 1px solid var(--color-surface); }
.oso-row .robustness { font-weight: 600; text-transform: capitalize; }
.oso-none { color: var(--color-text-muted); font-size: var(--text-sm); }

/* Step-9 OSO compliance card (Annex E criteria + operator record) */
.oso-compliance { border-top: 1px solid var(--color-surface); padding: var(--space-3) 0; }
.oso-compliance:first-child { border-top: 0; }
.oso-head { display: flex; justify-content: space-between; gap: var(--space-2); font-weight: 600; margin-bottom: var(--space-1); }
.oso-head .robustness { text-transform: capitalize; }
.oso-compliance details { margin: var(--space-1) 0; }
.oso-compliance summary { cursor: pointer; font-size: var(--text-sm); color: var(--color-text-muted); }
.oso-compliance h5 { font-size: var(--text-xs); margin: var(--space-1) 0 0; }
.oso-crit { font-size: var(--text-xs); color: var(--color-text-muted); margin: 0 0 var(--space-1); padding-left: var(--space-4); display: grid; gap: var(--space-1); }
.req-compliance { display: grid; gap: var(--space-2); padding: var(--space-3) 0; border-top: 1px solid var(--color-surface); }
.req-compliance:first-child { border-top: 0; }
.req-compliance .robustness { text-transform: capitalize; }

/* Requirement attachments (spec 025) */
.req-attachments { display: grid; gap: var(--space-2); }
.att-list { display: grid; gap: var(--space-1); }
.att-item { display: inline-flex; align-items: center; gap: var(--space-2); }
.att-size { color: var(--color-text-muted); font-size: var(--text-xs); }
.att-dl { background: none; border: 0; padding: 0; color: var(--color-primary); font: inherit; text-decoration: underline; cursor: pointer; }
.att-del { background: none; border: 0; padding: 0 var(--space-1); color: var(--color-text-muted); font-size: var(--text-md); line-height: 1; cursor: pointer; }
.att-upload { justify-self: start; }
.matrix-files { color: var(--color-text-muted); font-size: var(--text-xs); }

/* Geometry readout */
.geo { display: grid; gap: var(--space-1); }
.geo-row { display: flex; justify-content: space-between; gap: var(--space-3); }
.geo-row .geo-value { font-variant-numeric: tabular-nums; font-weight: 600; }

/* Document sections (CSP report) */
.doc-section { display: flex; flex-direction: column; gap: var(--space-2); }
.doc-section > h3 { margin: 0; }
.doc-grid { display: grid; gap: var(--space-1); }
.doc-row { display: flex; justify-content: space-between; gap: var(--space-3); }
.doc-row .doc-value { font-weight: 600; }

/* Compliance matrix table */
.matrix-wrap { overflow-x: auto; }
.matrix { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.matrix th, .matrix td { text-align: left; padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--color-surface); }
.matrix th { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.04em; color: var(--color-text-muted); }
.matrix td.required { text-transform: capitalize; font-weight: 600; }
.matrix-section th { text-align: left; background: var(--color-surface); font-weight: 700; text-transform: none; letter-spacing: normal; font-size: var(--text-sm); color: var(--color-text); }
.matrix-src { color: var(--color-text-muted); font-size: var(--text-sm); }
.matrix-status { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.04em; color: var(--color-text-muted); }
.matrix-status[data-status="compliant"] { color: var(--color-success); }

/* Status banners (stronger than .notice) */
.banner { padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); font-size: var(--text-sm); }
.banner-draft { background: color-mix(in srgb, var(--color-warning) 16%, var(--color-bg)); color: var(--color-warning); border: 1px solid var(--color-warning); }
.banner-ready { background: color-mix(in srgb, var(--color-success) 16%, var(--color-bg)); color: var(--color-success); border: 1px solid var(--color-success); }
.banner-draft strong, .banner-ready strong, .banner-reject strong { font-weight: 800; }

/* Submission action bar */
.submission { display: flex; flex-direction: column; gap: var(--space-3); }
.banner-reject { background: color-mix(in srgb, var(--color-danger) 16%, var(--color-bg)); color: var(--color-danger); border: 1px solid var(--color-danger); }
.submission textarea { resize: vertical; min-height: var(--touch-target); }

/* History — versions timeline */
.timeline { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--space-3); }
.timeline-entry { display: flex; flex-direction: column; gap: var(--space-2); }

/* History — audit trail */
.audit-log { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--space-1); }
.audit-line { padding: var(--space-2) 0; border-bottom: 1px solid var(--color-surface); font-size: var(--text-sm); }

/* Historical snapshot banner */
.banner-snapshot { background: var(--color-surface); color: var(--color-text-muted); border: 1px solid color-mix(in srgb, var(--color-text) 12%, transparent); }

/* Flight-geography map (Leaflet/Geoman vendored CSS is third-party, scoped to .fg-map) */
.fg-map { height: var(--map-height); width: 100%; border-radius: var(--radius-md); overflow: hidden; }
.fg-map .leaflet-container { height: 100%; width: 100%; }

/* Indeterminate spinner (raster download in progress) */
.spinner {
  display: inline-block; width: 1em; height: 1em; vertical-align: -0.15em;
  border: var(--border-emphasis) solid var(--color-surface); border-top-color: var(--color-primary);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Heatmap overlay: nearest-neighbour so block-reduced density cells stay crisp
   (smoothing would fade sparse populated cells to nothing when scaled down). */
.density-overlay { image-rendering: pixelated; }

/* Density band legend (swatch colours come from the server band palette) */
.density-legend { list-style: none; margin: var(--space-2) 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--space-2); font-size: var(--text-xs); }
.density-legend li { display: flex; align-items: center; gap: var(--space-1); }
.density-legend .swatch { width: var(--dot-size); height: var(--dot-size); border-radius: var(--radius-sm); display: inline-block; border: 1px solid var(--color-surface); }
