/* ==========================================================================
   E100 — CHHS Hygiene and Safety Ltd
   Component 1: Visual Identity & Branding System
   Single source of truth for palette, typography, spacing and controls.
   Every view (auth, course modules, assessment) consumes these tokens.
   ========================================================================== */

/* Typography note: Inter is loaded from Google Fonts in the document head;
   the stack degrades to Helvetica Neue / Roboto / system sans if unavailable. */

:root {
  /* --- Primary palette: trust & corporate quality ----------------------- */
  --navy-950: #060F1E;
  --navy-900: #0A192F;   /* backdrop base            */
  --navy-800: #0F2440;   /* raised surfaces on navy  */
  --navy-700: #143154;
  --navy-600: #1B4272;
  --navy-500: #22568F;   /* primary action           */
  --navy-400: #2E6DB0;   /* primary action, hover    */
  --navy-300: #5B93CC;

  /* --- Slate dark blue accents ----------------------------------------- */
  --slate-900: #0F172A;
  --slate-800: #1E293B;
  --slate-700: #334155;
  --slate-600: #475569;
  --slate-500: #64748B;  /* muted body text          */
  --slate-400: #94A3B8;
  --slate-300: #CBD5E1;  /* field borders            */
  --slate-200: #E2E8F0;  /* hairlines                */
  --slate-100: #F1F5F9;  /* inset fills              */
  --slate-050: #F8FAFC;  /* page ground              */

  /* --- Signaling & feedback -------------------------------------------- */
  --success: #10B981;    /* Emerald — correct answers, confirmations */
  --success-dark: #059669;
  --success-tint: #ECFDF5;
  --success-edge: #A7F3D0;

  --error: #EF4444;      /* Crimson — incorrect answers, failures    */
  --error-dark: #DC2626;
  --error-tint: #FEF2F2;
  --error-edge: #FECACA;

  --white: #FFFFFF;

  /* --- Semantic roles --------------------------------------------------- */
  --bg-page: var(--slate-050);
  --bg-surface: var(--white);
  --bg-inset: var(--slate-100);
  --text-strong: var(--navy-900);
  --text-body: var(--slate-700);
  --text-muted: var(--slate-500);
  --text-on-dark: var(--white);
  --text-on-dark-muted: #B6C6DC;
  --border: var(--slate-300);
  --border-soft: var(--slate-200);
  --focus-ring: rgba(34, 86, 143, 0.28);

  /* --- Type scale ------------------------------------------------------- */
  --font-sans: 'Inter', 'Helvetica Neue', Roboto, -apple-system,
               BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
  --fs-display: 2.25rem;
  --fs-h1: 1.75rem;
  --fs-h2: 1.375rem;
  --fs-body: 0.9375rem;
  --fs-sm: 0.8125rem;
  --fs-xs: 0.6875rem;

  /* --- Space, radius, elevation ---------------------------------------- */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px; --sp-12: 48px;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;

  --shadow-card: 0 1px 2px rgba(10, 25, 47, 0.04),
                 0 12px 32px -8px rgba(10, 25, 47, 0.16);
  --shadow-raised: 0 1px 2px rgba(10, 25, 47, 0.06),
                   0 4px 12px -4px rgba(10, 25, 47, 0.10);

  --transition: 140ms cubic-bezier(0.4, 0, 0.2, 1);
}

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

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

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: 1.55;
  color: var(--text-body);
  background: var(--bg-page);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'cv05' 1, 'ss01' 1;
}

h1, h2, h3, h4 {
  margin: 0;
  color: var(--text-strong);
  font-weight: 650;
  letter-spacing: -0.018em;
  line-height: 1.25;
}

img, svg { max-width: 100%; }
[hidden] { display: none !important; }

:focus-visible {
  outline: 2px solid var(--navy-500);
  outline-offset: 2px;
}

/* ==========================================================================
   Brand lockup — CHHS logo over the E100 course brand
   Two forms:
     .brand            compact horizontal — plate emblem + course text
     .brand--stacked   full vertical lockup + course text, centred
   ========================================================================== */
