@font-face {
    font-family: 'Vazirmatn';
    font-style: normal;
    font-weight: 100;
    font-display: swap;
    src: url('/assets/vendor/fonts/vazirmatn/vazirmatn-arabic-100-normal.woff2') format('woff2');
}

@font-face {
    font-family: 'Vazirmatn';
    font-style: normal;
    font-weight: 300;
    font-display: swap;
    src: url('/assets/vendor/fonts/vazirmatn/vazirmatn-arabic-300-normal.woff2') format('woff2');
}

@font-face {
    font-family: 'Vazirmatn';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url('/assets/vendor/fonts/vazirmatn/vazirmatn-arabic-400-normal.woff2') format('woff2');
}

@font-face {
    font-family: 'Vazirmatn';
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url('/assets/vendor/fonts/vazirmatn/vazirmatn-arabic-600-normal.woff2') format('woff2');
}

@font-face {
    font-family: 'Vazirmatn';
    font-style: normal;
    font-weight: 800;
    font-display: swap;
    src: url('/assets/vendor/fonts/vazirmatn/vazirmatn-arabic-800-normal.woff2') format('woff2');
}

:root {
    /* Dark Theme (Default) */
    --bg-main: #0f172a;
    --bg-panel: #111827;
    --bg-card: #1f2937;
    --text-primary: #f8fafc;
    --text-secondary: #9ca3af;
    --border-color: #1f2937;
    --input-bg: #1e293b;
    --input-border: #334155;
    --glass-bg: rgba(30, 41, 59, 0.8);
    --glass-border: rgba(255,255,255,0.05);
    --bg-image: url('/assets/img/dark-matter.png');
    --primary-gradient-start: #ca8a04;
    --primary-gradient-end: #eab308;
    --accent-color: #eab308;
}

body.light-theme {
    /* Light Theme */
    --bg-main: #f1f5f9;
    --bg-panel: #ffffff;
    --bg-card: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --border-color: #e2e8f0;
    --input-bg: #ffffff;
    --input-border: #cbd5e1;
    --glass-bg: rgba(255, 255, 255, 0.9);
    --glass-border: rgba(0,0,0,0.05);
    --bg-image: none;
}

/* Tailwind Overrides for Light Theme */
body.light-theme .bg-gray-900,
body.light-theme .bg-slate-900 { background-color: var(--bg-panel) !important; }
body.light-theme .bg-gray-900\/50 { background-color: rgba(255, 255, 255, 0.8) !important; }
body.light-theme .bg-gray-900\/40 { background-color: rgba(241, 245, 249, 0.8) !important; }

body.light-theme .bg-gray-800 { background-color: var(--bg-card) !important; }
body.light-theme .bg-gray-800\/50 { background-color: rgba(255, 255, 255, 0.5) !important; }
body.light-theme .bg-gray-800\/40 { background-color: rgba(248, 250, 252, 0.8) !important; }
body.light-theme .bg-gray-800\/80 { background-color: rgba(255, 255, 255, 0.9) !important; }

