/*
 * Mobile-only layout fixes. Every rule here lives inside a max-width media query so the
 * desktop layout is untouched. Many components use inline styles, hence the !important.
 */

@media (max-width: 768px) {
  /* ── /products: categories sidebar becomes a horizontal chip row above the grid ── */
  .products-layout { flex-direction: column !important; gap: 1rem !important; }
  .products-sidebar { width: 100% !important; position: static !important; }
  .products-cats {
    flex-direction: row !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    max-height: none !important;
    gap: 8px !important;
    padding-bottom: 6px;
    -webkit-overflow-scrolling: touch;
  }
  .products-cats > button {
    width: auto !important;
    flex-shrink: 0;
    white-space: nowrap;
    gap: 8px;
    border: 1px solid #e5e7eb !important;
    border-radius: 999px !important;
    padding: 0.5rem 0.9rem !important;
  }
  .products-layout > div { width: 100%; }
}

@media (max-width: 768px) {
  /* ── /cart: items and order summary stack instead of sitting side by side ── */
  .cart-body { flex-direction: column !important; overflow-y: auto !important; }
  .cart-items-col,
  .cart-summary-col {
    flex: none !important;
    width: 100% !important;
    overflow: visible !important;
    padding: 18px 16px !important;
    border-right: none !important;
    box-sizing: border-box;
  }
  .cart-items-col { border-bottom: 1px solid #eee; }
  .cart-item { min-height: 120px !important; }
  .cart-item-thumb { width: 104px !important; }
}

@media (max-width: 768px) {
  /* ── Apparel order pages (t-shirts, dress shirts): image above the order panel ── */
  .shirt-order-grid { grid-template-columns: 1fr !important; gap: 1.5rem !important; padding-top: 1rem !important; }
}

@media (max-width: 768px) {
  /* ── Admin: sidebar becomes an off-canvas drawer behind a top bar ── */
  div:has(> .admin-mobile-bar) { flex-direction: column !important; }
  div:has(> .admin-mobile-bar) > :not(.admin-mobile-bar):not(.admin-sidebar-panel):not(.admin-mobile-backdrop) { min-width: 0; min-height: 0; }
  .admin-mobile-bar {
    display: flex !important;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: #fff;
    border-bottom: 1px solid #f0f0f0;
    flex-shrink: 0;
  }
  .admin-mobile-toggle {
    display: flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; border-radius: 10px;
    border: 1px solid #e5e7eb; background: #fff; color: #111827; cursor: pointer;
  }
  .admin-sidebar-panel {
    position: fixed !important;
    top: 0; left: 0; bottom: 0;
    z-index: 1001;
    height: 100% !important;
    width: 264px !important;
    max-width: 85vw;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.18);
  }
  .admin-sidebar-panel.is-open { transform: none; }
  .admin-mobile-backdrop { position: fixed; inset: 0; background: rgba(15, 15, 25, 0.45); z-index: 1000; }
}

@media (max-width: 768px) {
  /* ── Packaging "coming soon": keep the 4 countdown boxes on one row ── */
  .coming-soon-countdown { gap: 0.5rem !important; flex-wrap: nowrap !important; }
  .coming-soon-countdown > div { min-width: 0 !important; flex: 1 1 0; max-width: 84px; padding: 0.75rem 0.25rem !important; }
  .coming-soon-countdown > div > div:first-child { font-size: 1.4rem !important; }
}

@media (max-width: 768px) {
  /* ── Product grids (/products and other listing grids): two compact columns ── */
  .lp-pop-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 12px !important; }
  .lp-pop-grid .lp-pop-img { height: 130px; }
  .lp-pop-grid .lp-pop-info { padding: 10px 10px 12px; }
  .lp-pop-grid .lp-pop-name { font-size: 0.82rem; }

  .coming-soon-countdown > div > div:last-child { font-size: 0.6rem !important; letter-spacing: 0.02em !important; }
}

@media (max-width: 768px) {
  /* ── Admin pages: wide tables scroll sideways instead of being clipped ── */
  div:has(> .admin-mobile-bar) :has(> table):not(.invoice-modal-content *) { overflow-x: auto !important; -webkit-overflow-scrolling: touch; }
  div:has(> .admin-mobile-bar) table:not(.invoice-modal-content table) { min-width: 620px; }

  /* ── Admin orders: list on top (scrollable), selected order's details below ── */
  .admin-orders-split { flex-direction: column !important; overflow-y: auto !important; }
  .admin-orders-list {
    width: 100% !important;
    max-height: 38vh;
    flex-shrink: 0;
    border-right: none !important;
    border-bottom: 1px solid #e5e7eb;
  }
  .admin-orders-split > :not(.admin-orders-list) { min-width: 0; flex: none !important; overflow: visible !important; padding: 16px !important; }
}

@media (max-width: 768px) {
  /* ── Admin: misc. rows that don't fit at phone width ── */
  div:has(> .admin-mobile-bar) select,
  .admin-legacy-main select { min-width: 0 !important; max-width: 100%; }
  .admin-review-stats { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 10px !important; }
  .admin-account-row { flex-wrap: wrap; }
  .admin-gallery-actions { flex-wrap: wrap; flex-shrink: 1 !important; }

  /* Gallery detail page has its own (server-rendered) sidebar; it has a "Back" link instead on mobile. */
  .admin-legacy-sidebar { display: none !important; }
  .admin-legacy-main { padding: 16px !important; min-width: 0; }
}