.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  --brand-emblem-size: 44px;
}

/* The header lockup is the home link: it takes everyone to their own start page. */
a.brand { color: inherit; text-decoration: none; }
a.brand:hover .brand__course { text-decoration: underline; text-underline-offset: 3px; }
a.brand:focus-visible { outline: 2px solid currentColor; outline-offset: 4px; border-radius: 4px; }

.brand__emblem {
  width: var(--brand-emblem-size);
  height: var(--brand-emblem-size);
  object-fit: contain;
  flex: none;
}

.brand__text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }

.brand__course {
  font-size: 1.0625rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--text-strong);
  text-transform: uppercase;
}

.brand__sub {
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* --- Stacked: the complete CHHS lockup above the course brand ----------- */
.brand--stacked {
  flex-direction: column;
  align-items: center;
  gap: var(--sp-4);
  --brand-logo-height: 128px;
}

.brand--stacked .brand__logo {
  height: var(--brand-logo-height);
  width: auto;
  object-fit: contain;
}

.brand--stacked .brand__text { align-items: center; text-align: center; }

/* Left-aligned stacked variant, for the navy panel header */
.brand--start { align-items: flex-start; }
.brand--start .brand__text { align-items: flex-start; text-align: left; }

.brand--stacked .brand__course { font-size: 0.9375rem; }

/* --- Inverted for navy backdrops ---------------------------------------- */
.brand--on-dark .brand__course { color: var(--text-on-dark); }
.brand--on-dark .brand__sub { color: var(--text-on-dark-muted); }

/* ==========================================================================
   Form controls — high-contrast minimalist fields
   ========================================================================== */
.field { display: flex; flex-direction: column; gap: var(--sp-2); }

.field__label {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-strong);
  letter-spacing: -0.005em;
}

.field__optional {
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0;
}

.input {
  width: 100%;
  padding: 11px var(--sp-3);
  font: inherit;
  font-size: var(--fs-body);
  color: var(--text-strong);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color var(--transition), box-shadow var(--transition);
  appearance: none;
}

.input::placeholder { color: var(--slate-400); }

.input:hover:not(:focus) { border-color: var(--slate-400); }

.input:focus {
  outline: none;
  border-color: var(--navy-500);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.input[aria-invalid='true'] {
  border-color: var(--error);
  background: var(--error-tint);
}
.input[aria-invalid='true']:focus {
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.20);
}

.field__error {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--error-dark);
}
.field__error:empty { display: none; }

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  width: 100%;
  padding: 12px var(--sp-5);
  font: inherit;
  font-size: var(--fs-body);
  font-weight: 600;
  letter-spacing: -0.005em;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color var(--transition), box-shadow var(--transition),
              transform var(--transition);
}

.btn--primary {
  background: var(--navy-500);
  color: var(--white);
  box-shadow: var(--shadow-raised);
}
.btn--primary:hover { background: var(--navy-400); }
.btn--primary:active { background: var(--navy-600); transform: translateY(1px); }

.btn[disabled] { opacity: 0.6; cursor: not-allowed; transform: none; }

.btn__spinner {
  width: 15px;
  height: 15px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: var(--white);
  border-radius: 50%;
  animation: spin 620ms linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Inline text link / state toggle */
.link {
  color: var(--navy-500);
  font-weight: 600;
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  border-bottom: 1px solid transparent;
}
.link:hover { color: var(--navy-400); border-bottom-color: currentColor; }

/* ==========================================================================
   Feedback banners — Emerald success / Crimson error
   ========================================================================== */
.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-sm);
  font-weight: 500;
  border: 1px solid;
  border-radius: var(--radius-sm);
}

.alert__icon { flex: none; margin-top: 1px; }

.alert--error {
  color: var(--error-dark);
  background: var(--error-tint);
  border-color: var(--error-edge);
}

.alert--success {
  color: var(--success-dark);
  background: var(--success-tint);
  border-color: var(--success-edge);
}

/* --- Accessible-only text ------------------------------------------------ */
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

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