/* ==========================================================================
   DEVFORGE FULL RESPONSIVE DESIGN SYSTEM
   Optimized for: Mobile (320px-480px), Phablets (481px-768px), 
                  Tablets (769px-1024px), Laptops & 4K Desktops (> 1024px)
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. BASE MOBILE DRAWER & NAVIGATION
   -------------------------------------------------------------------------- */
.mobile-nav-toggle {
  display: none;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.45rem 0.65rem;
  color: var(--text-primary);
  cursor: pointer;
  font-size: 1.25rem;
  line-height: 1;
  transition: background-color var(--transition-fast);
}

.mobile-nav-toggle:hover {
  background-color: var(--bg-subtle);
}

.mobile-menu-drawer {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 10000;
  display: none;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.mobile-menu-drawer.open {
  display: flex;
  opacity: 1;
}

.mobile-menu-content {
  width: 86%;
  max-width: 340px;
  background-color: var(--bg-surface);
  height: 100%;
  padding: 1.5rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
  transform: translateX(-100%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

.mobile-menu-drawer.open .mobile-menu-content {
  transform: translateX(0);
}

/* --------------------------------------------------------------------------
   2. TABLET & LAPTOP BREAKPOINT (max-width: 1024px)
   -------------------------------------------------------------------------- */
@media (max-width: 1024px) {
  .header-left {
    gap: 0.75rem;
  }

  .nav-links-desktop {
    gap: 0.15rem;
  }

  .nav-link {
    padding: 0.35rem 0.55rem;
    font-size: 0.84rem;
  }

  .header-search {
    max-width: 220px;
    min-width: 140px;
  }

  .grid-cols-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

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

  .footer-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 2rem;
  }

  .admin-sidebar {
    width: 200px;
  }
}

/* --------------------------------------------------------------------------
   3. TABLET & CHECKOUT STACKING (max-width: 992px)
   -------------------------------------------------------------------------- */
@media (max-width: 992px) {
  /* Stack multi-column checkout and cart layouts */
  #cart-content-wrapper,
  .checkout-grid,
  .grid-cols-3 {
    grid-template-columns: 1fr !important;
  }

  #cart-content-wrapper > div,
  .checkout-grid > div,
  .grid-cols-3 > div {
    grid-column: span 1 !important;
  }

  .product-details-grid,
  #product-content-area {
    grid-template-columns: 1fr !important;
  }
}

@media (max-width: 1250px) {
  .desktop-only-user-btns {
    display: none !important;
  }
}

@media (max-width: 992px) {
  .nav-links-desktop {
    gap: 0.2rem;
  }

  .nav-link {
    font-size: 0.82rem;
    padding: 0.35rem 0.5rem;
  }

  .header-search {
    max-width: 180px;
    min-width: 110px;
  }
}

/* --------------------------------------------------------------------------
   4. MOBILE BREAKPOINT (max-width: 768px)
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  /* Prevent iOS Safari 16px auto-zoom on form inputs */
  input, select, textarea, .form-input, .form-select, .form-textarea {
    font-size: 16px !important;
  }

  /* Header adjustments on mobile */
  .site-header {
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
  }

  .header-container {
    height: 58px !important;
    padding: 0 0.6rem !important;
    gap: 0.4rem !important;
    max-width: 100vw !important;
    box-sizing: border-box !important;
  }

  .brand-logo {
    font-size: 1.05rem !important;
    gap: 0.4rem !important;
    white-space: nowrap;
    flex-shrink: 0;
  }

  .brand-icon {
    width: 28px !important;
    height: 28px !important;
    font-size: 0.9rem !important;
    flex-shrink: 0;
  }

  .header-actions {
    gap: 0.35rem !important;
    flex-shrink: 0;
    align-items: center;
  }

  .cart-btn {
    padding: 0.35rem 0.55rem !important;
  }

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

  .announcement-bar {
    font-size: 0.78rem !important;
    padding: 0.4rem 0.6rem !important;
    line-height: 1.35;
    word-break: break-word;
  }

  .site-header .nav-links-desktop {
    display: none !important;
  }

  .header-search {
    display: none !important; /* Kept in mobile drawer and page headers */
  }

  .mobile-nav-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.35rem 0.5rem !important;
    font-size: 1.1rem !important;
  }

  /* Show compact admin/user quick link in mobile header for ALL logged-in users */
  #header-user-nav {
    display: flex !important;
    align-items: center;
  }

  #header-user-nav .desktop-only-user-btns,
  #header-user-nav .user-dropdown-wrapper {
    display: none !important;
  }

  #header-user-nav .header-admin-direct-btn,
  #header-user-nav .header-user-direct-btn {
    display: inline-flex !important;
    align-items: center;
    padding: 0.32rem 0.55rem !important;
    font-size: 0.75rem !important;
    font-weight: 600 !important;
    border-radius: var(--radius-md) !important;
    white-space: nowrap !important;
    line-height: 1.2 !important;
  }

  @media (max-width: 420px) {
    .brand-logo span {
      font-size: 0.95rem !important;
    }
    .header-user-btn-text {
      display: none !important;
    }
    .header-container {
      padding: 0 0.4rem !important;
      gap: 0.25rem !important;
    }
    .header-actions {
      gap: 0.25rem !important;
    }
  }

  /* Typography scaling */
  h1 { font-size: 1.75rem !important; }
  h2 { font-size: 1.45rem !important; }
  h3 { font-size: 1.2rem !important; }

  .hero-section {
    padding: 3rem 0 2rem !important;
    text-align: center;
  }

  .hero-actions {
    flex-direction: column;
    width: 100%;
  }

  .hero-actions .btn {
    width: 100%;
  }

  /* Grids collapse to 1 column */
  .grid-cols-4,
  .grid-cols-3,
  .grid-cols-2 {
    grid-template-columns: 1fr !important;
    gap: 1.25rem !important;
  }

  /* Footer */
  .footer-grid {
    grid-template-columns: 1fr !important;
    gap: 2rem;
  }

  .footer-bottom {
    flex-direction: column;
    gap: 1rem;
    text-align: center;
  }

  /* Buttons on mobile */
  .btn-lg {
    padding: 0.75rem 1.25rem;
    font-size: 0.95rem;
  }

  .container {
    padding-left: 1rem !important;
    padding-right: 1rem !important;
  }

  /* Horizontal Scrolling for Nav Tabs & Breadcrumbs */
  .tab-nav,
  .flex.gap-2[style*="border-bottom"] {
    overflow-x: auto;
    flex-wrap: nowrap !important;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.5rem;
  }

  .tab-nav a,
  .flex.gap-2[style*="border-bottom"] a {
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* Tables horizontal scrolling wrapper */
  .table-responsive,
  table {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* --------------------------------------------------------------------------
   5. EXTRA SMALL MOBILE (max-width: 480px)
   -------------------------------------------------------------------------- */
@media (max-width: 480px) {
  .brand-logo span {
    font-size: 1.15rem;
  }

  .container {
    padding-left: 0.85rem !important;
    padding-right: 0.85rem !important;
  }

  .card {
    padding: 1.15rem 1rem !important;
  }

  /* Product Cards on compact screens */
  .product-thumb {
    height: 180px;
  }

  .product-footer {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .product-pricing {
    flex-direction: row;
    justify-content: space-between;
    align-items: baseline;
    flex-wrap: wrap;
  }

  .product-actions {
    display: flex !important;
    width: 100% !important;
    gap: 0.35rem !important;
    align-items: stretch !important;
    flex-wrap: nowrap !important;
  }

  .product-actions .btn {
    flex: 1 1 auto !important;
    text-align: center !important;
    justify-content: center !important;
    padding: 0.45rem 0.3rem !important;
    font-size: 0.78rem !important;
    min-width: 0 !important;
  }

  /* Floating toast sizing */
  .toast {
    min-width: calc(100vw - 2rem);
    max-width: calc(100vw - 2rem);
  }
}

/* --------------------------------------------------------------------------
   6. WIDE SCREENS & 4K (min-width: 1440px)
   -------------------------------------------------------------------------- */
@media (min-width: 1440px) {
  .container {
    max-width: 1280px;
  }
}

/* --------------------------------------------------------------------------
   7. ACCESSIBILITY & REDUCED MOTION
   -------------------------------------------------------------------------- */
button, input, select, textarea, a {
  touch-action: manipulation;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* --------------------------------------------------------------------------
   8. PRODUCT DETAIL PAGE MOBILE RESPONSIVENESS
   -------------------------------------------------------------------------- */
@media (max-width: 992px) {
  .product-detail-layout {
    grid-template-columns: 1fr !important;
    gap: 1.75rem !important;
  }
}

@media (max-width: 768px) {
  .product-detail-layout {
    margin-bottom: 2rem !important;
  }

  .product-detail-title {
    font-size: 1.45rem !important;
    line-height: 1.3 !important;
    margin-bottom: 0.6rem !important;
  }

  .product-thumb-card {
    padding: 0.4rem !important;
    margin-bottom: 1.25rem !important;
  }

  .product-thumb-card img {
    max-height: 270px !important;
    object-fit: contain !important;
  }

  .product-price-box {
    padding: 1.15rem 1rem !important;
    margin-bottom: 1.5rem !important;
  }

  .product-active-price {
    font-size: 1.85rem !important;
  }

  .product-description-container {
    font-size: 0.92rem !important;
    line-height: 1.7 !important;
  }

  .product-description-container h4 {
    font-size: 1.05rem !important;
    margin-top: 1.25rem !important;
  }

  .product-description-container ul,
  .product-description-container ol {
    margin-left: 1rem !important;
  }

  #reviews-section {
    margin-top: 2.5rem !important;
    padding-top: 1.75rem !important;
  }

  #reviews-section .flex.justify-between {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem !important;
  }

  #reviews-section .btn {
    width: 100%;
    justify-content: center;
  }

  #review-form-card .grid-cols-2 {
    grid-template-columns: 1fr !important;
    gap: 0.75rem !important;
  }
}

@media (max-width: 540px) {
  .product-action-buttons {
    flex-direction: column !important;
    gap: 0.65rem !important;
  }

  .product-action-buttons .btn {
    width: 100% !important;
    justify-content: center !important;
    padding: 0.8rem 1rem !important;
    font-size: 1rem !important;
  }

  .product-breadcrumb {
    font-size: 0.8rem !important;
    margin-bottom: 1rem !important;
  }

  #related-products-grid {
    grid-template-columns: 1fr !important;
  }
}
