:root {
            --primary: #2563eb;
            --primary-hover: #1d4ed8;
            --bg: #f8fafc;
            --card-bg: #ffffff;
            --text: #0f172a;
            --border: #e2e8f0;
            --danger: #ef4444;
            --warning: #f59e0b;
            --sidebar-width: 200px;
        }
        * { box-sizing: border-box; font-family: 'Vazirmatn', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; }
        body { background: var(--bg); color: var(--text); margin: 0; padding: 0; direction: rtl; }
        
        .layout-wrapper { display: flex; min-height: 100vh; }
        
        /* سایدبار سمت راست */
        .sidebar { width: var(--sidebar-width); background: #1e293b; color: #fff; padding: 20px 10px; flex-shrink: 0; display: none; flex-direction: column; gap: 10px; }
        .sidebar-title { font-size: 1.1rem; font-weight: 700; text-align: center; padding-bottom: 15px; border-bottom: 1px solid #334155; margin-bottom: 10px; }
        .sidebar-menu { list-style: none; padding: 0; margin: 0; }
        .sidebar-menu li { margin-bottom: 5px; }
        .sidebar-menu button { width: 100%; text-align: right; background: transparent; color: #cbd5e1; border: none; padding: 10px 15px; border-radius: 6px; cursor: pointer; font-size: 0.9rem; font-weight: 600; transition: all 0.2s; }
        .sidebar-menu button:hover, .sidebar-menu button.active { background: var(--primary); color: #fff; }
        .sidebar-menu .has-submenu { position: relative; }
        .sidebar-menu .submenu { display: none; list-style: none; padding: 4px 12px 4px 0; margin: 2px 10px 2px 0; border-right: 2px solid #334155; }
        .sidebar-menu .has-submenu:hover > .submenu, .sidebar-menu .has-submenu:focus-within > .submenu { display: block; }
        .sidebar-menu .submenu li { margin-bottom: 3px; }
        .sidebar-menu .submenu button { font-size: 0.82rem; padding: 8px 12px; font-weight: 500; }
        .settings-sub-tabs { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
        .settings-sub-tabs button { background: #f1f5f9; color: #334155; border: 1px solid var(--border); padding: 8px 18px; border-radius: 8px; cursor: pointer; font-size: 0.85rem; font-weight: 700; }
        .settings-sub-tabs button.active { background: var(--primary); color: #fff; border-color: var(--primary); }

        .main-content { flex: 1; padding: 15px; overflow-x: hidden; }
        .container { max-width: 100%; margin: 0 auto; }
        
        .header-bar { display: flex; justify-content: space-between; align-items: center; background: #fff; padding: 10px 20px; border-radius: 10px; border: 1px solid var(--border); margin-bottom: 15px; }
        .user-info { font-weight: 600; font-size: 0.9rem; color: #334155; }
        .header-actions { display: flex; gap: 8px; align-items: center; }
        .btn-change-pass { background: #64748b; color: #fff; border: none; padding: 6px 14px; border-radius: 6px; cursor: pointer; font-weight: 600; font-size: 0.8rem; }
        .btn-change-pass:hover { background: #475569; }
        .btn-logout { background: var(--danger); color: #fff; border: none; padding: 6px 14px; border-radius: 6px; cursor: pointer; font-weight: 600; font-size: 0.8rem; }
        .btn-logout:hover { background: #dc2626; }

        .card { background: var(--card-bg); padding: 15px 20px; border-radius: 10px; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05); margin-bottom: 15px; border: 1px solid var(--border); }
        h2 { margin-top: 0; font-size: 1.1rem; border-bottom: 2px solid #f1f5f9; padding-bottom: 8px; margin-bottom: 12px; color: #1e293b; font-weight: 700; }
        
        .horizontal-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; }
        .form-group { display: flex; flex-direction: column; flex: 1; min-width: 110px; }
        .form-group.sm { flex: 0.7; min-width: 80px; }
        .form-group.lg { flex: 1.5; min-width: 150px; }
        
        .form-group label { font-size: 0.78rem; margin-bottom: 4px; font-weight: 600; color: #475569; white-space: nowrap; }
        .form-group input, .form-group select, .form-group textarea { padding: 7px 9px; border: 1px solid #cbd5e1; border-radius: 6px; outline: none; font-size: 0.85rem; height: 36px; transition: border 0.2s; }
        .form-group textarea { height: auto; }
        .form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: var(--primary); }
        
        .checkbox-group { display: flex; align-items: center; gap: 12px; height: 36px; padding: 0 10px; background: #f1f5f9; border-radius: 6px; border: 1px solid #e2e8f0; flex-wrap: wrap; }
        .checkbox-item { display: flex; align-items: center; gap: 4px; cursor: pointer; font-size: 0.8rem; font-weight: 600; color: #334155; white-space: nowrap; }
        .checkbox-item input { width: 15px; height: 15px; cursor: pointer; margin: 0; }
        
        .total-display { height: 36px; display: flex; align-items: center; font-size: 0.9rem; font-weight: 700; color: #1e3a8a; background: #eff6ff; padding: 0 12px; border-radius: 6px; border: 1px dashed #bfdbfe; white-space: nowrap; }
        
        .form-actions { display: flex; gap: 6px; }
        .btn-submit { background: var(--primary); color: #fff; border: none; padding: 0 16px; height: 36px; border-radius: 6px; cursor: pointer; font-weight: 600; font-size: 0.85rem; transition: background 0.2s; white-space: nowrap; }
        .btn-submit:hover { background: var(--primary-hover); }
        .btn-cancel-edit { background: #64748b; color: #fff; border: none; padding: 0 12px; height: 36px; border-radius: 6px; cursor: pointer; font-weight: 600; font-size: 0.85rem; display: none; white-space: nowrap; }

        .stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 15px; }
        .stat-card { background: #fff; padding: 12px; border-radius: 8px; text-align: center; border: 1px solid var(--border); box-shadow: 0 2px 4px rgba(0,0,0,0.02); }
        .stat-card h3 { margin: 0; font-size: 0.8rem; color: #64748b; font-weight: 600; }
        .stat-card p { margin: 4px 0 0 0; font-size: 1.4rem; font-weight: 700; }
        .stat-card.total p { color: #2563eb; }
        .stat-card.pending p { color: #d97706; }
        .stat-card.delivered p { color: #16a34a; }

        .table-controls { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
        .table-controls input { flex: 2; min-width: 180px; padding: 7px 10px; border: 1px solid #cbd5e1; border-radius: 6px; font-size: 0.85rem; }
        .table-controls select { flex: 1; min-width: 140px; padding: 7px 10px; border: 1px solid #cbd5e1; border-radius: 6px; font-size: 0.85rem; }
        .count-badge { background:#e2e8f0; color:#334155; border-radius:999px; padding:1px 8px; font-size:0.72rem; margin-right:6px; }
        .settings-grid { display:grid; grid-template-columns: 1fr 1fr; gap:12px; }
        .settings-table-wrapper { max-height: 380px; overflow:auto; border:1px solid #e2e8f0; border-radius:8px; }
        .settings-table-wrapper table { margin:0; }
        @media (max-width: 900px){ .settings-grid{ grid-template-columns: 1fr; } }
        
        .table-responsive { width: 100%; overflow-x: auto; }
        table { width: 100%; border-collapse: collapse; text-align: right; font-size: 0.75rem; table-layout: auto; }
        th, td { padding: 8px 6px; border-bottom: 1px solid #e2e8f0; vertical-align: middle; word-wrap: normal; white-space: nowrap; }
        th { background: #f8fafc; color: #475569; font-weight: 700; }
        
        tbody tr { cursor: pointer; user-select: none; transition: background 0.15s; }
        tbody tr:hover { background: #f1f5f9; }
        tbody tr.selected-row { background: #dbeafe !important; border-color: #93c5fd; }

        .badge { display: inline-block; padding: 2px 5px; border-radius: 4px; font-size: 0.68rem; font-weight: 600; text-align: center; white-space: nowrap; }
        .badge-paid { background: #dcfce7; color: #15803d; }
        .badge-unpaid { background: #fee2e2; color: #b91c1c; }

        .context-menu {
            display: none;
            position: fixed;
            z-index: 10000;
            background: #ffffff;
            border: 1px solid #cbd5e1;
            border-radius: 8px;
            box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.15), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
            min-width: 170px;
            padding: 5px 0;
            animation: contextMenuFade 0.12s ease-out;
        }

        @keyframes contextMenuFade {
            from { opacity: 0; transform: scale(0.95); }
            to { opacity: 1; transform: scale(1); }
        }

        .context-menu-item {
            display: flex;
            align-items: center;
            gap: 8px;
            padding: 8px 14px;
            font-size: 0.82rem;
            font-weight: 600;
            color: #334155;
            cursor: pointer;
            transition: background 0.15s, color 0.15s;
        }
        .context-menu-item:hover { background: #f1f5f9; color: var(--primary); }
        .context-menu-item.danger { color: #dc2626; }
        .context-menu-item.danger:hover { background: #fee2e2; color: #991b1b; }

        .modal { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(15, 23, 42, 0.6); align-items: center; justify-content: center; z-index: 1000; backdrop-filter: blur(2px); }
        .modal-content { background: #fff; padding: 20px; border-radius: 10px; max-width: 800px; width: 90%; text-align: right; box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1); display: flex; flex-direction: column; }
        
        #invoiceModal .modal-content {
            max-width: 850px;
            max-height: 90vh;
            overflow-y: auto;
        }

        /* باشگاه مشتریان — پیشنهاد نام */
        .cust-suggest { position:absolute; top:100%; right:0; left:0; z-index:30; background:#fff; border:1px solid #cbd5e1; border-radius:8px; box-shadow:0 8px 20px rgba(0,0,0,0.12); overflow:hidden; margin-top:4px; }
        .cust-suggest-item { padding:9px 12px; cursor:pointer; display:flex; justify-content:space-between; align-items:center; gap:8px; font-size:0.88rem; border-bottom:1px solid #f1f5f9; }
        .cust-suggest-item:last-child { border-bottom:none; }
        .cust-suggest-item:hover, .cust-suggest-item.active { background:#eff6ff; color:#1e40af; }
        .cust-suggest-name { font-weight:700; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
        .cust-suggest-phone { color:#64748b; font-size:0.82rem; direction:ltr; white-space:nowrap; }

        .modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 15px; }
        .btn-cancel { background: #64748b; color: #fff; border: none; padding: 8px 16px; border-radius: 6px; cursor: pointer; font-weight: 600; }
        .btn-pay { background: #16a34a; color: #fff; border: none; padding: 8px 16px; border-radius: 6px; cursor: pointer; font-weight: 600; }
        .btn-print { background: #2563eb; color: #fff; border: none; padding: 8px 16px; border-radius: 6px; cursor: pointer; font-weight: 600; }

        .login-card { max-width: 400px; margin: 80px auto; background: #fff; padding: 30px; border-radius: 12px; box-shadow: 0 10px 25px rgba(0,0,0,0.1); border: 1px solid var(--border); }
        .login-card h2 { text-align: center; border: none; font-size: 1.4rem; margin-bottom: 20px; font-weight: 700; }
        .login-field { margin-bottom: 15px; }
        .login-field label { display: block; margin-bottom: 5px; font-weight: 600; font-size: 0.85rem; color: #475569; }
        .login-field input { width: 100%; padding: 10px; border: 1px solid #cbd5e1; border-radius: 6px; font-size: 0.9rem; outline: none; }
        .login-field input:focus { border-color: var(--primary); }
        .btn-login { width: 100%; background: var(--primary); color: #fff; border: none; padding: 10px; border-radius: 6px; font-weight: 600; font-size: 0.95rem; cursor: pointer; transition: background 0.2s; }
        .btn-login:hover { background: var(--primary-hover); }
        .login-error { color: var(--danger); font-size: 0.85rem; text-align: center; margin-top: 10px; display: none; }

        .settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
        .settings-table-wrapper { overflow-x: auto; margin-top: 10px; }
        .inline-form { display: flex; gap: 8px; margin-bottom: 10px; align-items: flex-end; }
        .inline-form .form-group { margin: 0; }

        #invoicePrintArea {
            font-size: 12px;
            color: #1e293b;
            line-height: 1.5;
            padding: 30px;
            background: #fff;
            border: 1px solid #cbd5e1;
            border-radius: 8px;
            max-width: 100%;
            margin: 0 auto;
            box-shadow: 0 1px 3px rgba(0,0,0,0.05);
        }
        .invoice-header-box {
            display: flex;
            justify-content: space-between;
            align-items: flex-start;
            border-bottom: 2px solid #1e293b;
            padding-bottom: 15px;
            margin-bottom: 20px;
        }
        .invoice-title-main {
            font-size: 1.6rem;
            font-weight: 800;
            color: #0f172a;
            margin-bottom: 12px;
            letter-spacing: -0.5px;
        }
        .invoice-info-card {
            background: #f8fafc;
            border: 1px solid #e2e8f0;
            border-radius: 6px;
            padding: 10px 14px;
            font-size: 0.85rem;
            display: flex;
            flex-direction: column;
            gap: 4px;
        }
        .invoice-info-card div { display: flex; justify-content: space-between; gap: 15px; }
        .invoice-customer-box {
            background: #f1f5f9;
            border: 1px solid #cbd5e1;
            border-radius: 6px;
            padding: 10px 15px;
            margin-bottom: 20px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            font-size: 0.9rem;
            font-weight: 600;
        }
        .invoice-table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 10px;
            margin-bottom: 20px;
            table-layout: auto;
        }
        .invoice-table th, .invoice-table td {
            border: 1px solid #cbd5e1 !important;
            padding: 8px 6px;
            text-align: center;
            font-size: 0.8rem;
            white-space: nowrap;
        }
        .invoice-table th {
            background-color: #f1f5f9 !important;
            color: #1e293b !important;
            font-weight: 700;
        }
        .invoice-table tfoot td {
            background-color: #f8fafc;
        }
        .invoice-footer-box {
            display: flex;
            justify-content: space-between;
            align-items: flex-end;
            margin-top: 30px;
            padding-top: 20px;
            border-top: 1px dashed #cbd5e1;
        }
        .invoice-signatures {
            display: flex;
            justify-content: left;
            width: 100%;
            margin-top: 40px;
            padding: 0 30px;
            font-size: 0.85rem;
            font-weight: 600;
            color: #475569;
        }

        @page {
            size: A4 portrait;
            margin: 0;
        }

        @media print {
            html, body {
                margin: 0 !important;
                padding: 0 !important;
                background: #fff !important;
            }
            body > :not(#invoiceModal) {
                display: none !important;
            }
            
            #invoiceModal,
            #invoiceModal * {
                visibility: visible;
            }
            #invoiceModal {
                position: absolute !important;
                left: 0 !important;
                top: 0 !important;
                width: 100% !important;
                height: auto !important;
                background: white !important;
                margin: 0 !important;
                padding: 0 !important;
            }
            #invoiceModal .modal-content {
                max-height: none !important;
                overflow: visible !important;
                width: 100% !important;
                max-width: 100% !important;
                padding: 10mm !important;
                border: none !important;
                box-shadow: none !important;
            }
            .modal-actions, .context-menu { display: none !important; }
            #invoicePrintArea { border: none !important; padding: 0 !important; box-shadow: none !important; }
        }

        /* ── Toast (جایگزین alert) — شیشه‌ای رنگی، بالا وسط همیشه دیده می‌شود ── */
        .toast-container {
            position: fixed;
            top: 14px;
            left: 50%;
            transform: translateX(-50%);
            z-index: 10000;
            display: flex;
            flex-direction: column;
            gap: 10px;
            pointer-events: none;
            width: min(440px, calc(100vw - 20px));
            align-items: stretch;
        }
        .toast {
            pointer-events: auto;
            display: flex;
            align-items: center;
            gap: 12px;
            padding: 12px 14px 14px 12px;
            border-radius: 16px;
            font-size: 0.88rem;
            font-weight: 700;
            line-height: 1.55;
            color: #0f172a;
            background: rgba(255,255,255,0.82);
            backdrop-filter: blur(16px) saturate(165%);
            -webkit-backdrop-filter: blur(16px) saturate(165%);
            border: 1px solid rgba(255,255,255,0.65);
            box-shadow: 0 12px 36px rgba(15,23,42,0.14), 0 4px 12px rgba(15,23,42,0.08), inset 0 1px 0 rgba(255,255,255,0.75);
            animation: toastIn 0.38s cubic-bezier(0.16,1,0.3,1);
            word-break: break-word;
            position: relative;
            overflow: hidden;
        }
        .toast::before {
            content: "";
            position: absolute;
            inset: 0;
            border-radius: inherit;
            background: linear-gradient(135deg, rgba(255,255,255,0.55) 0%, transparent 55%);
            pointer-events: none;
            opacity: 0.9;
        }
        .toast.toast-success {
            background: linear-gradient(135deg, rgba(220,252,231,0.92), rgba(187,247,208,0.88));
            border-color: rgba(22,163,74,0.20);
            color: #14532d;
        }
        .toast.toast-error {
            background: linear-gradient(135deg, rgba(254,226,226,0.94), rgba(254,205,211,0.88));
            border-color: rgba(220,38,38,0.18);
            color: #7f1d1d;
        }
        .toast.toast-warning {
            background: linear-gradient(135deg, rgba(254,249,195,0.95), rgba(253,230,138,0.88));
            border-color: rgba(245,158,11,0.22);
            color: #78350f;
        }
        .toast.toast-info {
            background: linear-gradient(135deg, rgba(219,234,254,0.94), rgba(191,219,254,0.88));
            border-color: rgba(37,99,235,0.18);
            color: #1e3a5f;
        }
        .toast-icon {
            flex-shrink: 0;
            width: 34px;
            height: 34px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 1.05rem;
            line-height: 1;
            color: #fff;
            box-shadow: 0 4px 14px rgba(0,0,0,0.18), inset 0 1px 0 rgba(255,255,255,0.4);
            position: relative;
            z-index: 1;
        }
        .toast-success .toast-icon { background: linear-gradient(135deg, #16a34a, #15803d); }
        .toast-error   .toast-icon { background: linear-gradient(135deg, #ef4444, #dc2626); }
        .toast-warning .toast-icon { background: linear-gradient(135deg, #f59e0b, #d97706); }
        .toast-info    .toast-icon { background: linear-gradient(135deg, #3b82f6, #2563eb); }
        .toast-msg { flex: 1; position: relative; z-index: 1; }
        .toast-close {
            flex-shrink: 0;
            width: 28px;
            height: 28px;
            border-radius: 50%;
            background: rgba(15,23,42,0.08);
            border: 1px solid rgba(15,23,42,0.06);
            cursor: pointer;
            font-size: 1.05rem;
            line-height: 1;
            color: #475569;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.18s;
            position: relative;
            z-index: 1;
        }
        .toast-close:hover { background: rgba(15,23,42,0.14); color: #0f172a; transform: scale(1.05); }
        .toast-progress {
            position: absolute;
            bottom: 0;
            right: 0;
            left: 0;
            height: 3.5px;
            background: currentColor;
            opacity: 0.28;
            transform-origin: right center;
            animation: toastProgress linear forwards;
        }
        @keyframes toastIn {
            from { opacity: 0; transform: translateY(-16px) scale(0.96); filter: blur(4px); }
            to   { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); }
        }
        @keyframes toastOut {
            from { opacity: 1; transform: translateY(0) scale(1); }
            to   { opacity: 0; transform: translateY(-10px) scale(0.98); filter: blur(2px); }
        }
        @keyframes toastProgress {
            from { transform: scaleX(1); }
            to   { transform: scaleX(0); }
        }
        @media (max-width: 480px) {
            .toast-container { top: 10px; width: calc(100vw - 16px); }
            .toast { padding: 11px 12px 13px 10px; font-size: 0.84rem; }
            .toast-icon { width: 30px; height: 30px; font-size: 0.95rem; }
        }
        /* آمار ماهانه */
.monthly-stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 15px;
}

.monthly-stats-grid .stat-card {
    min-width: 0;
    overflow-wrap: anywhere;
}

.monthly-stats-grid .stat-card p {
    font-size: 1.15rem;
    margin-bottom: 0;
}

.monthly-stats-controls {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.monthly-stats-controls label {
    font-size: 0.88rem;
    font-weight: 600;
    color: #334155;
}

.monthly-stats-controls select {
    min-width: 140px;
    max-width: 100%;
}

.monthly-comparison {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    line-height: 1.9;
}

.monthly-comparison-change {
    font-weight: 700;
    color: #2563eb;
}

#tabMonthlyStats .table-responsive {
    max-width: 100%;
    overflow-x: auto;
}

#tabMonthlyStats table {
    width: 100%;
}

@media (max-width: 900px) {
    .monthly-stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .monthly-comparison {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .monthly-stats-grid {
        grid-template-columns: 1fr;
    }

    .monthly-stats-controls {
        align-items: stretch;
        flex-direction: column;
    }

    .monthly-stats-controls select,
    .monthly-stats-controls button {
        width: 100%;
    }
}