@media (max-width: 768px) {
  /* ── Design editor: canvas on top, then pages, tool icons and the tool panel ── */
  .de-topbar {
    height: auto !important;
    min-height: 56px;
    flex-wrap: wrap;
    padding: 8px 10px !important;
    gap: 6px !important;
  }
  .de-title { display: none !important; }
  .de-topbar > .de-back { padding: 0.4rem 0.7rem !important; font-size: 0.8rem !important; }
  .de-actions { margin-left: auto; gap: 6px !important; }
  .de-actions button { padding: 0.4rem 0.7rem !important; font-size: 0.8rem !important; }
  /* text / image formatting toolbar gets its own scrollable row */
  .de-ctx { order: 10; flex: 1 1 100% !important; padding-bottom: 2px; }

  /* tool icons on the left, canvas in the middle, Front/Back on the right.
     The tool panel opens as a popup over the canvas when an icon is tapped. */
  .de-body {
    position: relative;
    display: grid !important;
    grid-template-columns: 60px minmax(0, 1fr) 64px;
    grid-template-rows: minmax(0, 1fr);
  }
  .de-rail {
    grid-column: 1; grid-row: 1;
    width: auto !important;
    min-height: 0;
    overflow-y: auto;
    padding: 6px 4px !important;
    gap: 2px !important;
  }
  .de-rail > * { zoom: 0.78; min-width: 0; }
  .de-canvas { grid-column: 2; grid-row: 1; min-height: 0; min-width: 0; }
  .de-canvas-inner { padding: 12px !important; }
  .de-zoombar { padding: 4px 0 !important; }
  .de-zoombar > div { padding: 2px 4px !important; border-radius: 12px !important; zoom: 0.9; }
  .de-zoombar button { width: 30px !important; height: 30px !important; }
  .de-zoombar button:last-child { width: auto !important; }
  .de-pages {
    grid-column: 3; grid-row: 1;
    width: auto !important;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px 4px !important;
    gap: 8px !important;
    border-left: 1px solid #e5e7eb !important;
  }
  .de-pages > p { display: none; }
  .de-pages > div { zoom: 0.5; }
  .de-legend { gap: 6px !important; }
  .de-legend > span { font-size: 0.72rem !important; padding: 4px 10px !important; border-width: 1.5px !important; }

  .de-panel {
    display: none;
    position: absolute;
    z-index: 30;
    top: 8px; left: 64px;
    max-height: calc(100% - 16px);
    overflow-y: auto !important;
    width: min(320px, calc(100% - 76px)) !important;
    border: 1px solid #e5e7eb !important;
    border-radius: 16px;
    box-shadow: 0 16px 40px rgba(15, 15, 25, 0.22);
  }
  .de-panel.is-open { display: block; }
  .de-panel-head { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: #fff; z-index: 1; }
  .de-panel-close {
    display: flex !important; align-items: center; justify-content: center;
    width: 32px; height: 32px; border-radius: 50%;
    border: 1px solid #e5e7eb; background: #fff; color: #374151; cursor: pointer; font-size: 0.9rem;
  }
  .de-panel-backdrop { display: block !important; position: absolute; inset: 0 0 0 60px; z-index: 25; background: rgba(15, 15, 25, 0.25); }
}

@media (max-width: 768px) {
  /* ── Editor "Finalize Your Order": preview on top, options below, whole screen scrolls ── */
  .de-final-body { flex-direction: column !important; overflow-y: auto !important; }
  .de-final-left { flex: none !important; border-right: none !important; border-bottom: 1px solid #e5e7eb; padding: 16px !important; }
  .de-final-right { flex: none !important; overflow: visible !important; padding: 20px 16px 28px !important; }
  .cart-summary-col { border-left: none !important; }
}

@media (max-width: 768px) {
  /* ── Landing welcome popup: keep the Next/Finish footer visible, scroll the content ──
     (88vh on iOS Safari includes the toolbars, which pushed the footer off-screen) */
  .wp-shell { max-height: calc(100dvh - 32px) !important; overflow-y: auto !important; -webkit-overflow-scrolling: touch; }
  .wp-shell-footer { position: sticky; bottom: 0; z-index: 5; flex-shrink: 0; padding-top: 10px; background: inherit; }
  .wp-shell-footer > div { padding: 0 20px 16px !important; }
  .wp-choice-card { padding: 18px 12px !important; }
}

@media (max-width: 768px) {
  /* ── Admin gallery detail: design card previews keep their shape on iOS Safari ── */
  .adm-card-preview { aspect-ratio: auto !important; height: 0 !important; padding-top: var(--ar-pad, 58.7%) !important; }
  .adm-card-preview > div { position: absolute !important; inset: 0; }
  /* Admin top bar menu icon: fixed size (it rendered tiny on some iPhones) */
  .admin-mobile-toggle svg { width: 22px !important; height: 22px !important; flex-shrink: 0; }
}

@media (max-width: 768px) {
  /* ── Packaging quote form: delivery / contact fields stack ── */
  .pk-form-grid { grid-template-columns: 1fr !important; }
}

@media (max-width: 768px) {
  /* ── Admin packaging catalog / quotes: list above details, form fields stack ── */
  .admin-pkq-split { grid-template-columns: 1fr !important; }
  .admin-pkc-grid { grid-template-columns: 1fr !important; }
  .admin-pk-main { padding: 16px !important; }
}

@media (max-width: 768px) {
  /* ── Packaging pages: two compact tiles per row ── */
  .pk-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 12px !important; }
  .pk-tile > div:last-child { padding: 10px 10px 12px !important; }
  .pk-tile > div:last-child > span:first-child { font-size: 0.85rem !important; }

  /* ── Admin → Printing: category select and markup field stack, full width ── */
  .admin-markup-row { flex-direction: column; align-items: stretch !important; }
  .admin-markup-row > div, .admin-markup-row select { width: 100%; min-width: 0 !important; }
  .admin-markup-row > div:last-child > div { flex-wrap: wrap; }
}
