/*
 * XiaomiGlobal mobile polish layer.
 * Loaded after the legacy/minified styles so mobile fixes remain predictable.
 */

@media (max-width: 767px) {
  :root {
    --xg-mobile-gutter: 14px;
    --xg-mobile-radius: 18px;
    --xg-mobile-shadow: 0 10px 30px rgba(15, 23, 42, .07);
  }

  html,
  body {
    max-width: 100%;
    overflow-x: clip !important;
  }

  body {
    padding-bottom: calc(78px + env(safe-area-inset-bottom)) !important;
    background: #fff !important;
  }

  body .hsp-container {
    width: 100% !important;
    max-width: 100% !important;
    padding-right: var(--xg-mobile-gutter) !important;
    padding-left: var(--xg-mobile-gutter) !important;
  }

  /* Compact, balanced mobile header. */
  body .site-header.hsp-fashion-menu-header {
    position: sticky !important;
    top: 0 !important;
    z-index: 1000 !important;
    border-bottom: 1px solid #eef0f3 !important;
    background: rgba(255, 255, 255, .96) !important;
    box-shadow: 0 6px 22px rgba(15, 23, 42, .05) !important;
    backdrop-filter: blur(14px) !important;
    -webkit-backdrop-filter: blur(14px) !important;
  }

  body .site-header.hsp-fashion-menu-header .hsp-fashion-menu-inner {
    min-height: 62px !important;
    display: grid !important;
    grid-template-columns: 42px minmax(0, 1fr) 42px !important;
    grid-template-areas:
      "cart brand menu"
      "search search search" !important;
    align-items: center !important;
    gap: 8px !important;
    padding-top: 8px !important;
    padding-bottom: 8px !important;
  }

  body .site-header .site-branding {
    grid-area: brand !important;
    min-width: 0 !important;
    max-width: 100% !important;
    justify-self: center !important;
  }

  body .site-header .custom-logo-link,
  body .site-header .hsp-text-logo {
    max-width: 156px !important;
    min-width: 0 !important;
    font-size: 16px !important;
    line-height: 1.2 !important;
  }

  body .site-header .custom-logo {
    width: auto !important;
    max-width: 156px !important;
    height: 34px !important;
    object-fit: contain !important;
  }

  body .site-header .hsp-menu-toggle {
    grid-area: menu !important;
    width: 42px !important;
    height: 42px !important;
    min-width: 42px !important;
    padding: 10px !important;
    border: 0 !important;
    border-radius: 13px !important;
    background: #111827 !important;
    box-shadow: none !important;
  }

  body .site-header .hsp-menu-toggle span:not(.screen-reader-text) {
    width: 20px !important;
    height: 2px !important;
    margin: 3px auto !important;
    border-radius: 99px !important;
    background: #fff !important;
  }

  body .site-header .hsp-header-actions {
    grid-area: cart !important;
    width: 42px !important;
    min-width: 42px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  body .site-header .hsp-header-actions > :not(.hsp-cart-link) {
    display: none !important;
  }

  body .site-header .hsp-header-search-bar {
    grid-area: search !important;
    display: block !important;
    width: 100% !important;
    margin: 0 !important;
  }

  body .site-header .hsp-header-search-bar .hsp-search-form {
    width: 100% !important;
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) 66px !important;
    gap: 7px !important;
  }

  body .site-header .hsp-header-search-bar input[type="search"],
  body .site-header .hsp-header-search-bar button {
    height: 40px !important;
    min-height: 40px !important;
    border-radius: 12px !important;
    font-size: 12px !important;
  }

  body .site-header .hsp-cart-link {
    width: 42px !important;
    height: 42px !important;
    min-width: 42px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    border: 1px solid #e8ebef !important;
    border-radius: 13px !important;
    background: #fff !important;
    font-size: 18px !important;
  }

  /* Menu becomes a clean drawer; secondary mega content stays folded. */
  body .site-header .main-navigation {
    position: fixed !important;
    inset: 106px 0 0 auto !important;
    width: min(88vw, 360px) !important;
    height: calc(100dvh - 106px) !important;
    max-height: none !important;
    padding: 14px !important;
    overflow-y: auto !important;
    overscroll-behavior: contain !important;
    border: 0 !important;
    border-left: 1px solid #e8ebef !important;
    border-radius: 0 !important;
    background: #fff !important;
    box-shadow: -18px 0 45px rgba(15, 23, 42, .16) !important;
  }

  body .site-header .hsp-department-menu {
    display: grid !important;
    gap: 6px !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  body .site-header .hsp-department-menu > li,
  body .site-header .hsp-nav-mega-wrap,
  body .site-header .hsp-dept-menu-wrap {
    width: 100% !important;
    margin: 0 !important;
    border: 0 !important;
  }

  body .site-header .hsp-department-menu > li > a,
  body .site-header .hsp-all-categories-toggle {
    width: 100% !important;
    min-height: 48px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    padding: 11px 13px !important;
    border: 1px solid #edf0f3 !important;
    border-radius: 13px !important;
    background: #fafbfc !important;
    color: #151820 !important;
    font-size: 13px !important;
    font-weight: 800 !important;
    line-height: 1.7 !important;
  }

  body .site-header .hsp-dept-mega,
  body .site-header .hsp-nav-mega-panel {
    position: static !important;
    width: 100% !important;
    max-width: 100% !important;
    max-height: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: hidden !important;
    border: 0 !important;
    box-shadow: none !important;
  }

  body .site-header .hsp-dept-menu-wrap.is-open > .hsp-dept-mega,
  body .site-header .hsp-nav-mega-wrap.is-open > .hsp-nav-mega-panel {
    max-height: 1200px !important;
    padding: 10px 4px 4px !important;
  }

  /* Hero: readable image-first banner without text colliding with arrows. */
  body .hsp-fresh-hero {
    width: calc(100% - 28px) !important;
    min-height: 0 !important;
    max-height: none !important;
    aspect-ratio: 16 / 10 !important;
    margin: 14px auto 10px !important;
    border: 1px solid #edf0f3 !important;
    border-radius: 20px !important;
    overflow: hidden !important;
    box-shadow: var(--xg-mobile-shadow) !important;
  }

  body .hsp-fresh-hero-slides,
  body .hsp-fresh-hero-slide {
    min-height: 0 !important;
    max-height: none !important;
    height: 100% !important;
  }

  body .hsp-fresh-hero-img {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    object-position: center !important;
  }

  body .hsp-fresh-hero-copy {
    right: 12px !important;
    left: 12px !important;
    bottom: 12px !important;
    max-width: none !important;
    min-height: 0 !important;
    padding: 10px 12px !important;
    border-radius: 14px !important;
    display: block !important;
    white-space: normal !important;
    background: rgba(255, 255, 255, .92) !important;
    box-shadow: 0 8px 22px rgba(15, 23, 42, .10) !important;
  }

  body .hsp-fresh-hero-copy strong,
  body .hsp-fresh-hero-copy h1 {
    display: block !important;
    max-width: 100% !important;
    margin: 0 !important;
    overflow: visible !important;
    white-space: normal !important;
    text-overflow: clip !important;
    font-size: clamp(16px, 5vw, 22px) !important;
    line-height: 1.45 !important;
  }

  body .hsp-fresh-hero-copy span,
  body .hsp-fresh-hero-copy small,
  body .hsp-fresh-hero-button,
  body .hsp-fresh-hero .hsp-slider-nav {
    display: none !important;
  }

  body .hsp-fresh-hero .hsp-fresh-hero-dots {
    bottom: 6px !important;
    transform: scale(.78) !important;
  }

  /* Consistent section rhythm and headings. */
  body .hsp-builder-section,
  body .hsp-section {
    max-width: 100% !important;
    overflow: hidden !important;
  }

  body .hsp-section {
    padding-top: 22px !important;
    padding-bottom: 22px !important;
  }

  body .hsp-section-headline,
  body .hsp-hotspot-headline,
  body .hsp-weekly-deal-head,
  body .hsp-trust-panel-head {
    display: grid !important;
    gap: 7px !important;
    margin: 0 0 14px !important;
    padding: 0 !important;
    text-align: right !important;
  }

  body .hsp-section-headline h2,
  body .hsp-hotspot-headline h2,
  body .hsp-weekly-deal-head h2 {
    margin: 0 !important;
    font-size: 22px !important;
    line-height: 1.45 !important;
  }

  body .hsp-section-headline p,
  body .hsp-hotspot-headline p {
    margin: 0 !important;
    font-size: 12px !important;
    line-height: 1.8 !important;
  }

  /* Product carousels: one complete card plus a useful next-card preview. */
  body .hsp-product-carousel-viewport {
    width: 100% !important;
    padding: 4px 0 10px !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    scroll-snap-type: x mandatory !important;
    scrollbar-width: none !important;
  }

  body .hsp-product-carousel-viewport::-webkit-scrollbar {
    display: none !important;
  }

  body .hsp-product-carousel {
    width: 100% !important;
    max-width: 100% !important;
  }

  body .hsp-product-carousel ul.products {
    width: max-content !important;
    max-width: none !important;
    display: flex !important;
    flex-wrap: nowrap !important;
    gap: 12px !important;
    margin: 0 !important;
    padding: 0 2px !important;
  }

  body .hsp-product-carousel ul.products li.product.hsp-loop-product-card {
    float: none !important;
    flex: 0 0 min(78vw, 286px) !important;
    width: min(78vw, 286px) !important;
    min-width: min(78vw, 286px) !important;
    max-width: min(78vw, 286px) !important;
    margin: 0 !important;
    scroll-snap-align: start !important;
    border: 1px solid #eceff3 !important;
    border-radius: var(--xg-mobile-radius) !important;
    overflow: hidden !important;
    box-shadow: var(--xg-mobile-shadow) !important;
  }

  body .woocommerce ul.products li.product.hsp-loop-product-card .hsp-loop-thumb-wrap,
  body .woocommerce ul.products li.product.hsp-loop-product-card .hsp-loop-thumb-link {
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    aspect-ratio: 1 / .88 !important;
    overflow: hidden !important;
    background: #f8fafc !important;
  }

  body .woocommerce ul.products li.product.hsp-loop-product-card img {
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    object-fit: contain !important;
    padding: 16px !important;
    transform: none !important;
  }

  body .woocommerce ul.products li.product.hsp-loop-product-card .hsp-loop-card-body {
    min-height: 168px !important;
    padding: 14px !important;
  }

  body .woocommerce ul.products li.product.hsp-loop-product-card .woocommerce-loop-product__title {
    min-height: 3.4em !important;
    margin: 4px 0 8px !important;
    font-size: 14px !important;
    line-height: 1.7 !important;
    display: -webkit-box !important;
    -webkit-line-clamp: 2 !important;
    -webkit-box-orient: vertical !important;
    overflow: hidden !important;
  }

  body .hsp-product-carousel-nav {
    display: none !important;
  }

  /* Promotional banners: image first, copy below it, never on top of products. */
  body .hsp-feature-card-grid,
  body .hsp-tech-mosaic,
  body .hsp-milana-expand-grid,
  body .hsp-weekly-deal-grid {
    width: 100% !important;
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 14px !important;
  }

  body .hsp-feature-card,
  body .hsp-tech-mosaic a,
  body .hsp-milana-expand-card,
  body .hsp-weekly-deal-card {
    width: 100% !important;
    min-width: 0 !important;
    min-height: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    padding: 0 !important;
    overflow: hidden !important;
    border: 1px solid #eceff3 !important;
    border-radius: var(--xg-mobile-radius) !important;
    background: #fff !important;
    box-shadow: var(--xg-mobile-shadow) !important;
  }

  body .hsp-feature-card .hsp-banner-media,
  body .hsp-tech-mosaic a .hsp-banner-media,
  body .hsp-milana-expand-media,
  body .hsp-weekly-deal-image {
    order: 1 !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    aspect-ratio: 16 / 9 !important;
    padding: 0 !important;
    overflow: hidden !important;
    background: #f8fafc !important;
  }

  body .hsp-feature-card .hsp-banner-media img,
  body .hsp-tech-mosaic a .hsp-banner-media img,
  body .hsp-milana-expand-media img,
  body .hsp-weekly-deal-image img {
    width: 100% !important;
    height: 100% !important;
    min-height: 0 !important;
    object-fit: contain !important;
    padding: 12px !important;
  }

  body .hsp-feature-card .hsp-banner-copy,
  body .hsp-tech-mosaic a .hsp-banner-copy,
  body .hsp-milana-expand-content,
  body .hsp-weekly-deal-copy {
    position: static !important;
    inset: auto !important;
    order: 2 !important;
    width: 100% !important;
    min-height: 0 !important;
    padding: 14px 16px 16px !important;
    transform: none !important;
    background: #fff !important;
  }

  body .hsp-banner-copy h2,
  body .hsp-banner-copy h3,
  body .hsp-milana-expand-content h3,
  body .hsp-weekly-deal-copy h3 {
    margin: 0 0 7px !important;
    font-size: 18px !important;
    line-height: 1.55 !important;
    white-space: normal !important;
  }

  /* Hotspot area becomes a simple swipe row instead of a very tall stack. */
  body .hsp-hotspot-showcase-section .hsp-hotspot-stage {
    width: 100% !important;
    min-height: 0 !important;
    max-height: none !important;
    display: flex !important;
    gap: 12px !important;
    padding: 4px 0 12px !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    scroll-snap-type: x mandatory !important;
  }

  body .hsp-hotspot-showcase-section .hsp-hotspot-scene {
    display: none !important;
  }

  body .hsp-hotspot-showcase-section .hsp-hotspot-item {
    position: relative !important;
    inset: auto !important;
    flex: 0 0 min(76vw, 280px) !important;
    width: min(76vw, 280px) !important;
    display: grid !important;
    gap: 8px !important;
    justify-items: stretch !important;
    transform: none !important;
    scroll-snap-align: start !important;
  }

  body .hsp-hotspot-showcase-section .hsp-hotspot-product-link {
    width: 100% !important;
    min-height: 0 !important;
    aspect-ratio: 1 / .9 !important;
    border: 1px solid #eceff3 !important;
    border-radius: var(--xg-mobile-radius) !important;
    overflow: hidden !important;
    background: #f8fafc !important;
  }

  body .hsp-hotspot-showcase-section .hsp-hotspot-product-image {
    width: 100% !important;
    height: 100% !important;
    max-height: none !important;
    object-fit: contain !important;
    padding: 14px !important;
  }

  body .hsp-hotspot-showcase-section .hsp-hotspot-pin-wrap {
    display: none !important;
  }

  body .hsp-hotspot-showcase-section .hsp-hotspot-preview {
    position: static !important;
    width: 100% !important;
    opacity: 1 !important;
    visibility: visible !important;
    transform: none !important;
    border: 1px solid #eceff3 !important;
    border-radius: 14px !important;
    box-shadow: none !important;
  }

  /* Bottom contact bar no longer covers content and respects safe areas. */
  body .hsp-mobile-contact-bar {
    position: fixed !important;
    right: 12px !important;
    left: 12px !important;
    bottom: calc(8px + env(safe-area-inset-bottom)) !important;
    z-index: 990 !important;
    min-height: 58px !important;
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;
    padding: 7px !important;
    border: 1px solid rgba(255, 255, 255, .7) !important;
    border-radius: 18px !important;
    background: rgba(255, 255, 255, .94) !important;
    box-shadow: 0 14px 38px rgba(15, 23, 42, .20) !important;
    backdrop-filter: blur(14px) !important;
    -webkit-backdrop-filter: blur(14px) !important;
  }

  body .hsp-mobile-contact-bar a {
    min-width: 0 !important;
    min-height: 44px !important;
    padding: 0 10px !important;
    border-radius: 13px !important;
    font-size: 12px !important;
    line-height: 1 !important;
  }

  body .hsp-mobile-dock {
    display: none !important;
  }

  body.hsp-mobile-nav-open {
    overflow: hidden !important;
    touch-action: none !important;
  }

  body.admin-bar .site-header .main-navigation {
    top: 152px !important;
    height: calc(100dvh - 152px) !important;
  }
}

@media (max-width: 390px) {
  body .site-header .custom-logo-link,
  body .site-header .hsp-text-logo,
  body .site-header .custom-logo {
    max-width: 132px !important;
  }

  body .hsp-fresh-hero {
    aspect-ratio: 4 / 3 !important;
  }

  body .hsp-product-carousel ul.products li.product.hsp-loop-product-card {
    flex-basis: 82vw !important;
    width: 82vw !important;
    min-width: 82vw !important;
    max-width: 82vw !important;
  }
}
