/*
 * Asha Shop — responsive mobile layout.
 *
 * Every rule in this file is scoped inside @media (max-width: 991.98px) so the
 * desktop view is never affected. All colors come from the theme tokens injected
 * in base.html (:root { --c-* }) which are derived from app/config/site_config.py
 * THEME — recolor the whole shop by editing that one file.
 *
 * Structure added:
 *   #header .mobile-header-version   – sticky top header (logo + ورود/پروفایل + search)
 *   #mobile-bottom-nav                – floating "pill" bottom navigation
 *   #mobile-search-panel              – search bar that expands under the header
 *   #mobile-categories-drawer         – category tree drawer
 */

/* Mobile-only UI is hidden on desktop. */
#header .mobile-header-version,
#mobile-bottom-nav,
#mobile-search-panel,
#mobile-categories-drawer,
#mobile-categories-overlay { display: none; }

@media (max-width: 991.98px) {

  /* ═══════════════ 1. Sticky top header ═══════════════ */
  #header .desktop-header-version { display: none !important; }
  #header .mobile-header-version { display: block; }

  /* Sticky must live on #header (not .mobile-header-version): its parent
     (#page/.st-pusher) spans the full page, giving the sticky element room to
     stick. Sticking the inner div fails because #header is only as tall as the
     header itself, so it scrolls away with the page. */
  #header {
    position: sticky;
    top: 0;
    z-index: 1020;
    width: 100%;
    background: var(--c-slider-bg, #00a693);
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.06);
  }

  .mobile-header-version .mobile-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 16px;
    min-height: 56px;
  }

  /* Left side (RTL: right) — logo */
  .mobile-header-version .mobile-logo { flex: 1 1 auto; min-width: 0; }
  .mobile-header-version .mobile-logo a { display: inline-block; }
  .mobile-header-version .mobile-logo img {
    max-height: 42px;
    max-width: 100%;
    width: auto;
    height: auto;
  }

  /* Right side (RTL: left) — account text link + search icon */
  .mobile-header-version .mobile-actions {
    display: flex;
    align-items: center;
    gap: 14px;
    flex: none;
  }

  .mobile-header-version .mobile-account-link {
    color: #ffffff;
    font-size: 15px;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
  }
  .mobile-header-version .mobile-account-link:hover {
    color: rgba(255, 255, 255, 0.85);
    text-decoration: none;
  }

  /* profile button — avatar + name like the desktop account link */
  .mobile-header-version .mobile-profile-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    max-width: 150px;
    padding: 5px 10px;
    border: 1px solid rgba(255, 255, 255, 0.55);
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.14);
    color: #ffffff;
    cursor: pointer;
    font-family: IranSANS, sans-serif !important;
    -webkit-appearance: none;
    appearance: none;
  }
  .mobile-header-version .mobile-profile-btn img {
    width: 22px;
    height: 22px;
    flex: none;
  }
  .mobile-header-version .mobile-profile-btn span {
    font-size: 13px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-header-version .mobile-search-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.7);
    color: var(--c-text, #333);
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease;
  }
  .mobile-header-version .mobile-search-btn:hover {
    background: rgba(255, 255, 255, 0.95);
    color: var(--c-primary, #00a693);
  }
  .mobile-header-version .mobile-search-btn i { font-size: 18px; line-height: 1; }

  /* ─ search panel expanding under the header ─ */
  #mobile-search-panel {
    display: none;
    background: var(--c-slider-bg, #00a693);
    padding: 0 16px 12px;
  }
  #mobile-search-panel.open { display: block; }
  #mobile-search-panel form {
    position: relative;
    display: flex;
    align-items: center;
  }
  #mobile-search-panel input[type="text"] {
    flex: 1 1 auto;
    min-width: 0;
    height: 42px;
    border: 1px solid var(--c-border, #e2e2e2);
    border-radius: 10px;
    background: #fff;
    color: var(--c-text, #333);
    padding: 0 42px 0 14px;
    font-size: 14px;
    font-family: IranSANS, sans-serif !important;
    outline: none;
  }
  #mobile-search-panel button[type="submit"] {
    position: absolute;
    inset-inline-start: 4px;
    top: 4px;
    bottom: 4px;
    width: 34px;
    border: 0;
    border-radius: 8px;
    background: var(--c-primary, #00a693);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
  }
  #mobile-search-panel button[type="submit"] i { font-size: 15px; }

  /* ═══════════════ 1b. Hide the desktop sidebar on mobile ═══════════════
     The sidebar (category menu, support image, contact info) is desktop-only;
     on mobile the categories live in the bottom-nav drawer. The center column
     takes the full width instead. */
  #left-column.sidebar-column { display: none !important; }
  #center-column { flex: 0 0 100%; max-width: 100%; }

  /* Homepage tabs (کالای ویژه / کالای جدید / کالای تازه موجود) fit in one row */
  .aone-tabs .nav.nav-tabs {
    flex-wrap: nowrap;
    justify-content: center;
  }
  .aone-tabs .nav.nav-tabs .nav-item {
    flex: 1 1 0;
    min-width: 0;
    margin: 0 2px;
  }
  .aone-tabs .nav.nav-tabs .nav-item .nav-link {
    padding: 6px 4px;
    font-size: 0.8rem;
    white-space: nowrap;
    text-align: center;
  }
  .aone-tabs .nav.nav-tabs .nav-item .nav-link span {
    font-size: 0.8rem;
    white-space: nowrap;
  }

  /* ═══════════════ 2. Floating bottom navigation footer ═══════════════ */
  body {
    padding-bottom: calc(68px + env(safe-area-inset-bottom, 0px));
  }

  #mobile-bottom-nav {
    position: fixed;
    left: 16px;
    right: 16px;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    z-index: 1050;
    display: flex;
    /* same light-green derived from the theme primary as the slider buttons */
    background: color-mix(in srgb, var(--c-primary, #00a693) 15%, #ffffff);
    border-radius: 36px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.14);
    padding: 5px 10px;
    border: 1px solid rgba(0, 0, 0, 0.04);
  }

  #mobile-bottom-nav .mbn-item {
    position: relative;
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 2px;
    padding: 2px 0 3px;
    background: none;
    border: 0;
    box-shadow: none;
    -webkit-appearance: none;
    appearance: none;
    outline: none;
    text-decoration: none;
    color: var(--c-muted, #868686);
    cursor: pointer;
    transition: color 0.25s ease;
    -webkit-tap-highlight-color: transparent;
  }
  #mobile-bottom-nav .mbn-item:hover { color: var(--c-primary, #00a693); }
  #mobile-bottom-nav .mbn-item.active { color: var(--c-primary, #00a693); }

  /* icon is a fixed 32px box so the active circle always centers exactly on it */
  #mobile-bottom-nav .mbn-icon {
    position: relative;
    z-index: 2;
    width: 32px;
    height: 32px;
    font-size: 19px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  #mobile-bottom-nav .mbn-icon img { width: 18px; height: 18px; object-fit: contain; }
  #mobile-bottom-nav .mbn-label { font-size: 10.5px; font-weight: 600; line-height: 1; }

  /* sliding circle indicator (soft #00a693 circle, light animation while moving) */
  #mobile-bottom-nav .mbn-indicator {
    display: none !important;
    position: absolute;
    top: 3px;
    height: 32px;
    width: 32px;
    border-radius: 50%;
    background: rgba(0, 166, 147, 0.15);
    background: color-mix(in srgb, var(--c-primary, #00a693) 15%, transparent);
    transition: inset-inline-start 0.35s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.25s ease;
    opacity: 0;
    pointer-events: none;
    z-index: 1;
  }
  #mobile-bottom-nav[data-ready] .mbn-indicator { opacity: 1; }

  /* cart count badge overlapping the basket icon */
  #mobile-bottom-nav .mbn-cart-badge {
    position: absolute;
    top: -4px;
    inset-inline-end: -6px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 8px;
    background: var(--c-hint, #ff5722);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
    font-family: IranSANS, sans-serif !important;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  }

  /* resting scroll-to-top above the floating nav */
  #scrollTopButton { bottom: calc(76px + env(safe-area-inset-bottom, 0px)); z-index: 1040; }

  /* ═══════════════ 3. Categories drawer ═══════════════ */
  #mobile-categories-drawer {
    position: fixed;
    top: 0;
    bottom: 0;
    right: 0;
    left: auto;
    width: min(86vw, 360px);
    max-width: 92vw;
    z-index: 1060;
    background: #fff;
    box-shadow: -6px 0 24px rgba(0, 0, 0, 0.16);
    transform: translateX(100%);
    transition: transform 0.32s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    visibility: hidden;
  }
  #mobile-categories-drawer.open {
    transform: translateX(0);
    visibility: visible;
  }

  .mcd-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--c-primary, #00a693);
    color: #fff;
  }
  .mcd-header .mcd-title {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    color: #fff;
  }
  .mcd-close {
    border: 0;
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
  }
  .mcd-close i { font-size: 16px; }

  .mcd-body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 12px 8px;
    -webkit-overflow-scrolling: touch;
  }
  .mcd-body .category-tree > ul > li > a { font-weight: 700; }

  #mobile-categories-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1055;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
  }
  #mobile-categories-overlay.open {
    opacity: 1;
    visibility: visible;
  }

  /* ═══════════════ 4. Cart page (mobile only) ═══════════════
     Mobile layout stacks each cart line vertically so long product names and
     descriptions get the full card width instead of a narrow column:
       image → name → part number → price + tax → quantity / delete.
     Desktop is untouched (scoped to the cart page inside this media query). */
  .page-cart .cart-item-row {
    padding: 12px !important;
  }
  .page-cart .cart-item-flex {
    display: flex;
    flex-direction: column !important;
    align-items: stretch !important;
    flex-wrap: nowrap;
    gap: 10px;
  }
  .page-cart .cart-item-flex > * {
    flex: 0 0 auto;
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }
  .page-cart .cart-item-image {
    flex: 0 0 auto !important;
    width: 80px;
    max-width: 80px;
    align-self: flex-start;
  }
  .page-cart .cart-item-image img {
    width: 80px;
    height: 80px;
    object-fit: cover;
  }
  .page-cart .cart-item-details {
    flex: 1 1 auto;
    min-width: 0;
    width: 100%;
    padding-inline: 0 !important;
  }
  .page-cart .cart-item-details .cart-item-name {
    display: block;
    white-space: normal;
    overflow-wrap: break-word;
  }
  .page-cart .cart-item-prices {
    margin-top: 6px;
  }
  .page-cart .cart-item-qty {
    justify-content: flex-start;
  }
  .page-cart .cart-item-qty .qty input {
    width: 52px !important;
    height: 38px;
  }
  .page-cart .cart-item-total {
    min-width: 0 !important;
    padding-inline: 0 !important;
    text-align: start;
  }
  .page-cart .cart-item-actions {
    align-self: flex-start;
  }

  /* ═══════════════ 5. Home slider arrows (mobile only) ═══════════════
     Replace the default circular buttons / ">>" "<<" text glyphs with a simple
     rectangle button carrying a single direction icon (left / right). In RTL the
     theme's [dir='rtl'] rules put .slick-prev on the right and .slick-next on the
     left; on mobile we position prev on the left (pointing left) and next on the
     right (pointing right). Scoped to the home block sliders so desktop is
     unaffected. */
  .aone-homepage .product-list .js-home-block-slider .slick-prev,
  .aone-homepage .product-list .js-home-block-slider .slick-next {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 6px;
    /* light green derived from the theme primary (never hardcoded) */
    background: color-mix(in srgb, var(--c-primary, #00a693) 15%, #ffffff);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.10);
    line-height: 1;
  }
  .aone-homepage .product-list .js-home-block-slider .slick-prev {
    right: auto !important;
    left: -10px !important;
  }
  .aone-homepage .product-list .js-home-block-slider .slick-next {
    left: auto !important;
    right: -10px !important;
  }
  .aone-homepage .product-list .js-home-block-slider .slick-prev:before,
  .aone-homepage .product-list .js-home-block-slider .slick-next:before {
    font-family: FontAwesome !important;
    font-size: 17px !important;
    font-weight: normal !important;
    line-height: 1 !important;
    color: var(--c-primary, #00a693);
    margin: 0 !important;
  }
  .aone-homepage .product-list .js-home-block-slider .slick-prev:before {
    content: "\f053" !important;
  }
  .aone-homepage .product-list .js-home-block-slider .slick-next:before {
    content: "\f054" !important;
  }

  /* ═══════════════ 6. Category page description (mobile only) ═══════════════
     Show the category text near the image as a short 3-line excerpt with a
     «ادامه مطلب» toggle. Desktop keeps the full paragraph. */
  .page-category .category-description .js-expand-description .typo.descFull {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .page-category .category-description .js-expand-description.expanded .typo.descFull {
    display: block;
    -webkit-line-clamp: unset;
  }
  .page-category .category-description .js-expand-description .js-expand-description-btn {
    margin-top: 6px;
    padding: 3px 12px;
    font-size: 0.8rem;
    color: var(--c-primary, #00a693);
    background: transparent;
    border: 1px solid var(--c-primary, #00a693);
    border-radius: 6px;
    cursor: pointer;
  }
  .page-category .category-description .js-expand-description .js-expand-description-btn:hover {
    background: var(--c-primary, #00a693);
    color: #fff;
  }

  /* ═══════════════ 7. Product detail thumbnails (mobile only) ═══════════════
     Make every thumbnail below the selected image perfectly square
     (equal width = equal height) instead of following the source aspect
     ratio. Uses the classic padding-bottom ratio box (works in every
     browser, no aspect-ratio support needed): the <a> gets height:0 +
     padding-bottom:100% → an exact square, and the <img> is absolutely
     positioned to fill it with object-fit: cover.
     Scoped by .main-product-details (present statically in the DOM) rather
     than #product which is only added to <body> by JS. */
  .main-product-details .product-images li.thumb-container {
    flex: 0 0 25%;
    max-width: 25%;
    padding: 0 3px;
  }
  .main-product-details .product-images li.thumb-container .thumb {
    position: relative;
    display: block;
    width: 100%;
    height: 0;
    padding: 0;
    padding-bottom: 100%;
    border: 1px solid transparent;
    overflow: hidden;
    background: #f3f3f3;
  }
  .main-product-details .product-images li.thumb-container .thumb.selected {
    border-color: #fd6282;
  }
  .main-product-details .product-images li.thumb-container .thumb img.smallImage {
    position: absolute;
    top: 0;
    left: 0;
    display: block !important;
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
  }

  /* ═══════════════ 8. Categories drawer close button ═══════════════
     A font glyph can sit slightly off-centre because of font metrics/line-
     height, so instead of tweaking the font we DRAW the × from two rotated
     bars on a ::before/::after. These are absolutely centred on the icon
     box, which the flex-centred button holds dead in the middle — the glyph
     can no longer drift. */
  .mcd-close {
    padding: 0;
  }
  .mcd-close i {
    position: relative;
    display: block;
    width: 12px;
    height: 12px;
    font-size: 0 !important;
    line-height: 0;
  }
  .mcd-close i::before,
  .mcd-close i::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 13px;
    height: 2px;
    background: currentColor;
    border-radius: 2px;
    transform: translate(-50%, -50%) rotate(45deg);
  }
  .mcd-close i::after {
    transform: translate(-50%, -50%) rotate(-45deg);
  }

  /* ═══════════════ 9. Profile sliding sidebar (mobile only) ═══════════════
     Mirror the categories drawer: on phones the profile panel becomes a
     full-height fixed drawer with z-index above the floating bottom nav (the
     nav stays below it), and the links list is scrollable so every entry —
     including خروج — remains reachable. Desktop is untouched (scoped to
     max-width 991.98px). */
  .profile-effect-left.st-menu {
    top: 0;
    bottom: 0;
    width: min(86vw, 360px);
    max-width: 92vw;
    z-index: 1060;
    overflow: hidden;
  }
  .profile-effect-left.st-menu .block-myaccount-infos {
    display: flex;
    flex-direction: column;
    height: 100%;
  }
  .profile-effect-left.st-menu .account-list {
    flex: 1 1 auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 12px;
  }
  .profile-effect-left.st-menu .footer {
    flex: 0 0 auto;
    padding-bottom: 12px;
  }
}