@font-face {
    font-family: 'Vazirmatn';
    font-style: normal;
    font-weight: 100;
    font-display: swap;
    src: url('/assets/vendor/fonts/vazirmatn/vazirmatn-arabic-100-normal.woff2') format('woff2');
}

@font-face {
    font-family: 'Vazirmatn';
    font-style: normal;
    font-weight: 300;
    font-display: swap;
    src: url('/assets/vendor/fonts/vazirmatn/vazirmatn-arabic-300-normal.woff2') format('woff2');
}

@font-face {
    font-family: 'Vazirmatn';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url('/assets/vendor/fonts/vazirmatn/vazirmatn-arabic-400-normal.woff2') format('woff2');
}

@font-face {
    font-family: 'Vazirmatn';
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url('/assets/vendor/fonts/vazirmatn/vazirmatn-arabic-600-normal.woff2') format('woff2');
}

@font-face {
    font-family: 'Vazirmatn';
    font-style: normal;
    font-weight: 800;
    font-display: swap;
    src: url('/assets/vendor/fonts/vazirmatn/vazirmatn-arabic-800-normal.woff2') format('woff2');
}

:root {
    /* Dark Theme (Default) */
    --bg-main: #0f172a;
    --bg-panel: #111827;
    --bg-card: #1f2937;
    --text-primary: #f8fafc;
    --text-secondary: #9ca3af;
    --border-color: #1f2937;
    --input-bg: #1e293b;
    --input-border: #334155;
    --glass-bg: rgba(30, 41, 59, 0.8);
    --glass-border: rgba(255,255,255,0.05);
    --bg-image: url('/assets/img/dark-matter.png');
    --primary-gradient-start: #ca8a04;
    --primary-gradient-end: #eab308;
    --accent-color: #eab308;
}

body.light-theme {
    /* Light Theme */
    --bg-main: #f1f5f9;
    --bg-panel: #ffffff;
    --bg-card: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --border-color: #e2e8f0;
    --input-bg: #ffffff;
    --input-border: #cbd5e1;
    --glass-bg: rgba(255, 255, 255, 0.9);
    --glass-border: rgba(0,0,0,0.05);
    --bg-image: none;
}

/* Tailwind Overrides for Light Theme */
body.light-theme .bg-gray-900,
body.light-theme .bg-slate-900 { background-color: var(--bg-panel) !important; }
body.light-theme .bg-gray-900\/50 { background-color: rgba(255, 255, 255, 0.8) !important; }
body.light-theme .bg-gray-900\/40 { background-color: rgba(241, 245, 249, 0.8) !important; }

body.light-theme .bg-gray-800 { background-color: var(--bg-card) !important; }
body.light-theme .bg-gray-800\/50 { background-color: rgba(255, 255, 255, 0.5) !important; }
body.light-theme .bg-gray-800\/40 { background-color: rgba(248, 250, 252, 0.8) !important; }
body.light-theme .bg-gray-800\/80 { background-color: rgba(255, 255, 255, 0.9) !important; }

body.light-theme .bg-gray-700 { background-color: #e2e8f0 !important; }
body.light-theme .bg-gray-700\/30 { background-color: rgba(226, 232, 240, 0.5) !important; }
body.light-theme .bg-gray-700\/50 { background-color: rgba(226, 232, 240, 0.8) !important; }

/* Gradient Overrides */
body.light-theme .from-blue-900\/30 { --tw-gradient-from: rgba(59, 130, 246, 0.1) !important; }
body.light-theme .to-purple-900\/30 { --tw-gradient-to: rgba(147, 51, 234, 0.1) !important; }

body.light-theme .hover\:bg-gray-700:hover { background-color: #cbd5e1 !important; }
body.light-theme .hover\:bg-gray-800\/50:hover { background-color: rgba(203, 213, 225, 0.5) !important; }
body.light-theme .hover\:bg-gray-800\/40:hover { background-color: rgba(203, 213, 225, 0.4) !important; }

body.light-theme .text-white { color: var(--text-primary) !important; }
body.light-theme .text-gray-100 { color: #0f172a !important; }
body.light-theme .text-gray-200 { color: #1e293b !important; }
body.light-theme .text-gray-300 { color: #334155 !important; }
body.light-theme .text-gray-400 { color: var(--text-secondary) !important; }
body.light-theme .text-gray-500 { color: #64748b !important; }

body.light-theme .border-gray-800,
body.light-theme .border-gray-700 { border-color: var(--border-color) !important; }
body.light-theme .divide-gray-700 > * + * { border-color: var(--border-color) !important; }

body.light-theme .hover\:text-white:hover { color: var(--text-primary) !important; }

/* Table Header Specific */
body.light-theme thead.bg-gray-800 { background-color: #f1f5f9 !important; color: #475569 !important; }
body.light-theme thead.bg-gray-800 th { color: #475569 !important; font-weight: 600 !important; }

/* Scrollbar refinement for light mode */
body.light-theme ::-webkit-scrollbar-thumb { background: #cbd5e1; }
body.light-theme ::-webkit-scrollbar-track { background: #f1f5f9; }

body { 
    font-family: 'Vazirmatn', sans-serif; 
    background: var(--bg-main); 
    background-image: var(--bg-image);
    color: var(--text-primary); 
}

/* Branding Watermark */
body::before {
    content: "";
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 600px;
    height: 600px;
    background-image: url('/public/logo.png');
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    opacity: 0.05;
    pointer-events: none;
    z-index: 0;
}

.glass { 
    background: var(--glass-bg); 
    backdrop-filter: blur(8px); 
    border: 1px solid var(--glass-border); 
    border-radius: 12px; 
}

.input { 
    background: var(--input-bg); 
    border: 1px solid var(--input-border); 
    color: var(--text-primary); 
    padding: 10px; 
    border-radius: 6px; 
    width: 100%; 
    transition: 0.2s; 
}

.input:focus { 
    border-color: var(--accent-color); 
    outline: none; 
}

.btn-primary { 
    background: linear-gradient(135deg, #ca8a04, #eab308); 
    color: black; 
    font-weight: bold; 
    transition: 0.3s; 
}

.btn-primary:hover { 
    box-shadow: 0 4px 12px rgba(234, 179, 8, 0.3); 
    transform: translateY(-1px); 
}

.sidebar-item { 
    padding: 12px; 
    margin: 4px 0; 
    border-radius: 8px; 
    cursor: pointer; 
    transition: 0.2s; 
    color: #94a3b8; 
    display: flex; 
    align-items: center; 
    gap: 10px; 
}

.sidebar-item:hover, .sidebar-item.active { 
    background: rgba(234, 179, 8, 0.1); 
    color: #eab308; 
}

::-webkit-scrollbar { 
    width: 6px; 
    height: 6px; 
}

::-webkit-scrollbar-thumb { 
    background: #475569; 
    border-radius: 3px; 
}

.deal-card { 
    transition: all 0.2s; 
}

.deal-card:hover {
    transform: translateY(-2px);
    border-color: #eab308;
}

/* Persian Date Picker Custom Styles */
.pdp-container {
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%) !important;
    border: 1px solid rgba(59, 130, 246, 0.3) !important;
    border-radius: 12px !important;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5) !important;
    padding: 15px !important;
    z-index: 9999 !important; /* Fixed: Below modal top layer */
    font-family: 'Vazirmatn', sans-serif !important;
}

.pdp-header {
    background: rgba(59, 130, 246, 0.1) !important;
    border-radius: 8px !important;
    padding: 10px !important;
    margin-bottom: 10px !important;
}

.pdp-header .pdp-header-title {
    color: #e2e8f0 !important;
    font-weight: 600 !important;
}

.pdp-day {
    color: #e2e8f0 !important;
    border-radius: 6px !important;
    transition: all 0.2s !important;
    margin: 2px !important;
    padding: 8px !important;
}

.pdp-day:hover {
    background: rgba(59, 130, 246, 0.2) !important;
    transform: scale(1.05) !important;
    color: #fff !important;
}

.pdp-day-selected {
    background: linear-gradient(135deg, #3b82f6, #8b5cf6) !important;
    color: #fff !important;
    font-weight: bold !important;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.4) !important;
}

.pdp-day-today {
    border: 2px solid #3b82f6 !important;
    font-weight: bold !important;
    color: #3b82f6 !important;
}

.pdp-day-other-month {
    color: #64748b !important;
    opacity: 0.5 !important;
}

.pdp-day-disabled {
    color: #475569 !important;
    opacity: 0.3 !important;
    cursor: not-allowed !important;
}

.pdp-weekday {
    color: #94a3b8 !important;
    font-weight: 600 !important;
    padding: 8px !important;
}

.pdp-navbar {
    background: transparent !important;
    border: none !important;
}

.pdp-navbar button {
    background: rgba(59, 130, 246, 0.1) !important;
    border: 1px solid rgba(59, 130, 246, 0.3) !important;
    color: #3b82f6 !important;
    border-radius: 6px !important;
    padding: 6px 12px !important;
    transition: all 0.2s !important;
}

.pdp-navbar button:hover {
    background: rgba(59, 130, 246, 0.2) !important;
    transform: scale(1.05) !important;
}

.pdp-time-picker {
    background: rgba(59, 130, 246, 0.1) !important;
    border-radius: 8px !important;
    padding: 10px !important;
}

.pdp-time-picker input {
    background: rgba(30, 41, 59, 0.8) !important;
    border: 1px solid rgba(59, 130, 246, 0.3) !important;
    color: #e2e8f0 !important;
    border-radius: 6px !important;
    padding: 8px !important;
}

.pdp-time-picker input:focus {
    border-color: #3b82f6 !important;
    outline: none !important;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1) !important;
}

/* Time Select Styling */
#activity-due-hour,
#activity-due-minute {
    background: rgba(30, 41, 59, 0.8) !important;
    border: 1px solid rgba(59, 130, 246, 0.3) !important;
    color: #e2e8f0 !important;
    border-radius: 6px !important;
    padding: 10px !important;
    transition: all 0.2s !important;
    font-weight: 500 !important;
}

#activity-due-hour:focus,
#activity-due-minute:focus {
    border-color: #3b82f6 !important;
    outline: none !important;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1) !important;
    background: rgba(30, 41, 59, 1) !important;
}

#activity-due-hour:hover,
#activity-due-minute:hover {
    border-color: rgba(59, 130, 246, 0.5) !important;
    background: rgba(30, 41, 59, 0.9) !important;
}

/* Schedule Fields Container */
#activity-schedule-fields {
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Notification Popup Styles */
.notification-popup {
    position: fixed;
    top: 80px;
    right: 20px;
    min-width: 300px;
    max-width: 400px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
    z-index: 9999;
    opacity: 0;
    transform: translateX(100%);
    transition: all 0.3s ease-in-out;
    direction: rtl;
    font-family: 'Vazirmatn', sans-serif;
}

/* Mobile: Fix notification popup width and position */
@media (max-width: 480px) {
    .notification-popup {
        min-width: calc(100% - 40px);
        max-width: calc(100% - 40px);
        right: 20px;
        left: 20px;
        top: 70px; /* Adjusted for mobile header */
    }
    
    /* Reduce stacking offset on mobile */
    .notification-popup:nth-child(2) { top: 140px; }
    .notification-popup:nth-child(3) { top: 210px; }
    .notification-popup:nth-child(4) { top: 280px; }
    .notification-popup:nth-child(5) { top: 350px; }
    .notification-popup:nth-child(n+6) {
        top: 160px !important;
    }
}

.notification-popup.show {
    opacity: 1;
    transform: translateX(0);
}

.notification-popup.hide {
    opacity: 0;
    transform: translateX(100%);
}

.notification-popup-content {
    padding: 16px;
    color: var(--text-primary);
}

.notification-popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    flex-direction: row;
}

.notification-popup-title {
    font-weight: bold;
    font-size: 14px;
    color: var(--text-primary);
}

.notification-popup-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: color 0.2s;
}

.notification-popup-close:hover {
    color: var(--text-primary);
}

.notification-popup-close-all {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: color 0.2s;
    font-size: 14px;
}

.notification-popup-close-all:hover {
    color: #ef4444; /* Red color for close all */
}

.notification-popup-message {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.4;
}

.notification-popup-footer {
    margin-top: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.notification-popup-time {
    font-size: 11px;
    color: #6b7280;
}

.notification-popup-actions {
    display: flex;
    gap: 8px;
}

.notification-popup-action {
    padding: 4px 8px;
    border: none;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    transition: background-color 0.2s;
    font-weight: 500;
}

.notification-popup-action.primary {
    background-color: #3b82f6;
    color: white;
}

.notification-popup-action.primary:hover {
    background-color: #2563eb;
}

.notification-popup-action.secondary {
    background-color: #6b7280;
    color: white;
}

.notification-popup-action.secondary:hover {
    background-color: #4b5563;
}

/* Stack multiple popups */
.notification-popup:nth-child(2) { top: 170px; }
.notification-popup:nth-child(3) { top: 260px; }
.notification-popup:nth-child(4) { top: 350px; }
.notification-popup:nth-child(5) { top: 440px; }
.notification-popup:nth-child(6) { top: 530px; }
.notification-popup:nth-child(7) { top: 620px; }
.notification-popup:nth-child(8) { top: 710px; }
.notification-popup:nth-child(9) { top: 800px; }
.notification-popup:nth-child(10) { top: 890px; }

/* For very small screens, reduce spacing */
@media (max-height: 900px) {
    .notification-popup:nth-child(2) { top: 140px; }
    .notification-popup:nth-child(3) { top: 210px; }
    .notification-popup:nth-child(4) { top: 280px; }
    .notification-popup:nth-child(5) { top: 350px; }
    .notification-popup:nth-child(6) { top: 420px; }
    .notification-popup:nth-child(7) { top: 490px; }
    .notification-popup:nth-child(8) { top: 560px; }
    .notification-popup:nth-child(9) { top: 630px; }
    .notification-popup:nth-child(10) { top: 700px; }
}

/* Light theme support for popups */
body.light-theme .notification-popup {
    background: var(--bg-panel);
    border-color: var(--border-color);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
}

body.light-theme .notification-popup-title {
    color: var(--text-primary);
}

body.light-theme .notification-popup-message {
    color: var(--text-secondary);
}

body.light-theme .notification-popup-close {
    color: var(--text-secondary);
}

body.light-theme .notification-popup-close:hover {
    color: var(--text-primary);
}
/* Quick Filter Chips */
.quick-filter-chip {
    padding: 6px 16px;
    border-radius: 9999px;
    font-size: 11px;
    font-weight: 700;
    transition: all 0.3s ease;
    white-space: nowrap;
    border-width: 1px;
    background-color: rgba(31, 41, 55, 0.4);
    border-color: rgba(55, 65, 81, 0.5);
    color: #9ca3af;
    cursor: pointer;
}

.quick-filter-chip:hover {
    background-color: #374151;
    color: #ffffff;
}

.quick-filter-chip.active {
    background-color: #eab308;
    border-color: #ca8a04;
    color: #000000;
    box-shadow: 0 10px 15px -3px rgba(234, 179, 8, 0.2);
}

/* No scrollbar utility */
.no-scrollbar::-webkit-scrollbar {
    display: none;
}
.no-scrollbar {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

/* Neo Jalali DatePicker (replaces persian-datepicker) */
.neo-jdp {
    position: absolute;
    z-index: 9999;
    width: 260px;
    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-empty {
    height: 30px;
}

/* Custom Scrollbar */
.custom-scrollbar::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.custom-scrollbar::-webkit-scrollbar-track {
    background: rgba(31, 41, 55, 0.5);
    border-radius: 4px;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
    background: rgba(75, 85, 99, 0.8);
    border-radius: 4px;
}

.custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: rgba(107, 114, 128, 1);
}

/* ========================================
   MOBILE SIDEBAR FIX - Z-Index Correction
   Ensures sidebar appears above modals on mobile
   ======================================== */
@media (max-width: 768px) {
    /* Sidebar must be above all modals (which use z-index: 5000-10000) */
    #main-sidebar {
        z-index: 999999 !important;
    }
    
    /* Backdrop just below sidebar */
    #sidebar-backdrop {
        z-index: 999998 !important;
    }
    
    /* Prevent click-through during transition */
    #sidebar-backdrop:not(.hidden) {
        pointer-events: auto;
    }
    
    #sidebar-backdrop.hidden {
        pointer-events: none;
    }
    
    /* Ensure sidebar is fully visible when opened */
    #main-sidebar:not(.translate-x-full) {
        box-shadow: -10px 0 30px rgba(0, 0, 0, 0.5);
    }
}

/* ========================================
   MOBILE MODAL FIX - Height & Overflow
   Fixes modal cutoff on mobile browsers
   ======================================== */
@media (max-width: 768px) {
    /* Fix modal height to account for browser chrome */
    #modalProfile .glass,
    #modalDeal .glass,
    #modalLead .glass,
    #modalActivity .glass,
    #modalSatisfaction .glass,
    #modalSupport .glass {
        height: 100vh;
        height: -webkit-fill-available;
        max-height: 100%;
        border-radius: 0;
        margin: 0;
        width: 100%;
        max-width: 100%;
    }
    
    /* Fix modal content overflow */
    #modalProfile .glass .flex-1,
    #modalDeal .glass .flex-1,
    #modalLead .glass .flex-1 {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* ========================================
   MOBILE HEADER FIX - Button Overflow
   Prevents header buttons from overflowing
   ======================================== */
@media (max-width: 375px) {
    /* Reduce header padding on small screens */
    header h-16 {
        padding-left: 8px;
        padding-right: 8px;
    }
    
    /* Hide non-critical buttons on very small screens */
    header button[title="تست اعلان"],
    header button[title="تست یادآوری‌ها"],
    header button[title="تست پاپ‌آپ مستقیم"],
    header button[title="تست نوتیفیکیشن مرورگر"] {
        display: none;
    }
    
    /* Reduce gap between buttons */
    header .flex.items-center.gap-2 {
        gap: 0.25rem;
    }
    
    /* Make header scrollable if needed */
    header .flex.items-center.justify-between {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* ========================================
   MOBILE TABLE FIX - Card Layout
   Converts tables to cards on mobile
   ======================================== */
@media (max-width: 768px) {
    /* Referrals table */
    #view-referrals table {
        min-width: 0;
        display: block;
    }
    
    #view-referrals thead {
        display: none;
    }
    
    #view-referrals tbody tr {
        display: block;
        margin-bottom: 16px;
        padding: 12px;
        background: var(--bg-card);
        border-radius: 8px;
        border: 1px solid var(--border-color);
    }
    
    #view-referrals tbody td {
        display: flex;
        justify-content: space-between;
        padding: 8px 0;
        border-bottom: 1px solid var(--border-color);
        text-align: left;
    }
    
    #view-referrals tbody td:last-child {
        border-bottom: none;
    }
    
    /* Add labels using data-label attribute */
    #view-referrals tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-secondary);
        text-align: right;
        padding-left: 8px;
    }
}

/* ========================================
   MOBILE PAGINATION FIX - Touch Targets
   Makes pagination buttons finger-friendly
   ======================================== */
@media (max-width: 768px) {
    button[onclick*="loadLeads"],
    button[onclick*="loadDeals"],
    button[onclick*="loadBlataklifLeads"],
    button[onclick*="loadLegacyDeals"] {
        min-width: 44px;
        min-height: 44px;
        padding: 12px 16px;
        font-size: 14px;
    }
    
    /* Pagination container */
    #leads-pagination,
    #deals-pagination,
    #blataklif-leads-pagination {
        padding: 8px 0;
    }
}

/* ========================================
   MOBILE SEARCH INPUT FIX - Overflow
   Prevents search input from overflowing
   ======================================== */
@media (max-width: 768px) {
    #leads-search,
    #deals-search,
    #blataklif-leads-search {
        min-width: 0;
        flex-shrink: 1;
    }
}

/* ========================================
   MOBILE STICKY HEADER FIX
   Makes header fixed on mobile for stability
   ======================================== */
@media (max-width: 768px) {
    header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 100;
    }
    
    /* Compensate for fixed header */
    main {
        padding-top: 64px;
    }
    
    /* Adjust view sections */
    .view-section {
        padding-top: 8px;
    }
}

/* ========================================
   MOBILE VIEWPORT HEIGHT FIX
   Accounts for mobile browser chrome
   ======================================== */
:root {
    --vh: 1vh;
}

@supports (-webkit-touch-callout: none) {
    .h-screen,
    .h-\[90vh\] {
        height: -webkit-fill-available;
    }
}

.h-screen {
    height: 100vh;
    height: calc(var(--vh, 1vh) * 100);
}

.h-\[90vh\] {
    height: 90vh;
    height: calc(var(--vh, 1vh) * 90);
}

/* ========================================
   PHASE 1 & 2: MOBILE FILTER IMPROVEMENTS
   Complete mobile UX overhaul
   ======================================== */

/* --- Collapsible Filter Accordion --- */
@media (max-width: 768px) {
    /* Filter toggle button */
    .filter-toggle-btn {
        position: sticky;
        top: 70px;
        z-index: 50;
        margin: 8px 0;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }
    
    /* Collapsible filter container */
    .filters-collapsible {
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease-out;
        background: var(--bg-card);
        border-radius: 12px;
        margin-bottom: 0;
    }
    
    .filters-collapsible.open {
        max-height: 2000px; /* Large enough for all filters */
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        margin-bottom: 16px;
    }
    
    /* Filter count badge */
    .filter-count-badge {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        background: #eab308;
        color: #000;
        font-size: 11px;
        font-weight: 700;
        min-width: 20px;
        height: 20px;
        border-radius: 10px;
        padding: 0 6px;
        margin-right: 8px;
    }
    
    /* Clear filters button */
    .clear-filters-btn {
        background: rgba(239, 68, 68, 0.1);
        border: 1px solid rgba(239, 68, 68, 0.3);
        color: #ef4444;
        padding: 8px 16px;
        border-radius: 8px;
        font-size: 12px;
        font-weight: 600;
        transition: all 0.2s;
    }
    
    .clear-filters-btn:hover {
        background: rgba(239, 68, 68, 0.2);
    }
    
    /* Active filter indicator */
    .filter-input.active {
        border-color: #eab308;
        box-shadow: 0 0 0 2px rgba(234, 179, 8, 0.2);
    }
    
    /* Sticky action buttons */
    .sticky-filter-actions {
        position: sticky;
        bottom: 0;
        background: var(--bg-card);
        border-top: 1px solid var(--border-color);
        padding: 12px;
        z-index: 40;
        display: flex;
        gap: 8px;
        justify-content: space-between;
    }
}

/* --- Touch-Friendly Inputs (44px minimum) --- */
@media (max-width: 768px) {
    .touch-input,
    .input[type="text"],
    .input[type="tel"],
    .input[type="email"],
    .input[type="number"],
    .input[type="date"],
    select.input {
        min-height: 44px;
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 12px;
    }
    
    /* Date picker inputs */
    #leads-register-from,
    #leads-register-to,
    #leads-activity-from,
    #leads-activity-to,
    #deals-register-from,
    #deals-register-to,
    #deals-activity-from,
    #deals-activity-to {
        min-height: 44px;
    }
}

/* --- Bottom Sheet Filters --- */
@media (max-width: 768px) {
    .bottom-sheet-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 9998;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }
    
    .bottom-sheet-overlay.active {
        opacity: 1;
        pointer-events: auto;
    }
    
    .bottom-sheet {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--bg-panel);
        border-radius: 16px 16px 0 0;
        z-index: 9999;
        transform: translateY(100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        max-height: 85vh;
        display: flex;
        flex-direction: column;
    }
    
    .bottom-sheet.active {
        transform: translateY(0);
    }
    
    .bottom-sheet-header {
        padding: 16px;
        border-bottom: 1px solid var(--border-color);
        display: flex;
        justify-content: space-between;
        align-items: center;
        flex-shrink: 0;
    }
    
    .bottom-sheet-title {
        font-size: 16px;
        font-weight: 700;
        color: var(--text-primary);
    }
    
    .bottom-sheet-close {
        background: none;
        border: none;
        color: var(--text-secondary);
        font-size: 24px;
        padding: 8px;
        cursor: pointer;
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .bottom-sheet-content {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 16px;
    }
    
    .bottom-sheet-footer {
        padding: 16px;
        border-top: 1px solid var(--border-color);
        display: flex;
        gap: 12px;
        flex-shrink: 0;
    }
    
    .bottom-sheet-footer button {
        flex: 1;
        min-height: 48px;
        font-size: 14px;
        font-weight: 600;
    }
}

/* --- Simplified Mobile Cards --- */
@media (max-width: 768px) {
    .lead-card-mobile {
        padding: 12px;
    }
    
    .lead-card-mobile .card-header {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        margin-bottom: 8px;
    }
    
    .lead-card-mobile .card-name {
        font-size: 14px;
        font-weight: 700;
        color: var(--text-primary);
    }
    
    .lead-card-mobile .card-phone {
        font-size: 12px;
        color: var(--text-secondary);
        margin-top: 4px;
    }
    
    .lead-card-mobile .card-meta {
        display: flex;
        gap: 8px;
        flex-wrap: wrap;
        margin-top: 8px;
    }
    
    .lead-card-mobile .card-badge {
        font-size: 11px;
        padding: 4px 8px;
        border-radius: 6px;
        font-weight: 600;
    }
    
    .lead-card-mobile .card-actions {
        display: flex;
        gap: 8px;
        margin-top: 12px;
        padding-top: 12px;
        border-top: 1px solid var(--border-color);
    }
    
    .lead-card-mobile .card-actions button {
        flex: 1;
        min-height: 44px;
        font-size: 12px;
    }
}

/* --- Sticky Pagination --- */
@media (max-width: 768px) {
    .sticky-pagination {
        position: sticky;
        bottom: 0;
        background: var(--bg-panel);
        border-top: 1px solid var(--border-color);
        padding: 12px 0;
        z-index: 60;
        box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1);
    }
    
    .sticky-pagination button {
        min-width: 44px;
        min-height: 44px;
        padding: 12px 16px;
        font-size: 14px;
    }
    
    /* Add padding to content to prevent overlap */
    .pagination-spacer {
        height: 80px;
    }
}

/* --- Visual Scroll Indicators --- */
@media (max-width: 768px) {
    .scroll-indicator {
        position: relative;
        mask-image: linear-gradient(to right, black 85%, transparent 100%);
        -webkit-mask-image: linear-gradient(to right, black 85%, transparent 100%);
    }
    
    .scroll-hint {
        position: absolute;
        right: 0;
        top: 50%;
        transform: translateY(-50%);
        width: 40px;
        height: 40px;
        background: linear-gradient(90deg, transparent, var(--bg-card));
        pointer-events: none;
        display: flex;
        align-items: center;
        justify-content: flex-end;
        padding-right: 8px;
    }
    
    .scroll-hint::after {
        content: "›";
        font-size: 24px;
        color: var(--text-secondary);
        animation: scrollHint 1.5s infinite;
    }
    
    @keyframes scrollHint {
        0%, 100% { transform: translateX(0); opacity: 0.5; }
        50% { transform: translateX(4px); opacity: 1; }
    }
}

/* --- Multi-Step Modal Forms (Mobile) --- */
@media (max-width: 768px) {
    .modal-step {
        display: none;
    }
    
    .modal-step.active {
        display: block;
    }
    
    .modal-steps-indicator {
        display: flex;
        justify-content: space-between;
        margin-bottom: 16px;
        padding: 0 8px;
    }
    
    .step-dot {
        flex: 1;
        height: 4px;
        background: var(--border-color);
        margin: 0 4px;
        border-radius: 2px;
        transition: background 0.3s;
    }
    
    .step-dot.active {
        background: #eab308;
    }
    
    .step-dot.completed {
        background: #22c55e;
    }
    
    .modal-step-actions {
        display: flex;
        gap: 8px;
        margin-top: 16px;
    }
    
    .modal-step-actions button {
        flex: 1;
        min-height: 48px;
    }
}

/* Desktop: Hide mobile-specific elements */
@media (min-width: 769px) {
    .mobile-only {
        display: none !important;
    }
}

@media (max-width: 768px) {
    .desktop-only {
        display: none !important;
    }
    
    /* Show mobile-specific elements */
    .mobile-only {
        display: block !important;
    }
}

/* ========================================
   PHASE 3: MOBILE ENHANCEMENTS
   Filter presets, history, voice search, etc.
   ======================================== */

/* --- Mobile Filter Presets --- */
@media (max-width: 768px) {
    .filter-preset-bar {
        display: flex;
        gap: 8px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding: 8px 0;
        margin-bottom: 8px;
        scroll-indicator;
    }
    
    .filter-preset-chip {
        flex-shrink: 0;
        background: rgba(234, 179, 8, 0.1);
        border: 1px solid rgba(234, 179, 8, 0.3);
        color: #eab308;
        padding: 8px 16px;
        border-radius: 20px;
        font-size: 12px;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.2s;
        white-space: nowrap;
    }
    
    .filter-preset-chip:hover,
    .filter-preset-chip.active {
        background: #eab308;
        color: #000;
    }
    
    .filter-preset-chip i {
        margin-left: 6px;
        font-size: 10px;
    }
}

/* --- Filter History Dropdown --- */
@media (max-width: 768px) {
    .filter-history-container {
        position: relative;
        margin-bottom: 8px;
    }
    
    .filter-history-btn {
        width: 100%;
        background: rgba(59, 130, 246, 0.1);
        border: 1px solid rgba(59, 130, 246, 0.3);
        color: #3b82f6;
        padding: 10px 16px;
        border-radius: 8px;
        font-size: 12px;
        font-weight: 600;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: space-between;
    }
    
    .filter-history-btn:hover {
        background: rgba(59, 130, 246, 0.2);
    }
    
    .filter-history-dropdown {
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: var(--bg-panel);
        border: 1px solid var(--border-color);
        border-radius: 8px;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
        z-index: 100;
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease;
    }
    
    .filter-history-dropdown.open {
        max-height: 300px;
        overflow-y: auto;
    }
    
    .filter-history-item {
        padding: 12px 16px;
        border-bottom: 1px solid var(--border-color);
        cursor: pointer;
        transition: background 0.2s;
    }
    
    .filter-history-item:hover {
        background: rgba(234, 179, 8, 0.05);
    }
    
    .filter-history-item:last-child {
        border-bottom: none;
    }
    
    .filter-history-label {
        font-size: 12px;
        font-weight: 600;
        color: var(--text-primary);
        margin-bottom: 4px;
    }
    
    .filter-history-meta {
        font-size: 10px;
        color: var(--text-secondary);
        display: flex;
        justify-content: space-between;
    }
    
    .filter-history-delete {
        color: #ef4444;
        background: none;
        border: none;
        cursor: pointer;
        padding: 4px;
        font-size: 14px;
    }
}

/* --- Voice Search Button --- */
@media (max-width: 768px) {
    .voice-search-container {
        position: relative;
        display: inline-flex;
        align-items: center;
    }
    
    .voice-search-btn {
        position: absolute;
        right: 8px;
        top: 50%;
        transform: translateY(-50%);
        background: rgba(234, 179, 8, 0.1);
        border: none;
        color: #eab308;
        width: 36px;
        height: 36px;
        border-radius: 8px;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: all 0.2s;
        z-index: 10;
    }
    
    .voice-search-btn:hover {
        background: rgba(234, 179, 8, 0.2);
    }
    
    .voice-search-btn.listening {
        background: #ef4444;
        color: white;
        animation: pulse 1s infinite;
    }
    
    @keyframes pulse {
        0%, 100% { transform: translateY(-50%) scale(1); }
        50% { transform: translateY(-50%) scale(1.1); }
    }
    
    .voice-search-input {
        padding-right: 52px !important;
    }
}

/* --- Date Range Picker --- */
@media (max-width: 768px) {
    .date-range-picker {
        position: relative;
        background: var(--bg-card);
        border: 1px solid var(--border-color);
        border-radius: 12px;
        padding: 12px;
        margin-bottom: 12px;
    }
    
    .date-range-inputs {
        display: flex;
        gap: 8px;
        align-items: center;
    }
    
    .date-range-inputs .input {
        flex: 1;
        min-width: 0;
    }
    
    .date-range-separator {
        color: var(--text-secondary);
        font-size: 14px;
        font-weight: 700;
    }
    
    .date-range-presets {
        display: flex;
        gap: 6px;
        margin-top: 8px;
        flex-wrap: wrap;
    }
    
    .date-range-preset {
        background: rgba(59, 130, 246, 0.1);
        border: 1px solid rgba(59, 130, 246, 0.2);
        color: #3b82f6;
        padding: 6px 12px;
        border-radius: 6px;
        font-size: 11px;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.2s;
    }
    
    .date-range-preset:hover,
    .date-range-preset.active {
        background: #3b82f6;
        color: white;
    }
}

/* --- Quick Filter Toolbar --- */
@media (max-width: 768px) {
    .quick-filter-toolbar {
        position: sticky;
        top: 120px;
        z-index: 45;
        background: var(--bg-panel);
        border-bottom: 1px solid var(--border-color);
        padding: 8px 0;
        margin-bottom: 12px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }
    
    .quick-filter-scroll {
        display: flex;
        gap: 8px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding: 0 12px;
        scroll-indicator;
    }
    
    .quick-filter-item {
        flex-shrink: 0;
        background: var(--bg-card);
        border: 1px solid var(--border-color);
        color: var(--text-secondary);
        padding: 8px 16px;
        border-radius: 20px;
        font-size: 12px;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.2s;
        white-space: nowrap;
    }
    
    .quick-filter-item:hover,
    .quick-filter-item.active {
        background: #eab308;
        border-color: #eab308;
        color: #000;
    }
    
    .quick-filter-item i {
        margin-left: 6px;
        font-size: 10px;
    }
}

/* ========================================
   PHASE 4: ACCESSIBILITY & ENHANCEMENTS
   ======================================== */

/* --- Enhanced Focus States --- */
@media (max-width: 768px) {
    .input:focus,
    button:focus,
    select:focus,
    [tabindex]:focus {
        outline: 2px solid #eab308;
        outline-offset: 2px;
    }
    
    .input:focus-visible,
    button:focus-visible {
        outline: 3px solid #eab308;
        outline-offset: 3px;
        box-shadow: 0 0 0 6px rgba(234, 179, 8, 0.2);
    }
}

/* --- Haptic Feedback Indicator --- */
@media (max-width: 768px) {
    .haptic-button:active {
        transform: scale(0.95);
    }
    
    @keyframes hapticFeedback {
        0% { transform: translateX(0); }
        25% { transform: translateX(-2px); }
        50% { transform: translateX(2px); }
        75% { transform: translateX(-2px); }
        100% { transform: translateX(0); }
    }
    
    .haptic-feedback {
        animation: hapticFeedback 0.1s ease-in-out;
    }
}

/* --- Pull-to-Refresh Indicator --- */
@media (max-width: 768px) {
    .pull-to-refresh-container {
        position: relative;
        overflow: hidden;
    }
    
    .pull-to-refresh-indicator {
        position: absolute;
        top: -60px;
        left: 0;
        right: 0;
        height: 60px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: var(--bg-panel);
        transition: top 0.3s ease;
        z-index: 50;
    }
    
    .pull-to-refresh-indicator.visible {
        top: 0;
    }
    
    .pull-to-refresh-spinner {
        width: 24px;
        height: 24px;
        border: 3px solid rgba(234, 179, 8, 0.3);
        border-top-color: #eab308;
        border-radius: 50%;
        animation: spin 0.8s linear infinite;
    }
    
    @keyframes spin {
        to { transform: rotate(360deg); }
    }
    
    .pull-to-refresh-text {
        margin-left: 12px;
        font-size: 12px;
        font-weight: 600;
        color: var(--text-primary);
    }
}

/* --- Enhanced Loading States --- */
@media (max-width: 768px) {
    .loading-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.7);
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        z-index: 99999;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s;
    }
    
    .loading-overlay.active {
        opacity: 1;
        pointer-events: auto;
    }
    
    .loading-spinner {
        width: 48px;
        height: 48px;
        border: 4px solid rgba(234, 179, 8, 0.3);
        border-top-color: #eab308;
        border-radius: 50%;
        animation: spin 0.8s linear infinite;
        margin-bottom: 16px;
    }
    
    .loading-text {
        color: white;
        font-size: 14px;
        font-weight: 600;
    }
    
    .skeleton-loader {
        background: linear-gradient(
            90deg,
            var(--bg-card) 25%,
            var(--bg-panel) 50%,
            var(--bg-card) 75%
        );
        background-size: 200% 100%;
        animation: shimmer 1.5s infinite;
        border-radius: 8px;
    }
    
    @keyframes shimmer {
        0% { background-position: 200% 0; }
        100% { background-position: -200% 0; }
    }
}

/* --- Landscape Mode Optimization --- */
@media (max-width: 768px) and (orientation: landscape) {
    .filters-collapsible.open {
        max-height: 300px;
    }
    
    .bottom-sheet {
        max-height: 60vh;
    }
    
    .lead-card-mobile {
        display: flex;
        gap: 12px;
        align-items: center;
    }
    
    .lead-card-mobile .card-header {
        margin-bottom: 0;
        flex: 1;
    }
    
    .lead-card-mobile .card-actions {
        margin-top: 0;
        padding-top: 0;
        border-top: none;
        flex-direction: column;
    }
}

/* --- Tablet Optimization (768-1024px) --- */
@media (min-width: 769px) and (max-width: 1024px) {
    .filters-collapsible {
        max-height: none;
        overflow: visible;
    }
    
    .lead-card-mobile {
        padding: 16px;
    }
    
    #leads-list,
    #deals-container {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* --- Desktop Leads Grid Restore (1025px+) --- */
@media (min-width: 1025px) and (max-width: 1439px) {
    #leads-list {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 1440px) {
    #leads-list {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* --- Desktop Collapsible Filters (Leads) --- */
@media (min-width: 1025px) {
    #view-leads #leads-filters.filters-collapsible {
        max-height: 0;
        overflow: hidden;
        margin-bottom: 0 !important;
        padding-top: 0 !important;
        padding-bottom: 0 !important;
        border-color: transparent;
        opacity: 0;
        transition: max-height 0.25s ease, opacity 0.2s ease, margin 0.25s ease, padding 0.25s ease;
    }

    #view-leads #leads-filters.filters-collapsible.open {
        max-height: 1200px;
        overflow: visible;
        margin-bottom: 1rem !important;
        padding-top: 1rem !important;
        padding-bottom: 1rem !important;
        border-color: var(--border-color);
        opacity: 1;
    }

    #leads-desktop-filter-toggle .filter-count-badge {
        margin-right: 0;
        margin-left: 4px;
    }

    #leads-desktop-filter-toggle.open #leads-desktop-filter-toggle-icon {
        transform: rotate(180deg);
    }

    /* Desktop filter/header compaction */
    #view-leads > .mb-4.flex.gap-3.flex-wrap.items-center {
        margin-bottom: 0.5rem;
    }

    #view-leads > .mb-4.flex.gap-2.flex-wrap.desktop-only {
        margin-top: 0.25rem;
        margin-bottom: 0.75rem;
        align-items: center;
    }

    #view-leads .desktop-only .clear-filters-btn {
        background: rgba(239, 68, 68, 0.08);
        border: 1px solid rgba(239, 68, 68, 0.25);
        color: #f87171;
        transition: all 0.2s;
    }

    #view-leads .desktop-only .clear-filters-btn:hover {
        background: rgba(239, 68, 68, 0.14);
        border-color: rgba(239, 68, 68, 0.4);
    }

    /* Desktop lead card polish (Phase 5) */
    #leads-list .lead-card-desktop {
        min-height: 128px;
        border: 1px solid rgba(255, 255, 255, 0.06);
        display: flex;
        flex-direction: column;
        justify-content: space-between;
    }

    #leads-list .lead-card-desktop:hover {
        border-color: rgba(234, 179, 8, 0.25);
        box-shadow: 0 6px 16px rgba(0, 0, 0, 0.16);
    }

    #leads-list .lead-card-desktop .lead-name {
        line-height: 1.35;
    }

    #leads-list .lead-card-desktop .lead-products {
        display: -webkit-box;
        -webkit-line-clamp: 1;
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

/* --- 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;
    }
}
