/* ═══════════════════════════════════════════════════════════
   نظام إدارة العقارات - إصدار الويب
   CSS موحد مع دعم RTL وتصميم مشابه للنسخة المكتبية
   الألوان:
     Primary    = #2C3E50 (أزرق داكن)
     Secondary  = #3498DB (أزرق فاتح)
     Success    = #27AE60
     Danger     = #E74C3C
     Warning    = #F39C12
     Light      = #ECF0F1
   ═══════════════════════════════════════════════════════════ */

:root {
    --color-primary: #2C3E50;
    --color-secondary: #3498DB;
    --color-success: #27AE60;
    --color-danger: #E74C3C;
    --color-warning: #F39C12;
    --color-light: #ECF0F1;
    --color-dark: #1A252F;
    --color-border: #BDC3C7;
    --color-text: #2C3E50;
    --color-muted: #7F8C8D;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: "Segoe UI", Tahoma, Arial, sans-serif;
    font-size: 14px;
    color: var(--color-text);
    background: var(--color-light);
    direction: rtl;
    text-align: right;
}

h1, h2, h3, h4 { margin: 0 0 8px; color: var(--color-primary); }

/* ═════════════════════════════════════════ Layout ═════ */
.app-page {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-header {
    background: var(--color-primary);
    color: white;
    padding: 10px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.header-left { display: flex; align-items: center; gap: 20px; }
.app-title { font-size: 18px; font-weight: bold; }
.project-badge {
    background: var(--color-secondary);
    padding: 4px 12px;
    border-radius: 4px;
    font-size: 13px;
}

.header-right { display: flex; align-items: center; gap: 10px; }
.user-name { color: #ECF0F1; display: flex; align-items: center; gap: 8px; }
.badge-admin {
    background: var(--color-warning);
    color: white;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 11px;
}

.header-btn {
    color: white;
    padding: 6px 12px;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 4px;
    text-decoration: none;
    font-size: 13px;
    transition: background 0.2s;
}
.header-btn:hover { background: rgba(255,255,255,0.1); }
.btn-logout { background: var(--color-danger); border-color: var(--color-danger); }

.app-body { display: flex; flex: 1; }
.app-sidebar {
    width: 250px;
    background: white;
    border-left: 1px solid var(--color-border);
    overflow-y: auto;
}
.app-main {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
}
.app-main-fullscreen {
    flex: 1;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}
.app-footer {
    background: var(--color-primary);
    color: white;
    text-align: center;
    padding: 8px;
    font-size: 12px;
}

/* ═════════════════════════════════════════ Nav Menu ═════ */
.nav-menu { padding: 10px 0; }
.nav-group { margin-bottom: 15px; }
.nav-group-title {
    padding: 6px 16px;
    font-size: 11px;
    font-weight: bold;
    color: var(--color-muted);
    text-transform: uppercase;
    background: #f8f9fa;
    border-bottom: 1px solid #e0e0e0;
}
.nav-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    color: var(--color-text);
    text-decoration: none;
    transition: background 0.15s;
    font-size: 13px;
}
.nav-link:hover { background: #f0f3f5; }
.nav-link.active { background: var(--color-secondary); color: white; }
.nav-icon { width: 20px; text-align: center; }

/* المجموعات الفرعية داخل التقارير */
.nav-subgroup {
    border-bottom: 1px dashed #eee;
}
.nav-subgroup:last-child {
    border-bottom: none;
}
.nav-subgroup-title {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 16px;
    font-size: 12px;
    font-weight: 700;
    color: #34495E;
    background: #fafbfc;
    cursor: pointer;
    user-select: none;
    list-style: none;
}
/* `list-style: none` فوق بيخفي علامة الـ details في كل المتصفحات الحديثة.
   ::-webkit-details-marker اتشال لأنه deprecated في المتصفحات الحديثة
   (ومايتعرّفش عليه VS validator فبيطلع warning). */
.nav-subgroup-title::before {
    content: "▾";
    font-size: 10px;
    color: #95A5A6;
    transition: transform 0.15s;
}
.nav-subgroup:not([open]) > .nav-subgroup-title::before {
    transform: rotate(-90deg);
}
.nav-subgroup-title:hover { background: #f0f3f5; }
.nav-sublink {
    padding-inline-start: 32px;  /* تباعد إضافي عشان يبان كـ sub-item (RTL-safe) */
    font-size: 12.5px;
}

/* ═════════════════════════════════════════ Forms & Buttons ═════ */
.form-group { margin-bottom: 12px; }
.form-group label {
    display: block;
    margin-bottom: 4px;
    font-weight: 600;
    font-size: 13px;
}
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }
.form-control {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    font-size: 14px;
    font-family: inherit;
    direction: rtl;
}
.form-control:focus {
    outline: none;
    border-color: var(--color-secondary);
    box-shadow: 0 0 0 2px rgba(52,152,219,0.2);
}
textarea.form-control { resize: vertical; }

.btn {
    padding: 8px 18px;
    border: none;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    transition: all 0.2s;
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: var(--color-secondary); color: white; }
.btn-primary:hover:not(:disabled) { background: #2980B9; }
.btn-success { background: var(--color-success); color: white; }
.btn-success:hover:not(:disabled) { background: #229954; }
.btn-danger { background: var(--color-danger); color: white; }
.btn-danger:hover:not(:disabled) { background: #C0392B; }
.btn-secondary { background: #95A5A6; color: white; }
.btn-ghost { background: transparent; border: 1px solid var(--color-border); color: var(--color-text); }
.btn-block { width: 100%; }

.btn-small {
    padding: 4px 10px;
    font-size: 12px;
    margin: 0 2px;
    border: none;
    border-radius: 3px;
    cursor: pointer;
}
.btn-edit { background: var(--color-secondary); color: white; }
.btn-delete { background: var(--color-danger); color: white; }

.form-actions {
    display: flex;
    gap: 10px;
    margin-top: 15px;
    justify-content: flex-end;
}

/* ═════════════════════════════════════════ Tables ═════ */
.data-table-wrapper {
    background: white;
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    margin-top: 12px;
}

/* ─── ⚖️ Legal Cases Badge (في قوائم العملاء/العقود/الوحدات) ─── */
.legal-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 9px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: bold;
    margin-inline-start: 8px;
    cursor: help;
    white-space: nowrap;
    vertical-align: middle;
    border: 1px solid transparent;
}
.legal-badge-active {
    background: #FADBD8;
    color: #922B21;
    border-color: #E6B0AA;
}
.legal-badge-closed {
    background: #D4EFDF;
    color: #196F3D;
    border-color: #A9DFBF;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}
.data-table th {
    background: var(--color-primary);
    color: white;
    padding: 10px 12px;
    text-align: right;
    font-weight: 600;
    font-size: 13px;
}
.data-table td {
    padding: 8px 12px;
    border-bottom: 1px solid #eee;
    font-size: 13px;
}
.data-table tr:nth-child(even) td { background: #f8f9fa; }
.data-table tr:hover td { background: #e3f2fd; }
.data-table .empty {
    text-align: center;
    padding: 30px;
    color: var(--color-muted);
}
.actions-cell { white-space: nowrap; }
.row-count { text-align: left; color: var(--color-muted); margin-top: 8px; font-size: 12px; }

/* ═════════════════════════════════════════ Cards & Alerts ═════ */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--color-primary);
}
.page-actions { display: flex; gap: 8px; }
.search-bar { margin-bottom: 10px; }

.alert {
    padding: 12px 16px;
    border-radius: 4px;
    margin-bottom: 12px;
    border-right: 4px solid;
}
.alert-error { background: #fadbd8; border-color: var(--color-danger); color: #641E16; }
.alert-success { background: #d5f5e3; border-color: var(--color-success); color: #0E6251; }
.alert-warning { background: #fdebd0; border-color: var(--color-warning); color: #7E5109; }
.alert-info { background: #d4e6f1; border-color: var(--color-secondary); color: #1B4F72; }

.card {
    background: white;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.card-center {
    max-width: 500px;
    width: 100%;
}
.card-header { margin-bottom: 15px; text-align: center; }
.center-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 120px);
    padding: 20px;
}

/* ═════════════════════════════════════════ Login ═════ */
.login-wrapper {
    width: 100%;
    min-height: 100vh;
    background: linear-gradient(135deg, #2C3E50 0%, #3498DB 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.login-card {
    background: white;
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
    width: 100%;
    max-width: 400px;
}
.login-logo { text-align: center; margin-bottom: 30px; }
.logo-icon { font-size: 48px; margin-bottom: 10px; }
.login-logo h1 { margin: 0 0 5px; font-size: 22px; }
.subtitle { color: var(--color-muted); font-size: 12px; margin: 0; }
.login-form { display: flex; flex-direction: column; gap: 12px; }
.login-hint {
    margin-top: 20px;
    text-align: center;
    color: var(--color-muted);
    font-size: 12px;
}
.login-hint code {
    background: var(--color-light);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: Consolas, monospace;
}

/* زر hamburger - يظهر فقط على الموبايل */
.hamburger-btn {
    display: none;
    background: transparent; border: none; color: inherit;
    font-size: 22px; cursor: pointer; padding: 4px 10px;
}
@media (max-width: 768px) {
    .hamburger-btn { display: inline-block; }
}

/* ═════════════════════════════════════════ Mobile Responsive ═════ */
/* الـ data tables بتكون عريضة جداً على الموبايل - بنخليها تـ scroll أفقي
   وعمودها الأول sticky عشان المستخدم يحافظ على الـ context */
@media (max-width: 768px) {
    .app-header { flex-wrap: wrap; padding: 8px 12px; gap: 6px; }
    .app-header .header-left { flex: 1 1 100%; }
    .app-header .header-right { flex: 1 1 100%; justify-content: space-around; gap: 4px; }
    .app-header .header-btn { font-size: 11px; padding: 4px 8px; }
    .app-header .app-title { font-size: 14px; }
    .app-header .project-badge { font-size: 11px; }

    .app-sidebar { width: 100% !important; max-width: 280px; position: fixed;
                   top: 0; bottom: 0; right: -280px; z-index: 100;
                   transition: right 0.25s; box-shadow: -4px 0 12px rgba(0,0,0,0.2); }
    .app-sidebar.mobile-open { right: 0; }
    .app-main { padding: 10px !important; }

    /* الجداول: scroll أفقي + خط أصغر */
    .data-table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .data-table { font-size: 12px; min-width: 600px; }
    .data-table th, .data-table td { padding: 6px 8px; }

    /* الأزرار في الـ actions cell تتلف */
    .actions-cell { display: flex; flex-wrap: wrap; gap: 3px; }
    .btn-small { font-size: 11px; padding: 4px 6px; }

    /* الـ modals: عرض كامل تقريباً */
    .modal-card { width: 95% !important; max-width: 95vw !important; }
    .modal-body { padding: 10px !important; }

    /* page-header بقت تلف */
    .page-header { flex-wrap: wrap; gap: 8px; }
    .page-header h1 { font-size: 18px; flex: 1 1 100%; }
    .page-actions { flex-wrap: wrap; }

    /* form-row بتبقى عمود واحد */
    .form-row { flex-direction: column !important; gap: 8px !important; }
    .form-row .form-group { min-width: 100% !important; }
}

/* ═════════════════════════════════════════ Modal ═════ */
/* الإغلاق بالضغط على الخلفية معطّل عمداً عبر pointer-events:
   كان بيتسبب في race condition مع @bind:onchange على inputs (فقدان focus +
   إغلاق dialog يعملوا NullReferenceException). الإغلاق بقى بزر X / إلغاء فقط
   - أأمن وأقل احتمالاً للإغلاق العشوائي وضياع البيانات. */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
    pointer-events: none;  /* يمنع clicks من الوصول للـ Blazor handler */
}
.modal-card {
    background: white;
    border-radius: 8px;
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 40px rgba(0,0,0,0.3);
    pointer-events: auto;  /* الـ card نفسها بترجع تستقبل clicks عادي */
}
.modal-header {
    padding: 15px 20px;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-header h3 { margin: 0; }
.modal-header .close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--color-muted);
}
.modal-body { padding: 20px; }
.modal-footer {
    padding: 15px 20px;
    border-top: 1px solid var(--color-border);
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* ═════════════════════════════════════════ Home / Dashboard ═════ */
.home-hero {
    background: white;
    padding: 25px;
    border-radius: 8px;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.home-hero h1 { color: var(--color-primary); }
.dashboard-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}
.card-stat {
    background: white;
    padding: 20px;
    border-radius: 8px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.stat-icon { font-size: 32px; }
.stat-label { color: var(--color-muted); font-size: 13px; margin-top: 5px; }
.stat-value { font-size: 28px; font-weight: bold; color: var(--color-primary); }

/* ═════════════════════════════════════════ Select Project List ═════ */
.projects-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 15px 0;
}
.project-item {
    text-align: right;
    background: white;
    padding: 12px 15px;
    border: 2px solid var(--color-border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}
.project-item:hover { background: var(--color-light); border-color: var(--color-secondary); }
.project-item.selected {
    background: var(--color-secondary);
    color: white;
    border-color: var(--color-secondary);
}
.project-name { font-weight: bold; font-size: 15px; }
.project-meta { font-size: 12px; margin-top: 3px; opacity: 0.8; }

/* ═════════════════════════════════════════ Utilities ═════ */
.loading { text-align: center; padding: 30px; color: var(--color-muted); }
.muted { color: var(--color-muted); }

/* ═════════════════════════════════════════ Contract Picker (Smart Search) ═════ */
.contract-picker {
    max-width: 700px;
    margin: 10px 0;
}
.contract-picker-input {
    position: relative;
}
.contract-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    left: 0;
    background: white;
    border: 1px solid var(--color-border);
    border-radius: 0 0 6px 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    max-height: 300px;
    overflow-y: auto;
    z-index: 100;
}
.contract-item {
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    transition: background 0.1s;
}
.contract-item:hover {
    background: #e3f2fd;
}
.contract-item:last-child {
    border-bottom: none;
}
.contract-item .muted {
    color: var(--color-muted);
    font-size: 12px;
    margin-right: 5px;
}
.contract-item .info-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}
.contract-item b {
    color: var(--color-primary);
}
.contract-selected {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 12px 15px;
    background: #eafaf1;
    border: 2px solid var(--color-success);
    border-radius: 6px;
}
.contract-selected-info b {
    color: var(--color-primary);
    font-size: 15px;
}
.contract-no-results {
    padding: 20px;
    text-align: center;
    color: var(--color-muted);
    font-style: italic;
}

/* Blazor Error UI */
#blazor-error-ui {
    background: #ffffe0;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}
#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    left: 0.75rem;
    top: 0.5rem;
}


/* ═══════════════════════════════════════════════════════════
   📱 Mobile Responsive (≤ 900px)
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
    /* Layout */
    .app-body { flex-direction: column; }
    .app-sidebar {
        width: 100%;
        max-height: 50vh;
        border-left: none;
        border-bottom: 1px solid var(--color-border);
        position: relative;
    }
    .app-main { padding: 10px; }

    /* Header */
    .app-header {
        flex-wrap: wrap;
        padding: 8px 12px;
        gap: 8px;
    }
    .header-left { flex-wrap: wrap; gap: 8px; }
    .app-title { font-size: 15px; }
    .project-badge { font-size: 11px; padding: 3px 8px; }
    .header-right { flex-wrap: wrap; gap: 6px; }
    .header-btn { padding: 4px 8px; font-size: 11px; }
    .user-name { font-size: 12px; }

    /* Page Header */
    .page-header { flex-direction: column; align-items: flex-start; gap: 10px; }
    .page-header h1 { font-size: 18px; }
    .page-actions { flex-wrap: wrap; gap: 6px; }
    .page-actions .btn { font-size: 12px; padding: 6px 10px; }

    /* Tables - تخلي الجداول قابلة للسحب أفقياً */
    .data-table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .data-table { font-size: 12px; min-width: 600px; }
    .data-table th, .data-table td { padding: 6px 8px; }

    /* Cards */
    .dashboard-cards {
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)) !important;
        gap: 8px !important;
    }
    .card-stat { padding: 10px !important; }
    .stat-value { font-size: 16px !important; }
    .stat-label { font-size: 11px !important; }

    /* Forms */
    .form-row { flex-direction: column; gap: 8px; }
    .form-group { width: 100%; }
    .form-control { font-size: 14px; }

    /* Search Bar */
    .search-bar { flex-wrap: wrap; gap: 6px; padding: 8px; }
    .search-bar .form-control { width: 100%; }
    .search-bar label { font-size: 12px; }

    /* Modals */
    .modal-card {
        max-width: 95vw !important;
        width: 95vw;
        max-height: 90vh;
        overflow-y: auto;
    }
    .modal-body { padding: 12px; }

    /* Charts */
    .pie-chart-content { flex-direction: column; }
    .pie-svg { width: 180px !important; height: 180px !important; }

    /* NavMenu */
    .nav-group-btn { padding: 10px 12px; font-size: 14px; }
    .nav-link { padding: 9px 12px 9px 24px; font-size: 13px; }
}

/* للشاشات الصغيرة جداً (≤ 480px) */
@media (max-width: 480px) {
    .app-title { font-size: 13px; }
    .header-btn { font-size: 10px; padding: 3px 6px; }
    .badge-admin { font-size: 9px; }
    .btn { font-size: 12px; }
    .data-table { font-size: 11px; }

    /* اللوجو في صفحة الـ login يبقى أصغر */
    .login-card { padding: 20px !important; max-width: 95vw !important; }
    .logo-icon { font-size: 36px !important; }
    .login-card h1 { font-size: 18px !important; }
}



/* ═══════════════════════════════════════════════════════════
   🌙 Dark Mode
   ═══════════════════════════════════════════════════════════ */
body.dark-mode {
    --color-primary: #1A2530;
    --color-secondary: #5DADE2;
    --color-light: #2C3E50;
    --color-text: #ECF0F1;
    --color-muted: #95A5A6;
    --color-border: #34495E;
    background: #1A1F25;
    color: #ECF0F1;
}

body.dark-mode .app-sidebar { background: #2C3E50; border-color: #34495E; }
body.dark-mode .app-main { background: #1A1F25; }
body.dark-mode h1, body.dark-mode h2, body.dark-mode h3, body.dark-mode h4 { color: #ECF0F1; }

/* Cards & Tables */
body.dark-mode .card-stat,
body.dark-mode .data-table-wrapper,
body.dark-mode .modal-card,
body.dark-mode .nav-group-content,
body.dark-mode .pie-chart-wrapper,
body.dark-mode .bar-chart-wrapper {
    background: #2C3E50;
    color: #ECF0F1;
    border-color: #34495E;
}
body.dark-mode .data-table { color: #ECF0F1; }
body.dark-mode .data-table thead th { background: #34495E; color: #ECF0F1; border-color: #1A2530; }
body.dark-mode .data-table tbody tr { border-color: #34495E; }
body.dark-mode .data-table tbody tr:hover { background: #34495E; }
body.dark-mode .data-table tbody tr:nth-child(even) { background: #283747; }

/* Forms */
body.dark-mode .form-control,
body.dark-mode select.form-control,
body.dark-mode textarea.form-control {
    background: #1A2530;
    color: #ECF0F1;
    border-color: #34495E;
}
body.dark-mode .form-control:focus { border-color: #5DADE2; }
body.dark-mode .form-control::placeholder { color: #7F8C8D; }

/* NavMenu */
body.dark-mode .nav-group-btn { background: #34495E; color: #ECF0F1; }
body.dark-mode .nav-group-btn:hover { background: #3D566E; }
body.dark-mode .nav-group.open .nav-group-btn { background: #5DADE2; }
body.dark-mode .nav-link { color: #BDC3C7; }
body.dark-mode .nav-link:hover { background: #3D566E; }
body.dark-mode .nav-link.active { background: #1A2530; color: #5DADE2; }

/* Search bar */
body.dark-mode .search-bar { background: #2C3E50; border-color: #34495E; }

/* Alerts (keep readable) */
body.dark-mode .alert-success { background: #1E4D3D; color: #A9DFBF; border-color: #1ABC9C; }
body.dark-mode .alert-error { background: #4D1E1E; color: #F5B7B1; border-color: #E74C3C; }
body.dark-mode .alert-warning { background: #4D3D1E; color: #F8C471; border-color: #F39C12; }
body.dark-mode .alert-info { background: #1E3D4D; color: #AED6F1; border-color: #3498DB; }

/* Toast */
body.dark-mode .toast { background: #2C3E50; color: #ECF0F1; border-color: #34495E; }

/* Page Header */
body.dark-mode .page-header { background: transparent; border-color: #34495E; }

/* Empty states */
body.dark-mode .empty-state, body.dark-mode .empty { color: #7F8C8D; }

/* Theme toggle button */
.theme-toggle {
    background: rgba(255,255,255,0.15);
    color: white;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 4px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
}
.theme-toggle:hover { background: rgba(255,255,255,0.25); }



/* ═══════════════════════════════════════════════════════════
   🌙 Dark Mode - Override Strong (يتغلب على Bootstrap والـ CSS الأصلي)
   ═══════════════════════════════════════════════════════════ */
body.dark-mode { background: #1A1F25 !important; color: #ECF0F1 !important; }
body.dark-mode html, body.dark-mode .app-page { background: #1A1F25 !important; }

/* Layout */
body.dark-mode .app-sidebar { background: #2C3E50 !important; border-color: #34495E !important; }
body.dark-mode .app-main { background: #1A1F25 !important; }
body.dark-mode .app-footer { background: #1A2530 !important; }

/* الأيقونة */
body.dark-mode #theme-icon { color: #F39C12 !important; }

/* Cards & Panels */
body.dark-mode .card-stat,
body.dark-mode .summary-card,
body.dark-mode .data-table-wrapper,
body.dark-mode .modal-card,
body.dark-mode .pie-chart-wrapper,
body.dark-mode .bar-chart-wrapper,
body.dark-mode .toast,
body.dark-mode .home-hero {
    background: #2C3E50 !important;
    color: #ECF0F1 !important;
    border-color: #34495E !important;
}

/* Generic divs with hardcoded white */
body.dark-mode div[style*="background:white"],
body.dark-mode div[style*="background: white"],
body.dark-mode div[style*="background:#fff"],
body.dark-mode div[style*="background: #fff"] {
    background: #2C3E50 !important;
    color: #ECF0F1 !important;
}
body.dark-mode div[style*="background:#F8F9FA"],
body.dark-mode div[style*="background: #F8F9FA"],
body.dark-mode div[style*="background:#f8f9fa"] {
    background: #283747 !important;
}

/* Headings */
body.dark-mode h1, body.dark-mode h2, body.dark-mode h3,
body.dark-mode h4, body.dark-mode h5, body.dark-mode h6 { color: #ECF0F1 !important; }

/* Tables */
body.dark-mode .data-table { color: #ECF0F1 !important; background: #2C3E50 !important; }
body.dark-mode .data-table thead th { background: #1A2530 !important; color: #ECF0F1 !important; }
body.dark-mode .data-table tbody td { background: transparent !important; border-color: #34495E !important; color: #ECF0F1 !important; }
body.dark-mode .data-table tbody tr:nth-child(even) td { background: rgba(0,0,0,0.15) !important; }
body.dark-mode .data-table tbody tr:hover td { background: rgba(93, 173, 226, 0.15) !important; }

/* Forms */
body.dark-mode .form-control,
body.dark-mode select.form-control,
body.dark-mode textarea.form-control,
body.dark-mode input.form-control {
    background: #1A2530 !important;
    color: #ECF0F1 !important;
    border-color: #34495E !important;
}
body.dark-mode .form-control:focus { border-color: #5DADE2 !important; }
body.dark-mode .form-control::placeholder { color: #7F8C8D !important; }
body.dark-mode label { color: #BDC3C7 !important; }

/* NavMenu */
body.dark-mode .nav-group-btn { background: #34495E !important; color: #ECF0F1 !important; }
body.dark-mode .nav-group-btn:hover { background: #3D566E !important; }
body.dark-mode .nav-group.open .nav-group-btn { background: #5DADE2 !important; color: white !important; }
body.dark-mode .nav-link { color: #BDC3C7 !important; }
body.dark-mode .nav-link:hover { background: #3D566E !important; color: #ECF0F1 !important; }
body.dark-mode .nav-link.active { background: #1A2530 !important; color: #5DADE2 !important; }

/* Search bar */
body.dark-mode .search-bar { background: #2C3E50 !important; border-color: #34495E !important; color: #ECF0F1 !important; }

/* Page Header */
body.dark-mode .page-header { color: #ECF0F1 !important; }

/* Empty state */
body.dark-mode .empty-state, body.dark-mode .empty,
body.dark-mode .row-count { color: #95A5A6 !important; }

/* Alerts */
body.dark-mode .alert-success { background: #1E4D3D !important; color: #A9DFBF !important; border-color: #1ABC9C !important; }
body.dark-mode .alert-error, body.dark-mode .alert-danger { background: #4D1E1E !important; color: #F5B7B1 !important; border-color: #E74C3C !important; }
body.dark-mode .alert-warning { background: #4D3D1E !important; color: #F8C471 !important; border-color: #F39C12 !important; }
body.dark-mode .alert-info { background: #1E3D4D !important; color: #AED6F1 !important; border-color: #3498DB !important; }

/* Bootstrap overrides */
body.dark-mode .bg-light, body.dark-mode .bg-white { background: #2C3E50 !important; color: #ECF0F1 !important; }
body.dark-mode .text-dark { color: #ECF0F1 !important; }
body.dark-mode .text-muted { color: #95A5A6 !important; }
body.dark-mode .border { border-color: #34495E !important; }

/* Modal overlay */
body.dark-mode .modal-overlay { background: rgba(0,0,0,0.7) !important; }

/* Buttons - keep contrast */
body.dark-mode .btn-ghost {
    background: transparent !important;
    color: #ECF0F1 !important;
    border-color: #5DADE2 !important;
}
body.dark-mode .btn-ghost:hover { background: #34495E !important; }

/* Quick links */
body.dark-mode .quick-link {
    background: #2C3E50 !important;
    color: #ECF0F1 !important;
    border-color: #34495E !important;
}
body.dark-mode .quick-link:hover {
    background: #34495E !important;
    border-color: #5DADE2 !important;
}

/* Charts */
body.dark-mode .bar-track { background: #1A2530 !important; }
body.dark-mode .bar-label, body.dark-mode .pie-label { color: #ECF0F1 !important; }
body.dark-mode .bar-value, body.dark-mode .pie-value { color: white !important; text-shadow: 0 0 3px rgba(0,0,0,0.8) !important; }

/* Pagination */
body.dark-mode .page-btn { background: #2C3E50 !important; color: #ECF0F1 !important; border-color: #34495E !important; }
body.dark-mode .page-btn:hover:not(:disabled) { background: #34495E !important; }
body.dark-mode .page-btn.active { background: #5DADE2 !important; }
body.dark-mode .page-info { color: #95A5A6 !important; }



/* ═══════════════════════════════════════════════════════════
   🌙 Dark Mode - Fix لعناصر details/summary وغيرها
   ═══════════════════════════════════════════════════════════ */

/* details/summary (الأقسام القابلة للطي زي إعدادات التقرير) */
body.dark-mode details {
    background: #2C3E50 !important;
    color: #ECF0F1 !important;
    border-color: #34495E !important;
}
body.dark-mode summary {
    background: #34495E !important;
    color: #ECF0F1 !important;
    border-color: #1A2530 !important;
}
body.dark-mode summary:hover { background: #3D566E !important; }

/* أي div بيستخدم background فاتح ضمن inline style — coverage إضافي */
body.dark-mode div[style*="background:#fff3"],
body.dark-mode div[style*="background: #FCF3"],
body.dark-mode div[style*="background:#FCF3"] {
    background: #4D3D1E !important;
    color: #F8C471 !important;
}
body.dark-mode div[style*="background:#EBF5FB"],
body.dark-mode div[style*="background: #EBF5FB"] {
    background: #1E3D4D !important;
    color: #AED6F1 !important;
}
body.dark-mode div[style*="background:#FEF9E7"],
body.dark-mode div[style*="background: #FEF9E7"] {
    background: #4D3D1E !important;
    color: #F8C471 !important;
}
body.dark-mode div[style*="background:#FADBD8"],
body.dark-mode div[style*="background: #FADBD8"] {
    background: #4D1E1E !important;
    color: #F5B7B1 !important;
}
body.dark-mode div[style*="background:#D5F5E3"],
body.dark-mode div[style*="background: #D5F5E3"] {
    background: #1E4D3D !important;
    color: #A9DFBF !important;
}
body.dark-mode div[style*="background:#F8F9FA"],
body.dark-mode div[style*="background: #F8F9FA"],
body.dark-mode div[style*="background:#ECF0F1"],
body.dark-mode div[style*="background: #ECF0F1"] {
    background: #283747 !important;
    color: #ECF0F1 !important;
}

/* td الـ inline styles بـ background فاتح */
body.dark-mode td[style*="background:#F8F9FA"],
body.dark-mode td[style*="background: #F8F9FA"] {
    background: #283747 !important;
}

/* Small text and helper text */
body.dark-mode small,
body.dark-mode .small,
body.dark-mode span[style*="color:#7F8C8D"],
body.dark-mode div[style*="color:#7F8C8D"] {
    color: #95A5A6 !important;
}

/* بطاقات الـ stat-icon والـ stat-label */
body.dark-mode .stat-label { color: #BDC3C7 !important; }

/* Tabs و sub-headers في الإعدادات */
body.dark-mode .nav-subgroup-title { background: #34495E !important; color: #ECF0F1 !important; }
body.dark-mode .nav-subgroup-title:hover { background: #3D566E !important; }
body.dark-mode .nav-subgroup { border-color: #34495E !important; }

/* Code & pre */
body.dark-mode code, body.dark-mode pre {
    background: #1A2530 !important;
    color: #F39C12 !important;
    border-color: #34495E !important;
}

/* hr (separators) */
body.dark-mode hr { border-color: #34495E !important; }

/* a links inside content */
body.dark-mode .app-main a:not(.btn):not(.nav-link):not(.quick-link) {
    color: #5DADE2 !important;
}



/* ═══════════════════════════════════════════════════════════
   🌙 Dark Mode - Fix لـ table rows بـ inline styles
   ═══════════════════════════════════════════════════════════ */

/* Light green (مصاريف إدارية) */
body.dark-mode tr[style*="background:#D5F5E3"],
body.dark-mode tr[style*="background: #D5F5E3"] {
    background: #1E4D3D !important;
    color: #A9DFBF !important;
}
body.dark-mode tr[style*="background:#D5F5E3"] td,
body.dark-mode tr[style*="background: #D5F5E3"] td {
    background: #1E4D3D !important;
    color: #A9DFBF !important;
}

/* Light pink/red (يخصم:، فادبد8) */
body.dark-mode tr[style*="background:#FADBD8"],
body.dark-mode tr[style*="background: #FADBD8"] {
    background: #4D1E1E !important;
}
body.dark-mode tr[style*="background:#FADBD8"] td,
body.dark-mode tr[style*="background: #FADBD8"] td {
    background: #4D1E1E !important;
    color: #F5B7B1 !important;
}

/* Lighter pink (revenue deductions) */
body.dark-mode tr[style*="background:#FDEDEC"],
body.dark-mode tr[style*="background: #FDEDEC"] {
    background: #3D1818 !important;
}
body.dark-mode tr[style*="background:#FDEDEC"] td,
body.dark-mode tr[style*="background: #FDEDEC"] td {
    background: #3D1818 !important;
    color: #F5B7B1 !important;
}

/* Light blue (شركة/ملاك) */
body.dark-mode tr[style*="background:#EBF5FB"],
body.dark-mode tr[style*="background: #EBF5FB"] {
    background: #1E3D4D !important;
}
body.dark-mode tr[style*="background:#EBF5FB"] td,
body.dark-mode tr[style*="background: #EBF5FB"] td {
    background: #1E3D4D !important;
    color: #AED6F1 !important;
}

/* Light yellow (تحذيرات) */
body.dark-mode tr[style*="background:#FCF3CF"],
body.dark-mode tr[style*="background: #FCF3CF"] {
    background: #4D3D1E !important;
}
body.dark-mode tr[style*="background:#FCF3CF"] td,
body.dark-mode tr[style*="background: #FCF3CF"] td {
    background: #4D3D1E !important;
    color: #F8C471 !important;
}

/* Light gray (#DDEBF7 - أصول/حقوق ملكية sections) */
body.dark-mode tr[style*="background:#DDEBF7"],
body.dark-mode tr[style*="background: #DDEBF7"] {
    background: #1E3D4D !important;
}
body.dark-mode tr[style*="background:#DDEBF7"] td,
body.dark-mode tr[style*="background: #DDEBF7"] td {
    background: #1E3D4D !important;
    color: #AED6F1 !important;
}

/* Light green darker (#A9DFBF - إجمالي إيرادات) */
body.dark-mode tr[style*="background:#A9DFBF"],
body.dark-mode tr[style*="background: #A9DFBF"] {
    background: #1ABC9C !important;
}
body.dark-mode tr[style*="background:#A9DFBF"] td,
body.dark-mode tr[style*="background: #A9DFBF"] td {
    background: #1ABC9C !important;
    color: white !important;
}

/* Light red (#F1948A - إجمالي مصروفات) */
body.dark-mode tr[style*="background:#F1948A"],
body.dark-mode tr[style*="background: #F1948A"] {
    background: #C0392B !important;
}
body.dark-mode tr[style*="background:#F1948A"] td,
body.dark-mode tr[style*="background: #F1948A"] td {
    background: #C0392B !important;
    color: white !important;
}

/* Subheader bg #FFF3E0 (alt rows in tables) */
body.dark-mode tr[style*="background:#FFF3E0"] td,
body.dark-mode tr[style*="background: #FFF3E0"] td,
body.dark-mode td[style*="background:#FFF3E0"] {
    background: #4D3D1E !important;
    color: #F8C471 !important;
}

/* Generic: any tr with light hex background & inline color, force readable text */
body.dark-mode tr[style*="background:#"] td {
    color: inherit !important;
}

/* TD with بـ colspan و inline style — العناوين زي "يخصم:" */
body.dark-mode td[style*="text-align:right"][style*="font-weight:bold"] {
    color: #ECF0F1 !important;
}

/* ════════════════════════════════════════════════════
   Dark Mode للمكوّنات الجديدة (Global Search، Attachments، Sessions، Reminders)
   ════════════════════════════════════════════════════ */

/* Global Search */
body.dark-mode .gs-modal { background: #2C3E50 !important; color: #ECF0F1 !important; }
body.dark-mode .gs-input { color: #ECF0F1 !important; }
body.dark-mode .gs-input::placeholder { color: #7F8C8D !important; }
body.dark-mode .gs-input-wrapper { border-color: #34495E !important; }
body.dark-mode .gs-shortcut { background: #1A2530 !important; color: #BDC3C7 !important; }
body.dark-mode .gs-result:hover { background: #34495E !important; }
body.dark-mode .gs-result-title { color: #ECF0F1 !important; }
body.dark-mode .gs-group-header { background: #1A2530 !important; color: #BDC3C7 !important; }

/* CustomReport categories */
body.dark-mode .cr-category { background: #2C3E50 !important; border-color: #34495E !important; }
body.dark-mode .cr-pill { background: #34495E !important; color: #ECF0F1 !important; }
body.dark-mode .cr-pill:hover { background: #1A2530 !important; }
body.dark-mode .cr-pill.active { background: #196F3D !important; color: #D5F5E3 !important; border-color: #27AE60 !important; }
body.dark-mode .cr-quickfilter { background: #34495E !important; color: #ECF0F1 !important; }
body.dark-mode .cr-quickfilter:hover { background: #1A2530 !important; }
body.dark-mode .cr-quickfilter.active { background: #7D6608 !important; color: #FCF3CF !important; }
body.dark-mode .cr-counter-badge { background: #ECF0F1 !important; color: #2C3E50 !important; }

/* Modal overlay - dark backdrop with more contrast */
body.dark-mode .modal-overlay { background: rgba(0,0,0,0.75) !important; }

/* Hamburger button */
body.dark-mode .hamburger-btn { color: #ECF0F1 !important; }

/* Cards/tiles in portal-style displays (used in some pages) */
body.dark-mode .balance-tile.b-info { background: #1F4E79 !important; color: #D6EAF8 !important; }
body.dark-mode .balance-tile.b-good { background: #196F3D !important; color: #D5F5E3 !important; }
body.dark-mode .balance-tile.b-warn { background: #7D6608 !important; color: #FCF3CF !important; }
body.dark-mode .balance-tile.b-bad  { background: #922B21 !important; color: #FADBD8 !important; }

/* Status badges */
body.dark-mode .badge { color: #ECF0F1 !important; }

/* ════════════════════════════════════════════════════
   Empty States - تصميم موحّد للجداول الفاضية
   ════════════════════════════════════════════════════ */
.empty-state {
    text-align: center;
    padding: 50px 20px !important;
    color: #95A5A6;
    font-size: 14px;
    line-height: 1.7;
    background: linear-gradient(135deg, #FAFAFA 0%, #F0F2F5 100%);
    border-radius: 12px;
    border: 2px dashed #DDD;
    margin: 14px 0;
}
.empty-state::before {
    content: '📭';
    display: block;
    font-size: 48px;
    margin-bottom: 12px;
    opacity: 0.5;
}
/* لو فيه className يحدد أيقونة مخصصة، نستخدمها بدل الافتراضية */
.empty-state.empty-search::before { content: '🔍'; }
.empty-state.empty-add::before    { content: '➕'; }
.empty-state.empty-success::before{ content: '✅'; opacity: 0.7; }
.empty-state.empty-warning::before{ content: '⚠️'; opacity: 0.7; }
.empty-state td.empty { background: transparent !important; border: none !important; }

/* لو الـ empty-state داخل td (في tbody) - نزيل الـ background gradient */
table.data-table td.empty {
    text-align: center;
    padding: 40px 20px !important;
    color: #95A5A6;
    font-size: 14px;
    background: #FAFAFA !important;
    font-style: italic;
}
table.data-table td.empty::before {
    content: '📭 ';
    font-size: 22px;
}

body.dark-mode .empty-state {
    background: linear-gradient(135deg, #1A2530 0%, #283747 100%) !important;
    border-color: #34495E !important;
    color: #95A5A6 !important;
}
body.dark-mode table.data-table td.empty {
    background: #1A2530 !important;
}

