/* ============================================================
   FILE: mobile.css
   Phone and small tablet fixes for cart.html, account.html,
   admin.html and index.html. Desktop look is not changed.
   ============================================================ */

html { -webkit-text-size-adjust: 100%; }
body { overflow-x: hidden; }
img, video { max-width: 100%; height: auto; }
main, section, article, form, fieldset { min-width: 0; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid rgba(197, 155, 39, .75); outline-offset: 2px; }
/* Core fabric image controls do not depend on the optional enhancement sheet. */
.zoom-wrap { position: relative; touch-action: pan-y; cursor: zoom-in; }
.zoom-wrap.zoomed { touch-action: none; cursor: grab; }
.zoom-wrap.dragging { cursor: grabbing; }
.zoom-wrap img { transform-origin: center; user-select: none; -webkit-user-drag: none; }
.zoom-wrap.dragging img { transition: none; }
.zoom-ctrl { position: absolute; left: 8px; bottom: 8px; z-index: 10; display: flex; flex-direction: column; gap: 7px; }
.zoom-ctrl button { display: grid; place-items: center; width: 42px; height: 42px; min-width: 42px; min-height: 42px; padding: 0; border: 1px solid #C59B27; border-radius: 50%; color: #14281D; background: rgba(251,247,238,.96); box-shadow: 0 4px 12px rgba(0,0,0,.35); font-size: 21px; font-weight: 700; line-height: 1; touch-action: manipulation; }
.modal-arrow { position: fixed; z-index: 70; display: grid; place-items: center; width: 48px; height: 48px; min-width: 48px; min-height: 48px; padding: 0; border: 2px solid #fff4cf; border-radius: 50%; color: #14281D; background: linear-gradient(135deg,#f4dc8e,#C59B27); box-shadow: 0 8px 22px rgba(0,0,0,.38); cursor: pointer; touch-action: manipulation; }
.modal-arrow:disabled { color: #4b554e; background: #e7e5e4; border-color: #d6d3d1; opacity: .95; }
.modal-arrow svg { display: block; pointer-events: none; }
@media (min-width: 900px) { .modal-arrow { top: 50%; margin-top: -24px; } .modal-arrow-prev { left: max(10px,calc(50% - 384px - 64px)); } .modal-arrow-next { right: max(10px,calc(50% - 384px - 64px)); } }
@media (max-width: 899px) { .modal-arrow { bottom: calc(10px + env(safe-area-inset-bottom)); } .modal-arrow-prev { left: 12px; } .modal-arrow-next { right: 12px; } }

/* The three-line control stays hidden on desktop. */
.mobile-menu-toggle {
  display: none;
  width: 46px;
  height: 46px;
  min-width: 46px;
  min-height: 46px;
  flex: 0 0 46px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 5px;
  border: 1px solid rgba(250, 246, 240, 0.28);
  border-radius: 14px;
  color: #FAF6F0;
  background: rgba(250, 246, 240, 0.08);
  cursor: pointer;
  touch-action: manipulation;
}
.mobile-menu-toggle span {
  display: block;
  width: 20px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  transition: transform .2s ease, opacity .2s ease;
}
.mobile-menu-toggle.is-open span:first-child { transform: translateY(7px) rotate(45deg); }
.mobile-menu-toggle.is-open span:nth-child(2) { opacity: 0; }
.mobile-menu-toggle.is-open span:last-child { transform: translateY(-7px) rotate(-45deg); }
.glass-nav .site-nav > a { text-decoration: none; }

/* Keeps the bottom of the page clear of the iPhone home bar */
body { padding-bottom: env(safe-area-inset-bottom); }

/* ---------- Every page: phones and small tablets (up to 767px) ---------- */
@media (max-width: 767px) {

  /* 16px text stops iPhones zooming in when a box is tapped */
  input:not([type="checkbox"]):not([type="radio"]),
  select,
  textarea,
  .fld,
  .field {
    font-size: 16px !important;
  }
  .fld, .field { min-height: 46px; }
  textarea.fld, textarea.field { min-height: 90px; }

  /* Bigger tap targets */
  button,
  .btn-gold,
  .btn-soft,
  .btn-outline,
  .nav-pill,
  .tab-btn {
    min-height: 44px;
    touch-action: manipulation;
  }

  /* ---------- Header ---------- */
  header.glass-nav > div {
    position: relative;
    flex-wrap: nowrap !important;
    padding-top: 10px !important;
    padding-bottom: 10px !important;
  }
  header.glass-nav > div > a:first-child {
    flex: 1 1 auto;
    min-width: 0;
    gap: 8px !important;
  }
  header.glass-nav .mobile-menu-toggle { display: inline-flex; }
  header.glass-nav nav.site-nav {
    display: none !important;
    position: absolute;
    top: calc(100% + 8px);
    left: max(12px, env(safe-area-inset-left));
    right: max(12px, env(safe-area-inset-right));
    z-index: 40;
    width: auto;
    max-height: min(72vh, 560px);
    overflow-y: auto;
    flex-direction: column;
    align-items: stretch;
    gap: 7px !important;
    padding: 12px;
    border: 1px solid rgba(197, 155, 39, 0.5);
    border-radius: 18px;
    background: rgba(17, 34, 24, 0.98);
    box-shadow: 0 20px 45px rgba(0, 0, 0, 0.32);
    -webkit-backdrop-filter: blur(18px);
    backdrop-filter: blur(18px);
  }
  header.glass-nav nav.site-nav.is-open { display: flex !important; }
  header.glass-nav nav.site-nav > a {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    width: 100%;
    min-height: 48px;
    padding: 12px 16px !important;
    border-radius: 12px;
    white-space: normal;
    text-align: left;
  }
  header.glass-nav nav.site-nav > a.hidden { display: none !important; }
  header.glass-nav nav.site-nav > a:hover { transform: none; }
  header.glass-nav nav.site-nav > a.btn-gold { justify-content: center; }
  .brand-name { font-size: clamp(1.05rem, 5vw, 1.35rem) !important; line-height: 1.1; }
  #logoBadge { width: 42px !important; height: 42px !important; }
  #shopTagline { font-size: 8px !important; letter-spacing: 0.2em !important; }
  #announcementBar { font-size: 11px !important; padding: 8px 10px !important; letter-spacing: 0.02em; }

  /* About, policy and not-found page headers use the same drop-down menu. */
  .af-head .af-wrap { position: relative; flex-wrap: nowrap; gap: 8px; }
  .af-brand { min-width: 0; flex: 1 1 auto; font-size: clamp(17px, 5vw, 22px) !important; }
  .af-brand img { flex: 0 0 36px; }
  .af-menu-toggle { display: inline-flex; }
  .af-head .site-nav {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    left: max(12px, env(safe-area-inset-left));
    right: max(12px, env(safe-area-inset-right));
    z-index: 50;
    max-height: min(72vh, 560px);
    overflow-y: auto;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    padding: 12px;
    border: 1px solid rgba(197, 155, 39, .5);
    border-radius: 16px;
    background: rgba(17, 34, 24, .98);
    box-shadow: 0 20px 45px rgba(0, 0, 0, .32);
  }
  .af-head .site-nav.is-open { display: flex; }
  .af-head .af-nav a { display: block; margin: 0; padding: 12px 14px; border-radius: 10px; }
  .af-head .site-nav > a.hidden { display: none !important; }

  /* Content never pushes beyond the narrow viewport. */
  main { min-width: 0; }
  .af-main { padding: 24px 12px 44px; }
  .af-banner { padding: 38px 14px 34px; }
  .af-card { padding: 18px 16px; }
  .af-card p, .af-card li { font-size: 14px; }
  .af-grid { grid-template-columns: minmax(0, 1fr); }
  .af-foot { padding: 28px 14px calc(20px + env(safe-area-inset-bottom)); }

  /* Comfortable scrolling and safe-area spacing on iPhones. */
  .glass-nav, .af-head { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
  .af-main, main { overflow-wrap: anywhere; }

  /* ---------- Page title band ---------- */
  .page-band > div { padding-top: 26px !important; padding-bottom: 26px !important; }
  .page-band h1 { font-size: 2rem !important; line-height: 1.15; }

  /* ---------- Cards and boxes ---------- */
  .luxe-card,
  .panel-card {
    padding: 18px !important;
    border-radius: 14px;
  }
  .luxe-card h2,
  .panel-card h2 { font-size: 1.75rem; }
  .section-title { font-size: 1.3rem; }
  .panel-card, .luxe-card { max-width: 100%; }

  /* Stops long words or codes pushing the box wider than the screen */
  .luxe-card, .panel-card, #cartItems, #orderList, #ordersList, #productList {
    min-width: 0;
    overflow-wrap: anywhere;
  }

  /* WhatsApp button: smaller, away from the edge */
  #whatsappFloat {
    bottom: 14px !important;
    right: 12px !important;
    padding: 10px 14px !important;
    font-size: 13px !important;
  }

  /* Pop-up boxes fit the phone screen and scroll inside */
  .modal-back { padding: 10px; align-items: flex-end; }
  .modal-back > div {
    max-height: 92vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Pop-up messages stay on screen */
  #toast {
    max-width: 92vw;
    text-align: center;
    white-space: normal;
  }

  /* Wide data stays readable and scrolls within its own card. */
  .overflow-x-auto {
    max-width: 100%;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
  }
  .overflow-x-auto table { white-space: nowrap; }
  input, select, textarea { max-width: 100%; }
  .modal-back { padding-bottom: env(safe-area-inset-bottom); }
}

/* ---------- Cart page (cart.html) ---------- */
@media (max-width: 767px) {
  /* Each cart row: photo and text side by side, buttons under them */
  #cartItems > div {
    flex-wrap: wrap;
  }
  #cartItems > div img {
    width: 84px !important;
    height: 84px !important;
  }
  /* Quantity buttons and the total keep their size */
  #cartItems button[data-action] {
    width: 40px !important;
    height: 40px !important;
    min-height: 40px !important;
  }
  #cartItems input[data-qty] {
    width: 84px !important;
    min-height: 40px;
  }
  /* Order summary is normal flow on phones, not pinned */
  #summaryCard {
    position: static !important;
  }
  #checkoutForm button[type="submit"] {
    position: sticky;
    bottom: 12px;
    z-index: 5;
    box-shadow: 0 14px 28px -12px rgba(166, 127, 26, 0.9);
  }
  #orderSuccess a {
    width: 100%;
    text-align: center;
  }
}

