/* ==========================================================================
   Seedistry Comprehensive Responsive Design System (css/responsive.css)
   Targeted Viewports:
     - Large Desktops: 1200px+
     - Laptops & Tablets Landscape: 1024px
     - Tablets Portrait: 768px
     - Modern Smartphones (iPhone 14/15, Pixel, Galaxy): 580px - 420px
     - Compact Smartphones (iPhone SE, Small Androids): 320px - 380px
   Tested and verified for zero horizontal overflow, fluid typography,
   thumb-friendly touch targets (min 44px), and native-like app drawers.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Universal Mobile & Small Screen Foundations (< 1024px)
   -------------------------------------------------------------------------- */
@media (max-width: 1024px) {
  /* Layout Grids */
  .hero-grid {
    grid-template-columns: 1fr;
    gap: var(--space-8);
  }

  .shop-layout {
    grid-template-columns: 1fr;
    gap: var(--space-6);
  }

  /* Filter Drawer in Shop Page */
  #mobile-filter-drawer-btn {
    display: inline-flex !important;
    align-items: center;
    gap: 6px;
  }

  #mobile-filter-close-btn {
    display: inline-flex !important;
  }

  .filter-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(340px, 86vw);
    z-index: var(--z-drawer);
    background: var(--color-bg-white);
    padding: var(--space-5);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    transform: translateX(-105%);
    transition: transform var(--transition-normal);
    box-shadow: var(--shadow-lg);
    border-radius: 0;
    border: none;
    border-right: 1px solid var(--color-border);
  }

  .filter-sidebar.is-open {
    transform: translateX(0);
  }

  /* Drawer Backdrop */
  .drawer-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(7, 38, 29, 0.65);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: calc(var(--z-drawer) - 1);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-normal);
  }

  .drawer-backdrop.is-open {
    opacity: 1;
    pointer-events: auto;
  }

  body.drawer-open {
    overflow: hidden;
  }

  /* 2-Column Desktop Grid collapses */
  .pdp-grid,
  .cart-layout {
    grid-template-columns: 1fr;
    gap: var(--space-6);
  }

  .summary-card {
    position: static;
  }

  /* Footer 2-Column */
  .footer-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-6);
  }
}

