@font-face {
    font-family: 'Vazirmatn';
    font-style: normal;
    font-weight: 100;
    font-display: swap;
    src: url('../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('../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('../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('../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('../vendor/fonts/vazirmatn/vazirmatn-arabic-800-normal.woff2') format('woff2');
}

:root {
    /* SaleOs graphite/orange brand theme */
    --bg-main: #050607;
    --bg-panel: #090b0f;
    --bg-card: #12161c;
    --text-primary: #f7f8fa;
    --text-secondary: #a7adb6;
    --border-color: #272d35;
    --input-bg: #11161d;
    --input-border: #343b45;
    --glass-bg: rgba(13, 16, 21, 0.86);
    --glass-border: rgba(255, 122, 0, 0.18);
    --bg-image:
        linear-gradient(135deg, rgba(255, 122, 0, 0.06), transparent 28%),
        linear-gradient(180deg, #06080b 0%, #0d1117 100%);
    --primary-gradient-start: #ff5f00;
    --primary-gradient-end: #ff9d0a;
    --accent-color: #ff7a00;
    --accent-soft: rgba(255, 122, 0, 0.12);
    --accent-border: rgba(255, 122, 0, 0.32);
    --chrome-soft: #d7dce2;
}

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:not(.light-theme) .bg-gray-900,
body:not(.light-theme) .bg-slate-900 {
    background-color: #090b0f !important;
}

body:not(.light-theme) .bg-gray-900\/50,
body:not(.light-theme) .bg-gray-900\/40 {
    background-color: rgba(9, 11, 15, 0.78) !important;
}

body:not(.light-theme) .bg-gray-800 {
    background-color: #12161c !important;
}

body:not(.light-theme) .bg-gray-800\/80,
body:not(.light-theme) .bg-gray-800\/50,
body:not(.light-theme) .bg-gray-800\/40 {
    background-color: rgba(18, 22, 28, 0.82) !important;
}

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

body:not(.light-theme) .text-yellow-500,
body:not(.light-theme) .text-cyan-300 {
    color: var(--accent-color) !important;
}

body:not(.light-theme) .hover\:text-cyan-200:hover,
body:not(.light-theme) .hover\:text-yellow-400:hover {
    color: #ffb34d !important;
}

body:not(.light-theme) .from-yellow-500,
body:not(.light-theme) .from-amber-500 {
    --tw-gradient-from: #ff6900 !important;
}

body:not(.light-theme) .to-yellow-500,
body:not(.light-theme) .to-amber-500 {
    --tw-gradient-to: #ff9d0a !important;
}

body {
    font-family: 'Vazirmatn', sans-serif;
    background: var(--bg-main);
    background-image: var(--bg-image);
    background-attachment: fixed;
    color: var(--text-primary);
    line-height: 1.7; /* Persian script needs more vertical room than Latin */
    font-variant-numeric: tabular-nums; /* keep amounts/KPIs from jittering */
}

/* Global: 16px controls prevent iOS Safari auto-zoom on focus (all inputs,
   including <textarea> and untyped inputs the old scoped rule missed). */
input, select, textarea {
    font-size: 16px;
}

/* Bidi isolation safety net: keep Latin runs (phones, emails, Didar IDs,
   product codes) from visually reordering inside Persian/RTL text. Pairs
   with the app.bidi() <bdi> helper for inline-mixed values. */
.card-phone,
.dir-ltr,
.font-mono {
    unicode-bidi: isolate;
}

/* Branding Watermark */
body::before {
    content: "";
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 600px;
    height: 600px;
    background-image: url('../img/saleos-logo-mark.png');
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    opacity: 0.045;
    pointer-events: none;
    z-index: 0;
}

.glass { 
    background: var(--glass-bg); 
    backdrop-filter: blur(12px); 
    border: 1px solid var(--glass-border); 
    border-radius: 12px; 
    box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
}

.saleos-login-shell {
    position: relative;
    padding: 24px;
    overflow: hidden;
    background:
        linear-gradient(90deg, rgba(5, 6, 7, 0.92), rgba(5, 6, 7, 0.72)),
        url('../img/saleos-brand-board.png') center / cover no-repeat;
}

.saleos-login-shell::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(255, 122, 0, 0.10), transparent 38%, rgba(0, 0, 0, 0.42));
    pointer-events: none;
}

.saleos-login-card {
    position: relative;
    max-width: 430px;
    border-color: rgba(255, 122, 0, 0.24);
    background: rgba(7, 9, 12, 0.86);
}

.saleos-login-logo {
    width: min(320px, 100%);
    max-height: 120px;
}

.input {
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    color: var(--text-primary);
    padding: 10px;
    border-radius: 6px;
    width: 100%;
    transition: border-color 0.2s, box-shadow 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;
}

.deal-form-tab-btn {
    position: relative;
    min-height: 42px;
    background: rgba(15, 23, 42, 0.42);
    border-color: rgba(71, 85, 105, 0.78);
    color: #b8c1cf;
    box-shadow: inset 0 0 0 1px rgba(148, 163, 184, 0.03);
    transition: background-color 0.16s ease, border-color 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
}

.deal-form-tab-btn:hover {
    background: rgba(30, 41, 59, 0.68);
    border-color: rgba(100, 116, 139, 0.9);
    color: #f8fafc;
}

.deal-form-tab-btn.is-active {
    background: rgba(51, 65, 85, 0.9);
    border-color: rgba(203, 213, 225, 0.78);
    color: #ffffff;
    box-shadow:
        inset 0 0 0 1px rgba(226, 232, 240, 0.12),
        0 8px 18px rgba(2, 6, 23, 0.24);
}

.deal-form-tab-btn.is-active #deal-activities-badge {
    background: rgba(100, 116, 139, 0.96);
    color: #ffffff;
}

.input:focus {
    border-color: var(--accent-color);
    outline: none;
    box-shadow: 0 0 0 3px rgba(255, 122, 0, 0.14);
}

/* Global keyboard-focus ring for all interactive elements, every viewport.
   :focus-visible only triggers for keyboard/AT users, so mouse clicks stay clean. */
a:focus-visible,
button:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible,
.input:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

.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, var(--primary-gradient-start), var(--primary-gradient-end)); 
    color: #111111;
    font-weight: bold;
    border: 1px solid rgba(255, 185, 90, 0.42);
    box-shadow: 0 10px 26px rgba(255, 111, 0, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.28);
    transition: box-shadow 0.3s, transform 0.3s, filter 0.3s;
}

.btn-primary:hover { 
    box-shadow: 0 14px 34px rgba(255, 111, 0, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.34);
    filter: saturate(1.08);
    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; 
}

[data-rbac-menu]:not([data-rbac-visible="1"]) {
    display: none !important;
}

.sidebar-item:hover, .sidebar-item.active { 
    background: linear-gradient(90deg, rgba(255, 122, 0, 0.14), rgba(255, 122, 0, 0.04)); 
    color: var(--accent-color);
    box-shadow: inset -3px 0 0 var(--accent-color);
}

::-webkit-scrollbar { 
    width: 6px; 
    height: 6px; 
}

::-webkit-scrollbar-thumb { 
    background: #3a414c; 
    border-radius: 3px; 
}

.deal-card {
    transition: transform 0.2s, border-color 0.2s;
}

.deal-card:hover {
    transform: translateY(-2px);
    border-color: var(--accent-color);
}

/* 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) {
    /* modalProfile is a long detail view → keep it full-screen. Scope to the
       DIRECT child panel only (`> .glass`): the descendant form `.glass` also
       matched the ~28 inner info cards and stretched each to height:100vh,
       producing an enormous scroll. */
    #modalProfile > .glass {
        height: 100vh;
        height: 100dvh;
        max-height: 100%;
        border-radius: 0;
        margin: 0;
        width: 100%;
        max-width: 100%;
        /* Keep header/footer clear of the notch and home indicator */
        padding-top: env(safe-area-inset-top, 0px);
        padding-bottom: env(safe-area-inset-bottom, 0px);
        box-sizing: border-box;
    }
    #modalProfile > .glass > .flex-1 {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* --- P3a: lead-detail (profile) Info tab → compact spec sheet ---
       The Info tab was ~28 chunky glass cards stacked full-width (one huge
       empty card per field). Tighten the scroll padding and lay the fields out
       as a dense 2-column label/value grid with light chrome, so the tab reads
       as a spec sheet instead of an endless wall of panels. */
    #modalProfile .flex-1.overflow-y-auto.p-6 { padding: 12px; }

    #profile-tab-info > .grid {
        grid-template-columns: 1fr 1fr;
        gap: 6px;
    }
    #profile-tab-info > .grid > .glass {
        padding: 6px 9px;
        border-radius: 8px;
        background: rgba(255, 255, 255, 0.03);
        border: 1px solid var(--border-color);
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }
    /* label */
    #profile-tab-info > .grid > .glass > .text-xs {
        font-size: 10.5px;
        margin-bottom: 1px;
        line-height: 1.3;
    }
    /* value(s) */
    #profile-tab-info > .grid > .glass .font-bold {
        font-size: 12.5px;
        line-height: 1.35;
    }
    /* full-width description card under the grid */
    #profile-tab-info > .glass { padding: 9px 11px; }

    /* Smaller header avatar so the sheet leads with content, not a banner. */
    #profile-header .w-12.h-12 { width: 40px; height: 40px; font-size: 16px; }

    /* Create/edit forms (lead, deal, activity, …) present as bottom sheets:
       docked to the bottom, rounded top, sliver of backdrop above, content
       scrolls, and they slide up on open. Far less heavy than full-screen. */
    #modalDeal,
    #modalLead,
    #modalActivity,
    #modalSatisfaction,
    #modalSupport {
        align-items: flex-end !important;
        padding: 0 !important;
    }
    #modalDeal .glass,
    #modalLead .glass,
    #modalActivity .glass,
    #modalSatisfaction .glass,
    #modalSupport .glass {
        width: 100%;
        max-width: 100%;
        margin: 0;
        height: auto;
        max-height: 92vh;
        max-height: 92dvh;
        border-radius: 16px 16px 0 0;
        padding-bottom: env(safe-area-inset-bottom, 0px);
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        animation: soSheetUp 0.26s cubic-bezier(0.22, 1, 0.36, 1);
    }
    #modalDeal .glass .flex-1,
    #modalLead .glass .flex-1,
    #modalActivity .glass .flex-1,
    #modalSatisfaction .glass .flex-1,
    #modalSupport .glass .flex-1 {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}
@keyframes soSheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* ========================================
   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;
    }

    /* 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: 36px;
        min-height: 36px;
        padding: 8px 12px;
        font-size: 13px;
    }
    
    /* 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;
        /* Clear the status bar / notch when viewport-fit=cover is set */
        padding-top: env(safe-area-inset-top, 0px);
        box-sizing: content-box;
    }

    /* Compensate for fixed header (plus the safe-area inset it now carries) */
    main {
        padding-top: calc(64px + env(safe-area-inset-top, 0px));
    }

    /* Adjust view sections; reserve space so the bottom tab bar never covers content */
    .view-section {
        padding-top: 8px;
        padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px));
    }
}

/* ========================================
   MOBILE VIEWPORT HEIGHT FIX
   Accounts for mobile browser chrome
   ======================================== */
:root {
    --vh: 1vh;
}

.h-screen {
    height: 100vh; /* fallback for old browsers */
    height: 100dvh; /* tracks Safari's dynamic toolbar correctly */
}

.h-\[90vh\] {
    height: 90vh;
    height: 90dvh;
}

/* ========================================
   PHASE 1 & 2: MOBILE FILTER IMPROVEMENTS
   Complete mobile UX overhaul
   ======================================== */

/* --- Leads search/filter controls. Layout owned here (not Tailwind): the
   prebuilt Tailwind subset lacks col-span-* and arbitrary grid utilities. ---
   Desktop: search grows, code is fixed, actions inline. */
#leads-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
}
#leads-controls .lc-search { flex: 1 1 18rem; min-width: 0; }
#leads-controls .lc-code { width: 10rem; }
#leads-controls .lc-go,
#leads-controls .lc-didar { white-space: nowrap; }

@media (max-width: 768px) {
    /* Mobile: tidy 2x2 grid — search + کد مشتری on row 1, جستجو + فیلترها on
       row 2. No giant stacked full-width gold bars. */
    #leads-controls {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }
    #leads-controls > * { width: 100%; min-width: 0; margin: 0; text-align: center; }
    #leads-controls .lc-search { text-align: right; }
    #leads-controls .lc-code { text-align: right; }

    /* The inline filters panel is only shown inside the bottom sheet on mobile
       (openFilterSheet moves it in and tags it .in-sheet). Keep it fully
       hidden in the page until then — it was leaking its header inline. */
    #leads-filters.filters-collapsible:not(.in-sheet) { display: none; }
}