body.light-theme .bg-gray-700 { background-color: #e2e8f0 !important; }
body.light-theme .bg-gray-700\/30 { background-color: rgba(226, 232, 240, 0.5) !important; }
body.light-theme .bg-gray-700\/50 { background-color: rgba(226, 232, 240, 0.8) !important; }

/* Gradient Overrides */
body.light-theme .from-blue-900\/30 { --tw-gradient-from: rgba(59, 130, 246, 0.1) !important; }
body.light-theme .to-purple-900\/30 { --tw-gradient-to: rgba(147, 51, 234, 0.1) !important; }

body.light-theme .hover\:bg-gray-700:hover { background-color: #cbd5e1 !important; }
body.light-theme .hover\:bg-gray-800\/50:hover { background-color: rgba(203, 213, 225, 0.5) !important; }
body.light-theme .hover\:bg-gray-800\/40:hover { background-color: rgba(203, 213, 225, 0.4) !important; }

body.light-theme .text-white { color: var(--text-primary) !important; }
body.light-theme .text-gray-100 { color: #0f172a !important; }
body.light-theme .text-gray-200 { color: #1e293b !important; }
body.light-theme .text-gray-300 { color: #334155 !important; }
body.light-theme .text-gray-400 { color: var(--text-secondary) !important; }
body.light-theme .text-gray-500 { color: #64748b !important; }

body.light-theme .border-gray-800,
body.light-theme .border-gray-700 { border-color: var(--border-color) !important; }
body.light-theme .divide-gray-700 > * + * { border-color: var(--border-color) !important; }

body.light-theme .hover\:text-white:hover { color: var(--text-primary) !important; }

/* Table Header Specific */
body.light-theme thead.bg-gray-800 { background-color: #f1f5f9 !important; color: #475569 !important; }
body.light-theme thead.bg-gray-800 th { color: #475569 !important; font-weight: 600 !important; }

/* Scrollbar refinement for light mode */
body.light-theme ::-webkit-scrollbar-thumb { background: #cbd5e1; }
body.light-theme ::-webkit-scrollbar-track { background: #f1f5f9; }

body { 
    font-family: 'Vazirmatn', sans-serif; 
    background: var(--bg-main); 
    background-image: var(--bg-image);
    color: var(--text-primary); 
}

/* Branding Watermark */
body::before {
    content: "";
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 600px;
    height: 600px;
    background-image: url('/public/logo.png');
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    opacity: 0.05;
    pointer-events: none;
    z-index: 0;
}

.glass { 
    background: var(--glass-bg); 
    backdrop-filter: blur(8px); 
    border: 1px solid var(--glass-border); 
    border-radius: 12px; 
}

.input {
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    color: var(--text-primary);
    padding: 10px;
    border-radius: 6px;
    width: 100%;
    transition: 0.2s;
}

/* Keep numeric inputs and the service <select> the same height in the deal info tab. */
#deal-form-tab-info .input:not(textarea) {
    min-height: 44px;
    box-sizing: border-box;
}

.input:focus { 
    border-color: var(--accent-color); 
    outline: none; 
}

.financial-payment-filter-actions button {
    height: 46px;
    min-height: 46px;
    width: 100%;
    max-width: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    line-height: 1;
}

.financial-payment-filters-grid {
    align-items: end;
}

.financial-payment-filters-grid > div {
    align-self: end;
}

.financial-payment-filter-actions {
    align-self: end;
}

.financial-payment-filter-apply {
    color: #000000 !important;
    background: #eab308 !important;
    border-color: #eab308 !important;
    border-radius: 8px !important;
}

.financial-payment-filter-apply:hover {
    background: #facc15 !important;
    color: #000000 !important;
}

.financial-payment-filter-clear {
    color: #000000 !important;
    background: #e5e7eb !important;
    border-color: #9ca3af !important;
    border-radius: 8px !important;
}

.financial-payment-filter-clear:hover {
    background: #d1d5db !important;
    color: #000000 !important;
}

@media (max-width: 640px) {
    .financial-payment-filter-actions {
        grid-template-columns: 1fr;
    }
}

.financial-cheque-filters-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
    align-items: end;
}

.financial-cheque-filter-status,
.financial-cheque-filter-collection,
.financial-cheque-filter-dates,
.financial-cheque-filter-search,
.financial-cheque-filter-actions {
    min-width: 0;
    align-self: end;
}

@media (min-width: 768px) {
    .financial-cheque-filters-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (min-width: 1024px) {
    .financial-cheque-filters-grid {
        grid-template-columns:
            minmax(120px, 0.8fr)
            minmax(120px, 0.8fr)
            minmax(260px, 1.5fr)
            minmax(260px, 1.5fr)
            minmax(320px, 1.4fr);
    }
}

.btn-primary { 
    background: linear-gradient(135deg, #ca8a04, #eab308); 
    color: black; 
    font-weight: bold; 
    transition: 0.3s; 
}

.btn-primary:hover { 
    box-shadow: 0 4px 12px rgba(234, 179, 8, 0.3); 
    transform: translateY(-1px); 
}

.sidebar-item { 
    padding: 12px; 
    margin: 4px 0; 
    border-radius: 8px; 
    cursor: pointer; 
    transition: 0.2s; 
    color: #94a3b8; 
    display: flex; 
    align-items: center; 
    gap: 10px; 
}

.sidebar-item:hover, .sidebar-item.active { 
    background: rgba(234, 179, 8, 0.1); 
    color: #eab308; 
}

::-webkit-scrollbar { 
    width: 6px; 
    height: 6px; 
}

::-webkit-scrollbar-thumb { 
    background: #475569; 
    border-radius: 3px; 
}

.deal-card { 
    transition: all 0.2s; 
}

.deal-card:hover {
    transform: translateY(-2px);
    border-color: #eab308;
}

/* Persian Date Picker Custom Styles */
.pdp-container {
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%) !important;
    border: 1px solid rgba(59, 130, 246, 0.3) !important;
    border-radius: 12px !important;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5) !important;
    padding: 15px !important;
    z-index: 9999 !important; /* Fixed: Below modal top layer */
    font-family: 'Vazirmatn', sans-serif !important;
}

.pdp-header {
    background: rgba(59, 130, 246, 0.1) !important;
    border-radius: 8px !important;
    padding: 10px !important;
    margin-bottom: 10px !important;
}

.pdp-header .pdp-header-title {
    color: #e2e8f0 !important;
    font-weight: 600 !important;
}

.pdp-day {
    color: #e2e8f0 !important;
    border-radius: 6px !important;
    transition: all 0.2s !important;
    margin: 2px !important;
    padding: 8px !important;
}

.pdp-day:hover {
    background: rgba(59, 130, 246, 0.2) !important;
    transform: scale(1.05) !important;
    color: #fff !important;
}

.pdp-day-selected {
    background: linear-gradient(135deg, #3b82f6, #8b5cf6) !important;
    color: #fff !important;
    font-weight: bold !important;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.4) !important;
}

.pdp-day-today {
    border: 2px solid #3b82f6 !important;
    font-weight: bold !important;
    color: #3b82f6 !important;
}

.pdp-day-other-month {
    color: #64748b !important;
    opacity: 0.5 !important;
}

.pdp-day-disabled {
    color: #475569 !important;
    opacity: 0.3 !important;
    cursor: not-allowed !important;
}

.pdp-weekday {
    color: #94a3b8 !important;
    font-weight: 600 !important;
    padding: 8px !important;
}

.pdp-navbar {
    background: transparent !important;
    border: none !important;
}

.pdp-navbar button {
    background: rgba(59, 130, 246, 0.1) !important;
    border: 1px solid rgba(59, 130, 246, 0.3) !important;
    color: #3b82f6 !important;
    border-radius: 6px !important;
    padding: 6px 12px !important;
    transition: all 0.2s !important;
}

.pdp-navbar button:hover {
    background: rgba(59, 130, 246, 0.2) !important;
    transform: scale(1.05) !important;
}

.pdp-time-picker {
    background: rgba(59, 130, 246, 0.1) !important;
    border-radius: 8px !important;
    padding: 10px !important;
}

.pdp-time-picker input {
    background: rgba(30, 41, 59, 0.8) !important;
    border: 1px solid rgba(59, 130, 246, 0.3) !important;
    color: #e2e8f0 !important;
    border-radius: 6px !important;
    padding: 8px !important;
}

.pdp-time-picker input:focus {
    border-color: #3b82f6 !important;
    outline: none !important;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1) !important;
}

/* Time Select Styling */
#activity-due-hour,
#activity-due-minute {
    background: rgba(30, 41, 59, 0.8) !important;
    border: 1px solid rgba(59, 130, 246, 0.3) !important;
    color: #e2e8f0 !important;
    border-radius: 6px !important;
    padding: 10px !important;
    transition: all 0.2s !important;
    font-weight: 500 !important;
}

#activity-due-hour:focus,
#activity-due-minute:focus {
    border-color: #3b82f6 !important;
    outline: none !important;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1) !important;
    background: rgba(30, 41, 59, 1) !important;
}

#activity-due-hour:hover,
#activity-due-minute:hover {
    border-color: rgba(59, 130, 246, 0.5) !important;
    background: rgba(30, 41, 59, 0.9) !important;
}

/* Schedule Fields Container */
#activity-schedule-fields {
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Notification Popup Styles */
.notification-popup {
    position: fixed;
    top: 80px;
    right: 20px;
    min-width: 300px;
    max-width: 400px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
    z-index: 9999;
    opacity: 0;
    transform: translateX(100%);
    transition: all 0.3s ease-in-out;
    direction: rtl;
    font-family: 'Vazirmatn', sans-serif;
}

/* Mobile: Fix notification popup width and position */
@media (max-width: 480px) {
    .notification-popup {
        min-width: calc(100% - 40px);
        max-width: calc(100% - 40px);
        right: 20px;
        left: 20px;
        top: 70px; /* Adjusted for mobile header */
    }
    
    /* Reduce stacking offset on mobile */
    .notification-popup:nth-child(2) { top: 140px; }
    .notification-popup:nth-child(3) { top: 210px; }
    .notification-popup:nth-child(4) { top: 280px; }
    .notification-popup:nth-child(5) { top: 350px; }
    .notification-popup:nth-child(n+6) {
        top: 160px !important;
    }
}

.notification-popup.show {
    opacity: 1;
    transform: translateX(0);
}

.notification-popup.hide {
    opacity: 0;
    transform: translateX(100%);
}

.notification-popup-content {
    padding: 16px;
    color: var(--text-primary);
}

.notification-popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    flex-direction: row;
}

.notification-popup-title {
    font-weight: bold;
    font-size: 14px;
    color: var(--text-primary);
}

.notification-popup-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: color 0.2s;
}

.notification-popup-close:hover {
    color: var(--text-primary);
}

.notification-popup-close-all {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: color 0.2s;
    font-size: 14px;
}

.notification-popup-close-all:hover {
    color: #ef4444; /* Red color for close all */
}

.notification-popup-message {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.4;
}

.notification-popup-footer {
    margin-top: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.notification-popup-time {
    font-size: 11px;
    color: #6b7280;
}

.notification-popup-actions {
    display: flex;
    gap: 8px;
}

.notification-popup-action {
    padding: 4px 8px;
    border: none;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    transition: background-color 0.2s;
    font-weight: 500;
}

.notification-popup-action.primary {
    background-color: #3b82f6;
    color: white;
}

.notification-popup-action.primary:hover {
    background-color: #2563eb;
}

.notification-popup-action.secondary {
    background-color: #6b7280;
    color: white;
}

.notification-popup-action.secondary:hover {
    background-color: #4b5563;
}

/* Stack multiple popups */
.notification-popup:nth-child(2) { top: 170px; }
.notification-popup:nth-child(3) { top: 260px; }
.notification-popup:nth-child(4) { top: 350px; }
.notification-popup:nth-child(5) { top: 440px; }
.notification-popup:nth-child(6) { top: 530px; }
.notification-popup:nth-child(7) { top: 620px; }
.notification-popup:nth-child(8) { top: 710px; }
.notification-popup:nth-child(9) { top: 800px; }
.notification-popup:nth-child(10) { top: 890px; }

/* For very small screens, reduce spacing */
@media (max-height: 900px) {
    .notification-popup:nth-child(2) { top: 140px; }
    .notification-popup:nth-child(3) { top: 210px; }
    .notification-popup:nth-child(4) { top: 280px; }
    .notification-popup:nth-child(5) { top: 350px; }
    .notification-popup:nth-child(6) { top: 420px; }
    .notification-popup:nth-child(7) { top: 490px; }
    .notification-popup:nth-child(8) { top: 560px; }
    .notification-popup:nth-child(9) { top: 630px; }
    .notification-popup:nth-child(10) { top: 700px; }
}

/* Light theme support for popups */
body.light-theme .notification-popup {
    background: var(--bg-panel);
    border-color: var(--border-color);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
}

body.light-theme .notification-popup-title {
    color: var(--text-primary);
}

body.light-theme .notification-popup-message {
    color: var(--text-secondary);
}

body.light-theme .notification-popup-close {
    color: var(--text-secondary);
}

body.light-theme .notification-popup-close:hover {
    color: var(--text-primary);
}
/* Quick Filter Chips */
.quick-filter-chip {
    padding: 6px 16px;
    border-radius: 9999px;
    font-size: 11px;
    font-weight: 700;
    transition: all 0.3s ease;
    white-space: nowrap;
    border-width: 1px;
    background-color: rgba(31, 41, 55, 0.4);
    border-color: rgba(55, 65, 81, 0.5);
    color: #9ca3af;
    cursor: pointer;
}

.quick-filter-chip:hover {
    background-color: #374151;
    color: #ffffff;
}

.quick-filter-chip.active {
    background-color: #eab308;
    border-color: #ca8a04;
    color: #000000;
    box-shadow: 0 10px 15px -3px rgba(234, 179, 8, 0.2);
}

/* No scrollbar utility */
.no-scrollbar::-webkit-scrollbar {
    display: none;
}
.no-scrollbar {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

/* Neo Jalali DatePicker (replaces persian-datepicker) */
.neo-jdp {
    position: absolute;
    z-index: 9999;
    width: 260px;
    max-width: calc(100vw - 16px);
    padding: 10px;
    border-radius: 12px;
    background: rgba(15, 23, 42, 0.96);
    border: 1px solid rgba(148, 163, 184, 0.2);
    box-shadow: 0 12px 30px rgba(2, 6, 23, 0.45);
    direction: rtl;
    font-size: 13px;
}
.neo-jdp-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    gap: 6px;
}
.neo-jdp-title {
    font-size: 14px;
    font-weight: 700;
    color: #e2e8f0;
}
.neo-jdp-nav {
    background: rgba(148, 163, 184, 0.12);
    border: 1px solid rgba(148, 163, 184, 0.2);
    color: #e2e8f0;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    cursor: pointer;
}
.neo-jdp-nav:hover {
    border-color: #eab308;
    color: #eab308;
}
.neo-jdp-week,
.neo-jdp-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    text-align: center;
}
.neo-jdp-weekday {
    color: #94a3b8;
    font-size: 11px;
    padding: 4px 0;
}
.neo-jdp-day {
    background: rgba(148, 163, 184, 0.08);
    border: 1px solid transparent;
    border-radius: 8px;
    color: #e2e8f0;
    padding: 6px 0;
    cursor: pointer;
}
.neo-jdp-day:hover {
    border-color: #eab308;
    background: rgba(234, 179, 8, 0.1);
}
.neo-jdp-day.today {
    border-color: #eab308;
    color: #eab308;
}
.neo-jdp-day.selected {
    background: #eab308;
    color: #111827;
    font-weight: 700;
}
.neo-jdp-day.disabled,
.neo-jdp-day:disabled {
    opacity: 0.32;
    cursor: not-allowed;
    color: #64748b;
    background: rgba(30, 41, 59, 0.62);
    border-color: transparent;
}
.neo-jdp-day.disabled:hover,
.neo-jdp-day:disabled:hover {
    background: rgba(30, 41, 59, 0.62);
    border-color: transparent;
    color: #64748b;
}
.neo-jdp-empty {
    height: 30px;
}

/* Custom Scrollbar */
.custom-scrollbar::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.custom-scrollbar::-webkit-scrollbar-track {
    background: rgba(31, 41, 55, 0.5);
    border-radius: 4px;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
    background: rgba(75, 85, 99, 0.8);
    border-radius: 4px;
}

.custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: rgba(107, 114, 128, 1);
}

