:root {
    --primary: #0f766e;
    --primary-dark: #134e4a;
    --bg-color: #f1f5f9;
    --surface: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --success: #059669;
    --danger: #ef4444;
    --warning: #f59e0b;
}

* { box-sizing: border-box; margin: 0; padding: 0; outline: none; font-family: 'Tajawal', sans-serif; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-color); }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }

body { background-color: var(--bg-color); color: var(--text-main); display: flex; height: 100vh; width: 100vw; overflow: hidden; }

/* القائمة الجانبية */
.sidebar { width: 260px; background-color: var(--surface); border-left: 1px solid var(--border); display: flex; flex-direction: column; z-index: 100; box-shadow: -2px 0 10px rgba(0,0,0,0.02); flex-shrink: 0; }
.app-brand { padding: 25px 20px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--border); }
.app-brand .material-icons-round { color: var(--primary); font-size: 32px; }
.app-brand h2 { font-size: 19px; font-weight: 900; color: var(--primary-dark); }
.nav-links { flex: 1; padding: 15px 10px; overflow-y: auto; }
.nav-item { display: flex; justify-content: space-between; align-items: center; padding: 12px 15px; border-radius: 10px; color: var(--text-muted); cursor: pointer; transition: 0.2s; font-weight: 700; margin-bottom: 5px; text-decoration: none; }
.nav-item:hover, .nav-item.active { background-color: #f0fdfa; color: var(--primary); }
.nav-item.active .material-icons-round { color: var(--primary); }
.nav-item-content { display: flex; align-items: center; gap: 12px; }

/* ملف المستخدم */
.user-profile { padding: 15px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 10px; cursor: pointer; transition: background 0.2s; }
.user-profile:hover { background: #f8fafc; }
.avatar { width: 42px; height: 42px; border-radius: 50%; background: var(--primary); color: white; display: flex; align-items: center; justify-content: center; font-weight: 900; overflow: hidden; flex-shrink: 0; }
.user-info { flex: 1; overflow: hidden; }
.user-info h4 { font-size: 13px; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-info p { font-size: 11px; color: var(--text-muted); }
.logout-btn { background: #fef2f2; color: var(--danger); border: none; padding: 8px; border-radius: 8px; cursor: pointer; transition: 0.2s; }
.logout-btn:hover { background: #fee2e2; }

/* المحتوى الرئيسي */
.main-content { flex: 1; display: flex; flex-direction: column; height: 100vh; min-width: 0; overflow: hidden; position: relative; z-index: 1; }
.topbar { background-color: var(--surface); height: 75px; min-height: 75px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 25px; z-index: 5; flex-shrink: 0; gap: 20px; }
.page-content { flex: 1; overflow-y: auto; padding: 25px; padding-bottom: 100px; display: none; opacity: 0; }
.page-content.active { display: block; opacity: 1; animation: fadeIn 0.2s forwards; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

/* الأزرار والعناصر */
.btn-add { background: var(--primary); color: white; border: none; padding: 10px 22px; border-radius: 10px; font-weight: 800; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; transition: 0.2s; font-size: 14px; white-space: nowrap; }
.btn-add:hover { background: var(--primary-dark); transform: translateY(-1px); box-shadow: 0 4px 8px rgba(15,118,110,0.2); }
.btn-danger { background: var(--danger); color: white; border: none; padding: 10px 20px; border-radius: 10px; font-weight: bold; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; transition: 0.2s; }
.btn-action { padding: 8px 16px; border-radius: 8px; border: 1px solid var(--border); background: white; cursor: pointer; display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: bold; transition: 0.2s; color: var(--text-main); }
.btn-action:hover { background: #f8fafc; border-color: var(--primary); color: var(--primary); }
.search-input, .org-input { width: 100%; padding: 10px 15px; border: 1px solid var(--border); border-radius: 8px; font-family: 'Tajawal'; font-size: 14px; margin-bottom: 8px; background: #f8fafc; outline: none; transition: 0.2s; }
.search-input:focus, .org-input:focus { border-color: var(--primary); background: white; }
.en-num { font-family: Arial, sans-serif !important; direction: ltr; display: inline-block; text-align: left; }

/* الإحصائيات */
.welcome-banner { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: white; padding: 30px; border-radius: 20px; box-shadow: 0 8px 20px rgba(15,118,110,0.15); margin-bottom: 25px; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 20px; margin-bottom: 30px; }
.stat-card { background: white; border-radius: 15px; padding: 20px; border: 1px solid var(--border); box-shadow: 0 4px 15px rgba(0,0,0,0.03); display: flex; align-items: center; gap: 20px; transition: 0.2s; }
.stat-icon { width: 60px; height: 60px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 30px; color: white; flex-shrink: 0; }
.stat-info h3 { font-size: 24px; font-weight: 900; margin-bottom: 5px; font-family: Arial; }

/* الجداول والأقسام (تم إرجاع التنسيقات المفقودة) */
.admin-table { width: 100%; border-collapse: collapse; background: white; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 10px rgba(0,0,0,0.03); }
.admin-table th { background: #f8fafc; padding: 15px; text-align: right; font-size: 13px; color: var(--text-muted); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 2; }
.admin-table td { padding: 15px; border-bottom: 1px solid var(--border); font-size: 14px; font-weight: 700; vertical-align: middle; }
.org-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(350px, 1fr)); gap: 20px; }
.org-card { background: white; border-radius: 12px; border: 1px solid var(--border); overflow: hidden; box-shadow: 0 2px 10px rgba(0,0,0,0.02); }
.org-card-header { background: #f8fafc; padding: 15px; border-bottom: 1px solid var(--border); font-weight: 900; color: var(--primary-dark); display: flex; justify-content: space-between; align-items: center; }
.org-card-body { padding: 15px; }
.role-section { margin-bottom: 15px; }
.role-title { font-size: 12px; color: var(--text-muted); font-weight: bold; margin-bottom: 8px; border-bottom: 1px dashed var(--border); padding-bottom: 5px; }
.role-user-item { display: flex; justify-content: space-between; align-items: center; background: #f1f5f9; padding: 8px 10px; border-radius: 6px; font-size: 13px; margin-bottom: 5px; font-weight: bold; }
.role-tag { display: inline-block; padding: 4px 10px; border-radius: 12px; font-size: 12px; font-weight: bold; margin: 2px; }
.role-tag.admin { background: #fef2f2; color: #dc2626; }
.role-tag.dept { background: #f0fdfa; color: #0f766e; border: 1px solid #ccfbf1; }

/* النوافذ المنبثقة */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 2000; display: none; align-items: center; justify-content: center; backdrop-filter: blur(4px); }
.modal-content { background: white; width: 90%; max-width: 800px; max-height: 90vh; border-radius: 16px; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 20px 40px rgba(0,0,0,0.2); }
.modal-header { padding: 15px 20px; background: var(--primary); color: white; display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; }
.modal-body { flex: 1; padding: 25px; background: var(--bg-color); overflow-y: auto; min-height: 0; }

/* المراسلات والتبويبات (التصميم الذي كان مفقوداً) */
.corr-header { display: flex; gap: 10px; margin-bottom: 20px; border-bottom: 2px solid var(--border); padding-bottom: 15px; flex-wrap: wrap; }
.corr-tab { background: transparent; border: none; font-size: 14px; font-weight: 800; color: var(--text-muted); padding: 8px 15px; cursor: pointer; border-radius: 8px; transition: 0.2s; }
.corr-tab.active, .corr-tab:hover { background: #f0fdfa; color: var(--primary); }
.msg-list { background: white; border-radius: 12px; border: 1px solid var(--border); overflow: hidden; }
.msg-row { display: grid; grid-template-columns: 50px 180px 1fr 100px 120px; align-items: center; padding: 15px 20px; border-bottom: 1px solid var(--border); cursor: pointer; transition: 0.2s; color: var(--text-muted); }
.msg-row:hover { background: #f8fafc; }
.rt-toolbar { display: flex; gap: 5px; padding: 8px; background: #f8fafc; border: 1px solid var(--border); border-bottom: none; border-radius: 8px 8px 0 0; }
.rt-btn { background: white; border: 1px solid var(--border); padding: 5px 10px; border-radius: 4px; cursor: pointer; font-family: 'Tajawal'; font-weight: bold; font-size: 12px; color: var(--primary-dark); }
.rt-btn:hover { background: #e0f2fe; }
.rt-editor { height: 200px; border: 1px solid var(--border); border-radius: 0 0 8px 8px; padding: 15px; overflow-y: auto; background: white; outline: none; line-height: 1.6; margin-bottom: 15px; }

/* أدوات المستندات PDF (التصميم الذي كان مفقوداً) */
.pdf-tool-tabs { display: flex; gap: 10px; margin-bottom: 20px; border-bottom: 2px solid var(--border); padding-bottom: 15px; overflow-x: auto; }
.pdf-tool-tab { background: white; border: 1px solid var(--border); padding: 10px 20px; border-radius: 8px; cursor: pointer; font-weight: bold; color: var(--text-muted); transition: 0.2s; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.pdf-tool-tab.active, .pdf-tool-tab:hover { background: #f0fdfa; color: var(--primary); border-color: var(--primary); }
.pdf-tool-content { display: none; background: white; padding: 25px; border-radius: 12px; border: 1px solid var(--border); position: relative; }
.pdf-tool-content.active { display: block; animation: fadeIn 0.15s ease; }
.pdf-upload-zone { display: block; border: 2px dashed var(--primary); background: #f0fdfa; padding: 30px; text-align: center; border-radius: 12px; cursor: pointer; margin-bottom: 20px; transition: 0.2s; }
.pdf-upload-zone:hover { background: #ccfbf1; }
.pdf-pages-scroll-container { width: 100%; background: #e2e8f0; padding: 20px; overflow-y: auto; max-height: 650px; border-radius: 8px; border: 1px solid var(--border); display: flex; flex-wrap: wrap; justify-content: center; gap: 15px; }
.pdf-page-wrapper { position: relative; box-shadow: 0 5px 20px rgba(0,0,0,0.15); border: 2px solid #cbd5e1; background: white; margin-bottom: 10px; max-width: 100%; }
.pdf-page-wrapper canvas { max-width: 100%; height: auto !important; display: block; margin: 0 auto; }
.pdf-page-toolbar { background: #1e293b; color: white; padding: 8px 15px; display: flex; justify-content: space-between; align-items: center; font-size: 13px; font-weight: bold; }
.draggable-sig { position: absolute; cursor: grab; z-index: 1000; display: inline-flex; align-items: center; justify-content: center; border: 2px dashed #0ea5e9; background: rgba(255,255,255,0.2); }
.draggable-sig:active { cursor: grabbing; }
.sig-controls { position: absolute; top: -25px; right: 0; background: #ef4444; color: white; padding: 2px 8px; border-radius: 4px 4px 0 0; font-size: 11px; font-weight: bold; cursor: pointer; display: flex; align-items: center; gap: 4px; height: 25px; z-index: 1001; }
.rotate-handle { position: absolute; bottom: -12px; right: -12px; width: 24px; height: 24px; background: var(--warning); border-radius: 50%; border: 2px solid white; cursor: alias; display: flex; align-items: center; justify-content: center; z-index: 1002; box-shadow: 0 2px 5px rgba(0,0,0,0.3); }
.rotate-handle i { color: white; font-size: 12px; pointer-events: none; }
.pdf-page-preview { border: 2px solid #cbd5e1; margin: 5px; display: inline-flex; flex-direction: column; position: relative; background: white; transition: 0.2s; width: 140px; border-radius: 6px; box-shadow: 0 2px 5px rgba(0,0,0,0.05); overflow: hidden; }
.pdf-page-preview img { width: 100%; height: 140px; object-fit: contain; pointer-events: none; }
.pdf-page-preview.selected { border-color: var(--success); box-shadow: 0 0 0 3px rgba(5,150,105,0.3); }
.tool-topbar { background: #f8fafc; padding: 15px; border-radius: 8px; width: 100%; margin-bottom: 15px; display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; justify-content: space-between; border: 1px solid var(--border); }
.tool-topbar-group { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }

/* متفرقات */
.loader { width: 24px; height: 24px; border: 3px solid #f3f3f3; border-top: 3px solid var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 0 auto; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
.floating-fab { position: fixed; bottom: 30px; left: 30px; width: 60px; height: 60px; background: var(--primary); color: white; border-radius: 50%; display: flex; align-items: center; justify-content: center; box-shadow: 0 8px 25px rgba(15,118,110,0.5); cursor: pointer; z-index: 9999; transition: 0.3s; border: 3px solid white; }
.floating-fab:hover { transform: scale(1.1) rotate(5deg); background: var(--primary-dark); }
.toast-notification { position: fixed; top: -100px; left: 0; right: 0; margin: 0 auto; width: max-content; max-width: 90%; background: white; color: var(--text-main); padding: 15px 25px; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,0.1); display: flex; align-items: center; gap: 15px; z-index: 99999; font-weight: bold; transition: all 0.4s ease; border-right: 4px solid var(--primary); pointer-events: none; }
.toast-notification.show { top: 30px; }
.admin-nav-btn { display: flex !important; } 
.danger-zone { background: #fff5f5; border: 1px solid #fca5a5; border-radius: 12px; padding: 20px; margin-top: 20px; }

@media print { 
    body { background: white !important; height: auto !important; overflow: visible !important; display: block !important; } 
    .sidebar, .topbar, .no-print, .search-container, h3, .floating-fab { display: none !important; } 
    .main-content { margin: 0 !important; padding: 0 !important; overflow: visible !important; height: auto !important; display: block !important; } 
    .page-content { display: block !important; padding: 0 !important; height: auto !important; overflow: visible !important; opacity: 1 !important; } 
    #inquiry { display: block !important; } 
    .page-content:not(#inquiry) { display: none !important; } 
}