:root {
    --primary-color: #007aff;
    --primary-hover: #005bb5;
    --primary-bg: #e5f1ff;
    --sidebar-width: 260px;
    --header-height: 60px;
}
* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Noto Sans Arabic', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
body { background-color: #f2f2f7; color: #1c1c1e; direction: rtl; display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
a { text-decoration: none; color: inherit; }

/* Layout */
body { flex-direction: column; }
.app-container { display: flex; flex: 1; overflow: hidden; position: relative; }

/* Top Header */
.top-header { height: var(--header-height); background: #fff; border-bottom: 1px solid #e5e5ea; display: flex; justify-content: space-between; align-items: center; padding: 0 20px; z-index: 20; position: relative; }
.header-left { display: flex; align-items: center; gap: 16px; }
.menu-toggle { background: transparent; color: #1c1c1e; border: none; font-size: 20px; cursor: pointer; display: none; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; color: var(--primary-color); }
.brand-logo { font-size: 24px; }
.header-right { display: flex; align-items: center; gap: 16px; }

/* Profile Dropdown */
.profile-dropdown { position: relative; }
.profile-btn { display: flex; align-items: center; gap: 10px; background: transparent; border: none; cursor: pointer; text-align: right; padding: 4px; border-radius: 12px; transition: 0.2s; }
.profile-btn:hover { background: #f2f2f7; }
.profile-avatar { width: 36px; height: 36px; background: #e5e5ea; border-radius: 50%; display: flex; justify-content: center; align-items: center; color: #8e8e93; font-size: 16px; }
.profile-info { display: flex; flex-direction: column; }
.profile-name { font-size: 14px; font-weight: 600; color: #1c1c1e; }
.profile-role { font-size: 10px; padding: 2px 6px; margin: 0; margin-top: 2px; }
.dropdown-menu { position: absolute; top: 100%; left: 0; background: #fff; border: 1px solid #e5e5ea; border-radius: 12px; box-shadow: 0 4px 12px rgba(0,0,0,0.1); min-width: 180px; display: none; flex-direction: column; padding: 8px; z-index: 30; margin-top: 8px; }
.dropdown-menu.show { display: flex; }
.dropdown-item { padding: 10px 12px; font-size: 14px; color: #1c1c1e; border-radius: 8px; display: flex; align-items: center; gap: 10px; transition: 0.2s; }
.dropdown-item:hover { background: #f2f2f7; }
.dropdown-item.text-danger { color: #ff3b30; }
.dropdown-item.text-danger:hover { background: #ffe5e5; }

/* Sidebar */
.sidebar { width: var(--sidebar-width); background: #fff; border-left: 1px solid #e5e5ea; display: flex; flex-direction: column; z-index: 10; transition: width 0.3s, transform 0.3s; position: relative; }
.sidebar.collapsed { width: 80px; }
.sidebar.collapsed .nav-text { display: none; }
.sidebar-header { display: none; /* Replaced by top header */ }
.sidebar-close { display: none; position: absolute; top: 12px; left: 12px; font-size: 20px; color: #8e8e93; cursor: pointer; background: transparent; border: none; }
.sidebar-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 9; display: none; opacity: 0; transition: 0.3s; }
.sidebar-nav { flex: 1; padding: 16px 12px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; overflow-x: hidden; }
.sidebar-nav a { padding: 12px 16px; border-radius: 12px; font-size: 15px; display: flex; align-items: center; gap: 12px; color: #3a3a3c; transition: all 0.2s; white-space: nowrap; }
.sidebar-nav a:hover { background: #f2f2f7; }
.sidebar-nav a.active { background: var(--primary-bg); color: var(--primary-color); font-weight: 600; }
.sidebar-nav a i { width: 20px; text-align: center; font-size: 18px; }

/* Main Content */
.main-content { flex: 1; overflow-y: auto; padding: 32px; background-color: #f2f2f7; }

/* Responsive Media Queries */
@media (min-width: 1025px) {
    .menu-toggle { display: block; }
}

@media (max-width: 1024px) {
    .sidebar { position: absolute; top: 0; bottom: 0; right: 0; transform: translateX(100%); width: 260px; z-index: 100; box-shadow: -4px 0 24px rgba(0,0,0,0.1); }
    .sidebar.mobile-open { transform: translateX(0); }
    .sidebar-overlay.mobile-open { display: block; opacity: 1; }
    .sidebar-close { display: block; }
    .menu-toggle { display: block; }
    .main-content { padding: 20px 16px; }
}

@media (max-width: 767px) {
    .sidebar { display: none !important; } /* No sidebar on mobile */
    .menu-toggle { display: none !important; } /* Hide menu toggle */
    .top-header { padding: 0 16px; }
    .brand-name { font-size: 16px; }
    .profile-info { display: none; }
    .main-content { padding: 16px 12px; }
    .cards { grid-template-columns: 1fr; }
    .form-control { font-size: 16px; /* Prevents iOS zoom */ }
    
    /* Full screen modals */
    .modal-overlay { padding: 0; }
    .modal-card { width: 100vw; height: 100vh; max-height: 100vh; border-radius: 0; transform: translateY(0); display: flex; flex-direction: column; margin: 0; }
    .modal-body { flex: 1; overflow-y: auto; }

    /* Card-style tables for mobile */
    .mobile-card-table thead { display: none; }
    .mobile-card-table tbody { display: flex; flex-direction: column; gap: 12px; background: transparent; }
    .mobile-card-table tr { display: flex; flex-direction: column; background: #fff; padding: 16px; border-radius: 12px; border: 1px solid #e5e5ea; }
    .mobile-card-table td { border: none !important; padding: 4px 0 !important; }
    .mobile-card-table td:first-child { font-weight: 700; font-size: 16px; margin-bottom: 8px; border-bottom: 1px solid #f2f2f7 !important; padding-bottom: 8px !important; }
    html.dark-mode .mobile-card-table tr { background: #1c1c1e; border-color: #333; }
    html.dark-mode .mobile-card-table td:first-child { border-color: #333 !important; }
    
    /* Back arrow only */
    .header h1 { font-size: 22px; }
    .header .btn-secondary span { display: none; } /* Hide text in back buttons */
}

/* Utility */
.header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.header h1 { font-size: 28px; font-weight: 700; letter-spacing: -0.5px; }

/* Dashboard Cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 20px; margin-bottom: 32px; }
.card { background: #fff; padding: 20px 24px; border-radius: 20px; box-shadow: 0 2px 10px rgba(0,0,0,0.03); border: 1px solid #e5e5ea; display: flex; align-items: center; gap: 16px; transition: transform 0.2s, box-shadow 0.2s; cursor: pointer; }
.card:hover { transform: translateY(-2px); box-shadow: 0 4px 16px rgba(0,0,0,0.06); border-color: #d1d1d6; }
.card-icon { width: 52px; height: 52px; background: #f2f2f7; color: #007aff; border-radius: 16px; display: flex; justify-content: center; align-items: center; font-size: 24px; }
.card-data { display: flex; flex-direction: column; }
.card-title { font-size: 14px; color: #8e8e93; font-weight: 500; margin-bottom: 6px; }
.card-value { font-size: 28px; font-weight: 700; color: #1c1c1e; line-height: 1; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 12px 20px; border-radius: 12px; font-size: 15px; font-weight: 600; justify-content: center; cursor: pointer; border: none; transition: 0.2s; white-space: nowrap; height: 44px; }
.btn-primary { background: #007aff; color: #fff; }
.btn-primary:hover { background: #005bb5; }
.btn-secondary { background: #fff; color: #1c1c1e; border: 1px solid #e5e5ea; box-shadow: 0 1px 2px rgba(0,0,0,0.02); }
.btn-secondary:hover { background: #f2f2f7; }
.btn-danger { background: #ff3b30; color: #fff; }
.btn-danger:hover { background: #d63026; }
.btn-icon { width: 44px; height: 44px; padding: 0; justify-content: center; }

/* Checkboxes / Radio */
.checkbox-group { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 8px; }
.checkbox-item { display: inline-flex; align-items: center; gap: 8px; background: #f2f2f7; padding: 10px 16px; border-radius: 10px; cursor: pointer; border: 1px solid transparent; transition: 0.2s; }
.checkbox-item:hover { background: #e5e5ea; }
.checkbox-item input { accent-color: #007aff; width: 16px; height: 16px; }

/* Form Elements */
.form-card { background: #fff; border-radius: 20px; padding: 24px; border: 1px solid #e5e5ea; box-shadow: 0 1px 4px rgba(0,0,0,0.02); margin-bottom: 24px; }
.form-group { margin-bottom: 20px; }
.form-group label { display: block; font-size: 14px; font-weight: 500; color: #3a3a3c; margin-bottom: 8px; }
.form-control { width: 100%; padding: 14px 16px; border-radius: 12px; border: 1px solid #d1d1d6; font-size: 15px; outline: none; transition: 0.2s; background: #fafafa; }
.form-control:focus { border-color: #007aff; box-shadow: 0 0 0 3px rgba(0,122,255,0.15); background: #fff; }
select.form-control { appearance: none; background-image: url('data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%238e8e93%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%3E%3C%2Fpath%3E%3C%2Fsvg%3E'); background-repeat: no-repeat; background-position: left 16px top 50%; background-size: 12px auto; }

/* Tables */
.table-container { background: #fff; border-radius: 20px; overflow: hidden; box-shadow: 0 1px 4px rgba(0,0,0,0.02); border: 1px solid #e5e5ea; }
table { width: 100%; border-collapse: collapse; text-align: right; }
th, td { padding: 16px 20px; border-bottom: 1px solid #e5e5ea; }
th { color: #8e8e93; font-weight: 500; font-size: 14px; background: #fafafa; }
td { font-size: 15px; color: #1c1c1e; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fcfcfc; }
.badge { display: inline-flex; padding: 4px 10px; background: #e5f1ff; color: #007aff; border-radius: 8px; font-size: 12px; margin-left: 6px; margin-bottom: 4px; font-weight: 500; }

/* Badges for Evaluation */
.badge-excellent { background: #e5fceb; color: #34c759; }
.badge-good { background: #e5f1ff; color: #007aff; }
.badge-attention { background: #fff4e5; color: #ff9500; }
.badge-weak { background: #ffe5e5; color: #ff3b30; }

/* Filter Panel */
.filter-panel { background: #fff; padding: 20px; border-radius: 16px; margin-bottom: 24px; border: 1px solid #e5e5ea; display: none; }
.filter-panel.active { display: block; }
.filter-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }

/* Tabs */
.tabs { display: flex; border-bottom: 1px solid #e5e5ea; margin-bottom: 16px; overflow-x: auto; scrollbar-width: none; }
.tab-btn { padding: 12px 16px; border: none; background: transparent; font-size: 15px; font-weight: 500; color: #8e8e93; cursor: pointer; white-space: nowrap; border-bottom: 2px solid transparent; transition: 0.2s; outline: none; }
.tab-btn.active { color: #007aff; border-bottom-color: #007aff; }
.tab-content { display: none; padding: 8px 0; }
.tab-content.active { display: block; }

/* Accordion */
.accordion-item { border-bottom: 1px solid #e5e5ea; }
.accordion-header { padding: 16px 0; font-size: 15px; font-weight: 600; cursor: pointer; display: flex; justify-content: space-between; align-items: center; color: #1c1c1e; }
.accordion-body { padding-bottom: 16px; display: none; color: #3a3a3c; font-size: 14px; line-height: 1.6; }
.accordion-header.active + .accordion-body { display: block; }
.accordion-header i { transition: transform 0.2s; }
.accordion-header.active i { transform: rotate(180deg); }

/* Modal */
.modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.4); display: none; align-items: center; justify-content: center; z-index: 1000; opacity: 0; transition: opacity 0.3s ease; }
.modal-overlay.active { display: flex; opacity: 1; }
.modal-card { background: #fff; width: 90%; max-width: 600px; max-height: 90vh; border-radius: 24px; box-shadow: 0 10px 40px rgba(0,0,0,0.1); display: flex; flex-direction: column; transform: translateY(20px); transition: transform 0.3s ease; overflow: hidden; }
.modal-overlay.active .modal-card { transform: translateY(0); }
.modal-header { padding: 20px 24px; border-bottom: 1px solid #e5e5ea; display: flex; justify-content: space-between; align-items: center; background: #fcfcfc; }
.modal-title { font-size: 18px; font-weight: 700; color: #1c1c1e; }
.modal-close { background: none; border: none; font-size: 20px; color: #8e8e93; cursor: pointer; transition: 0.2s; }
.modal-close:hover { color: #ff3b30; }
.modal-body { padding: 24px; overflow-y: auto; flex: 1; background: #fff; }

/* Timeline */
.timeline { position: relative; padding-right: 24px; margin-top: 16px; }
.timeline::before { content: ''; position: absolute; right: 8px; top: 0; bottom: 0; width: 2px; background: #e5e5ea; }
.timeline-item { position: relative; margin-bottom: 24px; }
.timeline-item::before { content: ''; position: absolute; right: -21px; top: 4px; width: 12px; height: 12px; border-radius: 50%; background: #007aff; border: 2px solid #fff; box-shadow: 0 0 0 1px #e5e5ea; }
.timeline-date { font-size: 12px; color: #8e8e93; margin-bottom: 4px; display: block; font-weight: 500; }
.timeline-content { font-size: 14px; color: #3a3a3c; background: #fdfdfd; border: 1px solid #f2f2f7; padding: 12px; border-radius: 12px; }

/* Smart Alerts */
.alerts-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; margin-bottom: 32px; }
.alert-card { background: #fff; border-right: 4px solid #ff3b30; padding: 16px; border-radius: 12px; box-shadow: 0 1px 4px rgba(0,0,0,0.02); display: flex; align-items: flex-start; gap: 12px; border: 1px solid #e5e5ea; border-right-width: 4px; }
.alert-card.warning { border-right-color: #ff9500; }
.alert-icon { font-size: 20px; color: #ff3b30; }
.alert-card.warning .alert-icon { color: #ff9500; }
.alert-title { font-size: 13px; font-weight: 700; margin-bottom: 4px; color: #1c1c1e; }
.alert-desc { font-size: 12px; color: #8e8e93; }

/* Print Styles */
.print-only { display: none; }
@media print {
    @page { size: A4; margin: 15mm; }
    .no-print, .sidebar, .header, .filter-panel, .btn, .tabs { display: none !important; }
    .print-only { display: block; }
    body { background: #fff; height: auto; overflow: visible; font-size: 12pt; }
    .main-content { padding: 0 !important; overflow: visible; }
    .form-card, .table-container, .accordion-item { border: none !important; box-shadow: none !important; }
    table { width: 100%; border-collapse: collapse; page-break-inside: auto; }
    tr { page-break-inside: avoid; page-break-after: auto; }
    th, td { border: 1px solid #000 !important; padding: 6px !important; color: #000 !important; }
    th { background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; font-weight: bold; }
    .accordion-body { display: block !important; padding: 0 !important; }
    .accordion-header { border-bottom: none !important; padding-bottom: 8px !important; margin-top: 16px !important; font-size: 16pt !important; border-bottom: 2px solid #000 !important; page-break-after: avoid; }
    .accordion-header i { display: none !important; }
}

/* Dark Mode */
html.dark-mode body, .dark-mode .main-content { background-color: #121212; color: #e0e0e0; }
html.dark-mode .sidebar { background: #1e1e1e; border-color: #333; }
html.dark-mode .sidebar-header { border-color: #333; }
html.dark-mode .sidebar-nav a { color: #aaa; }
html.dark-mode .sidebar-nav a:hover { background: #2c2c2e; }
html.dark-mode .sidebar-nav a.active { background: #1a3a5f; color: #4da3ff; }
html.dark-mode .card, html.dark-mode .form-card, html.dark-mode .table-container, html.dark-mode .filter-panel, html.dark-mode .modal-card { background: #1e1e1e; border-color: #333; color: #e0e0e0; }
html.dark-mode .card:hover { border-color: #555; }
html.dark-mode .card-icon { background: #2c2c2e; color: #4da3ff; }
html.dark-mode .card-title, html.dark-mode .header h1, html.dark-mode h2, html.dark-mode .sidebar-header h2 { color: #e0e0e0; }
html.dark-mode .card-value { color: #fff; }
html.dark-mode .btn-secondary { background: #2c2c2e; color: #e0e0e0; border-color: #444; }
html.dark-mode .btn-secondary:hover { background: #3a3a3c; }
html.dark-mode .form-control { background: #2c2c2e; border-color: #444; color: #e0e0e0; }
html.dark-mode .form-control:focus { border-color: #4da3ff; }
html.dark-mode th { background: #2c2c2e; border-bottom-color: #444; color: #aaa; }
html.dark-mode td { border-bottom-color: #444; color: #e0e0e0; }
html.dark-mode tr:hover td { background: #2a2a2c; }
html.dark-mode .accordion-item { border-color: #333; }
html.dark-mode .accordion-header { color: #e0e0e0; }
html.dark-mode .accordion-body { color: #aaa; }
html.dark-mode .modal-header { background: #1e1e1e; border-color: #333; }
html.dark-mode .modal-title { color: #e0e0e0; }
html.dark-mode .modal-body { background: #1e1e1e; color: #e0e0e0; }
html.dark-mode .checkbox-item { background: #2c2c2e; color: #e0e0e0; border-color: #333; }
html.dark-mode .checkbox-item:hover { background: #3a3a3c; }
html.dark-mode .tab-btn { color: #aaa; }
html.dark-mode .tab-btn.active { color: #4da3ff; border-bottom-color: #4da3ff; }
html.dark-mode .alert-card { background: #1e1e1e; border-color: #333; }
html.dark-mode .alert-title { color: #e0e0e0; }
html.dark-mode .alert-desc { color: #aaa; }
html.dark-mode select.form-control { background-image: url('data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23aaa%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%3E%3C%2Fpath%3E%3C%2Fsvg%3E'); }
html.dark-mode .badge { background: #1a3a5f; color: #4da3ff; }
html.dark-mode .badge-excellent { background: #153f23; color: #4cd964; }
html.dark-mode .badge-good { background: #1a3a5f; color: #4da3ff; }
html.dark-mode .badge-attention { background: #4a3411; color: #ff9f0a; }
html.dark-mode .badge-weak { background: #4f1c1a; color: #ff453a; }
html.dark-mode .timeline-content { border-color: #333; background: #2c2c2e; color: #e0e0e0; }
html.dark-mode .timeline::before { background: #333; }
