/* =========================================================
   نظام الأرشفة - شركة المندرة العربية
   نظام تصميم احترافي - Design System v2
   ========================================================= */

:root {
    /* الهوية اللونية: أزرق مياه + أخضر بترولي للصرف الصحي */
    --primary: #0e7490;
    --primary-dark: #0b5566;
    --primary-light: #e0f2f8;
    --secondary: #0d9488;
    --accent: #d9a441;

    --sidebar-bg: #0b3142;
    --sidebar-bg-2: #0e4256;
    --sidebar-text: #c9dde4;
    --sidebar-text-active: #ffffff;
    --sidebar-active-bg: rgba(255, 255, 255, 0.10);

    --bg: #f3f6f8;
    --card-bg: #ffffff;
    --border: #e2e8ec;
    --border-strong: #cdd8de;
    --text: #1e2b33;
    --text-muted: #6b7c86;
    --text-faint: #98a7ae;

    --success: #16814f;
    --success-bg: #e3f7ec;
    --error: #c0392b;
    --error-bg: #fce9e6;
    --warning: #a3690f;
    --warning-bg: #fdf1de;
    --info: #2563a8;
    --info-bg: #e6f0fa;

    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 16px;

    --shadow-sm: 0 1px 2px rgba(15, 40, 55, 0.06);
    --shadow: 0 2px 10px rgba(15, 40, 55, 0.07);
    --shadow-lg: 0 12px 32px rgba(15, 40, 55, 0.14);

    --font: "Cairo", "Segoe UI", Tahoma, Arial, sans-serif;
    --sidebar-width: 264px;
    --topbar-height: 66px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    direction: rtl;
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 4px; font-weight: 700; color: var(--text); letter-spacing: -0.01em; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.05rem; margin-bottom: 12px; }

/* =========================================================
   الهيكل العام: شريط جانبي + شريط علوي + محتوى
   ========================================================= */

.app-shell { display: flex; min-height: 100vh; }

/* --------- الشريط الجانبي --------- */
.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: linear-gradient(180deg, var(--sidebar-bg) 0%, var(--sidebar-bg-2) 100%);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 40;
    transition: transform 0.25s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 22px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.sidebar-brand .logo-badge {
    width: 42px; height: 42px; border-radius: 12px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}
