:root {
    --primary-color: #0f172a;       /* Dark Navy */
    --primary-light: #334155;
    --accent-color: #3b82f6;        /* Bright Blue */
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --info-color: #0ea5e9;
    --light-bg: #f8fafc;
    --card-bg: #ffffff;
    --border-radius: 12px;
}

/* --- Global Scrollbar & Body Fixes --- */
body {
    font-family: 'Inter', sans-serif;
    background-color: var(--light-bg);
    font-size: 0.85rem;
    color: #1e293b;
    overflow-x: hidden;
    padding-bottom: 0; 
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Custom Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* --- Tooltip Customization --- */
.tooltip-inner {
    max-width: 300px;
    text-align: left;
    padding: 10px;
    background-color: #1e293b;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

/* --- Header Styling --- */
.header-bar {
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    padding: 10px 0;
    position: sticky;
    top: 0;
    z-index: 1000;
    flex-shrink: 0;
}

.header-brand {
    font-weight: 800;
    font-size: 1.35rem;
    color: var(--primary-color);
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    letter-spacing: -0.5px;
    cursor: pointer;
}

.brand-icon-box {
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
    color: white;
    border-radius: 8px;
    padding: 4px 8px;
    box-shadow: 0 4px 10px rgba(59, 130, 246, 0.3);
    transition: all 0.3s ease;
}

.by-somar {
    font-family: 'Dancing Script', cursive;
    font-size: 0.85rem;
    color: var(--accent-color);
    margin-top: -2px;
    opacity: 0.9;
    font-weight: 600;
}

.header-content-wrapper {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
}

.user-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-badge {
    background: #f1f5f9;
    padding: 5px 12px;
    border-radius: 50px;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1px solid #e2e8f0;
    cursor: pointer;
    transition: all 0.2s;
    color: #334155;
    user-select: none;
}
.user-badge:hover, .user-badge[aria-expanded="true"] { background: #e2e8f0; border-color: #cbd5e1; }
.user-avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; }

/* --- Sidebar --- */
.app-sidebar {
    position: fixed;
    top: 70px; 
    left: 0;
    bottom: 0;
    width: 260px;
    background: var(--primary-color); 
    border-right: 1px solid #334155;
    z-index: 1050;
    box-shadow: 5px 0 15px rgba(0,0,0,0.1);
    transform: translateX(-100%);
    transition: transform 0.3s ease-in-out;
    overflow-y: auto; 
    overflow-x: hidden;
}

.app-sidebar::-webkit-scrollbar { width: 4px; }
.app-sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 4px; }
.app-sidebar::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.4); }

.app-sidebar.open { transform: translateX(0); }

.sidebar-overlay {
    position: fixed;
    top: 70px;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(15, 23, 42, 0.6);
    z-index: 1040;
    display: none;
    backdrop-filter: blur(2px);
    transition: opacity 0.3s;
}
.sidebar-overlay.show { display: block; }

