:root, html[data-theme="blue"] {
    --primary: #1d4ed8;
    --primary-dark: #16337f;
    --primary-light: #3b82f6;
    --primary-soft: #eff6ff;
    --sidebar-from: #0b1f4d;
    --sidebar-to: #123a7a;
    --sidebar-active: #1d4ed8;
}
html[data-theme="green"] {
    --primary: #047857;
    --primary-dark: #064e3b;
    --primary-light: #10b981;
    --primary-soft: #ecfdf5;
    --sidebar-from: #022c22;
    --sidebar-to: #065f46;
    --sidebar-active: #047857;
}
html[data-theme="purple"] {
    --primary: #6d28d9;
    --primary-dark: #4c1d95;
    --primary-light: #8b5cf6;
    --primary-soft: #f5f3ff;
    --sidebar-from: #2e1065;
    --sidebar-to: #4c1d95;
    --sidebar-active: #6d28d9;
}
html[data-theme="maroon"] {
    --primary: #9f1239;
    --primary-dark: #6b0f2a;
    --primary-light: #e11d48;
    --primary-soft: #fff1f2;
    --sidebar-from: #4c0519;
    --sidebar-to: #881337;
    --sidebar-active: #9f1239;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 15px; }
body {
    font-family: 'Tajawal', 'Cairo', 'Segoe UI', Tahoma, Arial, sans-serif;
    background: #eef1f7;
    color: #1f2937;
    direction: rtl;
    min-height: 100vh;
}
a { color: var(--primary); text-decoration: none; }
.icon { vertical-align: middle; flex-shrink: 0; }

/* ---------- الهيكل العام ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
    width: 250px;
    background: linear-gradient(180deg, var(--sidebar-from) 0%, var(--sidebar-to) 100%);
    color: #e5e7eb;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; bottom: 0; right: 0;
    z-index: 50;
    transition: transform .25s ease;
}
.brand {
    display: flex; align-items: center; gap: 10px;
    padding: 20px 18px;
    border-bottom: 1px solid rgba(255,255,255,.12);
}
.brand-logo {
    width: 42px; height: 42px; border-radius: 12px;
    background: rgba(255,255,255,.15);
    display: flex; align-items: center; justify-content: center;
    color: #fff;
}
.brand-name { font-size: 1.05rem; font-weight: 700; color: #fff; line-height: 1.2; }
.brand-sub { font-size: .72rem; opacity: .7; }

.side-nav { flex: 1; overflow-y: auto; padding: 12px 0; }
.side-nav::-webkit-scrollbar { width: 5px; }
.side-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.2); border-radius: 4px; }
.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 18px;
    color: #cbd5e1;
    font-size: .95rem;
    margin: 2px 10px;
    border-radius: 10px;
    transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-item.active {
    background: var(--sidebar-active);
    color: #fff;
    font-weight: 600;
    box-shadow: 0 3px 10px rgba(0,0,0,.25);
}
.nav-badge {
    margin-inline-start: auto;
    background: #ef4444; color: #fff;
    font-size: .7rem; font-weight: 700;
    padding: 1px 8px; border-radius: 99px;
}
.side-foot { padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.12); font-size: .75rem; opacity: .65; }

.main { flex: 1; margin-right: 250px; display: flex; flex-direction: column; min-width: 0; }

.topbar {
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    padding: 12px 24px;
    display: flex; align-items: center; gap: 14px;
    position: sticky; top: 0; z-index: 40;
}
.topbar h1 { font-size: 1.15rem; font-weight: 700; color: #111827; flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.top-ic {
    position: relative;
    width: 38px; height: 38px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 10px; color: #4b5563;
    border: 1px solid #e5e7eb;
    background: #fff;
}
.top-ic:hover { background: var(--primary-soft); color: var(--primary); }
.top-badge {
    position: absolute; top: -6px; inset-inline-start: -6px;
    background: #ef4444; color: #fff;
    font-size: .68rem; font-weight: 700;
    min-width: 18px; height: 18px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 99px; padding: 0 4px;
}
.user-chip {
    display: flex; align-items: center; gap: 10px;
    background: #f9fafb; border: 1px solid #e5e7eb;
    padding: 6px 12px; border-radius: 12px;
}
.avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-light), var(--primary-dark));
    color: #fff; display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: .9rem;
}
.user-chip .u-name { font-size: .85rem; font-weight: 600; color: #111827; }
.user-chip .u-role { font-size: .7rem; color: #6b7280; }
.menu-btn { display: none; }

.content { padding: 24px; flex: 1; }

/* ---------- البطاقات ---------- */
.card {
    background: #fff;
    border-radius: 16px;
    border: 1px solid #e8ecf3;
    box-shadow: 0 2px 8px rgba(16,24,40,.04);
    padding: 22px;
    margin-bottom: 20px;
}
.card-header {
    display: flex; align-items: center; gap: 10px;
    margin-bottom: 18px;
    padding-bottom: 14px;
    border-bottom: 1px solid #eef1f7;
}
.card-header h2 { font-size: 1.05rem; font-weight: 700; color: #111827; flex: 1; }
.card-header .head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.card-header .head-ic {
    width: 38px; height: 38px; border-radius: 10px;
    background: var(--primary-soft); color: var(--primary);
    display: flex; align-items: center; justify-content: center;
}

/* ---------- شبكة مؤشرات KPI ---------- */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 16px;
    margin-bottom: 22px;
}
.kpi-card {
    background: #fff;
    border-radius: 16px;
    border: 1px solid #e8ecf3;
    padding: 18px;
    display: flex; align-items: center; gap: 14px;
    box-shadow: 0 2px 8px rgba(16,24,40,.04);
    transition: transform .15s, box-shadow .15s;
}
.kpi-card:hover { transform: translateY(-3px); box-shadow: 0 8px 20px rgba(16,24,40,.09); }
.kpi-ic {
    width: 48px; height: 48px; border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
    background: var(--primary-soft); color: var(--primary);
}
.kpi-ic.c-red { background: #fef2f2; color: #dc2626; }
.kpi-ic.c-green { background: #ecfdf5; color: #059669; }
.kpi-ic.c-orange { background: #fff7ed; color: #ea580c; }
.kpi-ic.c-gray { background: #f3f4f6; color: #6b7280; }
.kpi-ic.c-blue { background: var(--primary-soft); color: var(--primary); }
.kpi-num { font-size: 1.6rem; font-weight: 800; color: #111827; line-height: 1; }
.kpi-label { font-size: .8rem; color: #6b7280; margin-top: 5px; }

/* ---------- الرسوم البيانية البسيطة ---------- */
.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: flex; align-items: center; gap: 10px; }
.bar-label { width: 150px; font-size: .82rem; color: #4b5563; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { flex: 1; height: 14px; background: #f1f5f9; border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--primary-light), var(--primary)); min-width: 4px; }
.bar-fill.f-red { background: linear-gradient(90deg, #f87171, #dc2626); }
.bar-fill.f-green { background: linear-gradient(90deg, #34d399, #059669); }
.bar-fill.f-orange { background: linear-gradient(90deg, #fbbf24, #ea580c); }
.bar-fill.f-gray { background: linear-gradient(90deg, #9ca3af, #6b7280); }
.bar-val { width: 46px; font-size: .8rem; font-weight: 700; color: #374151; text-align: left; }

/* ---------- الأزرار ---------- */
.btn {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 9px 18px;
    border-radius: 10px;
    font-size: .9rem; font-weight: 600;
    border: 1px solid transparent;
    cursor: pointer;
    font-family: inherit;
    transition: filter .15s, background .15s, box-shadow .15s;
    text-decoration: none;
    white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.15); }
.btn-primary:hover { filter: brightness(1.1); }
.btn-secondary { background: #fff; color: #374151; border-color: #d1d5db; }
.btn-secondary:hover { background: #f9fafb; }
.btn-danger { background: #dc2626; color: #fff; }
.btn-danger:hover { filter: brightness(1.1); }
.btn-success { background: #059669; color: #fff; }
.btn-success:hover { filter: brightness(1.1); }
.btn-ghost { background: transparent; color: var(--primary); }
.btn-ghost:hover { background: var(--primary-soft); }
.btn-sm { padding: 6px 12px; font-size: .8rem; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-ic {
    display: inline-flex; align-items: center; justify-content: center;
    width: 32px; height: 32px;
    border-radius: 8px;
    color: var(--primary);
    background: var(--primary-soft);
    transition: filter .15s;
}
.btn-ic:hover { filter: brightness(.92); }
.btn-ic.danger { color: #dc2626; background: #fef2f2; }
.inline-form { display: inline; }

/* ---------- الجداول ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: .88rem; }
.tbl th {
    text-align: right;
    background: #f8fafc;
    color: #475569;
    font-weight: 700;
    padding: 11px 14px;
    border-bottom: 2px solid #e8ecf3;
    white-space: nowrap;
}
.tbl td { padding: 11px 14px; border-bottom: 1px solid #eef1f7; vertical-align: middle; }
.tbl tbody tr:hover { background: #f8fafc; }
.tbl .mono { font-family: 'Courier New', monospace; letter-spacing: .5px; direction: ltr; display: inline-block; }
.tbl-actions { display: flex; gap: 6px; justify-content: flex-start; }

/* ---------- الشارات ---------- */
.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 11px;
    border-radius: 99px;
    font-size: .76rem; font-weight: 700;
}
.badge-green { background: #ecfdf5; color: #047857; }
.badge-red { background: #fef2f2; color: #b91c1c; }
.badge-orange { background: #fff7ed; color: #c2410c; }
.badge-gray { background: #f3f4f6; color: #4b5563; }
.badge-blue { background: var(--primary-soft); color: var(--primary); }

/* ---------- النماذج ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full { grid-column: 1 / -1; }
.form-group label { font-size: .84rem; font-weight: 600; color: #374151; }
.form-group label .req { color: #dc2626; }
.form-control {
    padding: 9px 13px;
    border: 1.5px solid #d7dce6;
    border-radius: 10px;
    font-size: .9rem;
    font-family: inherit;
    background: #fff;
    color: #111827;
    width: 100%;
    transition: border-color .15s, box-shadow .15s;
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}
textarea.form-control { min-height: 90px; resize: vertical; }
.form-hint { font-size: .74rem; color: #9ca3af; }
.filter-bar {
    display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end;
    background: #f8fafc;
    border: 1px solid #eef1f7;
    border-radius: 12px;
    padding: 14px 16px;
    margin-bottom: 16px;
}
.filter-bar .form-group { min-width: 170px; flex: 1; }

/* ---------- التنبيهات ---------- */
.alert {
    display: flex; align-items: flex-start; gap: 10px;
    padding: 12px 16px;
    border-radius: 12px;
    margin-bottom: 16px;
    font-size: .88rem;
    border: 1px solid transparent;
}
.alert-ic { margin-top: 1px; }
.alert-success { background: #ecfdf5; color: #065f46; border-color: #a7f3d0; }
.alert-error { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.alert-warning { background: #fffbeb; color: #92400e; border-color: #fde68a; }
.alert-info { background: var(--primary-soft); color: var(--primary-dark); border-color: #c7d8fb; }

/* ---------- ترقيم الصفحات ---------- */
.pagination { display: flex; gap: 6px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.pg {
    min-width: 34px; height: 34px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 9px;
    border: 1px solid #d7dce6;
    color: #4b5563; font-size: .85rem; font-weight: 600;
    padding: 0 8px;
    background: #fff;
}
.pg:hover { border-color: var(--primary); color: var(--primary); }
.pg.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.pg-dots { align-self: center; color: #9ca3af; }

/* ---------- الإشعارات ---------- */
.notif-card {
    display: flex; gap: 14px;
    background: #fff;
    border: 1px solid #e8ecf3;
    border-radius: 14px;
    padding: 16px;
    margin-bottom: 12px;
    border-inline-start: 4px solid var(--primary);
}
.notif-card.unread { background: #f8faff; border-inline-start-color: var(--primary); }
.notif-card.sev-danger { border-inline-start-color: #dc2626; }
.notif-card.sev-danger.unread { background: #fff8f8; }
.notif-card.sev-warning { border-inline-start-color: #ea580c; }
.notif-card.sev-warning.unread { background: #fffaf5; }
.notif-ic { margin-top: 2px; }
.notif-card.sev-danger .notif-ic { color: #dc2626; }
.notif-card.sev-warning .notif-ic { color: #ea580c; }
.notif-card.sev-info .notif-ic { color: var(--primary); }
.notif-body { flex: 1; min-width: 0; }
.notif-title { font-weight: 700; font-size: .92rem; color: #111827; }
.notif-msg { font-size: .85rem; color: #4b5563; margin-top: 4px; }
.notif-meta { font-size: .74rem; color: #9ca3af; margin-top: 6px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }

/* ---------- الحالات الفارغة ---------- */
.empty-state { text-align: center; color: #9ca3af; padding: 30px 10px; }
.empty-state .icon { opacity: .5; }
.center-card { max-width: 640px; margin: 40px auto; }
.text-center { text-align: center; }
.text-muted { color: #6b7280; font-size: .85rem; }

/* ---------- شبكات إضافية ---------- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
@media (max-width: 1100px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* ---------- صفحة الدخول ---------- */
.login-page {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, var(--sidebar-from) 0%, var(--sidebar-to) 60%, var(--primary-dark) 100%);
    padding: 20px;
}
.login-card {
    background: #fff;
    width: 100%; max-width: 420px;
    border-radius: 20px;
    padding: 38px 34px;
    box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.login-logo {
    width: 70px; height: 70px;
    margin: 0 auto 16px;
    border-radius: 20px;
    background: linear-gradient(135deg, var(--primary-light), var(--primary-dark));
    color: #fff;
    display: flex; align-items: center; justify-content: center;
}
.login-card h1 { text-align: center; font-size: 1.3rem; color: #111827; margin-bottom: 4px; }
.login-card .login-sub { text-align: center; color: #6b7280; font-size: .85rem; margin-bottom: 24px; }
.login-card .form-group { margin-bottom: 16px; }
.login-card .btn { width: 100%; justify-content: center; padding: 12px; font-size: 1rem; }

/* ---------- صفحة التحقق العام ---------- */
.verify-wrap { max-width: 640px; margin: 40px auto; padding: 0 16px; }
.verify-card {
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 8px 40px rgba(16,24,40,.12);
    overflow: hidden;
}
.verify-head {
    background: linear-gradient(135deg, var(--sidebar-from), var(--sidebar-to));
    color: #fff;
    padding: 30px;
    text-align: center;
}
.verify-head h1 { font-size: 1.3rem; }
.verify-head p { opacity: .8; font-size: .85rem; margin-top: 6px; }
.verify-body { padding: 30px; }
.verify-result {
    display: flex; align-items: center; gap: 14px;
    padding: 18px;
    border-radius: 14px;
    margin-bottom: 22px;
    font-weight: 700;
}
.verify-result.ok { background: #ecfdf5; color: #047857; }
.verify-result.bad { background: #fef2f2; color: #b91c1c; }
.kv { display: grid; grid-template-columns: 1fr; gap: 0; }
.kv-row {
    display: flex; justify-content: space-between; gap: 14px;
    padding: 10px 4px;
    border-bottom: 1px dashed #e5e7eb;
    font-size: .88rem;
}
.kv-row:last-child { border-bottom: none; }
.kv-row .k { color: #6b7280; }
.kv-row .v { font-weight: 600; color: #111827; text-align: left; }

/* ---------- التقرير المطبوع ---------- */
.report-sheet { background: #fff; max-width: 850px; margin: 0 auto; }
.report-header {
    display: flex; justify-content: space-between; align-items: flex-start; gap: 16px;
    padding-bottom: 16px;
    border-bottom: 3px solid var(--primary);
    margin-bottom: 20px;
}
.report-header .rh-title { font-size: 1.25rem; font-weight: 800; color: #111827; }
.report-header .rh-sub { font-size: .82rem; color: #6b7280; margin-top: 4px; }
.report-qr { text-align: center; flex-shrink: 0; }
.report-qr svg { display: block; }
.report-qr .qr-caption { font-size: .7rem; color: #6b7280; margin-top: 6px; max-width: 150px; }
.report-section-title {
    display: flex; align-items: center; gap: 8px;
    font-size: .95rem; font-weight: 700;
    color: var(--primary-dark);
    margin: 22px 0 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid #e8ecf3;
}
.report-footer {
    margin-top: 26px; padding-top: 14px;
    border-top: 1px solid #e8ecf3;
    font-size: .78rem; color: #9ca3af;
    display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px;
}

/* ---------- لوحة اختيار السمات ---------- */
.themes-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.theme-card {
    border: 2px solid #e8ecf3;
    border-radius: 14px;
    padding: 14px;
    cursor: pointer;
    display: block;
    transition: border-color .15s, transform .15s;
}
.theme-card:hover { transform: translateY(-3px); }
.theme-card input { display: none; }
.theme-card input:checked ~ .theme-box { border-color: var(--primary); }
.theme-card.selected { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.theme-preview {
    height: 74px;
    border-radius: 10px;
    margin-bottom: 10px;
    display: flex; align-items: flex-end; padding: 10px; gap: 6px;
}
.theme-preview .tp-dot { width: 16px; height: 16px; border-radius: 50%; background: rgba(255,255,255,.85); }
.theme-name { font-weight: 700; font-size: .9rem; color: #111827; display: block; }
.theme-desc { font-size: .75rem; color: #6b7280; }

/* ---------- الاستيراد الذكي ---------- */
.import-steps { display: flex; gap: 0; margin-bottom: 22px; }
.import-step {
    flex: 1; text-align: center;
    padding: 12px 8px;
    font-size: .85rem; font-weight: 600;
    color: #9ca3af;
    border-bottom: 3px solid #e8ecf3;
}
.import-step.active { color: var(--primary); border-bottom-color: var(--primary); }
.import-step.done { color: #059669; border-bottom-color: #059669; }
.sum-chips { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.sum-chip { padding: 8px 16px; border-radius: 12px; font-size: .85rem; font-weight: 700; }
.sum-chip.ok { background: #ecfdf5; color: #047857; }
.sum-chip.warn { background: #fff7ed; color: #c2410c; }
.sum-chip.bad { background: #fef2f2; color: #b91c1c; }
.sum-chip.gray { background: #f3f4f6; color: #4b5563; }

/* ---------- الصلاحيات ---------- */
.perm-table th.center, .perm-table td.center { text-align: center; }
.perm-table input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; }
.perm-table input[type="checkbox"]:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- الكود والشارات الصغيرة ---------- */
code.inline {
    background: #f1f5f9; color: #be123c;
    padding: 1px 6px; border-radius: 6px;
    font-size: .8rem;
    direction: ltr; display: inline-block;
}

/* ---------- الجوال ---------- */
@media (max-width: 900px) {
    .sidebar { transform: translateX(100%); }
    .sidebar.open { transform: translateX(0); box-shadow: -10px 0 40px rgba(0,0,0,.3); }
    .main { margin-right: 0; }
    .menu-btn {
        display: inline-flex; align-items: center; justify-content: center;
        width: 38px; height: 38px;
        border: 1px solid #e5e7eb; border-radius: 10px;
        background: #fff; color: #4b5563;
        cursor: pointer;
    }
    .content { padding: 14px; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .bar-label { width: 90px; }
    .card { padding: 16px; border-radius: 12px; }
    .topbar { padding: 10px 14px; }
    .user-chip .u-name, .user-chip .u-role { display: none; }
    .overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 45; }
}

/* ---------- الطباعة ---------- */
@media print {
    body { background: #fff; }
    .sidebar, .topbar, .no-print, .btn, .pagination, .filter-bar { display: none !important; }
    .main { margin: 0; }
    .content { padding: 0; }
    .card { box-shadow: none; border: none; padding: 0; margin-bottom: 14px; page-break-inside: avoid; }
    .report-sheet { max-width: none; }
    .tbl th { background: #f1f5f9 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .badge, .alert, .theme-preview, .kpi-ic, .head-ic, .kpi-card, .report-qr svg { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
