@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=Manrope:wght@400;500;600;700;800&family=DM+Mono:wght@400;500&display=swap');
@import url('tokens.css');

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

/* App-wide blueprint-grid backdrop (Pippit promo video reference, 2026-08-12):
   the same faint grid .blueprint-panel already uses, but as a constant wash
   behind every screen instead of an opt-in per-card accent - matches the
   video's blueprint-backdrop-behind-every-mockup mood. Solid card
   backgrounds (--bg-raised) sit on top so it only shows in the gaps. */
body {
  background: var(--bg);
  background-image:
    linear-gradient(color-mix(in srgb, var(--pascal-green) 6%, transparent) 1px, transparent 1px),
    linear-gradient(90deg, color-mix(in srgb, var(--pascal-green) 6%, transparent) 1px, transparent 1px);
  background-size: 28px 28px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--step-0);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

/* :not(.btn) on every rule below: a button-styled anchor (<a class="btn
   btn-primary">) must keep .btn-primary/.btn-ghost's own text colour, not
   the plain-link colour - without the exclusion, these `a` rules
   out-specificity .btn-primary's single class selector and paint teal link
   text onto a near-identical teal button background, unreadable in light
   mode (e.g. "Open evidence portfolio" on account.html). */
a:not(.btn) { color: var(--pascal-blue-bright); }
:root[data-theme="light"] a:not(.btn) { color: var(--pascal-blue); }
/* Un-set data-theme (no stored preference yet - the common case on first
   run) must fall back on the OS's actual preference, not assume light -
   without this guard, :not([data-theme="dark"]) matches ANY unset theme
   and wins on specificity over .btn-primary's on-accent color, which is
   exactly the bug that made "Start your route" unreadable: the light-mode
   link colour (#0096B7) landing on a dark-mode cyan button (#00B4D8) it
   nearly matches. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) a:not(.btn) { color: var(--pascal-blue); }
}

h1, h2, h3, .display {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.1;
}

.mono { font-family: var(--font-mono); letter-spacing: 0.01em; }

:focus-visible {
  outline: 2px solid var(--pascal-green);
  outline-offset: 2px;
}

.container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 var(--space-4);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: var(--step-0);
  padding: 1rem 1.7rem;
  border-radius: 999px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--pascal-green); color: var(--on-accent); }
.btn-primary:hover { background: var(--pascal-green-dim); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { border-color: var(--text-muted); }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Uniform-size tile grid - buttons of unequal text length otherwise render
   as unequal-size boxes (e.g. registration milestones on the account page).
   Equal-width columns + stretch make every tile in the row the same size. */
.tile-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2); align-items: stretch; }
.tile-row > * { min-width: 0; }
.tile-row .btn { height: 100%; text-align: center; white-space: normal; line-height: 1.35; }
@media (max-width: 480px) { .tile-row { grid-template-columns: 1fr; } }

/* ── Cards / surfaces ── */
/* Soft colour glow under every card (video reference: glowing rings/panels
   on a dark ground) - reads off --accent-color when a card sets one (see
   .rtr-action-card), falls back to the default teal otherwise. */
.card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  box-shadow: var(--shadow), 0 0 40px -16px color-mix(in srgb, var(--accent-color, var(--pascal-green)) 45%, transparent);
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: var(--step--1);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--pascal-green-text);
}

/* ── Forms ── */
label { display: block; font-size: var(--step--1); color: var(--text-muted); margin-bottom: var(--space-1); }
input, select, textarea {
  width: 100%;
  background: var(--bg-raised-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-md);
  padding: 0.75rem 0.9rem;
  font-family: var(--font-body);
  font-size: var(--step-0);
}
/* Checkboxes/radios must stay their native small size - width:100% above
   stretches an invisible hit-box across the whole row while the visible
   tick stays tiny on the left, leaving a huge dead gap before its label
   text (e.g. the outcome checklist on the Engineering Report page). */
input[type="checkbox"], input[type="radio"] { width: auto; }
input:focus, select:focus, textarea:focus { border-color: var(--pascal-blue-bright); }
.field { margin-bottom: var(--space-3); }
/* Side-by-side field pairs (.grid-2/3/4) stretch every item to the row's
   tallest cell - a longer label wrapping to 2 lines otherwise pushes just
   that one input down, misaligning it against its neighbour's input. Bottom-
   aligning each field's own content keeps every input in the row level. */