/* ========================================
   MOBILE SIDEBAR FIX - Z-Index Correction
   Ensures sidebar appears above modals on mobile
   ======================================== */
@media (max-width: 768px) {
    /* Sidebar must be above all modals (which use z-index: 5000-10000) */
    #main-sidebar {
        z-index: 999999 !important;
    }
    
    /* Backdrop just below sidebar */
    #sidebar-backdrop {
        z-index: 999998 !important;
    }
    
    /* Prevent click-through during transition */
    #sidebar-backdrop:not(.hidden) {
        pointer-events: auto;
    }
    
    #sidebar-backdrop.hidden {
        pointer-events: none;
    }
    
    /* Ensure sidebar is fully visible when opened */
    #main-sidebar:not(.translate-x-full) {
        box-shadow: -10px 0 30px rgba(0, 0, 0, 0.5);
    }
}

/* ========================================
   MOBILE MODAL FIX - Height & Overflow
   Fixes modal cutoff on mobile browsers
   ======================================== */
@media (max-width: 768px) {
    /* Fix modal height to account for browser chrome */
    #modalProfile .glass,
    #modalDeal .glass,
    #modalLead .glass,
    #modalActivity .glass,
    #modalSatisfaction .glass,
    #modalSupport .glass {
        height: 100vh;
        height: -webkit-fill-available;
        max-height: 100%;
        border-radius: 0;
        margin: 0;
        width: 100%;
        max-width: 100%;
    }
    
    /* Fix modal content overflow */
    #modalProfile .glass .flex-1,
    #modalDeal .glass .flex-1,
    #modalLead .glass .flex-1 {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* ========================================
   MOBILE HEADER FIX - Button Overflow
   Prevents header buttons from overflowing
   ======================================== */
@media (max-width: 375px) {
    /* Reduce header padding on small screens */
    header h-16 {
        padding-left: 8px;
        padding-right: 8px;
    }
    
    /* Hide non-critical buttons on very small screens */
    header button[title="تست اعلان"],
    header button[title="تست یادآوری‌ها"],
    header button[title="تست پاپ‌آپ مستقیم"],
    header button[title="تست نوتیفیکیشن مرورگر"] {
        display: none;
    }
    
    /* Reduce gap between buttons */
    header .flex.items-center.gap-2 {
        gap: 0.25rem;
    }
    
    /* Make header scrollable if needed */
    header .flex.items-center.justify-between {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* ========================================
   MOBILE TABLE FIX - Card Layout
   Converts tables to cards on mobile
   ======================================== */
@media (max-width: 768px) {
    /* Referrals table */
    #view-referrals table {
        min-width: 0;
        display: block;
    }
    
    #view-referrals thead {
        display: none;
    }
    
    #view-referrals tbody tr {
        display: block;
        margin-bottom: 16px;
        padding: 12px;
        background: var(--bg-card);
        border-radius: 8px;
        border: 1px solid var(--border-color);
    }
    
    #view-referrals tbody td {
        display: flex;
        justify-content: space-between;
        padding: 8px 0;
        border-bottom: 1px solid var(--border-color);
        text-align: left;
    }
    
    #view-referrals tbody td:last-child {
        border-bottom: none;
    }
    
    /* Add labels using data-label attribute */
    #view-referrals tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-secondary);
        text-align: right;
        padding-left: 8px;
    }
}

/* ========================================
   MOBILE PAGINATION FIX - Touch Targets
   Makes pagination buttons finger-friendly
   ======================================== */
@media (max-width: 768px) {
    button[onclick*="loadLeads"],
    button[onclick*="loadDeals"],
    button[onclick*="loadBlataklifLeads"],
    button[onclick*="loadLegacyDeals"] {
        min-width: 44px;
        min-height: 44px;
        padding: 12px 16px;
        font-size: 14px;
    }
    
    /* Pagination container */
    #leads-pagination,
    #deals-pagination,
    #blataklif-leads-pagination {
        padding: 8px 0;
    }
}

