/* ============================================================================
   responsive.css — EVERY @media block in the project. No exceptions.
   Load order is load-bearing: main -> components -> responsive
   This file wins over components.css at equal specificity by source order only.
   Never add a @media to main.css or components.css.

   Block order (mobile-last: later rules override earlier ones):
     1. max-width 1024   tablet
     2. max-width  768   phone / navbar drawer
     3. max-width  480   small phone
     4. hover: none      touch — kills sticky :hover flips
     5. prefers-reduced-motion
     6. print
   ========================================================================= */


/* ============================================================================
   1. TABLET — max-width 1024
   ========================================================================= */
@media (max-width: 1024px) {

  /* ---- Grid collapse ladder: 4 -> 2, 3 -> 2, 2 stays --------------------- */
  .card-grid--cols-4 { grid-template-columns: repeat(2, 1fr); }
  .card-grid--cols-3 { grid-template-columns: repeat(2, 1fr); }

  /* Legacy .stakeholder-grid was 1-col + capped at 1024, not 2-col: the flip
     cards need width to hold both faces. Scoped so the InfoCard/knowledge
     grids keep their 2-col step. */
  .card-grid--cols-3:has(> .stakeholder-card) {
    grid-template-columns: 1fr;
    max-width: 520px;
    margin: 0 auto;
  }

  /* Legacy .calc-grid collapsed at 1024, before the generic 2-col ladder. */
  .card-grid--cols-2:has(> .calc-panel) {
    grid-template-columns: 1fr;
  }

  /* ---- Split layouts ---------------------------------------------------- */
  .split--sidebar { grid-template-columns: 1fr; }

  /* ---- ProcessTimeline: horizontal rail loses a row, so the rail goes ---- */
  .process-timeline {
    grid-template-columns: repeat(2, 1fr);
    gap: 40px;
  }
  .process-timeline::before { display: none; }

  /* ---- DataTable: never let a wide table push the page sideways ---------- */
  .data-table__wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .data-table { min-width: 640px; }

  /* ---- MapPanel --------------------------------------------------------- */
  .map-panel { height: 420px; }

  /* ---- ProgressTracker -------------------------------------------------- */
  .progress-tracker { gap: var(--sp-3); }
}


/* ============================================================================
   2. PHONE — max-width 768
   ========================================================================= */
@media (max-width: 768px) {

  /* ---- Navbar drawer ---------------------------------------------------- */
  /* .navbar-links.active is written by main.js only. */
  .navbar-links {
    display: none;
    position: absolute;
    top: var(--nav-h);
    left: 0;
    right: 0;
    background: var(--white);
    flex-direction: column;
    padding: 24px;
    gap: 16px;
    box-shadow: var(--shadow-lg);
    border-top: 1px solid rgba(12, 73, 138, 0.08);
    z-index: var(--z-drawer);
  }

  .navbar-links.active { display: flex; }

  .mobile-toggle { display: block; }

  /* Dropdowns inside the drawer are stacked, not floating overlays */
  .navbar-item { width: 100%; }
  .navbar-dropdown {
    position: static;
    opacity: 1;
    visibility: visible;
    transform: none;
    box-shadow: none;
    border: none;
    min-width: 0;
    padding: 0 0 0 var(--sp-4);
    display: none;
  }
  .navbar-item--has-children.is-open .navbar-dropdown { display: block; }
  /* The 16px hover bridge is meaningless on a stacked drawer */
  .navbar-item--has-children::after { display: none; }

  /* ---- Hero ------------------------------------------------------------- */
  .hero { padding: 120px 0 60px; }
  .hero h1 { font-size: 2.2rem; }
  .hero-subtitle { font-size: 1rem; }
  .hero-stats { gap: 24px; }
  .hero-stat .stat-number { font-size: 1.4rem; }

  .page-hero { padding: 104px 0 40px; }
  .page-hero h1 { font-size: 1.9rem; }
  .page-hero__sub { font-size: 1rem; }

  /* ---- Sections --------------------------------------------------------- */
  .section-header h2 { font-size: 2rem; }
  .section-header { margin-bottom: 40px; }
  .cta-section h2 { font-size: 2rem; }

  /* ---- Grid collapse ladder: everything is 1-col ------------------------- */
  .card-grid--cols-2,
  .card-grid--cols-3,
  .card-grid--cols-4 { grid-template-columns: 1fr; }

  .split,
  .split--sidebar { grid-template-columns: 1fr; }

  /* ---- ProcessTimeline: fully vertical ---------------------------------- */
  .process-timeline {
    grid-template-columns: 1fr;
    max-width: 300px;
    margin: 0 auto;
  }
  /* ...unless steps carry expandable panels — 300px is unreadable for prose.
     Legacy landing steps (number + label only) keep the narrow centred rail. */
  .process-timeline:has(.process-timeline__panel) {
    max-width: none;
    margin: 0;
  }

  /* ---- CalculatorPanel -------------------------------------------------- */
  .calc-panel__results { grid-template-columns: 1fr; }
  .calc-panel__body { padding: var(--sp-5); }
  .calc-panel__header { padding: var(--sp-5); }

  /* ---- TabPanel: scroll the list rather than wrap or squash the labels --- */
  .tabs__list {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }
  .tabs__list::-webkit-scrollbar { height: 4px; }
  .tabs__list button[role="tab"] {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  /* ---- MapPanel --------------------------------------------------------- */
  .map-panel { height: 340px; }

  /* ---- ProgressTracker: horizontal -> vertical -------------------------- */
  .progress-tracker {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--sp-4);
  }
  .progress-tracker::before { display: none; }
  .progress-tracker__step { width: 100%; text-align: left; }

  /* ---- QuizWidget ------------------------------------------------------- */
  .quiz { padding: var(--sp-5); }
  .quiz__options { grid-template-columns: 1fr; }
  .quiz__nav { flex-direction: column; gap: var(--sp-3); }
  .quiz__nav .btn { width: 100%; justify-content: center; }

  /* ---- ModalDetail ------------------------------------------------------ */
  .modal {
    width: calc(100vw - var(--sp-5));
    max-width: none;
    max-height: 88vh;
  }

  /* ---- Legacy landing sections ------------------------------------------ */
  .partners-row { gap: 32px; }

  .footer-content {
    flex-direction: column;
    text-align: center;
  }
  .footer-links {
    flex-wrap: wrap;
    justify-content: center;
  }
}