.grid-2 > .field, .grid-3 > .field, .grid-4 > .field { display: flex; flex-direction: column; justify-content: flex-end; }
.form-error { color: var(--danger); font-size: var(--step--1); margin-top: var(--space-1); min-height: 1.2em; }

/* ── Top nav ── */
.topnav {
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
}
.topnav-inner { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: var(--space-2); padding: var(--space-2) var(--space-4); max-width: 1180px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 0.6rem; font-family: var(--font-display); font-weight: 700; font-size: var(--step-1); text-decoration: none; color: var(--text); }
.brand-mark { width: 28px; height: 28px; flex-shrink: 0; }
.nav-links { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-3); row-gap: 0.5rem; }
.nav-links a:not(.btn) { color: var(--text-muted); text-decoration: none; font-size: var(--step--1); font-weight: 500; }
.nav-links a:not(.btn):hover, .nav-links a:not(.btn).active { color: var(--text); }

@media (max-width: 640px) {
  .topnav-inner { padding: var(--space-2) var(--space-3); }
  .nav-links { gap: var(--space-2); row-gap: 0.5rem; width: 100%; }
}

/* ── Responsive grid utilities ── */
/* Default gap so tile grids are equally spaced app-wide without every
   caller having to remember an inline override - a page-specific inline
   `gap:` (e.g. a tighter form-field pair) still wins over this default. */
.grid-hero { display: grid; grid-template-columns: 1.1fr 1fr; gap: var(--space-4); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-4); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-4); }
/* Grid items default to min-width:auto, sized to their content's
   intrinsic minimum - on a tablet-width 3/4-column layout, a card's own
   text refuses to shrink below that and forces its track wider than its
   1fr share, overlapping the next column. min-width:0 lets it wrap
   instead. Invisible on narrow single-column mobile, where there's
   already room, which is why this only shows up on wider screens. */
.grid-hero > *, .grid-2 > *, .grid-3 > *, .grid-4 > * { min-width: 0; }

@media (max-width: 760px) {
  .grid-hero, .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}
@media (min-width: 761px) and (max-width: 980px) {
  .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

/* ── Waypoint status chips (route map) ── */
.chip { font-family: var(--font-mono); font-size: var(--step--1); padding: 0.15rem 0.55rem; border-radius: var(--radius-sm); }
.chip-done { background: color-mix(in srgb, var(--contour-green) 22%, transparent); color: var(--contour-green-text); }
.chip-active { background: color-mix(in srgb, var(--pascal-green) 20%, transparent); color: var(--pascal-green-text); }
.chip-upcoming { background: var(--bg-raised-2); color: var(--text-muted); }

/* ── K53-style numbered step system ──────────────────────────────────
   Borrows the visual language of South Africa's K53 driving-manual: a
   bold numbered/lettered circle badge per step in a sequence, connected
   by a line, colour-coded by where you are in it. Used for any ordered
   procedure - landing-page "how it works", the onboarding wizard, the
   Degree-of-Responsibility ladder, the outcome checklist, and route
   waypoints - so the same "step 1 of N" visual reads consistently
   everywhere in the app. */
.k53-badge {
  display: inline-flex; align-items: center; justify-content: center;
  flex: none; width: 2.1rem; height: 2.1rem; border-radius: 999px;
  font-family: var(--font-mono); font-weight: 700; font-size: var(--step-0);
  border: 2px solid currentColor; transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.k53-badge.tone-done { color: var(--contour-green-text); background: color-mix(in srgb, var(--contour-green) 18%, transparent); }
.k53-badge.tone-active { color: var(--pascal-green-text); background: color-mix(in srgb, var(--pascal-green) 18%, transparent); }
.k53-badge.tone-milestone { color: var(--karoo-ochre-text); background: color-mix(in srgb, var(--karoo-ochre) 18%, transparent); }
.k53-badge.tone-upcoming { color: var(--text-muted); background: var(--bg-raised-2); border-color: var(--border); }
.k53-badge.sm { width: 1.6rem; height: 1.6rem; font-size: var(--step--1); border-width: 1.5px; }

/* Vertical stepper - a rail of badges connected by a line, body text to the right */
.k53-step { display: flex; gap: var(--space-3); }
.k53-step-rail { display: flex; flex-direction: column; align-items: center; flex: none; }
.k53-step-rail .k53-line { flex: 1; width: 2px; background: var(--border); min-height: var(--space-2); }
.k53-step:last-child .k53-step-rail .k53-line { display: none; }
.k53-step-body { padding-bottom: var(--space-4); flex: 1; min-width: 0; }

/* Horizontal stepper - badges in a row connected by a line (wizard-style flows) */
.k53-steps-h { display: flex; align-items: center; }
.k53-steps-h .k53-line-h { flex: 1; height: 2px; background: var(--border); min-width: 1rem; margin: 0 0.4rem; }

/* ── Error banner (window.rtrShowError) ── */
.rtr-error-banner {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-2);
  background: var(--danger); color: #fff;
  padding: 0.7rem var(--space-4);
  font-size: var(--step--1); font-weight: 500;
}
.rtr-error-banner button {
  background: transparent; border: none; color: #fff; font-size: 1.3rem; line-height: 1;
  cursor: pointer; padding: 0 0.3rem;
}

/* ── Icon tiles / badges (landing-page smart-art accents) ── */
.icon-tile {
  width: 44px; height: 44px; border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-raised-2); margin-bottom: var(--space-2);
}
.icon-badge {
  width: 56px; height: 56px; border-radius: 999px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.8rem; margin-bottom: var(--space-2);
}

