/* ═══════════════════════════════════════════════════════════════════
   FlorForMe — MOBILE V2 (2026)
   Overrides & new patterns — load after mobile.css + style.css
   ═══════════════════════════════════════════════════════════════════ */

:root {
  --mobile-nav-h: 56px;
  --app-height: 100vh;
  --tap-min: 44px;
}

@supports (height: 100dvh) {
  :root { --app-height: 100dvh; }
}

/* Scroll lock (drawer / sheets) */
.body-scroll-lock {
  position: fixed;
  left: 0;
  right: 0;
  width: 100%;
  overflow: hidden;
}

/* ─── Scoped touch targets (replaces global min 44px on all links) ─── */
@media (max-width: 767px) {
  button:not(.tap-target):not(.admin-btn-sm):not(.mobile-nav-item):not(.mobile-utility-item),
  a:not(.tap-target):not(.mobile-nav-item):not(.mobile-utility-item):not(.mobile-drawer-link):not(.logo):not(.footer-links a) {
    min-height: unset;
    min-width: unset;
  }

  .tap-target,
  .burger,
  .btn-icon,
  .btn-primary,
  .btn-secondary,
  .btn-checkout,
  .btn-add-cart,
  .btn-add-big,
  .cat-card-add,
  .cat-card-buynow,
  .cat-filter-btn,
  .cat-view-btn,
  .sp-attach-btn,
  .sp-send-btn,
  .admin-topbar .admin-btn,
  #sidebarToggle,
  #shopSidebarToggle,
  .modal-close,
  .cart-close {
    min-height: var(--tap-min);
    min-width: var(--tap-min);
  }

  .footer-links a {
    min-height: 0;
    min-width: 0;
    padding: 4px 0;
    display: inline-block;
  }
}

/* ─── Unified bottom padding when mobile nav present ─── */
@media (max-width: 767px) {
  body:has(.mobile-nav) {
    padding-bottom: calc(var(--mobile-nav-h, 56px) + env(safe-area-inset-bottom, 0px)) !important;
  }
  body.page-account:has(.mobile-utility-nav),
  body.page-support:has(.mobile-utility-nav),
  body:has(.mobile-utility-nav):not(:has(.mobile-nav)) {
    padding-bottom: calc(52px + env(safe-area-inset-bottom, 0px)) !important;
  }
  body:has(.admin-layout),
  body:has(.adminApp) {
    padding-bottom: 0 !important;
  }
}

/* ─── Mobile drawer ─── */
.mobile-drawer-overlay {
  position: fixed;
  inset: 0;
  z-index: 1200;
  background: rgba(26, 18, 8, 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s;
}
.mobile-drawer-overlay.is-open {
  opacity: 1;
  visibility: visible;
}

.mobile-drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(320px, 88vw);
  z-index: 1201;
  background: #fff;
  box-shadow: 8px 0 40px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  transform: translateX(-105%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.mobile-drawer.is-open {
  transform: translateX(0);
}

.mobile-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid rgba(200, 169, 110, 0.2);
  flex-shrink: 0;
}
.mobile-drawer-title {
  font-size: 1.1rem;
  font-weight: 800;
  color: #1a1208;
}
.mobile-drawer-close {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: #f5f0e8;
  font-size: 1.1rem;
  cursor: pointer;
}

.mobile-drawer-links,
.mobile-drawer-extra {
  display: flex;
  flex-direction: column;
  padding: 12px;
  gap: 4px;
  overflow-y: auto;
}
.mobile-drawer-extra {
  margin-top: auto;
  border-top: 1px solid #f0ebe3;
  padding-top: 16px;
}

.mobile-drawer-link {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  border-radius: 14px;
  font-size: 1rem;
  font-weight: 600;
  color: #1a1208;
  text-decoration: none;
  transition: background 0.15s;
}
.mobile-drawer-link:hover,
.mobile-drawer-link:active {
  background: rgba(200, 169, 110, 0.12);
}

.burger.is-open span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
.burger.is-open span:nth-child(2) {
  opacity: 0;
}
.burger.is-open span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* ─── Bottom nav polish ─── */
@media (max-width: 767px) {
  .mobile-nav {
    display: block !important;
    z-index: 900;
    padding-bottom: max(6px, env(safe-area-inset-bottom, 0px));
  }
  .mobile-nav-inner {
    height: auto;
    min-height: 48px;
    max-width: 100%;
    padding: 4px 8px 2px;
  }
  .mobile-nav-item {
    min-height: 48px !important;
    min-width: 48px !important;
    padding: 4px 8px !important;
    -webkit-tap-highlight-color: transparent;
  }
  .mobile-nav-label {
    font-size: 0.58rem !important;
  }
}

/* ─── Utility bottom nav (account / support) ─── */
.mobile-utility-nav {
  display: none;
}
@media (max-width: 767px) {
  .mobile-utility-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 900;
    background: rgba(255, 255, 255, 0.97);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    padding: 4px 6px calc(4px + env(safe-area-inset-bottom, 0px));
    justify-content: space-around;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.06);
  }
  .mobile-utility-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 6px 4px;
    text-decoration: none;
    color: #9ca3af;
    font-size: 0.58rem;
    font-weight: 600;
    min-height: 48px;
    border-radius: 10px;
  }
  .mobile-utility-item img {
    width: 22px;
    height: 22px;
    opacity: 0.7;
  }
  .mobile-utility-item.active {
    color: #374151;
  }
  .mobile-utility-item.active img {
    opacity: 1;
  }
}

