/* =====================================================================
   PREPARE-BANJIR — app.css (participant PWA)

   Layered on purpose:
     01 tokens · 02 base · 03 typography · 04 layout
     05 components · 06 states · 07 utilities · 08 accessibility

   Colour encodes function, never decoration:
     --learn  (teal)  learning zone   : /learn /quiz /chat
     --study  (amber) research task   : /consent /eligibility /assessment /feedback
     --danger (red)   REAL DANGER ONLY: the emergency banner + validation errors

   There are exactly three animations in the entire application. They are
   declared in 01-tokens and used nowhere else:
     --t-hover 150ms · --t-chat 200ms · --t-progress 300ms
   The emergency banner has none: it appears instantly.
   ===================================================================== */

/* ---------------------------------------------------------------
   01 TOKENS
   --------------------------------------------------------------- */
:root {
  /* Palette — each token has one fixed meaning */
  --deep:         #082F49;
  --primary:      #0E6BA8;
  --primary-dark: #0A5385;
  --primary-soft: #E7F1F8;
  --learn:        #0F766E;
  --learn-soft:   #E6F2F1;
  --study:        #B45309;
  --study-soft:   #FDF3E7;
  --danger:       #B3261E;
  --danger-soft:  #FBEAE9;
  --ok:           #15803D;

  --bg:      #F4F7FA;
  --surface: #FFFFFF;
  --border:  #E2E8F0;
  --text:    #12212E;
  --muted:   #5A6B7B;

  /* Typography — body is 16px, not 14px: the audience is the general public */
  --font: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --fs-xs: 13px;
  --fs-sm: 15px;
  --fs-md: 16px;
  --fs-lg: 18px;
  --fs-xl: 22px;
  --fs-2xl: 28px;
  --lh: 1.6;

  /* Spacing — multiples of 4 only */
  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px;
  --s5: 20px; --s6: 24px; --s8: 32px; --s10: 40px; --s12: 48px;

  /* Shape — one radius scale, nothing above 16px */
  --r-card:  12px;
  --r-input: 10px;
  --r-chip:  999px;

  /* Exactly one shadow in the whole product */
  --shadow: 0 1px 2px rgba(8,47,73,.06), 0 6px 20px rgba(8,47,73,.05);

  /* The only three transitions permitted */
  --t-hover:    150ms ease-out;
  --t-chat:     200ms ease-out;
  --t-progress: 300ms ease-out;

  /* Layout */
  --shell-max: 520px;
  --tap-min:   44px;   /* WCAG 2.2 AA target size */
  --bottomnav-h: 64px;
}

/* Bundled locally so the app still looks right with no network (NFR-04). */
@font-face {
  font-family: "Plus Jakarta Sans";
  src: url("../fonts/plus-jakarta-sans/PlusJakartaSans-Regular.woff2") format("woff2");
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Plus Jakarta Sans";
  src: url("../fonts/plus-jakarta-sans/PlusJakartaSans-Medium.woff2") format("woff2");
  font-weight: 500; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Plus Jakarta Sans";
  src: url("../fonts/plus-jakarta-sans/PlusJakartaSans-SemiBold.woff2") format("woff2");
  font-weight: 600; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Plus Jakarta Sans";
  src: url("../fonts/plus-jakarta-sans/PlusJakartaSans-Bold.woff2") format("woff2");
  font-weight: 700; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Plus Jakarta Sans";
  src: url("../fonts/plus-jakarta-sans/PlusJakartaSans-ExtraBold.woff2") format("woff2");
  font-weight: 800; font-style: normal; font-display: swap;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-md);
  line-height: var(--lh);
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
}

img, svg { max-width: 100%; height: auto; display: block; }

a { color: var(--primary); text-decoration: underline; text-underline-offset: 2px; }
a:hover { color: var(--primary-dark); }

/* Bootstrap 5.3 is used for grid and utilities only. These resets stop its
   default palette from leaking in, which would break the rule that red only
   ever means real danger. */
