/* ============================================================
   رصيد - التصميم العام (RTL)
   ============================================================ */

:root {
    --sidebar-width: 260px;
    --primary: #1e6f5c;
    --primary-dark: #14523f;
    --bg: #f4f6f9;
    --card-border: #e8ecf1;
    --income: #198754;
    --expense: #dc3545;
}

* { font-family: 'Tajawal', 'Segoe UI', Tahoma, sans-serif; }

body {
    background: var(--bg);
    color: #2c3345;
    font-size: 15px;
}

/* ---------------- الهيكل ---------------- */

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

.content {
    flex: 1;
    min-width: 0;
    margin-right: var(--sidebar-width);
    display: flex;
    flex-direction: column;
}

.page-body { padding: 1.25rem 1.5rem 3rem; }

/* ---------------- القائمة الجانبية ---------------- */

.sidebar {
    width: var(--sidebar-width);
    position: fixed;
    inset-block: 0;
    right: 0;
    z-index: 1040;
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, var(--primary-dark), var(--primary));
    color: #fff;
    overflow-y: auto;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: 1.25rem 1.25rem 1rem;
}
.sidebar-brand .bi { font-size: 1.9rem; }
.brand-name { font-size: 1.25rem; font-weight: 700; line-height: 1.2; }
.brand-company { font-size: .78rem; opacity: .75; }

.sidebar-nav { flex: 1; padding: .5rem .75rem; }

.nav-section {
    font-size: .72rem;
    letter-spacing: .5px;
    opacity: .6;
    margin: 1rem .75rem .35rem;
}

.nav-item-link {
    display: flex;
    align-items: center;
    gap: .7rem;
    color: rgba(255, 255, 255, .85);
    text-decoration: none;
    padding: .6rem .85rem;
    border-radius: .55rem;
    margin-bottom: .15rem;
    font-size: .95rem;
    transition: background .15s, color .15s;
}
.nav-item-link:hover { background: rgba(255, 255, 255, .12); color: #fff; }
.nav-item-link.active { background: rgba(255, 255, 255, .2); color: #fff; font-weight: 500; }
.nav-item-link .bi { font-size: 1.1rem; }

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid rgba(255, 255, 255, .15);
}
.user-chip { display: flex; align-items: center; gap: .6rem; }
.user-chip .bi { font-size: 1.6rem; }
.user-name { font-weight: 500; font-size: .92rem; }
.user-role { font-size: .75rem; opacity: .75; }

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .45);
    z-index: 1035;
}

/* ---------------- الشريط العلوي ---------------- */

.topbar {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .9rem 1.5rem;
    background: #fff;
    border-bottom: 1px solid var(--card-border);
    position: sticky;
    top: 0;
    z-index: 1020;
}
.page-title { font-size: 1.15rem; font-weight: 700; margin: 0; }

/* ---------------- البطاقات ---------------- */

