/* =============================================================================
   MondialPay — Responsive 2027 Foundation Layer
   ---------------------------------------------------------------------------
   Loaded after all core stylesheets. Provides:
     1) Fluid typography via clamp() (no more fixed px fonts that break on mobile)
     2) Consistent spacing + container scale
     3) SVG normalization (no overflow, intrinsic sizing)
     4) Image & media containment (CLS-safe)
     5) Touch-target + safe-area rules for iOS/Android notches
     6) Container-query helpers for truly modular sections
     7) Motion-reduce + contrast-preference respects
     8) Print hygiene
   Target: single source of truth for 2027 best practices.
   ============================================================================= */

/* -----------------------------------------------------------------------------
   1. DESIGN TOKENS (fluid scale)
     Uses clamp(min, preferred, max) — scales smoothly 360px → 1920px viewports.
   ----------------------------------------------------------------------------- */
:root {
  /* Fluid type scale — min / fluid / max */
  --fs-2xs: clamp(0.6875rem, 0.65rem + 0.1vw, 0.75rem);       /* 11–12px */
  --fs-xs:  clamp(0.75rem, 0.72rem + 0.15vw, 0.8125rem);      /* 12–13px */
  --fs-sm:  clamp(0.8125rem, 0.78rem + 0.2vw, 0.875rem);      /* 13–14px */
  --fs-base: clamp(0.9375rem, 0.89rem + 0.23vw, 1rem);        /* 15–16px */
  --fs-md:  clamp(1rem, 0.93rem + 0.35vw, 1.125rem);          /* 16–18px */
  --fs-lg:  clamp(1.125rem, 1.02rem + 0.52vw, 1.375rem);      /* 18–22px */
  --fs-xl:  clamp(1.25rem, 1.1rem + 0.75vw, 1.75rem);         /* 20–28px */
  --fs-2xl: clamp(1.5rem, 1.25rem + 1.25vw, 2.25rem);         /* 24–36px */
  --fs-3xl: clamp(1.875rem, 1.5rem + 1.85vw, 3rem);           /* 30–48px */
  --fs-4xl: clamp(2.25rem, 1.65rem + 3vw, 3.75rem);           /* 36–60px */
  --fs-5xl: clamp(2.75rem, 1.85rem + 4.5vw, 4.75rem);         /* 44–76px */
  --fs-6xl: clamp(3.25rem, 2rem + 6.25vw, 6rem);              /* 52–96px */

  /* Line heights paired with type scale */
  --lh-tight: 1.1;
  --lh-snug: 1.25;
  --lh-normal: 1.5;
  --lh-relaxed: 1.65;
  --lh-loose: 1.8;

  /* Fluid spacing scale */
  --space-3xs: clamp(0.25rem, 0.23rem + 0.1vw, 0.3125rem);
  --space-2xs: clamp(0.5rem, 0.46rem + 0.2vw, 0.625rem);
  --space-xs:  clamp(0.75rem, 0.68rem + 0.35vw, 1rem);
  --space-sm:  clamp(1rem, 0.9rem + 0.5vw, 1.375rem);
  --space-md:  clamp(1.5rem, 1.3rem + 1vw, 2.25rem);
  --space-lg:  clamp(2rem, 1.65rem + 1.75vw, 3.5rem);
  --space-xl:  clamp(3rem, 2.4rem + 3vw, 5.5rem);
  --space-2xl: clamp(4rem, 3rem + 5vw, 8rem);
  --space-3xl: clamp(5rem, 3.4rem + 8vw, 12rem);

  /* Section vertical rhythm — used by .section / .section-* */
  --section-py: var(--space-xl);
  --section-py-sm: var(--space-lg);
  --section-py-lg: var(--space-2xl);

  /* Container widths */
  --container-xs:  min(100% - 2rem, 40rem);
  --container-sm:  min(100% - 2rem, 48rem);
  --container-md:  min(100% - 2rem, 64rem);
  --container-lg:  min(100% - 2rem, 80rem);
  --container-xl:  min(100% - 2rem, 90rem);
  --container-2xl: min(100% - 2rem, 100rem);

  /* Radii */
  --r-xs: 0.25rem;
  --r-sm: 0.5rem;
  --r-md: 0.75rem;
  --r-lg: 1rem;
  --r-xl: 1.25rem;
  --r-2xl: 1.75rem;
  --r-pill: 9999px;

  /* Touch targets (WCAG 2.2) */
  --touch-min: 44px;
  --touch-comfort: 48px;

  /* Safe-area — iOS notch / Android gesture bars */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);

  /* Motion */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --dur-fast: 150ms;
  --dur-base: 240ms;
  --dur-slow: 400ms;
}

