/* Is It Approved?, "Signal Journey"
   Dark-first, theme-aware. Palette is defined as CSS custom properties in
   three passes: (1) light palette on bare :root, the default; (2) dark
   palette under a prefers-color-scheme media query, guarded so an explicit
   data-theme="light" always wins; (3) dark palette again under
   :root[data-theme="dark"] so an explicit toggle wins in both directions.
   See app/static/theme.js for the toggle itself. */

/* ---------- 1. Light palette (default) ---------- */
:root {
  --bg: #F7F9FB;
  --surface: #FFFFFF;
  --surface-2: #F0F4F8;
  --border: #DDE5EC;
  --text: #0F172A;
  --text-muted: #55677A;
  --accent: #059669;
  --accent-strong: #047857;
  --current: #D97706;
  --danger: #DC2626;

  /* Soft glows derived from --current/--accent/--danger, for rings and
     emphasis. Kept as explicit rgba (rather than color-mix()) for the
     widest browser support. */
  --current-glow: rgba(217, 119, 6, 0.20);
  --accent-glow: rgba(5, 150, 105, 0.16);
  --danger-glow: rgba(220, 38, 38, 0.16);

  /* Both palettes' --accent and --current are light/medium-bright colors;
     dark (near-black) text reads correctly on top of either in BOTH
     themes, verified against WCAG contrast math -- so this one token
     covers both without needing a themed variant. --on-danger DOES need a
     themed variant (see below): light-theme --danger is dark enough for
     white text, dark-theme --danger is too light for it. */
  --on-strong: #04140D;
  --on-danger: #FFFFFF;

  /* The hero artwork (hero-full.*) has a near-black background baked in.
     On the light theme that would read as a stray black rectangle dropped
     on a white page, so the hero sits it on a matching dark panel instead
     -- this literal value is chosen to match the artwork's own background
     closely (sampled ~#060D17) and is identical to the dark theme's --bg,
     so the "panel" look is consistent with what dark-theme users already
     see as their normal page background. */
  /* Light theme: NO full-bleed dark band. A hard-edged black stripe between
     a light header and light content reads as a rendering fault, not a
     design. Instead the dark artwork sits as a rounded, shadowed card on the
     light page, so it reads as a deliberate product visual. */
  --hero-panel-bg: transparent;
  --hero-art-shadow: 0 20px 45px -14px rgba(15, 23, 42, 0.38), 0 6px 14px -6px rgba(15, 23, 42, 0.18);
  --hero-art-ring: 1px solid rgba(15, 23, 42, 0.10);
  --hero-band-pad: 2.5rem 1.25rem 1rem;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.07);
  --shadow-md: 0 10px 30px rgba(15, 23, 42, 0.10);
}

/* ---------- 2. Dark palette via system preference ---------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0B0F14;
    --surface: #131A22;
    --surface-2: #1A232D;
    --border: #243040;
    --text: #E6EDF3;
    --text-muted: #8B9AAB;
    --accent: #34D399;
    --accent-strong: #10B981;
    --current: #FBBF24;
    --danger: #F87171;

    --current-glow: rgba(251, 191, 36, 0.22);
    --accent-glow: rgba(52, 211, 153, 0.18);
    --danger-glow: rgba(248, 113, 113, 0.20);

    --on-danger: #2A0B0B;

    /* In dark mode the page background already matches the artwork's own
       background, so the panel is set to --bg (not a fixed literal) -- it
       then simply disappears and the art reads as sitting straight on the
       page, no visible seam. */
    --hero-panel-bg: var(--bg);
    --hero-art-shadow: none;
    --hero-art-ring: none;
    --hero-band-pad: 2rem 1.25rem;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.45);
    --shadow-md: 0 12px 32px rgba(0, 0, 0, 0.5);
  }
}

/* ---------- 3. Dark palette via explicit toggle (wins both ways) ---------- */
:root[data-theme="dark"] {
  --bg: #0B0F14;
  --surface: #131A22;
  --surface-2: #1A232D;
  --border: #243040;
  --text: #E6EDF3;
  --text-muted: #8B9AAB;
  --accent: #34D399;
  --accent-strong: #10B981;
  --current: #FBBF24;
  --danger: #F87171;

  --current-glow: rgba(251, 191, 36, 0.22);
  --accent-glow: rgba(52, 211, 153, 0.18);
  --danger-glow: rgba(248, 113, 113, 0.20);

  --on-danger: #2A0B0B;

  --hero-panel-bg: var(--bg);
  --hero-art-shadow: none;
  --hero-art-ring: none;
  --hero-band-pad: 2rem 1.25rem;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.45);
  --shadow-md: 0 12px 32px rgba(0, 0, 0, 0.5);
}

