:root {
    --primary: #2563eb;       /* Modern Blue */
    --primary-dark: #1e40af;
    --bg-body: #f8fafc;       /* Cool Gray Background */
    --bg-card: #ffffff;
    --text-main: #0f172a;     /* Slate 900 */
    --text-muted: #64748b;    /* Slate 500 */
    --border: #e2e8f0;        /* Slate 200 */
    --danger: #ef4444;
    --success: #10b981;
    --warning: #f59e0b;
    --radius: 12px;           /* More rounded corners */
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    --sidebar-width: 280px;
    --header-height: 60px;
}

/* Reset & Basics */
* { box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Tahoma", sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    margin: 0;
    direction: rtl;
    text-align: right;
    font-size: 14px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

a { text-decoration: none; color: var(--primary); transition: 0.2s; }
a:hover { color: var(--primary-dark); }

svg {
    width: 20px;
    height: 20px;
    vertical-align: middle;
    display: inline-block;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* Login Page Styles */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f3f4f6;
    padding: 20px;
}
.login-card {
    width: 100%;
    max-width: 400px;
    background: white;
    padding: 2.5rem;
    border-radius: var(--radius);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    border: 1px solid var(--border);
}
.login-logo {
    text-align: center;
    margin-bottom: 2rem;
    color: var(--primary);
}
.login-logo svg {
    width: 64px;
    height: 64px;
    margin-bottom: 10px;
}

/* Mobile Header (Visible only on mobile) */
.mobile-header {
    display: none;
    background: #111827;
    color: white;
    padding: 0 1.5rem;
    height: var(--header-height);
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 999;
}
.mobile-logo { font-weight: 700; font-size: 1.1rem; }
.btn-icon {
    background: transparent;
    border: none;
    color: white;
    cursor: pointer;
    padding: 5px;
    display: flex;
    align-items: center;
}
.btn-icon svg { width: 28px; height: 28px; }

/* Backdrop */
.cms-backdrop {
    position: fixed;
    top: 0; right: 0; left: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}
.cms-backdrop.active { display: block; opacity: 1; }

/* CMS Layout */
.cms-layout {
    display: flex;
    min-height: 100vh;
}

.cms-sidebar {
    width: var(--sidebar-width);
    background: #111827; /* Dark sidebar */
    color: white;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    right: 0;
    top: 0;
    z-index: 1000;
    transition: transform 0.3s ease-in-out;
}

.cms-content {
    flex-grow: 1;
    margin-right: var(--sidebar-width);
    padding: 2rem;
    overflow-x: hidden;
    width: 100%;
}

/* Sidebar Elements */
.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid #374151;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: bold;
    font-size: 1.1rem;
    color: #f3f4f6;
    background: #1f2937;
    height: var(--header-height); /* Match mobile header height */
}
.sidebar-header svg { color: #60a5fa; width: 28px; height: 28px; }

.sidebar-menu {
    list-style: none;
    padding: 0;
    margin: 1rem 0;
    flex-grow: 1;
}

.sidebar-menu li a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0.85rem 1.5rem;
    color: #d1d5db;
    transition: all 0.2s;
    font-size: 0.95rem;
    border-right: 3px solid transparent;
}

.sidebar-menu li a:hover, .sidebar-menu li a.active {
    background: #1f2937;
    color: #fff;
    border-right-color: #3b82f6;
    padding-right: 1.8rem; /* Slide effect */
}
.sidebar-menu li a svg { width: 22px; height: 22px; opacity: 0.8; }

.sidebar-footer {
    margin-top: auto;
    padding: 1rem;
    border-top: 1px solid #374151;
    background: #1f2937;
}

.user-mini-profile {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 15px;
    color: #9ca3af;
    font-size: 0.9rem;
    padding: 0 5px;
}

/* Header (Legacy for non-admin pages / case view) */
.header {
    background: #fff;
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 0;
    margin-bottom: 2rem;
    box-shadow: var(--shadow);
}
.header .container {
    padding: 0 2rem;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.header-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-dark);
}
.header-brand svg { width: 28px; height: 28px; color: var(--primary); }
.header-user { display: flex; align-items: center; gap: 15px; }