/* --------------------------------------------------------------------------
   2. Tablets Portrait & Phablets (< 768px)
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  :root {
    --container-pad: 1rem;
    --space-12: 2.25rem;
    --space-16: 2.75rem;
  }

  /* Body overflow safeguard */
  body {
    overflow-x: hidden;
  }

  body.nav-open {
    overflow: hidden;
  }

  /* Typography Scale refinement */
  h1 { font-size: clamp(1.85rem, 5vw, 2.35rem); }
  h2 { font-size: clamp(1.45rem, 4.2vw, 1.85rem); }
  h3 { font-size: clamp(1.2rem, 3.4vw, 1.45rem); }

  /* Announcement Bar */
  .announcement-bar {
    padding: var(--space-2) 0;
    font-size: var(--text-xs);
  }

  .announcement-inner {
    justify-content: center;
    text-align: center;
  }

  .announcement-links {
    display: none; /* Keep announcement bar concise on tablets/phones */
  }

  /* Site Header */
  .header-main {
    flex-wrap: wrap;
    gap: var(--space-3);
    padding: 0.65rem 0;
  }

  .brand-logo-img {
    height: 44px;
    width: auto;
  }

  .brand-tagline-mini {
    display: none;
  }

  /* Header Utility Actions (Wishlist, Cart, Account, Menu) */
  .header-actions {
    gap: 8px;
    margin-left: auto;
  }

  .header-action-btn {
    width: 40px;
    height: 40px;
    min-width: 40px;
    padding: 0;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: relative;
  }

  .header-action-btn .action-label {
    display: none !important;
  }

  .header-action-btn .count-pill {
    position: absolute;
    top: -4px;
    right: -4px;
    font-size: 0.68rem;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
  }

  .mobile-menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 40px;
    padding: 0 12px;
    font-size: var(--text-xs);
    border-radius: var(--radius-pill);
    background: var(--color-forest);
    color: var(--color-bg-cream);
  }

  .mobile-menu-toggle.is-active {
    background: var(--color-terracotta);
  }

  /* Full-width Search Bar beneath brand and actions */
  .header-search-wrap {
    order: 3;
    flex: 1 1 100%;
    max-width: 100%;
    margin-top: 2px;
  }

  .header-search-form {
    border-width: 1.5px;
  }

  .header-search-input {
    font-size: 16px; /* Prevents auto-zoom on iOS */
    padding: 0.52rem 0.85rem;
  }

  .header-search-btn {
    padding: 0.52rem 1rem;
    font-size: var(--text-xs);
  }

  /* Mobile Slide-Down Navigation Menu */
  .mobile-nav-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(7, 38, 29, 0.65);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 190;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-normal);
  }

  .mobile-nav-backdrop.is-open {
    opacity: 1;
    pointer-events: auto;
  }

  .header-nav-bar {
    display: block;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--color-bg-white);
    border-top: 1px solid var(--color-border);
    border-bottom: 3px solid var(--color-forest);
    box-shadow: 0 14px 32px rgba(13, 59, 46, 0.18);
    max-height: calc(100vh - 120px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    transform: translateY(-120%);
    opacity: 0;
    pointer-events: none;
    transition: transform 260ms cubic-bezier(0.2, 0, 0, 1), opacity 240ms ease;
    z-index: 200;
  }

  .header-nav-bar.is-open {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
  }

  .mobile-nav-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-3) var(--space-4);
    background: var(--color-bg-stone);
    border-bottom: 1px solid var(--color-border);
  }

  .mobile-nav-title strong {
    display: block;
    font-size: var(--text-sm);
    color: var(--color-forest);
  }

  .mobile-nav-title span {
    font-size: var(--text-xs);
    color: var(--color-text-muted);
  }

  .mobile-nav-close-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid var(--color-border-strong);
    background: var(--color-bg-white);
    color: var(--color-forest);
    font-size: 1rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
  }

  .main-nav-list {
    flex-direction: column;
    align-items: stretch;
    padding: var(--space-2) 0 var(--space-4);
  }

  .main-nav-item {
    border-bottom: 1px solid var(--color-bg-stone);
  }

  .main-nav-item:last-child {
    border-bottom: none;
  }

  .main-nav-link {
    width: 100%;
    justify-content: space-between;
    padding: 0.75rem var(--space-4);
    font-size: var(--text-sm);
    border-bottom: none;
  }

  .main-nav-link:hover,
  .main-nav-link.is-active {
    background-color: var(--color-bg-sage);
    border-bottom: none;
    border-left: 4px solid var(--color-forest);
  }

  /* Subcategories inside Mobile Menu */
  .nav-dropdown-menu {
    position: static;
    box-shadow: none;
    border: none;
    border-radius: 0;
    background: var(--color-bg-cream);
    padding: var(--space-2) var(--space-4) var(--space-3);
    display: block;
  }

  .nav-dropdown-menu li {
    border-bottom: 1px dashed var(--color-border);
  }

  .nav-dropdown-menu li:last-child {
    border-bottom: none;
  }

  .nav-dropdown-menu a {
    padding: 0.55rem 0.65rem;
    font-size: var(--text-xs);
  }

  /* Breadcrumbs scrollable horizontally */
  .breadcrumb-bar {
    padding: 0.5rem 0;
  }

  .breadcrumb-list {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    white-space: nowrap;
    font-size: var(--text-xs);
  }

  .breadcrumb-list::-webkit-scrollbar {
    display: none;
  }

  /* 2-Column form rows stack on tablet/mobile */
  .form-grid-2 {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-2);
  }

  /* Cart Items Mobile Row Refinement (Eliminates grid squeezing) */
  .cart-item-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3);
  }

  .cart-item-row > a:first-child {
    flex: 0 0 74px;
    width: 74px;
  }

  .cart-item-row > a:first-child img {
    width: 100%;
    height: auto;
    aspect-ratio: 4 / 5;
    object-fit: cover;
  }

  .cart-item-row > div:nth-child(2) {
    flex: 1 1 calc(100% - 94px);
    min-width: 0;
  }

  .cart-item-row > div:nth-child(2) h3 {
    font-size: var(--text-sm);
    line-height: 1.3;
  }

  .cart-item-row .qty-control {
    margin-left: 0;
  }

  .cart-item-row > div:last-child {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-width: auto !important;
  }

  /* Sowing Calendar Month Pills: Horizontal scrolling strip */
  .calendar-month-pills {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 8px;
    gap: 6px;
    scrollbar-width: thin;
  }

  .month-pill-btn {
    flex-shrink: 0;
    padding: 0.45rem 0.85rem;
    font-size: var(--text-xs);
  }

  /* Sticky First Column for Sowing Calendar Matrix */
  .calendar-table-wrap {
    border-radius: var(--radius-md);
  }

  .calendar-matrix-table th:first-child,
  .calendar-matrix-table td:first-child {
    position: sticky;
    left: 0;
    background: var(--color-bg-white);
    z-index: 2;
    box-shadow: 3px 0 8px rgba(13, 59, 46, 0.08);
    border-right: 2px solid var(--color-border);
    min-width: 165px;
  }

  .calendar-matrix-table th:first-child {
    background: var(--color-bg-stone);
    z-index: 3;
  }

  /* Product Grid list view fallback */
  .product-grid.list-view .product-card {
    flex-direction: column;
  }

  .product-grid.list-view .product-card-media {
    width: 100%;
    aspect-ratio: 4 / 4.5;
  }

  /* Gallery PDP main frame */
  .gallery-main-frame img {
    max-height: 360px;
  }

  .gallery-caption-bar {
    flex-wrap: wrap;
    font-size: 0.72rem;
  }
}