/* -----------------------------------------------------------------------------
   2. GLOBAL RESET / BASELINE
   ----------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  tab-size: 4;
  -moz-text-size-adjust: 100%;
  font-size: 100%; /* respect user pref */
}

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

body {
  min-height: 100vh;
  min-height: 100dvh; /* dynamic viewport — fixes iOS Safari URL-bar jump */
  line-height: var(--lh-relaxed);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: clip; /* modern replacement for hidden — allows sticky */
}

/* Global break-word so long URLs/email never cause horizontal scroll */
p, li, dd, dt, figcaption, blockquote, td, th { overflow-wrap: anywhere; }

/* -----------------------------------------------------------------------------
   3. FLUID TYPOGRAPHY (applied globally)
     Overrides any fixed px fonts in legacy files — use the cascade.
   ----------------------------------------------------------------------------- */
body { font-size: var(--fs-base); }

h1, .h1 { font-size: var(--fs-5xl); line-height: var(--lh-tight); letter-spacing: -0.02em; }
h2, .h2 { font-size: var(--fs-4xl); line-height: var(--lh-tight); letter-spacing: -0.018em; }
h3, .h3 { font-size: var(--fs-3xl); line-height: var(--lh-snug); letter-spacing: -0.015em; }
h4, .h4 { font-size: var(--fs-2xl); line-height: var(--lh-snug); letter-spacing: -0.01em; }
h5, .h5 { font-size: var(--fs-xl);  line-height: var(--lh-snug); }
h6, .h6 { font-size: var(--fs-lg);  line-height: var(--lh-normal); }

h1, h2, h3, h4, h5, h6 {
  text-wrap: balance; /* modern: prevents orphan words in headings */
  font-weight: 700;
}

p, li { text-wrap: pretty; }

.lead, .section-lead, .eyebrow ~ p { font-size: var(--fs-md); line-height: var(--lh-relaxed); }

small, .text-sm { font-size: var(--fs-sm); }
.text-xs { font-size: var(--fs-xs); }

/* -----------------------------------------------------------------------------
   4. MEDIA / SVG / IMAGE NORMALIZATION
     Fixes overflowing SVGs and preserves aspect ratio.
   ----------------------------------------------------------------------------- */
img, video, canvas, audio, iframe, embed, object, picture {
  display: block;
  max-width: 100%;
}

img, video, picture { height: auto; }

/* SVG: preserve vector ratio; do NOT force fill (would override colored icons).
   We intentionally do not set a global `svg { ... }` rule — existing component
   CSS (megamenu icons, feature cards, etc.) already sizes its own SVGs. */
svg {
  max-width: 100%;
}

/* Utility icon class only — consumers opt in with class="icon" */
.icon {
  width: 1em;
  height: 1em;
  flex-shrink: 0;
  vertical-align: middle;
}

/* Responsive aspect ratios for embedded content */
iframe, video {
  aspect-ratio: 16 / 9;
  width: 100%;
  height: auto;
}

/* Hero illustrations & explicitly marked illustrations — cap at container.
   Note: We opt in by class name rather than blanket-sizing every SVG,
   so component icons (megamenu tiles, feature-card glyphs) keep their own dimensions. */
.hero-visual > svg,
.hero-art > svg,
.section-illustration > svg,
.product-illustration > svg,
[data-illustration] > svg {
  width: 100%;
  height: auto;
  max-width: 100%;
}

figure { margin: 0; }
figure img { border-radius: var(--r-md); }

/* -----------------------------------------------------------------------------
   5. CONTAINER & LAYOUT UTILITIES
   ----------------------------------------------------------------------------- */
.container,
.container-lg { width: var(--container-lg); margin-inline: auto; padding-inline: clamp(1rem, 3vw, 2rem); }
.container-xs { width: var(--container-xs); margin-inline: auto; padding-inline: 1rem; }
.container-sm { width: var(--container-sm); margin-inline: auto; padding-inline: 1rem; }
.container-md { width: var(--container-md); margin-inline: auto; padding-inline: 1rem; }
.container-xl { width: var(--container-xl); margin-inline: auto; padding-inline: clamp(1rem, 3vw, 2rem); }
.container-2xl { width: var(--container-2xl); margin-inline: auto; padding-inline: clamp(1rem, 3vw, 2rem); }
.container-fluid { width: 100%; padding-inline: clamp(1rem, 4vw, 3rem); }

.section,
section[class*="section"] { padding-block: var(--section-py); }
.section-sm { padding-block: var(--section-py-sm); }
.section-lg { padding-block: var(--section-py-lg); }
.section-flush { padding-block: 0; }

/* Grid helpers that auto-stack on small screens */
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); gap: var(--space-md); }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr)); gap: var(--space-md); }
.grid-4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr)); gap: var(--space-md); }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr)); gap: var(--space-md); }

