/* ==========================================================================
   نظام الهوية البصرية — إدارة المستودع
   الخط: Tajawal (مضمّن محلياً)
   الوضعان: داكن (dark-mode) / فاتح (light-mode) — الافتراضي فاتح
   ========================================================================== */

/* ---- إعلان الخط المحلي ---- */
@font-face {
    font-family: 'Tajawal';
    font-style: normal;
    font-weight: 400;
    src: url('fonts/Tajawal-Regular-latin.woff2') format('woff2');
    unicode-range: U+0000-00FF;
}
@font-face {
    font-family: 'Tajawal';
    font-style: normal;
    font-weight: 400;
    src: url('fonts/Tajawal-Regular-arabic.woff2') format('woff2');
    unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+08E3-08FF, U+200C-200E, U+2010-2011, U+FB50-FDFF, U+FE70-FEFC;
}
@font-face {
    font-family: 'Tajawal';
    font-style: normal;
    font-weight: 500;
    src: url('fonts/Tajawal-Medium-latin.woff2') format('woff2');
    unicode-range: U+0000-00FF;
}
@font-face {
    font-family: 'Tajawal';
    font-style: normal;
    font-weight: 500;
    src: url('fonts/Tajawal-Medium-arabic.woff2') format('woff2');
    unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+08E3-08FF, U+200C-200E, U+2010-2011, U+FB50-FDFF, U+FE70-FEFC;
}
@font-face {
    font-family: 'Tajawal';
    font-style: normal;
    font-weight: 700;
    src: url('fonts/Tajawal-Bold-latin.woff2') format('woff2');
    unicode-range: U+0000-00FF;
}
@font-face {
    font-family: 'Tajawal';
    font-style: normal;
    font-weight: 700;
    src: url('fonts/Tajawal-Bold-arabic.woff2') format('woff2');
    unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+08E3-08FF, U+200C-200E, U+2010-2011, U+FB50-FDFF, U+FE70-FEFC;
}

/* ==========================================================================
   ١. المتغيرات والألوان الأساسية
   ========================================================================== */
:root {
    /* ألوان الهوية */
    --brand-blue: #1E3A8A;
    --brand-blue-light: #2E5B94;
    --brand-orange: #F97316;
    --accent-blue: #2E5B94;

    /* نص */
    --text-primary: #26324A;
    --text-secondary: #64748B;
    --text-disabled: #94A3B8;
    --icon-inactive: #9AA3B2;

    /* أسطح (الوضع الفاتح) */
    --bg-app: #F8FAFC;
    --bg-card: #FFFFFF;
    --bg-card-hover: #F1F5F9;
    --bg-disabled: #E2E8F0;
    --bg-sidebar: #F9FAFB;
    --bg-input: #FFFFFF;
    --border: #E5E7EB;

    /* تنبيهات وحالات */
    --success: #10B981;
    --success-bg: #D1FAE5;
    --error: #EF4444;
    --error-bg: #FEE2E2;
    --warning: #F59E0B;
    --warning-bg: #FEF3C7;
    --info-bg: #DBEAFE;

    /* توهج الوضع الداكن */
    --glow-orange: 0 0 8px rgba(249, 115, 22, 0.55), 0 0 18px rgba(249, 115, 22, 0.3);
    --glow-blue: 0 0 0 3px rgba(46, 91, 148, 0.18);

    --radius: 10px;
    --shadow: 0 1px 3px rgba(22, 50, 79, .08), 0 4px 14px rgba(22, 50, 79, .06);
    --shadow-md: 0 10px 20px -6px rgba(15, 35, 56, .18);
}

/* ==========================================================================
   ٢. الوضع الداكن — تجاوز المتغيرات
   ========================================================================== */
body.dark-mode {
    --brand-blue: #93C5FD;
    --brand-blue-light: #60A5FA;
    --brand-orange: #FB923C;

    --text-primary: #E5E7EB;
    --text-secondary: #9CA3AF;
    --text-disabled: #6B7280;
    --icon-inactive: #7D8798;

    --bg-app: #0F172A;
    --bg-card: #1E2937;
    --bg-card-hover: #2D3A4F;
    --bg-disabled: #334155;
    --bg-sidebar: #1E2937;
    --bg-input: #263244;
    --border: #334155;

    --success-bg: rgba(16, 185, 129, .18);
    --error-bg: rgba(239, 68, 68, .18);
    --warning-bg: rgba(245, 158, 11, .18);
    --info-bg: rgba(46, 91, 148, .25);

    --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 6px 16px rgba(0, 0, 0, .3);
    --shadow-md: 0 14px 28px -8px rgba(0, 0, 0, .5);
}

/* ==========================================================================
   ٣. الأساسيات
   ========================================================================== */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
    font-family: 'Tajawal', 'Segoe UI', 'Tahoma', sans-serif;
    background: var(--bg-app);
    color: var(--text-primary);
    direction: rtl;
    font-size: 14px;
    font-weight: 400;
    overflow: hidden;
    transition: background-color .3s ease, color .3s ease;
}

.app { display: flex; height: 100vh; }

/* ==========================================================================
   ٤. الشريط الجانبي (Sidebar)
   ========================================================================== */
.sidebar {
    width: 240px;
    background: var(--bg-sidebar);
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: background-color .3s ease;
}

/* خلفية فاتحة للشريط */
body.light-mode .sidebar { box-shadow: 1px 0 0 var(--border); }
/* خلفية داكنة للشريط */
body.dark-mode .sidebar { border-left: 1px solid rgba(255,255,255,.06); }

/* --- اسم التطبيق (أعلى الشريط) --- */
.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 16px;
    border-bottom: 1px solid var(--border);
    position: relative;
}
.brand-logo { display: flex; align-items: center; flex-shrink: 0; }
.brand-img {
    width: 46px;
    height: auto;
    object-fit: contain;
    transition: filter .3s ease;
}
/* توهج الشعار في الوضع الداكن */
body.dark-mode .brand-img { filter: drop-shadow(0 0 8px rgba(201, 147, 70, .38)); }

.brand-text { flex: 1; min-width: 0; }
.brand-text h1 {
    font-size: 20px;
    font-weight: 700;
    color: var(--brand-blue);
    line-height: 1.2;
    transition: color .3s ease;
}
body.dark-mode .brand-text h1 { color: var(--brand-orange); text-shadow: var(--glow-orange); }
.brand-text small { color: var(--text-secondary); font-size: 11px; font-weight: 400; }

/* --- زر تبديل الوضع (في الإعدادات) --- */
#themeToggle {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    font-weight: 600;
    padding: 10px 18px;
}
#themeToggle .theme-icon-sun, #themeToggle .theme-icon-moon { font-size: 18px; line-height: 1; }
body.light-mode #themeToggle .theme-icon-moon { display: none; }
body.dark-mode #themeToggle .theme-icon-sun { display: none; }