/* Buttons */
.btn, .btn-secondary, .btn-danger, .btn-logout {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 0.65rem 1.25rem; 
    border-radius: 8px; 
    font-weight: 600; 
    cursor: pointer;
    font-size: 0.95rem; gap: 8px; transition: 0.2s;
    border: 1px solid transparent;
}
.btn { background-color: var(--primary); color: white; box-shadow: 0 1px 2px rgba(0,0,0,0.1); }
.btn:hover { background-color: var(--primary-dark); box-shadow: 0 4px 6px rgba(37, 99, 235, 0.2); }

.btn-secondary { background-color: white; border-color: #d1d5db; color: #374151; }
.btn-secondary:hover { background-color: #f9fafb; border-color: #9ca3af; color: #111827; }

.btn-danger { background-color: #ef4444; color: white; }
.btn-danger:hover { background-color: #dc2626; }

.btn-logout { background: #fee2e2; color: #991b1b; padding: 8px 16px; font-size: 0.85rem; }
.btn-logout:hover { background: #fecaca; }

.btn-small { padding: 0.4rem 0.85rem; font-size: 0.85rem; }
.btn-block { width: 100%; }
.btn-icon:focus { outline: none; }

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2.5rem;
}
.stat-card {
    background: white;
    padding: 1.5rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: transform 0.2s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1); }
.stat-content h3 { font-size: 0.9rem; color: var(--text-muted); margin: 0 0 5px 0; font-weight: normal; }
.stat-content .value { font-size: 1.75rem; font-weight: 800; color: var(--text-main); }
.stat-icon-wrapper {
    background: #eff6ff;
    color: var(--primary);
    padding: 12px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.stat-icon-wrapper svg { width: 32px; height: 32px; }

/* Cards & Layout */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
}

.card-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}
.card-header h2 { margin: 0; font-size: 1.1rem; color: var(--text-main); font-weight: 700; }
.card-header svg { color: var(--primary); width: 22px; height: 22px; }

/* Forms */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.form-group { margin-bottom: 1.25rem; }

label { display: block; margin-bottom: 0.5rem; font-weight: 600; color: #374151; font-size: 0.9rem; }

input[type="text"], input[type="password"], input[type="file"], textarea, select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: inherit;
    transition: all 0.2s;
    background-color: #fff;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Upload Area */
.upload-area {
    border: 2px dashed #cbd5e1;
    border-radius: var(--radius);
    padding: 2.5rem 1.5rem;
    text-align: center;
    background: #f8fafc;
    cursor: pointer;
    transition: all 0.3s ease;
}
.upload-area:hover, .upload-area.active { border-color: var(--primary); background: #eff6ff; }
.upload-icon { color: var(--primary); margin-bottom: 1rem; opacity: 0.8; }
.upload-text { font-weight: 600; font-size: 1rem; color: var(--text-main); margin-bottom: 0.5rem; }
.upload-hint { font-size: 0.85rem; color: var(--text-muted); }

/* File List */
.file-list { margin-top: 1.5rem; display: flex; flex-direction: column; gap: 8px; }
.file-item {
    display: flex; align-items: center; justify-content: space-between;
    background: white; padding: 12px 16px; border-radius: 8px; border: 1px solid var(--border);
    font-size: 0.9rem; animation: fadeIn 0.3s ease-in-out;
}
.file-info { display: flex; align-items: center; gap: 10px; font-weight: 500; }
.file-size { font-size: 0.75rem; color: var(--text-muted); background: #f3f4f6; padding: 4px 8px; border-radius: 6px; }

/* Tables */
.table-responsive { width: 100%; overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; background: white; }
th { background: #f9fafb; color: #4b5563; font-weight: 600; text-align: right; padding: 14px 16px; border-bottom: 1px solid var(--border); font-size: 0.85rem; text-transform: uppercase; white-space: nowrap; }
td { padding: 14px 16px; border-bottom: 1px solid var(--border); color: #334155; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background-color: #f8fafc; }

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}
.pagination a {
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: white;
    color: var(--text-main);
    font-size: 0.9rem;
    font-weight: 500;
}
.pagination a.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}
.pagination a:hover:not(.active) {
    background: #f1f5f9;
}

/* Alerts, Badges, Chat */
.alert { padding: 1rem; margin-bottom: 1.5rem; border-radius: 8px; font-weight: 500; display: flex; align-items: center; gap: 10px; }
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }

.badge { display: inline-flex; padding: 4px 10px; border-radius: 99px; font-size: 0.75rem; font-weight: 700; white-space: nowrap; }
.badge-pending { background: #fff7ed; color: #c2410c; border: 1px solid #fed7aa; }
.badge-approved { background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; }
.badge-rejected { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.badge-count { background: var(--danger); color: white; font-size: 0.75rem; font-weight: bold; border-radius: 99px; padding: 2px 8px; box-shadow: 0 2px 4px rgba(220, 38, 38, 0.3); }

.chat-box { background: #f9fafb; border: 1px solid var(--border); border-radius: var(--radius); height: 400px; overflow-y: auto; padding: 1.5rem; display: flex; flex-direction: column; gap: 1rem; margin-bottom: 1rem; }
.msg-row { display: flex; align-items: flex-end; gap: 10px; max-width: 85%; }
.msg-row.me { align-self: flex-end; flex-direction: row-reverse; }
.msg-row.other { align-self: flex-start; }
.msg-avatar { width: 32px; height: 32px; border-radius: 50%; background: #e5e7eb; color: #4b5563; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.8rem; flex-shrink: 0; }
.msg-bubble { padding: 0.85rem 1rem; border-radius: 16px; position: relative; font-size: 0.95rem; line-height: 1.5; box-shadow: 0 1px 2px rgba(0,0,0,0.05); }
.msg-row.other .msg-bubble { background: white; border: 1px solid var(--border); color: var(--text-main); border-bottom-right-radius: 4px; }
.msg-row.me .msg-bubble { background: var(--primary); color: white; border-bottom-left-radius: 4px; }
.msg-meta { font-size: 0.7rem; margin-top: 4px; opacity: 0.8; display: flex; gap: 6px; align-items: center; }

/* Notification Banner */
.notification-banner {
    background: #fffbeb; border: 1px solid #fcd34d; color: #92400e;
    padding: 1rem; border-radius: var(--radius); margin-bottom: 2rem;
    display: flex; align-items: center; gap: 12px; font-weight: 600;
}

/* Animations */
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

/* 
   ===================================
   MOBILE RESPONSIVE RULES 
   =================================== 
*/
@media (max-width: 992px) {
    .mobile-header { display: flex; }
    
    .cms-layout { display: block; } /* Remove flex layout on mobile */
    
    .cms-sidebar { 
        transform: translateX(100%); /* Hide sidebar off-screen */
        right: 0;
        top: 0;
        bottom: 0;
        height: 100vh;
        width: 280px;
        box-shadow: -4px 0 15px rgba(0,0,0,0.1);
    }
    
    .cms-sidebar.active {
        transform: translateX(0); /* Slide in */
    }

    .cms-content { 
        margin-right: 0; 
        padding: 1.5rem 1rem; 
        width: 100%;
    }

    .form-grid { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    /* Smart Tables (Cards) */
    table, thead, tbody, th, td, tr { display: block; }
    
    /* Hide Table Header */
    thead tr { position: absolute; top: -9999px; left: -9999px; }
    
    tr { 
        margin-bottom: 1rem; 
        border: 1px solid var(--border); 
        border-radius: var(--radius); 
        background: white; 
        padding: 0; 
        box-shadow: var(--shadow); 
        overflow: hidden;
    }
    
    td { 
        border: none; 
        position: relative; 
        padding: 12px 16px; 
        border-bottom: 1px solid #f1f5f9; 
        display: flex;
        justify-content: space-between;
        align-items: center;
        text-align: left; /* Value align */
    }
    
    td:last-child { border-bottom: none; background: #f8fafc; justify-content: flex-end; }
    
    /* Mobile Label */
    td::before { 
        content: attr(data-label); 
        font-weight: 600; 
        color: var(--text-muted); 
        font-size: 0.85rem; 
        text-align: right;
        margin-left: 10px;
        flex-shrink: 0;
    }

    .header .container { padding: 0 1rem; flex-direction: column; gap: 10px; align-items: flex-start; }
    .header-user { width: 100%; justify-content: space-between; }
    
    .pagination { font-size: 0.85rem; }
    .pagination a { padding: 6px 10px; }
}