/*
 * ============================================================
 * GAINVO Storefront v0.10.2 — MOBILE HEADER FOUNDATION
 * ============================================================
 *
 * FINAL AUTHORITY FOR ALL MOBILE STOREFRONT HEADERS.
 *
 * DESIGN TARGET
 * - Standard phone app header: 52px
 * - Official Storefront logo: 28px
 * - Location sits directly beside logo
 * - Heart/cart visual icons: 20px
 * - Heart/cart touch target: 44px
 * - Device status area handled exactly once
 *
 * ENGINEERING CONTRACT
 * 1. Never add safe-area padding directly inside `.topbar`.
 * 2. In standalone mode, `.topbar` is fixed BELOW the safe area.
 * 3. `.app-shell` reserves safe-area + header height exactly once.
 * 4. No page-specific header geometry is allowed.
 * 5. Never restore the mobile GAINVO wordmark beside the icon.
 */

@media (max-width:759px){
  :root{
    --gainvo-mobile-header-h:52px;
    --gainvo-mobile-logo:28px;
    --gainvo-mobile-action-hit:44px;
    --gainvo-mobile-action-icon:20px;
    --gainvo-mobile-status-safe:env(safe-area-inset-top,0px);
    --installed-header-height:52px;
  }

  /* ==========================================================
     COMMON MOBILE HEADER — ALL SCREENS
     ========================================================== */
  body .topbar,
  body:has(.home-v0911.active) .topbar,
  body:has(.screen[data-screen="home"].active) .topbar,
  body:has(.screen[data-screen="search"].active) .topbar,
  body:has(.screen[data-screen="shops"].active) .topbar,
  body:has(.screen[data-screen="orders"].active) .topbar,
  body:has(.screen[data-screen="account"].active) .topbar,
  body:has(.screen[data-screen="shop"].active) .topbar,
  body[data-active-screen="shop"] .topbar{
    position:sticky!important;
    inset:auto!important;
    top:0!important;
    left:auto!important;
    right:auto!important;
    z-index:65!important;

    display:block!important;
    width:100%!important;
    max-width:none!important;
    height:var(--gainvo-mobile-header-h)!important;
    min-height:var(--gainvo-mobile-header-h)!important;
    max-height:var(--gainvo-mobile-header-h)!important;

    margin:0!important;
    padding:4px 10px!important;
    box-sizing:border-box!important;
    overflow:visible!important;

    transform:none!important;
    contain:none!important;

    border-bottom:1px solid rgba(125,148,167,.18)!important;
    box-shadow:0 1px 0 rgba(8,34,59,.035)!important;
    backdrop-filter:blur(18px)!important;
    -webkit-backdrop-filter:blur(18px)!important;
  }

  .topbar .brand-row,
  body:has(.home-v0911.active) .topbar .brand-row{
    display:grid!important;
    grid-template-columns:minmax(0,1fr) auto!important;
    align-items:center!important;
    gap:7px!important;

    width:100%!important;
    height:44px!important;
    min-height:44px!important;
    max-height:44px!important;

    margin:0!important;
    padding:0!important;
  }

  /* Logo + location form one compact left group. */
  .topbar .brand-stack,
  body:has(.home-v0911.active) .topbar .brand-stack{
    display:flex!important;
    flex-direction:row!important;
    align-items:center!important;
    justify-content:flex-start!important;
    gap:6px!important;

    width:auto!important;
    min-width:0!important;
    height:44px!important;
    min-height:44px!important;
    max-height:44px!important;

    margin:0!important;
    padding:0!important;
  }

  .topbar .brand,
  body:has(.home-v0911.active) .topbar .brand{
    position:static!important;
    display:flex!important;
    align-items:center!important;
    justify-content:center!important;

    flex:0 0 var(--gainvo-mobile-logo)!important;
    width:var(--gainvo-mobile-logo)!important;
    min-width:var(--gainvo-mobile-logo)!important;
    max-width:var(--gainvo-mobile-logo)!important;
    height:var(--gainvo-mobile-logo)!important;
    min-height:var(--gainvo-mobile-logo)!important;
    max-height:var(--gainvo-mobile-logo)!important;

    margin:0!important;
    padding:0!important;
    gap:0!important;
    transform:none!important;
  }

  .topbar .brand .brand-mark,
  body:has(.home-v0911.active) .topbar .brand .brand-mark{
    display:block!important;
    width:var(--gainvo-mobile-logo)!important;
    min-width:var(--gainvo-mobile-logo)!important;
    max-width:var(--gainvo-mobile-logo)!important;
    height:var(--gainvo-mobile-logo)!important;
    min-height:var(--gainvo-mobile-logo)!important;
    max-height:var(--gainvo-mobile-logo)!important;

    object-fit:cover!important;
    border-radius:8px!important;
    background:transparent!important;
    filter:none!important;
    -webkit-filter:none!important;
    opacity:1!important;
    box-shadow:0 2px 6px rgba(3,33,76,.15)!important;
  }

  /* The approved app icon is the mobile brand identity. */
  .topbar .brand>span,
  body:has(.home-v0911.active) .topbar .brand>span{
    display:none!important;
  }

  .topbar .home-brand-location,
  body:has(.home-v0911.active) .topbar .home-brand-location,
  body:has(.screen[data-screen="home"].active) .home-brand-location,
  body:has(.screen[data-screen="search"].active) .home-brand-location,
  body:has(.screen[data-screen="shops"].active) .home-brand-location,
  body:has(.screen[data-screen="orders"].active) .home-brand-location,
  body:has(.screen[data-screen="account"].active) .home-brand-location,
  body:has(.screen[data-screen="shop"].active) .home-brand-location,
  body[data-active-screen="shop"] .home-brand-location{
    position:static!important;
    display:inline-flex!important;
    align-items:center!important;
    justify-content:flex-start!important;
    flex:0 1 auto!important;

    min-width:0!important;
    max-width:min(50vw,190px)!important;
    width:auto!important;
    height:36px!important;
    min-height:36px!important;
    max-height:36px!important;

    margin:0!important;
    padding:0!important;
    gap:4px!important;

    border:0!important;
    border-radius:0!important;
    background:transparent!important;
    box-shadow:none!important;
    transform:none!important;

    color:var(--ink)!important;
    text-align:left!important;
  }

  .topbar .home-brand-location>svg:first-child{
    width:12px!important;
    height:12px!important;
    min-width:12px!important;
    flex:0 0 12px!important;
    fill:#16b7a4!important;
    stroke:#16b7a4!important;
  }

  .topbar .home-brand-location strong{
    display:block!important;
    min-width:0!important;
    margin:0!important;
    overflow:hidden!important;
    text-overflow:ellipsis!important;
    white-space:nowrap!important;

    font-size:12px!important;
    line-height:1!important;
    font-weight:800!important;
    letter-spacing:0!important;
  }

  .topbar .home-location-chevron{
    width:10px!important;
    height:10px!important;
    min-width:10px!important;
    flex:0 0 10px!important;
    margin-left:1px!important;
    fill:none!important;
    stroke:currentColor!important;
    stroke-width:1.8!important;
    opacity:.70!important;
  }

  /* 44px touch target, visually smaller 20px symbols. */
  .topbar .top-actions,
  body:has(.home-v0911.active) .topbar .top-actions{
    display:flex!important;
    align-items:center!important;
    justify-content:flex-end!important;
    gap:4px!important;

    height:44px!important;
    min-height:44px!important;
    max-height:44px!important;

    margin:0!important;
    padding:0!important;
    flex:0 0 auto!important;
    transform:none!important;
  }

  .topbar .top-actions .icon-button,
  body:has(.home-v0911.active) .topbar .top-actions .icon-button{
    position:relative!important;
    display:grid!important;
    place-items:center!important;

    width:var(--gainvo-mobile-action-hit)!important;
    min-width:var(--gainvo-mobile-action-hit)!important;
    max-width:var(--gainvo-mobile-action-hit)!important;
    height:var(--gainvo-mobile-action-hit)!important;
    min-height:var(--gainvo-mobile-action-hit)!important;
    max-height:var(--gainvo-mobile-action-hit)!important;

    margin:0!important;
    padding:0!important;
    border-radius:12px!important;
    transform:none!important;
    box-shadow:none!important;
  }

  .topbar .top-action-svg,
  body:has(.home-v0911.active) .topbar .top-action-svg,
  .topbar #cartBtn .top-action-svg{
    width:var(--gainvo-mobile-action-icon)!important;
    height:var(--gainvo-mobile-action-icon)!important;
    min-width:var(--gainvo-mobile-action-icon)!important;
    max-width:var(--gainvo-mobile-action-icon)!important;
    flex:0 0 var(--gainvo-mobile-action-icon)!important;
    stroke-width:1.8!important;
  }

  .topbar .cart-count{
    top:-2px!important;
    right:-2px!important;
    min-width:17px!important;
    height:17px!important;
    padding:0 4px!important;
    font-size:8px!important;
    line-height:17px!important;
  }

  /* Old full-width location row is desktop-only. */
  .topbar>.location-pill{
    display:none!important;
  }

  html[data-theme="dark"] .topbar .home-brand-location,
  html[data-theme="dark"] .topbar .home-brand-location strong{
    color:#f5f8fb!important;
  }
}