/* ========================================
   MOBILE SEARCH INPUT FIX - Overflow
   Prevents search input from overflowing
   ======================================== */
@media (max-width: 768px) {
    #leads-search,
    #deals-search,
    #blataklif-leads-search {
        min-width: 0;
        flex-shrink: 1;
    }
}

/* ========================================
   MOBILE STICKY HEADER FIX
   Makes header fixed on mobile for stability
   ======================================== */
@media (max-width: 768px) {
    header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 100;
    }
    
    /* Compensate for fixed header */
    main {
        padding-top: 64px;
    }
    
    /* Adjust view sections */
    .view-section {
        padding-top: 8px;
    }
}

/* ========================================
   MOBILE VIEWPORT HEIGHT FIX
   Accounts for mobile browser chrome
   ======================================== */
:root {
    --vh: 1vh;
}

@supports (-webkit-touch-callout: none) {
    .h-screen,
    .h-\[90vh\] {
        height: -webkit-fill-available;
    }
}

.h-screen {
    height: 100vh;
    height: calc(var(--vh, 1vh) * 100);
}

.h-\[90vh\] {
    height: 90vh;
    height: calc(var(--vh, 1vh) * 90);
}

/* ========================================
   PHASE 1 & 2: MOBILE FILTER IMPROVEMENTS
   Complete mobile UX overhaul
   ======================================== */

/* --- Collapsible Filter Accordion --- */
@media (max-width: 768px) {
    /* Filter toggle button */
    .filter-toggle-btn {
        position: sticky;
        top: 70px;
        z-index: 50;
        margin: 8px 0;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }
    
    /* Collapsible filter container */
    .filters-collapsible {
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease-out;
        background: var(--bg-card);
        border-radius: 12px;
        margin-bottom: 0;
    }
    
    .filters-collapsible.open {
        max-height: 2000px; /* Large enough for all filters */
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        margin-bottom: 16px;
    }
    
    /* Filter count badge */
    .filter-count-badge {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        background: #eab308;
        color: #000;
        font-size: 11px;
        font-weight: 700;
        min-width: 20px;
        height: 20px;
        border-radius: 10px;
        padding: 0 6px;
        margin-right: 8px;
    }
    
    /* Clear filters button */
    .clear-filters-btn {
        background: rgba(239, 68, 68, 0.1);
        border: 1px solid rgba(239, 68, 68, 0.3);
        color: #ef4444;
        padding: 8px 16px;
        border-radius: 8px;
        font-size: 12px;
        font-weight: 600;
        transition: all 0.2s;
    }
    
    .clear-filters-btn:hover {
        background: rgba(239, 68, 68, 0.2);
    }
    
    /* Active filter indicator */
    .filter-input.active {
        border-color: #eab308;
        box-shadow: 0 0 0 2px rgba(234, 179, 8, 0.2);
    }
    
    /* Sticky action buttons */
    .sticky-filter-actions {
        position: sticky;
        bottom: 0;
        background: var(--bg-card);
        border-top: 1px solid var(--border-color);
        padding: 12px;
        z-index: 40;
        display: flex;
        gap: 8px;
        justify-content: space-between;
    }
}

/* --- Touch-Friendly Inputs (44px minimum) --- */
@media (max-width: 768px) {
    .touch-input,
    .input[type="text"],
    .input[type="tel"],
    .input[type="email"],
    .input[type="number"],
    .input[type="date"],
    select.input {
        min-height: 44px;
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 12px;
    }
    
    /* Date picker inputs */
    #leads-register-from,
    #leads-register-to,
    #leads-activity-from,
    #leads-activity-to,
    #deals-register-from,
    #deals-register-to,
    #deals-activity-from,
    #deals-activity-to {
        min-height: 44px;
    }
}

/* --- Bottom Sheet Filters --- */
@media (max-width: 768px) {
    .bottom-sheet-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 9998;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }
    
    .bottom-sheet-overlay.active {
        opacity: 1;
        pointer-events: auto;
    }
    
    .bottom-sheet {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--bg-panel);
        border-radius: 16px 16px 0 0;
        z-index: 9999;
        transform: translateY(100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        max-height: 85vh;
        display: flex;
        flex-direction: column;
    }
    
    .bottom-sheet.active {
        transform: translateY(0);
    }
    
    .bottom-sheet-header {
        padding: 16px;
        border-bottom: 1px solid var(--border-color);
        display: flex;
        justify-content: space-between;
        align-items: center;
        flex-shrink: 0;
    }
    
    .bottom-sheet-title {
        font-size: 16px;
        font-weight: 700;
        color: var(--text-primary);
    }
    
    .bottom-sheet-close {
        background: none;
        border: none;
        color: var(--text-secondary);
        font-size: 24px;
        padding: 8px;
        cursor: pointer;
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .bottom-sheet-content {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 16px;
    }
    
    .bottom-sheet-footer {
        padding: 16px;
        border-top: 1px solid var(--border-color);
        display: flex;
        gap: 12px;
        flex-shrink: 0;
    }
    
    .bottom-sheet-footer button {
        flex: 1;
        min-height: 48px;
        font-size: 14px;
        font-weight: 600;
    }
}

/* --- Simplified Mobile Cards --- */
@media (max-width: 768px) {
    .lead-card-mobile {
        padding: 12px;
    }
    
    .lead-card-mobile .card-header {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        margin-bottom: 8px;
    }
    
    .lead-card-mobile .card-name {
        font-size: 14px;
        font-weight: 700;
        color: var(--text-primary);
    }
    
    .lead-card-mobile .card-phone {
        font-size: 12px;
        color: var(--text-secondary);
        margin-top: 4px;
    }
    
    .lead-card-mobile .card-meta {
        display: flex;
        gap: 8px;
        flex-wrap: wrap;
        margin-top: 8px;
    }
    
    .lead-card-mobile .card-badge {
        font-size: 11px;
        padding: 4px 8px;
        border-radius: 6px;
        font-weight: 600;
    }
    
    .lead-card-mobile .card-actions {
        display: flex;
        gap: 8px;
        margin-top: 12px;
        padding-top: 12px;
        border-top: 1px solid var(--border-color);
    }
    
    .lead-card-mobile .card-actions button {
        flex: 1;
        min-height: 44px;
        font-size: 12px;
    }
}

/* --- Sticky Pagination --- */
@media (max-width: 768px) {
    .sticky-pagination {
        position: sticky;
        bottom: 0;
        background: var(--bg-panel);
        border-top: 1px solid var(--border-color);
        padding: 12px 0;
        z-index: 60;
        box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1);
    }
    
    .sticky-pagination button {
        min-width: 44px;
        min-height: 44px;
        padding: 12px 16px;
        font-size: 14px;
    }
    
    /* Add padding to content to prevent overlap */
    .pagination-spacer {
        height: 80px;
    }
}

/* --- Visual Scroll Indicators --- */
@media (max-width: 768px) {
    .scroll-indicator {
        position: relative;
        mask-image: linear-gradient(to right, black 85%, transparent 100%);
        -webkit-mask-image: linear-gradient(to right, black 85%, transparent 100%);
    }
    
    .scroll-hint {
        position: absolute;
        right: 0;
        top: 50%;
        transform: translateY(-50%);
        width: 40px;
        height: 40px;
        background: linear-gradient(90deg, transparent, var(--bg-card));
        pointer-events: none;
        display: flex;
        align-items: center;
        justify-content: flex-end;
        padding-right: 8px;
    }
    
    .scroll-hint::after {
        content: "›";
        font-size: 24px;
        color: var(--text-secondary);
        animation: scrollHint 1.5s infinite;
    }
    
    @keyframes scrollHint {
        0%, 100% { transform: translateX(0); opacity: 0.5; }
        50% { transform: translateX(4px); opacity: 1; }
    }
}