/* ============================================================================
   3. SMALL PHONE — max-width 480
   ========================================================================= */
@media (max-width: 480px) {

  .container { padding: 0 var(--sp-4); }

  /* ---- Hero ------------------------------------------------------------- */
  .hero { padding: 104px 0 48px; }
  .hero h1 { font-size: 1.75rem; letter-spacing: -0.5px; }
  .hero-subtitle { font-size: 0.95rem; margin-bottom: 28px; }
  .hero-search input { padding: 14px 52px 14px 18px; font-size: 0.95rem; }
  .hero-stats { flex-direction: column; gap: var(--sp-4); }
  .hero-stat .stat-label { max-width: none; }
  .page-hero h1 { font-size: 1.55rem; }

  /* ---- Sections --------------------------------------------------------- */
  .section { padding: 56px 0; }
  .section--tight { padding: 40px 0; }
  .section-header h2 { font-size: 1.6rem; }
  .section-header p { font-size: 1rem; }
  .cta-section { padding: 56px 0; }
  .cta-section h2 { font-size: 1.6rem; }
  .cta-buttons { flex-direction: column; align-items: stretch; }
  .cta-buttons .btn { justify-content: center; }

  .prose h2 { font-size: 1.5rem; }
  .prose h3 { font-size: 1.15rem; }

  /* ---- Grids ------------------------------------------------------------ */
  .card-grid { gap: var(--sp-4); }

  /* ---- Components ------------------------------------------------------- */
  .stakeholder-card { padding: 28px 20px; }
  .info-card { padding: var(--sp-5); }
  .case-card__stats { grid-template-columns: 1fr; }

  .stat-counter { font-size: 1.9rem; }

  .calc-panel__field { gap: var(--sp-2); }
  .calc-panel__field input[type="number"] { width: 100%; }
  .calc-panel__out { font-size: 1.25rem; }

  .data-table { min-width: 520px; font-size: 0.8rem; }

  .accordion__head { padding: var(--sp-3) var(--sp-4); font-size: 0.95rem; }
  .accordion__body { padding: 0 var(--sp-4) var(--sp-4); }

  .map-panel { height: 280px; }
  .map-panel__legend {
    position: static;
    margin-top: var(--sp-3);
    max-width: none;
  }

  .chart-panel { padding: var(--sp-4); }

  .tabs__list button[role="tab"] { padding: var(--sp-3) var(--sp-4); font-size: 0.82rem; }

  .quiz { padding: var(--sp-4); }
  .quiz__question { font-size: 1.05rem; }

  .modal { max-height: 92vh; }
  .modal__body { padding: var(--sp-4); }

  .download-card { flex-direction: column; align-items: flex-start; gap: var(--sp-3); }

  .partners-row { gap: var(--sp-5); }
  .partner-logo { width: 56px; height: 56px; font-size: 1.2rem; }

  .footer-links { gap: var(--sp-4); }
}


