:root {
    --primary: #2c7873;
    --primary-dark: #1e524d;
    --secondary: #ffb300;
    --light: #f8f9fa;
    --dark: #343a40;
    --success: #28a745;
    --danger: #dc3545;
    --warning: #ffc107;
    --info: #17a2b8;
    --border-radius: 12px;
    --box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Tajawal', sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: #f5f7fa;
    color: var(--dark);
    direction: rtl;
    background: linear-gradient(135deg, #f5f7fa 0%, #e4efe9 100%);
    min-height: 100vh;
    overflow-x: hidden;
    touch-action: manipulation;
}

/* شاشة التحميل */
#splash-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    transition: opacity 0.5s, visibility 0.5s;
}

#splash-screen.hidden {
    opacity: 0;
    visibility: hidden;
}

.splash-logo {
    width: 120px;
    height: 120px;
    background: white;
    border-radius: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 30px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(0.95); }
    50% { transform: scale(1.05); }
    100% { transform: scale(0.95); }
}

.splash-logo i {
    font-size: 60px;
    color: var(--primary);
}

.splash-title {
    color: white;
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 10px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.splash-subtitle {
    color: rgba(255, 255, 255, 0.85);
    font-size: 1.1rem;
    margin-bottom: 40px;
    text-align: center;
    max-width: 80%;
}

.progress-bar {
    width: 80%;
    max-width: 300px;
    height: 8px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    overflow: hidden;
}

.progress {
    height: 100%;
    background: white;
    border-radius: 4px;
    width: 0%;
    transition: width 0.5s ease;
}

/* زر التثبيت */
#install-button {
    position: fixed;
    bottom: 20px;
    left: 20px;
    background: var(--secondary);
    color: white;
    border: none;
    border-radius: 50px;
    padding: 12px 20px;
    font-weight: 600;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 100;
    display: none;
    cursor: pointer;
    transition: all 0.3s;
}

#install-button:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

.app-container {
    display: flex;
    min-height: 100vh;
    max-width: 1400px;
    margin: 0 auto;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.1);
}

/* الشريط الجانبي */
.sidebar {
    width: 280px;
    background: linear-gradient(180deg, var(--primary), var(--primary-dark));
    color: white;
    padding: 20px 0;
    box-shadow: var(--box-shadow);
    z-index: 100;
    position: relative;
    overflow: hidden;
}

.sidebar::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, rgba(255,255,255,0) 70%);
    transform: rotate(30deg);
}

.logo {
    text-align: center;
    padding: 25px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    position: relative;
    z-index: 1;
}

.logo h1 {
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: 1px;
    margin-bottom: 5px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.logo p {
    font-size: 0.95rem;
    opacity: 0.9;
    color: rgba(255, 255, 255, 0.85);
}

.nav-links {
    list-style: none;
    margin-top: 30px;
    position: relative;
    z-index: 1;
}

.nav-links li {
    padding: 0;
}

.nav-links a {
    display: flex;
    align-items: center;
    padding: 16px 30px;
    color: rgba(255, 255, 255, 0.85);
    text-decoration: none;
    font-size: 1.1rem;
    font-weight: 500;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.nav-links a::before {
    content: '';
    position: absolute;
    top: 0;
    right: -100%;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.1);
    transition: all 0.4s ease;
    z-index: -1;
}

.nav-links a i {
    margin-left: 12px;
    font-size: 1.2rem;
    width: 24px;
    text-align: center;
}

.nav-links a:hover, .nav-links a.active {
    color: white;
}

.nav-links a:hover::before, .nav-links a.active::before {
    right: 0;
}

.nav-links a.active {
    border-right: 4px solid var(--secondary);
}

/* المحتوى الرئيسي */
.main-content {
    flex: 1;
    padding: 25px;
    overflow-y: auto;
    background: #f8fafc;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    background: white;
    padding: 18px 30px;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    border-left: 5px solid var(--secondary);
}

.header h2 {
    font-size: 1.8rem;
    color: var(--primary-dark);
    display: flex;
    align-items: center;
    gap: 12px;
}

.header h2 i {
    color: var(--secondary);
}

/* شريط البحث */
.search-container {
    position: relative;
    width: 350px;
}

#globalSearch {
    width: 100%;
    padding: 12px 50px 12px 20px;
    border: 1px solid #ced4da;
    border-radius: 30px;
    font-size: 1rem;
    background: #f8f9fa;
    transition: all 0.3s;
}

#globalSearch:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(44, 120, 115, 0.2);
    background: white;
    border-color: var(--primary);
}

.search-icon {
    position: absolute;
    top: 50%;
    left: 20px;
    transform: translateY(-50%);
    color: var(--primary);
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    background: white;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    margin-top: 8px;
    box-shadow: var(--box-shadow);
    max-height: 300px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
}