/* --- Multi-Step Modal Forms (Mobile) --- */
@media (max-width: 768px) {
    .modal-step {
        display: none;
    }
    
    .modal-step.active {
        display: block;
    }
    
    .modal-steps-indicator {
        display: flex;
        justify-content: space-between;
        margin-bottom: 16px;
        padding: 0 8px;
    }
    
    .step-dot {
        flex: 1;
        height: 4px;
        background: var(--border-color);
        margin: 0 4px;
        border-radius: 2px;
        transition: background 0.3s;
    }
    
    .step-dot.active {
        background: #eab308;
    }
    
    .step-dot.completed {
        background: #22c55e;
    }
    
    .modal-step-actions {
        display: flex;
        gap: 8px;
        margin-top: 16px;
    }
    
    .modal-step-actions button {
        flex: 1;
        min-height: 48px;
    }
}

/* Desktop: Hide mobile-specific elements */
@media (min-width: 769px) {
    .mobile-only {
        display: none !important;
    }
}

@media (max-width: 768px) {
    .desktop-only {
        display: none !important;
    }
    
    /* Show mobile-specific elements */
    .mobile-only {
        display: block !important;
    }
}

/* ========================================
   PHASE 3: MOBILE ENHANCEMENTS
   Filter presets, history, voice search, etc.
   ======================================== */

/* --- Mobile Filter Presets --- */
@media (max-width: 768px) {
    .filter-preset-bar {
        display: flex;
        gap: 8px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding: 8px 0;
        margin-bottom: 8px;
        scroll-indicator;
    }
    
    .filter-preset-chip {
        flex-shrink: 0;
        background: rgba(234, 179, 8, 0.1);
        border: 1px solid rgba(234, 179, 8, 0.3);
        color: #eab308;
        padding: 8px 16px;
        border-radius: 20px;
        font-size: 12px;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.2s;
        white-space: nowrap;
    }
    
    .filter-preset-chip:hover,
    .filter-preset-chip.active {
        background: #eab308;
        color: #000;
    }
    
    .filter-preset-chip i {
        margin-left: 6px;
        font-size: 10px;
    }
}

/* --- Filter History Dropdown --- */
@media (max-width: 768px) {
    .filter-history-container {
        position: relative;
        margin-bottom: 8px;
    }
    
    .filter-history-btn {
        width: 100%;
        background: rgba(59, 130, 246, 0.1);
        border: 1px solid rgba(59, 130, 246, 0.3);
        color: #3b82f6;
        padding: 10px 16px;
        border-radius: 8px;
        font-size: 12px;
        font-weight: 600;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: space-between;
    }
    
    .filter-history-btn:hover {
        background: rgba(59, 130, 246, 0.2);
    }
    
    .filter-history-dropdown {
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: var(--bg-panel);
        border: 1px solid var(--border-color);
        border-radius: 8px;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
        z-index: 100;
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease;
    }
    
    .filter-history-dropdown.open {
        max-height: 300px;
        overflow-y: auto;
    }
    
    .filter-history-item {
        padding: 12px 16px;
        border-bottom: 1px solid var(--border-color);
        cursor: pointer;
        transition: background 0.2s;
    }
    
    .filter-history-item:hover {
        background: rgba(234, 179, 8, 0.05);
    }
    
    .filter-history-item:last-child {
        border-bottom: none;
    }
    
    .filter-history-label {
        font-size: 12px;
        font-weight: 600;
        color: var(--text-primary);
        margin-bottom: 4px;
    }
    
    .filter-history-meta {
        font-size: 10px;
        color: var(--text-secondary);
        display: flex;
        justify-content: space-between;
    }
    
    .filter-history-delete {
        color: #ef4444;
        background: none;
        border: none;
        cursor: pointer;
        padding: 4px;
        font-size: 14px;
    }
}

/* --- Voice Search Button --- */
@media (max-width: 768px) {
    .voice-search-container {
        position: relative;
        display: inline-flex;
        align-items: center;
    }
    
    .voice-search-btn {
        position: absolute;
        right: 8px;
        top: 50%;
        transform: translateY(-50%);
        background: rgba(234, 179, 8, 0.1);
        border: none;
        color: #eab308;
        width: 36px;
        height: 36px;
        border-radius: 8px;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: all 0.2s;
        z-index: 10;
    }
    
    .voice-search-btn:hover {
        background: rgba(234, 179, 8, 0.2);
    }
    
    .voice-search-btn.listening {
        background: #ef4444;
        color: white;
        animation: pulse 1s infinite;
    }
    
    @keyframes pulse {
        0%, 100% { transform: translateY(-50%) scale(1); }
        50% { transform: translateY(-50%) scale(1.1); }
    }
    
    .voice-search-input {
        padding-right: 52px !important;
    }
}

/* --- Date Range Picker --- */
@media (max-width: 768px) {
    .date-range-picker {
        position: relative;
        background: var(--bg-card);
        border: 1px solid var(--border-color);
        border-radius: 12px;
        padding: 12px;
        margin-bottom: 12px;
    }
    
    .date-range-inputs {
        display: flex;
        gap: 8px;
        align-items: center;
    }
    
    .date-range-inputs .input {
        flex: 1;
        min-width: 0;
    }
    
    .date-range-separator {
        color: var(--text-secondary);
        font-size: 14px;
        font-weight: 700;
    }
    
    .date-range-presets {
        display: flex;
        gap: 6px;
        margin-top: 8px;
        flex-wrap: wrap;
    }
    
    .date-range-preset {
        background: rgba(59, 130, 246, 0.1);
        border: 1px solid rgba(59, 130, 246, 0.2);
        color: #3b82f6;
        padding: 6px 12px;
        border-radius: 6px;
        font-size: 11px;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.2s;
    }
    
    .date-range-preset:hover,
    .date-range-preset.active {
        background: #3b82f6;
        color: white;
    }
}

/* --- Quick Filter Toolbar --- */
@media (max-width: 768px) {
    .quick-filter-toolbar {
        position: sticky;
        top: 120px;
        z-index: 45;
        background: var(--bg-panel);
        border-bottom: 1px solid var(--border-color);
        padding: 8px 0;
        margin-bottom: 12px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }
    
    .quick-filter-scroll {
        display: flex;
        gap: 8px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding: 0 12px;
        scroll-indicator;
    }
    
    .quick-filter-item {
        flex-shrink: 0;
        background: var(--bg-card);
        border: 1px solid var(--border-color);
        color: var(--text-secondary);
        padding: 8px 16px;
        border-radius: 20px;
        font-size: 12px;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.2s;
        white-space: nowrap;
    }
    
    .quick-filter-item:hover,
    .quick-filter-item.active {
        background: #eab308;
        border-color: #eab308;
        color: #000;
    }
    
    .quick-filter-item i {
        margin-left: 6px;
        font-size: 10px;
    }
}

/* ========================================
   PHASE 4: ACCESSIBILITY & ENHANCEMENTS
   ======================================== */

/* --- Enhanced Focus States --- */
@media (max-width: 768px) {
    .input:focus,
    button:focus,
    select:focus,
    [tabindex]:focus {
        outline: 2px solid #eab308;
        outline-offset: 2px;
    }
    
    .input:focus-visible,
    button:focus-visible {
        outline: 3px solid #eab308;
        outline-offset: 3px;
        box-shadow: 0 0 0 6px rgba(234, 179, 8, 0.2);
    }
}

/* --- Haptic Feedback Indicator --- */
@media (max-width: 768px) {
    .haptic-button:active {
        transform: scale(0.95);
    }
    
    @keyframes hapticFeedback {
        0% { transform: translateX(0); }
        25% { transform: translateX(-2px); }
        50% { transform: translateX(2px); }
        75% { transform: translateX(-2px); }
        100% { transform: translateX(0); }
    }
    
    .haptic-feedback {
        animation: hapticFeedback 0.1s ease-in-out;
    }
}

