/* ========================================================================== 
   Chef Fergany — Responsive Fit Layer
   Layout-only overrides. Keeps existing components, colors and interactions.
   ========================================================================== */

/* Prevent grid/flex children from forcing the page wider than the viewport. */
html,
body {
  width: 100%;
  min-width: 320px;
}

.store-shell,
.store-shell > *,
.catalog-main,
.hero-banner,
.hero-content,
.hero-visual,
.offers-section,
#offersGrid,
#productsGrid,
.product-card,
.offer-card,
.store-footer {
  min-width: 0;
}

input,
select,
textarea {
  max-width: 100%;
}

img,
svg {
  max-width: 100%;
}

/* Wide desktop and laptop screens. Keep the three existing content zones. */
@media (min-width: 1241px) {
  .store-shell {
    grid-template-columns: minmax(210px, 248px) minmax(0, 1fr) minmax(300px, 368px);
    column-gap: clamp(12px, 1.35vw, 20px);
    padding-inline: clamp(12px, 1.4vw, 20px);
  }

  .products-grid {
    grid-template-columns: repeat(auto-fill, minmax(225px, 1fr));
  }
}

/* Small laptop and landscape tablet: retain the category rail, use cart as drawer. */
@media (min-width: 861px) and (max-width: 1240px) {
  .store-shell {
    grid-template-columns: minmax(190px, 230px) minmax(0, 1fr);
    gap: clamp(12px, 1.5vw, 18px);
    padding-inline: clamp(12px, 1.5vw, 18px);
  }

  .products-grid {
    grid-template-columns: repeat(auto-fill, minmax(205px, 1fr));
    gap: 14px;
  }

  .offers-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 245px), 1fr));
  }

  .header-inner {
    grid-template-columns: minmax(175px, auto) minmax(180px, 1fr) auto;
    gap: 10px;
    padding-inline: 14px;
  }

  .header-actions {
    gap: 6px;
  }

  .btn-icon-pill {
    padding-inline: 9px;
  }
}

/* Tablet and mobile. Keep the established mobile navigation and category strip. */
@media (max-width: 860px) {
  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  body {
    padding-bottom: calc(var(--mobile-nav-h) + 12px + env(safe-area-inset-bottom, 0px));
  }

  .topbar {
    min-height: 32px;
    gap: 8px;
  }

  .topbar-group {
    min-width: 0;
    gap: 8px;
  }

  .topbar-link {
    font-size: 0.72rem;
  }

  .header-inner {
    width: 100%;
    grid-template-columns: minmax(0, 1fr) auto;
    min-width: 0;
  }

  .brand-lockup {
    min-width: 0;
    gap: 7px;
  }

  .brand-text {
    min-width: 0;
  }

  .brand-text h1,
  .brand-text span {
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .header-actions {
    min-width: 0;
    justify-content: flex-end;
  }

  .header-delivery-btn {
    max-width: 154px;
    min-width: 0;
    overflow: hidden;
  }

  .header-area-accent {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .search-wrap,
  .search-input {
    min-width: 0;
  }

  .mobile-cat-strip {
    width: 100%;
    min-width: 0;
    overscroll-behavior-x: contain;
  }

  .store-shell {
    width: 100%;
    grid-template-columns: minmax(0, 1fr);
    padding-inline: 12px;
  }

  .catalog-main {
    width: 100%;
  }

  .products-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .product-card,
  .offer-card {
    min-width: 0;
  }

  .product-body,
  .offer-body {
    min-width: 0;
  }

  .store-footer {
    align-items: flex-start;
  }

  .sidebar-left {
    width: min(420px, 94vw);
    max-width: 100%;
    max-height: 100dvh;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .mobile-bottom-nav {
    height: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom, 0px));
    padding: 4px 6px env(safe-area-inset-bottom, 0px);
  }

  .mob-nav-btn {
    min-width: 0;
  }

  .modal-overlay {
    padding: 12px;
  }

  .modal-dialog {
    width: 100%;
    max-height: calc(100dvh - 24px);
  }
}

/* Compact phones. Preserve all actions while allowing the header to breathe. */
@media (max-width: 520px) {
  .header-inner {
    padding-inline: 10px;
    gap: 7px;
  }

  .brand-logo {
    width: 36px;
    height: 36px;
  }

  .brand-text h1 {
    font-size: 0.9rem;
  }

  .brand-text span {
    display: none;
  }

  .header-delivery-btn {
    max-width: 126px;
    padding-inline: 7px;
    gap: 4px;
    font-size: 0.72rem;
  }

  .header-area-accent {
    font-size: 0.72rem;
  }

  .header-actions {
    gap: 5px;
  }

  .btn-icon-pill {
    padding-inline: 7px;
  }

  .header-address-bar {
    padding-inline: 9px;
    font-size: 0.66rem;
  }

  .store-shell {
    padding: 10px 10px 20px;
    gap: 12px;
  }

  .catalog-main {
    gap: 14px;
  }

  .offers-section {
    padding: 11px;
  }

  .product-body {
    padding: 8px;
    gap: 5px;
  }

  .product-title {
    font-size: 0.84rem;
    overflow-wrap: anywhere;
  }

  .product-desc {
    font-size: 0.72rem;
  }

  .price-current {
    font-size: 0.94rem;
  }

  .card-actions {
    gap: 4px;
  }

  .btn-add-cart {
    font-size: 0.72rem;
    gap: 3px;
  }

  .btn-options-sm {
    padding-inline: 7px;
    font-size: 0.7rem;
  }

  .section-title-group h3 {
    font-size: 1rem;
  }

  .section-subtitle {
    font-size: 0.72rem;
  }

  .store-footer {
    padding: 12px;
    font-size: 0.74rem;
    overflow-wrap: anywhere;
  }

  .offer-card {
    grid-template-columns: 96px minmax(0, 1fr);
  }

  .offer-body {
    padding: 8px;
  }

  .offer-title {
    font-size: 0.8rem;
    overflow-wrap: anywhere;
  }

  .offer-desc {
    font-size: 0.7rem;
  }

  .offer-footer {
    flex-wrap: wrap;
  }
}

/* Very narrow phones (320–380px). */
@media (max-width: 380px) {
  .topbar {
    padding-inline: 8px;
  }

  .topbar-theme-btn {
    padding-inline: 7px;
    font-size: 0.68rem;
  }

  .header-delivery-btn {
    display: none;
  }

  .header-actions {
    gap: 5px;
  }

  .header-inner {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .brand-text h1 {
    font-size: 0.86rem;
  }

  .products-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .product-body {
    padding: 10px;
  }

  .product-title {
    font-size: 0.9rem;
  }

  .product-desc {
    font-size: 0.76rem;
  }

  .btn-add-cart {
    font-size: 0.78rem;
  }

  .offer-card {
    grid-template-columns: 88px minmax(0, 1fr);
  }

  .modal-overlay {
    padding: 8px;
  }

  .modal-header {
    padding: 11px 12px;
  }

  .modal-body-grid {
    padding: 10px;
    gap: 12px;
  }
}

/* Landscape phones: avoid wasting vertical room and keep the catalog usable. */
@media (max-width: 860px) and (orientation: landscape) {
  .hero-banner {
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
  }

  .hero-content {
    padding: 13px;
  }

  .hero-visual {
    min-height: 150px;
  }

  .modal-dialog {
    max-height: calc(100dvh - 16px);
  }
}

/* Respect the device's reduced-motion preference without changing functionality. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