/* ---------- Reset & base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; color-scheme: light dark; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
h1, h2, h3 { font-weight: 700; }
p { margin: 0 0 1rem; }
a { color: var(--accent-strong); }

/* Identifiers only: reference numbers, serial numbers, application numbers. */
.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.01em;
}

a:focus-visible, button:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Visually hidden but still present for screen readers/SEO crawlers -- the
   clip-path/clip technique keeps the element in the accessibility tree,
   unlike display:none or visibility:hidden which remove it entirely. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.container { max-width: 760px; margin: 0 auto; padding: 0 1.25rem 3rem; }

/* ---------- Header ---------- */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  max-width: 760px;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 0;
}
.wordmark {
  display: inline-flex;
  align-items: center;
  gap: .55rem;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.wordmark-mark {
  width: .55rem;
  height: .55rem;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  flex-shrink: 0;
}
.wordmark-text { overflow: hidden; text-overflow: ellipsis; }
/* The question mark is part of the brand identity, not punctuation --
   accented so "Is It Approved?" reads as a wordmark, not a sentence. */
.wordmark-q {
  color: var(--accent-strong);
  font-weight: 800;
}
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: .4rem .75rem;
  border-radius: 999px;
  font-size: .8rem;
  font-family: inherit;
  cursor: pointer;
}
.theme-toggle:hover { border-color: var(--accent); }
.theme-toggle-icon {
  width: .6rem;
  height: .6rem;
  border-radius: 50%;
  background: var(--current);
  flex-shrink: 0;
}

/* ---------- Footer ---------- */
.site-footer {
  max-width: 760px;
  margin: 2.5rem auto 1.5rem;
  padding: 1.25rem 1.25rem 0;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: .75rem;
  text-align: center;
}
.site-footer p { margin: 0 0 .4rem; }
.site-footer p:last-child { margin-bottom: 0; }
.site-footer-brand {
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}
.site-footer .disclaimer { color: var(--text-muted); }

/* ---------- Hero / search form (landing page) ----------
   Single-column, centred hero: the full marketing artwork (baked-in
   headline, tagline, trust icons and CTA) IS the hero, shown large and
   full-bleed; the real lookup form sits directly below it, centred and
   prominent; trust points and the privacy line follow as real text. The
   artwork's own headline/tagline are pixels, so a real (visually hidden)
   <h1> and a real, visible tagline paragraph carry that content for SEO
   and assistive tech -- see index.html. */
.hero { padding-top: 1.5rem; }

/* Full-bleed band: a direct child of <main> (which no longer carries
   .container -- see base.html), so this naturally spans the full page
   width with no vw/scrollbar arithmetic. --hero-panel-bg makes the
   artwork's near-black background look deliberate on the light theme; on
   dark it's set equal to --bg and the band disappears. */
.hero-art-band {
  background: var(--hero-panel-bg);
  padding: var(--hero-band-pad);
}

/* The artwork itself: no card frame (padding/border/shadow) -- it reads as
   the hero, not a thumbnail in a box. overflow:hidden + border-radius on
   the link clips the image to a softly rounded rect; line-height:0 removes
   the stray inline-image gap under the anchor. Capped at ~1180px so it
   stays a hero, not a full-viewport-wide banner, on very wide screens. */
.hero-art-link {
  display: block;
  max-width: 1180px;
  margin: 0 auto;
  border-radius: var(--radius-lg);
  overflow: hidden;
  line-height: 0;
  box-shadow: var(--hero-art-shadow);
  border: var(--hero-art-ring);
}
.hero-art-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
.hero-art {
  display: block;
  width: 100%;
  height: auto;
}

.hero-below { text-align: center; }
.hero-below.container { padding-top: 2rem; }

.hero-tagline {
  color: var(--text);
  font-size: clamp(1.05rem, 2.6vw, 1.3rem);
  font-weight: 500;
  line-height: 1.45;
  max-width: 52ch;
  margin: 0 auto 1.75rem;
}

.hero-form-wrap {
  max-width: 640px;
  margin: 0 auto;
  text-align: left;
  /* Breathing room above the form when the artwork's baked-in "CHECK YOUR
     STATUS" button jumps here via #check, so the form isn't flush against
     the viewport's top edge. */
  scroll-margin-top: 1.5rem;
}

.lookup-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.35rem;
  box-shadow: var(--shadow-sm);
  display: grid;
  gap: 1.1rem;
}

/* ---------- Application-type selector (segmented control) ----------
   Three plain radios, no JS: the visual "pill" look comes entirely from
   styling the (visually hidden but still focusable/clickable) native
   radios and their adjacent <label>s. Works with keyboard, screen
   readers, and with JS disabled -- see also the :has() rules below, which
   react to these same radios to hide the serial field / swap helper text
   for Competency, again with zero JS. */
