:root {
    --primary: #0d6efd;
    --sidebar-bg: #1e293b;
    --sidebar-hover: #334155;
    --sidebar-active: #0d6efd;
    --content-bg: #f1f5f9;
}

* { font-family: "Segoe UI", "Tahoma", system-ui, sans-serif; }
body { background: var(--content-bg); }

/* ── التخطيط العام ── */
.app-wrapper { display: flex; min-height: 100vh; }

.sidebar {
    width: 250px;
    background: var(--sidebar-bg);
    color: #cbd5e1;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; right: 0; bottom: 0;
    z-index: 1030;
    transition: transform .25s ease;
}
.sidebar-brand {
    padding: 20px 18px;
    font-size: 1.15rem;
    font-weight: 700;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-brand i { font-size: 1.6rem; color: #38bdf8; }
.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }
.sidebar .nav-link {
    color: #cbd5e1;
    padding: 11px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: .95rem;
    border-right: 3px solid transparent;
    transition: all .15s;
}
.sidebar .nav-link:hover { background: var(--sidebar-hover); color: #fff; }
.sidebar .nav-link.active {
    background: rgba(13,110,253,.15);
    color: #fff;
    border-right-color: var(--sidebar-active);
}
.sidebar .nav-link i { font-size: 1.15rem; width: 22px; text-align: center; }
.sidebar-logout { padding: 12px; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-logout .nav-link:hover { color: #fca5a5; }

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

.topbar {
    background: #fff;
    padding: 14px 22px;
    display: flex;
    align-items: center;
    gap: 14px;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
    position: sticky; top: 0; z-index: 1020;
}
.topbar-title { font-size: 1.15rem; font-weight: 600; margin: 0; flex: 1; }
.topbar-user { display: flex; align-items: center; gap: 8px; color: #475569; font-size: .9rem; }
.topbar-user i { font-size: 1.4rem; color: var(--primary); }

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

/* ── البطاقات الإحصائية ── */
.stat-card {
    background: #fff;
    border-radius: 12px;
    padding: 18px 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
    display: flex;
    align-items: center;
    gap: 16px;
    height: 100%;
}
.stat-icon {
    width: 52px; height: 52px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.5rem; color: #fff; flex-shrink: 0;
}
.stat-info .stat-value { font-size: 1.5rem; font-weight: 700; line-height: 1.1; }
.stat-info .stat-label { color: #64748b; font-size: .85rem; }
.bg-gradient-blue   { background: linear-gradient(135deg,#3b82f6,#2563eb); }
.bg-gradient-green  { background: linear-gradient(135deg,#22c55e,#16a34a); }
.bg-gradient-red    { background: linear-gradient(135deg,#ef4444,#dc2626); }
.bg-gradient-amber  { background: linear-gradient(135deg,#f59e0b,#d97706); }
.bg-gradient-purple { background: linear-gradient(135deg,#8b5cf6,#7c3aed); }
.bg-gradient-teal   { background: linear-gradient(135deg,#14b8a6,#0d9488); }

/* ── البطاقات العامة ── */
.card { border: none; border-radius: 12px; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.card-header {
    background: #fff;
    border-bottom: 1px solid #eef2f7;
    font-weight: 600;
    padding: 14px 18px;
    border-radius: 12px 12px 0 0 !important;
}
.table { margin: 0; }
.table thead th { background: #f8fafc; color: #475569; font-weight: 600; font-size: .85rem; white-space: nowrap; }
.table td { vertical-align: middle; font-size: .9rem; }
.table-responsive { border-radius: 8px; }

.page-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
.page-actions .spacer { flex: 1; }

/* شارة الرصيد الكبيرة */
.balance-box {
    border-radius: 12px; padding: 18px 22px; color: #fff;
    display: flex; flex-direction: column; gap: 4px;
}
.balance-box .amount { font-size: 1.8rem; font-weight: 700; }
.balance-box.creditor { background: linear-gradient(135deg,#22c55e,#16a34a); }
.balance-box.debtor   { background: linear-gradient(135deg,#ef4444,#dc2626); }
.balance-box.balanced { background: linear-gradient(135deg,#64748b,#475569); }

/* ── صفحة الدخول ── */
.guest-body {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg,#1e293b,#0f172a);
    padding: 20px;
}
.guest-card {
    background: #fff; width: 100%; max-width: 400px;
    border-radius: 16px; padding: 36px 32px;
    box-shadow: 0 10px 40px rgba(0,0,0,.3);
}
.login-header { text-align: center; margin-bottom: 28px; }
.login-header i { font-size: 3rem; color: var(--primary); }
.login-header h1 { font-size: 1.4rem; font-weight: 700; margin-top: 10px; }

.cancelled-row { opacity: .55; }
.cancelled-row td { text-decoration: line-through; }

/* أزرار صغيرة في الجداول */
.btn-icon { padding: 4px 9px; }

/* رؤوس الأعمدة القابلة للفرز */
.th-sortable { cursor: pointer; user-select: none; position: relative; }
.th-sortable:hover { background: #eef2f7 !important; }
.th-caret { color: #b6c2cf; font-size: .8em; margin-inline-start: 3px; }
.th-sortable[data-dir="asc"] .th-caret,
.th-sortable[data-dir="desc"] .th-caret { color: var(--primary); }

/* إظهار/إخفاء كلمة المرور (العين) */
.pw-wrap { position: relative; }
.pw-wrap input { padding-left: 36px; }
.pw-wrap .pw-eye {
    position: absolute; top: 0; bottom: 0; left: 4px;
    border: none; background: transparent; color: #94a3b8;
    cursor: pointer; padding: 0 8px; font-size: 1rem; display: flex; align-items: center;
}
.pw-wrap .pw-eye:hover { color: #334155; }

/* عناصر تظهر عند الطباعة فقط */
.print-only { display: none; }
.print-report-head h4 { font-weight: 700; margin: 0; }

/* ── قائمة قابلة للبحث (searchable select) ── */
.ss-wrap { position: relative; }
.ss-display {
    cursor: pointer;
    background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23666'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E") no-repeat left .75rem center;
    background-size: 12px;
}
.ss-display.ss-open { border-color: #86b7fe; box-shadow: 0 0 0 .2rem rgba(13,110,253,.2); }
.ss-panel {
    position: absolute; z-index: 1060; top: 100%; inset-inline: 0;
    background: #fff; border: 1px solid #ced4da; border-radius: 8px;
    box-shadow: 0 6px 18px rgba(0,0,0,.14); margin-top: 3px;
    display: flex; flex-direction: column; overflow: hidden;
}
.ss-search {
    border: none !important; border-bottom: 1px solid #eee !important;
    border-radius: 0 !important; box-shadow: none !important; font-size: .9rem;
}
.ss-list { overflow-y: auto; max-height: 240px; }
.ss-item { padding: 8px 12px; cursor: pointer; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ss-item:hover, .ss-item.active { background: #e7f1ff; }
.ss-item.chosen { font-weight: 600; }
.ss-none { padding: 12px; color: #94a3b8; text-align: center; font-size: .85rem; }

/* ── الجوال ── */
@media (max-width: 991.98px) {
    .sidebar { transform: translateX(100%); }
    .sidebar.show { transform: translateX(0); }
    .main-area { margin-right: 0; }
}

/* ── الطباعة (A4 بالطول، كل المعلومات داخل الصفحة) ── */
@media print {
    @page { size: A4 portrait; margin: 6mm; }

    .sidebar, .topbar, .page-actions, .no-print, .no-print-col, .btn, .ss-panel { display: none !important; }
    .print-only { display: block !important; }
    .main-area { margin: 0 !important; }
    .content { padding: 0 !important; }
    body { background: #fff; font-size: 9px; }

    .card { box-shadow: none !important; border: 1px solid #ddd !important; border-radius: 0 !important; margin-bottom: 4px !important; }
    .card-header { border-radius: 0 !important; padding: 4px 8px; font-size: 10px; }
    a { color: #000 !important; text-decoration: none !important; }

    /* الجدول يملأ عرض الصفحة ويصغّر ليتّسع بالكامل */
    .table-responsive { overflow: visible !important; }
    table.table { font-size: 7.5px !important; width: 100% !important; table-layout: fixed; }
    .table th, .table td {
        padding: 1px 2px !important; vertical-align: middle; line-height: 1.2;
        white-space: normal !important; word-break: break-word; overflow-wrap: anywhere;
    }
    .table thead { display: table-header-group; }   /* تكرار الرأس في كل صفحة */
    .table thead th { background: #eee !important; font-size: 7.5px !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .table tr { page-break-inside: avoid; }
    /* الأرقام على سطر واحد */
    .table td.fw-bold, .table td.text-success, .table td.text-danger { white-space: nowrap !important; }

    /* الشارات والألوان تُطبع واضحة بلا خلفيات ثقيلة */
    .badge { background: transparent !important; color: #000 !important; border: 1px solid #888; padding: 0 2px; font-weight: 700; font-size: 7px; }
    .cancelled-row { opacity: 1; }
    .cancelled-row td { text-decoration: line-through; color: #666 !important; }

    /* بطاقات الإحصائيات مضغوطة في رأس التقرير */
    .stat-card { box-shadow: none; border: 1px solid #ddd; padding: 3px 6px; gap: 6px; }
    .stat-icon { display: none !important; }
    .stat-info .stat-value { font-size: .85rem !important; }
    .stat-info .stat-label { font-size: .62rem; }

    .print-report-head h4 { font-size: 13px; }
    .print-report-head .small { font-size: 8px; }
}