.stack { display: flex; flex-direction: column; gap: var(--space-sm); }
.stack-sm { gap: var(--space-xs); }
.stack-md { gap: var(--space-md); }
.stack-lg { gap: var(--space-lg); }

.cluster { display: flex; flex-wrap: wrap; gap: var(--space-xs); align-items: center; }

/* -----------------------------------------------------------------------------
   6. TOUCH TARGETS & INTERACTIVE ELEMENTS (WCAG 2.2 target-size)
   ----------------------------------------------------------------------------- */
button,
.btn,
[role="button"],
a.button,
input[type="submit"],
input[type="button"],
input[type="reset"] {
  min-height: var(--touch-min);
  min-width: var(--touch-min);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* Menu items in overlay/drawer contexts get comfortable tap targets.
   Do NOT blanket `nav a` — that would stretch dense footer link lists. */
.menu a,
[role="menuitem"],
.mobile-nav a,
.is-mobile-open .nav-menu__link {
  min-height: var(--touch-min);
  display: inline-flex;
  align-items: center;
}

/* Form inputs — prevent iOS zoom by ensuring 16px+ font-size */
input, select, textarea {
  font-size: max(16px, var(--fs-base));
  min-height: var(--touch-min);
  font-family: inherit;
}

input[type="checkbox"], input[type="radio"] {
  min-height: 1.125rem;
  min-width: 1.125rem;
}

/* Visible focus — required for a11y */
:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
  border-radius: 3px;
}

/* -----------------------------------------------------------------------------
   7. SAFE-AREA (iOS notch, Android gestures)
   ----------------------------------------------------------------------------- */
.has-safe-area-top { padding-top: var(--safe-top); }
.has-safe-area-bottom { padding-bottom: var(--safe-bottom); }
.has-safe-area-x { padding-left: var(--safe-left); padding-right: var(--safe-right); }

/* Fixed bottom bars (cookie, CTA, mobile nav) */
.fixed-bottom,
.sticky-bottom-cta,
[data-sticky-bottom] {
  padding-bottom: calc(var(--space-xs) + var(--safe-bottom));
}

