:root {
    --primary: #2563eb;
    --primary-dark: #1e40af;
    --danger: #dc2626;
    --success: #16a34a;
    --bg: #f3f4f6;
    --card-bg: #ffffff;
    --border: #e5e7eb;
    --text: #1f2937;
    --muted: #6b7280;
}

html {
    overflow-x: hidden;
    max-width: 100%;
}

* { box-sizing: border-box; }

body {
    font-family: 'Segoe UI', Tahoma, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    margin: 0;
    direction: rtl;
    text-align: right;
    overflow-x: hidden; /* يمنع تمدد الصفحة أفقيًا خارج الشاشة مهما حصل */
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
    background: var(--primary-dark);
    color: #fff;
    padding: 14px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
}
.topbar-top { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; max-width: 100%; }
.topbar .brand { font-weight: bold; font-size: 1.2rem; }
.topbar nav { display: flex; flex-wrap: wrap; gap: 10px; max-width: 100%; }

.brand-logo {
    display: inline-flex;
    align-items: center;
    gap: 14px;
    width: fit-content;
    max-width: 100%;
}
.brand-logo img {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    flex-shrink: 0;
}
.text-3d {
    font-family: 'Cairo', sans-serif;
    font-size: 1.5rem;
    font-weight: 900;
    line-height: 1;
    margin: 0;
    padding: 0;
    white-space: nowrap;
    color: #f39c3c;
    text-shadow:
        1px 1px 0 #d35400,
        2px 2px 0 #b84318,
        3px 3px 0 #872e12,
        4px 4px 0 #872e12,
        5px 5px 8px rgba(0,0,0,.4);
}
@media (max-width: 420px) {
    .text-3d { font-size: 1.15rem; }
    .brand-logo img { width: 40px; height: 40px; }
}

.nav3d-wrap {
    position: relative;
    display: inline-block;
    padding-bottom: 8px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}
