/* ==========================================
   نظام ضريبة أرباح العقارات العراقي
   Iraqi Property Tax System - Main Stylesheet
   ========================================== */

:root {
    --primary: #1a56db;
    --primary-dark: #1043b5;
    --success: #057a55;
    --warning: #c27803;
    --danger: #c81e1e;
    --info: #0694a2;
    --gold: #c6972e;
    --sidebar-width: 264px;
    --topbar-height: 56px;
    --footer-height: 78px;
    --font-arabic: 'Segoe UI', 'Tahoma', 'Arial', sans-serif;

    /* ألوان الهيكل — تتبدّل مع الوضع الليلي */
    --shell-bg: #f0f4f8;
    --shell-surface: #ffffff;
    --shell-border: #dde3ea;
    --shell-text: #1f2937;
    --shell-muted: #6b7280;
    --side-bg: #0f2557;
    --side-text: #c9d5ee;
    --side-active-bg: rgba(255, 255, 255, .14);
    --side-hover-bg: rgba(255, 255, 255, .07);
    --topbar-bg: #1a56db;
    --topbar-text: #ffffff;
}

/* الوضع الليلي — data-bs-theme يضبطه Bootstrap 5.3 وسكربت التهيئة المبكرة */
[data-bs-theme="dark"] {
    --shell-bg: #0b1220;
    --shell-surface: #131c2e;
    --shell-border: #24304a;
    --shell-text: #e5e9f0;
    --shell-muted: #9aa6b8;
    --side-bg: #0a1329;
    --side-text: #aebbd6;
    --side-active-bg: rgba(255, 255, 255, .12);
    --side-hover-bg: rgba(255, 255, 255, .06);
    --topbar-bg: #14203c;
    --topbar-text: #e5e9f0;
}

* { box-sizing: border-box; }

body {
    font-family: var(--font-arabic);
    background-color: var(--shell-bg);
    color: var(--shell-text);
    font-size: 14px;
}

/* الاتجاه يأتي من سمة dir على <html> حسب اللغة، لا من CSS ثابت */
html[dir="rtl"] body { text-align: right; }
html[dir="ltr"] body { text-align: left; }

/* اللغة الكردية السورانية تُكتب بالخط العربي وتحتاج خطاً يدعم محارفها */
html[lang="ckb"] body { font-family: 'Segoe UI', 'Tahoma', 'Noto Naskh Arabic', 'Arial', sans-serif; }

/* ========================================================
   هيكل التطبيق: شريط علوي + قائمة جانبية + محتوى + تذييل
   ======================================================== */

.app-shell { min-height: 100vh; }

/* ---------- الشريط العلوي ---------- */
.topbar {
    position: fixed;
    inset-block-start: 0;
    inset-inline: 0;
    height: var(--topbar-height);
    background: var(--topbar-bg);
    color: var(--topbar-text);
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: 0 .75rem;
    z-index: 1040;
    box-shadow: 0 1px 4px rgba(0, 0, 0, .18);
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: .5rem;
    color: var(--topbar-text);
    text-decoration: none;
    font-weight: 700;
}
.topbar-brand i { font-size: 1.35rem; }

.topbar-actions {
    margin-inline-start: auto;
    display: flex;
    align-items: center;
    gap: .25rem;
}

.icon-btn {
    background: transparent;
    border: 0;
    color: inherit;
    width: 38px;
    height: 38px;
    border-radius: 9px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    cursor: pointer;
}
.icon-btn:hover { background: rgba(255, 255, 255, .15); }

.user-chip {
    background: rgba(255, 255, 255, .13);
    border: 0;
    color: inherit;
    border-radius: 999px;
    padding: .3rem .7rem;
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    font-size: .85rem;
    cursor: pointer;
    max-width: 190px;
}
.user-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip:hover { background: rgba(255, 255, 255, .22); }

/* ---------- القائمة الجانبية ---------- */
.sidebar {
    position: fixed;
    inset-block-start: var(--topbar-height);
    inset-block-end: 0;
    inset-inline-start: 0;
    width: var(--sidebar-width);
    background: var(--side-bg);
    color: var(--side-text);
    display: flex;
    flex-direction: column;
    z-index: 1035;
    overflow-y: auto;
    overscroll-behavior: contain;
    transition: transform .22s ease;
}