/* ============================================================
   INSTALLED APP SAFE AREA — EXACTLY ONCE
   ============================================================ */
@media (display-mode:standalone) and (max-width:759px){
  :root{
    --installed-header-height:
      calc(var(--gainvo-mobile-status-safe) + var(--gainvo-mobile-header-h));
  }

  /* Keep the OS/status region GAINVO navy. */
  html::before{
    content:"";
    position:fixed;
    z-index:10000;
    top:0;
    left:0;
    right:0;
    height:var(--gainvo-mobile-status-safe);
    background:#082f63;
    pointer-events:none;
  }

  /* Fixed header starts directly BELOW status area. */
  body .topbar,
  body:has(.home-v0911.active) .topbar,
  body:has(.screen[data-screen="home"].active) .topbar,
  body:has(.screen[data-screen="search"].active) .topbar,
  body:has(.screen[data-screen="shops"].active) .topbar,
  body:has(.screen[data-screen="orders"].active) .topbar,
  body:has(.screen[data-screen="account"].active) .topbar,
  body:has(.screen[data-screen="shop"].active) .topbar,
  body[data-active-screen="shop"] .topbar{
    position:fixed!important;
    inset:auto 0 auto 0!important;
    top:var(--gainvo-mobile-status-safe)!important;
    left:0!important;
    right:0!important;
    transform:none!important;
    width:100%!important;
    max-width:none!important;
    margin:0!important;
    padding:4px 10px!important;
  }

  /* Reserve status area + header once. Overrides historical 72px shell pad. */
  body .app-shell{
    width:100%!important;
    min-height:100dvh!important;
    padding-top:var(--installed-header-height)!important;
    box-sizing:border-box!important;
    transform:none!important;
    transition:none!important;
  }

  /* Header itself receives NO safe-area padding. */
  body .topbar{
    padding-top:4px!important;
  }

  /* Pull-to-refresh sits beneath the compact header. */
  .pull-refresh{
    top:calc(var(--installed-header-height) + 6px)!important;
  }
  .refresh-success{
    top:calc(var(--installed-header-height) + 8px)!important;
  }
}