/* ---------- Account page (account.html) ---------- */
@media (max-width: 767px) {
  /* Welcome strip: Logout goes below the name */
  #memberArea > div:first-child {
    flex-direction: column;
    align-items: flex-start !important;
  }
  #memberArea > div:first-child button {
    width: 100%;
  }
  #memberArea .luxe-card h2 {
    font-size: 1.9rem;
  }
  #loginForm button,
  #signupForm button,
  #saveProfileBtn {
    width: 100%;
  }
  #ordersList article {
    padding: 14px !important;
  }
  #ordersList article > * {
    min-width: 0;
  }
  #ordersEmpty a {
    width: 100%;
  }
}

/* ---------- Admin panel (admin.html) ---------- */
@media (max-width: 767px) {
  /* Owner top bar: title and Logout stack neatly */
  #ownerArea > div:first-child {
    flex-direction: column;
    align-items: flex-start !important;
  }
  #ownerLogoutBtn { width: 100%; }

  /* Side menu becomes a swipeable row of tabs */
  #ownerArea aside.side-menu {
    position: static !important;
    padding: 8px !important;
    border-radius: 14px;
  }
  #ownerArea aside nav {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  #ownerArea aside nav::-webkit-scrollbar { display: none; }
  #ownerArea .tab-btn { flex: 0 0 auto; }

  /* Section titles shrink a little */
  #ownerArea h1.font-heading { font-size: 1.9rem !important; }
  #ownerArea h2.section-title { font-size: 1.5rem; }

  /* Fabric form: price boxes stack on small phones, two-up on bigger ones */
  #productForm .grid.grid-cols-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
  #productForm .grid.grid-cols-2 {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) !important;
  }
  #productForm .grid.grid-cols-3 > div:last-child {
    grid-column: span 2;
  }

  /* Colour boxes: stock field and name use full width */
  .color-row input[data-field="name"],
  .color-row select[data-field="stock"] {
    width: 100%;
    min-width: 0 !important;
  }
  .color-row input[data-field="qty"] {
    width: 100% !important;
  }
  .color-picker { width: 56px; }
  .color-thumb { width: 72px; height: 72px; }

  /* Settings tab: two columns become one */
  #settingsForm .sm\:grid-cols-2,
  #settingsForm .sm\:grid-cols-3 {
    grid-template-columns: minmax(0, 1fr) !important;
  }
  #settingsForm .sm\:col-span-2 { grid-column: auto !important; }
  #settingsForm .grid { grid-template-columns: minmax(0, 1fr) !important; }
  #settingsForm .panel-card { padding: 16px !important; }

  /* Orders and fabric list: one card per row */
  #productList { grid-template-columns: minmax(0, 1fr) !important; }
  #orderStats { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; }
  #orderStats > * { min-width: 0; padding: 10px 6px !important; overflow-wrap: anywhere; }

  /* Customer table scrolls sideways instead of squashing */
  #tab-customers .panel-card {
    padding: 0 !important;
  }
  #tab-customers table { min-width: 640px; }

  /* Pop-up for editing a customer */
  #customerModal .panel-card { padding: 18px !important; }
  #customerModal .flex button { flex: 1 1 auto; }
  #tab-orders .panel-card, #tab-customers .panel-card { max-width: 100%; }
}