/* --- Collapsible Filter Accordion --- */
@media (max-width: 768px) {
    /* Filter toggle button: full-width and centered, consistent on both the
       leads and deals pages. (Was an auto-width, left-aligned, position:sticky
       button that floated oddly mid-scroll on leads.) */
    .filter-toggle-btn {
        width: 100%;
        justify-content: center;
        margin: 0;
        /* Color discipline: filtering is a secondary/utility action — neutral
           surface + hairline, NOT gold, so search stays the one gold (primary)
           action per context. The gold count badge still flags active filters. */
        background: rgba(255, 255, 255, 0.04);
        color: var(--text-primary);
        border: 1px solid var(--border-color);
        font-weight: 600;
        box-shadow: none;
    }
    
    /* 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;
    }
}

/* --- Compact form controls (mobile). 38px visual height reads as a precise
   tool; 16px font is kept only to prevent iOS focus-zoom. --- */
@media (max-width: 768px) {
    .touch-input,
    .input,
    .input[type="text"],
    .input[type="tel"],
    .input[type="email"],
    .input[type="number"],
    .input[type="date"],
    textarea.input,
    select.input {
        min-height: 38px;
        font-size: 16px; /* iOS anti-zoom only; field stays compact */
        padding: 8px 10px;
    }
    textarea.input { min-height: 64px; }

    /* 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: 38px;
    }
}

/* --- 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: 20px 20px 0 0;
        border-top: 1px solid var(--glass-border);
        box-shadow: 0 -10px 34px rgba(0, 0, 0, 0.5);
        z-index: 9999;
        transform: translateY(100%);
        transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
        max-height: 88vh;
        max-height: 88dvh;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .bottom-sheet.active {
        transform: translateY(0);
    }

    /* Drag handle (visual affordance; dismissal is the close button + scrim). */
    .bottom-sheet-grip {
        width: 40px;
        height: 4px;
        border-radius: 2px;
        background: var(--border-color);
        margin: 8px auto 0;
        flex-shrink: 0;
    }

    /* Filter panels live in the sheet on mobile: the inline bar is hidden,
       and the moved node is fully expanded inside the sheet. */
    .bottom-sheet-content #deals-filter-bar { display: flex; }
    .bottom-sheet-content #leads-filters.filters-collapsible,
    .bottom-sheet-content #blataklif-leads-filters.filters-collapsible {
        max-height: none;
        overflow: visible;
        opacity: 1;
        margin: 0;
        padding: 4px 0 0;
        border: 0;
    }
    /* The moved filter node drops its own card chrome inside the sheet. */
    .bottom-sheet-content #deals-filter-bar {
        background: transparent;
        border: 0;
        padding: 0;
    }

    .bottom-sheet-header {
        padding: 6px 16px 14px;
        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: 800;
        color: var(--text-primary);
    }
    
    .bottom-sheet-close {
        background: none;
        border: none;
        color: var(--text-secondary);
        font-size: 20px;
        padding: 6px;
        cursor: pointer;
        min-width: 40px;
        min-height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .bottom-sheet-content {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 16px;
        padding-bottom: max(16px, env(safe-area-inset-bottom, 0px));
    }
    
    .bottom-sheet-footer {
        padding: 16px;
        padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
        border-top: 1px solid var(--border-color);
        display: flex;
        gap: 12px;
        flex-shrink: 0;
    }
    
    .bottom-sheet-footer button {
        flex: 1;
        min-height: 40px;
        font-size: 13px;
        font-weight: 600;
    }
}

/* --- Simplified Mobile Cards --- */
@media (max-width: 768px) {
    /* Compact 2-line lead card: name + status on row 1, phone · owner + a
       single call icon on row 2. No divider, no full-width button row — the
       card itself opens the profile on tap, so the old "view" button is gone.
       This roughly halves card height (~135px -> ~62px). */
    .lead-card-mobile {
        padding: 9px 11px;
    }

    .lead-card-mobile .lcm-row {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
        min-width: 0;
    }

    .lead-card-mobile .lcm-sub {
        margin-top: 4px;
    }

    .lead-card-mobile .card-name {
        font-size: 13.5px;
        font-weight: 700;
        color: var(--text-primary);
        line-height: 1.35;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .lead-card-mobile .lcm-meta {
        display: flex;
        align-items: center;
        gap: 6px;
        min-width: 0;
        font-size: 11.5px;
        color: var(--text-secondary);
        overflow: hidden;
    }

    .lead-card-mobile .card-phone {
        flex-shrink: 0;
    }

    .lead-card-mobile .lcm-sep {
        flex-shrink: 0;
        opacity: 0.5;
    }

    .lead-card-mobile .lcm-owner {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .lead-card-mobile .card-badge {
        flex-shrink: 0;
        font-size: 10.5px;
        padding: 3px 7px;
        border-radius: 6px;
        font-weight: 600;
    }

    .lead-card-mobile .lcm-call {
        flex-shrink: 0;
        width: 32px;
        height: 32px;
        min-height: 32px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border-radius: 8px;
        background: rgba(255, 255, 255, 0.06);
        border: 1px solid var(--border-color);
        color: var(--text-primary);
        font-size: 12px;
    }
}

/* --- Sticky Pagination --- */
@media (max-width: 768px) {
    .sticky-pagination {
        position: sticky;
        /* Float above the bottom tab bar */
        bottom: calc(64px + env(safe-area-inset-bottom, 0px));
        background: var(--bg-panel);
        border-top: 1px solid var(--border-color);
        padding: 12px 0;
        /* Reserve the FAB's corner (inset-inline-start: 16px + 56px wide) so
           the page buttons never render underneath the floating + button. */
        padding-inline-start: 80px;
        z-index: 60;
        box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1);
    }
    
    .sticky-pagination button {
        min-width: 36px;
        min-height: 36px;
        padding: 8px 12px;
        font-size: 13px;
    }
    
    /* 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: 40px;
    }
}

/* 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;
    }

    .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;
    }
    
    .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 */

/* =========================================================================
   SaleOS reusable info tooltip
   Inline help primitive for cards, table headers and form labels.
   ========================================================================= */

.so-info-tooltip {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    vertical-align: middle;
    margin-inline-start: 5px;
    isolation: isolate;
    line-height: 1;
    cursor: help;
    overflow: visible;
}
.so-info-tooltip-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 15px;
    height: 15px;
    border-radius: 999px;
    border: 1px solid rgba(125, 211, 252, 0.34);
    background: rgba(14, 165, 233, 0.13);
    color: #7dd3fc;
    font-size: 10px;
    font-weight: 850;
    line-height: 1;
    box-shadow: 0 0 0 2px rgba(14, 165, 233, 0.05);
}
.so-info-tooltip-panel {
    position: absolute;
    inset-inline-end: 0;
    top: calc(100% + 8px);
    z-index: 100000;
    display: none;
    width: min(430px, calc(100vw - 36px));
    padding: 11px 12px;
    border-radius: 8px;
    border: 1px solid rgba(125, 211, 252, 0.24);
    background: rgba(2, 6, 23, 0.97);
    color: #dbeafe;
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.42);
    text-align: right;
    white-space: normal;
    pointer-events: none;
}
.so-info-tooltip-panel::before {
    content: "";
    position: absolute;
    inset-inline-end: 10px;
    top: -5px;
    width: 9px;
    height: 9px;
    transform: rotate(45deg);
    border-inline-start: 1px solid rgba(125, 211, 252, 0.24);
    border-top: 1px solid rgba(125, 211, 252, 0.24);
    background: rgba(2, 6, 23, 0.97);
}
.so-info-tooltip-panel b {
    display: block;
    color: #f8fafc;
    font-size: 11.5px;
    font-weight: 850;
    margin-bottom: 5px;
}
.so-info-tooltip-panel span {
    display: block;
    color: #b6c7df;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.85;
}
/* The inline panel is never shown directly (it would be clipped by card
   overflow:hidden and mis-anchored by backdrop-filter ancestors). It serves
   only as the content source for the body-level #so-tip-layer, which the
   shell script positions as position:fixed. Hence no :hover/:focus display
   rule here. The floating layer hides its arrow (can't track the trigger). */
.so-info-tooltip-panel.so-tip-floating::before { display: none; }
#so-tip-layer { text-align: right; }
.so-info-tooltip:focus { outline: none; }
.so-info-tooltip:focus .so-info-tooltip-trigger {
    border-color: rgba(56, 189, 248, 0.82);
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.20);
}

/* =========================================================================
   Performance dashboard design system
   Scoped, reusable primitives shared by the summary cards, CEO report,
   activity section, charts panels, tab tables and drill-down modal.
   Presentation only — no behaviour depends on these class names.
   ========================================================================= */