/* --- Pull-to-Refresh Indicator --- */
@media (max-width: 768px) {
    .pull-to-refresh-container {
        position: relative;
        overflow: hidden;
    }
    
    .pull-to-refresh-indicator {
        position: absolute;
        top: -60px;
        left: 0;
        right: 0;
        height: 60px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: var(--bg-panel);
        transition: top 0.3s ease;
        z-index: 50;
    }
    
    .pull-to-refresh-indicator.visible {
        top: 0;
    }
    
    .pull-to-refresh-spinner {
        width: 24px;
        height: 24px;
        border: 3px solid rgba(234, 179, 8, 0.3);
        border-top-color: #eab308;
        border-radius: 50%;
        animation: spin 0.8s linear infinite;
    }
    
    @keyframes spin {
        to { transform: rotate(360deg); }
    }
    
    .pull-to-refresh-text {
        margin-left: 12px;
        font-size: 12px;
        font-weight: 600;
        color: var(--text-primary);
    }
}

/* --- Enhanced Loading States --- */
@media (max-width: 768px) {
    .loading-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.7);
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        z-index: 99999;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s;
    }
    
    .loading-overlay.active {
        opacity: 1;
        pointer-events: auto;
    }
    
    .loading-spinner {
        width: 48px;
        height: 48px;
        border: 4px solid rgba(234, 179, 8, 0.3);
        border-top-color: #eab308;
        border-radius: 50%;
        animation: spin 0.8s linear infinite;
        margin-bottom: 16px;
    }
    
    .loading-text {
        color: white;
        font-size: 14px;
        font-weight: 600;
    }
    
    .skeleton-loader {
        background: linear-gradient(
            90deg,
            var(--bg-card) 25%,
            var(--bg-panel) 50%,
            var(--bg-card) 75%
        );
        background-size: 200% 100%;
        animation: shimmer 1.5s infinite;
        border-radius: 8px;
    }
    
    @keyframes shimmer {
        0% { background-position: 200% 0; }
        100% { background-position: -200% 0; }
    }
}

/* --- Landscape Mode Optimization --- */
@media (max-width: 768px) and (orientation: landscape) {
    .filters-collapsible.open {
        max-height: 300px;
    }
    
    .bottom-sheet {
        max-height: 60vh;
    }
    
    .lead-card-mobile {
        display: flex;
        gap: 12px;
        align-items: center;
    }
    
    .lead-card-mobile .card-header {
        margin-bottom: 0;
        flex: 1;
    }
    
    .lead-card-mobile .card-actions {
        margin-top: 0;
        padding-top: 0;
        border-top: none;
        flex-direction: column;
    }
}

/* --- Tablet Optimization (768-1024px) --- */
@media (min-width: 769px) and (max-width: 1024px) {
    .filters-collapsible {
        max-height: none;
        overflow: visible;
    }
    
    .lead-card-mobile {
        padding: 16px;
    }
    
    #leads-list,
    #deals-container {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* --- Desktop Leads Grid Restore (1025px+) --- */
@media (min-width: 1025px) and (max-width: 1439px) {
    #leads-list {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 1440px) {
    #leads-list {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* --- Desktop Collapsible Filters (Leads) --- */
@media (min-width: 1025px) {
    #view-leads #leads-filters.filters-collapsible {
        max-height: 0;
        overflow: hidden;
        margin-bottom: 0 !important;
        padding-top: 0 !important;
        padding-bottom: 0 !important;
        border-color: transparent;
        opacity: 0;
        transition: max-height 0.25s ease, opacity 0.2s ease, margin 0.25s ease, padding 0.25s ease;
    }

    #view-leads #leads-filters.filters-collapsible.open {
        max-height: 1200px;
        overflow: visible;
        margin-bottom: 1rem !important;
        padding-top: 1rem !important;
        padding-bottom: 1rem !important;
        border-color: var(--border-color);
        opacity: 1;
    }

    #leads-desktop-filter-toggle .filter-count-badge {
        margin-right: 0;
        margin-left: 4px;
    }

    #leads-desktop-filter-toggle.open #leads-desktop-filter-toggle-icon {
        transform: rotate(180deg);
    }

    /* Desktop filter/header compaction */
    #view-leads > .mb-4.flex.gap-3.flex-wrap.items-center {
        margin-bottom: 0.5rem;
    }

    #view-leads > .mb-4.flex.gap-2.flex-wrap.desktop-only {
        margin-top: 0.25rem;
        margin-bottom: 0.75rem;
        align-items: center;
    }

    #view-leads .desktop-only .clear-filters-btn {
        background: rgba(239, 68, 68, 0.08);
        border: 1px solid rgba(239, 68, 68, 0.25);
        color: #f87171;
        transition: all 0.2s;
    }

    #view-leads .desktop-only .clear-filters-btn:hover {
        background: rgba(239, 68, 68, 0.14);
        border-color: rgba(239, 68, 68, 0.4);
    }

    /* Desktop lead card polish (Phase 5) */
    #leads-list .lead-card-desktop {
        min-height: 128px;
        border: 1px solid rgba(255, 255, 255, 0.06);
        display: flex;
        flex-direction: column;
        justify-content: space-between;
    }

    #leads-list .lead-card-desktop:hover {
        border-color: rgba(234, 179, 8, 0.25);
        box-shadow: 0 6px 16px rgba(0, 0, 0, 0.16);
    }

    #leads-list .lead-card-desktop .lead-name {
        line-height: 1.35;
    }

    #leads-list .lead-card-desktop .lead-products {
        display: -webkit-box;
        -webkit-line-clamp: 1;
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

/* --- Commission Wizard --- */
#commission-matrix-section {
    position: relative;
    z-index: 20;
    background: #ffffff;
    color: #0f172a;
    border: 1px solid rgba(148, 163, 184, 0.32);
    border-radius: 1.25rem;
    transform-origin: top center;
}

#commission-matrix-section.commission-wizard-shell {
    position: relative;
    isolation: isolate;
    box-shadow: 0 22px 70px rgba(15, 23, 42, 0.18);
}

#commission-matrix-section.commission-edit-highlight {
    animation: commissionEditPulse 1.2s ease-out;
}

#commission-matrix-section .commission-wizard-header {
    background:
        radial-gradient(circle at top right, rgba(16, 185, 129, 0.16), transparent 34%),
        linear-gradient(135deg, #f8fafc, #ecfeff);
    border-radius: 12px 12px 0 0;
    border-color: rgba(148, 163, 184, 0.28) !important;
}

#commission-matrix-section .text-white,
#commission-matrix-section .text-gray-100,
#commission-matrix-section .text-gray-200,
#commission-matrix-section .text-gray-300 {
    color: #0f172a !important;
}

#commission-matrix-section .text-gray-400 {
    color: #475569 !important;
}

#commission-matrix-section .text-gray-500 {
    color: #64748b !important;
}

#commission-matrix-section .text-blue-100 {
    color: #1e3a8a !important;
}

#commission-matrix-section .border-gray-700,
#commission-matrix-section .border-gray-800 {
    border-color: rgba(148, 163, 184, 0.32) !important;
}

#commission-matrix-section .bg-gray-800,
#commission-matrix-section .bg-gray-900\/40,
#commission-matrix-section .bg-gray-900 {
    background-color: #ffffff !important;
}

#commission-matrix-section .commission-wizard-body {
    overflow: visible;
    padding-bottom: 1.5rem;
}

#commission-matrix-section .commission-wizard-steps {
    background: #f8fafc;
    border-color: rgba(148, 163, 184, 0.24) !important;
}

#commission-matrix-section .commission-step-tab {
    flex: 1;
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-areas:
        "num title"
        "num desc";
    gap: 0 0.75rem;
    align-items: center;
    text-align: right;
    border: 1px solid rgba(203, 213, 225, 0.95);
    background: #ffffff;
    color: #334155;
    border-radius: 1rem;
    padding: 0.85rem;
    transition: border-color 0.2s, background 0.2s, transform 0.2s;
}

