/**
 * Modern Shop Theme — responsive-v14.css (PATCH v1.4)
 * ------------------------------------------------------------------
 * Mobile/responsive fixes reported by the shop owner:
 *
 *  A) Compact ONE-ROW mobile header (logo + toggle + user + cart + burger).
 *     Was: two rows (row 1 logo, row 2 dark-toggle & actions) eating the screen.
 *  B) Mobile drawer: close ✕ button + site-name header + search field +
 *     tap-outside overlay + hamburger morphs to ✕ (was impossible to close:
 *     the drawer's z-index buried the hamburger).
 *  C) Profile page grid blowout — the horizontal tab strip's nowrap items
 *     forced the grid to ~830px on 390px phones (page "not responsive").
 *  D) Wishlist heart: self-contained animation that can never be clipped
 *     by the product thumb's overflow:hidden (was: half-missing red heart).
 *  E) Categories section: short title "دسته‌بندی‌ها" on mobile (icon hidden,
 *     no wrapping) and a swipeable rail with arrow buttons when there are
 *     more than 10 categories.
 *
 * Loaded AFTER style.css / theme-v13.css so it wins the cascade.
 * ------------------------------------------------------------------ */

/* ==================================================================
 * A) COMPACT ONE-ROW MOBILE HEADER
 * ================================================================== */
@media (max-width: 767px) {
    .header-main {
        flex-wrap: nowrap !important;   /* kill the old wrap → single row */
        gap: 8px;
        padding: 10px 14px;
    }

    /* logo: small icon + truncated name */
    .logo {
        flex: 0 1 auto;
        min-width: 0;
        gap: 8px;
        font-size: 1.08rem;
    }
    .logo-icon {
        width: 34px;
        height: 34px;
        border-radius: 10px;
        font-size: 0.95rem;
    }
    .logo img { max-height: 34px !important; }
    .logo-text {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        max-width: 46vw;
    }

    /* actions: tight, round, icon-only */
    .user-actions {
        gap: 7px;
        flex: 0 0 auto;
        margin-right: auto; /* push to the far (left in RTL visual) side */
    }

    .btn-auth {
        padding: 0 !important;
        width: 38px;
        height: 38px;
        border-radius: 50%;
        justify-content: center;
        gap: 0;
        flex: 0 0 auto;
    }
    .btn-auth i { font-size: 0.98rem; }

    .cart-btn {
        padding: 0 !important;
        width: 38px;
        height: 38px;
        border-radius: 50%;
        justify-content: center;
        gap: 0;
        flex: 0 0 auto;
    }
    .cart-btn i { font-size: 1rem; }
    .cart-badge {
        position: absolute;
        top: -5px;
        left: -5px;
        min-width: 19px;
        height: 19px;
        padding: 0 5px;
        border-radius: 10px;
        font-size: 0.68rem;
        border: 2px solid var(--card-bg);
    }

    /* theme toggle: small pill */
    .ms-theme-toggle__track { width: 48px; height: 28px; padding: 0 6px; gap: 5px; }
    .ms-theme-toggle__icon { font-size: 0.66rem; }
    .ms-theme-toggle__thumb { width: 22px; height: 22px; top: 3px; right: 3px; }
    body.dark-mode .ms-theme-toggle__thumb { right: calc(100% - 25px); }

    /* hamburger: stays clickable above the drawer */
    .mobile-menu-toggle {
        flex: 0 0 auto;
        width: 38px;
        height: 38px;
        border-radius: 10px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-size: 1.15rem;
        padding: 0;
        position: relative;
        z-index: 10001; /* above drawer (9999) and its overlay */
        background: var(--input-bg);
        border: 2px solid var(--input-border);
        color: var(--text-strong);
    }
    .mobile-menu-toggle.is-open {
        background: var(--primary-gradient);
        border-color: transparent;
        color: #fff;
    }

    /* search stays hidden in the bar (it now lives inside the drawer) */
    .search-box { display: none !important; }
}