.apptype-select { border: 0; padding: 0; margin: 0; }
.apptype-select legend {
  font-size: .85rem;
  font-weight: 600;
  color: var(--text);
  padding: 0;
  margin: 0 0 .5rem;
}
.segmented {
  display: inline-flex;
  flex-wrap: wrap;
  gap: .2rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .2rem;
}
.segmented input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.segmented label {
  padding: .45rem 1rem;
  border-radius: 999px;
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}
.segmented input[type="radio"]:checked + label {
  background: var(--accent);
  color: var(--on-strong);
}
.segmented input[type="radio"]:focus-visible + label {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.field { display: flex; flex-direction: column; gap: .4rem; }
.field label { font-size: .85rem; font-weight: 600; color: var(--text); }
.field .optional { font-weight: 400; color: var(--text-muted); }
.field input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: .75rem .85rem;
  font-size: 1rem;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.field input::placeholder { color: var(--text-muted); opacity: .65; }
.field input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Helper text under the reference field: one sentence shown at a time,
   picked purely by which apptype radio is currently checked. .hint-default
   is the fallback for browsers without :has() support (still one accurate,
   generic sentence -- never blank). */
.field-hint { display: none; margin: 0; font-size: .8rem; color: var(--text-muted); }
.hint-default { display: block; }
.lookup-form:has(.apptype-radio:checked) .hint-default { display: none; }
.lookup-form:has(#apptype-licence:checked) .hint-licence { display: block; }
.lookup-form:has(#apptype-competency:checked) .hint-competency { display: block; }
.lookup-form:has(#apptype-renewal:checked) .hint-renewal { display: block; }

/* Competency has no serial number field (SAPS's own rule: a competency
   enquiry takes the reference number only) -- hidden via :has() alone, no
   JS. Browsers without :has() simply keep showing the serial field, which
   is harmless: SAPS ignores an unused serial. */
.lookup-form:has(#apptype-competency:checked) .field-serial { display: none; }

.btn-primary {
  justify-self: start;
  background: var(--accent);
  color: var(--on-strong);
  border: 0;
  border-radius: var(--radius-md);
  padding: .85rem 1.5rem;
  font-size: 1rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
}
.btn-primary:hover { background: var(--accent-strong); }

#result { margin-top: .25rem; }

.privacy { color: var(--text-muted); font-size: .85rem; margin-top: 1.5rem; }

/* Below the form (per the redesigned single-column hero, see .hero-below in
   the Hero block above) -- centred via the flex row's own justify-content
   rather than relying on inherited text-align, so this reads correctly
   wherever else .trust-points might ever be reused. */
.trust-points {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: .5rem 1.4rem;
  margin: 2.25rem 0 0;
  padding: 0;
  font-size: .85rem;
  color: var(--text-muted);
}
.trust-points li {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
}
.trust-icon {
  width: 1.15rem;
  height: 1.15rem;
  color: var(--accent-strong);
  flex-shrink: 0;
}

/* ---------- Result: non-record states ---------- */
.state-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-top: 1.25rem;
}
.state-card h2 { margin: 0 0 .5rem; font-size: 1.1rem; }
.state-card p:last-child { margin-bottom: 0; }
.state-card ul { margin: .5rem 0 0; padding-left: 1.2rem; color: var(--text-muted); }
.state-card ul li { margin-bottom: .3rem; }
.state-card.state-error { border-color: var(--danger); }

/* ---------- Result: records ---------- */
.results-summary {
  margin: 1.25rem 0 0;
  color: var(--text-muted);
  font-size: .85rem;
}

.app-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-top: 1.25rem;
  box-shadow: var(--shadow-sm);
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
}
.app-type {
  text-transform: uppercase;
  letter-spacing: .08em;
  font-size: .7rem;
  color: var(--text-muted);
  font-weight: 700;
  margin: 0 0 .4rem;
}
.app-title {
  font-size: clamp(1.15rem, 4vw, 1.5rem);
  margin: 0 0 .5rem;
  letter-spacing: -0.01em;
  text-transform: uppercase;
  overflow-wrap: anywhere;
}
.app-title .dot { color: var(--accent); padding: 0 .3rem; }
.app-ids {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem .9rem;
  margin: 0;
  font-size: .8rem;
  color: var(--text-muted);
}
.app-ids .mono { color: var(--text); }

.status-pill {
  flex-shrink: 0;
  background: var(--pill-bg, var(--current));
  color: var(--pill-fg, var(--on-strong));
  font-weight: 700;
  font-size: .8rem;
  padding: .4rem .9rem;
  border-radius: 999px;
  white-space: nowrap;
}

/* ---------- Progress rail ---------- */
.rail-block { margin-top: 1.35rem; }
.rail-meta {
  display: flex;
  justify-content: space-between;
  font-size: .8rem;
  color: var(--text-muted);
  margin-bottom: .4rem;
}
.rail-meta strong { color: var(--text); font-weight: 700; }
.rail { display: flex; gap: 3px; }
.rail-segment { flex: 1 1 0; min-width: 0; height: 6px; border-radius: 3px; background: var(--border); }
.rail-segment.is-done { background: var(--accent); }
.rail-segment.is-current { background: var(--current); box-shadow: 0 0 0 3px var(--current-glow); }

/* ---------- Chip row ---------- */
.chip-row {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin: 1.1rem 0 0;
  padding: 0;
}
.chip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: .78rem;
  padding: .35rem .7rem;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: .3rem;
}
.chip .mono { color: var(--text); }

/* ---------- What's happening ---------- */
.whats-happening {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}
.whats-happening h3 { margin: 0 0 .5rem; font-size: .9rem; color: var(--text-muted); }
.whats-happening p { margin: 0 0 .6rem; color: var(--text); }
.next-line { color: var(--text-muted); font-size: .9rem; margin: 0; }
.next-label {
  font-weight: 700;
  color: var(--accent-strong);
  text-transform: uppercase;
  font-size: .72rem;
  letter-spacing: .05em;
  margin-right: .4rem;
}

/* Branch / unmatched status note (replaces the rail+timeline for
   non-linear states, so nothing implies a false linear position). */
.status-note {
  margin-top: 1.5rem;
  padding: .9rem 1rem;
  border-radius: var(--radius-md);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: .88rem;
}
.status-note strong { color: var(--text); }
.status-note.is-branch { border-color: var(--current); }

/* ---------- Timeline (hero element) ---------- */
.timeline-block {
  margin-top: 1.75rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}
.timeline-block h3 { margin: 0 0 1.1rem; font-size: .9rem; color: var(--text-muted); }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline-step { position: relative; padding: 0 0 1.75rem 2.35rem; }
.timeline-step:last-child { padding-bottom: 0; }

/* Connector line: the segment below THIS step's marker, colored to show
   whether the journey has passed through here yet. */
.timeline-step::after {
  content: "";
  position: absolute;
  left: .6875rem;
  top: 1.5rem;
  bottom: 0;
  width: 2px;
  background: var(--border);
}
.timeline-step:last-child::after { content: none; }
.timeline-step.is-done::after { background: var(--accent); }

.timeline-marker {
  position: absolute;
  left: 0;
  top: 0;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .75rem;
  font-weight: 700;
  line-height: 1;
  background: var(--surface-2);
  border: 2px solid var(--border);
  color: var(--text-muted);
}
.timeline-step.is-done .timeline-marker {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-strong);
}
.timeline-step.is-current .timeline-marker {
  background: var(--current);
  border-color: var(--current);
  color: var(--on-strong);
  box-shadow: 0 0 0 5px var(--current-glow);
  transform: scale(1.18);
}

.timeline-content { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; padding-top: .1rem; }
.timeline-label { color: var(--text-muted); font-size: .95rem; }
.timeline-step.is-current .timeline-label { color: var(--text); font-weight: 700; font-size: 1rem; }
.timeline-step.is-future .timeline-label { opacity: .55; }

.timeline-badge {
  background: var(--current);
  color: var(--on-strong);
  font-size: .65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: .2rem .55rem;
  border-radius: 999px;
}

/* ---------- Full details ---------- */
.full-details { margin-top: 1.5rem; padding-top: 1.25rem; border-top: 1px solid var(--border); }
.full-details summary {
  cursor: pointer;
  font-weight: 600;
  font-size: .9rem;
  color: var(--text);
  list-style: none;
}
.full-details summary::-webkit-details-marker { display: none; }
.full-details summary::before {
  content: "▸";
  display: inline-block;
  margin-right: .4rem;
  color: var(--accent);
  transition: transform .15s ease;
}
.full-details[open] summary::before { transform: rotate(90deg); }

.detail-grid {
  display: grid;
  grid-template-columns: minmax(9rem, max-content) 1fr;
  column-gap: 1rem;
  row-gap: .6rem;
  margin: 1rem 0 0;
}
.detail-grid dt { color: var(--text-muted); font-size: .8rem; }
.detail-grid dd { margin: 0; word-break: break-word; }

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
  .site-header { padding-left: 1rem; padding-right: 1rem; }
  .container { padding-left: 1rem; padding-right: 1rem; }
  .site-footer { padding-left: 1rem; padding-right: 1rem; }
  .hero-art-band { padding-left: 1rem; padding-right: 1rem; }
  .app-card, .state-card, .lookup-form { padding: 1.1rem; }
  .app-header { flex-direction: column; align-items: flex-start; }
  .status-pill { align-self: flex-start; }
  .detail-grid { grid-template-columns: 1fr; }
  .detail-grid dt { margin-top: .4rem; }
}

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