#commission-matrix-section .commission-step-tab:hover {
    transform: translateY(-1px);
    border-color: rgba(234, 179, 8, 0.55);
}

#commission-matrix-section .commission-step-tab span {
    grid-area: num;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #e2e8f0;
    color: #0f172a;
    font-weight: 800;
}

#commission-matrix-section .commission-step-tab strong {
    grid-area: title;
    color: #0f172a;
    font-size: 0.9rem;
}

#commission-matrix-section .commission-step-tab small {
    grid-area: desc;
    color: #64748b;
    font-size: 0.72rem;
}

#commission-matrix-section .commission-step-tab.is-active {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.16), rgba(14, 165, 233, 0.10));
    border-color: rgba(16, 185, 129, 0.75);
}

#commission-matrix-section .commission-step-tab.is-active span,
#commission-matrix-section .commission-step-tab.is-complete span {
    background: linear-gradient(135deg, #10b981, #facc15);
    color: #020617;
}

#commission-matrix-section .commission-card-soft {
    border: 1px solid rgba(203, 213, 225, 0.95);
    background:
        linear-gradient(145deg, #ffffff, #f8fafc),
        radial-gradient(circle at top left, rgba(14, 165, 233, 0.08), transparent 34%);
    border-radius: 1rem;
    padding: 1rem;
}

#commission-matrix-section .commission-block-label {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    margin-bottom: 0.75rem;
    color: #0f766e;
    font-size: 0.72rem;
    font-weight: 800;
}

#commission-matrix-section .commission-block-label span {
    background: #ccfbf1;
    color: #115e59;
    border-radius: 999px;
    padding: 0.18rem 0.5rem;
}

#commission-matrix-section .commission-date-note {
    border: 1px dashed rgba(20, 184, 166, 0.45);
    background: #f0fdfa;
    color: #0f766e;
    border-radius: 0.75rem;
    padding: 0.65rem;
    font-size: 0.72rem;
    line-height: 1.7;
}

#commission-matrix-section .input {
    background: #ffffff !important;
    border-color: #cbd5e1 !important;
    color: #0f172a !important;
}

#commission-matrix-section .input:focus {
    border-color: #14b8a6 !important;
    box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.12);
}

#commission-matrix-section .commission-wizard-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    margin-top: 1.25rem;
    padding-top: 1rem;
    border-top: 1px solid rgba(203, 213, 225, 0.85);
}

#commission-matrix-section .commission-mini-action {
    font-size: 0.68rem;
    padding: 0.28rem 0.5rem;
    border-radius: 999px;
    color: #dcfce7;
    background: rgba(4, 120, 87, 0.68);
    border: 1px solid rgba(16, 185, 129, 0.22);
}

#commission-matrix-section .commission-mini-action.is-muted {
    color: #334155;
    background: #e2e8f0;
    border-color: rgba(100, 116, 139, 0.22);
}

#commission-matrix-section .commission-multi-select {
    min-height: 9rem;
}

#commission-matrix-section .commission-tier-row {
    border: 1px solid rgba(203, 213, 225, 0.95);
    background: #f8fafc;
    border-radius: 0.9rem;
    padding: 0.75rem;
}

#commission-matrix-section #commission-product-panel {
    z-index: 100500 !important;
    max-height: min(420px, 56vh);
    background: #ffffff !important;
    border-color: #cbd5e1 !important;
    box-shadow: 0 18px 50px rgba(15, 23, 42, 0.18);
}

#commission-matrix-section table {
    background: #ffffff;
    border: 1px solid rgba(203, 213, 225, 0.8);
    border-radius: 0.85rem;
    overflow: hidden;
}

#commission-matrix-section thead tr {
    background: #f8fafc;
}

#commission-matrix-section tbody tr {
    border-color: #e2e8f0 !important;
}

#commission-matrix-toggle-btn {
    background: linear-gradient(135deg, #0f766e, #14b8a6) !important;
    color: #ffffff !important;
}

#commission-matrix-section .commission-assignment-board {
    direction: rtl;
}

#commission-matrix-section .commission-assignment-panel {
    background: #1f2937;
    border: 1px solid #334155;
    border-radius: 18px;
    padding: 1.5rem;
    color: #e2e8f0;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

#commission-matrix-section .commission-assignment-title {
    color: #f5b400 !important;
    font-size: 1.25rem;
    font-weight: 900;
    line-height: 1.8;
}

#commission-matrix-section .commission-assignment-subtitle,
#commission-matrix-section .commission-assignment-help {
    color: #94a3b8 !important;
    font-size: 0.76rem;
    line-height: 1.8;
}

#commission-matrix-section .commission-assignment-chip {
    background: rgba(15, 23, 42, 0.72);
    border: 1px solid rgba(51, 65, 85, 0.95);
    color: #94a3b8;
    border-radius: 999px;
    padding: 0.25rem 0.65rem;
    font-size: 0.7rem;
    font-weight: 800;
}

#commission-matrix-section .commission-assignment-label {
    color: #94a3b8 !important;
    font-size: 0.8rem;
    font-weight: 800;
}

#commission-matrix-section .commission-assignment-select,
#commission-matrix-section .commission-assignment-panel .input,
#commission-matrix-section .commission-assignment-panel .kpi-tag-picker-root button,
#commission-matrix-section .commission-assignment-panel #commission-product-search {
    background: #0f172a !important;
    border: 1px solid #334155 !important;
    color: #e5e7eb !important;
    border-radius: 10px !important;
}

#commission-matrix-section .commission-assignment-panel .commission-multi-select {
    min-height: 4.7rem;
}

#commission-matrix-section .commission-assignment-panel option {
    color: #e5e7eb;
    background: #0f172a;
}

#commission-matrix-section .commission-assignment-panel .text-gray-500,
#commission-matrix-section .commission-assignment-panel .text-gray-400 {
    color: #94a3b8 !important;
}

#commission-matrix-section .commission-assignment-panel .bg-blue-900\/60 {
    background: rgba(8, 47, 73, 0.92) !important;
    border-color: rgba(14, 165, 233, 0.36) !important;
    color: #bae6fd !important;
}

#commission-matrix-section .commission-assignment-submit {
    width: 100%;
    min-height: 3.3rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background: linear-gradient(180deg, #f5b400, #e4a300);
    color: #0f172a;
    font-weight: 900;
    transition: transform 0.15s ease, filter 0.15s ease;
}

#commission-matrix-section .commission-assignment-submit:hover {
    filter: brightness(1.05);
    transform: translateY(-1px);
}

#commission-matrix-section .commission-assignments-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-height: 36rem;
    overflow: auto;
    padding-inline-end: 0.2rem;
}

#commission-matrix-section .commission-assignment-card {
    background: #172233;
    border: 1px solid #334155;
    border-radius: 16px;
    padding: 1.25rem;
}

#commission-matrix-section .commission-assignment-card.is-active {
    border-color: #3b4a60;
}

#commission-matrix-section .commission-assignment-card.is-inactive {
    opacity: 0.74;
}

#commission-matrix-section .commission-assignment-card h5 {
    color: #f8fafc !important;
    font-size: 1rem;
    font-weight: 900;
    margin-bottom: 0.45rem;
    overflow-wrap: anywhere;
}

#commission-matrix-section .commission-assignment-card p {
    color: #94a3b8 !important;
    font-size: 0.82rem;
    line-height: 1.9;
}

#commission-matrix-section .commission-assignment-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 1.25rem;
}

#commission-matrix-section .commission-role-badge,
#commission-matrix-section .commission-status-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    padding: 0.32rem 0.7rem;
    font-size: 0.76rem;
    font-weight: 900;
    white-space: nowrap;
}

