/* گپیار پلاس — موبایل‌فرندلی */

@media (max-width: 991.98px) {
    body.gp-has-panel {
        padding-top: 3.25rem;
        padding-bottom: calc(4.25rem + env(safe-area-inset-bottom, 0px));
    }

    #gpGlobalTopbar.gp-mobile-topbar {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        margin: 0;
        z-index: 1030;
        display: flex !important;
    }

    body.gp-has-panel .gp-main {
        padding: 0.85rem 0.75rem 1rem;
        width: 100%;
        max-width: 100%;
        flex: 0 0 100%;
    }

    body.gp-has-panel .container-fluid {
        padding-left: 0;
        padding-right: 0;
    }

    body.gp-has-panel .container-fluid > .row {
        margin-left: 0;
        margin-right: 0;
    }

    /* سایدبار: کاملاً مخفی وقتی بسته است — نه لبه‌ی دیده‌شده */
    body.gp-has-panel .gp-sidebar.col-lg-2 {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        left: auto;
        width: min(320px, 92vw) !important;
        max-width: 92vw !important;
        flex: none !important;
        padding: 0 !important;
        margin: 0 !important;
        z-index: 1055;
        display: flex !important;
        flex-direction: column;
        height: 100vh;
        height: 100dvh;
        max-height: 100dvh;
        min-height: 0 !important;
        overflow: hidden;
        transform: translateX(100%);
        visibility: hidden;
        pointer-events: none;
        transition: transform 0.28s ease, visibility 0.28s;
        box-shadow: none;
        border-left: 1px solid var(--gp-border);
        -webkit-overflow-scrolling: touch;
    }

    body.gp-has-panel .gp-sidebar.show {
        transform: translateX(0);
        visibility: visible;
        pointer-events: auto;
        box-shadow: -8px 0 32px rgba(15, 23, 42, 0.2);
    }

    .gp-sidebar-close {
        display: flex;
        align-items: center;
        justify-content: space-between;
        flex-shrink: 0;
        padding: 0.85rem 1rem;
        border-bottom: 1px solid var(--gp-border);
        font-weight: 600;
        color: var(--gp-text);
        font-size: 0.9rem;
        background: #fff;
    }

    .gp-sidebar-close button {
        min-width: 2.5rem;
        min-height: 2.5rem;
        font-size: 1.1rem;
        line-height: 1;
    }

    .gp-sidebar-brand {
        flex-shrink: 0;
        margin-bottom: 0 !important;
    }

    /* ناحیه اسکرول منو */
    .gp-sidebar-scroll {
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        touch-action: pan-y;
        padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    }

    .gp-sidebar .nav-link {
        padding: 0.85rem 1rem;
        margin: 0.1rem 0.5rem;
        font-size: 0.95rem;
        min-height: 2.75rem;
        display: flex;
        align-items: center;
    }

    .gp-sidebar .nav.flex-column {
        padding-bottom: 0.5rem;
    }

    .gp-sidebar-logout {
        flex-shrink: 0;
        padding: 0.75rem 1rem 1rem;
        border-top: 1px solid var(--gp-border);
        background: #fff;
    }

    body.gp-sidebar-open {
        overflow: hidden;
    }

    /* نوار بالا */
    .gp-mobile-topbar {
        display: flex;
        align-items: center;
        gap: 0.65rem;
        min-height: 3.25rem;
        padding: 0.5rem 0.75rem;
        background: rgba(255, 255, 255, 0.96);
        backdrop-filter: blur(10px);
        border-bottom: 1px solid var(--gp-border);
        box-shadow: 0 2px 12px rgba(15, 23, 42, 0.06);
    }

    .gp-mobile-topbar-title {
        flex: 1;
        font-weight: 700;
        font-size: 0.95rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        margin: 0;
    }

    .gp-mobile-menu-btn {
        flex-shrink: 0;
        width: 2.75rem;
        height: 2.75rem;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border-radius: 12px;
        border: 1px solid var(--gp-border);
        background: #fff;
        color: var(--gp-text);
        font-size: 1.25rem;
        padding: 0;
    }

    .gp-sidebar-backdrop {
        backdrop-filter: blur(2px);
    }

    /* نوار پایین */
    .gp-mobile-bottom {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1040;
        display: flex;
        justify-content: space-around;
        align-items: stretch;
        gap: 0.15rem;
        padding: 0.35rem 0.4rem calc(0.35rem + env(safe-area-inset-bottom, 0px));
        background: rgba(255, 255, 255, 0.96);
        backdrop-filter: blur(12px);
        border-top: 1px solid var(--gp-border);
        box-shadow: 0 -4px 20px rgba(15, 23, 42, 0.08);
    }

    .gp-mobile-bottom a,
    .gp-mobile-bottom button {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 0.15rem;
        min-height: 3.25rem;
        max-width: 5.5rem;
        border: none;
        background: transparent;
        color: var(--gp-muted);
        text-decoration: none;
        font-size: 0.65rem;
        font-weight: 600;
        border-radius: 12px;
        padding: 0.25rem 0.15rem;
    }

    .gp-mobile-bottom a.active,
    .gp-mobile-bottom button.active {
        color: var(--gp-primary);
        background: rgba(79, 70, 229, 0.08);
    }

    .gp-mobile-bottom .gp-mb-icon {
        font-size: 1.15rem;
        line-height: 1;
    }

    .gp-page-title { font-size: 1.2rem; }
    .gp-page-subtitle { font-size: 0.82rem; }
    .gp-card { border-radius: 12px; }
    .gp-card.p-4, .gp-card.p-5 { padding: 1rem !important; }
    .stat-value { font-size: 1.25rem; }

    .gp-page-header,
    main > .d-flex.justify-content-between,
    main > .d-flex.flex-wrap.justify-content-between {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0.75rem !important;
    }

    .gp-page-header .btn,
    main > .d-flex.justify-content-between > .btn,
    main > .d-flex.justify-content-between .btn-gp,
    main > .d-flex.flex-wrap .btn-gp {
        width: 100%;
        justify-content: center;
    }

    .form-control, .form-select, .form-control-lg {
        font-size: 16px !important;
        min-height: 48px;
    }

    .form-control-sm {
        font-size: 16px !important;
        min-height: 44px;
    }

    textarea.form-control { min-height: 6rem; }

    .btn, .btn-gp {
        min-height: 44px;
        padding-top: 0.55rem;
        padding-bottom: 0.55rem;
    }

    .btn-sm { min-height: 38px; }

    .input-group { flex-wrap: wrap; }
    .input-group > .form-control {
        width: 100%;
        border-radius: 10px !important;
        margin-bottom: 0.5rem;
    }
    .input-group > .btn {
        width: 100%;
        border-radius: 10px !important;
    }

    .gp-mobile-table { border: 0; }
    .gp-mobile-table thead { display: none; }
    .gp-mobile-table tbody tr {
        display: block;
        margin-bottom: 0.75rem;
        padding: 0.85rem;
        background: #f8fafc;
        border: 1px solid var(--gp-border);
        border-radius: 12px;
    }
    .gp-mobile-table tbody td {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: 0.75rem;
        padding: 0.35rem 0;
        border: 0;
    }
    .gp-mobile-table tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        font-size: 0.75rem;
        color: var(--gp-muted);
        flex-shrink: 0;
        max-width: 42%;
    }
    .gp-mobile-table tbody td[data-label=""]::before,
    .gp-mobile-table tbody td:not([data-label])::before { display: none; }
    .gp-mobile-table tbody td.gp-td-actions {
        flex-direction: column;
        align-items: stretch;
        padding-top: 0.65rem;
        margin-top: 0.35rem;
        border-top: 1px dashed var(--gp-border);
    }
    .gp-mobile-table tbody td.gp-td-actions::before { display: none; }
    .gp-mobile-table tbody td.gp-td-actions .btn { width: 100%; margin: 0.15rem 0; }
    .gp-mobile-table tbody td.gp-td-actions form { display: block; width: 100%; }

    .table-responsive {
        -webkit-overflow-scrolling: touch;
    }

    .btn-group { display: flex; flex-wrap: wrap; width: 100%; }
    .btn-group .btn { flex: 1; min-width: 0; }

    .home-header { padding-left: 1rem !important; padding-right: 1rem !important; }
    .home-header .btn-lg { width: 100%; font-size: 1rem; }
    .org-portal-logo-wrap { width: 56px !important; height: 56px !important; }
    .org-portal-card-inner { padding: 0.85rem 0.65rem !important; }

    .signup-page .container { padding-left: 0.75rem; padding-right: 0.75rem; }
    .signup-page .gp-card.p-md-5 { padding: 1rem !important; }

    .container.py-4, .container.py-5 {
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
        padding-top: 1.25rem !important;
        padding-bottom: 1.5rem !important;
    }

    .container .d-flex.flex-wrap.gap-2 .btn,
    .container .d-flex.flex-wrap.gap-2 form { width: 100%; }
    .container .d-flex.flex-wrap.gap-2 form .btn { width: 100%; }

    .gp-auth-wrap {
        padding: 1rem 0.75rem;
        align-items: flex-start;
        padding-top: 2rem;
    }
    .gp-auth-card { max-width: 100%; }

    #chartWrap canvas { max-height: 260px; }
    .datepicker-plot-area { z-index: 1060 !important; max-width: 96vw; }
    .notyf { max-width: calc(100vw - 1.5rem); }

    .pagination { flex-wrap: wrap; justify-content: center; gap: 0.25rem; }
    .pagination .page-link {
        min-width: 2.5rem;
        min-height: 2.5rem;
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

@media (max-width: 575.98px) {
    .row.g-2 > [class*="col-md"],
    .item-row > [class*="col-md"] {
        flex: 0 0 100%;
        max-width: 100%;
    }
    .gp-mobile-table tbody td {
        flex-direction: column;
        align-items: stretch;
        gap: 0.2rem;
    }
    .gp-mobile-table tbody td::before { max-width: 100%; }
}

@media (min-width: 992px) {
    .gp-mobile-topbar,
    .gp-mobile-bottom,
    .gp-sidebar-close,
    .gp-sidebar-scroll,
    .gp-sidebar-logout { display: contents; }
}