/* ---------- Very small phones (up to 380px) ---------- */
@media (max-width: 380px) {
  .brand-name { font-size: 1.15rem !important; }
  #productGrid { gap: 12px !important; }
  .mobile-menu-toggle { width: 44px; height: 44px; min-width: 44px; min-height: 44px; flex-basis: 44px; }
  #productForm .grid.grid-cols-3 { grid-template-columns: minmax(0, 1fr) !important; }
  #productForm .grid.grid-cols-3 > div:last-child { grid-column: auto; }
  #orderStats { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
}

/* Calm page for people who prefer less motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
  }
}

/* ============================================================
   ROUND 3: fabric item boxes, popup, arrows and zoom on phones.
   Animations are lighter on phones so they stay smooth.
   ============================================================ */

/* ---------- Item cards on phones: two per row, neat spacing ---------- */
@media (max-width: 767px) {
  article.af-item {
    min-width: 0;
    border-radius: 14px !important;
  }
  article.af-item h3 {
    font-size: 0.98rem !important;
    line-height: 1.25;
  }
  article.af-item .p-3 { padding: 10px !important; }
  article.af-item p.font-bold { font-size: 0.95rem; }
  article.af-item:hover { transform: none; }   /* no hover lift on touch screens */

  .bulk-pill { font-size: 10px; padding: 2px 8px; }
  .low-chip { font-size: 9.5px; }

  /* Lighter scroll reveal on phones: no blur, less movement */
  @keyframes afReveal {
    from { opacity: 0; translate: 0 18px; }
    to { opacity: 1; translate: 0 0; }
  }
}