.perf-panel {
    background: rgba(17, 24, 39, 0.45);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 14px;
    padding: 16px;
}
.perf-panel--bare { background: transparent; border: 0; padding: 0; }
.perf-panel-title {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 12px;
}
.perf-section-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 4px;
}
.perf-section-title { font-size: 16px; font-weight: 800; color: #f8fafc; }
.perf-section-sub { font-size: 11.5px; color: #94a3b8; margin-top: 2px; }

.perf-group {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 12px;
    font-weight: 700;
    color: #cbd5e1;
    margin: 16px 0 10px;
}
.perf-dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }
.perf-row-grid {
    display: grid;
    grid-template-columns: minmax(230px, 1.08fr) repeat(auto-fit, minmax(174px, 1fr));
    gap: 10px;
    align-items: stretch;
}

/* Compact metric card: subtle full-border accent, dense readable metadata */
.perf-card {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 104px;
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.88), rgba(15, 23, 42, 0.68));
    border: 1px solid color-mix(in srgb, var(--perf-rail, #64748b) 34%, rgba(255, 255, 255, 0.08));
    border-radius: 10px;
    padding: 10px 12px;
    transition: background-color .15s ease, border-color .15s ease, transform .15s ease, box-shadow .15s ease;
}
.perf-card.is-click { cursor: pointer; }
.perf-card.is-click:hover {
    background: rgba(24, 34, 52, 0.92);
    border-color: color-mix(in srgb, var(--perf-rail, #38bdf8) 62%, rgba(255, 255, 255, 0.12));
    box-shadow: 0 8px 22px rgba(2, 6, 23, 0.18);
}
.perf-card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; overflow: visible; }
.perf-card-lbl { display: inline-flex; align-items: center; min-width: 0; font-size: 11px; color: #a9b6c9; font-weight: 700; line-height: 1.55; white-space: nowrap; overflow: visible; }
.perf-card-lbl-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.perf-card-lbl .so-info-tooltip { flex: 0 0 auto; }
.perf-card-val { font-size: 18px; font-weight: 850; color: #f7f9fc; margin-top: 6px; letter-spacing: 0; line-height: 1.35; overflow-wrap: anywhere; }
.perf-card-val .unit { font-size: 11px; font-weight: 600; color: #a9b6c9; margin-inline-start: 2px; }
.perf-card-meta { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.perf-card-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-height: 22px;
    padding: 2px 7px;
    border-radius: 6px;
    background: rgba(14, 165, 233, 0.12);
    border: 1px solid rgba(56, 189, 248, 0.16);
    color: #9bd8f5;
    font-size: 10.5px;
    line-height: 1.45;
}
.perf-card-chip b { color: #dff6ff; font-weight: 800; }
.perf-card-sub { font-size: 10.5px; color: #7f8da3; margin-top: 3px; }
.perf-card-hint { font-size: 10px; color: #38d2ff; display: inline-flex; align-items: center; gap: 3px; white-space: nowrap; flex: 0 0 auto; }

.perf-hero {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 108px;
    background: linear-gradient(180deg, rgba(20, 83, 77, 0.42), rgba(15, 60, 66, 0.34));
    border: 1px solid rgba(45, 212, 191, 0.42);
    border-radius: 10px;
    padding: 11px 13px;
    cursor: pointer;
    transition: background-color .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.perf-hero:hover { background: rgba(20, 83, 77, 0.52); border-color: rgba(45, 212, 191, 0.66); box-shadow: 0 8px 22px rgba(2, 6, 23, 0.20); }
.perf-hero .perf-card-lbl { color: #a7f3d0; }
.perf-hero .perf-card-val { font-size: 24px; }
.perf-hero .perf-card-chip { background: rgba(56, 189, 248, 0.14); border-color: rgba(125, 211, 252, 0.20); color: #b7e8fb; }
.perf-hero .perf-card-chip b { color: #ecfbff; }

/* Semantic rail colours (colour encodes meaning, not sequence) */
.perf-rail-money  { --perf-rail: #10b981; }
.perf-rail-bal    { --perf-rail: #22d3ee; }
.perf-rail-cheque { --perf-rail: #f59e0b; }
.perf-rail-vol    { --perf-rail: #38bdf8; }
.perf-rail-src    { --perf-rail: #818cf8; }
.perf-rail-access { --perf-rail: #2dd4bf; }

/* Status badge pill */
.perf-badge {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    width: 100%;
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 12px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    cursor: pointer;
    transition: filter .15s ease;
}
.perf-badge:hover { filter: brightness(1.15); }
.perf-badge b { font-weight: 800; }
.perf-badge.is-green { background: rgba(16, 185, 129, 0.14); color: #6ee7b7; }
.perf-badge.is-red   { background: rgba(248, 113, 113, 0.14); color: #fca5a5; }
.perf-badge.is-amber { background: rgba(245, 158, 11, 0.14); color: #fcd34d; }
.perf-badge.is-gray  { background: rgba(100, 116, 139, 0.16); color: #cbd5e1; }
.perf-badge.is-teal  { background: rgba(45, 212, 191, 0.14); color: #5eead4; }

/* Clickable stat tile */
.perf-tile {
    background: rgba(17, 24, 39, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 10px;
    padding: 10px;
    text-align: center;
    cursor: pointer;
    transition: border-color .15s ease, background-color .15s ease;
}
.perf-tile:hover { background: rgba(30, 41, 59, 0.85); }
.perf-tile-lbl { font-size: 10.5px; }
.perf-tile-val { font-size: 20px; font-weight: 800; color: #f8fafc; margin-top: 6px; }
.perf-tile.is-previous {
    border-color: rgba(129, 140, 248, 0.26);
    background: rgba(30, 27, 75, 0.22);
}
.perf-deal-source-pills {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 5px;
    margin-top: 8px;
}
.perf-deal-source-pills span {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    min-height: 20px;
    padding: 2px 6px;
    border-radius: 6px;
    background: rgba(15, 23, 42, 0.72);
    border: 1px solid rgba(71, 85, 105, 0.72);
    color: #9fb0c8;
    font-size: 10px;
    line-height: 1.35;
    white-space: nowrap;
}
.perf-deal-source-pills b {
    color: #e0f2fe;
    font-weight: 850;
}
.perf-prev-success {
    border: 1px solid rgba(129, 140, 248, 0.18);
    border-radius: 12px;
    padding: 10px;
    background: rgba(15, 23, 42, 0.35);
}
.perf-prev-success-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.perf-prev-success-title {
    color: #c4b5fd;
    font-size: 12px;
    font-weight: 850;
}
.perf-prev-success-sub {
    color: #7f8da3;
    font-size: 10.5px;
    margin-top: 2px;
}

/* Polished table (zebra + hover rail + money pill + deal cell) */
.perf-tbl { width: 100%; border-collapse: collapse; font-size: 11.5px; }
.perf-tbl th { color: #94a3b8; font-weight: 700; text-align: right; padding: 8px 9px; border-bottom: 1px solid rgba(255, 255, 255, 0.08); white-space: nowrap; }
.perf-tbl td { padding: 7px 9px; color: #e2e8f0; }
.perf-tbl tbody tr { border-right: 2px solid transparent; transition: background-color .12s ease, border-color .12s ease; }
.perf-tbl tbody tr:nth-child(even) td { background: rgba(255, 255, 255, 0.02); }
.perf-tbl tbody tr:hover { border-right-color: #818cf8; background: rgba(129, 140, 248, 0.06); }
.perf-tbl tfoot td { padding: 8px 9px; color: #f8fafc; font-weight: 800; background: rgba(14, 165, 233, 0.10); border-top: 1px solid rgba(56, 189, 248, 0.28); white-space: nowrap; }
.perf-tbl tfoot .perf-pill { background: rgba(14, 165, 233, 0.18); color: #bae6fd; }
.perf-pill { display: inline-flex; align-items: center; background: rgba(16, 185, 129, 0.13); color: #6ee7b7; padding: 2px 8px; border-radius: 6px; font-weight: 700; font-size: 11px; }
.perf-dealcell { display: inline-flex; align-items: center; gap: 5px; color: #fcd34d; font-weight: 600; }
.perf-linkbtn { color: #93c5fd; font-weight: 700; background: transparent; border: 0; padding: 0; cursor: pointer; text-align: right; }
.perf-linkbtn:hover { color: #bfdbfe; text-decoration: underline; }
.perf-empty { font-size: 12px; color: #64748b; padding: 14px 4px; }
.perf-agent-source-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 62px;
    padding: 3px 7px;
    border-radius: 7px;
    background: rgba(14, 165, 233, 0.11);
    border: 1px solid rgba(56, 189, 248, 0.18);
    color: #e0f2fe;
    white-space: nowrap;
}
.perf-agent-source-count b { font-size: 12px; color: #f8fafc; }
.perf-agent-source-count em { font-style: normal; font-size: 10px; color: #7dd3fc; }
.perf-agent-amount-split {
    display: inline-flex;
    flex-direction: column;
    gap: 3px;
    min-width: 116px;
    text-align: right;
}
.perf-agent-amount-split span {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 2px 6px;
    border-radius: 6px;
    background: rgba(15, 23, 42, 0.38);
    border: 1px solid rgba(148, 163, 184, 0.10);
}
.perf-agent-amount-split em { font-style: normal; color: #94a3b8; font-size: 10px; }
.perf-agent-amount-split b { color: #e2e8f0; font-size: 10.5px; font-weight: 800; }
.perf-agent-amount-split small,
.perf-agent-sudran-amount small {
    color: #7dd3fc;
    font-size: 9.5px;
    font-weight: 700;
    margin-inline-start: 5px;
}
.perf-agent-sudran-amount {
    display: inline-flex;
    align-items: center;
    min-width: 94px;
    justify-content: center;
    padding: 4px 8px;
    border-radius: 7px;
    background: rgba(45, 212, 191, 0.10);
    border: 1px solid rgba(45, 212, 191, 0.18);
    color: #99f6e4;
    font-weight: 800;
    white-space: nowrap;
}

.perf-legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 11px; color: #94a3b8; margin-bottom: 8px; }
.perf-legend span { display: flex; align-items: center; gap: 5px; }
.perf-legend .sw { width: 9px; height: 9px; border-radius: 2px; display: inline-block; flex: 0 0 auto; }

.perf-filter-bar {
    position: relative;
    z-index: 5000;
    isolation: isolate;
    overflow: visible;
    margin-bottom: 14px;
    padding: 9px 11px 10px;
    border: 1px solid rgba(51, 65, 85, 0.78);
    border-radius: 10px;
    background: rgba(15, 23, 42, 0.78);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
}
.perf-filter-head {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    margin-bottom: 7px;
    min-height: 16px;
}
.perf-filter-title {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-width: max-content;
    color: #f8fafc;
    font-size: 12px;
    font-weight: 800;
}
.perf-filter-dot {
    width: 7px;
    height: 7px;
    border-radius: 999px;
    background: #22d3ee;
    box-shadow: 0 0 0 4px rgba(34, 211, 238, 0.10);
}
.perf-filter-note {
    color: #64748b;
    font-size: 10px;
    flex: 1 1 auto;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.perf-filter-grid {
    display: grid !important;
    grid-template-columns: minmax(120px, 0.75fr) minmax(120px, 0.75fr) minmax(180px, 1.1fr) minmax(210px, 1.25fr) 118px;
    gap: 8px;
    align-items: end;
}
.perf-filter-field,
.perf-select-field {
    position: relative;
    min-width: 0;
}
.perf-filter-field > span {
    display: block;
    margin-bottom: 4px;
    padding-inline: 2px;
    color: #94a3b8;
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
}
.perf-filter-input {
    width: 100%;
    height: 30px !important;
    min-height: 30px !important;
    padding: 4px 8px !important;
    border: 1px solid rgba(71, 85, 105, 0.95) !important;
    border-radius: 6px !important;
    outline: none;
    background: rgba(2, 6, 23, 0.88) !important;
    color: #f8fafc !important;
    font-size: 12px !important;
    line-height: 20px !important;
    box-shadow: none !important;
}
.perf-filter-input:focus {
    border-color: rgba(34, 211, 238, 0.82) !important;
    box-shadow: 0 0 0 1px rgba(34, 211, 238, 0.18) !important;
}
.perf-apply-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    height: 30px;
    margin: 0;
    border: 0;
    border-radius: 6px;
    background: #2563eb;
    color: #fff;
    font-size: 11px;
    font-weight: 800;
    cursor: pointer;
    transition: background-color .12s ease, transform .12s ease;
}
.perf-apply-btn:hover { background: #1d4ed8; }
.perf-apply-btn:active { transform: translateY(1px); }
.perf-quick-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 5px;
    flex: 0 0 auto;
    min-width: max-content;
}
.perf-quick-actions button {
    height: 26px;
    padding: 0 9px;
    border: 1px solid rgba(71, 85, 105, 0.88);
    border-radius: 6px;
    background: rgba(30, 41, 59, 0.88);
    color: #cbd5e1;
    font-size: 10px;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color .12s ease, border-color .12s ease, color .12s ease;
}
.perf-quick-actions button:hover {
    border-color: rgba(56, 189, 248, 0.45);
    background: rgba(51, 65, 85, 0.92);
    color: #f8fafc;
}
.custom-multiselect-compact {
    position: relative;
    z-index: 7000;
}
.custom-multiselect-compact > label {
    margin-bottom: 4px !important;
    color: #94a3b8 !important;
    font-size: 10px !important;
    font-weight: 700 !important;
    line-height: 1 !important;
}
.custom-multiselect-compact > button {
    height: 30px !important;
    min-height: 30px !important;
    padding: 4px 9px !important;
    border-radius: 7px !important;
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.96), rgba(2, 6, 23, 0.92)) !important;
    border-color: rgba(71, 85, 105, 0.95) !important;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03) !important;
}
.custom-multiselect-compact > button:hover,
.custom-multiselect-compact > button:focus {
    border-color: rgba(56, 189, 248, 0.75) !important;
    background: linear-gradient(180deg, rgba(15, 23, 42, 1), rgba(8, 14, 28, 0.98)) !important;
}
.custom-multiselect-compact > button span {
    color: #e5eefb !important;
    font-size: 12px !important;
    line-height: 1.2 !important;
}
.custom-multiselect-compact > button i {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    margin-inline-end: 6px;
    border-radius: 5px;
    background: rgba(30, 41, 59, 0.85);
    color: #93c5fd !important;
}
.custom-multiselect-compact [id^="dropdown-"] {
    z-index: 60000 !important;
    max-height: 292px;
    border-radius: 9px !important;
    border-color: rgba(56, 189, 248, 0.38) !important;
    background: #0b1220 !important;
    box-shadow: 0 22px 48px rgba(0, 0, 0, 0.52), 0 0 0 1px rgba(15, 23, 42, 0.9) !important;
}
.custom-multiselect-compact .custom-multiselect-searchbar {
    padding: 7px !important;
    border-color: rgba(51, 65, 85, 0.82) !important;
    background: #0f172a !important;
}
.custom-multiselect-compact .custom-multiselect-search {
    height: 30px !important;
    border-radius: 7px !important;
    border-color: rgba(71, 85, 105, 0.9) !important;
    background: rgba(2, 6, 23, 0.82) !important;
    color: #f8fafc !important;
}
.custom-multiselect-compact .custom-multiselect-search:focus {
    border-color: rgba(96, 165, 250, 0.85) !important;
    background: rgba(15, 23, 42, 0.95) !important;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.16) !important;
}
.custom-multiselect-compact .custom-multiselect-options {
    max-height: 224px !important;
    padding: 4px !important;
    background: #0b1220;
}
.custom-multiselect-compact .select-item {
    min-height: 34px;
    gap: 8px;
    padding: 7px 8px !important;
    border: 0 !important;
    border-radius: 7px;
    background: transparent;
}
.custom-multiselect-compact .select-item:hover {
    background: rgba(30, 41, 59, 0.92) !important;
}
.custom-multiselect-compact .select-item.is-selected {
    background: rgba(14, 165, 233, 0.12) !important;
    box-shadow: inset 0 0 0 1px rgba(56, 189, 248, 0.18);
}
.custom-multiselect-compact .select-item span {
    margin-right: 8px !important;
    color: #dbeafe !important;
    font-size: 12px;
    font-weight: 650;
    line-height: 1.35;
}
.custom-multiselect-compact .select-item:not(.is-selected) span {
    color: #cbd5e1 !important;
    font-weight: 600;
}
.custom-multiselect-compact input[type="checkbox"] {
    width: 14px;
    height: 14px;
    border-radius: 4px;
    border-color: rgba(148, 163, 184, 0.72) !important;
    background: rgba(15, 23, 42, 0.92) !important;
}
.custom-multiselect-compact input[type="checkbox"]:checked {
    border-color: #38bdf8 !important;
    background: #0284c7 !important;
}
@media (max-width: 1280px) {
    .perf-filter-grid {
        grid-template-columns: minmax(112px, 1fr) minmax(112px, 1fr) minmax(160px, 1.35fr) minmax(170px, 1.35fr) 108px;
    }
}
@media (max-width: 1100px) {
    .perf-filter-head { flex-wrap: wrap; }
    .perf-filter-note { order: 3; flex-basis: 100%; }
    .perf-quick-actions { margin-inline-start: auto; }
    .perf-filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) 108px; }
    .perf-product-field { grid-column: span 2; }
}
@media (max-width: 820px) {
    .perf-filter-head { align-items: flex-start; flex-direction: column; gap: 6px; }
    .perf-filter-grid { grid-template-columns: 1fr 1fr; }
    .perf-select-field,
    .perf-product-field,
    .perf-apply-btn { grid-column: 1 / -1; }
    .perf-quick-actions { flex-wrap: wrap; justify-content: flex-start; }
}

/* Skeleton loader (matches the final card grid to avoid layout shift) */
.perf-skel {
    border-radius: 12px;
    background: linear-gradient(100deg, rgba(148,163,184,.06) 30%, rgba(148,163,184,.16) 50%, rgba(148,163,184,.06) 70%);
    background-size: 200% 100%;
    animation: perfShimmer 1.3s ease-in-out infinite;
}
@keyframes perfShimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* Light-theme overrides */
body.light-theme .perf-panel { background: rgba(248, 250, 252, 0.85); border-color: var(--border-color); }
body.light-theme .perf-card,
body.light-theme .perf-tile { background: #ffffff; border-color: var(--border-color); }
body.light-theme .perf-card.is-click:hover,
body.light-theme .perf-tile:hover { background: #f1f5f9; }
body.light-theme .perf-section-title,
body.light-theme .perf-card-val,
body.light-theme .perf-tile-val { color: var(--text-primary); }
body.light-theme .perf-card-lbl,
body.light-theme .perf-section-sub,
body.light-theme .perf-group { color: #475569; }
body.light-theme .perf-card-sub { color: #64748b; }
body.light-theme .perf-card-chip { background: #e0f2fe; border-color: #bae6fd; color: #0369a1; }
body.light-theme .perf-card-chip b { color: #075985; }
body.light-theme .perf-tbl td { color: #1e293b; }
body.light-theme .perf-tbl tfoot td { color: #0f172a; background: rgba(14, 165, 233, 0.08); border-top-color: rgba(14, 165, 233, 0.24); }
body.light-theme .perf-linkbtn { color: #1d4ed8; }
body.light-theme .perf-tbl tbody tr:nth-child(even) td { background: rgba(15, 23, 42, 0.02); }
body.light-theme .perf-hero { background: rgba(16, 185, 129, 0.08); }
body.light-theme .perf-hero .perf-card-lbl { color: #047857; }
body.light-theme .so-info-tooltip-trigger {
    background: #e0f2fe;
    border-color: #7dd3fc;
    color: #0369a1;
}
body.light-theme .so-info-tooltip-panel,
body.light-theme .so-info-tooltip-panel::before {
    background: #ffffff;
}
body.light-theme .so-info-tooltip-panel {
    border-color: #bae6fd;
    color: #334155;
    box-shadow: 0 16px 34px rgba(15, 23, 42, 0.18);
}
body.light-theme .so-info-tooltip-panel b { color: #0f172a; }
body.light-theme .so-info-tooltip-panel span { color: #475569; }

@media (max-width: 640px) {
    .perf-row-grid {
        grid-template-columns: 1fr;
    }
}

/* =========================================================================
   DRILL-DOWN v2  (.dd-*)  — self-contained, tokenized, RTL.
   Dark-first analytics surface; neutrals tinted toward the dashboard indigo.
   Colour encodes meaning: money=emerald, balance=cyan, cheque=amber,
   source=indigo, danger=red. No glass-as-default, no side-stripe accents.
   ========================================================================= */
.dd-root {
    /* surfaces */
    --dd-bg:        oklch(0.175 0.022 270);
    --dd-surface:   oklch(0.214 0.026 270);
    --dd-surface-2: oklch(0.252 0.030 270);
    --dd-surface-3: oklch(0.300 0.034 270);
    --dd-border:    oklch(0.380 0.030 270 / 0.55);
    --dd-border-2:  oklch(0.470 0.040 270 / 0.85);
    /* text */
    --dd-text:      oklch(0.965 0.008 270);
    --dd-muted:     oklch(0.745 0.022 270);
    --dd-faint:     oklch(0.615 0.024 270);
    /* semantic roles */
    --dd-accent:    oklch(0.735 0.135 274);
    --dd-money:     oklch(0.800 0.140 168);
    --dd-balance:   oklch(0.815 0.115 205);
    --dd-cheque:    oklch(0.830 0.150 78);
    --dd-source:    oklch(0.745 0.130 276);
    --dd-danger:    oklch(0.700 0.165 24);
    color: var(--dd-text);
    direction: rtl;
}

/* ---- modal shell ---- */
.dd-overlay.hidden { display: none !important; }
.dd-overlay {
    position: fixed; inset: 0; z-index: 999999;
    display: flex; align-items: flex-start; justify-content: center;
    padding: clamp(8px, 3vw, 32px);
    /* Clear the notch / home indicator on mobile. */
    padding-top: max(clamp(8px, 3vw, 32px), env(safe-area-inset-top));
    padding-bottom: max(clamp(8px, 3vw, 32px), env(safe-area-inset-bottom));
    background: oklch(0.12 0.02 270 / 0.74);
    overflow-y: auto;
    animation: ddFade .18s cubic-bezier(0.22, 1, 0.36, 1);
}
.dd-shell {
    width: 100%; max-width: 1180px; margin: auto;
    background: var(--dd-bg);
    border: 1px solid var(--dd-border);
    border-radius: 16px;
    box-shadow: 0 24px 60px oklch(0.08 0.02 270 / 0.55);
    display: flex; flex-direction: column;
    max-height: calc(100vh - clamp(16px, 6vw, 64px));
    max-height: calc(100dvh - clamp(16px, 6vw, 64px)); /* dynamic vh on mobile */
    overflow: hidden;
    animation: ddRise .22s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes ddFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes ddRise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
    .dd-overlay, .dd-shell { animation: none; }
}

/* ---- sticky header + inline metric strip ---- */
.dd-head {
    position: sticky; top: 0; z-index: 2;
    background: linear-gradient(180deg, var(--dd-surface), var(--dd-bg));
    border-bottom: 1px solid var(--dd-border);
    padding: 16px 20px 14px;
}
.dd-head-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.dd-title { font-size: 17px; font-weight: 800; color: var(--dd-text); line-height: 1.4; }
.dd-subtitle { font-size: 11.5px; color: var(--dd-muted); margin-top: 3px; }
.dd-close {
    flex: 0 0 auto;
    width: 36px; height: 36px; border-radius: 9px;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--dd-surface-2); border: 1px solid var(--dd-border);
    color: var(--dd-muted); cursor: pointer;
    transition: color .15s ease, background-color .15s ease, border-color .15s ease;
}
.dd-close:hover { color: var(--dd-text); background: var(--dd-surface-3); border-color: var(--dd-border-2); }
.dd-close:focus-visible { outline: 2px solid var(--dd-accent); outline-offset: 2px; }

.dd-metrics { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.dd-metric {
    display: inline-flex; align-items: baseline; gap: 7px;
    padding: 7px 12px; border-radius: 9px;
    background: var(--dd-surface);
    border: 1px solid var(--dd-border);
    border-top: 2px solid var(--role, var(--dd-accent));
}
.dd-metric-val { font-size: 15px; font-weight: 850; color: var(--dd-text); }
.dd-metric-lbl { font-size: 11px; font-weight: 600; color: var(--dd-muted); }
.dd-metric.is-money   { --role: var(--dd-money); }
.dd-metric.is-balance { --role: var(--dd-balance); }
.dd-metric.is-cheque  { --role: var(--dd-cheque); }
.dd-metric.is-source  { --role: var(--dd-source); }
.dd-metric.is-vol     { --role: var(--dd-accent); }

/* ---- scrollable body ---- */
.dd-body { padding: 18px 20px 22px; overflow-y: auto; }
.dd-section { margin-top: 18px; }
.dd-section:first-child { margin-top: 0; }
.dd-section-head {
    display: flex; align-items: center; gap: 8px;
    font-size: 13px; font-weight: 700; color: var(--dd-text); margin-bottom: 10px;
}
.dd-section-head i { color: var(--role, var(--dd-accent)); }
.dd-section.is-cheque  { --role: var(--dd-cheque); }
.dd-section.is-balance { --role: var(--dd-balance); }
.dd-section.is-money   { --role: var(--dd-money); }
.dd-section.is-source  { --role: var(--dd-source); }

/* ---- adaptive table ---- */
.dd-tablewrap {
    border: 1px solid var(--dd-border); border-radius: 12px;
    overflow: auto; max-height: 56vh;
}
.dd-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.dd-table thead th {
    position: sticky; top: 0; z-index: 1;
    background: var(--dd-surface-2);
    color: var(--dd-muted); font-weight: 700; text-align: right;
    padding: 10px 11px; white-space: nowrap;
    border-bottom: 1px solid var(--dd-border);
}
.dd-table th.is-num, .dd-table td.is-num { text-align: center; }
.dd-table tbody td { padding: 9px 11px; color: var(--dd-text); border-bottom: 1px solid var(--dd-border); }
.dd-table tbody tr:nth-child(even) td { background: oklch(0.97 0.01 270 / 0.022); }
.dd-table tbody tr:hover td { background: oklch(0.735 0.135 274 / 0.09); }
.dd-table tfoot td {
    padding: 11px; font-weight: 800; color: var(--dd-text);
    background: var(--dd-surface-2);
    border-top: 1px solid var(--dd-border-2); white-space: nowrap;
}
.dd-ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }

.dd-pill {
    display: inline-flex; align-items: center;
    padding: 2px 9px; border-radius: 7px; font-weight: 700; font-size: 11.5px;
    background: oklch(0.800 0.140 168 / 0.16); color: var(--dd-money);
}
.dd-pill.is-balance { background: oklch(0.815 0.115 205 / 0.16); color: var(--dd-balance); }
.dd-pill.is-danger  { background: oklch(0.700 0.165 24 / 0.16);  color: var(--dd-danger); }
.dd-pill.is-muted   { background: var(--dd-surface-3); color: var(--dd-muted); }

.dd-link {
    display: inline-flex; align-items: center; gap: 5px;
    background: none; border: 0; padding: 0; cursor: pointer;
    color: var(--dd-accent); font-weight: 700; font-size: 11.5px; font-family: inherit;
}
.dd-link:hover { text-decoration: underline; }
.dd-link.is-faint { color: var(--dd-faint); }
.dd-cell-sub { display: block; font-size: 10.5px; color: var(--dd-faint); margin-top: 2px; }

/* status badge (cheque collection / state) */
.dd-badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; white-space: nowrap;
}
.dd-badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.dd-badge.is-collected { background: oklch(0.800 0.140 168 / 0.15); color: var(--dd-money); }
.dd-badge.is-returned  { background: oklch(0.700 0.165 24 / 0.16);  color: var(--dd-danger); }
.dd-badge.is-pending   { background: oklch(0.830 0.150 78 / 0.16);  color: var(--dd-cheque); }
.dd-badge.is-neutral   { background: var(--dd-surface-3); color: var(--dd-muted); }

/* aging chip for outstanding balance */
.dd-age { font-size: 11px; font-weight: 700; }
.dd-age.is-fresh { color: var(--dd-money); }
.dd-age.is-warn  { color: var(--dd-cheque); }
.dd-age.is-stale { color: var(--dd-danger); }

.dd-empty {
    padding: 28px 16px; text-align: center;
    color: var(--dd-faint); font-size: 12.5px;
    border: 1px dashed var(--dd-border); border-radius: 12px;
}
.dd-empty i { display: block; font-size: 22px; margin-bottom: 8px; opacity: 0.5; }

/* ---- collapsible export panel (top-anchored, prominent) ---- */
.dd-export { margin: 0 0 16px; border: 1px solid var(--dd-border); border-top: 2px solid var(--dd-accent); border-radius: 12px; overflow: hidden; background: var(--dd-surface-2); }
.dd-export > summary {
    list-style: none; cursor: pointer; user-select: none;
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 13px 16px; font-size: 13px; font-weight: 800; color: var(--dd-text);
    transition: background-color .15s ease;
}
.dd-export > summary:hover { background: var(--dd-surface-3); }
.dd-export > summary:focus-visible { outline: 2px solid var(--dd-accent); outline-offset: -2px; }
.dd-export-label { display: inline-flex; align-items: center; gap: 8px; }
.dd-export-label > i { color: var(--dd-accent); margin-inline-end: 2px; }
.dd-export-quick { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.dd-export-toggle { display: inline-flex; align-items: center; gap: 6px; padding-inline-start: 4px; color: var(--dd-muted); }
.dd-btn-sm { padding: 6px 12px; font-size: 11.5px; }
.dd-export > summary::-webkit-details-marker { display: none; }
.dd-export > summary .dd-chev { transition: transform .2s ease; color: var(--dd-muted); }
.dd-export[open] > summary .dd-chev { transform: rotate(180deg); }
.dd-export > summary .dd-tag { font-size: 10.5px; font-weight: 600; color: var(--dd-faint); }
.dd-export-body { padding: 0 14px 14px; }
.dd-field-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 10px; }
.dd-search {
    flex: 1 1 180px; min-width: 140px;
    background: var(--dd-bg); border: 1px solid var(--dd-border); border-radius: 8px;
    color: var(--dd-text); font-size: 12px; padding: 7px 10px; font-family: inherit;
}
.dd-search:focus-visible { outline: 2px solid var(--dd-accent); outline-offset: 1px; }
.dd-btn {
    display: inline-flex; align-items: center; gap: 6px;
    border-radius: 8px; font-size: 11.5px; font-weight: 700; cursor: pointer;
    padding: 7px 12px; font-family: inherit; transition: filter .15s ease, background-color .15s ease;
    border: 1px solid var(--dd-border); background: var(--dd-surface-2); color: var(--dd-text);
}
.dd-btn:hover { background: var(--dd-surface-3); }
.dd-btn:focus-visible { outline: 2px solid var(--dd-accent); outline-offset: 1px; }
.dd-btn.is-ghost { background: transparent; }
.dd-btn.is-primary { background: var(--dd-accent); border-color: transparent; color: oklch(0.16 0.02 270); }
.dd-btn.is-primary:hover { filter: brightness(1.08); }
.dd-preset { font-size: 11px; padding: 5px 10px; }
.dd-preset.is-active { background: var(--dd-accent); border-color: transparent; color: oklch(0.16 0.02 270); }

.dd-fieldset { border: 1px solid var(--dd-border); border-radius: 9px; margin: 0 0 8px; padding: 0; overflow: hidden; }
.dd-fieldset > legend { float: none; width: 100%; }
.dd-fieldset-head {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    padding: 8px 11px; cursor: pointer; user-select: none;
    background: var(--dd-surface-2); font-size: 11.5px; font-weight: 700; color: var(--dd-text);
}
.dd-fieldset-head .dd-count { font-size: 10px; font-weight: 600; color: var(--dd-faint); }
.dd-fieldset-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 4px 12px;
    padding: 10px 12px;
}
.dd-fieldset.is-collapsed .dd-fieldset-grid { display: none; }
.dd-field {
    display: flex; align-items: center; gap: 8px;
    font-size: 11.5px; color: var(--dd-text); padding: 4px 2px; cursor: pointer;
}
.dd-field input { width: 16px; height: 16px; accent-color: var(--dd-accent); flex: 0 0 auto; }
.dd-field.is-hidden { display: none; }
.dd-export-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.dd-export-actions .dd-split { display: inline-flex; }
.dd-export-actions .dd-split .dd-btn:first-child { border-start-end-radius: 0; border-end-end-radius: 0; }
.dd-export-actions .dd-split .dd-btn:last-child { border-start-start-radius: 0; border-end-start-radius: 0; border-inline-start: 0; }

/* formula / criteria blocks for dedicated views */
.dd-note { background: var(--dd-surface); border: 1px solid var(--dd-border); border-radius: 11px; padding: 12px 14px; }
.dd-note-title { font-size: 12.5px; font-weight: 800; margin-bottom: 6px; color: var(--role, var(--dd-accent)); }
.dd-note-body { font-size: 12px; color: var(--dd-muted); line-height: 1.75; }
.dd-grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.dd-kv { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding: 5px 0; border-bottom: 1px dashed var(--dd-border); font-size: 11.5px; }
.dd-kv:last-child { border-bottom: 0; }
.dd-kv-k { color: var(--dd-faint); }
.dd-kv-v { color: var(--dd-text); font-weight: 700; }

/* mini distribution bars (conversion-time) */
.dd-dist { display: flex; flex-direction: column; gap: 7px; }
.dd-dist-row { display: grid; grid-template-columns: 96px 1fr 52px; align-items: center; gap: 10px; font-size: 11.5px; }
.dd-dist-lbl { color: var(--dd-muted); white-space: nowrap; }
.dd-dist-track { height: 9px; border-radius: 999px; background: var(--dd-surface-3); overflow: hidden; }
.dd-dist-fill { height: 100%; border-radius: 999px; background: var(--dd-accent); }
.dd-dist-val { color: var(--dd-text); font-weight: 700; text-align: center; }

@media (max-width: 640px) {
    .dd-body { padding: 14px 12px 18px; }
    .dd-head { padding: 13px 13px 11px; }
    .dd-fieldset-grid { grid-template-columns: 1fr; }
    .dd-dist-row { grid-template-columns: 78px 1fr 44px; }
}

/* ---- light-theme mapping (free, all token-driven) ---- */
body.light-theme .dd-root {
    --dd-bg:        oklch(0.985 0.004 270);
    --dd-surface:   oklch(0.965 0.006 270);
    --dd-surface-2: oklch(0.935 0.008 270);
    --dd-surface-3: oklch(0.900 0.010 270);
    --dd-border:    oklch(0.840 0.014 270 / 0.9);
    --dd-border-2:  oklch(0.740 0.020 270);
    --dd-text:      oklch(0.255 0.022 270);
    --dd-muted:     oklch(0.470 0.024 270);
    --dd-faint:     oklch(0.580 0.022 270);
    --dd-accent:    oklch(0.520 0.150 274);
    --dd-money:     oklch(0.560 0.140 168);
    --dd-balance:   oklch(0.560 0.120 215);
    --dd-cheque:    oklch(0.600 0.140 70);
    --dd-source:    oklch(0.520 0.140 276);
    --dd-danger:    oklch(0.560 0.180 26);
}
body.light-theme .dd-overlay { background: oklch(0.45 0.02 270 / 0.42); }
body.light-theme .dd-btn.is-primary,
body.light-theme .dd-preset.is-active { color: oklch(0.99 0.004 270); }
/* ========================================
   MOBILE BOTTOM TAB BAR + FAB
   Thumb-zone navigation (phones only). Lives below modal backdrops
   (z-index 50+) so any open modal's full-screen backdrop covers it,
   and below the sidebar drawer (z 999999) so "More" overlays it.
   Logical properties (inset-inline) keep it correct in RTL.
   ======================================== */
.mobile-bottom-nav { display: none; }

@media (max-width: 768px) {
    .mobile-bottom-nav {
        position: fixed;
        inset-inline: 0;
        bottom: 0;
        z-index: 40;
        display: flex;
        justify-content: space-around;
        align-items: stretch;
        background: var(--bg-panel);
        border-top: 1px solid var(--border-color);
        padding-bottom: env(safe-area-inset-bottom, 0px);
        box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.25);
    }

    .mobile-tab {
        flex: 1 1 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        min-height: 56px;
        padding: 6px 2px;
        background: none;
        border: none;
        color: var(--text-secondary);
        font-family: inherit;
        font-size: 10px;
        font-weight: 600;
        cursor: pointer;
        transition: color 0.2s;
    }

    .mobile-tab i { font-size: 18px; }
    .mobile-tab span { line-height: 1; }
    .mobile-tab.active { color: var(--accent-color); }
    .mobile-tab:active { transform: scale(0.95); }

    /* Context-aware primary create button, floating above the tab bar */
    .mobile-fab {
        position: fixed;
        inset-inline-start: 16px; /* RTL start = right edge = right-thumb zone */
        bottom: calc(56px + env(safe-area-inset-bottom, 0px) + 16px);
        z-index: 62; /* above the sticky pagination (z 60) so + is never covered */
        width: 56px;
        height: 56px;
        border-radius: 50%;
        border: none;
        background: linear-gradient(135deg, #ca8a04, #eab308);
        color: #111827;
        font-size: 22px;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 6px 18px rgba(234, 179, 8, 0.4);
        cursor: pointer;
        transition: transform 0.2s, box-shadow 0.2s;
    }

    .mobile-fab:active { transform: scale(0.92); }
    .mobile-fab.hidden { display: none !important; }
}

/* ========================================
   PHASE 2: MOBILE MODAL SAFETY (all modals)
   The full-screen treatment above is an ID allowlist; every other modal
   (KPI, DealDetails, Didar*, Course, change-password, ...) rendered as a
   centered desktop box that overflowed the viewport on phones. Constrain
   each modal panel to the viewport with internal scroll, and keep it clear
   of the notch / home indicator. ID-specificity lets the full-screen
   allowlist above still win for its six modals.
   ======================================== */
@media (max-width: 768px) {
    [id^="modal"] > .glass {
        max-width: 100%;
        max-height: calc(100dvh - 24px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        margin-block: calc(12px + env(safe-area-inset-top, 0px)) calc(12px + env(safe-area-inset-bottom, 0px));
    }

    /* Header icon buttons: compact 40px tap target (not bulky). */
    header button {
        min-width: 40px;
        min-height: 40px;
    }
}

/* ===========================================================================
   P2b — Deal list cards: compact on mobile (mobile-only; desktop grid card
   unchanged). The card stacks full-width on phones with 20px padding and three
   nested info mini-cards, making it ~300px tall. Trim padding, inter-section
   margins, nested-card padding and footer gap to cut ~40% height.
   =========================================================================== */
@media (max-width: 768px) {
    #deals-container .glass { padding: 12px; }
    #deals-container .glass .mb-4 { margin-bottom: 9px; }
    #deals-container .glass .space-y-2 > * + * { margin-top: 6px; }
    #deals-container .glass .p-2\.5 { padding: 7px 9px; }
    #deals-container .glass .p-2 { padding: 6px 8px; }
    #deals-container .glass .pt-4 { padding-top: 9px; }
}

/* ===========================================================================
   P3b/P3c — Deal-detail modal + create/edit form density (mobile-only).
   The lead/deal/activity create forms already present as bottom sheets; inputs
   are already 38px from the global control rule. This trims the spacing
   *between* fields and the deal lead-summary block. Outer .glass padding is
   left alone so the bottom-sheet safe-area-inset handling is preserved.
   =========================================================================== */
@media (max-width: 768px) {
    #modalDeal .space-y-5 > * + * { margin-top: 12px; }
    #modalDeal .space-y-4 > * + *,
    #modalLead .space-y-4 > * + *,
    #modalActivity .space-y-4 > * + * { margin-top: 10px; }
    #modalDeal .space-y-3 > * + *,
    #modalLead .space-y-3 > * + *,
    #modalActivity .space-y-3 > * + * { margin-top: 8px; }

    /* Deal lead-summary block: smaller heading + trimmed nested info cards. */
    #modalDeal #deal-summary-name { font-size: 15px; }
    #modalDeal .bg-gray-900\/40.p-4 { padding: 10px; margin-bottom: 12px; }
    #modalDeal .bg-gray-800\/40.p-2 { padding: 6px 8px; }
}

/* ===========================================================================
   P4 — Dashboard / KPI compaction (mobile-only). Top stat cards stacked
   full-width with 24px numbers; pull them 2-up, shrink the hero numbers to
   20px, and trim section-card padding so the dashboard isn't an endless
   scroll of big panels. Desktop (md/lg grid) unchanged.
   =========================================================================== */
@media (max-width: 768px) {
    /* Top stat cards: 2-up instead of full-width stacks. */
    #dashboard-content > .grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    #dashboard-content .glass { padding: 12px; }
    /* Hero numbers down from 24/20px. */
    #dashboard-content .text-2xl { font-size: 20px; }
    #dashboard-content .text-xl { font-size: 18px; }
    /* Pipeline / stage cells. */
    #dashboard-content .p-3 { padding: 8px; }
    #dashboard-content h3.text-lg { font-size: 15px; }
    /* Dashboard filter bar: tighter. */
    #dashboard-filters { padding: 10px; gap: 8px; margin-bottom: 12px; }
}

/* ===========================================================================
   MOBILE GESTURES — feedback styles (the engine lives in app.js).
   - View slide-in when switching tabs by swipe.
   - The bottom-sheet drag handles opt out of native scroll so the dismiss
     drag is smooth (they aren't scrollable, so this is safe).
   =========================================================================== */
@keyframes viewSwipeInL { from { opacity: 0.45; transform: translateX(26px); } to { opacity: 1; transform: none; } }
@keyframes viewSwipeInR { from { opacity: 0.45; transform: translateX(-26px); } to { opacity: 1; transform: none; } }
@media (max-width: 768px) {
    .view-swipe-in-l { animation: viewSwipeInL 0.22s ease-out; }
    .view-swipe-in-r { animation: viewSwipeInR 0.22s ease-out; }
    .bottom-sheet-grip, .bottom-sheet-header { touch-action: none; }
    /* Bigger, clearer drag affordance on the sheet grip. */
    .bottom-sheet-grip { width: 44px; height: 5px; cursor: grab; }
}

/* ===========================================================================
   SHARED SEMANTIC COMPONENT LAYER (mobile-only)
   Distilled from the commission / payment-cheque / access-request sections,
   which all use one recipe: a status = a hue, applied as bg 15-18%, border
   60%, text 300-level, accent bar 85%. These reusable classes let the plain
   pages (leads, deals, dashboard, profile, notifications) adopt the same
   color-coded look by adding classes only — no behaviour change. All scoped to
   mobile so desktop is untouched.
   =========================================================================== */
@media (max-width: 768px) {
    /* Status palette: set CSS vars per state; pill/accent read them. */
    .s--success { --s-bg: rgba(16,185,129,0.16); --s-fg: #6ee7b7; --s-bd: rgba(16,185,129,0.55); --s-accent: rgba(16,185,129,0.9); }
    .s--danger  { --s-bg: rgba(239,68,68,0.16);  --s-fg: #fca5a5; --s-bd: rgba(239,68,68,0.55);  --s-accent: rgba(239,68,68,0.9); }
    .s--pending { --s-bg: rgba(234,179,8,0.16);  --s-fg: #fde047; --s-bd: rgba(234,179,8,0.55);  --s-accent: rgba(234,179,8,0.9); }
    .s--info    { --s-bg: rgba(59,130,246,0.16); --s-fg: #93c5fd; --s-bd: rgba(59,130,246,0.5);  --s-accent: rgba(59,130,246,0.9); }
    .s--warning { --s-bg: rgba(249,115,22,0.16); --s-fg: #fdba74; --s-bd: rgba(249,115,22,0.5);  --s-accent: rgba(249,115,22,0.9); }
    .s--neutral { --s-bg: rgba(148,163,184,0.14);--s-fg: #cbd5e1; --s-bd: rgba(148,163,184,0.34);--s-accent: rgba(148,163,184,0.6); }
    /* Customer-tier metals (distinct from the semantic states above). */
    .s--gold    { --s-bg: rgba(234,179,8,0.18);  --s-fg: #fcd34d; --s-bd: rgba(234,179,8,0.6);   --s-accent: rgba(234,179,8,0.95); }
    .s--silver  { --s-bg: rgba(148,163,184,0.20);--s-fg: #e5e7eb; --s-bd: rgba(203,213,225,0.6); --s-accent: rgba(203,213,225,0.9); }
    .s--bronze  { --s-bg: rgba(180,83,9,0.20);   --s-fg: #fdba74; --s-bd: rgba(180,83,9,0.6);    --s-accent: rgba(217,119,6,0.9); }

    /* Status pill */
    .s-pill {
        display: inline-flex; align-items: center; gap: 5px;
        padding: 3px 9px; border-radius: 999px;
        font-size: 11px; font-weight: 700; line-height: 1.4;
        white-space: nowrap;
        background: var(--s-bg, rgba(148,163,184,0.14));
        color: var(--s-fg, #cbd5e1);
        border: 1px solid var(--s-bd, rgba(148,163,184,0.34));
    }
    .s-pill > i { font-size: 10px; }

    /* Accent-bar card: a colored stripe on the inline-start edge (right in RTL),
       coloured by the status modifier on the same element. */
    .accent-card { position: relative; overflow: hidden; }
    .accent-card::before {
        content: ""; position: absolute; inset-inline-start: 0; top: 0;
        width: 3px; height: 100%;
        background: var(--s-accent, rgba(148,163,184,0.5));
    }

    /* Info tile: muted label over a semibold value on a dark surface. */
    .info-tile {
        background: rgba(15,23,42,0.55);
        border: 1px solid rgba(148,163,184,0.16);
        border-radius: 8px; padding: 7px 9px; min-width: 0;
    }
    .info-tile__label { font-size: 10.5px; font-weight: 700; color: #9ca3af; margin-bottom: 2px; }
    .info-tile__value { font-size: 12.5px; font-weight: 600; color: #f3f4f6; word-break: break-word; }

    /* Money chip: emerald-tinted amount highlight. */
    .money-chip {
        display: inline-flex; align-items: center;
        background: rgba(16,185,129,0.12); color: #a7f3d0;
        font-weight: 700; padding: 2px 8px; border-radius: 6px;
    }
}

/* Light-theme parity for the tile/value text (keeps the existing theme tokens). */
@media (max-width: 768px) {
    body.light-theme .info-tile { background: #f8fafc; border-color: #e2e8f0; }
    body.light-theme .info-tile__label { color: #64748b; }
    body.light-theme .info-tile__value { color: #0f172a; }
}

/* Dashboard stat cards: tint subtly by their existing accent border so the top
   KPIs read as colour-coded, and colour the success/fail numbers (mobile-only;
   purely additive — the border-r-4 accent already exists on both viewports). */
@media (max-width: 768px) {
    #dashboard-content .border-blue-500 { background: rgba(59,130,246,0.07); }
    #dashboard-content .border-green-500 { background: rgba(16,185,129,0.08); }
    #dashboard-content .border-red-500 { background: rgba(239,68,68,0.08); }
    #dashboard-content .border-green-500 .text-2xl { color: #6ee7b7; }
    #dashboard-content .border-red-500 .text-2xl { color: #fca5a5; }
}

/* ===========================================================================
   COMPONENT POLISH (mobile-only) — tactile feedback, depth, smooth motion.
   Lifts every surface that already uses the shared classes above.
   =========================================================================== */
@media (max-width: 768px) {
    .lead-card-mobile,
    #deals-container .glass,
    .accent-card,
    .info-tile,
    .s-pill,
    .lcm-call {
        transition: transform 0.14s ease, box-shadow 0.2s ease, border-color 0.2s ease, background 0.15s ease;
    }

    /* Cards: subtle depth + press feedback. */
    .lead-card-mobile { box-shadow: 0 1px 2px rgba(0,0,0,0.18); }
    .lead-card-mobile:active,
    #deals-container .glass:active,
    .info-tile:active { transform: scale(0.985); }

    /* Accent stripe: soft status-coloured glow + rounded inner cap. */
    .accent-card::before {
        border-radius: 2px;
        box-shadow: 0 0 10px -2px var(--s-accent, transparent);
    }

    /* Status pill: crisper edge, aligned icon. */
    .s-pill { box-shadow: inset 0 1px 0 rgba(255,255,255,0.06); letter-spacing: 0.1px; }
    .s-pill > i { opacity: 0.9; }

    /* Lead-card call button: pressable. */
    .lcm-call:active { transform: scale(0.9); background: rgba(255,255,255,0.12); }

    /* Money chip: tabular figures. */
    .money-chip { font-variant-numeric: tabular-nums; }

    /* Bottom sheet: deeper, softer shadow + clearer grip. */
    .bottom-sheet { box-shadow: 0 -12px 40px rgba(0,0,0,0.55); }
}

/* ===========================================================================
   SWIPE-TO-ACTION (mobile-only). A .swipe-row wraps the card; a .swipe-actions
   panel sits behind it at the inline-end; .swipe-content slides to reveal it.
   .swipe-actions is display:none off-mobile, so wrapping a shared card template
   is inert on desktop. The sliding content gets a solid bg so nothing bleeds
   through the (semi-transparent) glass card on top.
   =========================================================================== */
.swipe-actions { display: none; }
@media (max-width: 768px) {
    .swipe-row { position: relative; overflow: hidden; border-radius: 14px; }
    .swipe-actions {
        display: flex; position: absolute; inset-block: 0; inset-inline-end: 0;
        align-items: stretch; z-index: 0;
    }
    .swipe-actions button {
        width: 68px; border: 0; color: #fff; cursor: pointer;
        display: flex; flex-direction: column; align-items: center; justify-content: center;
        gap: 5px; font-size: 11px; font-weight: 700;
        transition: filter 0.15s ease;
    }
    .swipe-actions button:active { filter: brightness(1.15); }
    .swipe-actions button i { font-size: 16px; }
    .swipe-actions .sa-call { background: #0e7490; }
    .swipe-actions .sa-view { background: #4338ca; }
    .swipe-actions .sa-edit { background: #b45309; }
    .swipe-content {
        position: relative; z-index: 1; background: var(--bg-panel);
        touch-action: pan-y;
        transition: transform 0.22s cubic-bezier(0.22,1,0.36,1); will-change: transform;
    }
}

/* ===========================================================================
   DEEPER CARD POLISH — leads & deals (mobile-only).
   =========================================================================== */
@media (max-width: 768px) {
    /* Lead card: hairline border, a touch more presence on the name, wider
       accent, and a soft press-lift. */
    .lead-card-mobile {
        border: 1px solid rgba(148,163,184,0.10);
        box-shadow: 0 2px 6px rgba(0,0,0,0.22);
    }
    .lead-card-mobile .card-name { font-size: 14px; letter-spacing: 0.2px; }
    .lead-card-mobile .lcm-owner { color: #94a3b8; }
    .lead-card-mobile.accent-card::before { width: 4px; }

    /* Deal card: tighten the inner mini-cards' borders and lift the price so
       the amount reads first; wider accent to match the leads. */
    #deals-container .glass.accent-card::before { width: 4px; }
    #deals-container .glass .text-yellow-500.font-mono { font-size: 13px; }
    #deals-container .glass { box-shadow: 0 2px 8px rgba(0,0,0,0.24); }
}

/* ===========================================================================
   Mobile UX Phase A — cross-cutting refinements (codex-aware)
   (Tabular figures are already global via `body { font-variant-numeric }`.)
   =========================================================================== */

@media (max-width: 768px) {
    /* Drilldown close button: compact 40px tap target. */
    .dd-close { min-width: 40px; min-height: 40px; }

    /* Reclaim horizontal space on phones: the dense dashboards lose ~48px to
       the .view-section p-6 padding (only padding-top was overridden). */
    .view-section { padding-left: 12px; padding-right: 12px; }
}

/* ===========================================================================
   Mobile UX — dashboards/leads/deals: filters, headers, bottom-nav clearance
   (mobile-only; desktop unchanged)
   =========================================================================== */
@media (max-width: 768px) {
    /* (Bottom-nav clearance is already handled by .view-section padding-bottom
       and .sticky-pagination bottom offset — no extra main padding needed.) */

    /* --- Deals filter bar: the flex-wrap row crams 11 controls on a phone.
       Stack everything full-width; keep date pairs two-up. --- */
    #deals-filter-bar {
        /* Inline bar is hidden on phones; the filters open in a bottom sheet
           (the .bottom-sheet-content rule above re-shows it as a column). */
        display: none;
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        padding: 12px;
    }
    #deals-filter-bar > * { width: 100%; min-width: 0; }
    #deals-filter-bar .flex.flex-col { width: 100%; }
    #deals-filter-bar select,
    #deals-filter-bar input { width: 100%; min-width: 0; height: 40px; }
    #deals-filter-bar .flex.gap-2 { display: flex; width: 100%; }
    #deals-filter-bar .flex.gap-2 > input { flex: 1 1 0; width: auto; }
    #deals-filter-bar button { width: 100%; justify-content: center; }

    /* Quick-status chips (همه/جاری/موفق/ناموفق): 4 short chips read as a
       sparse left-huddle on a phone. Make them an even full-width segmented
       row, taller for touch, and drop the heavy active drop-shadow. */
    #view-deals .quick-filter-chip {
        flex: 1 1 0;
        min-width: 0;
        min-height: 34px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-size: 12px;
        padding: 6px 8px;
    }
    #view-deals .quick-filter-chip.active {
        box-shadow: none;
    }

    /* --- Trim the view header / filter card padding so the list starts
       higher up. --- */
    #view-deals .glass > .p-4,
    #view-leads .glass > .p-4 { padding: 12px; }

    /* Make the inner list scroller clear the bottom nav too (it has its own
       scroll context inside the glass card). */
    #deals-container, #leads-list { padding-bottom: 16px; }

    /* --- Lead/customer profile modal header: the action buttons used to
       flex-wrap into an uneven 2-row mess with the close (X) stranded. Lay
       them out as a tidy 2-up grid and pin the close to the corner. --- */
    #profile-header { position: relative; padding-top: 18px; }
    #profile-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        width: 100%;
    }
    #profile-actions > button {
        flex: none;
        width: 100%;
        min-height: 38px;
        font-size: 12.5px;
        margin: 0;
        white-space: nowrap;
    }
    /* Close (X) is the last child — lift it out of the grid into the corner. */
    #profile-actions > button:last-child {
        position: absolute;
        top: 8px;
        inset-inline-end: 8px;
        width: 40px;
        height: 40px;
        min-height: 0;
        padding: 0;
    }

    /* --- Profile "اطلاعات" (Info) tab: P3 density ---
       Desktop shows ~28 fields as a 3-4 column grid of glass cards. On mobile
       `grid-cols-1` stacked every card full-width into a giant scroll. Pack
       them into a dense 2-column label/value grid and trim the per-card chrome
       so the tab reads as a compact spec sheet instead of 28 panels. */
    #modalProfile .flex-1.p-6 { padding: 12px; }

    #profile-tab-info > .grid {
        grid-template-columns: 1fr 1fr;
        gap: 6px;
    }

    #profile-tab-info > .grid > .glass {
        padding: 7px 9px;
        border-radius: 8px;
        background: rgba(255, 255, 255, 0.03);
        border: 1px solid var(--border-color);
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }

    /* label (the small muted caption above each value) */
    #profile-tab-info > .grid > .glass > .text-xs,
    #profile-tab-info > .grid > .glass > .flex > .text-xs {
        font-size: 10.5px;
        margin-bottom: 1px;
        line-height: 1.3;
    }

    /* value */
    #profile-tab-info > .grid > .glass .font-bold {
        font-size: 12.5px;
        line-height: 1.35;
    }

    /* full-width description card sitting below the grid */
    #profile-tab-info > .glass {
        padding: 10px 11px;
    }
}

/* =========================================================================
   MOBILE DESIGN SYSTEM — P1 foundation (compact & refined)
   Every rule is scoped to <=768px; desktop rendering is intentionally
   unchanged. Pairs with the in-place control/card compaction above.
   ========================================================================= */
@media (max-width: 768px) {
    /* Type: tighten the Persian body rhythm. Desktop keeps its 1.7 from the
       base `body` rule; only mobile is pulled in to ~1.55 for density. */
    body { line-height: 1.55; }

    /* Deal-form numeric inputs: the desktop base rule pins these at 44px via
       higher specificity; re-compact them on mobile only. */
    #deal-form-tab-info .input:not(textarea) { min-height: 38px; }

    /* Denser list rhythm: cards sit 8px apart instead of the 16-20px Tailwind
       grid gaps, so 6-8 records fit per screen instead of ~3. */
    #leads-list,
    #deals-container,
    #blataklif-leads-list { gap: 8px; }
}

/* =========================================================================
   AI ASSISTANT — "دستیار SaleOs"  (Phase 1)
   A native, RTL-first surface layer. The accent is a calm cyan-teal so the
   assistant reads as "intelligent helper" without the purple-glow AI cliché,
   and it never competes with the app's gold primary, green deals, or red
   danger. Risk/status reuse the established semantic hues so meaning carries.
   Tokens are OKLCH (chroma eased toward the extremes) with hex fallbacks on
   the load-bearing accents. Everything is namespaced `.ai-*`.
   ========================================================================= */
:root {
    --ai-accent: #19b6c9;
    --ai-accent: oklch(0.74 0.115 210);
    --ai-accent-strong: #0fa0b4;
    --ai-accent-strong: oklch(0.66 0.13 215);
    --ai-accent-deep: oklch(0.58 0.12 245);          /* indigo lean, used only for depth in the mark */
    --ai-on-accent: #04181b;
    --ai-fg: oklch(0.9 0.04 210);
    --ai-fg-muted: oklch(0.74 0.02 230);
    --ai-surface: oklch(0.205 0.024 245);            /* drawer body, a touch cooler than --bg-panel */
    --ai-surface-2: oklch(0.255 0.028 245);          /* raised cards inside the drawer */
    --ai-surface-3: oklch(0.30 0.03 245);
    --ai-border: oklch(0.42 0.03 235 / 0.55);
    --ai-border-soft: oklch(0.5 0.03 235 / 0.32);
    --ai-glow: oklch(0.74 0.12 210 / 0.28);
    --ai-tint: oklch(0.74 0.115 210 / 0.12);         /* faint accent wash for AI surfaces */
    --ai-tint-strong: oklch(0.74 0.115 210 / 0.2);
    --ai-z-overlay: 99000;
    --ai-z-drawer: 99001;
    --ai-ease: cubic-bezier(0.22, 1, 0.36, 1);
}
body.light-theme {
    --ai-accent: #0e8fa3;
    --ai-accent: oklch(0.62 0.11 215);
    --ai-accent-strong: oklch(0.55 0.12 218);
    --ai-on-accent: #ffffff;
    --ai-fg: oklch(0.32 0.03 240);
    --ai-fg-muted: oklch(0.5 0.02 240);
    --ai-surface: oklch(0.99 0.004 230);
    --ai-surface-2: oklch(0.97 0.006 230);
    --ai-surface-3: oklch(0.94 0.008 230);
    --ai-border: oklch(0.84 0.01 230 / 0.9);
    --ai-border-soft: oklch(0.88 0.01 230 / 0.8);
    --ai-glow: oklch(0.62 0.11 215 / 0.22);
    --ai-tint: oklch(0.62 0.11 215 / 0.1);
    --ai-tint-strong: oklch(0.62 0.11 215 / 0.16);
}

/* ---- The AI mark: a small rounded badge with the depth gradient ---------- */
.ai-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 9px;
    color: var(--ai-on-accent);
    background: linear-gradient(135deg, var(--ai-accent), var(--ai-accent-deep));
    box-shadow: 0 2px 10px var(--ai-glow), inset 0 1px 0 rgba(255, 255, 255, 0.25);
    flex-shrink: 0;
    font-size: 13px;
}
.ai-mark--lg { width: 36px; height: 36px; border-radius: 11px; font-size: 16px; }

/* ---- Launcher (header pill + sidebar entry) ------------------------------ */
.ai-launch {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px 7px 8px;
    border-radius: 999px;
    border: 1px solid var(--ai-border);
    background: var(--ai-tint);
    color: var(--ai-fg);
    font-size: 12.5px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    transition: border-color 0.18s var(--ai-ease), background-color 0.18s var(--ai-ease), transform 0.18s var(--ai-ease), box-shadow 0.18s var(--ai-ease);
}
.ai-launch.hidden,
.sidebar-item.ai-sidebar-item.hidden,
[data-ai-surface].hidden {
    display: none !important;
}
.ai-launch:hover { background: var(--ai-tint-strong); border-color: var(--ai-accent); transform: translateY(-1px); box-shadow: 0 6px 18px var(--ai-glow); }
.ai-launch:active { transform: translateY(0); }
.ai-launch .ai-mark { width: 24px; height: 24px; border-radius: 7px; font-size: 11px; }
.ai-launch__label { white-space: nowrap; }
.ai-launch--icon { padding: 8px; }                    /* compact icon-only variant for tight headers */
.ai-launch--icon .ai-launch__label { display: none; }

/* Sidebar variant reuses .sidebar-item spacing but carries the AI tint. */
.sidebar-item.ai-sidebar-item { display: flex; align-items: center; gap: 10px; }
.sidebar-item.ai-sidebar-item .ai-mark { width: 22px; height: 22px; border-radius: 6px; font-size: 10px; }

/* ---- Drawer scrim + panel ------------------------------------------------ */
.ai-drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(3, 8, 14, 0.55);
    backdrop-filter: blur(2px);
    z-index: var(--ai-z-overlay);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.26s var(--ai-ease);
}
.ai-drawer-overlay.active { opacity: 1; pointer-events: auto; }

.ai-drawer {
    position: fixed;
    top: 0;
    bottom: 0;
    inset-inline-end: 0;                               /* RTL: settles on the left edge of the viewport */
    width: 420px;
    max-width: 92vw;
    display: flex;
    flex-direction: column;
    background: var(--ai-surface);
    border-inline-start: 1px solid var(--ai-border);
    box-shadow: -24px 0 60px -20px rgba(0, 0, 0, 0.6);
    z-index: var(--ai-z-drawer);
    transform: translateX(-104%);                     /* off-screen to the inline-end (left in RTL) */
    transition: transform 0.32s var(--ai-ease);
    direction: rtl;
}
.ai-drawer.active { transform: translateX(0); }

.ai-drawer__header {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 16px 18px 14px;
    border-bottom: 1px solid var(--ai-border-soft);
    background: linear-gradient(180deg, var(--ai-tint), transparent);
}
.ai-drawer__title { font-size: 15px; font-weight: 800; color: var(--ai-fg); line-height: 1.3; }
.ai-drawer__hint {
    margin-top: 3px;
    font-size: 10.5px;
    font-weight: 600;
    color: var(--ai-fg-muted);
    display: flex;
    align-items: center;
    gap: 5px;
    line-height: 1.5;
}
.ai-drawer__hint i { color: var(--ai-accent); font-size: 10px; }
.ai-drawer__close {
    margin-inline-start: auto;
    width: 32px;
    height: 32px;
    border-radius: 9px;
    color: var(--ai-fg-muted);
    border: 1px solid transparent;
    background: transparent;
    cursor: pointer;
    flex-shrink: 0;
    transition: color 0.15s, background-color 0.15s, border-color 0.15s;
}
.ai-drawer__close:hover { color: var(--ai-fg); background: var(--ai-surface-2); border-color: var(--ai-border-soft); }

/* Mode tabs (پرسش / پیشنهاد / پیش‌نویس) */
.ai-modes { display: flex; gap: 6px; padding: 12px 16px 0; }
.ai-mode-tab {
    flex: 1;
    padding: 8px 6px;
    border-radius: 10px 10px 0 0;
    border: 1px solid transparent;
    border-bottom: none;
    background: transparent;
    color: var(--ai-fg-muted);
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: color 0.15s, background-color 0.15s;
}
.ai-mode-tab:hover { color: var(--ai-fg); }
.ai-mode-tab.is-active {
    color: var(--ai-fg);
    background: var(--ai-surface-2);
    border-color: var(--ai-border-soft);
}

/* Context chip row */
.ai-context-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--ai-border-soft);
    background: var(--ai-surface-2);
    font-size: 11px;
}
.ai-context-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--ai-tint);
    border: 1px solid var(--ai-border);
    color: var(--ai-fg);
    font-weight: 700;
    white-space: nowrap;
    max-width: 100%;
}
.ai-context-chip i { color: var(--ai-accent); font-size: 10px; }
.ai-context-chip__entity { color: var(--ai-fg-muted); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Scrolling conversation / response body */
.ai-drawer__body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Empty state that teaches the surface */
.ai-empty { text-align: center; padding: 22px 14px 8px; color: var(--ai-fg-muted); }
.ai-empty .ai-mark { margin: 0 auto 12px; }
.ai-empty__title { font-size: 13.5px; font-weight: 800; color: var(--ai-fg); margin-bottom: 4px; }
.ai-empty__text { font-size: 12px; line-height: 1.7; max-width: 34ch; margin: 0 auto; }

/* Suggested-prompt chips */
.ai-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.ai-chip {
    padding: 7px 12px;
    border-radius: 999px;
    border: 1px solid var(--ai-border-soft);
    background: var(--ai-surface-2);
    color: var(--ai-fg);
    font-size: 11.5px;
    font-weight: 600;
    line-height: 1.5;
    cursor: pointer;
    text-align: start;
    transition: border-color 0.15s var(--ai-ease), background-color 0.15s var(--ai-ease), transform 0.12s var(--ai-ease);
}
.ai-chip:hover { border-color: var(--ai-accent); background: var(--ai-tint); transform: translateY(-1px); }
.ai-chip i { color: var(--ai-accent); margin-inline-end: 5px; font-size: 10px; }

/* Chat bubbles */
.ai-msg { max-width: 90%; padding: 10px 13px; border-radius: 14px; font-size: 12.5px; line-height: 1.85; white-space: pre-wrap; word-break: break-word; }
.ai-msg--user { align-self: flex-start; background: var(--ai-accent); color: var(--ai-on-accent); border-bottom-right-radius: 5px; font-weight: 600; }
.ai-msg--ai { align-self: flex-end; background: var(--ai-surface-2); color: var(--ai-fg); border: 1px solid var(--ai-border-soft); border-bottom-left-radius: 5px; }
.ai-msg--ai strong { color: var(--ai-accent); font-weight: 800; }

/* Source chips (always shown with results) */
.ai-sources { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.ai-source-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    border-radius: 7px;
    background: oklch(0.5 0.02 235 / 0.16);
    border: 1px solid var(--ai-border-soft);
    color: var(--ai-fg-muted);
    font-size: 10px;
    font-weight: 700;
}
.ai-source-chip i { font-size: 9px; opacity: 0.8; }

/* Composer pinned to the foot of the drawer */
.ai-composer {
    border-top: 1px solid var(--ai-border-soft);
    background: var(--ai-surface-2);
    padding: 12px 14px;
    padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
}
.ai-composer__field {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--ai-surface);
    border: 1px solid var(--ai-border);
    border-radius: 14px;
    padding: 6px 6px 6px 12px;
    transition: border-color 0.15s var(--ai-ease), box-shadow 0.15s var(--ai-ease);
}
.ai-composer__field:focus-within { border-color: var(--ai-accent); box-shadow: 0 0 0 3px var(--ai-glow); }
.ai-composer textarea {
    flex: 1;
    resize: none;
    border: none;
    outline: none;
    background: transparent;
    color: var(--ai-fg);
    font-family: inherit;
    font-size: 12.5px;
    line-height: 1.7;
    max-height: 120px;
    padding: 5px 0;
}
.ai-composer textarea::placeholder { color: var(--ai-fg-muted); }
.ai-send {
    width: 38px;
    height: 38px;
    border-radius: 11px;
    border: none;
    background: linear-gradient(135deg, var(--ai-accent), var(--ai-accent-strong));
    color: var(--ai-on-accent);
    cursor: pointer;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.14s var(--ai-ease), box-shadow 0.14s var(--ai-ease), opacity 0.14s;
}
.ai-send:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 6px 16px var(--ai-glow); }
.ai-send:disabled { opacity: 0.45; cursor: not-allowed; }

/* =========================================================================
   In-context AI panels (brief / deal risk / activity draft / KPI / rule)
   ========================================================================= */
.ai-panel {
    border: 1px solid var(--ai-border);
    border-radius: 14px;
    background:
        radial-gradient(120% 140% at 100% 0%, var(--ai-tint), transparent 60%),
        var(--ai-surface-2);
    overflow: hidden;
}
.ai-panel__head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 14px;
}
.ai-panel__titles { min-width: 0; }
.ai-panel__title { font-size: 13px; font-weight: 800; color: var(--ai-fg); line-height: 1.3; }
.ai-panel__sub { font-size: 10.5px; color: var(--ai-fg-muted); font-weight: 600; margin-top: 1px; }
.ai-panel__cta {
    margin-inline-start: auto;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 14px;
    border-radius: 10px;
    border: 1px solid var(--ai-accent);
    background: var(--ai-tint-strong);
    color: var(--ai-fg);
    font-size: 12px;
    font-weight: 800;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color 0.16s var(--ai-ease), box-shadow 0.16s var(--ai-ease), transform 0.14s var(--ai-ease);
}
.ai-panel__cta:hover:not(:disabled) { background: var(--ai-accent); color: var(--ai-on-accent); box-shadow: 0 6px 16px var(--ai-glow); transform: translateY(-1px); }
.ai-panel__cta:disabled { opacity: 0.5; cursor: not-allowed; }
.ai-panel__body { padding: 0 14px 14px; }
.ai-panel--compact .ai-panel__head { padding: 9px 12px; }

/* Result blocks shared by brief/risk */
.ai-result { display: flex; flex-direction: column; gap: 12px; }
.ai-result__summary { font-size: 12.5px; line-height: 1.9; color: var(--ai-fg); }
.ai-result__section-label { font-size: 10.5px; font-weight: 800; letter-spacing: 0.02em; color: var(--ai-fg-muted); margin-bottom: 6px; text-transform: none; }

/* Reason / step list — leading dot, never a side stripe */
.ai-list { display: flex; flex-direction: column; gap: 6px; }
.ai-list__item {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    font-size: 12px;
    line-height: 1.7;
    color: var(--ai-fg);
    background: var(--ai-surface);
    border: 1px solid var(--ai-border-soft);
    border-radius: 10px;
    padding: 8px 11px;
}
.ai-list__item::before {
    content: "";
    width: 6px; height: 6px;
    margin-top: 8px;
    border-radius: 50%;
    background: var(--ai-accent);
    flex-shrink: 0;
}
.ai-list--warn .ai-list__item::before { background: #f59e0b; }

/* Next-action card */
.ai-next {
    display: flex;
    gap: 11px;
    align-items: flex-start;
    background: var(--ai-tint);
    border: 1px solid var(--ai-border);
    border-radius: 12px;
    padding: 11px 13px;
}
.ai-next__icon {
    width: 32px; height: 32px;
    border-radius: 9px;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--ai-accent); color: var(--ai-on-accent);
    flex-shrink: 0; font-size: 13px;
}
.ai-next__title { font-size: 12.5px; font-weight: 800; color: var(--ai-fg); }
.ai-next__reason { font-size: 11px; color: var(--ai-fg-muted); line-height: 1.7; margin-top: 2px; }

/* Draft note block with quick actions */
.ai-draft {
    background: var(--ai-surface);
    border: 1px dashed var(--ai-border);
    border-radius: 12px;
    padding: 11px 13px;
    font-size: 12px;
    line-height: 1.9;
    color: var(--ai-fg);
    white-space: pre-wrap;
    word-break: break-word;
}

/* Risk / status badges — reuse semantic meaning, AI-styled shell */
.ai-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 11px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 800;
    line-height: 1.4;
    border: 1px solid;
    white-space: nowrap;
}
.ai-badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: 0.9; }
.ai-badge--low { color: #34d399; background: rgba(16, 185, 129, 0.14); border-color: rgba(16, 185, 129, 0.5); }
.ai-badge--medium { color: #fbbf24; background: rgba(245, 158, 11, 0.14); border-color: rgba(245, 158, 11, 0.5); }
.ai-badge--high { color: #f87171; background: rgba(239, 68, 68, 0.15); border-color: rgba(239, 68, 68, 0.5); }
.ai-badge--neutral { color: var(--ai-fg-muted); background: var(--ai-surface); border-color: var(--ai-border-soft); }
.ai-badge--score { color: var(--ai-fg); background: var(--ai-tint); border-color: var(--ai-border); }
.ai-badge--score::before { display: none; }

/* Action row under a result */
.ai-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.ai-action {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 11px;
    border-radius: 9px;
    border: 1px solid var(--ai-border-soft);
    background: var(--ai-surface);
    color: var(--ai-fg);
    font-size: 11.5px;
    font-weight: 700;
    cursor: pointer;
    transition: border-color 0.15s, background-color 0.15s, transform 0.12s var(--ai-ease);
}
.ai-action:hover { border-color: var(--ai-accent); background: var(--ai-tint); transform: translateY(-1px); }
.ai-action i { font-size: 11px; color: var(--ai-accent); }
.ai-action--primary { border-color: var(--ai-accent); background: var(--ai-tint-strong); }

/* Feedback ("مفید بود / نبود") */
.ai-feedback { display: inline-flex; align-items: center; gap: 8px; font-size: 11px; color: var(--ai-fg-muted); }
.ai-feedback__btns { display: inline-flex; gap: 6px; }
.ai-feedback__btn {
    width: 30px; height: 28px;
    border-radius: 8px;
    border: 1px solid var(--ai-border-soft);
    background: var(--ai-surface);
    color: var(--ai-fg-muted);
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s, background-color 0.15s;
}
.ai-feedback__btn:hover { color: var(--ai-fg); border-color: var(--ai-accent); }
.ai-feedback__btn.is-up.is-active { color: #34d399; border-color: rgba(16,185,129,0.6); background: rgba(16,185,129,0.12); }
.ai-feedback__btn.is-down.is-active { color: #f87171; border-color: rgba(239,68,68,0.6); background: rgba(239,68,68,0.12); }
.ai-feedback__done { color: #34d399; font-weight: 700; }

/* Always-present caution line on draft / action surfaces */
.ai-disclaimer {
    display: flex;
    align-items: flex-start;
    gap: 7px;
    font-size: 10.5px;
    line-height: 1.6;
    color: var(--ai-fg-muted);
    background: rgba(245, 158, 11, 0.08);
    border: 1px solid rgba(245, 158, 11, 0.22);
    border-radius: 9px;
    padding: 7px 10px;
}
.ai-disclaimer i { color: #f59e0b; margin-top: 2px; flex-shrink: 0; }

/* Skeletons — reuse the app shimmer language */
.ai-skel { border-radius: 9px; background: linear-gradient(90deg, var(--ai-surface) 25%, var(--ai-surface-3) 50%, var(--ai-surface) 75%); background-size: 200% 100%; animation: shimmer 1.5s infinite; }
.ai-skel + .ai-skel { margin-top: 9px; }
.ai-skel--line { height: 11px; }
.ai-skel--w90 { width: 90%; } .ai-skel--w70 { width: 70%; } .ai-skel--w50 { width: 50%; }
.ai-skel--chip { height: 24px; width: 84px; border-radius: 999px; display: inline-block; }
.ai-skel--block { height: 58px; }

/* Inline error */
.ai-error {
    display: flex; align-items: flex-start; gap: 9px;
    font-size: 12px; line-height: 1.7;
    color: #fca5a5;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 11px;
    padding: 11px 13px;
}
.ai-error i { color: #f87171; margin-top: 2px; flex-shrink: 0; }
.ai-error button { color: var(--ai-fg); text-decoration: underline; background: none; border: none; cursor: pointer; font: inherit; font-size: 11px; }

/* Typing indicator */
.ai-typing { display: inline-flex; gap: 4px; align-items: center; padding: 12px 14px; }
.ai-typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--ai-accent); opacity: 0.4; animation: aiTyping 1.1s infinite; }
.ai-typing span:nth-child(2) { animation-delay: 0.15s; }
.ai-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes aiTyping { 0%, 60%, 100% { opacity: 0.3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

/* JSON preview for the operation-rule draft */
.ai-json {
    background: var(--ai-surface);
    border: 1px solid var(--ai-border-soft);
    border-radius: 10px;
    padding: 10px 12px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 11px;
    line-height: 1.7;
    color: var(--ai-fg);
    direction: ltr;
    text-align: left;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 180px;
    overflow: auto;
}

/* =========================================================================
   AI — responsive: the drawer becomes a near-full-height bottom sheet
   ========================================================================= */
@media (max-width: 768px) {
    .ai-drawer {
        inset-inline: 0;
        top: auto;
        bottom: 0;
        width: 100%;
        max-width: 100%;
        height: 90vh;
        height: 90dvh;
        border-inline-start: none;
        border-top: 1px solid var(--ai-border);
        border-radius: 20px 20px 0 0;
        transform: translateY(104%);
        box-shadow: 0 -22px 60px -20px rgba(0, 0, 0, 0.65);
    }
    .ai-drawer.active { transform: translateY(0); }
    .ai-drawer__grip {
        width: 40px; height: 4px; border-radius: 999px;
        background: var(--ai-border);
        margin: 8px auto 2px;
        flex-shrink: 0;
    }
    .ai-launch__label { display: none; }              /* header pill collapses to icon on phones */
    .ai-launch { padding: 8px; }
}
@media (min-width: 769px) {
    .ai-drawer__grip { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    .ai-drawer, .ai-drawer-overlay, .ai-launch, .ai-chip, .ai-action, .ai-panel__cta, .ai-send { transition: none; }
    .ai-skel, .ai-typing span { animation: none; }
}
