/* =============================================================
 * Mobile-only refinements (≤640px, with extra tweaks ≤390px).
 * This file is loaded AFTER styles.css and only contains rules
 * inside @media (max-width: …) blocks, so it never affects
 * tablet (>640px) or desktop. To roll back, remove the <link>
 * in src/routes/__root.tsx.
 * ============================================================= */

@media (max-width: 640px) {
  /* ---------- Global hygiene ---------- */
  html { -webkit-text-size-adjust: 100%; }
  body { overflow-x: hidden; }
  .container { width: min(100% - 32px, 1160px); }
  h1, h2 { text-wrap: balance; }
  p, li { text-wrap: pretty; }

  /* iOS focus-zoom fix: any input ≥16px font-size doesn't trigger zoom */
  input, textarea, select { font-size: 16px; }

  /* ---------- Header ---------- */
  .header-inner { height: 64px; gap: 12px; }
  .header.is-scrolled { box-shadow: 0 6px 18px -16px rgba(0, 0, 0, .35); }
  .brand-logo { width: 150px; }
  .menu-btn {
    width: 44px; height: 44px;
    border-radius: 12px;
    margin-left: auto;
  }
  .menu-btn span { transition: transform .22s ease, opacity .18s ease; }
  .menu-btn[aria-expanded="true"] span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
  .menu-btn[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
  .menu-btn[aria-expanded="true"] span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

  /* ============================================================
   * Full-screen mobile nav sheet
   * ============================================================ */

  /* Hide desktop-only header bits */
  .header-inner > .lang-switcher,
  .header-inner > .header-cta,
  .header-inner > .header-divider { display: none; }
  /* But re-show the one inside the mobile sheet footer */
  .header-inner .nav-sheet-footer .lang-switcher { display: inline-flex; }

  /* Backdrop */
  .menu-backdrop {
    position: fixed; inset: 0;
    background: rgba(23, 19, 18, 0.45);
    backdrop-filter: blur(4px);
    opacity: 0; visibility: hidden;
    transition: opacity .25s ease, visibility .25s ease;
    z-index: 110;
  }
  body.menu-open .menu-backdrop { opacity: 1; visibility: visible; }
  /* Lift the whole header stacking context above the backdrop so the
   * fixed .nav inside it renders on top, not behind. */
  body.menu-open .header { z-index: 130; }

  /* The sheet itself */
  .nav {
    position: fixed;
    inset: 0 0 0 auto;
    width: min(420px, 100vw);
    max-width: 100vw;
    top: 0; left: auto; right: 0; bottom: 0;
    height: 100dvh;
    background: #fff;
    border: 0;
    border-radius: 0;
    padding: 0;
    margin: 0;
    box-shadow: -20px 0 60px -30px rgba(0, 0, 0, 0.35);
    display: flex;
    flex-direction: column;
    gap: 0;
    transform: translateX(100%);
    transition: transform .3s cubic-bezier(0.22, 1, 0.36, 1);
    z-index: 120;
    overflow: hidden;
  }
  .nav.is-open { display: flex; transform: translateX(0); }
  /* Override the styles.css `display:none` on .nav (mobile) so transform animates */
  .nav { display: flex; }
  body:not(.menu-open) .nav { pointer-events: none; }
  body.menu-open { overflow: hidden; }

  /* Sheet header (logo + close) */
  .nav-sheet-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 18px;
    height: 64px;
    border-bottom: 1px solid var(--line);
    flex: none;
  }
  .nav-sheet-header .brand-logo { width: 150px; }
  .nav-sheet-close {
    width: 44px; height: 44px;
    border-radius: 12px;
    background: var(--wash-2);
    border: 1px solid var(--line);
    color: var(--ink);
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer;
    transition: background .18s ease, color .18s ease;
  }
  .nav-sheet-close:hover { background: var(--red-soft); color: var(--red); }

  /* Scrollable middle */
  .nav-sheet-links {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 14px 20px 24px;
    display: flex; flex-direction: column;
    gap: 0;
  }

  /* Top-level links */
  .nav-sheet-links > a {
    display: block;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -.01em;
    color: var(--ink);
    padding: 16px 4px;
    border-bottom: 1px solid color-mix(in oklab, var(--line) 70%, transparent);
    position: relative;
  }
  .nav-sheet-links > a::after { display: none; }
  .nav-sheet-links > a[aria-current="page"] { color: var(--red); }

  /* Megamenu inside sheet */
  .nav-sheet-links .has-megamenu {
    display: block;
    width: 100%;
    padding: 8px 0 4px;
    border-bottom: 0;
  }
  .nav-sheet-links .megamenu-trigger { display: none; }
  .nav-sheet-eyebrow {
    display: block;
    margin: 18px 0 12px;
    color: var(--red);
    font-size: 11px;
    font-weight: 850;
    letter-spacing: .18em;
    text-transform: uppercase;
  }
  .nav-sheet-links .megamenu {
    position: static;
    display: block;
    opacity: 1; visibility: visible; pointer-events: auto;
    transform: none;
    width: 100%;
    background: transparent;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    padding: 0;
    grid-template-columns: 1fr;
    overflow: visible;
  }
  /* Definitive mobile lock: iOS/Android can keep :hover/:focus-within active
     after a long press, so override the desktop megamenu centering transform. */
  body.menu-open .nav-sheet-links .has-megamenu:hover > .megamenu,
  body.menu-open .nav-sheet-links .has-megamenu:focus-within > .megamenu,
  body.menu-open .nav-sheet-links .has-megamenu > .megamenu {
    position: static;
    left: auto;
    right: auto;
    top: auto;
    transform: none !important;
  }
  .nav-sheet-links .megamenu::before { display: none; }
  .nav-sheet-links .megamenu-intro { display: none; }
  .nav-sheet-links .megamenu-cards {
    padding: 0;
    background: transparent;
    display: grid; gap: 10px;
  }
  /* Cards: "rest = hover" so they don't look bugged without hover support */
  .nav-sheet-links .megamenu-card {
    padding: 14px 16px;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: #fff;
    column-gap: 14px;
    transition: transform .15s ease, background .18s ease;
  }
  /* Neutralize desktop hover (it fires on tap and made the card "jump") */
  .nav-sheet-links .megamenu-card:hover {
    transform: none;
    box-shadow: none;
    border-color: var(--line);
    color: var(--ink);
  }
  .nav-sheet-links .megamenu-card:hover .megamenu-card-icon {
    background: var(--red-soft);
    color: var(--red);
  }
  .nav-sheet-links .megamenu-card:hover strong { color: var(--ink); }
  /* Touch-only press feedback */
  @media (hover: none) {
    .nav-sheet-links .megamenu-card:active { transform: scale(0.99); background: var(--wash-2); }
  }
  .nav-sheet-links .megamenu-card-icon {
    width: 40px; height: 40px;
    background: var(--red-soft);
    color: var(--red);
    border-radius: 12px;
  }
  .nav-sheet-links .megamenu-card-icon svg { width: 20px; height: 20px; }
  .nav-sheet-links .megamenu-card .megamenu-eyebrow {
    font-size: 10.5px; line-height: 1.2; color: var(--red);
  }
  .nav-sheet-links .megamenu-card strong {
    font-size: 16px; line-height: 1.25; color: var(--ink);
    align-items: center;
  }
  .nav-sheet-links .megamenu-card p {
    font-size: 13.5px; line-height: 1.5; margin-top: 4px;
  }
  .nav-sheet-links .megamenu-arrow {
    opacity: 1; transform: translateX(0);
    width: 14px; height: 14px;
    color: var(--red);
  }

  /* Sheet footer (lang + CTA) */
  .nav-sheet-footer {
    flex: none;
    display: flex; align-items: center; gap: 12px;
    padding: 14px 18px calc(14px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: #fff;
  }
  .nav-sheet-footer .lang-switcher {
    flex: none;
    width: auto;
    height: 40px;
    margin: 0;
  }
  .nav-sheet-footer .lang-switcher .lang-option { min-width: 0; }
  .nav-sheet-footer .lang-switcher a::after { display: none !important; }
  .nav-sheet-footer .lang-switcher a { border-bottom: 0 !important; padding: 6px 12px; }
  .nav-sheet-footer .lang-switcher .lang-option { font-size: 11px; }
  .nav-sheet-footer .lang-switcher .lang-flag { width: 16px; height: 16px; }
  .nav-sheet-cta {
    flex: 1;
    display: inline-flex; align-items: center; justify-content: center;
    padding: 12px 18px;
    font-size: 15px;
    border-radius: 999px;
    min-height: 44px;
  }

  /* ---------- Headings & lead ---------- */
  h1 { font-size: 38px; line-height: 1.02; letter-spacing: -.04em; margin-bottom: 18px; }
  h2 { font-size: 30px; line-height: 1.08; margin-bottom: 14px; }
  h3 { font-size: 19px; }
  .lead { font-size: 16.5px; line-height: 1.55; }

  /* ---------- Sections ---------- */
  .section { padding: 56px 0; }
  .section.compact { padding: 36px 0; }

  /* ---------- Hero (home) ---------- */
  .home-hero { padding: 40px 0 36px; }
  .home-hero::before { background: radial-gradient(circle at 100% 0%, rgba(158,27,34,.08), transparent 45%); }
  .hero-layout { gap: 32px; }
  .label { font-size: 11px; margin-bottom: 14px; }
  .hero-actions { gap: 10px; margin-top: 22px; flex-direction: column; align-items: stretch; }
  .hero-actions .btn { width: 100%; }

  /* ---------- Diagnostic card ---------- */
  .diagnostic-card { padding: 24px; border-radius: 22px; }
  .diagnostic-card::before { top: 22px; bottom: 22px; width: 4px; }
  .diagnostic-card h2 { font-size: 24px; }
  .diagnostic-card ul { margin: 18px 0; }

  /* ---------- Audience / cards ---------- */
  .audience { gap: 12px; margin-top: 22px; }
  .audience-card { padding: 22px; border-radius: 20px; }
  .audience-card h2 { font-size: 22px; }

  /* ---------- Buttons ---------- */
  .btn { min-height: 48px; padding: 13px 20px; }

  /* ---------- Section heads ---------- */
  .section-head { margin-bottom: 26px; }
  .section-head.split { display: block; }
  .section-head.split .btn { margin-top: 16px; width: 100%; }

  /* ---------- Two-col / detail / lead-box ---------- */
  .two-col { gap: 32px; }
  .detail { gap: 28px; padding: 36px 0; }
  .detail ul { gap: 10px; }
  .detail li { padding: 16px; border-radius: 14px; }
  .lead-box { gap: 24px; }

  /* ---------- Process & service grids ---------- */
  .process, .services-grid { gap: 12px; }
  .process article, .service-card { padding: 22px; border-radius: 18px; }
  .process span, .service-card span, .num { width: 38px; height: 38px; margin-bottom: 16px; }

  /* ---------- KPI / proof ---------- */
  .proof-grid { border-radius: 22px; }
  .proof-grid > div { padding: 22px; border-right: 0; border-bottom: 1px solid rgba(255,255,255,.12); }
  .proof-grid > div:last-child { border-bottom: 0; }
  .kpi { font-size: 40px; }

  /* ---------- Lead form (red CTA section) ---------- */
  .lead-section { padding: 48px 0; }
  .lead-form { padding: 20px; border-radius: 22px; }
  .form-inline { display: grid; gap: 10px; }
  .form-inline .btn { width: 100%; }

  /* ---------- Resources ---------- */
  .resource-grid, .resource-grid.large { gap: 12px; }
  .resource-card { padding: 22px; min-height: 0; border-radius: 18px; }

  /* ---------- Final CTA ---------- */
  .final-cta .cta-inner {
    display: flex; flex-direction: column; align-items: flex-start;
    gap: 14px; padding: 26px; border-radius: 22px;
  }
  .final-cta .cta-inner .btn { width: 100%; }

  /* ---------- Page hero (internal pages) ---------- */
  .page-hero { padding: 56px 0 44px; }
  .page-hero h1 { font-size: 36px; }

  /* ---------- Contact / forms ---------- */
  .contact-layout { gap: 18px; }
  .contact-form, .side-card { padding: 22px; border-radius: 22px; }
  .contact-form h2, .side-card h2 { font-size: 24px; }
  fieldset { padding: 14px; margin: 16px 0; border-radius: 16px; }
  .form-grid { gap: 14px; }
  .form-grid .btn { width: 100%; }
  .contact-form button[type="submit"], .contact-form .btn { width: 100%; }

  /* ---------- Team ---------- */
  .team-hero-grid { gap: 28px; }
  .team-hero-note { left: 12px; bottom: 12px; padding: 12px 14px; }
  .team-teaser-grid { padding: 22px; gap: 22px; border-radius: 22px; }
  .image-panel img { height: 240px; }

  /* ---------- LinkedIn feed ---------- */
  .linkedin-layout { gap: 22px; }
  .linkedin-post { padding: 18px 20px; border-radius: 16px; }
  .linkedin-post::before { right: 16px; top: 14px; width: 28px; height: 28px; font-size: 13px; }
  .linkedin-post span, .linkedin-post h3 { padding-right: 38px; }

  /* ---------- Article (legal/recursos detail) ---------- */
  .article h2 { font-size: 26px; margin-top: 28px; }
  .article p { font-size: 16.5px; }
  .article-cta { padding: 22px; border-radius: 20px; margin-top: 32px; }

  /* ---------- Identity panel ---------- */
  .identity-panel { padding: 24px; border-radius: 22px; }
  .identity-panel h3 { font-size: 24px; }

  /* ---------- Footer ---------- */
  .footer { padding: 48px 0 22px; }
  .footer-grid { gap: 28px; }
  .footer .brand-logo { width: 220px; }
  .footer h3 { margin-top: 4px; }
  .footer-bottom { margin-top: 32px; padding-top: 16px; }
  .footer-social { gap: 8px; margin-top: 14px; }
  .footer-social a { width: 40px; height: 40px; }

  /* ---------- Skip link (visibility on small screens) ---------- */
  .skip-link:focus { left: 12px; top: 12px; }
}

/* =============================================================
 * Extra tightening for very narrow phones (iPhone SE, S8)
 * ============================================================= */
@media (max-width: 390px) {
  .container { width: min(100% - 24px, 1160px); }
  .brand-logo { width: 138px; }
  .header-inner { height: 60px; }

  h1 { font-size: 32px; }
  h2 { font-size: 26px; }
  .page-hero h1 { font-size: 30px; }
  .diagnostic-card h2 { font-size: 22px; }

  .section { padding: 48px 0; }
  .home-hero { padding: 32px 0 28px; }

  .diagnostic-card,
  .audience-card,
  .service-card,
  .resource-card,
  .contact-form,
  .side-card,
  .lead-form,
  .article-cta { padding: 20px; }

  .btn { padding: 12px 18px; font-size: 14.5px; }
  .footer .brand-logo { width: 200px; }
}