/* iOS standalone fallback for Safari/PWA versions with unreliable media query. */
@supports(-webkit-touch-callout:none){
  @media(max-width:759px){
    html.gainvo-standalone{
      --installed-header-height:
        calc(var(--gainvo-mobile-status-safe) + var(--gainvo-mobile-header-h));
    }

    html.gainvo-standalone::before{
      content:"";
      position:fixed;
      z-index:10000;
      top:0;
      left:0;
      right:0;
      height:var(--gainvo-mobile-status-safe);
      background:#082f63;
      pointer-events:none;
    }

    html.gainvo-standalone body .topbar{
      position:fixed!important;
      inset:auto 0 auto 0!important;
      top:var(--gainvo-mobile-status-safe)!important;
      left:0!important;
      right:0!important;
      width:100%!important;
      max-width:none!important;
      transform:none!important;
      margin:0!important;
      padding:4px 10px!important;
    }

    html.gainvo-standalone body .app-shell{
      padding-top:var(--installed-header-height)!important;
      box-sizing:border-box!important;
    }
  }
}

/* Compact phones preserve the same structure. */
@media(max-width:360px){
  :root{
    --gainvo-mobile-header-h:50px;
    --gainvo-mobile-logo:27px;
    --gainvo-mobile-action-hit:42px;
    --gainvo-mobile-action-icon:19px;
  }

  body .topbar{
    padding-left:8px!important;
    padding-right:8px!important;
  }

  .topbar .brand-row,
  .topbar .brand-stack{
    height:42px!important;
    min-height:42px!important;
    max-height:42px!important;
  }

  .topbar .home-brand-location{
    height:34px!important;
    min-height:34px!important;
    max-height:34px!important;
    max-width:min(48vw,155px)!important;
  }

  .topbar .home-brand-location strong{
    font-size:11px!important;
  }

  .topbar .top-actions{
    height:42px!important;
    min-height:42px!important;
    max-height:42px!important;
    gap:3px!important;
  }
}