/* ============================================================================
   4. TOUCH — (hover: none)
   On touch, :hover latches after the first tap and never clears. A hover-flip
   card would flip and stay flipped with no way back. JS owns the flip here via
   click -> .is-flipped, so the hover rules must be neutralised.
   :not(.is-flipped) guards the JS state: without it these rules sit later in
   source order than components.css and would beat .is-flipped at equal
   specificity — i.e. the card could never flip at all.
   ========================================================================= */
@media (hover: none) {

  .stakeholder-card:hover:not(.is-flipped) .stakeholder-card__front,
  .stakeholder-card:hover:not(.is-flipped) .stakeholder-card__back,
  .case-card:hover:not(.is-flipped) .case-card__front,
  .case-card:hover:not(.is-flipped) .case-card__back {
    transform: none;
  }

  /* Lift-on-hover is meaningless on touch and leaves cards stuck raised */
  .stakeholder-card:hover,
  .case-card:hover,
  .info-card:hover,
  .download-card:hover,
  .chart-panel:hover {
    transform: none;
  }

  /* Touch targets: the dropdown is opened by JS (.is-open), not by hover */
  .navbar-item--has-children:hover .navbar-dropdown {
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
  }
  .navbar-item--has-children.is-open .navbar-dropdown,
  .navbar-dropdown:focus-within {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
  }
  .navbar-item--has-children:hover .navbar-caret { transform: none; }
  .navbar-item--has-children.is-open .navbar-caret { transform: rotate(180deg); }
}


/* ============================================================================
   5. REDUCED MOTION — prefers-reduced-motion: reduce
   Contract §11: kills AOS, flips, counters, step-throughs.
   StatCounter snap-to-final is handled in JS (utils.prefersReducedMotion()).
   ========================================================================= */
@media (prefers-reduced-motion: reduce) {

  /* ---- Global brake ----------------------------------------------------- */
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  html { scroll-behavior: auto; }

  /* ---- AOS -------------------------------------------------------------- */
  /* Beats both AOS's own [data-aos^="fade"]{opacity:0} and main.css's
     body.aos-ready guard. Elements are visible, full stop. */
  [data-aos] {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
  }

  /* main.css .fade-in / IntersectionObserver reveal */
  .fade-in,
  .fade-in.visible {
    opacity: 1;
    transform: none;
    transition: none;
  }

  /* ---- Card flips -> cross-fade ----------------------------------------- */
  /* No rotation, no 3D. Faces cross-fade in place; both hover (desktop) and
     .is-flipped (JS/touch) still reveal the back. */
  .stakeholder-card__front,
  .stakeholder-card__back,
  .case-card__front,
  .case-card__back {
    transform: none !important;
    backface-visibility: visible !important;
    transition: opacity 0.01ms !important;
  }

  .stakeholder-card__back,
  .case-card__back { opacity: 0; }

  .stakeholder-card:hover .stakeholder-card__back,
  .stakeholder-card.is-flipped .stakeholder-card__back,
  .stakeholder-card:focus-within .stakeholder-card__back,
  .case-card:hover .case-card__back,
  .case-card.is-flipped .case-card__back,
  .case-card:focus-within .case-card__back { opacity: 1; }

  .stakeholder-card:hover .stakeholder-card__front,
  .stakeholder-card.is-flipped .stakeholder-card__front,
  .stakeholder-card:focus-within .stakeholder-card__front,
  .case-card:hover .case-card__front,
  .case-card.is-flipped .case-card__front,
  .case-card:focus-within .case-card__front { opacity: 0; }

  /* ---- translateY hover lifts ------------------------------------------- */
  .btn:hover,
  .btn-primary:hover,
  .btn-outline:hover,
  .btn-outline-blue:hover,
  .btn-green:hover,
  .stakeholder-card:hover,
  .case-card:hover,
  .info-card:hover,
  .download-card:hover,
  .chart-panel:hover,
  .knowledge-card:hover {
    transform: none !important;
  }

  /* ---- Step-through / progressive reveal -------------------------------- */
  .process-timeline__panel,
  .accordion__body,
  .quiz__question,
  .quiz__result {
    transition: none !important;
    animation: none !important;
  }

  /* Smooth-height accordion: JS animates max-height; do not tween it */
  .accordion__item[open] .accordion__body { max-height: none !important; }

  .progress-tracker__step,
  .progress-tracker__bar { transition: none !important; }

  /* StatCounter: JS snaps to the final value; kill any CSS tween on it */
  .stat-counter { transition: none !important; }

  /* Navbar drawer + dropdown open instantly */
  .navbar-dropdown,
  .navbar-caret,
  .navbar-links { transition: none !important; }
}