.sidebar-brand .logo-badge svg { width: 22px; height: 22px; stroke: #fff; }
.sidebar-brand .brand-text { line-height: 1.3; }
.sidebar-brand .brand-text strong { display: block; color: #fff; font-size: 0.98rem; font-weight: 700; }
.sidebar-brand .brand-text span { display: block; color: var(--sidebar-text); font-size: 0.75rem; opacity: 0.85; }

.sidebar-cta { padding: 16px 16px 4px; }
.sidebar-cta a {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    background: var(--accent); color: #2b2107;
    padding: 11px 14px; border-radius: var(--radius-sm);
    font-weight: 700; font-size: 0.88rem;
    box-shadow: 0 4px 14px rgba(217, 164, 65, 0.35);
}
.sidebar-cta a:hover { background: #e5b458; text-decoration: none; }
.sidebar-cta a svg { width: 16px; height: 16px; stroke: #2b2107; }

.sidebar-nav { flex: 1; padding: 10px 12px 20px; }
.sidebar-section-title {
    font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em;
    color: var(--sidebar-text); opacity: 0.55; font-weight: 700;
    padding: 18px 10px 6px;
}
.sidebar-nav a {
    display: flex; align-items: center; gap: 11px;
    padding: 9px 12px; margin-bottom: 2px;
    border-radius: var(--radius-sm);
    color: var(--sidebar-text); font-size: 0.89rem; font-weight: 600;
}
.sidebar-nav a svg { width: 17px; height: 17px; stroke: currentColor; flex-shrink: 0; opacity: 0.9; }
.sidebar-nav a:hover { background: rgba(255, 255, 255, 0.06); color: var(--sidebar-text-active); text-decoration: none; }
.sidebar-nav a.active { background: var(--sidebar-active-bg); color: var(--sidebar-text-active); box-shadow: inset 3px 0 0 var(--accent); }
.sidebar-nav a .nav-count {
    margin-inline-start: auto; background: rgba(255, 255, 255, 0.14);
    color: #fff; font-size: 0.72rem; font-weight: 700;
    padding: 1px 8px; border-radius: 999px;
}
.sidebar-nav a.nav-count-alert .nav-count { background: var(--error); }

.sidebar-footer {
    padding: 14px 20px; border-top: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 0.72rem; color: var(--sidebar-text); opacity: 0.6;
}

/* --------- الشريط العلوي --------- */
.topbar {
    position: sticky; top: 0; z-index: 30;
    height: var(--topbar-height);
    background: #fff;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 24px;
    gap: 16px;
}
.topbar-start { display: flex; align-items: center; gap: 14px; min-width: 0; }
.sidebar-toggle {
    display: none; background: none; border: 1px solid var(--border); border-radius: var(--radius-sm);
    width: 38px; height: 38px; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0;
}
.sidebar-toggle svg { width: 18px; height: 18px; stroke: var(--text); }
.topbar-title { font-weight: 700; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.topbar-end { display: flex; align-items: center; gap: 10px; }

.sector-form select {
    padding: 8px 30px 8px 12px;
    border-radius: 999px;
    border: 1px solid var(--border-strong);
    background: var(--bg);
    font-family: inherit; font-size: 0.85rem; font-weight: 600; color: var(--text);
    cursor: pointer;
}

.icon-btn {
    position: relative;
    width: 38px; height: 38px; border-radius: 999px;
    border: 1px solid var(--border); background: #fff;
    display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.icon-btn svg { width: 18px; height: 18px; stroke: var(--text-muted); }
.icon-btn:hover { background: var(--bg); }
.icon-btn .dot {
    position: absolute; top: 5px; left: 5px; width: 8px; height: 8px;
    background: var(--error); border-radius: 50%; border: 2px solid #fff;
}

.dropdown { position: relative; }
.dropdown > button {
    display: flex; align-items: center; gap: 8px;
    border: 1px solid var(--border); background: #fff;
    padding: 6px 12px 6px 8px; border-radius: 999px;
    font-family: inherit; font-size: 0.86rem; font-weight: 600; color: var(--text);
    cursor: pointer;
}
.dropdown > button:hover { background: var(--bg); }
.dropdown > button .avatar {
    width: 26px; height: 26px; border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: #fff; font-size: 0.78rem; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
}
.dropdown > button svg.chev { width: 13px; height: 13px; stroke: var(--text-muted); }

.dropdown-menu {
    display: none;
    position: absolute; top: calc(100% + 8px); left: 0;
    background: #fff; color: var(--text);
    min-width: 210px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    z-index: 100;
    padding: 6px;
}
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu a {
    display: flex; align-items: center; gap: 9px;
    padding: 9px 10px; border-radius: var(--radius-sm);
    color: var(--text); font-size: 0.87rem; font-weight: 600;
}
.dropdown-menu a svg { width: 15px; height: 15px; stroke: var(--text-muted); }
.dropdown-menu a:hover { background: var(--bg); text-decoration: none; }
.dropdown-menu .menu-divider { height: 1px; background: var(--border); margin: 6px 4px; }

/* --------- المحتوى --------- */
.main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.container { max-width: 1240px; margin: 0 auto; padding: 26px 24px 40px; width: 100%; }

.sidebar-backdrop { display: none; }

/* =========================================================
   المكونات المشتركة
   ========================================================= */

.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 18px;
    box-shadow: var(--shadow-sm);
}

.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }

.stat-card {
    display: flex; align-items: center; gap: 14px;
    padding: 20px; position: relative; overflow: hidden;
}
.stat-card .stat-icon {
    width: 46px; height: 46px; border-radius: 12px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    background: var(--primary-light); color: var(--primary);
}
.stat-card .stat-icon svg { width: 22px; height: 22px; stroke: currentColor; }
.stat-card.stat-warning .stat-icon { background: var(--warning-bg); color: var(--warning); }
.stat-card.stat-error .stat-icon { background: var(--error-bg); color: var(--error); }
.stat-card.stat-success .stat-icon { background: var(--success-bg); color: var(--success); }
.stat-card .stat-value { font-size: 1.7rem; font-weight: 800; color: var(--text); line-height: 1.15; }
.stat-card .stat-label { color: var(--text-muted); font-size: 0.83rem; margin-top: 2px; }
.stat-card .stat-value a { color: var(--primary); font-size: 1.1rem; }

.page-header {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    margin-bottom: 18px; flex-wrap: wrap;
}
.page-header h2 { display: flex; align-items: center; gap: 10px; }
.page-header .page-subtitle { color: var(--text-muted); font-size: 0.88rem; margin-top: 2px; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 10px; border-bottom: 1px solid var(--border); text-align: right; font-size: 0.89rem; }
th { background: var(--bg); font-weight: 700; color: var(--text-muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.02em; }
tbody tr:hover { background: var(--primary-light); }
.card table { margin: -4px -4px 0; width: calc(100% + 8px); }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 4px 11px; border-radius: 999px; font-size: 0.76rem; font-weight: 700; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-available { background: var(--success-bg); color: var(--success); }
.badge-borrowed { background: var(--warning-bg); color: var(--warning); }
.badge-overdue { background: var(--error-bg); color: var(--error); }
.badge-archived { background: #eef1f3; color: var(--text-muted); }

.btn {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 9px 18px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--primary);
    background: var(--primary);
    color: #fff;
    cursor: pointer;
    font-size: 0.88rem; font-weight: 700;
    font-family: inherit;
    transition: background 0.15s ease, box-shadow 0.15s ease;
}
.btn svg { width: 15px; height: 15px; stroke: currentColor; }
.btn:hover { background: var(--primary-dark); border-color: var(--primary-dark); text-decoration: none; box-shadow: var(--shadow); }
.btn-secondary { background: #fff; color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--bg); border-color: var(--border-strong); box-shadow: none; }
.btn-danger { background: var(--error); border-color: var(--error); }
.btn-danger:hover { background: #96271b; border-color: #96271b; }
.btn-sm { padding: 5px 12px; font-size: 0.78rem; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 700; font-size: 0.85rem; color: var(--text); }
.form-control {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-family: inherit;
    background: #fff;
    color: var(--text);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }

.filters-bar { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.filters-bar .form-group { margin-bottom: 0; min-width: 160px; }

.flash-messages { margin-bottom: 18px; display: flex; flex-direction: column; gap: 8px; }
.flash { padding: 12px 16px; border-radius: var(--radius-sm); font-size: 0.88rem; font-weight: 600; border-inline-start: 4px solid transparent; }
.flash-success { background: var(--success-bg); color: var(--success); border-color: var(--success); }
.flash-error { background: var(--error-bg); color: var(--error); border-color: var(--error); }
.flash-warning { background: var(--warning-bg); color: var(--warning); border-color: var(--warning); }
.flash-info { background: var(--info-bg); color: var(--info); border-color: var(--info); }

.pagination { display: flex; gap: 6px; margin-top: 16px; }
.pagination a, .pagination span { padding: 7px 13px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 0.83rem; font-weight: 600; color: var(--text); }
.pagination a:hover { background: var(--bg); text-decoration: none; }
.pagination .active { background: var(--primary); color: #fff; border-color: var(--primary); }

.text-muted { color: var(--text-muted); }
.mt-2 { margin-top: 12px; }
.mb-2 { margin-bottom: 12px; }
.d-flex { display: flex; gap: 10px; align-items: center; }
.justify-between { justify-content: space-between; }

.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px 26px; }
.detail-grid dt { font-weight: 700; color: var(--text-muted); font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.03em; }
.detail-grid dd { margin: 3px 0 0; font-size: 0.95rem; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.empty-state svg { width: 48px; height: 48px; stroke: var(--text-faint); margin-bottom: 10px; }

footer { text-align: center; color: var(--text-muted); font-size: 0.78rem; padding: 26px 0 10px; }

/* =========================================================
   صفحة تسجيل الدخول
   ========================================================= */

.login-page {
    display: flex; min-height: 100vh; margin: 0;
    background: var(--bg);
    font-family: var(--font);
}
.login-panel {
    flex: 1; display: flex; align-items: center; justify-content: center; padding: 40px 24px;
}
.login-box { width: 100%; max-width: 380px; }
.login-box .login-logo {
    width: 56px; height: 56px; border-radius: 16px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    display: flex; align-items: center; justify-content: center; margin-bottom: 18px;
    box-shadow: var(--shadow);
}
.login-box .login-logo svg { width: 28px; height: 28px; stroke: #fff; }
.login-box h1 { font-size: 1.3rem; color: var(--text); margin-bottom: 2px; }
.login-box .subtitle { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 26px; }
.login-box .btn { width: 100%; justify-content: center; padding: 11px; font-size: 0.92rem; }

.login-brand-panel {
    flex: 1;
    background:
        radial-gradient(circle at 15% 20%, rgba(255,255,255,0.08), transparent 40%),
        radial-gradient(circle at 85% 80%, rgba(255,255,255,0.06), transparent 45%),
        linear-gradient(150deg, var(--sidebar-bg) 0%, var(--primary-dark) 60%, var(--secondary) 130%);
    color: #fff;
    display: flex; flex-direction: column; justify-content: center;
    padding: 60px;
    position: relative;
    overflow: hidden;
}
.login-brand-panel .brand-mark { display: flex; align-items: center; gap: 12px; margin-bottom: 40px; }
.login-brand-panel .brand-mark .logo-badge {
    width: 46px; height: 46px; border-radius: 13px; background: rgba(255,255,255,0.14);
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
    backdrop-filter: blur(4px);
}
.login-brand-panel .brand-mark .logo-badge svg { width: 24px; height: 24px; stroke: #fff; }
.login-brand-panel .brand-mark strong { font-size: 1.1rem; }
.login-brand-panel .brand-mark span { display: block; font-size: 0.78rem; opacity: 0.75; }
.login-brand-panel h2 { color: #fff; font-size: 1.7rem; line-height: 1.4; max-width: 420px; margin-bottom: 14px; }
.login-brand-panel p { color: rgba(255,255,255,0.75); font-size: 0.95rem; max-width: 400px; line-height: 1.7; }

.sector-pills { display: flex; gap: 10px; margin-top: 34px; }
.sector-pill {
    display: flex; align-items: center; gap: 8px;
    background: rgba(255,255,255,0.10); border: 1px solid rgba(255,255,255,0.18);
    padding: 9px 16px; border-radius: 999px; font-size: 0.83rem; font-weight: 600;
    backdrop-filter: blur(4px);
}
.sector-pill svg { width: 15px; height: 15px; stroke: #fff; }

@media (max-width: 860px) {
    .login-brand-panel { display: none; }
}

/* =========================================================
   استجابة للشاشات الصغيرة
   ========================================================= */

@media (max-width: 960px) {
    .sidebar {
        position: fixed; inset-inline-start: 0; top: 0; height: 100vh;
        transform: translateX(100%);
        box-shadow: var(--shadow-lg);
    }
    html[dir="rtl"] .sidebar { transform: translateX(100%); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-toggle { display: flex; }
    .sidebar-backdrop.open {
        display: block; position: fixed; inset: 0; background: rgba(10, 25, 35, 0.45);
        z-index: 35;
    }
    .container { padding: 18px 16px 32px; }
    .topbar { padding: 0 14px; }
    .topbar-title { display: none; }
}

@media (max-width: 600px) {
    .filters-bar .form-group { min-width: 100%; }
    .grid-4 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
    .stat-card .stat-value { font-size: 1.4rem; }
}