/* ── Blueprint & Drafting Instruments (signature theme) ──────────────
   .blueprint-panel: faint drafting-grid texture for hero/summary cards -
   used sparingly (one or two per page, never every card) so it reads as a
   deliberate accent, not wallpaper. Pair with a .blueprint-mark crosshair
   (an inline SVG dropped in the corner) and .instrument-icon svgs for the
   hand-drawn compass/set-square/level iconography. Screen-only: reports
   strip all of this under @media print - a real ECSA submission stays a
   plain document, not a themed one. */
.blueprint-panel {
  position: relative;
  overflow: hidden;
  background-image:
    linear-gradient(color-mix(in srgb, var(--pascal-green) 10%, transparent) 1px, transparent 1px),
    linear-gradient(90deg, color-mix(in srgb, var(--pascal-green) 10%, transparent) 1px, transparent 1px);
  background-size: 24px 24px;
}
.blueprint-mark { position: absolute; top: var(--space-2); right: var(--space-2); width: 20px; height: 20px; opacity: 0.4; color: var(--pascal-green); pointer-events: none; }
.instrument-icon { width: 32px; height: 32px; flex: none; stroke: currentColor; stroke-width: 1.75; fill: none; stroke-linecap: round; stroke-linejoin: round; }
/* Compact variant for an icon sitting inline next to a card's own h2/h3
   heading (account.html's section headers, etc.) - the default size above
   is for a page's single big H1 icon, too large next to in-card heading text. */
.instrument-icon.sm { width: 20px; height: 20px; }

/* Dimension-line stat - a value flanked by tick marks, like a measurement
   callout on a technical drawing. Use for headline numbers you want to
   read as "measured", not just displayed. */
.dimension-stat { display: flex; align-items: center; gap: 0.5rem; }
.dimension-stat .dim-tick { width: 1px; height: 10px; background: var(--karoo-ochre); flex: none; }
.dimension-stat .dim-rule { flex: 1; height: 1px; background: color-mix(in srgb, var(--karoo-ochre) 55%, transparent); min-width: 0.75rem; }
.dimension-stat .dim-label { font-family: var(--font-mono); font-size: var(--step--1); color: var(--text-muted); white-space: nowrap; }

@media print {
  body { background-image: none; }
  .blueprint-panel { background-image: none; }
  .blueprint-mark { display: none; }
}

.no-print { }
@media print {
  .no-print { display: none !important; }
}