.sidebar-head {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .9rem .9rem .7rem;
    border-block-end: 1px solid rgba(255, 255, 255, .1);
}
.sidebar-head > i { font-size: 1.6rem; color: #fff; }
.sidebar-title .t1 { color: #fff; font-weight: 700; font-size: .95rem; line-height: 1.2; }
.sidebar-title .t2 { font-size: .7rem; opacity: .7; }

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

.sidebar-group {
    font-size: .68rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    opacity: .55;
    padding: .9rem .65rem .3rem;
}

.side-link {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .58rem .65rem;
    margin-block-end: 2px;
    border-radius: 9px;
    color: var(--side-text);
    text-decoration: none;
    font-size: .88rem;
    line-height: 1.2;
}
.side-link i { font-size: 1.05rem; width: 1.3rem; text-align: center; flex-shrink: 0; }
.side-link:hover { background: var(--side-hover-bg); color: #fff; }
.side-link.active { background: var(--side-active-bg); color: #fff; font-weight: 600; }

/* شريط التحديد على الحافة الداخلية — يتبع اتجاه اللغة تلقائياً */
.side-link.active::before {
    content: "";
    position: absolute;
    inset-inline-start: 0;
    width: 3px;
    height: 1.6rem;
    background: #fff;
    border-radius: 0 3px 3px 0;
}
.side-link { position: relative; }
.side-link.danger { color: #ffb4b4; }
.side-link.danger:hover, .side-link.danger.active { background: rgba(220, 53, 69, .22); color: #fff; }

.sidebar-foot {
    padding: .75rem .9rem;
    border-block-start: 1px solid rgba(255, 255, 255, .1);
}

.role-badge {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    font-size: .75rem;
    padding: .25rem .6rem;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, .25);
}
.role-taxpayer { background: rgba(13, 110, 253, .25); color: #cfe2ff; }
.role-auditor  { background: rgba(13, 202, 240, .22); color: #cff4fc; }
.role-admin    { background: rgba(255, 193, 7, .22);  color: #ffe69c; }
.role-super    { background: rgba(220, 53, 69, .22);  color: #f5c2c7; }

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .5);
    z-index: 1030;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
}
.sidebar-backdrop.show { opacity: 1; pointer-events: auto; }

/* ---------- المحتوى ---------- */
.app-main {
    margin-block-start: var(--topbar-height);
    margin-inline-start: var(--sidebar-width);
    padding-block-end: calc(var(--footer-height) + .5rem);
    min-height: calc(100vh - var(--topbar-height));
}

/* ---------- التذييل الثابت ---------- */
.app-footer {
    position: fixed;
    inset-block-end: 0;
    inset-inline-start: var(--sidebar-width);
    inset-inline-end: 0;
    background: var(--shell-surface);
    color: var(--shell-muted);
    border-block-start: 1px solid var(--shell-border);
    padding: .5rem 1rem;
    font-size: .74rem;
    text-align: center;
    z-index: 1020;
    line-height: 1.55;
}
.app-footer .foot-line1 { color: var(--shell-text); font-size: .8rem; }
.app-footer .foot-line1 i { color: var(--primary); }
.app-footer .law { white-space: nowrap; }
.app-footer .sep { margin-inline: .4rem; opacity: .5; }

/* ---------- الشاشات المتوسطة والصغيرة (هاتف / تابلت) ---------- */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(calc(var(--sidebar-width) * -1));
        box-shadow: 0 0 24px rgba(0, 0, 0, .35);
    }
    /* في RTL تنزلق القائمة من اليمين */
    html[dir="rtl"] .sidebar { transform: translateX(var(--sidebar-width)); }
    .sidebar.open { transform: translateX(0) !important; }

    .app-main { margin-inline-start: 0; }
    .app-footer { inset-inline-start: 0; }
}

@media (max-width: 575.98px) {
    :root { --footer-height: 92px; }
    .app-footer { font-size: .68rem; padding: .45rem .6rem; }
    .app-footer .foot-line1 { font-size: .72rem; }
    .app-footer .law { white-space: normal; }
    .user-chip { max-width: 44px; padding: .3rem .45rem; }
}

/* أدوات اللغة والمظهر فوق شاشة الدخول */
.auth-toolbar {
    position: absolute;
    inset-block-start: .75rem;
    inset-inline-end: .9rem;
    z-index: 5;
    display: flex;
    gap: .25rem;
    color: #fff;
}
.auth-footer { color: rgba(255, 255, 255, .75); }

/* ========== NAVBAR (صفحات الدخول القديمة) ========== */
.navbar { height: var(--topbar-height); }
.main-content { margin-top: var(--topbar-height); padding: 1rem; }

/* ========== AUTH PAGES ========== */
.auth-wrapper {
    min-height: 100vh;
    background: linear-gradient(135deg, #1a56db 0%, #0e346f 50%, #071b3f 100%);
    display: flex;
    flex-direction: column;
}

.auth-bg { flex: 1; display: flex; align-items: center; }
.auth-content { width: 100%; }

.auth-card {
    background: white;
    border-radius: 16px;
    padding: 2rem;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.auth-logo {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border-radius: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1rem;
    color: white;
    font-size: 28px;
}

.auth-footer {
    color: rgba(255,255,255,0.6);
    background: rgba(0,0,0,0.2);
}

/* ========== CARDS ========== */
.card {
    border-radius: 12px;
    transition: box-shadow 0.2s;
}

.card.shadow-sm:hover { box-shadow: 0 4px 20px rgba(0,0,0,0.12) !important; }

/* ========== QUICK ACTION CARDS ========== */
.quick-action {
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: pointer;
}

.quick-action:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.15) !important;
}

/* ========== WIZARD STEPS ========== */
.wizard-steps {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
}

.wizard-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.step-circle {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #e2e8f0;
    color: #64748b;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    transition: all 0.3s;
    border: 2px solid #e2e8f0;
}

.wizard-step.active .step-circle {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(26, 86, 219, 0.2);
}

.wizard-step.done .step-circle {
    background: var(--success);
    color: white;
    border-color: var(--success);
}

.step-label {
    font-size: 11px;
    color: #64748b;
    font-weight: 500;
    white-space: nowrap;
}

.wizard-step.active .step-label { color: var(--primary); font-weight: 700; }
.wizard-step.done .step-label { color: var(--success); }

.step-line {
    flex: 1;
    height: 2px;
    background: #e2e8f0;
    margin: 0 8px;
    margin-bottom: 24px;
    min-width: 30px;
    transition: background 0.3s;
}

.step-line.done { background: var(--success); }

/* ========== CALCULATION ========== */
.calc-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid #f1f5f9;
}

.tax-summary-box {
    background: linear-gradient(135deg, #f0fdf4, #dcfce7);
    border: 2px solid #86efac;
    border-radius: 12px;
    padding: 1.5rem;
}

.tax-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid #bbf7d0;
}

.tax-row.total {
    border-bottom: none;
    border-top: 2px solid #4ade80;
    margin-top: 8px;
    padding-top: 12px;
    color: var(--success);
}

/* ========== PAYMENT METHODS ========== */
.payment-method-card {
    border: 2px solid #e2e8f0;
    border-radius: 10px;
    padding: 12px 8px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}

.payment-method-card:hover {
    border-color: var(--primary);
    background: #eff6ff;
}

.payment-method-card.selected {
    border-color: var(--primary);
    background: #eff6ff;
    color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26, 86, 219, 0.15);
}

/* ========== RECEIPT ========== */
.receipt-paper {
    background: white;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    padding: 2rem;
    font-size: 13px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
}

.receipt-header {
    border-bottom: 3px double #1a56db;
    padding-bottom: 1rem;
    margin-bottom: 1rem;
}

.receipt-title {
    background: linear-gradient(135deg, #1a56db, #0e346f);
    color: white;
    padding: 12px;
    text-align: center;
    border-radius: 8px;
    margin-bottom: 1.5rem;
}

.receipt-table {
    border-collapse: collapse;
}

.receipt-table th {
    padding: 4px 8px;
    font-weight: 600;
    color: #64748b;
    white-space: nowrap;
}

.receipt-table td {
    padding: 4px 8px;
}

.receipt-amounts {
    background: #f8fafc;
    border-radius: 8px;
    overflow: hidden;
}

.receipt-footer {
    border-top: 2px dashed #e2e8f0;
    padding-top: 1rem;
}

.validity-stamp {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.qr-placeholder {
    width: 80px;
    height: 80px;
    background: #1a56db;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 18px;
    border-radius: 8px;
    margin: 0 auto;
}

/* ========== RISK ========== */
.risk-score-circle {
    width: 90px;
    height: 90px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    font-weight: 700;
    color: white;
    margin: 0 auto;
}

/* ========== ADMIN MODULES ========== */
.admin-module {
    transition: transform 0.2s, box-shadow 0.2s;
}

.admin-module:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(0,0,0,0.15) !important;
}

/* ========== TABLES ========== */
.table th { font-weight: 600; font-size: 13px; }
.table td { vertical-align: middle; }

/* ========== BADGES ========== */
/* ---------- واجهة إعادة الاتصال ----------
   Blazor يضيف على العنصر أحد الأصناف: components-reconnect-show أثناء
   المحاولة، أو -failed بعد فشلها، أو -rejected حين تنتهي الجلسة على
   الخادم. الحاوية مخفية ما لم يُضَف أحدها، ويُعرض القسم المطابق وحده. */
.reconnect-modal { display: none; }

#components-reconnect-modal.components-reconnect-show,
#components-reconnect-modal.components-reconnect-failed,
#components-reconnect-modal.components-reconnect-rejected {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 1080;
    align-items: center;
    justify-content: center;
    background: rgba(15, 23, 42, .55);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}

.reconnect-card {
    background: var(--bs-body-bg, #fff);
    color: var(--bs-body-color, #212529);
    border-radius: .9rem;
    padding: 1.75rem 2rem;
    min-width: min(24rem, 90vw);
    text-align: center;
    box-shadow: 0 1.5rem 3rem rgba(0, 0, 0, .35);
}

.reconnect-body { display: none; }
.reconnect-card .btn + .btn { margin-inline-start: .5rem; }

#components-reconnect-modal.components-reconnect-show .reconnect-show,
#components-reconnect-modal.components-reconnect-failed .reconnect-failed,
#components-reconnect-modal.components-reconnect-rejected .reconnect-rejected {
    display: block;
}

/* ---------- الرسائل العائمة ----------
   position: fixed لا absolute: الرسالة تبقى في موضعها من نافذة العرض
   مهما نزل المستخدم في الصفحة. هذه هي العلّة كلها. */
.toast-host {
    position: fixed;
    top: 4.5rem;                 /* أسفل الشريط العلوي مباشرة */
    left: 50%;
    transform: translateX(-50%);
    z-index: 1090;               /* فوق النوافذ المنبثقة والقائمة الجانبية */
    display: flex;
    flex-direction: column;
    gap: .5rem;
    width: min(34rem, calc(100vw - 2rem));
    pointer-events: none;        /* لا يحجب النقر على ما تحته */
}

.toast-item {
    pointer-events: auto;        /* الرسالة نفسها قابلة للنقر والإغلاق */
    display: flex;
    align-items: flex-start;
    gap: .625rem;
    padding: .75rem 1rem;
    border-radius: .6rem;
    border-inline-start: .3rem solid;
    background: var(--bs-body-bg, #fff);
    color: var(--bs-body-color, #212529);
    box-shadow: 0 .6rem 1.6rem rgba(0, 0, 0, .22);
    animation: toast-in .22s ease-out;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(-.65rem); }
    to   { opacity: 1; transform: translateY(0); }
}

.toast-icon { font-size: 1.15rem; line-height: 1.4; flex-shrink: 0; }
.toast-text { flex: 1; font-size: .9rem; line-height: 1.55; white-space: pre-line; }

.toast-close {
    background: none;
    border: 0;
    padding: 0 .15rem;
    color: inherit;
    opacity: .5;
    flex-shrink: 0;
    line-height: 1;
    cursor: pointer;
}
.toast-close:hover { opacity: 1; }

.toast-success { border-inline-start-color: #16a34a; }
.toast-success .toast-icon { color: #16a34a; }
.toast-error   { border-inline-start-color: #dc2626; }
.toast-error   .toast-icon { color: #dc2626; }
.toast-warning { border-inline-start-color: #f59e0b; }
.toast-warning .toast-icon { color: #f59e0b; }
.toast-info    { border-inline-start-color: #2563eb; }
.toast-info    .toast-icon { color: #2563eb; }

@media (max-width: 576px) {
    .toast-host { top: 3.9rem; }
}

.bg-orange { background-color: #f97316 !important; }
.bg-purple { background-color: #7c3aed !important; }
/* الكشف منجَز — لون وسيط بين «مكلَّفة» و«قيد التدقيق» في مسار الإقرار */
.bg-teal { background-color: #5eead4 !important; }

/* ========== BORDERS ========== */
.border-orange { border-color: #f97316 !important; }

/* ========== MINISTRY EMBLEM ========== */
.ministry-emblem { font-size: 48px; }

/* ========== PRINT ========== */
/* المحتوى الخاص بالطباعة مخفي على الشاشة ويظهر في الورق فقط */
.print-only { display: none; }

@media print {
    .no-print { display: none !important; }

    /* هيكل التطبيق لا يُطبع: الشريط العلوي والقائمة الجانبية والتذييل الثابت
       وغطاء القائمة — وإلا خرجت الأوراق بقائمة جانبية ومحتوى مُزاح. */
    .navbar,
    .topbar,
    .sidebar,
    .sidebar-backdrop,
    .app-footer { display: none !important; }

    .app-main {
        margin-block-start: 0 !important;
        margin-inline-start: 0 !important;
        padding-block-end: 0 !important;
        min-height: auto !important;
    }

    .main-content { margin-top: 0 !important; }
    .receipt-paper {
        border: none;
        box-shadow: none;
        padding: 0;
    }
    body { background: white; }

    .print-only { display: block !important; }

    /* الأزرار والروابط التفاعلية لا معنى لها على الورق */
    .btn, .pwa-install-banner, .offline-toast { display: none !important; }

    .print-letterhead {
        text-align: center;
        margin-bottom: 12px;
    }

    /* إطار للجدول وتفادي قطع الصفوف بين الصفحات */
    .card { border: none !important; box-shadow: none !important; }
    table { border-collapse: collapse !important; width: 100% !important; }
    table th, table td {
        border: 1px solid #999 !important;
        padding: 4px 6px !important;
        font-size: 11px !important;
    }
    thead { display: table-header-group; }
    tr { page-break-inside: avoid; }

    /* الشارات الملوّنة تُطبع رمادية بلا خلفية، فيُعتمد النص وحده */
    .badge {
        background: transparent !important;
        color: #000 !important;
        border: 1px solid #999 !important;
        font-weight: 600;
    }

    @page { margin: 12mm; }
}

/* ========== RESPONSIVE ========== */
@media (max-width: 576px) {
    .wizard-steps { gap: 4px; }
    .step-label { font-size: 9px; }
    .step-line { min-width: 15px; }
}

/* ========================================================
   الوضع الليلي — معالجة الأصناف الثابتة المستخدمة في الصفحات
   Bootstrap 5.3 يتكفّل بمكوّناته، لكن bg-white/bg-light/text-dark
   المكتوبة يدوياً تبقى فاتحة ما لم تُعالَج هنا.
   ======================================================== */
[data-bs-theme="dark"] .card,
[data-bs-theme="dark"] .bg-white {
    background-color: var(--shell-surface) !important;
    color: var(--shell-text);
}

[data-bs-theme="dark"] .bg-light {
    background-color: #1b2438 !important;
    color: var(--shell-text) !important;
}

[data-bs-theme="dark"] .table-light th,
[data-bs-theme="dark"] .table-light td {
    background-color: #1b2438 !important;
    color: var(--shell-text) !important;
}

[data-bs-theme="dark"] .text-dark { color: var(--shell-text) !important; }
[data-bs-theme="dark"] .text-muted { color: var(--shell-muted) !important; }
[data-bs-theme="dark"] .border,
[data-bs-theme="dark"] .border-top,
[data-bs-theme="dark"] .border-bottom { border-color: var(--shell-border) !important; }

[data-bs-theme="dark"] .card-header.bg-white {
    border-block-end-color: var(--shell-border);
}

[data-bs-theme="dark"] .quick-action:hover { background: #1b2438; }

[data-bs-theme="dark"] .receipt-paper {
    background: var(--shell-surface);
    color: var(--shell-text);
}

/* بطاقات الدفع وخطوات المعالج */
[data-bs-theme="dark"] .payment-method-card {
    background: var(--shell-surface);
    border-color: var(--shell-border);
    color: var(--shell-text);
}

/* شاشات الدخول تبقى بتدرّجها الداكن أصلاً، لكن البطاقة تحتاج تعديلاً */
[data-bs-theme="dark"] .auth-card {
    background: var(--shell-surface);
    color: var(--shell-text);
}

/* ========================================================
   منتقي موقع العقار على الخارطة
   ======================================================== */
.map-picker {
    border: 1px solid var(--shell-border);
    border-radius: 12px;
    overflow: hidden;
    background: var(--shell-surface);
}

.map-toolbar {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-wrap: wrap;
    padding: .6rem .75rem;
    border-block-end: 1px solid var(--shell-border);
}

.map-hint {
    font-size: .74rem;
    color: var(--shell-muted);
    margin-inline-start: auto;
}

.map-canvas {
    height: 380px;
    width: 100%;
    /* الخارطة تحت القوائم المنسدلة للشريط العلوي */
    z-index: 0;
}
.map-canvas-sm { height: 240px; }

/* الخارطة تُرسم بالإنجليزية دائماً فتُثبَّت جهة الكتابة */
.map-canvas, .leaflet-container { direction: ltr; }

/* دبوس العقار */
.prop-pin-inner {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    color: #c81e1e;
    filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .45));
    animation: pin-drop .35s ease-out;
}
@keyframes pin-drop {
    from { transform: translateY(-14px) scale(.85); opacity: 0; }
    to   { transform: translateY(0) scale(1); opacity: 1; }
}

.map-readout {
    display: flex;
    gap: 1.25rem;
    flex-wrap: wrap;
    padding: .6rem .75rem;
    border-block-start: 1px solid var(--shell-border);
    background: var(--shell-bg);
}
.map-readout .coord { display: flex; flex-direction: column; }
.map-readout .lbl { font-size: .68rem; color: var(--shell-muted); }
.map-readout .val { font-size: .85rem; font-weight: 600; }

.map-manual {
    display: flex;
    gap: .5rem;
    align-items: center;
    flex-wrap: wrap;
    padding: .6rem .75rem;
    border-block-start: 1px dashed var(--shell-border);
}
.map-manual input { max-width: 150px; }

@media (max-width: 575.98px) {
    .map-canvas { height: 300px; }
    .map-hint { display: none; }
    .map-manual input { max-width: 100%; flex: 1 1 45%; }
}

/* الوضع الليلي: تخفيف وهج الأدوات البيضاء لـ Leaflet */
[data-bs-theme="dark"] .leaflet-control-zoom a {
    background: #1b2438;
    color: #e5e9f0;
    border-color: #24304a;
}
[data-bs-theme="dark"] .leaflet-control-attribution {
    background: rgba(19, 28, 46, .85);
    color: #9aa6b8;
}
[data-bs-theme="dark"] .leaflet-control-attribution a { color: #7aa2e3; }

/* ========== UTILITY ========== */
.x-small { font-size: 11px; }
/* الأرقام المرجعية لاتينية داخل واجهة عربية، فتُعزل اتجاهياً لئلا تتبعثر
   علاماتها (الشرطات والنقاط) عند التجاور مع نص عربي.
   لا display ولا direction هنا: الصنف يُستعمل على خلايا الجدول أيضاً،
   و inline-block يُخرج الخلية من شبكة الجدول فتنكسر محاذاة الأعمدة،
   و direction تقلب محاذاة الخلية إلى اليسار داخل جدول من اليمين لليسار.
   ما يلزمه اتجاه صريح يُعلَن بسمة dir="ltr" على العنصر نفسه. */
.font-monospace { font-family: 'Courier New', monospace; unicode-bidi: isolate; }
.cursor-pointer { cursor: pointer; }

/* ========== PWA & MOBILE ENHANCEMENTS ========== */

/* Safe area insets for notched phones */
/* الهواتف ذات النتوء والشريط السفلي: يُزاح الشريط العلوي والتذييل الثابت
   عن المناطق المحجوزة، وإلا اختفى محتواهما تحت واجهة النظام. */
@supports (padding-top: env(safe-area-inset-top)) {
  .topbar {
    height: calc(var(--topbar-height) + env(safe-area-inset-top));
    padding-top: env(safe-area-inset-top);
  }
  /* تُعاد القيمة كاملة لا الإزاحة وحدها، وإلا انزلق المحتوى تحت الشريط العلوي */
  .sidebar { inset-block-start: calc(var(--topbar-height) + env(safe-area-inset-top)); }
  .app-main {
    margin-block-start: calc(var(--topbar-height) + env(safe-area-inset-top));
    padding-block-end: calc(var(--footer-height) + .5rem + env(safe-area-inset-bottom));
  }

  .app-footer { padding-bottom: calc(.5rem + env(safe-area-inset-bottom)); }

  .navbar { padding-top: env(safe-area-inset-top); }
}

/* Touch-friendly: 16px prevents auto-zoom on iOS */
.form-control, .form-select { font-size: 16px; }
.form-control-sm, .form-select-sm { font-size: 14px; }

/* Prevent double-tap zoom */
button, a { touch-action: manipulation; }

/* Smooth scrolling */
html { scroll-behavior: smooth; -webkit-overflow-scrolling: touch; }

/* Mobile improvements */
@media (max-width: 767px) {
  .main-content { padding: 0.5rem; }
  .card { border-radius: 10px; }
  .card-body { padding: 0.875rem; }
  .card-header { padding: 0.75rem 0.875rem; }
  .table { font-size: 13px; }
  .table th, .table td { padding: 0.5rem 0.4rem; white-space: nowrap; }
  .auth-card { padding: 1.5rem 1.25rem; border-radius: 12px; }
  .modal-dialog { margin: 0.5rem; }
  .modal-content { border-radius: 16px; }
}

/* PWA Install Banner */
.pwa-install-banner {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: #1a56db;
  color: white;
  padding: 1rem 1.25rem;
  padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.25);
  transform: translateY(100%);
  transition: transform 0.35s ease;
}
.pwa-install-banner.show { transform: translateY(0); }
.pwa-install-banner .banner-text { flex: 1; }
.pwa-install-banner .banner-title { font-weight: 700; font-size: 0.95rem; margin: 0; }
.pwa-install-banner .banner-sub  { font-size: 0.8rem; opacity: 0.85; margin: 0; }
.pwa-install-banner .btn-install {
  background: white; color: #1a56db;
  border: none; padding: 0.5rem 1.25rem;
  border-radius: 50px; font-weight: 700;
  font-size: 0.875rem; white-space: nowrap; cursor: pointer;
}
.pwa-install-banner .btn-dismiss {
  background: transparent; border: none;
  color: rgba(255,255,255,0.7); font-size: 1.25rem;
  cursor: pointer; padding: 0.25rem; line-height: 1;
}

/* Offline toast */
.offline-toast {
  position: fixed;
  top: 70px; left: 50%;
  transform: translateX(-50%) translateY(-120px);
  background: #1e293b; color: white;
  padding: 0.5rem 1.25rem; border-radius: 50px;
  font-size: 0.85rem; z-index: 9998;
  display: flex; align-items: center; gap: 0.5rem;
  white-space: nowrap;
  transition: transform 0.3s ease;
  box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}
.offline-toast.show { transform: translateX(-50%) translateY(0); }

/* Settings page */
.settings-section-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #6b7280;
  font-weight: 700;
  margin-bottom: 0.75rem;
}
.gateway-badge {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.3rem 0.85rem; border-radius: 50px;
  font-size: 0.8rem; font-weight: 600;
}
.gateway-badge.on  { background: #d1fae5; color: #065f46; }
.gateway-badge.off { background: #f3f4f6; color: #6b7280; }
.gateway-badge.test{ background: #fef3c7; color: #92400e; }

/* ========== الخارطة: صقل المظهر ========== */

/* حواف مستديرة وحدّ خفيف: الخارطة عنصر ضمن بطاقة لا لوحة معلّقة */
.leaflet-container {
    border-radius: .5rem;
    background: var(--shell-bg);
    font-family: inherit;
}

/* أدوات Leaflet الافتراضية حادّة وبيضاء ناصعة؛ تُلطَّف لتشبه بقية الواجهة */
.leaflet-bar {
    border: 1px solid var(--shell-border);
    border-radius: .5rem;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .12);
}
.leaflet-bar a {
    border-bottom-color: var(--shell-border);
    font-weight: 600;
}
.leaflet-control-attribution {
    border-radius: .35rem 0 0 0;
    font-size: .65rem;
    opacity: .75;
}
.leaflet-control-scale-line {
    border-color: var(--shell-border);
    border-radius: .25rem;
    background: rgba(255, 255, 255, .78);
    font-size: .68rem;
}

[data-bs-theme="dark"] .leaflet-control-scale-line {
    background: rgba(19, 28, 46, .8);
    color: #cfd6e4;
    border-color: #2a3550;
}
[data-bs-theme="dark"] .leaflet-bar {
    border-color: #24304a;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .45);
}

/* الدبوس: هالة تحته تفصله عن البلاطة مهما كان لونها */
.prop-pin-inner::after {
    content: "";
    position: absolute;
    inset-block-end: -2px;
    inset-inline-start: 50%;
    transform: translateX(-50%);
    width: 12px;
    height: 5px;
    border-radius: 50%;
    background: rgba(0, 0, 0, .3);
    filter: blur(1.5px);
}
.prop-pin-inner { position: relative; }

/* ========== الوضع الليلي: بطاقات ذات خلفية فاتحة مثبَّتة ==========

   العلّة: هذه البطاقات تحمل خلفية فاتحة صريحة ولا تحمل لون نص، فترث
   في الوضع الليلي نص الواجهة الفاتح فيقع فاتحٌ على فاتح ويتعذّر
   قراءة المبلغ — وهو أهم ما في الشاشة.

   العلاج ضبط الخلفية والنص معاً لا الخلفية وحدها: ضبط أحدهما دون
   الآخر يعيد المشكلة معكوسة. */

[data-bs-theme="dark"] .tax-summary-box {
    background: linear-gradient(135deg, #10281d, #14352a);
    border-color: #2f6b4c;
    color: #e7f6ee;
}
[data-bs-theme="dark"] .tax-row { border-bottom-color: #2a5a41; }
[data-bs-theme="dark"] .tax-row.total {
    border-top-color: #3f9c6d;
    color: #6ee7a8;
}

[data-bs-theme="dark"] .receipt-amounts {
    background: #16203a;
    color: #dfe5f0;
}
[data-bs-theme="dark"] .receipt-footer { border-top-color: #2a3550; }

/* شريط الخطوات: الدائرة والخط غير المقطوعَين يبقيان رماديين فاتحين
   فيبدوان منفصلين عن الخلفية الداكنة */
[data-bs-theme="dark"] .step-circle {
    background: #22304d;
    color: #9fb0cc;
}
[data-bs-theme="dark"] .step-line { background: #22304d; }

/* ========================================================
   شعار الهيئة العامة للضرائب
   شعار رسمي: يُعرض بنسبته ولا يُشوَّه ولا تُقلب ألوانه في
   الوضع الليلي ولا تُطبَّق عليه مرشّحات.
   ======================================================== */
.emblem {
    object-fit: contain;
    flex-shrink: 0;
    /* الشعار شفاف الخلفية، فيظهر على الفاتح والداكن معاً بلا تعديل */
    filter: none !important;
}

/* الترويسة والقائمة: الشعار على خلفية داكنة، فيُعطى هالة خفيفة
   تفصله عنها دون المساس بألوانه */
.topbar-emblem,
.sidebar-emblem {
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .35)) !important;
}

.foot-emblem { vertical-align: -.35em; }

.banner-emblem { border-radius: 8px; }

/* ترويسة الوثائق: الوصل والبطاقة وصفحات التحقق */
.doc-emblem {
    display: block;
    margin-inline: auto;
}

/* صفحة الدخول */
.auth-logo .emblem {
    margin-inline: auto;
    display: block;
}

/* الطباعة: الشعار جزء من الوثيقة الرسمية فلا يُحذف مع بقية الزينة،
   والمتصفحات تُسقط الصور الخلفية افتراضاً فيُفرض طبعها */
@media print {
    .emblem {
        display: block !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .doc-emblem { max-width: 90px; height: auto; }
}