/* ---------- Fabric popup as a bottom sheet on phones ---------- */
@media (max-width: 767px) {
  #productModal {
    align-items: flex-end !important;
    padding: 0 !important;
  }
  #productModal > div,
  #productModal .modal-panel {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 94vh !important;
    max-height: 94dvh !important;
    border-radius: 22px 22px 0 0 !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    padding: 58px 14px calc(112px + env(safe-area-inset-bottom)) !important; /* room for close button and scroll tail */
  }

  /* Photo is shorter on phones so the price and Add to Cart fit on screen */
  #productModal #zoomWrap {
    aspect-ratio: auto !important;
    height: min(92vw, 44vh, 380px) !important;
    height: min(92vw, 44dvh, 380px) !important;
    max-height: 44vh;
    max-height: 44dvh;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f3f0e8 !important;
  }
  #productModal #zoomImg { object-fit: contain !important; }
  #closeModal {
    top: 8px !important;
    right: 12px !important;
    z-index: 30 !important;
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border: 1px solid #d8cfb8;
    border-radius: 50%;
    background: #fffdf8;
    font-size: 28px;
    line-height: 1;
  }
  #productModal h2 {
    font-size: 1.6rem !important;
  }
  #productModal .del-circle {
    width: 58px !important;
    height: 58px !important;
  }

  /* Quantity and colour controls stay grouped and readable. */
  #productModal .modal-color-options > [data-color] {
    flex: 1 1 140px;
    min-width: 128px;
    min-height: 58px;
    padding: 9px 10px !important;
    justify-content: flex-start;
  }
  #productModal .modal-color-options > [data-color] > span { min-width: 0; line-height: 1.25; }
  #productModal .modal-color-options small { white-space: normal; }
  #productModal .modal-quantity { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 10px; }
  #productModal .modal-quantity > span:first-child { grid-column: 1 / -1; }
  #productModal .modal-quantity-controls { display: flex; align-items: center; gap: 8px; }
  #productModal .modal-quantity-controls button { flex: 0 0 44px; }
  #productModal .modal-quantity-controls input { width: 88px !important; }
  #productModal .modal-quantity > span:last-child { justify-self: end; }

  /* Quantity row fits in one screen width */
  #productModal [data-step] {
    width: 44px !important;
    height: 44px !important;
    min-height: 44px !important;
  }
  #productModal #mQty {
    width: 96px !important;
    min-height: 44px;
  }

  /* Colour circles: easy to tap with a thumb */
  #productModal [data-color] {
    width: 40px !important;
    height: 40px !important;
  }

  /* The purchase action follows the choices and never covers product details. */
  #productModal [data-add] {
    position: static !important;
    display: block;
    z-index: auto;
    min-height: 50px;
    font-size: 1rem;
    box-shadow: 0 14px 26px -12px rgba(166, 127, 26, 0.95);
  }

  /* Zoom buttons are bigger and sit on the photo */
  .zoom-ctrl button {
    width: 44px !important;
    height: 44px !important;
    font-size: 22px !important;
  }
  .zoom-hint { display: none; }
}

