/*
 * critical.css — above-the-fold critical CSS for Ecopan public site
 *
 * Purpose: prevent FOUC / blank flash on slow connections (3G) by ensuring
 * the browser paints a white body and a correctly-sized fixed header
 * before the main CSS bundle (global.css → /assets/index.[hash].css) arrives.
 *
 * Rules deliberately use raw values (no CSS custom properties) because
 * the token sheet has not loaded yet when this file is parsed.
 * Keep in sync with:
 *   • src/styles/base/_reset.css     (box-sizing, margin/padding reset)
 *   • src/styles/base/_body.css      (body background, color, font-family)
 *   • src/styles/tokens/_layout.css  (--header-height-sm: 3.25rem, --header-height-md: 4rem)
 *   • src/styles/tokens/_colors.css  (#ffffff = --color-white, #0f172a = --color-slate-900,
 *                                     #e2e8f0 = --color-slate-200)
 * Do NOT add anything here that is not strictly needed for first paint.
 * This file is served from 'self' — no CSP hash needed.
 */

/*
 * IMPORTANT: всё содержимое critical.css обёрнуто в @layer reset.
 *
 * Эта таблица грузится отдельным <link rel="stylesheet"> в head, ДО основного
 * бандла. Если универсальный сброс `* { margin: 0 }` оставить вне @layer,
 * по правилам CSS Cascade Layers он будет считаться unlayered и победит
 * ВСЕ правила в layered главном бандле — включая `.container-main {
 * margin-inline: auto }`. Эффект: все .container-main теряют центрирование,
 * макет прижимается к левому краю.
 *
 * Главный бандл объявляет порядок: `@layer reset, tokens, base, utilities,
 * components, overrides`. Когда critical.css первым вводит `@layer reset`,
 * последующее объявление в главном бандле этот же reset помещает на самый
 * низ каскада. utilities (`.container-main`) перебивают наш reset → центр
 * восстанавливается.
 */
@layer reset {
  /* ── Reset (minimal subset needed before main reset loads) ── */
  *,
  *::before,
  *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
  }

  /* ── Antialiasing (matches _reset.css) ───────────────────── */
  html {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    scroll-behavior: auto;
  }

  /* ── Body: white background + font stack fallback ────────── */
  body {
    background-color: #ffffff;
    color: #0f172a;
    /* System fallback until Inter Variable loads via <Font preload /> */
    font-family: system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  }
}

/* Header dimensions — keep in @layer reset same as the universal reset
   above so utilities/components can still override. The ID selector here
   has high specificity but layer order beats specificity. */
@layer reset {
  /* ── Fixed header: dimensions + white bg so it never collapses ── */
  #main-header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    /* z-index: 50 matches .header in Header.astro scoped style */
    z-index: 50;
    background-color: #ffffff;
    border-bottom: 1px solid #e2e8f0;
    /* 3.25rem = --header-height-sm (52px at 16px base) */
    height: 3.25rem;
  }

  @media (min-width: 768px) {
    #main-header {
      /* 4rem = --header-height-md (64px at 16px base) */
      height: 4rem;
    }
  }

  /*
   * Cookie consent banner anti-flash.
   * The blocking inline script in Layout.astro <head> sets
   * `<html data-consent-known>` synchronously when localStorage already
   * holds a recorded choice. This rule then keeps the banner hidden from
   * the very first paint — preventing the brief flash users saw between
   * SSR (hidden by `hidden` attr → display:none) and JS hydration (which
   * could remove the attr for a frame on some renders).
   */
  [data-consent-known] [data-cookie-banner] {
    display: none;
  }
}
