/* =====================================================================
   responsive.css — Mayorcity E-Mart
   Makes the WHOLE site fit phones, tablets and laptops.
   Loaded AFTER style.css (and admin.css on the admin page), so it only
   adds/overrides what is needed. Delete this file + its <link> to undo.

   Breakpoints:  ≤360 small phones · ≤600 phones · ≤768 large phones/
   small tablets · ≥1400 big laptops/desktops.
   ===================================================================== */

/* ---------- Everywhere: safety nets ---------- */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { overflow-x: hidden; min-width: 320px; }
img, video { max-width: 100%; height: auto; }
input, select, textarea { max-width: 100%; }
.product-card, .modal-box, .dash-listing-info, .vm-layout { overflow-wrap: anywhere; }

/* Grid never forces a card wider than the screen (was minmax(280px) which
   overflowed small phones once section padding was added). */
.products-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); }

/* Safe areas (iPhone notch / home bar) */
header { padding-top: max(16px, env(safe-area-inset-top)); }
@supports (padding: max(0px)) {
  header { padding-left: max(40px, env(safe-area-inset-left)); padding-right: max(40px, env(safe-area-inset-right)); }
}

/* Larger tap targets on touch screens */
@media (pointer: coarse) {
  .tab-btn, .category-item, .auth-open-btn, .nav-lf-btn, .nav-dashboard-btn,
  .view-all-link, .user-menu-btn, .notif-bell-btn, .theme-toggle-btn,
  .refresh-app-btn, .dash-tab, .clear-filters-btn { min-height: 40px; }
  .page-btn { width: 36px; height: 36px; font-size: 13px; }
  .modal-close { font-size: 32px; padding: 4px 8px; top: 10px; right: 12px; }
}