.search-results.active {
    display: block;
}

.search-result-item {
    padding: 12px 20px;
    border-bottom: 1px solid #f1f1f1;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: background 0.2s;
}

.search-result-item:hover {
    background: #f8f9fa;
}

.search-result-item i {
    color: var(--primary);
    width: 20px;
}

.search-result-item .type {
    font-size: 0.8rem;
    background: #e8f4f3;
    color: var(--primary);
    padding: 2px 8px;
    border-radius: 4px;
}

.stats-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 22px;
    margin-bottom: 35px;
}

.stat-card {
    background: white;
    border-radius: var(--border-radius);
    padding: 25px;
    box-shadow: var(--box-shadow);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    border-top: 4px solid var(--primary);
    position: relative;
    overflow: hidden;
}

.stat-card::after {
    content: '';
    position: absolute;
    top: -10px;
    right: -10px;
    width: 40px;
    height: 40px;
    background: var(--primary);
    border-radius: 50%;
    opacity: 0.1;
}

.stat-card:hover {
    transform: translateY(-8px);
    box-shadow: 0 12px 25px rgba(0, 0, 0, 0.12);
}

.stat-card i {
    font-size: 2.8rem;
    float: left;
    margin-left: 15px;
    color: var(--primary);
    opacity: 0.8;
}

.stat-card .title {
    font-size: 1.05rem;
    color: #6c757d;
    margin-bottom: 8px;
}

.stat-card .value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--dark);
    letter-spacing: -1px;
}

.charts-row {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 25px;
    margin-bottom: 35px;
}

.chart-container {
    background: white;
    border-radius: var(--border-radius);
    padding: 25px;
    box-shadow: var(--box-shadow);
}

.chart-container h3 {
    margin-bottom: 20px;
    color: var(--primary-dark);
    font-size: 1.35rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

.chart-container h3 i {
    color: var(--secondary);
}

.chart-wrapper {
    height: 300px;
    position: relative;
}

/* الجداول والنماذج */
.section {
    background: white;
    border-radius: var(--border-radius);
    padding: 30px;
    box-shadow: var(--box-shadow);
    margin-bottom: 35px;
    border-left: 3px solid var(--primary);
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
}

.section-title {
    font-size: 1.5rem;
    color: var(--primary-dark);
    display: flex;
    align-items: center;
    gap: 10px;
}

.section-title i {
    color: var(--secondary);
}

.btn {
    padding: 12px 24px;
    border-radius: 8px;
    border: none;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 1.05rem;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-warning {
    background: var(--warning);
    color: var(--dark);
}

.btn-info {
    background: var(--info);
    color: white;
}

.table-container {
    overflow-x: auto;
    border-radius: var(--border-radius);
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 800px;
}

thead {
    background: linear-gradient(to right, var(--primary), var(--primary-dark));
    color: white;
}

th, td {
    padding: 16px 20px;
    text-align: right;
    border-bottom: 1px solid #e9ecef;
}

th {
    font-weight: 600;
}

tbody tr {
    transition: background 0.2s;
}

tbody tr:nth-child(even) {
    background-color: #f9fafb;
}

tbody tr:hover {
    background-color: #f1f5f9;
}

.action-buttons {
    display: flex;
    gap: 8px;
}

.action-buttons button {
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.95rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* النماذج */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s;
}

.modal-content {
    background: white;
    border-radius: var(--border-radius);
    width: 90%;
    max-width: 650px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25);
    transform: translateY(0);
    animation: slideUp 0.4s ease;
}

.modal-header {
    padding: 20px 25px;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--primary);
    color: white;
    border-radius: var(--border-radius) var(--border-radius) 0 0;
}

.modal-title {
    font-size: 1.4rem;
    font-weight: 600;
}

.close-modal {
    background: none;
    border: none;
    font-size: 1.8rem;
    cursor: pointer;
    color: rgba(255,255,255,0.8);
    transition: all 0.2s;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.close-modal:hover {
    background: rgba(255,255,255,0.1);
    color: white;
}

.modal-body {
    padding: 25px;
}

.form-group {
    margin-bottom: 22px;
}

.form-group label {
    display: block;
    margin-bottom: 10px;
    font-weight: 500;
    color: var(--dark);
    font-size: 1.05rem;
}

.form-control {
    width: 100%;
    padding: 14px 18px;
    border: 1px solid #ced4da;
    border-radius: 8px;
    font-size: 1.05rem;
    transition: border-color 0.3s;
    background: #f8fafc;
}

.form-control:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(44, 120, 115, 0.1);
    background: white;
}