/* slightly wider phones / small tablets: same compact rules apply */
@media (min-width: 768px) {
    .mobile-menu-toggle { display: none !important; }
    .ms-nav-overlay { display: none !important; }
    .ms-drawer-head, .ms-drawer-search { display: none !important; }
}

/* ==================================================================
 * B) MOBILE DRAWER (header-nav) + OVERLAY
 * ================================================================== */
.ms-nav-overlay {
    position: fixed;
    inset: 0;
    z-index: 9998;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(2px);
    animation: msOverlayIn .25s ease;
}
@keyframes msOverlayIn { from { opacity: 0; } to { opacity: 1; } }

@media (max-width: 767px) {
    .header-nav {
        display: none;
        position: fixed;
        top: 0;
        right: 0;
        width: min(320px, 86vw);
        height: 100dvh;
        background: var(--card-bg);
        box-shadow: -8px 0 40px rgba(0, 0, 0, 0.22);
        z-index: 9999;
        padding: 0 14px 24px;
        overflow-y: auto;
        flex-direction: column;
        overscroll-behavior: contain;
    }
    .header-nav.mobile-open {
        display: flex;
        animation: msDrawerIn .3s cubic-bezier(.22,.9,.3,1);
    }
    @keyframes msDrawerIn {
        from { transform: translateX(24px); opacity: .4; } /* slides in from the right edge (RTL) */
        to   { transform: translateX(0); opacity: 1; }
    }

    /* drawer header bar */
    .ms-drawer-head {
        position: sticky;
        top: 0;
        z-index: 2;
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 14px 2px 12px;
        background: var(--card-bg);
        border-bottom: 1px solid var(--card-border);
        margin: 0 -4px 12px;
    }
    .ms-drawer-close {
        width: 36px;
        height: 36px;
        border: 2px solid var(--input-border);
        border-radius: 10px;
        background: var(--input-bg);
        color: var(--text-strong);
        font-size: 1rem;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        flex: 0 0 auto;
        transition: var(--transition);
    }
    .ms-drawer-close:active { transform: scale(.94); }
    .ms-drawer-title {
        font-size: 1rem;
        font-weight: 900;
        color: var(--text-heading);
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* search inside the drawer */
    .ms-drawer-search {
        position: relative;
        margin-bottom: 14px;
    }
    .ms-drawer-search input {
        width: 100%;
        box-sizing: border-box;
        padding: 12px 48px 12px 16px;
        border-radius: 14px;
        border: 2px solid var(--input-border);
        background: var(--input-bg);
        color: var(--text-main);
        font: inherit;
        font-size: 0.88rem;
        outline: none;
        transition: var(--transition);
    }
    .ms-drawer-search input:focus {
        border-color: var(--primary);
        background: var(--input-bg-focus, var(--card-bg));
        box-shadow: var(--input-focus-ring);
    }
    .ms-drawer-search button {
        position: absolute;
        right: 6px;
        top: 50%;
        transform: translateY(-50%);
        width: 36px;
        height: 36px;
        border: 0;
        border-radius: 10px;
        background: var(--primary-gradient);
        color: #fff;
        font-size: 0.9rem;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
    }

    /* nav items inside the drawer */
    .header-nav .nav-container { flex-direction: column; gap: 0; }
    .header-nav .nav-item {
        padding: 13px 10px;
        border-bottom: 1px solid var(--card-border);
        justify-content: flex-start;
        font-size: 0.92rem;
    }
    .header-nav .nav-item::after { display: none; } /* kill the underline (active keeps color) */
    .header-nav .nav-dropdown {
        position: static;
        display: flex;
        box-shadow: none;
        padding: 0 10px 6px 24px;
        min-width: 0;
        background: transparent;
    }
    .header-nav .nav-dropdown .nav-item {
        font-size: 0.82rem;
        color: var(--text-muted);
        border-bottom: 1px dashed var(--card-border);
    }
    /* dropdowns always expanded inside the drawer (no hover on touch) */
    .nav-dropdown-wrapper:hover .nav-dropdown,
    .header-nav .nav-dropdown-wrapper .nav-dropdown { display: flex; }

    body.ms-nav-open { overflow: hidden; }
}

/* ==================================================================
 * C) PROFILE PAGE — grid blowout fixes
 * ================================================================== */
/* Grid items must be allowed to shrink (their default min-width:auto made
   the nowrap tab strip stretch the whole layout to ~830px on phones). */
.account-layout > .account-sidebar,
.account-layout > .account-content {
    min-width: 0;
    max-width: 100%;
}
.account-nav { max-width: 100%; }
.account-nav-item { min-width: 0; }
.account-stats > * { min-width: 0; }

@media (max-width: 992px) {
    /* the horizontal tab strip must SCROLL, never stretch the page */
    .account-nav {
        display: flex;
        flex-direction: row;
        overflow-x: auto;
        gap: 6px;
        padding: 8px 6px;
        max-width: 100%;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .account-nav::-webkit-scrollbar { display: none; }
    .account-nav-item {
        white-space: nowrap;
        flex: 0 0 auto;
        width: auto;
        padding: 10px 16px;
        border-radius: 14px;
    }
    .account-nav-item i { width: auto; }
    .account-nav-badge { margin-right: auto; margin-right: 6px; }

    /* user card: compact horizontal on tablets */
    .account-user-card { padding: 18px 14px; }
}

@media (max-width: 640px) {
    .account-layout { gap: 14px; margin-bottom: 36px; }
    .account-content { padding: 16px 12px; border-radius: var(--radius-lg); }
    .account-user-card { padding: 16px 12px; }

    /* stats: 2-up grid that actually fits */
    .account-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .account-stat-card { padding: 14px 10px; }
    .account-stat-value { font-size: 1.25rem !important; }
    .account-stat-label { font-size: 0.72rem !important; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .account-stat-icon { width: 40px; height: 40px; font-size: 1rem !important; }

    .account-panel-title { font-size: 1.08rem; }
    .account-form-grid { grid-template-columns: 1fr; }
    .account-order-item { flex-wrap: wrap; }
    .account-order-item-title { white-space: normal; width: 100%; flex: none; }
    .account-order-card-head,
    .account-order-card-foot { flex-direction: column; align-items: stretch; gap: 10px; }
    .account-security-tips { padding: 14px; }
}

/* any wide table that lives inside account panels scrolls on its own */
.account-content .table-scroll,
.account-order-card .table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* ==================================================================
 * D) WISHLIST HEART — self-contained animation (never clipped)
 * ================================================================== */
/* Remove the legacy infinite ring that overflowed the thumb and looked
   "cut in half" when the heart turned red (reported on desktop grid). */
.ms-wish-btn { overflow: hidden; }               /* clip effects to the circle */
.ms-wish-btn.is-active::after { content: none; } /* legacy ring disabled */

.ms-wish-btn.is-active {
    color: #fff;
    background: var(--primary-gradient);
    animation: msHeartBeat .9s ease-in-out infinite;
}
/* heartbeat of the ICON only — stays inside the button at all times */
.ms-wish-btn.is-active i {
    animation: msHeartIcon .9s ease-in-out infinite;
}
@keyframes msHeartBeat {
    0%, 100% { transform: scale(1); }
    12% { transform: scale(1.06); }
    24% { transform: scale(1); }
    36% { transform: scale(1.04); }
    48% { transform: scale(1); }
}
@keyframes msHeartIcon {
    0%, 100% { transform: scale(1); }
    12% { transform: scale(1.18); }
    24% { transform: scale(1); }
    36% { transform: scale(1.12); }
    48% { transform: scale(1); }
}

/* one-shot inner ripple when the heart is activated — clipped by the
   button itself, so nothing can ever stick out of the product image */
.ms-wish-btn .ms-wish-ripple {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: rgba(255, 46, 99, 0.45);
    transform: scale(0);
    opacity: 0;
    pointer-events: none;
}
.ms-wish-btn.ms-wish--pop .ms-wish-ripple {
    animation: msWishRipple .6s ease-out 1;
}
@keyframes msWishRipple {
    0%   { transform: scale(.25); opacity: .9; }
    100% { transform: scale(1);   opacity: 0; }
}

/* hover stays subtle and inside bounds */
.ms-wish-btn:hover { transform: scale(1.08); }

/* ==================================================================
 * E) CATEGORIES SHOWCASE — mobile title + swipe rail
 * ================================================================== */
/* default (desktop): long title, short hidden */
.ms-cat-showcase .ms-cat-title-short { display: none; }
.ms-cat-showcase .ms-cat-title-long { display: inline; }

/* Mobile: icon hidden, SHORT title ("دسته‌بندی‌ها"), nothing wraps */
@media (max-width: 640px) {
    .ms-cat-showcase .section-title-wrap { gap: 8px; margin-bottom: 18px; }
    .ms-cat-showcase .section-title {
        font-size: 1.02rem;
        gap: 8px;
        white-space: nowrap;
        min-width: 0;
    }
    .ms-cat-showcase .section-title::before { width: 5px; height: 20px; }
    .ms-cat-showcase .section-title > i { display: none; }        /* icon off on mobile */
    .ms-cat-showcase .section-title .ms-cat-title-long { display: none; }
    .ms-cat-showcase .section-title .ms-cat-title-short { display: inline; }
    .ms-cat-showcase .view-all {
        font-size: 0.78rem;
        padding: 7px 12px;
        white-space: nowrap;
        flex: 0 0 auto;
    }
    /* smaller cards on phones */
    .ms-cat-card { padding: 16px 8px 12px; gap: 8px; }
    .ms-cat-icon { width: 50px; height: 50px; font-size: 1.2rem; border-radius: 16px; }
    .ms-cat-name { font-size: 0.82rem; }
    .ms-cat-count { font-size: 0.66rem; }
}

/* --- Swipeable rail (used when there are MORE than 10 categories) --- */
.ms-cat-rail-wrap { position: relative; }
.ms-cat-rail {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    scroll-snap-type: x proximity; /* mandatory fights with drag-to-scroll */
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    padding: 4px 2px 14px;
    scrollbar-width: none;
}
.ms-cat-rail::-webkit-scrollbar { display: none; }
.ms-cat-rail .ms-cat-card {
    flex: 0 0 148px;
    scroll-snap-align: start;
}
@media (max-width: 640px) {
    .ms-cat-rail .ms-cat-card { flex-basis: 118px; }
}

/* arrow buttons (RTL-aware: "next" goes to the LEFT visually) */
.ms-cat-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 5;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 0;
    background: var(--card-bg);
    color: var(--text-strong);
    font-size: 0.9rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.16);
    transition: transform .2s ease, opacity .2s ease, background .2s ease;
}
.ms-cat-arrow:hover { background: var(--primary); color: #fff; }
.ms-cat-arrow:active { transform: translateY(-50%) scale(.92); }
.ms-cat-arrow[disabled] { opacity: 0; pointer-events: none; }
.ms-cat-arrow--next { left: -8px; }   /* RTL: forward = visually left */
.ms-cat-arrow--prev { right: -8px; }  /* RTL: backward = visually right */
@media (max-width: 640px) {
    .ms-cat-arrow { width: 32px; height: 32px; font-size: 0.8rem; }
    .ms-cat-arrow--next { left: 2px; }
    .ms-cat-arrow--prev { right: 2px; }
}

/* thin progress bar under the rail */
.ms-cat-progress {
    height: 5px;
    border-radius: 5px;
    background: var(--thumb-bg, #E2E8F0);
    overflow: hidden;
    margin-top: 2px;
}
.ms-cat-progress__fill {
    height: 100%;
    width: 20%;
    border-radius: 5px;
    background: var(--primary-gradient);
    transition: width .25s ease;
}

body.dark-mode .ms-drawer-search input,
body.dark-mode .ms-drawer-close { background: var(--input-bg); }
body.dark-mode .ms-cat-arrow { background: var(--card-bg); color: var(--text-main); }
body.dark-mode .ms-cat-arrow:hover { background: var(--primary); color: #fff; }