.nav3d-wrap::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 0;
    width: 100%;
    height: calc(100% - 8px);
    background: #075985;
    border-radius: 999px;
    box-shadow: 0 6px 10px rgba(0,0,0,.3);
    transition: all .15s cubic-bezier(.2,.8,.2,1);
}
.nav3d {
    position: relative;
    display: block;
    padding: 8px 14px;
    font-size: .8rem;
    font-weight: 700;
    color: #fff;
    text-decoration: none;
    text-align: center;
    white-space: nowrap;
    background: linear-gradient(180deg, #38bdf8 0%, #0ea5e9 40%, #0284c7 100%);
    border: 1px solid rgba(255,255,255,.3);
    border-radius: 999px;
    transform: translateY(0);
    text-shadow: 0 1px 2px rgba(0,0,0,.3);
    transition: transform .12s cubic-bezier(.2,.8,.2,1), background .15s ease;
    box-shadow:
        inset 0 1px 1px rgba(255,255,255,.6),
        inset 0 -4px 6px rgba(0,0,0,.2);
}
.nav3d::after {
    content: '';
    position: absolute;
    top: 2px; left: 10%;
    width: 80%; height: 42%;
    background: linear-gradient(180deg, rgba(255,255,255,.45) 0%, rgba(255,255,255,.05) 100%);
    border-radius: 999px;
    pointer-events: none;
}
.nav3d-wrap:hover .nav3d {
    background: linear-gradient(180deg, #56cbfb 0%, #38bdf8 40%, #0ea5e9 100%);
    text-decoration: none;
}
.nav3d-wrap:hover::before { box-shadow: 0 8px 14px rgba(0,0,0,.35); }
.nav3d-wrap:active .nav3d, .nav3d-wrap.active .nav3d {
    transform: translateY(6px);
    box-shadow: inset 0 2px 3px rgba(0,0,0,.2);
}
.nav3d-wrap:active::before, .nav3d-wrap.active::before {
    height: calc(100% - 8px - 4px);
    box-shadow: 0 2px 4px rgba(0,0,0,.3);
}

.nav3d-wrap.logout::before { background: #7f1d1d; }
.nav3d-wrap.logout .nav3d {
    background: linear-gradient(180deg, #f87171 0%, #ef4444 45%, #dc2626 100%);
}

.container { max-width: 1100px; margin: 24px auto; padding: 0 16px; width: 100%; overflow-x: hidden; }

.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,.05);
}

h1 { font-size: 1.5rem; margin-top: 0; }
h2 { font-size: 1.2rem; }

.btn {
    display: inline-block;
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 9px 18px;
    border-radius: 6px;
    cursor: pointer;
    font-size: .95rem;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn-danger { background: var(--danger); }
.btn-secondary { background: #6b7280; }
.btn-sm { padding: 5px 10px; font-size: .8rem; }

.form-group { margin-bottom: 14px; }
.form-group label { display: block; margin-bottom: 5px; font-weight: 600; font-size: .9rem; }
.form-group input, .form-group select {
    width: 100%;
    max-width: 100%;
    padding: 9px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: .95rem;
}

.alert { padding: 12px 16px; border-radius: 6px; margin-bottom: 16px; }
.alert-error { background: #fee2e2; color: #991b1b; }
.alert-success { background: #dcfce7; color: #166534; }

table { border-collapse: collapse; width: 100%; font-size: .88rem; }
td, th { overflow-wrap: break-word; word-break: break-word; }

/* جدول الجدول الشهري تحديدًا: عمود "التفاصيل" فقط ثابت العرض لا يتمدد حسب طول
   الاسم، والنص يصغّر ليلتزم بالمساحة — باقي أعمدة الأشهر تبقى بنفس نظامها السابق */
.monthly-table th:first-child,
.monthly-table td:first-child {
    width: 130px;
    font-size: .78rem;
    line-height: 1.3;
    white-space: normal;
    overflow-wrap: break-word;
    padding: 6px 6px;
}
/* الجدول كان محشورًا بعرض 100% من الشاشة (من القاعدة العامة أعلاه)، فيضطر يضغط
   كل الأعمدة ليدخل بالعرض المتاح مهما كان صغيرًا. هنا نحرّره ليأخذ عرضه
   الطبيعي (13 عمودًا)، ويصير التمرير الأفقي بـ .table-wrap هو اللي يتكفّل
   بإظهار الباقي، بدل ما تنضغط كل الأعمدة على حساب بعض. */
.monthly-table {
    width: auto;
    min-width: 900px;
}
th, td { border: 1px solid var(--border); padding: 7px 9px; text-align: center; white-space: nowrap; }
th { background: #f9fafb; }
td:first-child, th:first-child { text-align: right; background: #fff; }
th:first-child { background: #f9fafb; }
.table-wrap { overflow-x: auto; }

tr.row-total { background: #eef2ff; font-weight: bold; }
tr.row-remaining td { font-weight: bold; }
tr.loan-balance-row { background: #fafafa; }
.forecast-cell { color: #b0b5bd; font-style: italic; }
.estimate-cell { color: #b45309; background: #fffbeb; font-style: italic; }
.pos { color: var(--success); }
.neg { color: var(--danger); }

.year-tabs { margin-bottom: 16px; }
.year-tabs a {
    display: inline-block;
    padding: 6px 14px;
    margin-inline-end: 6px;
    border-radius: 6px;
    background: #e5e7eb;
    color: var(--text);
}
.year-tabs a.active { background: var(--primary); color: #fff; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 700px) { .grid-2 { grid-template-columns: 1fr; } }

.stat-cards { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.stat-card {
    flex: 1;
    min-width: 160px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
    text-align: center;
}
.stat-card .value { font-size: 1.5rem; font-weight: bold; }
.stat-card .label { color: var(--muted); font-size: .85rem; }

.chart-box { position: relative; height: 320px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: .75rem; }
.badge-loan { background: #fef3c7; color: #92400e; }
.badge-expense { background: #dbeafe; color: #1e40af; }

/* دليل الاستخدام: رادع بسيط ضد النسخ (ليس حماية حقيقية - أي شخص يقدر يشوف
   الكود المصدري أو يصوّر الشاشة، لكنه يمنع النسخ العرضي بالضغط المطوّل/التحديد) */
.guide-content, .no-select {
    -webkit-user-select: none;
    -moz-user-select: none;
    user-select: none;
}

.hidden-form { display: none; }