/* --------------------------------------------------------------------------
   3. Modern Smartphones (< 580px)
   -------------------------------------------------------------------------- */
@media (max-width: 580px) {
  :root {
    --container-pad: 0.85rem;
    --space-8: 1.5rem;
    --space-10: 1.75rem;
    --space-12: 2rem;
  }

  /* Section vertical breathing room */
  .section {
    padding: var(--space-10) 0;
  }

  .section-sm {
    padding: var(--space-6) 0;
  }

  /* Hero Section */
  .hero-section {
    padding: var(--space-8) 0;
  }

  .hero-title {
    font-size: clamp(1.75rem, 7vw, 2.25rem);
    line-height: 1.2;
    margin-bottom: var(--space-3);
  }

  .hero-subtitle {
    font-size: var(--text-sm);
    line-height: 1.5;
    margin-bottom: var(--space-4);
  }

  .hero-cta-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-2);
    margin-bottom: var(--space-4);
  }

  .hero-cta-group > a:first-child {
    grid-column: 1 / -1;
    font-size: var(--text-base);
    padding: 0.85rem 1.25rem;
    text-align: center;
  }

  .hero-cta-group > a:not(:first-child) {
    font-size: var(--text-xs);
    padding: 0.65rem 0.5rem;
    text-align: center;
  }

  .hero-trust-bullets {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    font-size: var(--text-xs);
  }

  .hero-visual-card {
    border-radius: var(--radius-lg);
    padding: var(--space-3);
  }

  .hero-card-media {
    aspect-ratio: 16 / 10;
  }

  .hero-card-footer {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-2);
  }

  .hero-card-btn {
    width: 100%;
    justify-content: center;
    padding: 0.65rem 1rem;
    font-size: var(--text-xs);
  }

  /* Category Tiles Grid */
  .category-grid {
    grid-template-columns: 1fr;
    gap: var(--space-3);
  }

  .category-tile {
    padding: var(--space-4);
  }

  /* Product Catalog Grid */
  .product-grid {
    grid-template-columns: 1fr;
    gap: var(--space-4);
  }

  .product-card-body {
    padding: var(--space-3) var(--space-4);
  }

  .product-card-actions {
    grid-template-columns: 1fr;
    gap: var(--space-2);
  }

  .product-card-actions .btn {
    width: 100%;
    min-height: 44px;
  }

  /* Shop Toolbar */
  .shop-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-3);
    padding: var(--space-3);
  }

  .shop-toolbar > div:first-child {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
  }

  .shop-toolbar > div:last-child {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
  }

  .shop-toolbar select {
    flex: 1;
  }

  /* Product Detail Page (PDP) Buy Box */
  .pdp-grid {
    gap: var(--space-4);
  }

  .variant-selector-grid {
    grid-template-columns: 1fr;
    gap: var(--space-2);
  }

  .variant-option-btn {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-3);
  }

  .spec-table th,
  .spec-table td {
    padding: 0.55rem 0.65rem;
    font-size: var(--text-xs);
  }

  .spec-table th {
    width: 42%;
    word-break: break-word;
  }

  /* Seed Finder Form */
  #seed-finder-form {
    padding: var(--space-4);
  }

  #seed-finder-form > div:last-child {
    flex-direction: column;
    gap: var(--space-2);
  }

  #seed-finder-form > div:last-child .btn {
    width: 100%;
  }

  /* Modals on Mobile */
  .modal-dialog {
    max-width: 95vw;
    width: 95vw;
    padding: var(--space-4);
    max-height: 88vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-md);
  }

  /* Toasts on Mobile */
  .toast-region {
    left: var(--space-3);
    right: var(--space-3);
    bottom: var(--space-3);
    max-width: none;
  }

  .toast-card {
    padding: 0.65rem 0.85rem;
    font-size: var(--text-xs);
  }

  /* Footer */
  .site-footer {
    padding: var(--space-8) 0 var(--space-5);
    margin-top: var(--space-8);
  }

  .footer-grid {
    grid-template-columns: 1fr;
    gap: var(--space-5);
    padding-bottom: var(--space-6);
  }

  .footer-bottom {
    flex-direction: column;
    text-align: center;
    gap: var(--space-2);
  }
}