/* ─── Catalog: compact icon buttons (catalog-new.css wins sizing) ─── */
@media (max-width: 767px) {
  .cat-card-footer button.cat-card-buynow,
  .cat-card-footer button.cat-card-add {
    min-width: 0 !important;
    min-height: 0 !important;
  }
  .cat-view-btn {
    width: 40px !important;
    height: 40px !important;
  }
}

/* ─── Support chat inputs ─── */
@media (max-width: 767px) {
  .sp-attach-btn,
  .sp-send-btn {
    width: 44px !important;
    height: 44px !important;
    flex-shrink: 0;
  }
  .sp-textarea,
  .sp-input-area input {
    font-size: 16px !important;
  }
  .sp-input-area {
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)) !important;
  }
  #chatWrap {
    min-height: 0;
    max-height: calc(var(--app-height, 100vh) - 52px);
  }
}

/* ─── Admin mobile: overlay + scroll ─── */
@media (max-width: 1023px) {
  .admin-sidebar-overlay.active,
  .admin-sidebar-overlay.show,
  #adminSidebarOverlay.active {
    display: block !important;
  }
}

@media (max-width: 767px) {
  body:has(.admin-layout) .admin-main,
  body:has(.admin-layout) .admin-content {
    min-height: 0;
    max-height: var(--app-height, 100vh);
  }
  body.admin-mobile-scroll .admin-content {
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
  .admin-table {
    min-width: 0 !important;
  }
  .order-mobile-card {
    display: block !important;
  }
}

/* ─── Cart & modals: full width sheets ─── */
@media (max-width: 767px) {
  .cart-sidebar {
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 20px 20px 0 0;
    max-height: min(92vh, var(--app-height, 100vh));
  }
  .cart-overlay.open {
    backdrop-filter: blur(4px);
  }
  .modal-overlay.open {
    align-items: flex-end !important;
    padding: 0 !important;
  }
  .modal-overlay.open .modal {
    border-radius: 20px 20px 0 0 !important;
    max-height: min(92vh, var(--app-height, 100vh));
    width: 100%;
  }
}

/* ─── Product page CTA ─── */
@media (max-width: 767px) {
  .btn-add-big,
  .product-cta .btn-primary {
    width: 100%;
    min-height: 48px;
    font-size: 1rem;
  }
  .qty-btn {
    width: 44px;
    height: 44px;
  }
}

/* ─── Shop profile ─── */
@media (max-width: 767px) {
  .sh-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .sh-tabs::-webkit-scrollbar { display: none; }
}

/* ─── Breakpoint sync 768 → 767 for style.css leftovers ─── */
@media (max-width: 767px) {
  .nav { display: none !important; }
  .burger { display: flex !important; }
}

/* ─── Burger animation base ─── */
.burger span {
  display: block;
  transition: transform 0.25s ease, opacity 0.2s;
}

/* ─── Catalog page ─── */
@media (max-width: 767px) {
  .page-catalog .cat-layout {
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px)) !important;
  }
  .page-catalog .cat-layout > main {
    width: 100%;
    min-width: 0;
  }
  .page-catalog .cat-toolbar {
    gap: 8px;
  }
  .page-catalog .cat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 10px !important;
  }
  .page-catalog .cat-sidebar-close-btn {
    min-width: 44px;
    min-height: 44px;
  }
}