/* --- القائمة --- */
.nav { padding: 14px 10px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-btn {
    background: transparent;
    border: none;
    color: var(--text-primary);
    text-align: right;
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all .15s;
    font-family: inherit;
    display: flex;
    align-items: center;
    gap: 12px;
}
.nav-btn svg { width: 18px; height: 18px; flex-shrink: 0; color: var(--icon-inactive); transition: color .15s; }
.nav-btn span { color: var(--text-primary); transition: color .15s; }

/* وضع فاتح: نشط بخلفية رمادية ولون براند أزرق */
body.light-mode .nav-btn:hover { background: var(--bg-card-hover); }
body.light-mode .nav-btn.active {
    background: var(--bg-disabled);
    color: var(--brand-blue);
    font-weight: 600;
}
body.light-mode .nav-btn.active svg { color: var(--brand-blue); }
body.light-mode .nav-btn.active span { color: var(--brand-blue); }

/* وضع داكن: نشط بخلفية hover وتوهج برتقالي */
body.dark-mode .nav-btn:hover { background: var(--bg-card-hover); }
body.dark-mode .nav-btn.active {
    background: var(--bg-card-hover);
    color: var(--brand-orange);
    font-weight: 600;
    box-shadow: inset 3px 0 0 var(--brand-orange);
}
body.dark-mode .nav-btn.active svg { color: var(--brand-orange); filter: drop-shadow(0 0 4px rgba(249,115,22,.4)); }
body.dark-mode .nav-btn.active span { color: var(--brand-orange); }

.sidebar-footer {
    padding: 12px 14px;
    font-size: 12px;
    color: var(--text-disabled);
    text-align: center;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.sidebar-footer .nav-btn { justify-content: center; }
.sidebar-version { font-size: 11px; color: var(--text-disabled); }

/* ==========================================================================
   ٥. المحتوى الرئيسي
   ========================================================================== */
.main { flex: 1; overflow-y: auto; padding: 24px 30px; }
.screen { display: none; }
.screen.active { display: block; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px);} to { opacity: 1; transform: none;} }

/* --- العناوين الرئيسية (Page Title) --- */
.screen-header { margin-bottom: 18px; }
.screen-header h2 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    transition: color .3s ease;
}
.help-text { color: var(--text-secondary); font-size: 13px; margin-top: 4px; font-weight: 400; }

