/**
 * Tối ưu mobile / iPhone — safe area, chạm, không zoom input, không tràn ngang.
 */
:root {
  --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);
  --mobile-bar-h: 52px;
  --float-stack-bottom: calc(var(--mobile-bar-h) + var(--safe-bottom) + 12px);
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  overflow-x: clip;
  -webkit-overflow-scrolling: touch;
}

@supports (overflow-x: clip) {
  body {
    overflow-x: clip;
  }
}

.container {
  padding-left: max(15px, var(--safe-left));
  padding-right: max(15px, var(--safe-right));
}

/* Sticky header + tai thỏ */
.site-header {
  top: 0;
  padding-top: var(--safe-top);
}

/* Thanh liên hệ cố định + home indicator */
@media (max-width: 768px) {
  body {
    padding-bottom: calc(var(--mobile-bar-h) + var(--safe-bottom));
  }

  .float-contact {
    display: grid;
    padding-bottom: var(--safe-bottom);
    min-height: calc(var(--mobile-bar-h) + var(--safe-bottom));
  }

  .float-contact a {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: var(--mobile-bar-h);
    padding: 10px 8px;
    font-size: 12px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }

  .scroll-top {
    right: max(12px, var(--safe-right));
    bottom: var(--float-stack-bottom);
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    touch-action: manipulation;
  }

  .zalo-float {
    right: max(12px, var(--safe-right));
    bottom: calc(var(--float-stack-bottom) + 56px);
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
    touch-action: manipulation;
  }

  /* Top bar gọn */
  .top-bar .container {
    min-height: 32px;
    padding-top: 4px;
    padding-bottom: 4px;
  }

  .top-links {
    display: none;
  }

  .top-bar span {
    font-size: 11px;
    text-align: center;
    line-height: 1.35;
  }

  /* Header compact */
  .header-main {
    grid-template-columns: minmax(0, auto) minmax(0, 1fr) auto;
    gap: 8px;
    padding: 10px 0;
  }

  .logo-img {
    height: 44px;
    max-width: min(160px, 38vw);
  }

  .search-box {
    border-width: 1.5px;
  }

  .search-box input {
    font-size: 16px;
    padding: 10px 10px;
    min-height: 44px;
  }

  .search-box button {
    min-width: 44px;
    min-height: 44px;
    padding: 0 14px;
  }

  .cart-box {
    min-width: 0;
    padding: 6px 8px;
    border-radius: 6px;
  }

  .cart-box strong {
    font-size: 10px;
  }

  .cart-box > span:not(.cart-count) {
    display: none;
  }

  .cart-count {
    top: -4px;
    right: -4px;
  }

  .menu-toggle {
    min-width: 44px;
    min-height: 44px;
    border-radius: 6px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  /* Tab danh mục — cuộn ngang, dễ chạm */
  .tab-row {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }

  .tab-row::-webkit-scrollbar {
    display: none;
  }

  .tab-row a {
    flex: 0 0 auto;
    min-width: 42%;
    max-width: 72%;
    scroll-snap-align: start;
    white-space: nowrap;
    font-size: 12px;
    padding: 13px 14px;
    border-right: 1px solid #eee;
    border-bottom: none;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Hero */
  .slider {
    height: clamp(220px, 48vw, 300px);
    min-height: 220px;
  }

  .slide-content {
    padding: 0 44px 0 max(14px, var(--safe-left));
  }

  .slide-content h2 {
    font-size: clamp(18px, 5.2vw, 24px);
    line-height: 1.2;
  }

  .slide-content p {
    font-size: 13px;
    line-height: 1.45;
    max-width: 92%;
  }

  .slider-btn {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    touch-action: manipulation;
  }

  .slider-btn.prev {
    left: max(6px, var(--safe-left));
  }

  .slider-btn.next {
    right: max(6px, var(--safe-right));
  }

  .slider-dots button {
    width: 12px;
    height: 12px;
    min-width: 12px;
    min-height: 12px;
    padding: 10px;
    box-sizing: content-box;
    background-clip: content-box;
  }

  /* Lưới sản phẩm */
  .section-title {
    font-size: clamp(18px, 4.8vw, 22px);
    padding: 0 4px;
  }

  .section-lead {
    font-size: 13px;
    padding: 0 4px;
  }

  .product-card--photo .product-body h3 {
    font-size: 13px;
  }

  .partners-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .partner-item {
    min-height: 64px;
    padding: 8px;
  }

  .promo-banner {
    padding: 20px 16px;
  }

  .promo-banner h3 {
    font-size: 18px;
  }

  .promo-phones .phone {
    white-space: normal;
    text-align: center;
    font-size: 16px;
  }

  .staff-grid--contacts {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .staff-card a.phone {
    min-height: 44px;
    width: 100%;
    touch-action: manipulation;
  }

  /* Drawer */
  .drawer-panel {
    width: min(320px, 88vw);
    padding-top: max(16px, var(--safe-top));
    padding-bottom: max(16px, var(--safe-bottom));
    padding-left: max(16px, var(--safe-left));
  }

  .drawer-panel a,
  .drawer-link {
    min-height: 44px;
    display: flex;
    align-items: center;
    font-size: 15px;
    touch-action: manipulation;
  }

  .drawer-close {
    min-height: 44px;
    min-width: 44px;
  }
}

@media (max-width: 390px) {
  .product-grid {
    gap: 8px;
  }

  .product-card--photo .product-body {
    padding: 10px 8px 12px;
  }

  .product-card--photo .product-body h3 {
    font-size: 12px;
  }

  .tab-row a {
    min-width: 48%;
    font-size: 11px;
  }
}

/* Khóa scroll khi mở menu (iOS) */
body.drawer-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
  touch-action: none;
}

body.drawer-open .site-header {
  z-index: 299;
}

/* Trang catalog / mẫu */
@media (max-width: 768px) {
  .breadcrumb-nav {
    font-size: 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .breadcrumb-nav ol {
    flex-wrap: nowrap;
    white-space: nowrap;
    padding-bottom: 2px;
  }

  .product-hero-banner img {
    max-height: 200px;
  }

  .product-title-band h1 {
    font-size: 20px;
    line-height: 1.25;
  }

  .sample-cta,
  .sample-cta--outline {
    flex: 1 1 auto;
    justify-content: center;
    min-height: 44px;
    font-size: 14px;
    touch-action: manipulation;
  }

  .sample-cta-row {
    flex-direction: column;
  }

  .sample-article__body {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    word-break: break-word;
  }

  .sample-article__body table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }

  .sample-article__body img {
    max-width: 100% !important;
    height: auto !important;
  }

  .sample-intro--rich img {
    max-width: 100% !important;
  }
}

/* Giảm motion trên iOS khi user bật Reduce Motion */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .slide.active .slide-bg {
    animation: none;
  }

  .slide {
    transition: opacity 0.2s ease;
  }
}