/* ============================================================================
   6. PRINT
   Contract §11: force-expand every <details>, hide map/tabs/modal/quiz/video.
   ========================================================================= */
@media print {

  /* ---- Chrome that cannot print ----------------------------------------- */
  .navbar,
  .hero-search,
  .mobile-toggle,
  .cta-section,
  .calculators,
  .skip-link,
  .breadcrumbs { display: none; }

  /* Interactive-only components: meaningless or broken on paper */
  .map-panel,
  .tabs__list,
  .modal,
  .quiz,
  .video-embed { display: none !important; }

  /* A <dialog> is also hidden by the UA unless open — belt and braces */
  dialog.modal[open] { display: none !important; }

  /* Tab panels: the list is gone, so print every panel, not just the
     selected one — otherwise the content silently vanishes */
  .tabs__panel {
    display: block !important;
    break-inside: avoid;
  }
  .tabs__panel[hidden] { display: block !important; }

  body {
    font-size: 11pt;
    color: #000;
    line-height: 1.5;
    padding-top: 0;
  }

  .hero,
  .page-hero {
    background: none !important;
    color: #000;
    padding: 20px 0;
    margin-top: 0;
  }

  .hero::before, .hero::after,
  .page-hero::before { display: none; }

  .hero h1, .hero h1 span,
  .page-hero h1 {
    color: #000 !important;
    -webkit-text-fill-color: #000 !important;
    font-size: 24pt;
  }

  .hero-subtitle,
  .page-hero__sub { color: #333 !important; }
  .hero-stats { margin-top: 10px; }
  .hero-stat .stat-number { color: #000 !important; }
  .hero-stat .stat-label { color: #333 !important; }

  .stakeholder-card {
    break-inside: avoid;
    color: #000 !important;
    background: #f5f5f5 !important;
    border: 1px solid #ccc;
    box-shadow: none;
  }

  .stakeholder-card h3 { color: #000 !important; }

  /* Flip cards have no back side on paper — print both faces stacked */
  .stakeholder-card__front,
  .stakeholder-card__back,
  .case-card__front,
  .case-card__back {
    position: static !important;
    transform: none !important;
    backface-visibility: visible !important;
    opacity: 1 !important;
    display: block !important;
  }

  /* ---- Force-expand every <details> ------------------------------------- */
  /* An unopened <details> prints as a bare summary line: the answer is simply
     gone from the page. Every accordion body must be on paper. */
  .accordion__item,
  .accordion__item[open] {
    display: block;
    break-inside: avoid;
  }

  .accordion__body {
    display: block !important;
    max-height: none !important;
    height: auto !important;
    overflow: visible !important;
    opacity: 1 !important;
  }

  .accordion__head { list-style: none; }
  .accordion__head::-webkit-details-marker { display: none; }

  /* ProcessTimeline panels are the same problem: collapsed = content lost */
  .process-timeline { grid-template-columns: 1fr; }
  .process-timeline::before { display: none; }
  .process-timeline__panel {
    display: block !important;
    max-height: none !important;
    height: auto !important;
    overflow: visible !important;
  }
  .process-timeline__step { break-inside: avoid; }

  /* ---- Tables + charts -------------------------------------------------- */
  .data-table__wrap { overflow: visible !important; }
  .data-table { min-width: 0 !important; width: 100% !important; font-size: 9pt; }
  .data-table thead { display: table-header-group; }
  .data-table tr { break-inside: avoid; }

  .chart-panel { break-inside: avoid; }

  /* ---- Links ------------------------------------------------------------ */
  .prose a { color: #000 !important; text-decoration: underline; }

  section {
    padding: 30px 0 !important;
    break-inside: avoid;
  }

  .section { padding: 30px 0 !important; }

  /* The only place colour is deliberately forced onto paper */
  .footer-bar { print-color-adjust: exact; -webkit-print-color-adjust: exact; }

  /* The carousel stacks all slides in one grid cell and reveals one via
     .is-active. On paper there is no rotation, so un-stack it and print every
     slide — otherwise 4 of the 5 sourced lessons silently vanish. */
  .carousel__track { display: block; }
  .carousel__slide {
    grid-area: auto;
    opacity: 1 !important;
    visibility: visible !important;
    break-inside: avoid;
  }
  .carousel__controls { display: none !important; }
}