.btn-danger, .bg-danger, .text-danger, .badge.bg-danger,
.btn-primary, .bg-primary, .btn-success, .bg-success,
.btn-warning, .bg-warning, .btn-info, .bg-info {
  all: unset;
}

/* ---------------------------------------------------------------
   03 TYPOGRAPHY
   --------------------------------------------------------------- */
h1, h2, h3, h4 { color: var(--deep); margin: 0 0 var(--s3); line-height: 1.3; font-weight: 700; }
h1 { font-size: var(--fs-2xl); font-weight: 800; letter-spacing: -0.01em; }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }
h4 { font-size: var(--fs-md); font-weight: 600; }

p { margin: 0 0 var(--s4); }
p:last-child { margin-bottom: 0; }

.lead   { font-size: var(--fs-lg); color: var(--muted); }
.muted  { color: var(--muted); }
.small  { font-size: var(--fs-sm); }
.xsmall { font-size: var(--fs-xs); }
.strong { font-weight: 600; }

/* Learning material never exceeds ~60 characters per line. */
.prose { max-width: 60ch; }
.prose p { margin-bottom: var(--s5); }
.prose h2, .prose h3 { margin-top: var(--s8); }

.num { font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------
   04 LAYOUT — mobile first, one column, one primary action per screen
   --------------------------------------------------------------- */
.shell {
  max-width: var(--shell-max);
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  padding-bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0px));
}