#commission-matrix-section .commission-role-badge.is-agent {
    background: rgba(6, 95, 70, 0.55);
    color: #34d399;
}

#commission-matrix-section .commission-role-badge.is-muted {
    background: rgba(51, 65, 85, 0.75);
    color: #cbd5e1;
}

#commission-matrix-section .commission-status-pill.is-active {
    background: rgba(6, 95, 70, 0.5);
    color: #34d399;
}

#commission-matrix-section .commission-status-pill.is-inactive {
    background: rgba(127, 29, 29, 0.48);
    color: #fca5a5;
}

#commission-matrix-section .commission-switch {
    width: 3.2rem;
    height: 1.65rem;
    border-radius: 999px;
    padding: 0.18rem;
    display: inline-flex;
    align-items: center;
    transition: background 0.18s ease;
}

#commission-matrix-section .commission-switch span {
    width: 1.28rem;
    height: 1.28rem;
    border-radius: 999px;
    background: #f8fafc;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.35);
    transition: transform 0.18s ease;
}

#commission-matrix-section .commission-switch.is-on {
    background: #10b981;
}

#commission-matrix-section .commission-switch.is-on span {
    transform: translateX(-1.45rem);
}

#commission-matrix-section .commission-switch.is-off {
    background: #64748b;
}

#commission-matrix-section .commission-assignment-empty {
    min-height: 12rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    color: #94a3b8;
    border: 1px dashed #334155;
    border-radius: 14px;
    background: rgba(15, 23, 42, 0.34);
    font-size: 0.85rem;
}

#commission-matrix-section .commission-assignment-empty i {
    color: #f5b400;
    font-size: 1.35rem;
}

#commission-matrix-section .commission-rules-admin-wrap {
    background: #f8fafc;
    border: 1px solid rgba(203, 213, 225, 0.85);
    border-radius: 16px;
    padding: 1rem;
}

.persian-datepicker,
.datepicker-plot-area,
.select2-container,
.select2-dropdown {
    z-index: 100600 !important;
}

@keyframes commissionEditPulse {
    0% {
        box-shadow: 0 0 0 0 rgba(20, 184, 166, 0.45), 0 22px 70px rgba(15, 23, 42, 0.18);
    }
    45% {
        box-shadow: 0 0 0 10px rgba(20, 184, 166, 0.13), 0 22px 70px rgba(15, 23, 42, 0.18);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(20, 184, 166, 0), 0 22px 70px rgba(15, 23, 42, 0.18);
    }
}

@media (max-width: 768px) {
    #commission-matrix-section .commission-wizard-body {
        padding: 1rem;
    }

    #commission-matrix-section .commission-wizard-actions {
        flex-direction: column-reverse;
        align-items: stretch;
    }

    #commission-matrix-section .commission-wizard-actions > div {
        display: grid;
        grid-template-columns: 1fr;
        width: 100%;
    }
}

/* --- Screen Reader Only (Accessibility) --- */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* --- High Contrast Mode Support --- */
@media (prefers-contrast: high) {
    .input,
    button,
    select {
        border-width: 2px;
    }
    
    .filter-count-badge {
        border: 2px solid #000;
    }
}

/* --- Reduced Motion Support --- */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ===========================================================================
   RBAC permission UI — explicit styles.
   The bundled Tailwind build is purged and lacks cyan/emerald/amber bg, ring,
   opacity and cursor utilities, so the preset/tab "active" states must be
   defined here rather than via utility classes.
   =========================================================================== */

/* Quick-preset buttons (هیچ‌کدام / مشاهده / مدیریت / کامل) */
.rbac-preset-btn {
    padding: 3px 11px;
    font-size: 10px;
    line-height: 1.6;
    border-radius: 6px;
    border: 1px solid #374151;        /* gray-700 */
    color: #9ca3af;                   /* gray-400 */
    background: transparent;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease;
}
.rbac-preset-btn:hover:not(:disabled):not(.is-active) {
    color: #e5e7eb;                   /* gray-200 */
    border-color: #6b7280;            /* gray-500 */
}
.rbac-preset-btn:disabled {
    border-color: #1f2937;            /* gray-800 */
    color: #4b5563;                   /* gray-600 */
    opacity: .45;
    cursor: not-allowed;
}
.rbac-preset-btn.is-active {
    font-weight: 700;
    color: #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, .45);
}
.rbac-preset-btn.is-active.preset-none   { background: #6b7280; border-color: #d1d5db; }  /* gray   */
.rbac-preset-btn.is-active.preset-view   { background: #0891b2; border-color: #67e8f9; }  /* cyan   */
.rbac-preset-btn.is-active.preset-manage { background: #059669; border-color: #6ee7b7; }  /* emerald*/
.rbac-preset-btn.is-active.preset-full   { background: #f59e0b; border-color: #fcd34d; color: #111827; } /* amber */

.rbac-perm-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 58px;
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid rgba(71, 85, 105, .55);
    background: rgba(15, 23, 42, .62);
    cursor: pointer;
    transition: background-color .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.rbac-perm-row:hover {
    border-color: rgba(34, 211, 238, .55);
    background: rgba(15, 23, 42, .86);
}
.rbac-perm-row:focus-within {
    border-color: #67e8f9;
    box-shadow: 0 0 0 3px rgba(34, 211, 238, .18);
}
.rbac-perm-row.is-selected {
    border-color: rgba(96, 165, 250, .72);
    background: rgba(30, 64, 175, .22);
}
.rbac-perm-row .rbac-label {
    color: #f8fafc;
    font-size: 13px;
    font-weight: 800;
    line-height: 1.45;
}
.rbac-perm-row .rbac-key {
    display: block;
    margin-top: 4px;
    color: #9ca3af;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0;
}
.rbac-perm-row .rbac-cb {
    width: 20px;
    height: 20px;
    margin: 0;
    cursor: pointer;
}

/* Customer access request cards — light theme overrides.
   The card markup uses hardcoded dark inline styles; a stylesheet !important
   rule outranks an inline style without !important, so these reskin them. */
body.light-theme .access-card {
    background: #ffffff !important;
    border-color: var(--border-color) !important;
    box-shadow: 0 10px 24px rgba(15, 23, 42, .08) !important;
}
body.light-theme .access-chip {
    background: #f1f5f9 !important;
    border-color: #cbd5e1 !important;
    color: #0f172a !important;
}
body.light-theme .access-divider {
    border-bottom-color: #e2e8f0 !important;
}
body.light-theme .access-tile {
    background: #f8fafc !important;
    border-color: #e2e8f0 !important;
}
body.light-theme .access-tile-label {
    color: #64748b !important;
}
body.light-theme .access-tile-value {
    color: #0f172a !important;
}
body.light-theme .access-note-value.is-reject {
    color: #dc2626 !important;
}
body.light-theme .access-note-value.is-approve {
    color: #059669 !important;
}

/* Capability category tabs (اصلی / گزارش‌ها / …) */
.rbac-tab {
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.4;
    border-radius: 8px;
    border: 1px solid #374151;        /* gray-700 */
    color: #9ca3af;                   /* gray-400 */
    background: rgba(17, 24, 39, .4);  /* gray-900/40 */
    cursor: pointer;
    transition: background-color .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease;
}
.rbac-tab:hover:not(.is-active) {
    color: #e5e7eb;                   /* gray-200 */
    border-color: #0e7490;            /* cyan-700 */
}
.rbac-tab.is-active {
    background: #06b6d4;              /* cyan-500 */
    color: #fff;
    border-color: #67e8f9;           /* cyan-300 */
    font-weight: 800;
    box-shadow: 0 4px 14px rgba(8, 145, 178, .40), 0 0 0 3px rgba(34, 211, 238, .30);
}
.rbac-tab.is-active .rbac-tab-count { color: #ecfeff; }  /* cyan-50 */
.rbac-tab .rbac-tab-count { color: #22d3ee; font-size: 10px; }  /* cyan-400 */