/* --- الشريط العلوي الذكي (Operations Top Bar) --- */
.topbar {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 16px;
    margin-bottom: 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    flex-wrap: wrap;
}
.topbar-brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.topbar-org { color: var(--text-primary); }
.topbar-fork {
    font-size: 11px;
    font-weight: 700;
    padding: 2px 10px;
    border-radius: 20px;
    background: var(--bg-disabled);
    color: var(--text-disabled);
    white-space: nowrap;
}
body.dark-mode .topbar-fork.ok, .topbar-fork.ok { background: rgba(22,163,74,.14); color: var(--success, #16a34a); }
body.dark-mode .topbar-fork.err, .topbar-fork.err { background: rgba(220,38,38,.16); color: var(--error, #dc2626); }
.topbar-sep { color: var(--border); }
.topbar-status { flex: 1; font-size: 12.5px; color: var(--text-secondary); min-width: 140px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.topbar-last { font-size: 11.5px; color: var(--text-disabled); white-space: nowrap; }
#topbar-theme .theme-icon-sun, #topbar-theme .theme-icon-moon { font-size: 16px; line-height: 1; }
body.light-mode #topbar-theme .theme-icon-moon { display: none; }
body.dark-mode #topbar-theme .theme-icon-sun { display: none; }
@media (max-width: 1100px) { .topbar-status { order: 5; flex-basis: 100%; } }

/* --- بطاقات العمليات السريعة (Ops Grid) --- */
.ops-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
@media (max-width: 1100px) { .ops-grid { grid-template-columns: repeat(2, 1fr); } }
.ops-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    padding: 18px 16px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-card);
    box-shadow: var(--shadow);
    cursor: pointer;
    text-align: right;
    font-family: inherit;
    color: var(--text-primary);
    transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;
    border-top: 3px solid var(--brand-blue);
}
.ops-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.ops-card:active { transform: translateY(0); }
.ops-icon { font-size: 26px; line-height: 1; }
.ops-name { font-size: 15px; font-weight: 700; }
.ops-meta { font-size: 12px; color: var(--text-secondary); }
.ops-card.ops-blue { border-top-color: #1E3A8A; }
.ops-card.ops-green { border-top-color: #16a34a; }
.ops-card.ops-purple { border-top-color: #7c3aed; }
.ops-card.ops-orange { border-top-color: #F97316; }

/* --- البحث الشامل (Ctrl+K) --- */
.modal-quick { width: min(620px, 92vw); padding: 14px; }
.quick-search-row { display: flex; align-items: center; gap: 8px; }
.quick-search-icon { font-size: 18px; }
.quick-search-input { width: 100%; font-size: 15px; }
.quick-results { margin-top: 10px; max-height: 55vh; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.quick-empty { padding: 14px; text-align: center; color: var(--text-disabled); font-size: 13px; }
.quick-group { font-size: 11px; font-weight: 700; color: var(--text-disabled); padding: 6px 4px 2px; letter-spacing: .4px; }
.quick-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 8px;
    cursor: pointer;
    border: 1px solid transparent;
}
.quick-item:hover, .quick-item.sel { background: var(--bg-card-hover); border-color: var(--border); }
.quick-item-title { font-weight: 700; font-size: 14px; }
.quick-item-sub { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.quick-item-go { font-size: 11.5px; color: var(--text-disabled); white-space: nowrap; }
.quick-hint { margin-top: 10px; font-size: 11px; color: var(--text-disabled); text-align: center; }

/* --- شارات الحالة --- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.install-badge { background: rgba(22,163,74,.12); color: var(--success, #16a34a); border: 1px solid rgba(22,163,74,.35); }
.install-pending { background: var(--bg-disabled, #e2e8f0); color: var(--text-disabled, #94a3b8); border: 1px solid transparent; }

/* --- شريط الأدوات --- */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar .input { width: 260px; }
.review-case-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); align-items: end; gap: 12px; margin: 14px 0 8px; }
.review-case-form .btn { min-height: 42px; }
.review-calendar-select { width: 100%; margin-bottom: 8px; }
.review-date-field { display: grid; grid-template-columns: minmax(0, 1fr) 106px; align-items: center; column-gap: 8px; row-gap: 6px; }
.review-date-field > label { grid-column: 1; grid-row: 1; }
.review-date-field > .review-calendar-select { grid-column: 2; grid-row: 1; width: 100%; margin: 0; padding-inline: 8px; }
.review-date-field > #review-case-date,
.review-date-field > .review-hijri-picker,
.review-date-field > .review-date-display { grid-column: 1 / -1; }
.review-date-field > #review-case-date,
.review-date-field > .review-hijri-picker { grid-row: 2; }
.review-date-field > .review-date-display { grid-row: 3; }
.review-date-display { display: block; min-height: 0; margin-top: 0; }
.review-hijri-picker { position: relative; width: 100%; }
.review-hijri-input-row { position: relative; }
.review-hijri-input-row .input { width: 100%; padding-inline-end: 42px; cursor: pointer; }
.review-hijri-open { position: absolute; inset-inline-end: 7px; top: 50%; transform: translateY(-50%); width: 30px; height: 30px; border: 0; border-radius: 7px; background: transparent; color: var(--primary, #3f7880); cursor: pointer; font-size: 18px; }
.review-hijri-open:hover { background: rgba(63,120,128,.1); }
.review-hijri-calendar { position: absolute; z-index: 30; inset-inline: 0; top: calc(100% + 6px); min-width: 280px; padding: 12px; border: 1px solid var(--border, #d9e4e1); border-radius: 12px; background: #fff; box-shadow: 0 12px 28px rgba(24,48,52,.18); direction: rtl; }
.review-hijri-calendar-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; color: var(--text, #18383e); }
.review-hijri-calendar-head button { width: 32px; height: 30px; border: 1px solid var(--border, #d9e4e1); border-radius: 7px; background: #f5f8f7; color: inherit; cursor: pointer; font-size: 20px; line-height: 1; }
.review-hijri-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; text-align: center; }
.review-hijri-weekday { padding: 4px 0; color: #71818a; font-size: 10px; font-weight: 700; }
.review-hijri-blank { min-height: 32px; }
.review-hijri-day { min-height: 32px; border: 1px solid transparent; border-radius: 7px; background: transparent; color: var(--text, #18383e); cursor: pointer; font: inherit; font-size: 12px; }
.review-hijri-day:hover { border-color: #b8d6d2; background: #edf6f4; }
.review-hijri-day.selected { border-color: var(--primary, #3f7880); background: var(--primary, #3f7880); color: #fff; font-weight: 700; }
.review-hijri-calendar-error { grid-column: 1 / -1; margin: 8px 0; color: #9b3333; font-size: 12px; }
.review-case-title-row .card-title { margin-bottom: 0; }
.review-case-tools { display: flex; flex: 1; justify-content: flex-end; align-items: center; gap: 8px; flex-wrap: wrap; }
.review-case-tools input[type="month"] { width: 175px; }
.review-case-tools .input.search { width: 260px; }
.review-case-status {
    min-width: 122px;
    padding-inline: 9px;
    border-width: 1.5px;
    border-radius: 999px;
    font-weight: 700;
    text-align: center;
}
.review-case-status[data-status="جديد"],
.review-case-status[data-status="محظور"] {
    width: 100px;
    min-width: 100px;
    padding: 5px 20px 5px 6px;
    font-size: 12px;
}
.review-case-status[data-status="جديد"] { background: #eff6ff; color: #1d4ed8; border-color: #93c5fd; }
.review-case-status[data-status="قيد المراجعة"] { background: #fffbeb; color: #a16207; border-color: #fcd34d; }
.review-case-status[data-status="تمت المراجعة"] { background: #ecfdf5; color: #047857; border-color: #6ee7b7; }
.review-case-status[data-status="اكتمل"] { background: #ecfdf5; color: #047857; border-color: #6ee7b7; }
.review-case-status[data-status="مؤجل"] { background: #f1f5f9; color: #475569; border-color: #cbd5e1; }
.review-case-status[data-status="محظور"] { background: #fef2f2; color: #b91c1c; border-color: #fca5a5; }
.review-case-actions { display: flex; align-items: center; justify-content: center; gap: 7px; white-space: nowrap; }
.review-case-complete {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #ecfdf5;
    color: #047857;
    border: 1px solid #6ee7b7;
    font-size: 15px;
    font-weight: 800;
    line-height: 1;
}
.review-case-blocked {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fca5a5;
    font-size: 15px;
    font-weight: 800;
    line-height: 1;
}
body.dark-mode .review-case-status[data-status="جديد"] { background: rgba(59, 130, 246, .2); color: #bfdbfe; border-color: #3b82f6; }
body.dark-mode .review-case-status[data-status="قيد المراجعة"] { background: rgba(245, 158, 11, .18); color: #fde68a; border-color: #d97706; }
body.dark-mode .review-case-status[data-status="تمت المراجعة"] { background: rgba(16, 185, 129, .18); color: #a7f3d0; border-color: #059669; }
body.dark-mode .review-case-status[data-status="اكتمل"] { background: rgba(16, 185, 129, .18); color: #a7f3d0; border-color: #059669; }
body.dark-mode .review-case-status[data-status="مؤجل"] { background: #334155; color: #cbd5e1; border-color: #64748b; }
body.dark-mode .review-case-status[data-status="محظور"] { background: rgba(239, 68, 68, .18); color: #fecaca; border-color: #dc2626; }
body.dark-mode .review-case-complete { background: rgba(16, 185, 129, .18); color: #a7f3d0; border-color: #059669; }
body.dark-mode .review-case-blocked { background: rgba(239, 68, 68, .18); color: #fecaca; border-color: #dc2626; }

/* --- البطاقات (Card Header = Medium 12px) --- */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 18px;
    border: 1px solid var(--border);
    transition: background-color .3s ease, border-color .3s ease;
}
.card-title {
    font-size: 13px;
    font-weight: 500;
    letter-spacing: .5px;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 16px;
}
.card-actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }

/* --- حقول الإدخال --- */
.input {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 400;
    color: var(--text-primary);
    background: var(--bg-input);
    transition: border .15s, box-shadow .15s, background-color .3s ease;
}
.input::placeholder { color: var(--text-disabled); font-size: 12px; }
.input:focus { outline: none; border-color: var(--accent-blue); box-shadow: var(--glow-blue); }
.input.search { width: 300px; }
.balance-hint { font-size: 12px; margin-top: 4px; font-weight: 600; color: var(--text-secondary); }
.balance-hint.warn { color: var(--warning); }
.balance-hint.ok { color: var(--success); }

/* --- الأزرار --- */
.btn {
    padding: 9px 16px;
    border-radius: 8px;
    border: 1px solid transparent;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s;
    display: inline-flex;
    align-items: center;
    gap: 7px;
}
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--accent-blue); color: #fff; }
.btn-primary:hover { background: var(--brand-blue); box-shadow: var(--shadow-md); }
.btn-danger { background: var(--error); color: #fff; }
.btn-danger:hover { background: #DC2626; }
.btn-ghost { background: var(--bg-disabled); color: var(--text-primary); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg-card-hover); }
.btn-outline { background: transparent; color: var(--accent-blue); border-color: var(--accent-blue); }
.btn-outline:hover { background: var(--info-bg); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* --- جداول (Table Header = Medium 12px Uppercase) --- */
.table-wrap { overflow: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; background: var(--bg-card); border-radius: 8px; overflow: hidden; }
.table thead th {
    background: var(--bg-card);
    color: var(--text-secondary);
    padding: 10px 12px;
    text-align: right;
    font-weight: 500;
    font-size: 12px;
    letter-spacing: .4px;
    white-space: nowrap;
    position: sticky;
    top: 0;
    border-bottom: 1px solid var(--border);
}
.table tbody td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    color: var(--text-primary);
}
.table tbody tr:hover { background: var(--bg-card-hover); }

/* --- جدول مصفوفة الحضور الشهري --- */
.att-name-col { min-width: 130px; }
.att-section-col { min-width: 90px; }
.att-day-col { min-width: 34px; padding: 8px 4px !important; text-align: center; font-size: 11px; }
.att-day-cell { text-align: center; white-space: nowrap; font-size: 11.5px; }
.att-pre { color: var(--success); font-weight: 700; }
.att-abs { color: var(--error); font-weight: 700; }

/* --- حالات (Badges) --- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 12px; font-size: 12px; font-weight: 700; color: #fff; }
.badge.red { background: var(--error); }
.badge.yellow { background: var(--warning); }
.badge.green { background: var(--success); }
.badge.gray { background: var(--text-secondary); }
.badge.blue { background: var(--accent-blue); }

.remaining.red { background: var(--error-bg); color: var(--error); font-weight: 700; }
.remaining.yellow { background: var(--warning-bg); color: var(--warning); font-weight: 700; }
.remaining.green { background: var(--success-bg); color: var(--success); font-weight: 700; }

/* --- نموذج الشبكة --- */
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; color: var(--text-secondary); font-weight: 600; }

.dispense-head { display: grid; grid-template-columns: 1fr 2fr 1fr; gap: 14px; margin-bottom: 18px; }
.date-format-row { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.date-format-row .input { width: 110px; }
.disp-date-display { font-size: 12px; font-weight: 700; color: var(--text, #334155); }

/* --- صفوف الصرف --- */
.disp-row {
    display: grid;
    grid-template-columns: 2fr 1.2fr 0.9fr 0.9fr 1fr 1.2fr 40px;
    gap: 8px;
    align-items: center;
    margin-bottom: 8px;
    background: var(--bg-card);
    padding: 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
}
.disp-row .input { font-size: 13px; padding: 7px 10px; }
.disp-qty-cell { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.disp-qty-cell .input { width: 100%; }
.row-balance { font-size: 10px; font-weight: 600; line-height: 1.25; color: var(--text-soft, #64748b); }
.row-balance.low { color: var(--error); }
.row-balance.ok { color: var(--success); }
.row-balance.external, .external-item-mark { color: var(--text-soft, #64748b); font-size: 10px; font-weight: 600; }
.remove-row {
    background: var(--error-bg); color: var(--error); border: none; border-radius: 6px;
    width: 30px; height: 30px; cursor: pointer; font-size: 16px; font-weight: 700;
}
.remove-row:hover { background: var(--error-bg); filter: brightness(.95); }

/* --- الإعدادات --- */
.settings-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; margin-bottom: 30px; }
@media (max-width: 900px) { .settings-grid { grid-template-columns: 1fr; } }
.settings-card {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 18px 16px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-card);
    box-shadow: var(--shadow);
    text-align: right;
    border-top: 3px solid var(--brand-blue);
}
.settings-card-head { display: flex; align-items: center; gap: 10px; }
.settings-card-icon { font-size: 24px; line-height: 1; }
.settings-card-title { font-size: 15px; font-weight: 700; color: var(--text-primary); }
.settings-card.ops-blue { border-top-color: #1E3A8A; }
.settings-card.ops-green { border-top-color: #16a34a; }
.settings-card.ops-purple { border-top-color: #7c3aed; }
.settings-card.ops-orange { border-top-color: #F97316; }
.settings-card .list-editor { margin-bottom: 4px; }
.list-editor { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
#locations-editor {
    max-height: 260px;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 2px 7px 2px 2px;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}
#locations-editor::-webkit-scrollbar { width: 8px; }
#locations-editor::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
#locations-editor::-webkit-scrollbar-thumb:hover { background: var(--text-soft, #94a3b8); }
.list-tag {
    display: flex; justify-content: space-between; align-items: center;
    background: var(--bg-card); border: 1px solid var(--border); border-radius: 7px;
    padding: 8px 12px; font-size: 13.5px;
}
.list-tag .del { background: none; border: none; color: var(--error); cursor: pointer; font-size: 15px; }
.add-line { display: flex; gap: 6px; }

.help-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.help-item { background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; padding: 14px; }
.help-item h4 { color: var(--text-primary); margin-bottom: 6px; font-size: 14px; font-weight: 600; }
.help-item p { color: var(--text-secondary); font-size: 13px; line-height: 1.7; }

/* --- النوافذ المنبثقة --- */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(2, 6, 23, .55);
    display: flex; align-items: center; justify-content: center; z-index: 100;
    backdrop-filter: blur(2px);
}
.modal {
    background: var(--bg-card); border-radius: 12px; padding: 24px; width: 420px;
    box-shadow: 0 20px 50px rgba(0,0,0,.3); max-height: 90vh; overflow-y: auto;
    border: 1px solid var(--border);
}
.modal-sm { width: 380px; }
.modal h3 { color: var(--text-primary); margin-bottom: 16px; font-size: 18px; font-weight: 700; }
.modal .field { margin-bottom: 12px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

.hidden { display: none !important; }

/* --- رسائل الحالات (Alerts) --- */
.msg { margin-top: 12px; padding: 10px 14px; border-radius: 8px; font-size: 13.5px; display: none; }
.msg.show { display: block; }
.msg.error { background: var(--error-bg); color: var(--error); }
.msg.success { background: var(--success-bg); color: var(--success); }
.msg.warning { background: var(--warning-bg); color: var(--warning); }
.msg.info { background: var(--info-bg); color: var(--accent-blue); }

/* --- التفاصيل --- */
.detail-card { margin-top: 16px; }
.detail-card h4 { margin-bottom: 10px; color: var(--text-primary); }

/* --- الطباعة --- */
#print-area { display: none; }

/* --- لوحة المعلومات --- */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card {
    background: var(--bg-card); border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 16px 18px; border: 1px solid var(--border); border-top: 4px solid var(--accent-blue);
    display: flex; flex-direction: column; gap: 6px;
}
.stat-card .stat-num { font-size: 28px; font-weight: 700; color: var(--text-primary); line-height: 1; }
.stat-card .stat-label { font-size: 12px; color: var(--text-secondary); font-weight: 600; }
.stat-card.warn { border-top-color: var(--warning); }
.stat-card.danger { border-top-color: var(--error); }
.stat-card.ok { border-top-color: var(--success); }
.stat-card .stat-hint { font-size: 11.5px; color: var(--text-secondary); }

.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.dash-grid .card { margin-bottom: 0; }
.dash-grid .card-full { grid-column: 1 / -1; }
.dash-low-table-wrap { max-height: 360px; overflow: auto; overscroll-behavior: contain; }
.dash-low-table-wrap .table thead th { position: sticky; top: 0; z-index: 2; }
#screen-warehouse #wh-category-filter { width: 190px; }
@media (max-width: 1100px) { .dash-grid { grid-template-columns: 1fr; } }

/* --- التقارير --- */
.report-controls { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.report-controls .field { width: 170px; }
.report-controls input[type="month"] { width: 190px; }
.report-card-row { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 1100px) { .report-card-row { grid-template-columns: 1fr; } }
.report-card-row .card { margin-bottom: 18px; }

/* --- شريط التمرير --- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-disabled); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-disabled); }

/* --- تخصيص تقرير PDF --- */
.report-config { display: flex; flex-direction: column; gap: 14px; }
.logo-upload-row { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.rc-logo-preview { width: 64px; height: 64px; object-fit: contain; border: 1px solid var(--border); border-radius: 12px; background: #fff; padding: 4px; }
.sig-fields { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 900px) { .sig-fields { grid-template-columns: 1fr; } }
.checkbox-line { flex-direction: row; align-items: center; gap: 10px; margin-top: 4px; }
.checkbox-line label { display: flex; align-items: center; gap: 8px; color: var(--text-primary); font-weight: 500; cursor: pointer; }
.checkbox-line input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent-blue); }
.btn-row { display: flex; gap: 10px; margin-top: 6px; }

/* --- تنبيهات لوحة المعلومات --- */
.alert-panel { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.alert-item { padding: 10px 14px; border-radius: 10px; font-size: 13px; border: 1px solid; }
.alert-red { background: var(--error-bg); color: var(--error); border-color: var(--error); }
.alert-yellow { background: var(--warning-bg); color: var(--warning); border-color: var(--warning); }
.alert-blue { background: var(--info-bg); color: var(--accent-blue); border-color: var(--accent-blue); }
.low-totals { margin-top: 10px; text-align: left; font-size: 13px; color: var(--text-soft); }
.card-title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-title-row .card-title { margin-bottom: 0; }

/* --- نافذة التحديث التلقائي --- */
.update-progress { height: 10px; background: var(--bg-soft); border-radius: 20px; overflow: hidden; margin: 10px 0 4px; }
.update-progress-bar { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent-blue), var(--success)); border-radius: 20px; transition: width .3s ease; }

/* --- النسخ الاحتياطي --- */
.backup-config { display: flex; flex-direction: column; gap: 14px; }
.bk-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 700px) { .bk-row { grid-template-columns: 1fr; } }
.bk-list-title { margin: 8px 0 10px; color: var(--text-primary); font-size: 14px; }

/* --- محلول التركيب --- */
.install-actions { display: flex; align-items: center; gap: 12px; margin-top: 16px; flex-wrap: wrap; }
.install-item-help { margin: 4px 0 8px; }
.inst-loc-cell { display: flex; align-items: center; gap: 8px; }
.inst-loc-cell .input { flex: 1; min-width: 0; }
.inst-type-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.inst-type-row label { flex: 0 0 auto; color: var(--text-secondary); font-size: 11px; font-weight: 700; }
.inst-type-row .input { flex: 1; min-width: 0; min-height: 38px; }
#inst-items-table td { padding: 6px; }
#inst-items-table .input { font-size: 13px; padding: 7px 10px; }
.inst-idx { font-weight: 600; color: var(--text-secondary); }

/* التحقق من مطابقة محضر التركيب مع صرف المواد */
.inst-report-cell { display: flex; flex-direction: column; gap: 3px; }
.inst-report-status { font-size: 11px; line-height: 1.4; min-height: 1.2em; font-weight: 600; }
.inst-report-status.inst-ok { color: var(--success, #16a34a); }
.inst-report-status.inst-bad { color: var(--danger, #dc2626); }
.inst-report-status.inst-external { color: var(--text-secondary, #64748b); }
#inst-items-table tr.inst-row-ok { background: rgba(22,163,74,.07); }
#inst-items-table tr.inst-row-bad { background: rgba(220,38,38,.07); }
#inst-items-table tr.inst-row-ok .inst-report,
#inst-items-table tr.inst-row-ok .inst-qty { border-color: rgba(22,163,74,.55); }
#inst-items-table tr.inst-row-bad .inst-report,
#inst-items-table tr.inst-row-bad .inst-qty { border-color: #dc2626; }

/* خلية الكمية والمؤشر لقفل الكمية من صرف المواد */
.inst-qty-cell { display: flex; align-items: center; gap: 4px; }
.inst-qty-cell .inst-qty { flex: 1; min-width: 0; }
.inst-qty-lock { font-size: 13px; line-height: 1; color: #16a34a; cursor: default; }
#inst-items-table tr.inst-row-ok .inst-qty { background: rgba(22,163,74,.08); }

@media print {
    body * { visibility: hidden; }
    #print-area, #print-area * { visibility: visible; }
    #print-area { display: block !important; position: absolute; inset: 0; }
    .btn { display: none; }
}

/* ==========================================================================
   تجاوب الشاشات — الهاتف والأجهزة الصغيرة
   ========================================================================== */
.sidebar-toggle { display: none; align-items: center; justify-content: center; padding: 6px 8px; }
.sidebar-toggle svg { width: 20px; height: 20px; }
.sidebar-backdrop {
    position: fixed; inset: 0; z-index: 140; background: rgba(2, 6, 23, .5);
    opacity: 0; pointer-events: none; transition: opacity .25s ease;
}

@media (max-width: 992px) {
    body { font-size: 13.5px; }

    /* القائمة الجانبية تتحول إلى درج جانبي */
    .sidebar {
        position: fixed;
        top: 0; right: 0; bottom: 0;
        width: 250px;
        z-index: 200;
        transform: translateX(100%);
        transition: transform .25s ease;
        box-shadow: -8px 0 24px rgba(2, 6, 23, .25);
    }
    body.sidebar-open .sidebar { transform: translateX(0); }
    body.sidebar-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
    body.sidebar-open { overflow: hidden; }

    .sidebar-toggle { display: inline-flex; flex-shrink: 0; }

    /* المحتوى الرئيسي */
    .main { padding: 14px 12px 48px; }
    .screen-header h2 { font-size: 20px; }
    .help-text { font-size: 12px; }

    /* الشريط العلوي */
    .topbar { gap: 8px; padding: 8px 10px; margin-bottom: 14px; }
    .topbar-actions { flex-wrap: wrap; }
    .topbar-last { display: none; }
    .topbar-status { flex-basis: 100%; }

    /* بطاقات العمليات: عمودان دائماً على الشاشات الصغيرة */
    .ops-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .ops-card { padding: 14px 12px; }
    .ops-icon { font-size: 22px; }

    /* شبكات النماذج تتكدس عمودياً */
    .form-grid, .dispense-head, .review-case-form { grid-template-columns: 1fr; gap: 12px; }
    .disp-row { min-width: 620px; }
    #disp-items-container, .dispense-head { overflow-x: auto; }

    /* الحقول وأدوات البحث بعرض كامل */
    .toolbar { align-items: stretch; }
    .toolbar .input, .toolbar .input.search { width: 100%; }
    .report-controls { align-items: stretch; }
    .report-controls .field, .report-controls input[type="month"], .report-controls .input { width: 100%; }
    .report-card-row { grid-template-columns: 1fr; }

    /* النوافذ المنبثقة بعرض الشاشة */
    .modal { width: min(94vw, 420px); padding: 18px 16px; }
    .modal-sm { width: min(94vw, 380px); }
    .modal-quick { width: min(94vw, 620px); }

    /* الكروت والتفاصيل */
    .card { padding: 14px; }
    .settings-grid { grid-template-columns: 1fr; }
    .bk-row { grid-template-columns: 1fr; }
    .stat-cards { grid-template-columns: repeat(2, 1fr); }
    .stat-card .stat-num { font-size: 24px; }
    .list-editor .add-line { flex-wrap: wrap; }
    .date-format-row { flex-wrap: wrap; }
    .logo-upload-row { align-items: flex-start; }
    .sign-row { flex-wrap: wrap; }

    /* تمرير لمس سلس للجداول */
    .table-wrap { -webkit-overflow-scrolling: touch; }
    .table thead th { font-size: 11px; padding: 8px; }
    .table tbody td { padding: 8px; font-size: 12.5px; }

    .btn-lg { padding: 12px 18px; font-size: 14px; }
}

@media (max-width: 480px) {
    .ops-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .ops-name { font-size: 13px; }
    .ops-meta { font-size: 11px; }
    .stat-cards { grid-template-columns: 1fr 1fr; gap: 8px; }
    .stat-card { padding: 12px; }
    .sidebar { width: 240px; }
    .quick-hint { font-size: 10px; }
    .card-actions, .install-actions, .btn-row { flex-direction: column; align-items: stretch; }
    .card-actions .btn, .install-actions .btn, .btn-row .btn { width: 100%; justify-content: center; }
}

/* ========================================================================
   طبقة توحيد المظهر — واجهة إدارة واضحة ومريحة للاستخدام اليومي
   ======================================================================== */
:root {
    --brand-blue: #183B66;
    --brand-blue-light: #315B88;
    --accent-blue: #2563EB;
    --bg-app: #F3F6FA;
    --bg-card: #FFFFFF;
    --bg-card-hover: #F7F9FC;
    --bg-disabled: #EDF2F7;
    --bg-sidebar: #FFFFFF;
    --bg-input: #FFFFFF;
    --border: #E2E8F0;
    --text-primary: #172B45;
    --text-secondary: #64748B;
    --text-disabled: #94A3B8;
    --radius: 14px;
    --shadow: 0 2px 8px rgba(25, 48, 77, .045), 0 10px 26px rgba(25, 48, 77, .045);
    --shadow-md: 0 12px 28px rgba(25, 48, 77, .12);
    --glow-blue: 0 0 0 4px rgba(37, 99, 235, .13);
}

body.dark-mode {
    --brand-blue: #A9C8F5;
    --brand-blue-light: #82AAE6;
    --accent-blue: #78A9FA;
    --bg-app: #101827;
    --bg-card: #182438;
    --bg-card-hover: #223149;
    --bg-disabled: #27364D;
    --bg-sidebar: #141F31;
    --bg-input: #121D2E;
    --border: #2B3B52;
    --text-primary: #E6EDF7;
    --text-secondary: #A7B4C7;
    --text-disabled: #74849B;
    --shadow: 0 2px 8px rgba(0, 0, 0, .16), 0 12px 28px rgba(0, 0, 0, .12);
    --shadow-md: 0 14px 32px rgba(0, 0, 0, .28);
    --glow-blue: 0 0 0 4px rgba(120, 169, 250, .16);
}

body { font-size: 14px; line-height: 1.55; }
.app { min-height: 100vh; }

.sidebar {
    width: 258px;
    border-inline-start: 1px solid var(--border);
}
.brand {
    padding: 22px 18px;
    min-height: 90px;
    gap: 12px;
}
.brand-img { width: 48px; }
.brand-text h1 { font-size: 19px; }
.brand-text small { font-size: 12px; }
.nav { padding: 18px 12px; gap: 5px; }
.nav-btn {
    min-height: 44px;
    border-radius: 10px;
    padding: 10px 13px;
    gap: 11px;
    font-size: 13.5px;
}
.nav-btn svg { width: 19px; height: 19px; }
body.light-mode .nav-btn.active {
    background: #EEF4FF;
    box-shadow: inset -3px 0 0 var(--accent-blue);
}
.sidebar-footer { padding: 14px; }

.main { padding: 28px clamp(18px, 3vw, 42px) 44px; }
.screen-header {
    margin: 6px 0 22px;
    padding-inline-start: 2px;
}
.screen-header h2 {
    font-size: clamp(22px, 2vw, 28px);
    letter-spacing: -.35px;
}
.help-text { font-size: 13px; line-height: 1.7; }

.topbar {
    min-height: 58px;
    padding: 10px 14px;
    margin-bottom: 26px;
    border-radius: 14px;
    box-shadow: 0 2px 8px rgba(25, 48, 77, .035);
}
.topbar-brand { gap: 9px; }
.topbar-status { font-size: 12px; }
.topbar-fork { background: var(--success-bg); color: var(--success); }

.ops-grid, .stat-cards { gap: 14px; margin-bottom: 20px; }
.ops-card, .stat-card, .settings-card {
    border: 1px solid var(--border);
    border-radius: 15px;
    box-shadow: var(--shadow);
}
.ops-card {
    position: relative;
    overflow: hidden;
    min-height: 132px;
    padding: 18px;
    border-top-width: 0;
}
.ops-card::before {
    position: absolute;
    inset-block: 0;
    inset-inline-start: 0;
    width: 4px;
    content: '';
    background: var(--brand-blue);
}
.ops-card.ops-green::before { background: #16A36A; }
.ops-card.ops-purple::before { background: #7957D5; }
.ops-card.ops-orange::before { background: #E8872B; }
.ops-card:hover { transform: translateY(-3px); border-color: #C9D7E8; }
.ops-icon {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    margin-bottom: 3px;
    border-radius: 12px;
    background: var(--bg-disabled);
    font-size: 21px;
}
.ops-name { font-size: 15px; }
.ops-meta { line-height: 1.55; }

.card, .detail-card {
    border-radius: 15px;
    padding: 20px;
    box-shadow: var(--shadow);
}
.card-title {
    margin-bottom: 13px;
    color: var(--text-primary);
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: none;
}
.card-title-row { margin-bottom: 14px; }
.dash-grid { gap: 16px; }
.stat-card {
    position: relative;
    overflow: hidden;
    min-height: 112px;
    gap: 8px;
    padding: 18px;
    border-top-width: 1px;
}
.stat-card::before {
    position: absolute;
    inset-block: 0;
    inset-inline-start: 0;
    width: 4px;
    content: '';
    background: var(--accent-blue);
}
.stat-card.warn::before { background: var(--warning); }
.stat-card.danger::before { background: var(--error); }
.stat-card.ok::before { background: var(--success); }
.stat-card .stat-num { font-size: 30px; letter-spacing: -.5px; }
.stat-card .stat-label { font-size: 13px; }

.table-wrap {
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg-card);
}
.table {
    min-width: 640px;
    border-radius: 12px;
    font-size: 13px;
}
.table thead th {
    z-index: 1;
    padding: 12px 14px;
    background: var(--bg-disabled);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0;
}
.table tbody td { padding: 12px 14px; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background-color .15s ease; }
.table tbody tr:hover { background: var(--bg-card-hover); }

.toolbar { gap: 9px; margin-bottom: 18px; }
.input {
    min-height: 42px;
    border-radius: 10px;
    padding: 9px 12px;
}
.input:focus { border-color: var(--accent-blue); }
.input::placeholder { font-size: 13px; }
.btn {
    min-height: 40px;
    border-radius: 10px;
    padding: 9px 15px;
}
.btn-primary { background: var(--accent-blue); }
.btn-primary:hover { background: var(--brand-blue-light); }
.btn-outline { color: var(--accent-blue); border-color: #CBD8E8; }
.btn-outline:hover { background: var(--info-bg); border-color: var(--accent-blue); }
.btn-ghost { border-color: transparent; }
.btn-sm { min-height: 32px; padding: 6px 11px; }
.btn:focus-visible, .nav-btn:focus-visible, .ops-card:focus-visible {
    outline: 3px solid rgba(61, 116, 124, .4);
    outline-offset: 2px;
}

.form-grid { gap: 18px; }
.field { gap: 7px; }
.field label { color: var(--text-primary); font-size: 13px; }
.disp-row {
    border-radius: 11px;
    padding: 11px;
    box-shadow: 0 1px 3px rgba(25, 48, 77, .035);
}
.modal-overlay { background: rgba(13, 27, 45, .52); backdrop-filter: blur(5px); }
.modal {
    border-radius: 18px;
    padding: 25px;
    box-shadow: 0 24px 64px rgba(8, 22, 40, .24);
}
.modal h3 { font-size: 20px; }
.msg, .alert-item { border-radius: 11px; }
.badge { padding: 4px 10px; }

@media (max-width: 992px) {
    .main { padding: 16px 14px 42px; }
    .screen-header { margin: 4px 0 18px; }
    .topbar { margin-bottom: 18px; }
    .ops-grid, .stat-cards { gap: 10px; }
    .card { padding: 16px; }
    .table { min-width: 600px; }
}

@media (max-width: 480px) {
    .main { padding-inline: 11px; }
    .screen-header h2 { font-size: 21px; }
    .topbar { border-radius: 12px; }
    .ops-card { min-height: 120px; padding: 13px; }
    .ops-icon { width: 36px; height: 36px; }
    .stat-card { min-height: 98px; padding: 12px; }
    .stat-card .stat-num { font-size: 24px; }
    .card { padding: 13px; border-radius: 13px; }
    .card-title-row { align-items: flex-start; }
    .modal { border-radius: 16px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        scroll-behavior: auto !important;
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
}

/* قوائم داخلية وألوان هادئة */
:root {
    --brand-blue: #294D56;
    --brand-blue-light: #456D73;
    --brand-orange: #C99346;
    --accent-blue: #3D747C;
    --bg-app: #F4F6F4;
    --bg-card: #FFFFFF;
    --bg-card-hover: #F0F5F3;
    --bg-disabled: #E8EFEC;
    --bg-sidebar: #F9FAF8;
    --bg-input: #FFFFFF;
    --border: #DEE7E3;
    --text-primary: #26383B;
    --text-secondary: #68797A;
    --success: #39836D;
    --success-bg: #E5F1EB;
    --warning: #A97830;
    --warning-bg: #F6EFDF;
    --error: #C45F58;
    --error-bg: #F9EAE8;
    --info-bg: #E7F0F1;
    --table-zebra: #FAFCFB;
    --list-surface: #F7FAF9;
    --glow-blue: 0 0 0 4px rgba(61, 116, 124, .14);
}

body.dark-mode {
    --brand-blue: #B6D0CE;
    --brand-blue-light: #91B9B8;
    --brand-orange: #D8B16F;
    --accent-blue: #3D747C;
    --bg-app: #151F22;
    --bg-card: #1E2B2F;
    --bg-card-hover: #29393C;
    --bg-disabled: #29393C;
    --bg-sidebar: #192629;
    --bg-input: #19272A;
    --border: #344649;
    --text-primary: #E7EEEC;
    --text-secondary: #A7B6B3;
    --text-disabled: #829492;
    --success: #79B99E;
    --success-bg: rgba(67, 139, 105, .2);
    --warning: #D6AE6B;
    --warning-bg: rgba(164, 122, 49, .2);
    --error: #E08C84;
    --error-bg: rgba(196, 95, 88, .18);
    --info-bg: rgba(79, 135, 139, .2);
    --table-zebra: #1A272B;
    --list-surface: #202F32;
    --glow-blue: 0 0 0 4px rgba(117, 171, 171, .18);
}

body.light-mode .nav-btn:hover { background: #EEF3F1; }
body.light-mode .nav-btn.active {
    color: #315D63;
    background: #E8F0ED;
    box-shadow: inset -3px 0 0 #648D88;
}
body.light-mode .nav-btn.active svg,
body.light-mode .nav-btn.active span { color: #315D63; }
body.dark-mode .nav-btn:hover { background: #253639; }
body.dark-mode .nav-btn.active {
    color: #B5D2CF;
    background: #27393B;
    box-shadow: inset -3px 0 0 #C49B5B;
}
body.dark-mode .nav-btn.active svg,
body.dark-mode .nav-btn.active span { color: #B5D2CF; }

.nav-btn { border-radius: 11px; }
.topbar-fork { background: #E7F0EC; color: #47766B; }
body.dark-mode .topbar-fork { background: #293D39; color: #A9CEC0; }
.table thead th { background: #EDF2F0; color: #5E7472; }
body.dark-mode .table thead th { background: #29393B; color: #B8C7C3; }
.table tbody tr:nth-child(even) { background: var(--table-zebra); }
.table tbody tr:hover { background: var(--bg-card-hover); }

.list-tag {
    background: var(--list-surface);
    border-color: var(--border);
    border-radius: 10px;
    padding: 9px 12px;
    transition: background-color .15s ease, border-color .15s ease;
}
.list-tag:hover { background: var(--bg-card-hover); border-color: #B8CDCA; }
.list-tag .del { border-radius: 7px; padding: 3px 8px; }
.settings-card { background: var(--bg-card); }
.settings-card.ops-blue,
.settings-card.ops-green,
.settings-card.ops-purple,
.settings-card.ops-orange { border-top-color: var(--border); }
.settings-card-head { min-height: 40px; }
.settings-card-icon {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 11px;
    background: var(--bg-disabled);
    font-size: 19px;
}
.help-item { background: var(--list-surface); border-radius: 12px; }
.help-item h4 { color: var(--brand-blue); }
.quick-item:hover, .quick-item.sel { background: var(--bg-card-hover); border-color: var(--border); }
.perms-grid .perm-row { background: var(--list-surface); border-color: var(--border); }
.input[type="checkbox"] { accent-color: var(--accent-blue); }
select.input { color-scheme: light; }
body.dark-mode select.input { color-scheme: dark; }

/* تمرير مستقل لسجلي الصرف ومحاضر التركيب في شاشة الطلبات */
#screen-orders .orders-log-scroll {
    max-height: 390px;
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    -webkit-overflow-scrolling: touch;
}
#screen-orders #committed-disp-table > thead th,
#screen-orders #install-log-table > thead th {
    position: sticky;
    top: 0;
    z-index: 2;
}

@media (max-width: 760px) {
    #screen-orders .orders-log-scroll { max-height: 320px; }
    .review-case-tools { width: 100%; justify-content: stretch; }
    .review-case-tools input[type="month"], .review-case-tools .input.search { width: 100%; }
    .review-case-tools .btn { width: 100%; justify-content: center; }
}

/* ترتيب متناسق لنموذجي صرف المواد ومحضر التركيب */
.workflow-section-title {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}
.workflow-section-title > span {
    display: grid;
    place-items: center;
    width: 29px;
    height: 29px;
    flex: 0 0 29px;
    border-radius: 9px;
    background: var(--info-bg);
    color: var(--accent-blue);
    font-size: 13px;
    font-weight: 700;
}
.workflow-section-title .card-title { margin: 0; font-size: 15px; }
#screen-dispense .workflow-section-title:first-child,
#screen-install .card > .workflow-section-title:first-child { margin-bottom: 15px; }
.workflow-items-head {
    margin: 22px 0 12px;
    padding-bottom: 11px;
    border-bottom: 1px solid var(--border);
}
#screen-dispense .dispense-head {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr) minmax(0, 1fr);
    gap: 16px;
    align-items: start;
    padding: 16px;
    margin-bottom: 8px;
    border: 1px solid var(--border);
    border-radius: 13px;
    background: var(--list-surface);
}
#screen-install .install-meta-grid {
    grid-template-columns: minmax(0, .9fr) minmax(0, 1.6fr) minmax(0, .9fr) minmax(0, 1.2fr);
    gap: 16px;
    align-items: start;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 13px;
    background: var(--list-surface);
}
.disp-row {
    grid-template-columns: minmax(160px, 1.55fr) minmax(110px, 1fr) minmax(95px, .8fr) minmax(105px, .85fr) minmax(125px, 1fr) minmax(145px, 1.15fr) 38px;
    grid-template-areas: "item section unit qty order location remove";
    gap: 10px;
    align-items: end;
    padding: 13px;
    margin-bottom: 10px;
    border-color: var(--border);
    background: var(--bg-card);
}
.disp-field { display: flex; min-width: 0; flex-direction: column; gap: 6px; }
.disp-field label { color: var(--text-secondary); font-size: 11px; font-weight: 700; }
.disp-field-item { grid-area: item; }
.dispense-item-help { margin: 0 0 10px; }
.disp-field-section { grid-area: section; }
.disp-field-unit { grid-area: unit; }
.disp-field-qty { grid-area: qty; }
.disp-field-order { grid-area: order; }
.disp-field-location { grid-area: location; }
.disp-row .input { min-width: 0; min-height: 41px; }
.disp-qty-cell { display: flex; min-width: 0; flex-direction: column; gap: 3px; }
.row-balance { min-height: 1.25em; }
.disp-row .remove-row { grid-area: remove; width: 36px; height: 41px; border-radius: 10px; }
#screen-dispense .card-actions,
#screen-install .install-actions {
    padding-top: 15px;
    border-top: 1px solid var(--border);
}
#screen-install .install-actions .msg { flex: 1 1 100%; }

@media (max-width: 992px) {
    #screen-dispense .dispense-head { grid-template-columns: repeat(2, minmax(0, 1fr)); overflow: visible; }
    #screen-dispense .disp-row {
        min-width: 0;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        grid-template-areas: "item item" "section unit" "qty order" "location remove";
    }
    #screen-dispense #disp-items-container { overflow: visible; }
    #screen-dispense .disp-row .remove-row { justify-self: end; }
    #screen-install .install-meta-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
    #screen-dispense .dispense-head,
    #screen-install .install-meta-grid { grid-template-columns: minmax(0, 1fr); padding: 12px; }
    #screen-dispense .disp-row { padding: 10px; gap: 9px; }
    .workflow-items-head { align-items: center; }
    .workflow-items-head > .btn { white-space: nowrap; }
}

/* Visually hidden labels keep form controls accessible without changing the layout. */
.sr-only { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }
