/* =========================================
   NEXUS DESK - MASTER GLOBAL CSS (Light Elegant SaaS)
   ========================================= */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap');

:root {
    /* ☁️ Light Elegant Theme Colors */
    --bg-base: #F4F7FE; 
    --bg-surface: #ffffff; 
    --bg-hover: #f8fafc;
    --border-light: #e2e8f0;
    --border-focus: #3b82f6;
    
    /* ✨ Brand & AI Accents */
    --primary-blue: #2563eb; 
    --primary-hover: #1d4ed8;
    --ai-purple: #8b5cf6; 
    --ai-gradient: linear-gradient(135deg, #8b5cf6, #d946ef);
    
    /* 📝 Text Colors */
    --text-pure: #0f172a; 
    --text-dim: #64748b;
    
    /* 🚦 Status Colors */
    --status-danger: #ef4444;
    --status-warning: #f59e0b;
    --status-success: #10b981;

    /* 💧 Soft Shadows */
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.02);
    --shadow-md: 0 10px 25px rgba(112, 144, 176, 0.12); 
    --shadow-ai: 0 8px 20px rgba(139, 92, 246, 0.2);
    
    --radius-lg: 16px;
    --radius-md: 8px;
    --radius-sm: 4px;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Plus Jakarta Sans', sans-serif; }

body {
    background-color: var(--bg-base);
    color: var(--text-pure);
    font-size: 13px;
    height: 100vh; display: flex; flex-direction: column; overflow: hidden;
}

/* Custom Clean Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* =========================================
   Layout Components
   ========================================= */
.wrapper { display: flex; flex-grow: 1; overflow: hidden; }

.top-navbar { 
    height: 60px; background: #ffffff; border-bottom: 1px solid var(--border-light); 
    display: flex; justify-content: space-between; align-items: center; 
    padding: 0 20px; box-shadow: var(--shadow-sm); z-index: 10; flex-shrink: 0;
}

.desktop-sidebar { 
    width: 250px; background: #ffffff; border-right: 1px solid var(--border-light); 
    display: flex; flex-direction: column; padding: 25px 0; z-index: 10; flex-shrink: 0;
}

/* اللوحة الجانبية اليمنى (الخاصة ببيانات العميل) */
.context-sidebar { 
    width: 320px; background-color: var(--bg-surface); border-left: 1px solid var(--border-light); 
    display: flex; flex-direction: column; flex-shrink: 0; z-index: 5; box-shadow: -4px 0 15px rgba(0,0,0,0.02);
}
.context-header { padding: 15px; border-bottom: 1px solid var(--border-light); font-size: 12px; font-weight: 700; color: var(--text-dim); text-transform: uppercase; display: flex; justify-content: space-between;}
.contact-widget { padding: 30px 20px; text-align: center; border-bottom: 1px solid var(--border-light); }

/* =========================================
   UI Components (Cards, Buttons, Inputs)
   ========================================= */
.glass-panel { background: var(--bg-surface); border: 1px solid #ffffff; border-radius: var(--radius-lg); box-shadow: var(--shadow-md); }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 8px 16px; border-radius: var(--radius-md); font-weight: 600;
    cursor: pointer; transition: all 0.3s ease; border: none; outline: none; font-size: 13px;
}
.btn-primary { background: var(--primary-blue); color: white; box-shadow: 0 4px 10px rgba(37, 99, 235, 0.2); }
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 6px 15px rgba(37, 99, 235, 0.3); }
.btn-secondary { background: transparent; color: var(--text-pure); border: 1px solid var(--border-light); }
.btn-secondary:hover { background: var(--bg-hover); }

.btn-ai { background: var(--ai-gradient); color: white; box-shadow: var(--shadow-ai); padding: 6px 15px; border-radius: 20px;}
.btn-ai:hover { transform: translateY(-2px); box-shadow: 0 10px 25px rgba(139, 92, 246, 0.3); }
.btn-link { color: var(--primary-blue); background: transparent; border: none; cursor: pointer; font-weight: 700; font-size: 12px; }

/* Forms & Inputs */
.form-area { flex-grow: 1; overflow-y: auto; padding: 30px 40px; }
.form-section { margin-bottom: 40px; }
.form-section-title { font-size: 16px; font-weight: 800; margin-bottom: 20px; color: var(--text-pure); border-bottom: 1px solid var(--border-light); padding-bottom: 10px;}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.full-width { grid-column: span 2; }

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 12px; color: var(--text-pure); font-weight: 700; }
.req-star { color: var(--status-danger); }