.appbar {
  background: var(--deep);
  color: #fff;
  padding: var(--s4);
  padding-top: calc(var(--s4) + env(safe-area-inset-top, 0px));
  display: flex;
  align-items: center;
  gap: var(--s3);
  position: sticky;
  top: 0;
  z-index: 20;
}
.appbar h1, .appbar h2 { color: #fff; margin: 0; font-size: var(--fs-lg); font-weight: 700; }
.appbar__sub { color: rgba(255,255,255,.72); font-size: var(--fs-xs); margin: 0; }
.appbar__back {
  color: #fff; text-decoration: none; min-width: var(--tap-min); min-height: var(--tap-min);
  display: inline-flex; align-items: center; justify-content: center; margin-left: calc(var(--s2) * -1);
  border-radius: var(--r-input);
}
.appbar__back:hover { background: rgba(255,255,255,.12); color: #fff; }
.appbar__spacer { flex: 1; }

.page { padding: var(--s5) var(--s4); flex: 1; }
.page > * + * { margin-top: var(--s5); }

.stack   { display: flex; flex-direction: column; gap: var(--s4); }
.stack-2 { display: flex; flex-direction: column; gap: var(--s2); }
.row     { display: flex; align-items: center; gap: var(--s3); }
.row--between { justify-content: space-between; }
.row--wrap    { flex-wrap: wrap; }

/* Bottom navigation, 5 items, each meeting the 44px target minimum. */
.bottomnav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: var(--shell-max);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: grid; grid-template-columns: repeat(5, 1fr);
  z-index: 30;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.bottomnav a {
  min-height: var(--bottomnav-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; text-decoration: none; color: var(--muted);
  font-size: var(--fs-xs); font-weight: 500;
  transition: color var(--t-hover), background var(--t-hover);
}
.bottomnav a i { font-size: 18px; }
.bottomnav a[aria-current="page"] { color: var(--primary); background: var(--primary-soft); font-weight: 600; }
.bottomnav a:hover { color: var(--primary); }

/* The single primary action, pinned above the navigation. */
.actionbar {
  position: sticky; bottom: 0;
  background: linear-gradient(to top, var(--bg) 72%, rgba(244,247,250,0));
  padding: var(--s4) 0 var(--s2);
  margin-top: var(--s6);
}

/* Zone tinting — teal for learning, amber for research tasks. */
.zone-learn .appbar { background: var(--learn); }
.zone-learn .btn--primary { background: var(--learn); }
.zone-learn .btn--primary:hover { background: #0c5f58; }
.zone-study .appbar { background: var(--study); }
.zone-study .btn--primary { background: var(--study); }
.zone-study .btn--primary:hover { background: #96450a; }

/* ---------------------------------------------------------------
   05 COMPONENTS — one card, one primary button, one rhythm
   --------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  padding: var(--s5);
  box-shadow: var(--shadow);
}
.card + .card { margin-top: var(--s4); }
.card__head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s3); }
.card__title { margin: 0; font-size: var(--fs-lg); }
.card__meta { color: var(--muted); font-size: var(--fs-sm); }
.card--flat { box-shadow: none; }
/* Cards do NOT grow on hover. A list of cards should sit still. */
.card--link { display: block; text-decoration: none; color: inherit; transition: border-color var(--t-hover); }
.card--link:hover { border-color: var(--primary); color: inherit; }
.card--locked { opacity: .72; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: var(--tap-min); padding: var(--s3) var(--s5);
  border-radius: var(--r-input); border: 1px solid transparent;
  font-family: var(--font); font-size: var(--fs-md); font-weight: 600;
  cursor: pointer; text-decoration: none; text-align: center;
  transition: background var(--t-hover), border-color var(--t-hover), color var(--t-hover);
}
.btn--primary   { background: var(--primary); color: #fff; }
.btn--primary:hover { background: var(--primary-dark); color: #fff; }
.btn--secondary { background: var(--surface); color: var(--primary); border-color: var(--border); }
.btn--secondary:hover { border-color: var(--primary); color: var(--primary-dark); }
.btn--ghost     { background: transparent; color: var(--primary); }
.btn--ghost:hover { background: var(--primary-soft); }
.btn--block     { width: 100%; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; pointer-events: none; }
/* There is deliberately no .btn--danger. Destructive actions use
   .btn--secondary plus an explicit confirmation dialog. */

.field { margin-bottom: var(--s5); }
.field__label { display: block; font-weight: 600; margin-bottom: var(--s2); color: var(--text); }
.field__hint  { display: block; color: var(--muted); font-size: var(--fs-sm); margin-bottom: var(--s2); }
.field__error { color: var(--danger); font-size: var(--fs-sm); margin: var(--s2) 0 0; font-weight: 500; }

.input, .select, .textarea {
  width: 100%; min-height: var(--tap-min);
  padding: var(--s3) var(--s4);
  border: 1px solid var(--border); border-radius: var(--r-input);
  background: var(--surface); color: var(--text);
  font-family: var(--font); font-size: var(--fs-md); line-height: var(--lh);
  transition: border-color var(--t-hover);
}
.input:hover, .select:hover, .textarea:hover { border-color: #cbd5e1; }
.input[aria-invalid="true"], .select[aria-invalid="true"] { border-color: var(--danger); }
.textarea { min-height: 96px; resize: vertical; }
.input--code {
  font-size: var(--fs-xl); letter-spacing: .32em; text-align: center;
  font-weight: 700; text-transform: uppercase;
}
.input--pin { font-size: var(--fs-xl); letter-spacing: .48em; text-align: center; }

/* Radio and checkbox rows are whole-row tap targets. */
.choice {
  display: flex; align-items: flex-start; gap: var(--s3);
  min-height: var(--tap-min); padding: var(--s3) var(--s4);
  border: 1px solid var(--border); border-radius: var(--r-input);
  background: var(--surface); cursor: pointer;
  transition: border-color var(--t-hover), background var(--t-hover);
}
.choice + .choice { margin-top: var(--s2); }
.choice:hover { border-color: var(--primary); }
.choice input { margin: 4px 0 0; width: 20px; height: 20px; accent-color: var(--primary); flex: none; }
.choice__label { flex: 1; }
.choice input:checked ~ .choice__label { font-weight: 600; }
.choice:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }

.chip {
  display: inline-flex; align-items: center; gap: var(--s2);
  padding: 6px var(--s3); border-radius: var(--r-chip);
  background: var(--primary-soft); color: var(--deep);
  font-size: var(--fs-xs); font-weight: 500; text-decoration: none;
  border: 1px solid transparent;
}
.chip--source {
  background: var(--learn-soft); color: #0b544e; border-color: #cde5e2;
  margin-top: var(--s3);
}
a.chip--source:hover { border-color: var(--learn); color: #0b544e; }
.chip--quick {
  background: var(--surface); border-color: var(--border); color: var(--primary);
  min-height: 36px; padding: var(--s2) var(--s4); font-size: var(--fs-sm);
}
a.chip--quick:hover { border-color: var(--primary); background: var(--primary-soft); }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px var(--s3); border-radius: var(--r-chip);
  font-size: var(--fs-xs); font-weight: 600; white-space: nowrap;
}
.badge--neutral { background: #EEF2F6; color: var(--muted); }
.badge--learn   { background: var(--learn-soft); color: #0b544e; }
.badge--study   { background: var(--study-soft); color: #8a4208; }
.badge--ok      { background: #E7F4EC; color: var(--ok); }
/* --warn is amber, NOT red: a pending decision is not a danger. */
.badge--warn    { background: var(--study-soft); color: #8a4208; }

/* Chat bubbles: plain, aligned, no floating shadows. */
.bubble {
  max-width: 88%; padding: var(--s3) var(--s4);
  border-radius: var(--r-card); font-size: var(--fs-md); line-height: var(--lh);
  animation: fade-slide-up var(--t-chat);
}
.bubble--bot  { background: var(--surface); border: 1px solid var(--border); align-self: flex-start; }
.bubble--user { background: var(--primary-soft); align-self: flex-end; color: var(--deep); }
.bubble p:last-child { margin-bottom: 0; }
.bubble__time { display: block; font-size: var(--fs-xs); color: var(--muted); margin-top: var(--s2); }

@keyframes fade-slide-up {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

/* THE emergency banner. The only large red surface in the product.
   No transition, no animation: it must appear the instant it is rendered. */
.banner-danger {
  background: var(--danger-soft);
  border: 2px solid var(--danger);
  border-radius: var(--r-card);
  padding: var(--s5);
  color: #6b1712;
  transition: none !important;
  animation: none !important;
}
.banner-danger__head { display: flex; align-items: center; gap: var(--s2); color: var(--danger); font-size: var(--fs-lg); margin-bottom: var(--s3); }
.banner-danger__body { margin: 0 0 var(--s4); font-weight: 500; }
.banner-danger__contacts { list-style: none; margin: 0; padding: 0; }
.banner-danger__contacts li { margin-bottom: var(--s3); }
.banner-danger__contacts a {
  display: flex; align-items: center; gap: var(--s2);
  min-height: var(--tap-min); padding: var(--s3) var(--s4);
  background: var(--danger); color: #fff; border-radius: var(--r-input);
  text-decoration: none; font-weight: 600;
}
.banner-danger__contacts a:hover { background: #8f1e17; color: #fff; }
.contact-agency { flex: 1; }
.contact-number { font-variant-numeric: tabular-nums; }
.contact-scope  { display: block; font-size: var(--fs-xs); color: #6b1712; margin-top: 2px; }
.banner-danger__empty { margin: 0; font-weight: 500; }

.notice {
  display: flex; gap: var(--s3); align-items: flex-start;
  background: var(--primary-soft); border-radius: var(--r-card);
  padding: var(--s4); color: var(--deep); font-size: var(--fs-sm);
}
.notice i { color: var(--primary); margin-top: 3px; }
.notice p { margin: 0; }
.notice--compact { padding: var(--s3); font-size: var(--fs-xs); }

.progress { width: 100%; }
.progress__label { display: flex; justify-content: space-between; font-size: var(--fs-sm); margin-bottom: var(--s2); }
.progress__value { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--deep); }
.progress__track { height: 8px; background: var(--border); border-radius: var(--r-chip); overflow: hidden; }
.progress__fill  { height: 100%; background: var(--learn); border-radius: var(--r-chip); transition: width var(--t-progress); }

.sync-indicator { display: inline-flex; align-items: center; gap: var(--s2); font-size: var(--fs-xs); color: var(--muted); }
.sync-indicator__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
.sync-indicator[data-state="queued"]  .sync-indicator__dot { background: var(--study); }
.sync-indicator[data-state="offline"] .sync-indicator__dot { background: var(--muted); }
.sync-indicator[data-state="failed"]  .sync-indicator__dot { background: var(--danger); }

.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); padding: var(--s4); }
.stat__value { font-size: var(--fs-2xl); font-weight: 800; color: var(--deep); font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat__label { font-size: var(--fs-sm); color: var(--muted); margin-top: var(--s1); }

.divider { height: 1px; background: var(--border); border: 0; margin: var(--s6) 0; }

details.disclosure { border: 1px solid var(--border); border-radius: var(--r-card); background: var(--surface); }
details.disclosure > summary {
  min-height: var(--tap-min); display: flex; align-items: center; gap: var(--s2);
  padding: var(--s4); cursor: pointer; font-weight: 600; color: var(--deep); list-style: none;
}
details.disclosure > summary::-webkit-details-marker { display: none; }
details.disclosure > summary::after { content: "\f078"; font-family: "Font Awesome 6 Free"; font-weight: 900; margin-left: auto; font-size: 12px; color: var(--muted); }
details.disclosure[open] > summary::after { content: "\f077"; }
details.disclosure > .disclosure__body { padding: 0 var(--s4) var(--s4); }

/* ---------------------------------------------------------------
   06 STATES — every screen must have all five
   --------------------------------------------------------------- */
.empty-state { text-align: center; padding: var(--s10) var(--s5); }
.empty-state__icon { font-size: 32px; color: var(--border); margin: 0 auto var(--s4); }
.empty-state h3 { margin-bottom: var(--s2); }
.empty-state p  { color: var(--muted); margin-bottom: var(--s5); }

.skeleton { background: var(--border); border-radius: var(--r-input); height: 16px; opacity: .6; }
.skeleton + .skeleton { margin-top: var(--s2); }

.state-error {
  background: var(--danger-soft); border: 1px solid var(--danger);
  border-radius: var(--r-card); padding: var(--s4); color: #6b1712;
}
.state-offline {
  background: #EEF2F6; border: 1px dashed #94a3b8;
  border-radius: var(--r-card); padding: var(--s4); color: var(--muted);
}

.offline-bar {
  background: var(--deep); color: #fff; font-size: var(--fs-sm);
  padding: var(--s2) var(--s4); text-align: center; display: none;
}
body.is-offline .offline-bar { display: block; }

/* ---------------------------------------------------------------
   07 UTILITIES — deliberately small, this is not a utility framework
   --------------------------------------------------------------- */
.mt-0 { margin-top: 0 !important; }
.mt-2 { margin-top: var(--s2); }
.mt-4 { margin-top: var(--s4); }
.mt-6 { margin-top: var(--s6); }
.mb-0 { margin-bottom: 0 !important; }
.mb-2 { margin-bottom: var(--s2); }
.mb-4 { margin-bottom: var(--s4); }
.text-center { text-align: center; }
.flex-1 { flex: 1; }
.hidden { display: none !important; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }

/* ---------------------------------------------------------------
   08 ACCESSIBILITY — WCAG 2.2 AA is a requirement, not a nice-to-have
   --------------------------------------------------------------- */
:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
  border-radius: 4px;
}
.banner-danger :focus-visible { outline-color: var(--danger); }

.sr-only {
  position: absolute; 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: -9999px; top: 0; z-index: 100;
  background: var(--surface); color: var(--primary);
  padding: var(--s3) var(--s4); border-radius: 0 0 var(--r-input) 0; font-weight: 600;
}
.skip-link:focus { left: 0; }

/* Honour the OS setting. The emergency banner never animated anyway. */
@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;
  }
}

/* Content must stay readable at 200% zoom / 320px reflow. */
@media (max-width: 360px) {
  :root { --s4: 12px; --s5: 16px; }
  .page { padding: var(--s4) var(--s3); }
  .bottomnav a { font-size: 11px; }
  .input--code { font-size: var(--fs-lg); letter-spacing: .2em; }
}

@media (min-width: 560px) {
  .shell { box-shadow: var(--shadow); border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
}

@media print {
  .bottomnav, .actionbar, .appbar__back, .offline-bar { display: none !important; }
  .shell { max-width: none; }
}