.sidebar-link {
    color: #94a3b8;
    font-size: 0.9rem;
    font-weight: 500;
    padding: 10px 15px;
    border-radius: 8px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
}
.sidebar-link:hover { background-color: rgba(255, 255, 255, 0.05); color: #fff; transform: translateX(3px); }
.sidebar-link.active { background: linear-gradient(90deg, var(--accent-color), #2563eb); color: #fff; box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3); font-weight: 600; }
.sidebar-link i { font-size: 1.1rem; opacity: 0.9; }

/* --- Main Content --- */
main.flex-grow-1 {
    background-color: #f1f5f9;
    width: 100%;
    overflow-y: auto; 
    height: calc(100vh - 70px); 
}

/* --- Interface Styles --- */
.custom-card {
    border: 1px solid #e2e8f0;
    border-radius: var(--border-radius);
    box-shadow: 0 2px 5px rgba(0,0,0,0.03);
    background: var(--card-bg);
    margin-bottom: 20px;
    overflow: hidden;
    transition: all 0.2s;
}
.card-header-custom { background-color: #fff; border-bottom: 1px solid #f1f5f9; padding: 15px 20px; font-weight: 700; color: #334155; display: flex; justify-content: space-between; align-items: center; }
.card-header-custom h6 { margin: 0; font-weight: 700; font-size: 0.95rem; }

/* Tables & Inputs */
.table-custom th { background-color: #f8fafc; color: #475569; font-weight: 700; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.3px; vertical-align: middle; text-align: center; border-bottom: 2px solid #e2e8f0; white-space: nowrap; padding: 12px 10px; }
.table-custom td { vertical-align: middle; text-align: center; padding: 10px 8px; border-bottom: 1px solid #f1f5f9; color: #334155; font-size: 0.85rem; }
.table-custom tr:last-child td { border-bottom: 0; }

/* إزالة الظل الرمادي المزعج عند التمرير على الجداول والبطاقات */
.table-hover > tbody > tr:hover > * {
    background-color: transparent !important;
    box-shadow: none !important;
    color: inherit !important;
}
.table-hover > tbody > tr:hover {
    background-color: #fff !important;
}

/* Sticky Header for Long Tables */
.sticky-header th {
    position: sticky;
    top: 0;
    z-index: 10;
    box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.1);
}

.form-control-sm, .form-select-sm { border-radius: 6px; border: 1px solid #cbd5e1; text-align: center; font-size: 0.85rem; padding: 8px; background-color: #fff; transition: all 0.2s; font-weight: 500; }
.table-custom input.form-control-sm { min-width: 85px; }
.c-name { min-width: 140px !important; text-align: left !important; }
.c-rev, .c-cogs { min-width: 110px !important; } 
.form-control-sm:focus { border-color: var(--accent-color); box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1); }
.btn-icon { width: 28px; height: 28px; padding: 0; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; transition: all 0.2s; }
.help-icon { cursor: help; color: #94a3b8; margin-left: 4px; font-size: 0.85rem; transition: color 0.2s; }
.help-icon:hover { color: var(--accent-color); }

/* Updated Report Table Styles */
.row-loss { background-color: #fef2f2 !important; }
.row-win { }
.clickable-cell { transition: all 0.2s; position: relative; }
.clickable-cell:hover { color: var(--accent-color) !important; background-color: #eff6ff; }
.alloc-badge { cursor: pointer; font-size: 0.7rem; padding: 4px 10px; background-color: #e2e8f0; color: #475569; border-radius: 20px; display: inline-block; border: 1px solid #cbd5e1; width: 100%; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.alloc-badge:hover { background-color: #cbd5e1; border-color: #94a3b8; }
.brand-checkbox-list { max-height: 200px; overflow-y: auto; border: 1px solid #dee2e6; padding: 10px; border-radius: 6px; background: #fff; }
.form-check-label { font-size: 0.85rem; cursor: pointer; width: 100%; }
.year-select-container { display: inline-flex; align-items: center; background: #f1f5f9; padding: 4px 12px; border-radius: 20px; border: 1px solid #e2e8f0; }
.year-select-container select { background-color: transparent; border: none; color: #334155; font-weight: 700; cursor: pointer; outline: none; }
.auth-hidden { display: none !important; }

/* تبويبات الفلترة في التذاكر - لضمان بقائها بسطر واحد مع التقلص */
.nav-pills.flex-nowrap .nav-item { min-width: 0; }
.nav-pills.flex-nowrap .nav-link { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.type-filter-btn { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex-shrink: 1; }

/* Marketing & Others */
.hero-section { background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%); color: white; padding: 120px 0 100px; position: relative; overflow: hidden; }
.hero-shape { position: absolute; top: 0; right: 0; bottom: 0; left: 0; background-image: radial-gradient(circle at 70% 30%, rgba(59, 130, 246, 0.2) 0%, transparent 50%); pointer-events: none; }
.mock-report-card { background: white; border-radius: 12px; box-shadow: 0 20px 50px rgba(0,0,0,0.2); overflow: hidden; transform: rotate(2deg); border: 1px solid rgba(255,255,255,0.2); }
.mock-report-header { background: var(--primary-color); padding: 15px; color: white; font-weight: bold; display: flex; justify-content: space-between; }
.mock-row { border-bottom: 1px solid #eee; }
.mock-row td { padding: 12px; font-size: 0.9rem; }
.mock-loss { color: var(--danger-color); font-weight: bold; background: #fff1f2; }
.mock-win { color: var(--success-color); font-weight: bold; }
#loadingOverlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(255,255,255,0.98); z-index: 9999; display: flex; flex-direction: column; justify-content: center; align-items: center; }
.company-select-card { transition: transform 0.2s, box-shadow 0.2s; cursor: pointer; border: 1px solid #e2e8f0; position: relative; overflow: hidden; background: white; }
.company-select-card:hover { transform: translateY(-5px); box-shadow: 0 10px 25px rgba(0,0,0,0.08); border-color: var(--primary-color); }
.add-company-card { border: 2px dashed #cbd5e1; background-color: #f8fafc; }
.add-company-card:hover { border-color: var(--primary-color); background-color: #fff; }
.demo-company-card { border: 1px solid #fcd34d; background: #fffbeb; }
.demo-company-card:hover { border-color: #f59e0b; box-shadow: 0 10px 25px rgba(245, 158, 11, 0.15); }
.delete-comp-btn { position: absolute; top: 15px; right: 15px; background: #fee2e2; color: #ef4444; border: none; width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center; transition: all 0.2s; z-index: 10; }
.delete-comp-btn:hover { background: #ef4444; color: white; }
.role-badge { font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.5px; padding: 3px 8px; border-radius: 4px; background: #fbbf24; color: #78350f; font-weight: 700; }
.sync-pulse { animation: pulse-green 1s ease-out; }
@keyframes pulse-green { 0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); } 100% { box-shadow: 0 0 0 10px rgba(16, 185, 129, 0); } }
.input-group-text { font-size: 0.75rem; background-color: #f8fafc; }
.demo-alert-bar { background-color: #dc2626; color: white; text-align: center; padding: 8px; font-weight: bold; font-size: 0.9rem; }
.pricing-card { border: 1px solid #e2e8f0; border-radius: 16px; padding: 2rem; text-align: center; transition: all 0.3s; }
.pricing-card:hover { transform: translateY(-5px); box-shadow: 0 10px 30px rgba(0,0,0,0.1); }
.pricing-highlight { border: 2px solid var(--primary-color); background: #f8fafc; position: relative; }
.pricing-badge { position: absolute; top: -12px; left: 50%; transform: translateX(-50%); background: var(--primary-color); color: white; padding: 4px 12px; border-radius: 20px; font-size: 0.75rem; font-weight: bold; }
.pin-input { letter-spacing: 0.5em; text-align: center; font-size: 1.5rem; font-weight: bold; }
.pro-status { background: linear-gradient(135deg, #f59e0b, #fbbf24); color: black; font-weight: bold; border: 1px solid #d97706; box-shadow: 0 2px 5px rgba(245, 158, 11, 0.3); }
.fade-in { animation: fadeIn 0.4s ease-in-out; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

/* =========================================
   Sales Order Module Specific Styles
   ========================================= */

/* 1. Group Hover Lift */
.group-hover-lift {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.group-hover-lift:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    background-color: #f8fafc;
    z-index: 1;
    position: relative;
}

/* 2. Read-Only Fields */
#orderForm input:disabled, 
#orderForm select:disabled, 
#orderForm textarea:disabled {
    background-color: transparent;
    border: none;
    padding-left: 0;
    padding-right: 0;
    color: #334155;
    font-weight: 600;
    opacity: 1; 
    cursor: text;
}

#orderForm select:disabled {
    background-image: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

#orderForm input:enabled, 
#orderForm select:enabled, 
#orderForm textarea:enabled {
    background-color: #fff;
    border: 1px solid #cbd5e1;
    padding: 0.375rem 0.75rem; 
    border-radius: 0.375rem;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}
.table-custom input.form-control-sm:enabled {
    padding: 4px 8px;
    text-align: center;
}

/* 3. Product Search Dropdown */
.product-search-results {
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    overflow: hidden;
    background: white;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}
.product-search-results .list-group-item {
    border: none;
    border-bottom: 1px solid #f1f5f9;
    cursor: pointer;
    transition: background-color 0.15s;
}
.product-search-results .list-group-item:last-child {
    border-bottom: none;
}
.product-search-results .list-group-item:hover {
    background-color: #f8fafc;
}

/* 4. Modal Toolbar */
#modalActionsToolbar button {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}
/* --- Modern Modal Styling --- */
.modal-fullscreen .modal-header {
    border-bottom: 1px solid rgba(0,0,0,0.05) !important;
}
.modal-fullscreen .modal-footer {
    border-top: 1px solid rgba(0,0,0,0.05) !important;
    background: rgba(255,255,255,0.9);
    backdrop-filter: blur(10px);
}
.hover-scale { transition: transform 0.2s; }
.hover-scale:hover { transform: scale(1.02); }

/* --- Mobile Optimization (Smart Cards V4.0 - Corrected Alignment) --- */
@media (max-width: 768px) {
    /* 1. إعدادات الحاوية العامة (تم تقليص الهوامش الجانبية لتكبير البطاقة، والاعتماد على Padding) */
    .container-fluid, .container, .row, .col-12, #appContainer {
        padding-left: 5px !important;
        padding-right: 5px !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
    .row { margin: 0 !important; }
    main.flex-grow-1 { padding-top: 5px !important; padding-bottom: 80px !important; overflow-x: hidden !important; }

    /* إلغاء التمرير الأفقي الإجباري الذي يفرضه بوتستراب على الجداول */
    .table-responsive {
        overflow-x: visible !important; 
        width: 100% !important;
    }

    /* 2. تحويل الجداول إلى بطاقات */
    .table-responsive table, .table-responsive tbody, .table-responsive tr, .table-responsive td {
        display: block; width: 100%; box-sizing: border-box !important;
    }
    .table-responsive thead { display: none; }
    
    .table-responsive tr {
        background: #fff; 
        margin-bottom: 8px !important; 
        border: 1px solid #e2e8f0;
        border-radius: 10px; 
        box-shadow: 0 2px 5px rgba(0,0,0,0.03);
        padding: 10px 12px; 
        position: relative;
        /* تم إزالة الهوامش الجانبية تماماً لمنع عرض 100% + مسافة من اختراق الشاشة */
        margin-left: 0 !important; 
        margin-right: 0 !important;
        width: 100% !important;
    }

    /* التنسيق الافتراضي للخلايا */
    .table-responsive td {
        display: flex; justify-content: space-between; align-items: center;
        text-align: left; 
        padding: 5px 0; border-bottom: 1px dashed #f1f5f9; font-size: 0.9rem;
    }
    .table-responsive td:last-child { border-bottom: none; }


    /* --- 3. إصلاح تذاكر الصيانة (Helpdesk Custom Card V6.0 - Final Alignment) --- */
    
    #ticketsTableBody tr { 
        padding-top: 75px !important; 
        padding-bottom: 45px !important; 
        padding-left: 10px !important;
        padding-right: 10px !important;
        position: relative;
    }

    /* 1. أيقونة النوع (أقصى اليسار) */
    #ticketsTableBody td:nth-child(2) { 
        position: absolute;
        top: 12px;
        left: 10px !important; 
        right: auto !important;
        font-size: 1.3rem;
        border: none; padding: 0; margin: 0;
        width: 30px; text-align: center;
        display: block !important;
    }

    /* 2. اسم العيادة */
    #ticketsTableBody td:nth-child(5) { 
        position: absolute;
        top: 10px;
        left: 45px !important; 
        width: calc(100% - 135px) !important; 
        text-align: left !important;
        font-weight: 800;
        font-size: 0.95rem;
        color: #1e293b;
        border: none; padding: 0; margin: 0;
        
        white-space: normal !important; 
        display: -webkit-box !important;
        -webkit-line-clamp: 2; 
        -webkit-box-orient: vertical;
        overflow: hidden; 
        line-height: 1.2;
    }
    #ticketsTableBody td:nth-child(5)::before { display: none !important; }

    /* 3. رقم التذكرة */
    #ticketsTableBody td:nth-child(1) { 
        position: absolute;
        top: 50px !important; 
        left: 45px !important; 
        right: auto !important;
        text-align: left !important;
        font-size: 0.75rem;
        color: #94a3b8;
        font-weight: 600;
        border: none; padding: 0; margin: 0;
        width: auto;
        display: block !important;
    }

    /* 4. الحالة / البادج (تصغير واختصار النص) */
    #ticketsTableBody td:nth-child(3) { 
        position: absolute;
        top: 10px;
        right: 10px !important; 
        left: auto !important;
        
        display: flex !important;
        justify-content: flex-end;
        width: auto !important;
        max-width: 80px !important; /* تحديد أقصى عرض للبادج */
        
        border: none; padding: 0; margin: 0;
        background: transparent !important;
        z-index: 10; 
    }
    
    #ticketsTableBody td:nth-child(3) .badge {
        display: inline-block;
        max-width: 100%; /* يجب أن لا يتجاوز حاويته */
        overflow: hidden; /* إخفاء ما يزيد */
        text-overflow: ellipsis; /* وضع نقاط بدل النص الزائد */
        white-space: nowrap; /* إجبار النص على سطر واحد */
        
        font-size: 0.7rem; 
        padding: 4px 6px;
    }

    /* 5. جسم البطاقة (الوصف) */
    #ticketsTableBody td:nth-child(4) { 
        width: 100%;
        border-top: 1px dashed #e2e8f0;
        padding-top: 10px;
        margin-top: 0; 
        display: block !important;
        text-align: left !important;
    }
    
    .mobile-comment-text {
        display: -webkit-box;
        -webkit-line-clamp: 2; 
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
        font-size: 0.9rem;
        line-height: 1.4;
        color: #334155;
    }

    /* 6. الفوتر (التاريخ المستهدف) */
    #ticketsTableBody td:nth-child(6) { 
        position: absolute;
        bottom: 0; left: 0; right: 0;
        background-color: #f8fafc;
        border-top: 1px solid #e2e8f0;
        border-radius: 0 0 10px 10px;
        padding: 8px 12px;
        font-size: 0.8rem;
        color: #334155;
        display: flex !important;
        align-items: center; justify-content: space-between;
        height: 38px;
    }

    #ticketsTableBody td:nth-child(7) { display: none; }

    /* --- 4. باقي الموديولات (Assets & Sales) --- */
    
    /* Assets */
    #assets_grid .col-12 { padding: 0 2px !important; }
    #assets_grid .card { flex-direction: row; min-height: 90px; margin-bottom: 5px; }
    #assets_grid .card-body { padding: 10px !important; text-align: left; } 
    #assets_grid .border-top { margin-top: 6px !important; padding-top: 6px !important; display: flex; justify-content: space-between; }

    /* Sales Lines */
    #linesTable tr { display: flex !important; flex-wrap: wrap !important; padding: 10px !important; gap: 5px; }
    #linesTable td.col-product { width: 100% !important; display: block !important; border-bottom: 1px solid #eee !important; margin-bottom: 5px !important; text-align: left !important; }
    #linesTable td.col-qty, #linesTable td.col-price, #linesTable td.col-disc { width: 32% !important; flex-direction: column !important; align-items: center !important; border:none !important; }
    #linesTable td.col-total { width: 100% !important; background: #f0f9ff !important; margin-top: 5px !important; border-radius: 5px; padding: 5px 10px !important; }
}