/* ---------- Big laptops / desktops ---------- */
@media (min-width: 1400px) {
  section, .header-container, .stats-grid { max-width: 1320px; }
}
@media (min-width: 1800px) {
  section, .header-container, .stats-grid { max-width: 1500px; }
  .products-grid { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
}

/* ---------- Tablets & large phones (≤768px) ---------- */
@media (max-width: 768px) {
  header { padding-left: 14px; padding-right: 14px; padding-bottom: 12px; }
  .header-container { gap: 10px; }

  /* Dropdowns become bottom sheets so they can never run off-screen. */
  .notif-dropdown, .user-dropdown {
    position: fixed;
    left: 8px; right: 8px;
    top: auto;
    bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    width: auto; max-width: none;
    transform: none;
    max-height: 70vh; max-height: 70dvh;
    overflow-y: auto;
    z-index: 2100;
    border-radius: 16px;
    animation: rSheetUp .22s ease-out;
  }
  .notif-dropdown.open, .user-dropdown.open { animation: rSheetUp .22s ease-out; }

  .price-sort-wrapper { gap: 14px; padding: 14px; }
  .price-range-filter, .sort-filter { flex: 1 1 100%; }
  .sort-filter select { width: 100%; }
  .clear-filters-btn { width: 100%; }
}
@keyframes rSheetUp { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Phones (≤600px) ---------- */
@media (max-width: 600px) {
  /* A sticky 3-row header eats a third of a phone screen — let it scroll away. */
  header { position: relative; padding-top: max(10px, env(safe-area-inset-top)); }
  .logo { font-size: 23px; }
  nav#main-nav { gap: 8px 12px; }
  nav#main-nav .nav-link { font-size: 14px; }

  /* Stats: three compact columns instead of three tall stacked boxes */
  .stats-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .stat-box { padding: 10px 4px; }
  .stat-box h3 { font-size: 20px; }
  .stat-box p { font-size: 10px; letter-spacing: 0; }

  /* Hero */
  .hero-section { padding: 36px 16px; }
  .hero-section h2 { font-size: clamp(26px, 8vw, 32px); letter-spacing: -0.5px; }
  .hero-section p { font-size: 14.5px; margin-bottom: 20px; }
  .hero-cta-buttons { gap: 10px; }
  .hero-cta-buttons button { width: 100%; padding: 13px 16px; }

  /* Sections */
  section { margin: 10px; padding: 16px; border-radius: 10px; }
  .listings-container-section h2, section h2 { font-size: 20px; }

  /* Search / filters */
  .search-wrapper input { padding: 13px 14px; font-size: 16px; }   /* 16px stops iOS auto-zoom */
  .tab-filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .tab-filters .tab-btn { width: 100%; padding: 10px 6px; font-size: 13px; }
  #category-list { gap: 8px; }
  .category-item { padding: 8px 12px; font-size: 13px; }

  /* Cards */
  .products-grid { gap: 14px; margin-top: 14px; }
  .product-card { padding: 14px; }
  .horizontal-scroll .product-card { flex: 0 0 min(220px, 72vw); }

  /* Forms (post item, sign up, lost & found, edit…) — 16px inputs, full width */
  form input, form select, form textarea,
  .modal-box input, .modal-box select, .modal-box textarea { font-size: 16px; }
  form input[type="file"] { font-size: 14px; width: 100%; padding: 10px; }
  form button[type="submit"], .auth-submit-btn { width: 100%; padding: 14px; }
  #upload-form-section { padding: 16px; }

  /* Pop-ups: near full-screen with scrolling inside */
  .modal-overlay { padding: 8px; align-items: flex-end; }
  .modal-box, .large-modal-box {
    max-width: 100%;
    padding: 22px 16px calc(18px + env(safe-area-inset-bottom, 0px));
    max-height: calc(100vh - 16px); max-height: calc(100dvh - 16px);
    border-radius: 18px;
  }
  .dialog-box { max-width: 100%; padding: 22px 16px; }
  .vm-layout { gap: 12px; }
  .vm-image { max-height: 300px; }
  .vm-owner-actions { flex-wrap: wrap; }

  /* Notifications toasts: full width, below the notch */
  #toast-container {
    top: calc(10px + env(safe-area-inset-top, 0px));
    left: 10px; right: 10px;
    max-width: none;
  }

  /* Install banner wraps instead of overflowing */
  #install-app-banner { flex-wrap: wrap; gap: 8px; padding: 10px 12px; }
  #install-app-banner-text { font-size: 13px; flex: 1 1 100%; }

  /* Dashboard */
  .dash-tabs-row { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .dash-tab { white-space: nowrap; flex: 0 0 auto; padding: 10px 14px; }
  .dash-listings-list { max-height: 55vh; max-height: 55dvh; }

  /* Pagination, footer */
  .pagination-controls { gap: 6px; }
  footer { padding-left: 16px; padding-right: 16px; }

  /* Floating buttons: keep them clear of each other and the home bar */
  #backToTopBtn { right: 14px; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); width: 42px; height: 42px; }
  #assistant-launcher {
    right: 14px;
    bottom: calc(72px + env(safe-area-inset-bottom, 0px));
    padding: 11px 15px 11px 13px;
  }
  #assistant-panel {
    left: 8px; right: 8px; width: auto; max-width: none;
    bottom: calc(132px + env(safe-area-inset-bottom, 0px));
    height: min(70dvh, 520px); height: min(70vh, 520px);
    max-height: calc(100vh - 160px); max-height: calc(100dvh - 160px);
  }
  #assistant-input { font-size: 16px; }
}

/* ---------- Small phones (≤360px) ---------- */
@media (max-width: 360px) {
  .logo { font-size: 21px; }
  section { margin: 8px; padding: 14px; }
  .stat-box h3 { font-size: 18px; }
  .stat-box p { font-size: 9px; }
  .tab-filters .tab-btn { font-size: 12px; }
  .dash-stats-grid { gap: 6px; }
  .dash-stat-value { font-size: 18px; }
  #assistant-launcher-label { display: none; }               /* icon-only to save space */
  #assistant-launcher { padding: 12px; }
  .hero-section h2 { font-size: 25px; }
}

/* ---------- Phones turned sideways (short screens) ---------- */
@media (max-height: 480px) and (orientation: landscape) {
  header { position: relative; }
  .hero-section { padding: 24px 16px; }
  .modal-box, .large-modal-box { max-height: calc(100vh - 16px); max-height: calc(100dvh - 16px); }
  .modal-overlay { align-items: center; }
  #assistant-panel { height: calc(100vh - 100px); bottom: 70px; }
}

/* ---------- Admin dashboard (admin.html) ---------- */
@media (max-width: 600px) {
  .admin-main { padding: 12px; }
  .admin-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .admin-table { min-width: 560px; }
  .admin-page-header { flex-wrap: wrap; gap: 8px; }
  .admin-section-card { padding: 12px; }
}
