/* ==========================================================================
   لایه تخصصی موبایل — تجربه‌ای جداگانه و اپ‌مانند برای گوشی و تبلت
   --------------------------------------------------------------------------
   ۱) پایه و جلوگیری از سرریز افقی
   ۲) نوار بالای موبایل + منوی کشویی
   ۳) نوار پایین (Bottom Navigation)
   ۴) صفحه اصلی و بخش‌های عمومی
   ۵) محصولات، سبد خرید و پرداخت
   ۶) مقالات
   ۷) پنل کاربری و مدیریت (جدول‌های کارتی)
   ========================================================================== */

:root {
    --mobile-appbar: 58px;
    --mobile-bottom-nav: 62px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);
}

html, body { max-width: 100%; overflow-x: hidden; }
body { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
img, video, iframe, svg { max-width: 100%; }

.mobile-only { display: none !important; }

@media (max-width: 992px) {
    .desktop-only { display: none !important; }
    .mobile-only { display: block !important; }

    /* ------------------------------------------------------------------ */
    /* ۲) نوار بالا و منوی کشویی                                          */
    /* ------------------------------------------------------------------ */
    body.has-mobile-nav { padding-top: calc(var(--mobile-appbar) + var(--safe-top)); }
    body.mobile-nav-open { overflow: hidden; }

    .mobile-appbar {
        position: fixed;
        inset: 0 0 auto 0;
        z-index: 1200;
        display: flex;
        align-items: center;
        gap: 10px;
        height: calc(var(--mobile-appbar) + var(--safe-top));
        padding: var(--safe-top) 14px 0;
        background: #fff;
        border-bottom: 1px solid #e8eef9;
        box-shadow: 0 6px 18px rgba(14, 38, 88, .08);
    }
    .mobile-appbar .ma-icon {
        display: grid;
        place-items: center;
        width: 44px;
        height: 44px;
        border: 1px solid #e3ebf9;
        border-radius: 13px;
        background: #f7faff;
        color: #16305e;
        flex: 0 0 44px;
    }
    .mobile-appbar .ma-icon svg { width: 22px; height: 22px; fill: currentColor; }
    .mobile-appbar .ma-brand {
        display: flex;
        align-items: center;
        gap: 8px;
        margin-inline-end: auto;
        font-weight: 900;
        color: #0d2b6b;
        font-size: .95rem;
        min-width: 0;
    }
    .mobile-appbar .ma-brand img { width: 30px; height: 30px; border-radius: 9px; }
    .mobile-appbar .ma-brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .mobile-appbar .ma-cart { position: relative; }
    .mobile-appbar .ma-cart .ma-cart-count {
        position: absolute;
        top: -4px;
        inset-inline-start: -4px;
        min-width: 20px;
        height: 20px;
        border-radius: 999px;
        background: #e8484f;
        color: #fff;
        font-size: .68rem;
        font-weight: 800;
        display: grid;
        place-items: center;
        padding: 0 4px;
    }
    .mobile-appbar .ma-toggle[aria-expanded="true"] { background: #1557f4; color: #fff; border-color: #1557f4; }

    .mobile-drawer {
        position: fixed;
        inset: 0 var(--drawer-inset, 0) 0 auto;
        z-index: 1300;
        width: min(88vw, 380px);
        background: #fff;
        transform: translateX(105%);
        transition: transform .28s cubic-bezier(.4, 0, .2, 1);
        display: flex;
        flex-direction: column;
        box-shadow: -18px 0 50px rgba(11, 31, 74, .18);
        padding-bottom: var(--safe-bottom);
    }
    html[dir="ltr"] .mobile-drawer { inset: 0 auto 0 0; transform: translateX(-105%); }
    .mobile-drawer.open { transform: translateX(0); }
    .mobile-drawer-head {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 14px;
        border-bottom: 1px solid #eef2fa;
        background: linear-gradient(135deg, #0d2b6b, #1557f4);
        color: #fff;
        padding-top: calc(14px + var(--safe-top));
    }
    .mobile-drawer-head img { width: 34px; height: 34px; border-radius: 10px; background: #fff; padding: 3px; }
    .mobile-drawer-head strong { font-size: .95rem; }
    .mobile-drawer-head button {
        margin-inline-start: auto;
        width: 40px;
        height: 40px;
        border: 1px solid rgba(255, 255, 255, .35);
        background: rgba(255, 255, 255, .12);
        color: #fff;
        border-radius: 12px;
        font-size: 1.1rem;
    }
    .mobile-drawer-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 10px 12px 24px; }
    .mobile-drawer-section { margin-top: 12px; }
    .mobile-drawer-section > h3 {
        font-size: .74rem;
        color: #7d8aa5;
        font-weight: 800;
        letter-spacing: .02em;
        padding: 6px 8px;
    }
    .mobile-acc { border: 1px solid #eef2fa; border-radius: 14px; margin-bottom: 8px; overflow: hidden; background: #fff; }
    .mobile-acc > summary {
        list-style: none;
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 13px 14px;
        font-weight: 800;
        font-size: .92rem;
        color: #16305e;
        cursor: pointer;
        min-height: 48px;
    }
    .mobile-acc > summary::-webkit-details-marker { display: none; }
    .mobile-acc > summary:after {
        content: "";
        margin-inline-start: auto;
        width: 9px;
        height: 9px;
        border-left: 2px solid #97a6c4;
        border-bottom: 2px solid #97a6c4;
        transform: rotate(-45deg);
        transition: transform .2s;
    }
    .mobile-acc[open] > summary:after { transform: rotate(135deg); }
    .mobile-acc .mobile-acc-links { padding: 4px 10px 12px; display: grid; gap: 2px; }
    .mobile-acc .mobile-acc-links a {
        display: block;
        padding: 11px 12px;
        border-radius: 10px;
        color: #46567a;
        font-size: .86rem;
        min-height: 44px;
    }
    .mobile-acc .mobile-acc-links a:active { background: #f2f6ff; color: #1557f4; }
    .mobile-drawer-actions { display: grid; gap: 8px; padding: 12px 4px 0; }
    .mobile-drawer-actions .btn { width: 100%; padding: 13px; }
    .mobile-drawer-actions .btn.ghost {
        background: #f5f8ff;
        color: #16305e;
        border: 1px solid #dbe6fb;
        box-shadow: none;
    }

    .mobile-backdrop {
        position: fixed;
        inset: 0;
        z-index: 1250;
        background: rgba(9, 22, 52, .48);
        opacity: 0;
        visibility: hidden;
        transition: opacity .25s;
        backdrop-filter: blur(2px);
    }
    .mobile-backdrop.show { opacity: 1; visibility: visible; }

    /* منوی دسکتاپ در موبایل پنهان می‌شود */
    body.has-mobile-nav .navbar,
    body.has-mobile-nav .sub-menu-below-nav { display: none !important; }

    /* ------------------------------------------------------------------ */
    /* ۳) نوار پایین                                                       */
    /* ------------------------------------------------------------------ */
    body.has-mobile-nav, body.has-mobile-bottom { padding-bottom: calc(var(--mobile-bottom-nav) + var(--safe-bottom) + 8px); }
    .mobile-bottom-nav {
        position: fixed;
        inset: auto 0 0 0;
        z-index: 1150;
        display: grid;
        grid-template-columns: repeat(5, 1fr);
        background: rgba(255, 255, 255, .97);
        border-top: 1px solid #e8eef9;
        box-shadow: 0 -8px 24px rgba(14, 38, 88, .09);
        padding-bottom: var(--safe-bottom);
        backdrop-filter: blur(10px);
    }
    .mobile-bottom-nav a {
        display: grid;
        place-items: center;
        gap: 3px;
        padding: 9px 2px 8px;
        min-height: 56px;
        color: #6d7b99;
        font-size: .68rem;
        font-weight: 700;
    }
    .mobile-bottom-nav a svg { width: 22px; height: 22px; fill: currentColor; }
    .mobile-bottom-nav a.active { color: #1557f4; }
    .mobile-bottom-nav a.active svg { transform: translateY(-1px); }
    .mobile-bottom-nav a .mbn-badge {
        position: absolute;
        transform: translate(-14px, -12px);
        background: #e8484f;
        color: #fff;
        border-radius: 999px;
        font-size: .6rem;
        min-width: 16px;
        height: 16px;
        display: grid;
        place-items: center;
    }

    /* ------------------------------------------------------------------ */
    /* ۴) چیدمان عمومی                                                    */
    /* ------------------------------------------------------------------ */
    .container { width: min(100% - 24px, 1180px); }
    .section { padding: 40px 0; }
    .section-header { flex-direction: column; align-items: flex-start; gap: 10px; }
    .page-hero { padding: 32px 0; }
    .hero-copy h1, .page-hero h1 { font-size: clamp(1.6rem, 6vw, 2.1rem); }
    .footer-grid { grid-template-columns: 1fr; gap: 26px; }
    .quick-grid, .product-grid, .support-grid, .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .article-grid, .home-article-grid { grid-template-columns: 1fr; }
    .home-article-grid { display: grid; gap: 18px; }
    .la-footer { text-align: center; margin-top: 26px; }
    .btn, button, .action-btn, a.btn { min-height: 44px; }
    input, select, textarea { font-size: 16px !important; }
    .toast { left: 12px; right: 12px; top: auto; bottom: calc(var(--mobile-bottom-nav) + 16px + var(--safe-bottom)); }
    /* لمس راحت‌تر برای آیتم‌های منو */
    .mobile-acc .mobile-acc-links a,
    .mobile-bottom-nav a,
    .mobile-appbar .ma-icon { touch-action: manipulation; }

    /* ------------------------------------------------------------------ */
    /* ۷) پنل کاربری و مدیریت                                             */
    /* ------------------------------------------------------------------ */
    .mobile-panel-bar {
        position: fixed;
        inset: 0 0 auto 0;
        z-index: 1200;
        display: flex;
        align-items: center;
        gap: 10px;
        height: calc(var(--mobile-appbar) + var(--safe-top));
        padding: var(--safe-top) 12px 0;
        background: #0d2b6b;
        color: #fff;
        box-shadow: 0 6px 20px rgba(9, 25, 60, .22);
    }
    .mobile-panel-bar button {
        width: 44px;
        height: 44px;
        border: 1px solid rgba(255, 255, 255, .3);
        background: rgba(255, 255, 255, .1);
        color: #fff;
        border-radius: 12px;
        font-size: 1.15rem;
    }
    .mobile-panel-bar strong { font-size: .92rem; font-weight: 800; }
    .mobile-panel-bar .mpb-back { margin-inline-start: auto; }

    body.has-panel-bar { padding-top: calc(var(--mobile-appbar) + var(--safe-top)); }

    .admin-sidebar, .user-sidebar {
        position: fixed !important;
        inset: 0 0 0 auto;
        z-index: 1300;
        width: min(84vw, 320px) !important;
        max-width: 320px;
        transform: translateX(105%);
        transition: transform .28s cubic-bezier(.4, 0, .2, 1);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 !important;
        border-radius: 0 !important;
    }
    .admin-sidebar.open, .user-sidebar.open { transform: translateX(0); }
    .admin-sidebar .sb-menu-item a span:not(.sb-badge),
    .admin-sidebar .sb-welcome,
    .admin-sidebar .sb-role,
    .admin-sidebar .sb-menu-title { display: revert !important; }
    .admin-main, .user-main, .main-content { margin-right: 0 !important; padding: 16px 14px 40px !important; }
    .top-bar { padding: 16px 14px !important; }
    .top-title h1 { font-size: 1.1rem; }
    .stats-grid, .stats-cards { grid-template-columns: 1fr; }

    /* جدول‌ها در موبایل به کارت تبدیل می‌شوند */
    .table-wrapper, .table-responsive { overflow: visible !important; border: 0 !important; background: transparent !important; }
    table:not(.prose-table):not(.mobile-keep-table) { border: 0; width: 100%; min-width: 0 !important; }
    table:not(.prose-table):not(.mobile-keep-table) thead { display: none; }
    table:not(.prose-table):not(.mobile-keep-table),
    table:not(.prose-table):not(.mobile-keep-table) tbody,
    table:not(.prose-table):not(.mobile-keep-table) tr,
    table:not(.prose-table):not(.mobile-keep-table) td { display: block; width: 100%; }
    table:not(.prose-table):not(.mobile-keep-table) tr {
        background: #fff;
        border: 1px solid #e8eef9;
        border-radius: 16px;
        padding: 12px 14px;
        margin-bottom: 12px;
        box-shadow: 0 8px 22px rgba(18, 43, 94, .06);
    }
    table:not(.prose-table):not(.mobile-keep-table) td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        border: 0 !important;
        padding: 8px 0 !important;
        min-height: 40px;
        text-align: end;
    }
    table:not(.prose-table):not(.mobile-keep-table) td + td { border-top: 1px dashed #eef2fa !important; }
    table:not(.prose-table):not(.mobile-keep-table) td:before {
        content: attr(data-label);
        flex: 0 0 auto;
        color: #7d8aa5;
        font-size: .74rem;
        font-weight: 800;
    }
    table:not(.prose-table):not(.mobile-keep-table) td[data-label=""]:before { display: none; }
    table:not(.prose-table):not(.mobile-keep-table) td .action-btns { justify-content: flex-start; }
    .article-thumb { width: 54px; height: 54px; }
    .articles-section, .users-section, .orders-section { padding: 14px !important; }
    .articles-toolbar, .toolbar { flex-direction: column; align-items: stretch; gap: 10px; }
    .articles-header { flex-direction: column; align-items: flex-start; gap: 12px; }

    /* مودال‌ها تمام‌صفحه */
    .modal, .modal-content, .modal-dialog { width: 100% !important; max-width: 100% !important; border-radius: 18px !important; }
    .modal .modal-body { max-height: 70vh; overflow-y: auto; }
}

@media (max-width: 640px) {
    body { font-size: 15px; line-height: 1.9; }
    .container { width: min(100% - 20px, 1180px); }
    .quick-grid, .product-grid, .support-grid { grid-template-columns: 1fr; }
    .hero { padding: 28px 0; }
    .hero-visual { height: 220px; }
    .visual-window { height: 190px; }
    .floating-card, .hero-trust { display: none !important; }
    .hero-actions { flex-direction: column; align-items: stretch; gap: 10px; }
    .hero-actions .btn { width: 100%; }
    .section { padding: 32px 0; }
    .section-header h2, .split-section h2, .newsletter h2 { font-size: 1.35rem; }
    .newsletter-inner { flex-direction: column-reverse; text-align: center; gap: 18px; }
    .newsletter form { flex-direction: column; }
    .newsletter input { width: 100%; }
    .nl-socials { flex-direction: column; align-items: center; }
    .footer-col { min-width: 100%; }
    .footer-bottom { padding: 16px 12px; font-size: .74rem; }
    .bs-carousel-wrapper { padding: 0 6px; }
    .bs-slide, .solution-card, .testimonial-card { flex: 0 0 100% !important; }

    /* مقالات */
    .archive-hero { padding: 22px 0 18px; }
    .archive-hero h1 { font-size: 1.35rem; }
    .article-search { flex-direction: column; }
    .article-search .btn { width: 100%; }
    .article-card-body { padding: 16px; }
    .article-hero { padding: 20px 0 26px; }
    .article-hero h1 { font-size: 1.4rem; line-height: 1.6; }
    .article-meta-list { gap: 10px; font-size: .76rem; }
    .article-share { gap: 6px; }
    .share-btn { padding: 8px 11px; font-size: .72rem; }
    .article-layout { padding: 18px 0 40px; gap: 22px; }
    .article-prose { font-size: .98rem; line-height: 2; }
    .article-prose h2 { font-size: 1.2rem; }
    .article-prose h3 { font-size: 1.05rem; }
    .author-box { flex-direction: column; align-items: flex-start; }
    .article-sidebar { grid-template-columns: 1fr; }
    .article-progress {
        position: fixed;
        top: calc(var(--mobile-appbar) + var(--safe-top));
        left: 0;
        right: 0;
        margin: 0;
        border-radius: 0;
        z-index: 1100;
    }
    .ai-answer { padding: 14px 15px; border-radius: 14px; }
    .article-toc { padding: 14px 16px; }

    /* فیلتر دسته‌بندی محصولات: نوار افقی قابل اسکرول */
    .category-list {
        display: flex !important;
        gap: 8px !important;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding: 4px 2px 10px !important;
        grid-template-columns: none !important;
        scrollbar-width: none;
    }
    .category-list::-webkit-scrollbar { display: none; }
    .category-list-item {
        flex: 0 0 auto;
        border: 1px solid #e3ebf9 !important;
        border-radius: 999px !important;
        background: #fff;
    }
    .category-list-item a {
        padding: 10px 16px !important;
        font-size: .82rem !important;
        white-space: nowrap;
    }
    .category-list-item.active, .category-list-item:hover { border-color: #1557f4 !important; }

    /* سبد خرید و پرداخت */
    .cart-item { grid-template-columns: 60px 1fr; }
    .order-summary { position: static; }
    .price-box { flex-direction: column; align-items: stretch; gap: 12px; }
    .price-box .btn { width: 100%; }

    /* فرم‌ها */
    .filters { grid-template-columns: 1fr; padding: 16px; }
    .stack-form label { font-size: .82rem; }
}

@media (min-width: 993px) {
    .mobile-appbar, .mobile-drawer, .mobile-backdrop, .mobile-bottom-nav, .mobile-panel-bar { display: none !important; }
}
