/* ══════════════════════════════════════════════════════════════
   نظام المخزن والكاشير — الملف التنسيقي الموحّد
   ══════════════════════════════════════════════════════════════ */

/* ══════════════════════════════════════════════════════════════
   ★ هوية «مكتبة المتنبي» — نبيذي عميق مع ذهبي عتيق ★

   نظام «مكتبة أحمد» كحليّ (#16324F). هذا النظام نبيذيّ عمداً كي
   يعرف الكاشير من أول نظرة أيّ محلّ فتح، فلا يبيع على المحل الخطأ.

   كل ألوان النظام تُشتقّ من المتغيّرات أدناه — لتغيير الهوية كلها
   يكفي تعديل هذه الأسطر وحدها، ولا تُلمس بقية الملف.
   ══════════════════════════════════════════════════════════════ */

:root {
    --primary:       #6B2440;   /* نبيذيّ عميق — لون المحل */
    --primary-dark:  #4A1730;
    --primary-light: #F7EAEF;
    --accent:        #A87C22;   /* ذهبيّ عتيق */
    --accent-soft:   #FBF3E0;

    --bg:      #F8F5F6;
    --surface: #FFFFFF;
    --text:    #26161E;
    --muted:   #7A6670;
    --border:  #EBE0E4;

    --danger:       #DC2626;
    --danger-soft:  #FEE2E2;
    --success:      #15803D;
    --success-soft: #DCFCE7;
    --warn:         #D97706;
    --warn-soft:    #FEF3C7;
    --info:         #0284C7;
    --info-soft:    #E0F2FE;

    --sh-sm: 0 1px 3px rgba(60,15,35,.06);
    --sh-md: 0 4px 10px -2px rgba(60,15,35,.09);
    --sh-lg: 0 14px 30px -8px rgba(60,15,35,.18);
    --r:  16px;
    --r2: 11px;
    --tr: all .22s ease;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Tajawal', sans-serif; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }
body { background: var(--bg); color: var(--text); overflow: hidden; }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #D8C4CC; border-radius: 20px; }
::-webkit-scrollbar-thumb:hover { background: #B9959F; }


/* ═══ 1. الهيكل العام ═══ */

.wrapper { display: flex; height: 100vh; width: 100%; }

.sidebar {
    width: 258px; flex-shrink: 0;
    background: var(--surface);
    border-left: 1px solid var(--border);
    display: flex; flex-direction: column;
    z-index: 1000; transition: var(--tr);
}
.brand-header {
    height: 74px; display: flex; align-items: center; gap: 12px;
    padding: 0 20px; border-bottom: 1px solid var(--border);
}
.brand-icon {
    width: 42px; height: 42px; flex-shrink: 0;
    background: var(--primary); color: #fff;
    border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 19px;
}
.brand-title h1 { font-size: 17px; font-weight: 900; line-height: 1.2; }
.brand-title span { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.close-sidebar-mobile {
    display: none; background: none; border: none; font-size: 22px;
    color: var(--muted); cursor: pointer; margin-right: auto;
}

.sidebar-nav { flex: 1; padding: 16px 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 5px; }
.nav-item {
    display: flex; align-items: center; gap: 13px;
    padding: 12px 16px; border-radius: var(--r2);
    text-decoration: none; color: var(--muted);
    font-size: 14px; font-weight: 700; transition: var(--tr);
}
.nav-item i { width: 20px; text-align: center; font-size: 15px; }
.nav-item:hover { background: var(--primary-light); color: var(--primary); }
.nav-item.active { background: var(--primary); color: #fff; box-shadow: var(--sh-md); }
.nav-sep { font-size: 10.5px; font-weight: 800; color: #a3aec0; padding: 12px 16px 4px; letter-spacing: .5px; }

.sidebar-footer { padding: 14px; border-top: 1px solid var(--border); }

.sidebar-backdrop { display: none; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
    height: 68px; flex-shrink: 0; background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 14px; padding: 0 22px;
}
.topbar h2 { font-size: 19px; font-weight: 900; }
.topbar .sub { font-size: 12px; color: var(--muted); font-weight: 600; }
.topbar-actions { margin-right: auto; display: flex; gap: 9px; align-items: center; }
.menu-toggle { display: none; background: none; border: none; font-size: 20px; color: var(--text); cursor: pointer; }

.content { flex: 1; overflow-y: auto; padding: 22px; }
.section { margin-bottom: 22px; }
.section-header {
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px;
}
.section-header h3 { font-size: 16px; font-weight: 900; }


/* ═══ 2. الأزرار ═══ */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 11px 18px; border-radius: var(--r2); border: 1.5px solid transparent;
    font-family: inherit; font-size: 13.5px; font-weight: 800;
    cursor: pointer; transition: var(--tr); text-decoration: none; white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); box-shadow: var(--sh-md); }
.btn-accent  { background: var(--accent); color: #fff; }
.btn-accent:hover:not(:disabled) { filter: brightness(.92); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { filter: brightness(.92); }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(.92); }
.btn-outline { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-outline:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.btn-ghost   { background: transparent; color: var(--muted); }
.btn-ghost:hover:not(:disabled) { background: var(--primary-light); color: var(--primary); }
.btn-sm { padding: 7px 12px; font-size: 12px; border-radius: 9px; }
.btn-lg { padding: 15px 24px; font-size: 15.5px; }
.btn-block { width: 100%; }

.icon-btn {
    width: 36px; height: 36px; border-radius: 10px; border: none;
    background: var(--primary-light); color: var(--primary);
    cursor: pointer; font-size: 14px; transition: var(--tr); flex-shrink: 0;
}
.icon-btn:hover { background: var(--primary); color: #fff; }
.icon-btn.danger { background: var(--danger-soft); color: var(--danger); }
.icon-btn.danger:hover { background: var(--danger); color: #fff; }


/* ═══ 3. الحقول ═══ */

.form-group { margin-bottom: 14px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
label {
    display: block; font-size: 12.5px; font-weight: 800;
    color: var(--muted); margin-bottom: 6px;
}
label i { margin-left: 4px; }
input, select, textarea {
    width: 100%; padding: 11px 14px;
    border: 1.5px solid var(--border); border-radius: var(--r2);
    background: var(--surface); color: var(--text);
    font-family: inherit; font-size: 14px; font-weight: 600;
    transition: var(--tr); outline: none;
}
input:focus, select:focus, textarea:focus {
    border-color: var(--primary); box-shadow: 0 0 0 3px rgba(22,50,79,.09);
}
input::placeholder, textarea::placeholder { color: #a3aec0; font-weight: 500; }
input[type=number] { -moz-appearance: textfield; }
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
textarea { resize: vertical; min-height: 74px; }
.hint { font-size: 11.5px; color: var(--muted); font-weight: 600; margin-top: 5px; }

.search-container { position: relative; flex: 1; min-width: 180px; }
.search-container input { padding-right: 42px; }
.search-icon { position: absolute; right: 15px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 14px; pointer-events: none; }

.switch-row { display: flex; align-items: center; gap: 10px; }
.switch-row input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; }
.switch-row label { margin: 0; cursor: pointer; color: var(--text); }


/* ═══ 4. البطاقات والجداول ═══ */

.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--r); padding: 20px; box-shadow: var(--sh-sm);
}
.card + .card { margin-top: 16px; }
.card-title { font-size: 15px; font-weight: 900; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }
.card-title i { color: var(--accent); }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--r2);
    padding: 16px 18px; box-shadow: var(--sh-sm);
    display: flex; align-items: center; gap: 13px; position: relative; overflow: hidden;
}
.stat .ic {
    width: 44px; height: 44px; border-radius: 12px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center; font-size: 17px;
    background: var(--primary-light); color: var(--primary);
}
.stat .l { font-size: 11.5px; color: var(--muted); font-weight: 700; }
.stat .v { font-size: 20px; font-weight: 900; margin-top: 2px; line-height: 1.2; }
.stat .v small { font-size: 11px; font-weight: 700; color: var(--muted); }

.tbl-wrap { overflow-x: auto; border-radius: var(--r2); border: 1px solid var(--border); background: var(--surface); }
table.tbl { width: 100%; border-collapse: collapse; min-width: 560px; }
table.tbl thead th {
    background: var(--primary-light); color: var(--primary);
    font-size: 12px; font-weight: 900; text-align: right;
    padding: 12px 14px; white-space: nowrap; position: sticky; top: 0; z-index: 2;
}
table.tbl tbody td { padding: 12px 14px; font-size: 13.5px; font-weight: 600; border-top: 1px solid var(--border); }
table.tbl tbody tr:hover { background: #fafbfd; }
table.tbl .num { font-weight: 800; white-space: nowrap; }

.badge {
    display: inline-block; padding: 3px 10px; border-radius: 7px;
    font-size: 11px; font-weight: 800; white-space: nowrap;
}
.badge.ok    { background: var(--success-soft); color: var(--success); }
.badge.bad   { background: var(--danger-soft);  color: var(--danger); }
.badge.warn  { background: var(--warn-soft);    color: var(--warn); }
.badge.info  { background: var(--info-soft);    color: var(--info); }
.badge.mute  { background: #f1f5f9;             color: #64748b; }
.badge.gold  { background: var(--accent-soft);  color: var(--accent); }

.chips { display: flex; gap: 7px; flex-wrap: wrap; }
.chip {
    padding: 8px 15px; border-radius: 30px; font-size: 12.5px; font-weight: 800;
    border: 1.5px solid var(--border); background: var(--surface);
    color: var(--muted); cursor: pointer; font-family: inherit; transition: var(--tr);
}
.chip:hover { border-color: var(--primary); color: var(--primary); }
.chip.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip.on.warn { background: var(--warn); border-color: var(--warn); }
.chip.on.bad  { background: var(--danger); border-color: var(--danger); }

.empty {
    text-align: center; padding: 52px 20px;
    background: var(--surface); border: 1px dashed var(--border); border-radius: var(--r);
}
.empty i { font-size: 44px; color: #cbd5e1; margin-bottom: 14px; display: block; }
.empty p { color: var(--muted); font-weight: 700; font-size: 15px; }


/* ═══ 5. النوافذ ═══ */

.modal {
    display: none; position: fixed; inset: 0; z-index: 3000;
    background: rgba(13,32,54,.55); backdrop-filter: blur(3px);
    align-items: center; justify-content: center; padding: 16px;
}
.modal.active { display: flex; }
.modal-content {
    background: var(--surface); border-radius: 18px; width: 100%; max-width: 560px;
    max-height: 92vh; display: flex; flex-direction: column;
    box-shadow: var(--sh-lg); animation: pop .2s ease;
}
@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(.98); } }
.modal-header {
    display: flex; align-items: center; gap: 10px;
    padding: 17px 20px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.modal-header h2 { font-size: 16.5px; font-weight: 900; display: flex; align-items: center; gap: 9px; }
.modal-header h2 i { color: var(--accent); }
.close-modal-btn {
    margin-right: auto; background: none; border: none; font-size: 19px;
    color: var(--muted); cursor: pointer; width: 34px; height: 34px; border-radius: 9px; transition: var(--tr);
}
.close-modal-btn:hover { background: var(--danger-soft); color: var(--danger); }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; flex-shrink: 0; }


/* ═══ 6. الرسائل ═══ */

.toast-container {
    position: fixed; top: 18px; left: 50%; transform: translateX(-50%);
    z-index: 5000; display: flex; flex-direction: column; gap: 9px; align-items: center;
    pointer-events: none; width: max-content; max-width: 92vw;
}
.toast {
    display: flex; align-items: center; gap: 10px;
    background: var(--text); color: #fff;
    padding: 12px 20px; border-radius: 12px;
    font-size: 13.5px; font-weight: 700; box-shadow: var(--sh-lg);
    opacity: 0; transform: translateY(-14px); transition: all .28s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { background: var(--success); }
.toast-error   { background: var(--danger); }
.toast-warn    { background: var(--warn); }
.toast-info    { background: var(--info); }


/* ═══ 7. لوحة الدخول ═══ */

.login-page {
    display: flex; align-items: center; justify-content: center;
    height: 100vh; padding: 20px; overflow: auto;
    background: linear-gradient(140deg, var(--primary) 0%, var(--primary-dark) 100%);
}
.login-card {
    background: var(--surface); border-radius: 22px; padding: 34px 30px;
    width: 100%; max-width: 400px; box-shadow: 0 24px 60px rgba(0,0,0,.3);
}
.login-card .logo {
    width: 64px; height: 64px; margin: 0 auto 16px; border-radius: 18px;
    background: var(--primary); color: #fff;
    display: flex; align-items: center; justify-content: center; font-size: 27px;
}
.login-card h1 { font-size: 21px; font-weight: 900; text-align: center; }
.login-card p.s { font-size: 13px; color: var(--muted); text-align: center; margin: 6px 0 24px; font-weight: 600; }
.login-err {
    background: var(--danger-soft); color: var(--danger);
    padding: 11px 14px; border-radius: 10px; font-size: 13px; font-weight: 800;
    margin-bottom: 16px; display: flex; align-items: center; gap: 8px;
}


/* ═══ 8. الاستجابة للشاشات الصغيرة ═══ */

@media (max-width: 1024px) {
    .sidebar {
        position: fixed; inset: 0 auto 0 0; right: 0; left: auto;
        transform: translateX(100%); box-shadow: var(--sh-lg);
    }
    .sidebar.active { transform: translateX(0); }
    .sidebar.active ~ .sidebar-backdrop,
    .sidebar.active + .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(13,32,54,.45); z-index: 999; }
    .close-sidebar-mobile { display: block; }
    .menu-toggle { display: block; }
    .content { padding: 16px; }
    .topbar { padding: 0 16px; }
    .topbar h2 { font-size: 16.5px; }
}

@media (max-width: 620px) {
    .stat-grid { grid-template-columns: repeat(auto-fit, minmax(148px, 1fr)); gap: 10px; }
    .stat { padding: 13px; gap: 10px; }
    .stat .ic { width: 38px; height: 38px; font-size: 15px; }
    .stat .v { font-size: 17px; }
    .card { padding: 15px; }
    .modal-content { max-height: 95vh; }
    .modal-body { padding: 15px; }
}

/* ═══ 9. شاشة التحميل — تغطي الصفحة حتى يجهز النظام ═══ */

#pageLoader {
    position: fixed; inset: 0; z-index: 9000;
    background: var(--bg);
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
    transition: opacity .3s ease;
}
#pageLoader.done { opacity: 0; pointer-events: none; }
#pageLoader .pl-logo {
    width: 74px; height: 74px; border-radius: 20px;
    background: var(--primary); color: #fff;
    display: flex; align-items: center; justify-content: center; font-size: 32px;
    box-shadow: var(--sh-lg);
    animation: pl-pulse 1.2s ease infinite;
}
@keyframes pl-pulse { 50% { transform: scale(1.07); } }
#pageLoader .pl-txt { font-size: 14px; font-weight: 800; color: var(--muted); }
#pageLoader .pl-bar {
    width: 190px; height: 5px; border-radius: 10px; background: var(--border); overflow: hidden;
}
#pageLoader .pl-bar b {
    display: block; width: 40%; height: 100%; border-radius: 10px; background: var(--primary);
    animation: pl-slide 1.1s ease-in-out infinite;
}
@keyframes pl-slide { 0% { margin-right: -40%; } 100% { margin-right: 100%; } }

/* لا يُطبع الشريط الجانبي ولا الأزرار */
@media print {
    .sidebar, .topbar, .no-print { display: none !important; }
    body { overflow: visible; }
}