/* --------------------------------------------------------------------------
   4. Compact Smartphones & Extra-Narrow Screens (< 380px)
   -------------------------------------------------------------------------- */
@media (max-width: 380px) {
  :root {
    --container-pad: 0.75rem;
  }

  .brand-logo-img {
    height: 38px;
  }

  .header-action-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
  }

  .mobile-menu-toggle {
    height: 36px;
    padding: 0 10px;
    font-size: 0.72rem;
  }

  .hero-title {
    font-size: 1.65rem;
  }

  .btn {
    padding: 0.65rem 1rem;
    font-size: var(--text-xs);
  }

  .btn-sm {
    padding: 0.45rem 0.75rem;
  }

  .cart-item-row > a:first-child {
    flex: 0 0 60px;
    width: 60px;
  }

  .cart-item-row > div:nth-child(2) {
    flex: 1 1 calc(100% - 75px);
  }

  .qty-btn {
    width: 30px;
    height: 32px;
  }

  .qty-input {
    width: 38px;
    height: 32px;
  }
}

/* --------------------------------------------------------------------------
   5. Landscape Viewport on Phones
   -------------------------------------------------------------------------- */
@media (max-height: 500px) and (orientation: landscape) {
  .header-nav-bar {
    max-height: calc(100vh - 65px);
  }

  .modal-dialog {
    max-height: 90vh;
  }

  .hero-section {
    padding: var(--space-6) 0;
  }
}