.form-row {
    display: flex;
    gap: 18px;
}

.form-row .form-group {
    flex: 1;
}

.modal-footer {
    padding: 20px 25px;
    border-top: 1px solid #e9ecef;
    text-align: left;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* رسائل التنبيه */
.alert {
    padding: 16px;
    border-radius: 8px;
    margin-bottom: 25px;
    display: none;
    animation: fadeIn 0.3s;
}

.alert-success {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.alert-danger {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.badge {
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
}

.badge-success {
    background: #d4edda;
    color: #155724;
}

.badge-danger {
    background: #f8d7da;
    color: #721c24;
}

.badge-info {
    background: #d1ecf1;
    color: #0c5460;
}

/* متجاوب */
@media (max-width: 992px) {
    .app-container {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        height: auto;
    }
    
    .nav-links {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .nav-links li {
        width: auto;
    }
    
    .charts-row {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }
    
    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }
    
    .stats-container {
        grid-template-columns: 1fr;
    }
    
    .form-row {
        flex-direction: column;
        gap: 0;
    }
    
    .modal-content {
        width: 95%;
    }
    
    .search-container {
        width: 100%;
    }
}

/* تحسينات للأجهزة المحمولة */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        height: auto;
        position: fixed;
        bottom: 0;
        top: auto;
        padding: 0;
        z-index: 50;
        border-radius: 0;
        box-shadow: 0 -5px 15px rgba(0,0,0,0.1);
    }
    
    .logo {
        display: none;
    }
    
    .nav-links {
        display: flex;
        flex-wrap: nowrap;
        justify-content: space-around;
        overflow-x: auto;
        margin-top: 0;
        padding: 10px 0;
    }
    
    .nav-links li {
        flex: 1;
        min-width: 80px;
    }
    
    .nav-links a {
        flex-direction: column;
        padding: 10px 5px;
        font-size: 0.85rem;
        text-align: center;
    }
    
    .nav-links a i {
        margin-left: 0;
        margin-bottom: 5px;
        font-size: 1.2rem;
    }
    
    .nav-links a.active {
        border-right: none;
        border-top: 3px solid var(--secondary);
    }
    
    .main-content {
        padding: 15px;
        padding-bottom: 80px; /* لحساب الشريط الجانبي في الأسفل */
    }
    
    .header {
        flex-direction: column;
        gap: 15px;
        padding: 15px;
    }
    
    .search-container {
        width: 100%;
    }
    
    .stats-container {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .charts-row {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .section {
        padding: 20px;
    }
    
    .section-header {
        flex-direction: column;
        gap: 15px;
    }
    
    .btn {
        padding: 10px 15px;
        font-size: 0.95rem;
    }
    
    table {
        min-width: auto;
    }
    
    th, td {
        padding: 12px 8px;
        font-size: 0.9rem;
    }
    
    .modal-content {
        max-height: 80vh;
    }
    
    .form-control {
        padding: 12px 15px;
        font-size: 1rem;
    }
}

/* الرسوم المتحركة */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { 
        transform: translateY(30px);
        opacity: 0;
    }
    to { 
        transform: translateY(0);
        opacity: 1;
    }
}

/* شريط التحميل */
.progress-bar {
    height: 6px;
    background: #e9ecef;
    border-radius: 3px;
    overflow: hidden;
    margin-top: 10px;
}

.progress {
    height: 100%;
    background: var(--primary);
    border-radius: 3px;
    transition: width 0.5s ease;
}

/* إضافات جديدة */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s ease-in-out infinite;
    margin-right: 10px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.empty-table {
    text-align: center;
    padding: 30px;
    color: #6c757d;
    font-size: 1.1rem;
}

.empty-table i {
    font-size: 3rem;
    display: block;
    margin-bottom: 15px;
    color: #ced4da;
}

.reference-link {
    color: var(--primary);
    cursor: pointer;
    text-decoration: underline;
}

.reference-link:hover {
    color: var(--primary-dark);
}

/* طباعة */
@media print {
    body * {
        visibility: hidden;
    }
    
    .print-section, .print-section * {
        visibility: hidden !important;
    }
    
    .print-section {
        display: none !important;
    }
    
    .section, .section * {
        visibility: visible;
    }
    
    .section {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        box-shadow: none;
        border: none;
    }
    
    .action-buttons {
        display: none;
    }
    
    .header, .sidebar, .section-header {
        display: none !important;
    }
    
    .table-container {
        box-shadow: none;
        overflow: visible;
    }
    
    table {
        min-width: auto;
        width: 100%;
    }
    
    th, td {
        padding: 8px;
        font-size: 12px;
    }
    
    .badge {
        padding: 2px 6px;
        font-size: 10px;
    }
}