.input-control {
    width: 100%; background: #f8fafc; border: 1px solid var(--border-light); color: var(--text-pure);
    padding: 10px 14px; border-radius: var(--radius-md); font-size: 13px; transition: all 0.3s; outline: none;
}
.input-control:focus { background: #ffffff; border-color: var(--primary-blue); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1); }

/* =========================================
   Smart Hints & Badges
   ========================================= */
.label-with-hint { display: flex; align-items: center; gap: 8px; }
.hint-icon {
    display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; border-radius: 50%;
    background: #eff6ff; color: var(--primary-blue); font-size: 11px; font-weight: 800; cursor: help; position: relative;
}
.hint-icon::after {
    content: attr(data-hint); position: absolute; bottom: 130%; left: 50%; transform: translateX(-50%) translateY(10px);
    background: var(--text-pure); color: #fff; padding: 6px 10px; border-radius: var(--radius-sm);
    font-size: 11px; white-space: nowrap; box-shadow: var(--shadow-md); opacity: 0; visibility: hidden; transition: all 0.2s ease; z-index: 1000;
}
.hint-icon:hover::after { opacity: 1; visibility: visible; transform: translateX(-50%) translateY(0); }

.badge-neon { padding: 4px 10px; border-radius: 20px; font-size: 11px; font-weight: 700; display: inline-block; }
.badge-success { background: #ecfdf5; color: #059669; border: 1px solid #a7f3d0; }
.badge-warning { background: #fffbeb; color: #d97706; border: 1px solid #fde68a; }
.badge-danger { background: #fef2f2; color: #dc2626; border: 1px solid #fecaca; }

/* =========================================
   Mobile App View (PWA Responsive)
   ========================================= */
.mobile-bottom-nav { display: none; }
@media (max-width: 768px) {
    .desktop-sidebar, .context-sidebar { display: none !important; }
    .form-grid { grid-template-columns: 1fr !important; gap: 15px;}
    .full-width { grid-column: span 1 !important; }
    .form-area { padding: 15px; margin-bottom: 60px; }
    
    .mobile-bottom-nav {
        display: flex; position: fixed; bottom: 0; left: 0; width: 100%; height: 65px;
        background: rgba(255, 255, 255, 0.95); backdrop-filter: blur(10px);
        border-top: 1px solid var(--border-light); justify-content: space-around;
        align-items: center; z-index: 1000; padding-bottom: env(safe-area-inset-bottom);
    }
    .m-nav-item { display: flex; flex-direction: column; align-items: center; gap: 4px; color: var(--text-dim); text-decoration: none; font-size: 10px; font-weight: 700; }
    .m-nav-item.active { color: var(--primary-blue); }
    .m-nav-icon { font-size: 20px; }
    .m-fab {
        width: 50px; height: 50px; border-radius: 50%; background: var(--primary-blue);
        display: flex; align-items: center; justify-content: center; font-size: 24px; color: white;
        transform: translateY(-15px); box-shadow: 0 4px 15px rgba(37, 99, 235, 0.3); border: 4px solid #f4f7fe;
    }
}
/* =======================================================
   📱 الكود السحري للتجاوب مع الموبايل والتابلت (Mobile Responsiveness)
   ======================================================= */

@media (max-width: 1024px) {
    /* 1. تظبيط الهيكل الأساسي (إلغاء العرض الجانبي وجعله رأسي) */
    .wrapper, .layout-3col, .crm-layout { 
        flex-direction: column !important; 
        height: auto !important; 
        overflow: visible !important; 
    }

    /* 2. تحويل الـ Sidebars (القوائم الجانبية) لشريط أفقي قابل للسحب (Scrollable Tabs) */
    .desktop-sidebar, .setup-sidebar, .col-ticket-list, .contacts-list-col { 
        width: 100% !important; 
        height: auto !important; 
        max-height: 250px !important;
        flex-direction: row !important; 
        overflow-x: auto !important; 
        overflow-y: hidden !important;
        padding: 10px !important; 
        border-right: none !important; 
        border-bottom: 1px solid var(--border-light) !important;
        white-space: nowrap !important;
        align-items: center !important;
        z-index: 10 !important;
    }
    
    /* إخفاء اللوجوهات من القوائم الجانبية في الموبايل لتوفير المساحة */
    .desktop-sidebar .sidebar-brand, .setup-sidebar .setup-search, .sidebar-category { 
        display: none !important; 
    }

    /* تظبيط زراير القائمة لتكون أفقية */
    .sidebar-link, .setup-link { 
        display: inline-flex !important; 
        border-left: none !important; 
        border-bottom: 3px solid transparent !important; 
        margin-right: 15px !important;
        padding: 10px 15px !important;
        font-size: 14px !important;
    }
    .sidebar-link.active, .setup-link.active { 
        border-bottom-color: var(--primary-blue) !important; 
        background: transparent !important;
    }
    
    /* دعم اللغة العربية للقوائم الأفقية */
    body[dir="rtl"] .sidebar-link { border-right: none !important; margin-right: 0 !important; margin-left: 15px !important;}

    /* 3. شاشة الـ 3 أعمدة (Ticket Details) والـ CRM */
    .col-properties { 
        width: 100% !important; 
        max-height: none !important; 
        border-right: none !important; 
    }
    .col-main-chat, .contact-profile-col { 
        min-height: 600px !important; 
        overflow-y: visible !important;
    }
    .cp-header { flex-direction: column !important; gap: 15px !important; align-items: flex-start !important;}

    /* 4. شريط الـ Navbar العلوي */
    .top-nav-links { display: none !important; /* إخفاء اللينكات العلوية في الموبايل عشان الزحمة */ }
    .top-navbar { padding: 0 15px !important; }

    /* 5. الداشبورد والتحليلات (الرسومات البيانية والكروت) */
    .charts-grid, .charts-row, .bottom-charts-grid { 
        grid-template-columns: 1fr !important; 
    }
    .kpi-grid, .mini-kpi-grid { 
        grid-template-columns: repeat(2, 1fr) !important; 
    }
    .stats-top-row, .stats-grid { 
        grid-template-columns: repeat(2, 1fr) !important; 
    }
}

/* 🟢 شاشات الموبايل الصغيرة جداً (أقل من 768px) 🟢 */
@media (max-width: 768px) {
    .kpi-grid, .mini-kpi-grid { grid-template-columns: 1fr !important; }
    
    /* تظبيط شريط الأدوات (Toolbar) بتاع جدول التذاكر */
    .toolbar { flex-direction: column !important; gap: 15px !important; align-items: flex-start !important; }
    .toolbar-right { width: 100% !important; flex-wrap: wrap !important; justify-content: flex-start !important;}
    
    /* تظبيط هيدر المحادثة (Chat Header) */
    .chat-header { flex-direction: column !important; gap: 15px !important; align-items: flex-start !important;}
    .ch-actions { width: 100% !important; flex-wrap: wrap !important; }
    .reply-tabs { flex-wrap: wrap !important; gap: 10px !important;}
    
    /* تصغير حجم الخطوط في الموبايل */
    .hero-section h1 { font-size: 24px !important; }
    .dashboard-header h1 { font-size: 20px !important; }
}   
/* =======================================================
   🚪 Custom Logout Modal (نافذة تسجيل الخروج الاحترافية)
   ======================================================= */
.logout-modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(15, 23, 42, 0.6); 
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    display: flex; align-items: center; justify-content: center; z-index: 999999;
    opacity: 0; visibility: hidden; transition: all 0.3s ease;
}

.logout-modal-overlay.show { opacity: 1; visibility: visible; }

.logout-modal-box {
    background: #ffffff; width: 100%; max-width: 380px; border-radius: 24px;
    padding: 35px 30px; text-align: center; box-shadow: 0 25px 50px rgba(0,0,0,0.15);
    transform: translateY(20px) scale(0.95); transition: all 0.3s ease;
}

.logout-modal-overlay.show .logout-modal-box { transform: translateY(0) scale(1); }

.logout-icon-wrap {
    width: 65px; height: 65px; background: #fee2e2; color: #ef4444; border-radius: 50%;
    display: flex; align-items: center; justify-content: center; font-size: 30px; margin: 0 auto 20px;
}

.logout-modal-box h3 { font-size: 22px; font-weight: 800; color: var(--text-pure); margin: 0 0 10px 0; }
.logout-modal-box p { font-size: 14px; color: var(--text-dim); margin: 0 0 30px 0; font-weight: 600; line-height: 1.6;}

.logout-actions { display: flex; gap: 12px; }

.logout-btn-cancel { 
    flex: 1; padding: 14px; border-radius: 14px; border: 1px solid var(--border-light); 
    background: #ffffff; color: var(--text-pure); font-weight: 800; font-size: 14px; 
    cursor: pointer; transition: all 0.2s; font-family: inherit;
}
.logout-btn-cancel:hover { background: #f8fafc; border-color: #cbd5e1; }

.logout-btn-confirm { 
    flex: 1; padding: 14px; border-radius: 14px; border: none; 
    background: #ef4444; color: #ffffff; font-weight: 800; font-size: 14px; 
    cursor: pointer; transition: all 0.2s; box-shadow: 0 4px 12px rgba(239, 68, 68, 0.2); font-family: inherit;
}
.logout-btn-confirm:hover { background: #dc2626; transform: translateY(-2px); box-shadow: 0 6px 15px rgba(239, 68, 68, 0.3);}
/* =======================================================
   🛡️ Anti-Selection (منع تحديد ونسخ النصوص)
   ======================================================= */
body {
    -webkit-user-select: none; /* Safari */
    -moz-user-select: none; /* Firefox */
    -ms-user-select: none; /* IE10+/Edge */
    user-select: none; /* Standard */
}

/* 🟢 لازم نستثني مربعات الإدخال عشان اليوزر يقدر يكتب براحته 🟢 */
input, textarea, select {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}
/* =======================================================
   📱 Mobile Responsiveness (NexusDesk Enterprise Fix)
   ======================================================= */
@media (max-width: 768px) {
    /* 1. إصلاح التول بار العلوي (Top Navbar) */
    .top-navbar {
        padding: 10px 15px !important;
        flex-wrap: wrap !important;
        height: auto !important;
        gap: 10px;
    }
    .top-nav-links { display: none !important; } /* إخفاء لينكات الديسكتوب واستخدام البار السفلي بدالها */
    #globalLangSwitcher { display: none !important; } /* إخفاء تغيير اللغة في الموبايل لتوفير المساحة */
    
    /* تظبيط اللوجو والبادج عشان مياخدوش مساحة كبيرة */
    .top-navbar > div:first-child { flex-grow: 1; }
    .brand-logo span { font-size: 16px !important; }
    #adminBadgeTag { font-size: 8px !important; padding: 2px 4px !important; margin-left: 2px !important; }
    
    /* إخفاء كلمة (Username) والاكتفاء بالدايرة اللي فيها أول حرفين */
    .dropdown-container > div > span { display: none !important; } 

    /* 2. إصلاح الجداول عشان متطلعش بره الشاشة (Swipeable Tables) */
    .table-container, .setup-card-body, .crm-layout {
        padding: 15px !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch; /* سكرول ناعم جداً للآيفون */
        width: 100vw !important;
    }
    .tickets-table, .setup-table, .patient-tickets-table {
        min-width: 900px !important; /* إجبار الجدول يفضل محتفظ بشكله، وتعمله سكرول بصباعك يمين وشمال */
    }

    /* 3. إصلاح شريط الأدوات (البحث والفلترة) */
    .toolbar, .setup-header, .dashboard-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        padding: 15px !important;
        gap: 15px;
        height: auto !important;
    }
    .toolbar-left, .toolbar-right {
        width: 100% !important;
        justify-content: space-between !important;
        flex-wrap: wrap !important;
        gap: 10px;
    }
    .toolbar-right input { width: 100% !important; margin-top: 10px; } /* شريط البحث ياخد العرض كله */

    /* 4. إصلاح الداشبورد (Dashboard Cards) */
    .mini-kpi-grid {
        grid-template-columns: repeat(2, 1fr) !important; /* كارتين جنب بعض بدل 6 */
        gap: 10px !important;
    }
    .stats-top-row {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    .stat-item { 
        border-right: none !important; 
        border-bottom: 1px solid var(--border-light); 
        padding: 10px 5px !important; 
    }
    .bottom-charts-grid {
        grid-template-columns: 1fr !important; /* كروت الرسم البياني تنزل تحت بعض */
    }

    /* 5. إخفاء القائمة الجانبية للديسكتوب */
    .desktop-sidebar {
        display: none !important;
    }

    /* 6. تظبيط المسافات العامة عشان التليفون */
    .main-content {
        padding: 10px !important;
    }
    .wrapper {
        padding-bottom: 70px !important; /* مساحة للـ Mobile Bottom Nav عشان ميغطيش على الداتا */
    }
    .bulk-actions-bar {
        width: 90%;
        padding: 10px 15px;
        gap: 10px;
        flex-wrap: wrap;
        justify-content: center;
    }
}