.card {
    border: 1px solid var(--card-border);
    border-radius: .8rem;
    box-shadow: 0 1px 3px rgba(20, 30, 50, .04);
}
.card-header { background: #fff; border-bottom: 1px solid var(--card-border); font-weight: 700; }

.stat-card {
    border-radius: .9rem;
    padding: 1.15rem 1.3rem;
    background: #fff;
    border: 1px solid var(--card-border);
    display: flex;
    align-items: center;
    gap: 1rem;
    height: 100%;
}
.stat-icon {
    width: 52px;
    height: 52px;
    border-radius: .8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    flex-shrink: 0;
}
.stat-icon.income  { background: #e7f5ee; color: var(--income); }
.stat-icon.expense { background: #fdeaec; color: var(--expense); }
.stat-icon.balance { background: #e8f0fd; color: #2563eb; }
.stat-label { font-size: .85rem; color: #6b7385; margin-bottom: .15rem; }
.stat-value { font-size: 1.45rem; font-weight: 700; line-height: 1.1; }
.stat-value.positive { color: var(--income); }
.stat-value.negative { color: var(--expense); }

/* ---------------- الجداول ---------------- */

.table { margin-bottom: 0; }
.table thead th {
    background: #f8fafc;
    font-size: .82rem;
    color: #5a6274;
    font-weight: 600;
    white-space: nowrap;
    border-bottom-width: 1px;
}
.table td { vertical-align: middle; font-size: .92rem; }

.badge-income  { background: #e7f5ee; color: var(--income); }
.badge-expense { background: #fdeaec; color: var(--expense); }

.amount-income  { color: var(--income); font-weight: 700; }
.amount-expense { color: var(--expense); font-weight: 700; }

/* علامة استلام الإيصال/الفاتورة */
.badge-receipt {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .35rem .65rem;
    border-radius: .5rem;
    border: none;
    font-size: .78rem;
    font-weight: 700;
    line-height: 1;
    white-space: nowrap;
}
.badge-receipt-received { background: var(--income); color: #fff; }
.badge-receipt-missing  { background: #fd7e14; color: #fff; }
button.badge-receipt { cursor: pointer; transition: filter .15s, transform .1s; }
button.badge-receipt:hover  { filter: brightness(.92); }
button.badge-receipt:active { transform: scale(.97); }
button.badge-receipt:disabled { opacity: .6; cursor: progress; }

/* ---------------- تسجيل الدخول والتثبيت ---------------- */

.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    padding: 1rem;
}
.auth-card {
    width: 100%;
    max-width: 420px;
    background: #fff;
    border-radius: 1rem;
    padding: 2rem;
    box-shadow: 0 10px 40px rgba(0, 0, 0, .18);
}
.auth-logo { text-align: center; margin-bottom: 1.5rem; }
.auth-logo .bi { font-size: 3rem; color: var(--primary); }
.auth-logo h1 { font-size: 1.5rem; font-weight: 700; margin-top: .5rem; }

.install-card { max-width: 720px; }

.install-steps {
    display: flex;
    justify-content: space-between;
    margin-bottom: 1.75rem;
    gap: .25rem;
}
.install-step { text-align: center; flex: 1; font-size: .74rem; color: #98a1b3; }
.install-step .num {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #eef1f6;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    margin-bottom: .3rem;
}
.install-step.active { color: var(--primary); font-weight: 500; }
.install-step.active .num { background: var(--primary); color: #fff; }
.install-step.done .num { background: #d7ece3; color: var(--primary); }

.check-list { list-style: none; padding: 0; margin: 0; }
.check-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: .65rem .25rem;
    border-bottom: 1px solid #f0f2f6;
    font-size: .93rem;
}

/* ---------------- التذييل ---------------- */

.app-footer {
    margin-top: auto;
    padding: 1rem 1.5rem;
    text-align: center;
    font-size: .82rem;
    color: #8a92a6;
}
.app-footer a,
.auth-footer a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}
.app-footer a:hover,
.auth-footer a:hover { text-decoration: underline; }

.auth-footer {
    margin-top: 1.5rem;
    text-align: center;
    font-size: .8rem;
    color: #8a92a6;
}

/* ---------------- الأزرار ---------------- */

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
}
.btn-primary:hover, .btn-primary:focus {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}
.btn-outline-primary { color: var(--primary); border-color: var(--primary); }
.btn-outline-primary:hover { background: var(--primary); border-color: var(--primary); }

/* ---------------- الجوال ---------------- */

@media (max-width: 991.98px) {
    .content { margin-right: 0; }

    .sidebar {
        transform: translateX(100%);
        transition: transform .25s ease;
        box-shadow: none;
    }
    .sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0, 0, 0, .3); }
    .sidebar-backdrop.show { display: block; }

    .page-body { padding: 1rem .85rem calc(5rem + env(safe-area-inset-bottom)); }
    .stat-value { font-size: 1.25rem; }

    /* تحويل الجداول إلى بطاقات - بدون تمرير أفقي */
    .table-mobile thead { display: none; }
    .table-mobile tbody tr {
        display: block;
        background: #fff;
        border: 1px solid var(--card-border);
        border-radius: .7rem;
        margin-bottom: .75rem;
        padding: .5rem .85rem;
    }
    .table-mobile tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 1rem;
        border: 0;
        padding: .45rem 0;
        border-bottom: 1px dashed #eef1f6;
        text-align: start;
    }
    .table-mobile tbody td:last-child { border-bottom: 0; }
    .table-mobile tbody td::before {
        content: attr(data-label);
        font-size: .78rem;
        color: #8a92a6;
        font-weight: 600;
        flex-shrink: 0;
    }
    .table-mobile tbody td.no-label::before { content: none; }

    /* جداول تبقى على هيئة جدول حقيقي في الجوال مع تمرير أفقي
       (كشف الحساب وآخر العمليات) */
    .table-grid thead { display: table-header-group; }
    .table-grid tbody tr {
        display: table-row;
        background: transparent;
        border: 0;
        border-radius: 0;
        margin: 0;
        padding: 0;
    }
    .table-grid thead th {
        padding: .5rem .55rem;
        font-size: .74rem;
    }
    .table-grid tbody td {
        display: table-cell;
        border: 0;
        border-bottom: 1px solid #f0f2f6;
        padding: .5rem .55rem;
        font-size: .82rem;
        white-space: nowrap;
        text-align: start;
    }
    .table-grid tbody td::before { content: none; }
    .table-grid tbody tr:last-child td { border-bottom: 0; }

    /* خلايا نصية طويلة: يسمح لها بالالتفاف ضمن عرض محدود */
    .table-grid .cell-wrap {
        white-space: normal;
        min-width: 120px;
        max-width: 190px;
    }

    .table-grid .badge { font-size: .68rem; }
    .table-grid .badge-receipt { font-size: .68rem; padding: .28rem .5rem; }
    .table-grid .btn-sm { padding: .2rem .4rem; font-size: .72rem; }

    /* تلميح التمرير الأفقي أعلى الجدول */
    .table-scroll-hint {
        display: flex;
        align-items: center;
        gap: .35rem;
        font-size: .74rem;
        color: #8a92a6;
        padding: .5rem .85rem .25rem;
    }

    /* شريط التنقّل السفلي للجوال */
    .mobile-bottom-nav {
        position: fixed;
        inset-inline: 0;
        bottom: 0;
        z-index: 1030;
        display: flex;
        align-items: stretch;
        background: #fff;
        border-top: 1px solid var(--card-border, #e5e9f0);
        box-shadow: 0 -4px 18px rgba(15, 23, 42, .08);
        padding-bottom: env(safe-area-inset-bottom);
    }
    .mbn-item {
        flex: 1 1 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        padding: .5rem .15rem;
        font-size: .72rem;
        font-weight: 600;
        color: #64748b;
        background: none;
        border: 0;
        text-decoration: none;
        transition: color .15s ease;
        min-height: 58px;
    }
    .mbn-item i { font-size: 1.35rem; line-height: 1; }
    .mbn-item span { line-height: 1; }
    .mbn-item:active { transform: scale(.95); }
    .mbn-item.active { color: var(--primary, #0f766e); }
    .mbn-item.active i { transform: translateY(-1px); }
    /* تمييز لوني لأزرار الإضافة */
    a.mbn-item[href*="type=expense"] i { color: #dc3545; }
    a.mbn-item[href*="type=income"] i  { color: #198754; }
    a.mbn-item.active[href*="type=expense"],
    a.mbn-item.active[href*="type=income"] { color: var(--primary, #0f766e); }
}

@media print {
    .sidebar, .topbar, .btn, .no-print { display: none !important; }
    .content { margin-right: 0; }
}