/* Fullscreen overlays — respect safe areas */
.overlay,
.modal,
.drawer {
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

/* -----------------------------------------------------------------------------
   8. SKIP-TO-CONTENT — accessible for screen readers
   ----------------------------------------------------------------------------- */
.skip-to-content {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 10000;
  background: #000;
  color: #fff;
  padding: 0.75rem 1rem;
  border-radius: 0 0 var(--r-sm) 0;
  text-decoration: none;
  font-weight: 600;
}
.skip-to-content:focus {
  left: 0;
  outline: 2px solid #fff;
  outline-offset: 2px;
}

/* -----------------------------------------------------------------------------
   9. MESSAGES / ALERTS (Django messages framework)
   ----------------------------------------------------------------------------- */
.messages-container {
  padding-top: calc(var(--header-height, 72px) + var(--announcement-height, 0px) + var(--space-xs));
}
.alert {
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--r-md);
  font-size: var(--fs-sm);
  margin-block-end: var(--space-xs);
  border: 1px solid transparent;
}
.alert-success { background: #ecfdf5; color: #065f46; border-color: #a7f3d0; }
.alert-info    { background: #eff6ff; color: #1e40af; border-color: #bfdbfe; }
.alert-warning { background: #fffbeb; color: #92400e; border-color: #fde68a; }
.alert-error,
.alert-danger  { background: #fef2f2; color: #991b1b; border-color: #fecaca; }

/* -----------------------------------------------------------------------------
   10. MOBILE BREAKPOINT REFINEMENTS
     We intentionally keep these light — the fluid tokens above do the heavy lifting.
     Only break on true layout shifts.
   ----------------------------------------------------------------------------- */

/* Small tablets + below */
@media (max-width: 1024px) {
  .hide-md-down { display: none !important; }
}

/* Tablet portrait + mobile */
@media (max-width: 768px) {
  :root {
    --section-py: var(--space-lg);
    --section-py-sm: var(--space-md);
    --section-py-lg: var(--space-xl);
  }

  .hide-sm-down { display: none !important; }

  /* Stack any side-by-side 2-col layouts */
  .row-2, .two-col, .split, .split-2 {
    grid-template-columns: 1fr !important;
    flex-direction: column !important;
  }

  /* Tables: horizontal scroll wrapper */
  .table-responsive,
  table.responsive-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Reduce very large headings on small screens */
  .hero h1, .hero-title, .display-1 { line-height: 1.08; }
}

/* Phone portrait */
@media (max-width: 480px) {
  .hide-xs-down { display: none !important; }

  .container, .container-lg, .container-md, .container-xl, .container-2xl {
    padding-inline: 1rem;
  }

  /* Full-width buttons on phone for primary CTAs */
  .btn-block-mobile,
  .cta-primary-mobile {
    width: 100%;
  }

  /* Reduce card padding */
  .card, .card-body, [class*="card-"] {
    padding: var(--space-sm);
  }
}

/* Landscape phone — horizontal cramped — trim section padding further */
@media (max-height: 480px) and (orientation: landscape) {
  :root { --section-py: var(--space-md); }
}

/* Large desktop & wide monitors */
@media (min-width: 1440px) {
  .hide-lg-up { display: none !important; }
}

/* -----------------------------------------------------------------------------
   11. HOVER-CAPABILITY MEDIA QUERIES — avoid sticky hover on touch devices
   ----------------------------------------------------------------------------- */
@media (hover: hover) and (pointer: fine) {
  a:hover, button:hover, .btn:hover { transition: all var(--dur-base) var(--ease-out); }
}

@media (hover: none) {
  /* Remove hover-only effects on touch devices */
  .hover-only { display: none !important; }
  *:hover { transition: none !important; }
}

/* -----------------------------------------------------------------------------
   12. DARK-MODE AWARE (automatic if [data-theme="dark"])
   ----------------------------------------------------------------------------- */
[data-theme="dark"] img:not([src*=".svg"]):not(.no-dim) {
  filter: brightness(0.92) contrast(1.05);
}

@media (prefers-contrast: more) {
  :root {
    --fs-base: 1rem;
  }
  body { font-weight: 500; }
}

/* -----------------------------------------------------------------------------
   13. PRINT HYGIENE
   ----------------------------------------------------------------------------- */
@media print {
  header, footer, .cta-section, nav, .no-print,
  .chat-widget, .cookie-banner, .scroll-to-top { display: none !important; }
  body { font-size: 11pt; line-height: 1.4; color: #000; background: #fff; }
  a { text-decoration: underline; color: #000; }
  a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 9pt; }
  h1, h2, h3 { page-break-after: avoid; break-after: avoid; }
  img, svg, table { page-break-inside: avoid; break-inside: avoid; }
}

/* -----------------------------------------------------------------------------
   14. UTILITY ESCAPE HATCHES (for 2027 pages)
   ----------------------------------------------------------------------------- */
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

.clamp-1 { display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
.clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.clamp-3 { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.clamp-4 { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }

.text-balance { text-wrap: balance; }
.text-pretty { text-wrap: pretty; }

.flow > * + * { margin-block-start: var(--flow-space, var(--space-sm)); }
.flow-lg > * + * { margin-block-start: var(--space-md); }

/* Reveal-on-scroll baseline (JS sets .is-visible) */
[data-reveal] {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity var(--dur-slow) var(--ease-out), transform var(--dur-slow) var(--ease-out);
}
[data-reveal].is-visible { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) {
  [data-reveal] { opacity: 1; transform: none; transition: none; }
}

/* -----------------------------------------------------------------------------
   15. CONTAINER QUERIES (modern responsive — per-component)
   ----------------------------------------------------------------------------- */
.cq-card, .cq-section, [data-container-query] {
  container-type: inline-size;
}

/* Card auto-adjusts when its own width < 360px regardless of viewport */
@container (max-width: 360px) {
  .card-cq .card-title { font-size: var(--fs-md); }
  .card-cq .card-meta { flex-direction: column; align-items: flex-start; gap: 0.25rem; }
}

/* -----------------------------------------------------------------------------
   16. FIX: PREVENT HORIZONTAL SCROLL AT ANY VIEWPORT
   ----------------------------------------------------------------------------- */
html, body { max-width: 100vw; }

/* Anything absolutely positioned shouldn't push layout */
.hero, .hero-section, [class*="hero"] { overflow: clip; }

/* Long inline code/urls inside content */
pre, code { overflow-x: auto; max-width: 100%; }
pre { padding: var(--space-xs); border-radius: var(--r-sm); }
code { font-size: 0.92em; }

/* -----------------------------------------------------------------------------
   17. HEADER LOGO SIZE — final authority (loaded last, wins all cascades)
   ----------------------------------------------------------------------------- */
.header__logo-img,
.header__logo img {
  height: 64px !important;
  max-height: 64px !important;
  width: auto !important;
  max-width: none !important;
  display: block !important;
  object-fit: contain;
}
.header__logo {
  height: auto !important;
  display: flex !important;
  align-items: center !important;
}
@media (max-width: 767px) {
  .header__logo-img,
  .header__logo img {
    height: 48px !important;
    max-height: 48px !important;
  }
}
