/* ============ رسپانسیو — چیدمان و موبایل ============ */

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 900;
    background: var(--overlay-bg);
    opacity: 0;
    transition: opacity .25s ease;
    pointer-events: none;
}
.sidebar-backdrop.is-visible {
    display: block;
    opacity: 1;
    pointer-events: auto;
}

.topbar {
    flex-wrap: wrap;
    gap: 12px;
}
.topbar-start {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    flex: 1;
}
.topbar-end {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}
.topbar h1 {
    font-size: clamp(17px, 4vw, 22px);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.topbar-date {
    font-size: 12px;
    white-space: nowrap;
}

.icon-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    flex-shrink: 0;
    transition: background .15s, border-color .15s;
}
.icon-btn:hover { border-color: var(--primary); color: var(--primary); }
.icon-btn svg { width: 22px; height: 22px; }

/* --- تبلت --- */
@media (max-width: 1100px) {
    .main { padding: 20px 18px; }
    .card { padding: 18px; }
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .grid-2 { grid-template-columns: 1fr; }
    .field-row { grid-template-columns: 1fr; }

    #users-table col.subs-col-expired,
    #users-table .subs-col-expired-head,
    #users-table .users-cell-expired {
        display: none;
    }
    #users-table.users-data-table {
        min-width: 700px;
        width: max(100%, 700px);
    }
}

/* --- موبایل / تبلت کوچک: سایدبار کشویی --- */
@media (max-width: 900px) {
    .icon-btn.mobile-menu-btn { display: inline-flex; }

    .app { position: relative; }

    .sidebar {
        position: fixed;
        top: 0;
        right: 0;
        z-index: 950;
        width: min(280px, 88vw);
        height: 100vh;
        height: 100dvh;
        transform: translateX(100%);
        transition: transform .28s cubic-bezier(.4, 0, .2, 1);
        box-shadow: -8px 0 40px rgba(0, 0, 0, 0.2);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    .sidebar.is-open { transform: translateX(0); }

    .main {
        width: 100%;
        padding: 14px 14px 24px;
        min-height: 100vh;
        min-height: 100dvh;
    }

    #users-table col.subs-col-simul,
    #users-table .subs-col-simul-head,
    #users-table .users-cell-simul,
    #users-table col.subs-col-id,
    #users-table .subs-col-id-head,
    #users-table .users-cell-id {
        display: none;
    }
    #users-table.users-data-table {
        min-width: 680px;
        width: max(100%, 680px);
    }

    .topbar { margin-bottom: 14px; }
    .topbar-date { display: none; }

    .content { min-width: 0; }

    /* کارت‌ها */
    .card { padding: 16px; margin-bottom: 14px; border-radius: 12px; }
    .card-header {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    .card-header h2 { font-size: 15px; }

    /* جدول — اسکرول افقی */
    .table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -4px;
        padding: 0 4px;
    }
    .table-wrap table:not(.users-data-table) { min-width: 640px; }

    /* دکمه‌ها */
    .btn-row { flex-direction: column; align-items: stretch; }
    .btn-row .btn { width: 100%; justify-content: center; }
    .users-header-actions { justify-content: stretch; width: 100%; }
    .users-header-actions .btn { flex: 1; min-width: 0; }

    /* فیلترها */
    .inv-filter-bar,
    .subs-filter-bar,
    .um-filter-bar,
    .sms-logs-filter-bar {
        margin-left: 0 !important;
        margin-right: 0 !important;
        padding: 12px !important;
    }
    .sms-logs-bulk-bar {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    /* مودال تمام‌عرض */
    .modal-overlay { padding: 0; align-items: flex-end; }
    .modal-card {
        max-width: none;
        width: 100%;
        max-height: 92vh;
        max-height: 92dvh;
        border-radius: 20px 20px 0 0;
        margin: 0;
    }

    /* تب‌های مدیریت کاربر */
    .users-manage-tabs { grid-template-columns: 1fr !important; }
    .um-tab { padding: 12px 14px; }

    /* داشبورد */
    .dash-grid--6,
    .dash-grid--3,
    .stat-grid { grid-template-columns: 1fr; }
    .dash-hero { flex-direction: column; padding: 18px; }
    .dash-hero-date { width: 100%; text-align: right; }

    /* یادآوری */
    .rem-tpl-grid { grid-template-columns: 1fr; }

    /* inline form */
    .inline-form { flex-direction: column; }
}

@media (max-width: 640px) {
    .main { padding: 12px 12px 20px; }

    .topbar-end .topbar-date { display: none; }
    .topbar-profile-name { display: none; }
    .topbar-profile { padding: 4px; border-radius: 12px; max-width: none; }

    .alert { font-size: 13px; padding: 11px 14px; }

    .pagination-wrap { flex-direction: column; align-items: stretch; gap: 10px; }
    .pagination { justify-content: center; flex-wrap: wrap; }
    .pagination-meta { text-align: center; font-size: 12.5px; }

    .login-card { padding: 28px 22px; border-radius: 18px; }
    .login-title { font-size: 18px; }

    .users-search-wrap { flex-direction: column; align-items: stretch; }
    .users-live-input { max-width: none; min-width: 0; width: 100%; }
    .users-per-page { width: 100%; justify-content: space-between; }

    .sms-logs-header { flex-direction: column; align-items: stretch; }
    .sms-logs-stats { justify-content: flex-start; }
    .sms-logs-clear-form .btn { width: 100%; }

    .inv-card-header { flex-direction: column; align-items: stretch; gap: 8px; }
    .inv-sum-badge { text-align: center; }

    .subs-card-header { flex-direction: column; align-items: stretch; }

    .modal-header h2 { font-size: 16px; }
    .modal-body { padding: 16px; }
    .modal-footer { flex-direction: column-reverse; gap: 8px; }
    .modal-footer .btn { width: 100%; }

    .um-svc-reminder-wrap-wide { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .um-svc-reminder-table-wide { min-width: 560px; }

    .code-block { font-size: 11px; padding: 10px 12px; }

    .field > span { font-size: 12.5px; }
    input[type="text"], input[type="password"], input[type="number"], input[type="search"],
    select, textarea {
        font-size: 16px; /* جلوگیری از zoom در iOS */
    }
}

@media (max-width: 400px) {
    .theme-toggle,
    .icon-btn { width: 38px; height: 38px; border-radius: 10px; }
    .topbar h1 { font-size: 16px; }
}

/* جلوگیری از scroll بدن وقتی منو باز است */
body.sidebar-open { overflow: hidden; }