/* ---------- Arrows stay over the product photo on phones ---------- */
@media (max-width: 767px) {
  .modal-arrow {
    position: absolute !important;
    top: 50% !important;
    bottom: auto !important;
    width: 46px !important;
    height: 46px !important;
    min-width: 46px !important;
    min-height: 46px !important;
    margin: 0 !important;
    transform: translateY(-50%);
  }
  .modal-arrow-prev { left: 8px !important; }
  .modal-arrow-next { right: 8px !important; }
  #productModal .zoom-ctrl {
    z-index: 12;
    left: 10px;
    right: auto;
    top: auto;
    bottom: 10px;
    flex-direction: row;
    gap: 8px;
    transform: none;
  }
  #productModal .zoom-ctrl button {
    width: 42px !important;
    height: 42px !important;
    min-width: 42px !important;
    min-height: 42px !important;
  }
}

/* ---------- Very small phones ---------- */
@media (max-width: 380px) {
  article.af-item h3 { font-size: 0.9rem !important; }
  .del-circle { width: 48px !important; height: 48px !important; }
  .del-circle b { font-size: 10px !important; }
  #productModal h2 { font-size: 1.35rem !important; }
}

/* Keep two product cards on compact phones; use one column only on very narrow screens. */
@media (max-width: 350px) {
  #productGrid, #homeSections .grid { grid-template-columns: minmax(0, 1fr) !important; }
}

/* Phone ticker has its own styles so it remains tidy if animation styling is blocked. */
@media (max-width: 767px) {
  .fabric-ticker {
    display: block;
    position: relative;
    z-index: 1;
    width: 100%;
    margin: 0;
    padding: 8px 0;
    overflow: hidden;
    white-space: nowrap;
    -webkit-mask-image: linear-gradient(90deg, transparent, #000 5%, #000 95%, transparent);
    mask-image: linear-gradient(90deg, transparent, #000 5%, #000 95%, transparent);
  }
  .fabric-ticker .track {
    display: inline-flex;
    width: max-content;
    gap: 10px;
    animation: afTicker 26s linear infinite;
  }
  .fabric-ticker span {
    flex: 0 0 auto;
    padding: 7px 12px;
    border: 1px solid rgba(197, 155, 39, .4);
    border-radius: 999px;
    color: #f4dc8e;
    background: rgba(197, 155, 39, .1);
    font-size: 11px;
    line-height: 1.2;
  }
  .hero-title { font-size: clamp(2rem, 8.4vw, 3rem) !important; line-height: 1.08 !important; }
  .hero-panel { padding: 1.8rem 1rem !important; border-radius: 22px !important; }
}
@keyframes afTicker { to { transform: translateX(-50%); } }
@media (prefers-reduced-motion: reduce) {
  .fabric-ticker .track { animation: none !important; transform: none !important; }
}