/* ============================================================
   v0.10.3 — HEADER PARITY ACROSS ALL STOREFRONT PAGES
   ============================================================ */
@media(max-width:759px){
  body:has(.screen[data-screen="search"].active) .topbar,
  body:has(.screen[data-screen="shops"].active) .topbar,
  body:has(.screen[data-screen="orders"].active) .topbar,
  body:has(.screen[data-screen="account"].active) .topbar,
  body:has(.screen[data-screen="shop"].active) .topbar,
  body[data-active-screen="search"] .topbar,
  body[data-active-screen="shops"] .topbar,
  body[data-active-screen="orders"] .topbar,
  body[data-active-screen="account"] .topbar,
  body[data-active-screen="shop"] .topbar,
  body:has(.product-modal.open) .topbar{
    height:var(--gainvo-mobile-header-h)!important;
    min-height:var(--gainvo-mobile-header-h)!important;
    max-height:var(--gainvo-mobile-header-h)!important;
    padding:4px 10px!important;
    margin:0!important;
    transform:none!important;
  }

  body:has(.screen[data-screen="search"].active) .brand-row,
  body:has(.screen[data-screen="shops"].active) .brand-row,
  body:has(.screen[data-screen="orders"].active) .brand-row,
  body:has(.screen[data-screen="account"].active) .brand-row,
  body:has(.screen[data-screen="shop"].active) .brand-row,
  body[data-active-screen="search"] .brand-row,
  body[data-active-screen="shops"] .brand-row,
  body[data-active-screen="orders"] .brand-row,
  body[data-active-screen="account"] .brand-row,
  body[data-active-screen="shop"] .brand-row,
  body:has(.product-modal.open) .brand-row{
    display:grid!important;
    grid-template-columns:minmax(0,1fr) auto!important;
    align-items:center!important;
    gap:7px!important;
    height:44px!important;
    min-height:44px!important;
    max-height:44px!important;
    margin:0!important;
    padding:0!important;
  }

  body:has(.screen[data-screen="search"].active) .brand-stack,
  body:has(.screen[data-screen="shops"].active) .brand-stack,
  body:has(.screen[data-screen="orders"].active) .brand-stack,
  body:has(.screen[data-screen="account"].active) .brand-stack,
  body:has(.screen[data-screen="shop"].active) .brand-stack,
  body[data-active-screen="search"] .brand-stack,
  body[data-active-screen="shops"] .brand-stack,
  body[data-active-screen="orders"] .brand-stack,
  body[data-active-screen="account"] .brand-stack,
  body[data-active-screen="shop"] .brand-stack,
  body:has(.product-modal.open) .brand-stack{
    display:flex!important;
    flex-direction:row!important;
    align-items:center!important;
    justify-content:flex-start!important;
    gap:6px!important;
    height:44px!important;
    min-height:44px!important;
    max-height:44px!important;
    margin:0!important;
    padding:0!important;
  }

  body:has(.screen[data-screen="search"].active) .brand,
  body:has(.screen[data-screen="shops"].active) .brand,
  body:has(.screen[data-screen="orders"].active) .brand,
  body:has(.screen[data-screen="account"].active) .brand,
  body:has(.screen[data-screen="shop"].active) .brand,
  body[data-active-screen="search"] .brand,
  body[data-active-screen="shops"] .brand,
  body[data-active-screen="orders"] .brand,
  body[data-active-screen="account"] .brand,
  body[data-active-screen="shop"] .brand,
  body:has(.product-modal.open) .brand{
    flex:0 0 var(--gainvo-mobile-logo)!important;
    width:var(--gainvo-mobile-logo)!important;
    min-width:var(--gainvo-mobile-logo)!important;
    max-width:var(--gainvo-mobile-logo)!important;
    height:var(--gainvo-mobile-logo)!important;
    min-height:var(--gainvo-mobile-logo)!important;
    max-height:var(--gainvo-mobile-logo)!important;
    gap:0!important;
    margin:0!important;
    padding:0!important;
  }

  body:has(.screen[data-screen="search"].active) .brand-mark,
  body:has(.screen[data-screen="shops"].active) .brand-mark,
  body:has(.screen[data-screen="orders"].active) .brand-mark,
  body:has(.screen[data-screen="account"].active) .brand-mark,
  body:has(.screen[data-screen="shop"].active) .brand-mark,
  body[data-active-screen="search"] .brand-mark,
  body[data-active-screen="shops"] .brand-mark,
  body[data-active-screen="orders"] .brand-mark,
  body[data-active-screen="account"] .brand-mark,
  body[data-active-screen="shop"] .brand-mark,
  body:has(.product-modal.open) .brand-mark{
    width:var(--gainvo-mobile-logo)!important;
    min-width:var(--gainvo-mobile-logo)!important;
    max-width:var(--gainvo-mobile-logo)!important;
    height:var(--gainvo-mobile-logo)!important;
    min-height:var(--gainvo-mobile-logo)!important;
    max-height:var(--gainvo-mobile-logo)!important;
    flex:0 0 var(--gainvo-mobile-logo)!important;
  }

  body:has(.screen[data-screen="search"].active) .brand>span,
  body:has(.screen[data-screen="shops"].active) .brand>span,
  body:has(.screen[data-screen="orders"].active) .brand>span,
  body:has(.screen[data-screen="account"].active) .brand>span,
  body:has(.screen[data-screen="shop"].active) .brand>span,
  body[data-active-screen="search"] .brand>span,
  body[data-active-screen="shops"] .brand>span,
  body[data-active-screen="orders"] .brand>span,
  body[data-active-screen="account"] .brand>span,
  body[data-active-screen="shop"] .brand>span,
  body:has(.product-modal.open) .brand>span{
    display:none!important;
  }

  body:has(.screen[data-screen="search"].active) .home-brand-location,
  body:has(.screen[data-screen="shops"].active) .home-brand-location,
  body:has(.screen[data-screen="orders"].active) .home-brand-location,
  body:has(.screen[data-screen="account"].active) .home-brand-location,
  body:has(.screen[data-screen="shop"].active) .home-brand-location,
  body[data-active-screen="search"] .home-brand-location,
  body[data-active-screen="shops"] .home-brand-location,
  body[data-active-screen="orders"] .home-brand-location,
  body[data-active-screen="account"] .home-brand-location,
  body[data-active-screen="shop"] .home-brand-location,
  body:has(.product-modal.open) .home-brand-location{
    position:static!important;
    display:inline-flex!important;
    align-items:center!important;
    justify-content:flex-start!important;
    flex:0 1 auto!important;
    width:auto!important;
    max-width:min(50vw,190px)!important;
    height:36px!important;
    min-height:36px!important;
    max-height:36px!important;
    margin:0!important;
    padding:0!important;
    gap:4px!important;
    transform:none!important;
    border:0!important;
    background:transparent!important;
    box-shadow:none!important;
  }

  body:has(.screen[data-screen="search"].active) .top-actions,
  body:has(.screen[data-screen="shops"].active) .top-actions,
  body:has(.screen[data-screen="orders"].active) .top-actions,
  body:has(.screen[data-screen="account"].active) .top-actions,
  body:has(.screen[data-screen="shop"].active) .top-actions,
  body[data-active-screen="search"] .top-actions,
  body[data-active-screen="shops"] .top-actions,
  body[data-active-screen="orders"] .top-actions,
  body[data-active-screen="account"] .top-actions,
  body[data-active-screen="shop"] .top-actions,
  body:has(.product-modal.open) .top-actions{
    display:flex!important;
    align-items:center!important;
    justify-content:flex-end!important;
    gap:4px!important;
    height:44px!important;
    margin:0!important;
    padding:0!important;
  }

  body:has(.screen[data-screen="search"].active) .top-actions .icon-button,
  body:has(.screen[data-screen="shops"].active) .top-actions .icon-button,
  body:has(.screen[data-screen="orders"].active) .top-actions .icon-button,
  body:has(.screen[data-screen="account"].active) .top-actions .icon-button,
  body:has(.screen[data-screen="shop"].active) .top-actions .icon-button,
  body[data-active-screen="search"] .top-actions .icon-button,
  body[data-active-screen="shops"] .top-actions .icon-button,
  body[data-active-screen="orders"] .top-actions .icon-button,
  body[data-active-screen="account"] .top-actions .icon-button,
  body[data-active-screen="shop"] .top-actions .icon-button,
  body:has(.product-modal.open) .top-actions .icon-button{
    width:var(--gainvo-mobile-action-hit)!important;
    min-width:var(--gainvo-mobile-action-hit)!important;
    max-width:var(--gainvo-mobile-action-hit)!important;
    height:var(--gainvo-mobile-action-hit)!important;
    min-height:var(--gainvo-mobile-action-hit)!important;
    max-height:var(--gainvo-mobile-action-hit)!important;
    border-radius:12px!important;
    margin:0!important;
    padding:0!important;
    box-shadow:none!important;
  }

  /* Product details keep the global Storefront header visible.
     Its own row becomes a compact contextual back/share bar underneath. */
  body:has(.product-modal.open) .topbar{
    z-index:90!important;
  }

  body:has(.product-modal.open) .product-modal{
    z-index:80!important;
    top:var(--gainvo-mobile-header-h)!important;
    height:calc(100dvh - var(--gainvo-mobile-header-h))!important;
    max-height:calc(100dvh - var(--gainvo-mobile-header-h))!important;
  }

  body:has(.product-modal.open) .pdp-topbar{
    min-height:44px!important;
    height:44px!important;
    grid-template-columns:36px minmax(0,1fr) 36px!important;
    padding:4px 10px!important;
    gap:6px!important;
  }

  body:has(.product-modal.open) .pdp-back-button,
  body:has(.product-modal.open) .pdp-icon-button{
    width:34px!important;
    height:34px!important;
    min-width:34px!important;
    min-height:34px!important;
    border-radius:10px!important;
  }

  body:has(.product-modal.open) .pdp-back-button svg,
  body:has(.product-modal.open) .pdp-icon-button svg{
    width:17px!important;
    height:17px!important;
  }

  body:has(.product-modal.open) .pdp-topbar-title{
    font-size:11px!important;
  }
}

@media(display-mode:standalone) and (max-width:759px){
  body:has(.product-modal.open) .product-modal{
    top:var(--installed-header-height)!important;
    height:calc(100dvh - var(--installed-header-height))!important;
    max-height:calc(100dvh - var(--installed-header-height))!important;
  }
}

@supports(-webkit-touch-callout:none){
  @media(max-width:759px){
    html.gainvo-standalone body:has(.product-modal.open) .product-modal{
      top:var(--installed-header-height)!important;
      height:calc(100dvh - var(--installed-header-height))!important;
      max-height:calc(100dvh - var(--installed-header-height))!important;
    }
  }
}