/* ── App chrome: X-style top bar + bottom tab bar ──────────────────
   Replaces the old per-page horizontal .topnav link list. Injected once
   by rtrRenderAppChrome() (assets/js/ui.js) into every authenticated app
   page - body gets .rtr-has-chrome for the top/bottom safe-area padding.
   Both bars carry .no-print so neither appears in Print/Save-as-PDF output.
   Icon <svg> elements also carry explicit width/height XML attributes (set
   in ui.js, not just here) as a defense-in-depth belt-and-braces measure -
   see service-worker.js's CACHE version comment for the stale-cache bug
   this guards against: if CSS ever fails to load, an unstyled <svg> with no
   width/height attribute renders at the browser's oversized intrinsic
   default instead of collapsing to 0, which is exactly what shipped once.
   No backdrop-filter here (2026-08-12): both bars are fixed and always
   on-screen, so blur() was resampling everything scrolling underneath on
   every frame - measurably part of the Android WebView scroll jank found
   during the perf pass (see PLAY-STORE-LAUNCH.md-adjacent perf notes).
   Dropped in favour of the same solid-ish color-mix background alone,
   which reads almost identically at 88-94% opacity without the per-frame
   resample cost. */
body.rtr-has-chrome { padding-top: 58px; padding-bottom: 64px; }

.rtr-topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 30; height: 58px;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 0 var(--space-3);
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  border-bottom: 1px solid var(--border);
}
.rtr-topbar-start { justify-self: start; }
.rtr-topbar-center { justify-self: center; display: flex; align-items: center; gap: 0.4rem; }
.rtr-topbar-end { justify-self: end; }
/* Circle behind the logo, matching .rtr-avatar's own badge treatment
   (same background + border ring) rather than a flat white fill - a
   plain navy-on-transparent mark reads as decoration, not a button, in
   dark mode without some kind of badge around it. */
.rtr-topbar-center a {
  display: flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 999px; flex: none;
  background: var(--bg-raised-2);
  border: 1px solid var(--border);
}
.rtr-topbar-logo { width: 26px; height: 26px; flex: none; display: block; }

.rtr-avatar {
  width: 34px; height: 34px; border-radius: 999px; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-raised-2); color: var(--text);
  font-family: var(--font-display); font-weight: 700; font-size: 0.85rem;
  border: 1px solid var(--border); overflow: hidden; text-decoration: none;
}
.rtr-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Legal/info link, top right - same badge treatment as the avatar and
   topbar logo so all three chrome buttons read as one family. */
.rtr-topbar-info {
  display: flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 999px; flex: none;
  background: var(--bg-raised-2); border: 1px solid var(--border);
  color: var(--text-muted); text-decoration: none;
}
.rtr-topbar-info:hover { color: var(--text); }

/* Bottom bar: icon-only (no visible labels), matching the X app reference -
   each tab still carries aria-label/title for screen readers and long-press
   tooltips even without on-screen text. */
.rtr-bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; height: 64px;
  display: flex; align-items: stretch; justify-content: space-around;
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.rtr-tab {
  flex: 1; min-width: 0; display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); text-decoration: none; background: none; border: none; cursor: pointer;
}
.rtr-tab svg { width: 28px; height: 28px; stroke: currentColor; stroke-width: 1.8; fill: none; stroke-linecap: round; stroke-linejoin: round; display: block; }
.rtr-tab.active { color: var(--pascal-green); }

/* Page action row (Print / Share) - replaces the buttons that used to live
   in each report page's nav bar. .no-print hides it from the PDF output. */
.rtr-action-row { display: flex; gap: var(--space-2); flex-wrap: wrap; margin: var(--space-4) 0; justify-content: center; }

/* ── Centered-by-default headings (uniform look across the app) ────────
   Every card's own heading and lead-in description centers by default.
   Structured content - lists, tables, form fields, logged entries - is
   nested deeper than a direct child, so the `>` combinator leaves it
   alone: centering a bullet list or a form field is a readability bug,
   not a style choice, regardless of how the surrounding card looks. */
.card > h1, .card > h2, .card > h3 { text-align: center; }
.card > h1.row, .card > h2.row, .card > h3.row { justify-content: center; }
/* Page-header icon+title rows (icon <svg> + h1.display inside a centered
   .row): a centered flex item still left-aligns its OWN wrapped lines, so
   a two-line title looks off-center without this - the row's own
   justify-content:center only centers the icon+title as a group. */
.row > h1.display, .row > h2.display, .row > h3.display { text-align: center; }
.card > p.muted { text-align: center; }