/* ─── Product page ─── */
@media (max-width: 767px) {
  .page-product .pd-wrap {
    padding: calc(52px + env(safe-area-inset-top, 0px)) 12px calc(88px + env(safe-area-inset-bottom, 0px)) !important;
  }
  .page-product .pd-grid,
  .page-product .pd-gallery,
  .page-product .pd-info,
  .page-product .pd-main-img {
    min-width: 0;
    max-width: 100%;
  }
  .page-product section[style*="grid-template-columns"] > div[style*="grid-template-columns"] {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 12px !important;
  }
  .page-product .pd-actions {
    position: sticky;
    bottom: calc(var(--mobile-nav-h, 56px) + env(safe-area-inset-bottom, 0px));
    z-index: 40;
    background: linear-gradient(180deg, transparent, #fff 24%);
    padding-top: 12px;
    margin: 0 -4px;
  }
}

/* ─── Account ─── */
@media (max-width: 767px) {
  body.page-account .acc-root {
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px)) !important;
  }
  body.page-account .acc-input,
  body.page-account .acc-btn {
    font-size: 16px !important;
  }
}

/* ─── Support chat ─── */
@media (max-width: 767px) {
  body.page-support {
    height: var(--app-height, 100dvh);
    max-height: var(--app-height, 100dvh);
  }
  body.page-support .sp-header {
    padding-top: env(safe-area-inset-top, 0px);
    height: calc(52px + env(safe-area-inset-top, 0px));
  }
  body.page-support .sp-input-area {
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)) !important;
  }
}

/* ─── Track / legal ─── */
@media (max-width: 767px) {
  .track-page {
    padding: 16px 16px calc(72px + env(safe-area-inset-bottom, 0px));
  }
  .track-page .track-card,
  .track-page .track-form {
    border-radius: 16px;
  }
  .legal-page,
  body:has(.legal-content) {
    padding: 16px 16px calc(72px + env(safe-area-inset-bottom, 0px));
  }
}

/* ─── Home hero & sections ─── */
@media (max-width: 767px) {
  .page-home .header {
    padding-top: env(safe-area-inset-top, 0px);
  }
  .page-home .hero-content {
    padding-top: 8px;
  }
  .page-home .products-grid,
  .page-home #productsGrid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 10px !important;
  }
  .page-home .shops-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ─── Search modal full screen on phone ─── */
@media (max-width: 767px) {
  #searchModal.modal-overlay.open,
  .modal-overlay#searchModal.open {
    align-items: stretch !important;
  }
  #searchModal .modal {
    border-radius: 0 !important;
    max-height: 100% !important;
    height: 100%;
  }
}

/* ─── Toast above bottom nav ─── */
@media (max-width: 767px) {
  .toast-container,
  #toastContainer {
    bottom: calc(var(--mobile-nav-h, 56px) + 12px + env(safe-area-inset-bottom, 0px)) !important;
    left: 12px !important;
    right: 12px !important;
  }
}

/* ─── Form inputs iOS ─── */
@media (max-width: 767px) {
  .form-input,
  .form-input-admin,
  input[type="text"],
  input[type="email"],
  input[type="tel"],
  input[type="password"],
  input[type="search"],
  input[type="number"],
  select,
  textarea {
    font-size: 16px !important;
  }
}