/* ── Utility ── */
.stack { display: flex; flex-direction: column; gap: var(--space-3); }
.row { display: flex; align-items: center; gap: var(--space-2); }
.muted { color: var(--text-muted); }
.center-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: var(--space-4); }
.skip-link { position: absolute; left: -9999px; }
.skip-link:focus { left: var(--space-2); top: var(--space-2); background: var(--pascal-green); color: var(--on-accent); padding: 0.6rem 1rem; border-radius: var(--radius-sm); z-index: 100; }

/* ── ECSA print document ──────────────────────────────────────────────
   Printing the live editable form (input boxes, textareas, dropdowns)
   produces a screenshot of a web form, not a document - see
   assets/js/ecsa-print.js. Each report builds a typeset, bordered-table
   version of itself into a hidden sibling of <main>, appended directly
   to <body> (never nested inside <main> - see rtrSetPrintSheet), and
   print mode hides everything else and shows only that. Letterhead/
   table/signature-row conventions verified against ECSA's own R-03-TER-PE
   and R-03-TES-PE templates (2013 revision) - field content itself
   follows the current 2022 R-03-PRO-SC Rev 3 structure where the two
   differ (see report-engineering.js's research note). */
.ecsa-print-sheet { display: none; }
@media print {
  body > *:not(.ecsa-print-sheet) { display: none !important; }
  .ecsa-print-sheet { display: block !important; }
}
/* Branded document treatment (Pippit promo video reference, 2026-08-12):
   navy letterhead band + teal accent rules, matching the video's document
   mockup - GEC navy for anything text sits on (contrast), teal reserved for
   thin accent lines and light tints where it never carries body text.
   Still black-on-white for every actual field value: this is a real
   document a candidate submits to ECSA, not a marketing showpiece, so the
   branding stays at the edges (header band, rules, table-header tint)
   and never touches legibility of the content itself. print-color-adjust
   is required here - browsers drop background colours from print output
   by default unless told otherwise. */
.ecsa-doc {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 9.5pt;
  color: #111; max-width: 190mm; margin: 0 auto; line-height: 1.35;
  -webkit-print-color-adjust: exact; print-color-adjust: exact; color-adjust: exact;
}
.ecsa-doc table { width: 100%; border-collapse: collapse; margin-bottom: 10pt; page-break-inside: auto; }
.ecsa-doc th, .ecsa-doc td { border: 1px solid #0B1E3D; padding: 4pt 7pt; text-align: left; vertical-align: top; }
.ecsa-doc th { background: #E8F1F8; }
.ecsa-doc .ecsa-letterhead { text-align: center; font-weight: bold; padding: 9pt 8pt; font-size: 11pt; background: #0B1E3D; color: #fff; border-bottom: 3pt solid #00B4D8; letter-spacing: 0.01em; }
.ecsa-doc .ecsa-formno { text-align: right; font-size: 8.5pt; margin: 0 0 2pt; color: #0096B7; font-weight: bold; }
.ecsa-doc .ecsa-footer { font-size: 8pt; margin-top: 6pt; display: flex; justify-content: space-between; color: #444; }
.ecsa-doc h2 { font-size: 11pt; margin: 14pt 0 4pt; color: #0B1E3D; border-bottom: 2pt solid #00B4D8; padding-bottom: 2pt; }
.ecsa-doc p { margin: 0 0 6pt; }
.ecsa-doc .ecsa-sig-row td { height: 26pt; }
.ecsa-doc .ecsa-section { margin-bottom: 10pt; page-break-inside: avoid; }
.ecsa-doc .ecsa-label { font-weight: bold; font-size: 8.5pt; text-transform: uppercase; letter-spacing: 0.02em; display: block; margin-bottom: 2pt; color: #0096B7; }

/* ── Organogram chart (boxes + connecting line) - shared between the
   organogram builder page and the TER report/print sheet, since the TER's
   real ECSA form requires this as its own section, not just a text field. */
.org-chart { display: flex; flex-direction: column; align-items: center; padding: var(--space-3, 1rem) 0; }
.org-box { border: 1px solid var(--border, #ccc); border-radius: var(--radius-sm, 4px); padding: var(--space-2, 0.5rem) var(--space-3, 1rem); text-align: center; min-width: 200px; background: var(--bg-raised, #fff); }
.org-box.you { border-color: var(--pascal-blue-bright, #00B4D8); border-width: 2px; font-weight: 600; }
.org-link { width: 2px; height: 1.4rem; background: var(--pascal-blue-bright, #00B4D8); }
