@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;500;600;700;800&display=swap');

:root {
    --vivo-primary: #0f59c9;
    --vivo-body-bg: #F3F2F7;
    --vivo-card-bg: #ffffff;
    --vivo-text: #13181e;
    --vivo-muted: #6c7788;
    --vivo-border: #eaedf3;
    --vivo-success: #149865;
    --vivo-danger: #EB3333;
    --vivo-warning: #dda50e;
}

html {
    overflow-y: scroll;
    scrollbar-gutter: stable;
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Cairo', sans-serif !important;
    background-color: var(--vivo-body-bg);
    color: var(--vivo-text);
    direction: rtl;
    text-align: right;
    margin: 0;
    padding: 0;
    overflow-x: hidden;
}

/* Page Layout according to Vivo Admin specification */
.page-wrapper {
    padding: 0;
    position: relative;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    flex: 1 0 auto;
    background-color: var(--vivo-body-bg);
}

/* Sidebar - Vivo curved aesthetic in RTL - 100% Fixed Width */
.sidebar-wrapper {
    width: 220px;
    min-width: 220px;
    max-width: 220px;
    flex-shrink: 0;
    height: calc(100vh - 20px);
    position: fixed;
    top: 10px;
    right: 10px;
    left: auto;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.04);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    border: 1px solid rgba(0, 0, 0, 0.06);
    transition: width 0.28s cubic-bezier(0.4, 0, 0.2, 1), 
                min-width 0.28s cubic-bezier(0.4, 0, 0.2, 1), 
                max-width 0.28s cubic-bezier(0.4, 0, 0.2, 1) !important;
}

@media (min-width: 992px) {
    body.sidebar-minimized .sidebar-wrapper {
        width: 68px !important;
        min-width: 68px !important;
        max-width: 68px !important;
    }

    body.sidebar-minimized .main-container {
        padding-right: 84px !important;
    }
}

.sidebar-brand {
    padding: 24px 16px 20px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    border-bottom: 1px solid #f0f0f5;
    width: 100%;
}

.sidebar-brand .brand-title {
    font-weight: 900;
    font-size: 1.3rem;
    color: var(--vivo-primary);
    margin: 0 0 8px 0;
    line-height: 1.3;
}

.sidebar-brand .brand-subtitle {
    font-size: 0.8rem;
    color: #6b7280;
    margin: 0;
    font-weight: 700;
    line-height: 1.4;
    letter-spacing: 0.2px;
}

.sidebar-menu {
    flex: 1;
    overflow-y: auto;
    padding: 20px 12px;
}

.sidebar-menu ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar-menu li a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 12px;
    color: #4b5563;
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 700;
    transition: all 0.2s ease;
}

.sidebar-menu li.active a {
    background: linear-gradient(135deg, #0f59c9 0%, #1e6beb 100%);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(15, 89, 201, 0.25);
}

.sidebar-menu li.active a i {
    color: #ffffff;
}

/* Main Container */
.main-container {
    padding-right: 245px;
    padding-left: 10px;
    padding-top: 5px;
    padding-bottom: 75px;
    width: 100%;
}

/* Page Header */
.page-header {
    background: #ffffff;
    border-radius: 14px;
    padding: 16px 24px;
    margin-bottom: 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.03);
    border: 1px solid var(--vivo-border);
}

.page-header h1 {
    font-size: 1.3rem;
    font-weight: 800;
    color: #111827;
    margin: 0;
}

.page-header p {
    font-size: 0.82rem;
    color: var(--vivo-muted);
    margin: 0;
}

/* Table Card */
.card-vivo {
    background: #ffffff;
    border-radius: 14px;
    border: 1px solid var(--vivo-border);
    box-shadow: 0 2px 14px rgba(0, 0, 0, 0.03);
    overflow: hidden;
}

.card-vivo .card-header {
    background: #ffffff;
    border-bottom: 1px solid #f0f2f7;
    padding: 16px 22px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-vivo .card-header .card-title {
    font-size: 1.05rem;
    font-weight: 800;
    color: #111827;
    margin: 0;
}

/* Scrollable Table Container */
.table-scroll-container {
    overflow-x: auto;
    width: 100%;
    max-height: calc(100vh - 220px);
    position: relative;
}

/* Data Table */
.residents-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.85rem;
}

.residents-table th {
    background-color: #f8fafc;
    color: #374151;
    font-weight: 800;
    padding: 12px 14px;
    border-bottom: 2px solid #e5e7eb;
    border-left: 1px solid #f1f3f8;
    white-space: nowrap;
    text-align: center;
    position: sticky;
    top: 0;
    z-index: 10;
    min-width: 90px;
}

.residents-table th:nth-child(1) { min-width: 145px; } /* الرقم التعريفي */
.residents-table th:nth-child(2) { min-width: 110px; } /* الاسم الأول */
.residents-table th:nth-child(3) { min-width: 110px; } /* الاسم الثاني */
.residents-table th:nth-child(4) { min-width: 85px; }  /* رقم العمارة */
.residents-table th:nth-child(5) { min-width: 85px; }  /* رقم الشقة */
.residents-table th:nth-child(6) { min-width: 115px; } /* هاتف أول */
.residents-table th:nth-child(7) { min-width: 115px; } /* هاتف ثاني */
.residents-table th:nth-child(8) { min-width: 95px; }  /* داخلي/خارجي */
.residents-table th:nth-child(9) { min-width: 110px; } /* حالة التشطيب */
.residents-table th:nth-child(10) { min-width: 120px; } /* تاريخ بداية الحساب */
.residents-table th:nth-child(11) { min-width: 110px; } /* أحدث ميزانية */
.residents-table th:nth-child(12) { min-width: 100px; } /* مصاريف التأسيس */
.residents-table th:nth-child(13) { min-width: 100px; } /* الشهرية الحالية */
.residents-table th:nth-child(14) { min-width: 120px; } /* المتأخرات */

.residents-table td {
    padding: 10px 14px;
    border-bottom: 1px solid #f1f3f8;
    border-left: 1px solid #f1f3f8;
    white-space: nowrap;
    text-align: center;
    vertical-align: middle;
    background: #ffffff;
}

.residents-table tbody tr:hover td {
    background-color: #f8fbff;
}

/* Month Columns Header Highlight */
.residents-table th.month-header {
    background-color: #eef4ff;
    color: #1e40af;
    min-width: 95px;
    font-size: 0.8rem;
    font-weight: 700;
}

/* Sticky Key Columns (الرقم التعريفي، الاسم، الوحدة) */
.residents-table .col-sticky-1 {
    position: sticky;
    right: 0;
    z-index: 5;
    background: #ffffff !important;
    box-shadow: -2px 0 6px rgba(0, 0, 0, 0.04);
}

.residents-table .col-sticky-2 {
    position: sticky;
    right: 125px;
    z-index: 5;
    background: #ffffff !important;
}

.residents-table th.col-sticky-1,
.residents-table th.col-sticky-2 {
    z-index: 15;
    background: #f8fafc !important;
}

/* Badges */
.badge-code {
    background-color: #eff6ff;
    color: #1d4ed8;
    border: 1px solid #bfdbfe;
    font-family: monospace;
    font-size: 0.82rem;
    font-weight: 700;
    padding: 4px 8px;
    border-radius: 6px;
    display: inline-block;
}

.badge-paid {
    background-color: #ecfdf5;
    color: #065f46;
    border: 1px solid #a7f3d0;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 0.8rem;
}

.badge-unpaid {
    background-color: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 0.8rem;
}

.badge-partial {
    background-color: #fef08a !important;
    color: #78350f !important;
    border: 1.5px solid #eab308 !important;
    font-weight: 800 !important;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 0.8rem;
}

.badge-clean {
    background-color: #dcfce7;
    color: #15803d;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 6px;
}

.badge-debt {
    background-color: #fee2e2;
    color: #b91c1c;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 6px;
}

/* ========================================================
   WORLD-CLASS RESPONSIVE MOBILE OPTIMIZATION
   ======================================================== */
@media (max-width: 991.98px) {
    /* Prevent page-level horizontal scroll */
    html, body, .page-wrapper {
        overflow-x: hidden !important;
        width: 100% !important;
        max-width: 100vw !important;
        position: relative;
    }

    /* Mobile Topbar */
    .mobile-topbar {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 56px;
        background: #ffffff;
        border-bottom: 1px solid #e2e8f0;
        z-index: 1030;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 14px;
        box-shadow: 0 2px 10px rgba(15, 23, 42, 0.05);
    }

    .mobile-menu-btn {
        background: none;
        border: none;
        padding: 4px;
        color: #0f59c9;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
    }

    .mobile-brand-link {
        font-weight: 800;
        color: #0f172a;
        font-size: 0.95rem;
    }

    .mobile-brand-logo {
        width: 32px;
        height: 32px;
        border-radius: 50%;
        border: 1.5px solid #0f59c9;
        object-fit: cover;
    }

    .mobile-brand-title {
        color: #0f172a;
        font-weight: 800;
        font-size: 0.92rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 180px;
    }

    /* Backdrop Overlay */
    .sidebar-mobile-backdrop {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(15, 23, 42, 0.6);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
        z-index: 1040;
        display: none;
        opacity: 0;
        transition: opacity 0.25s ease;
    }

    .sidebar-mobile-backdrop.show {
        display: block !important;
        opacity: 1 !important;
    }

    /* Sidebar Drawer on Mobile - 100% Off-screen until opened */
    #sidebarWrapper, .sidebar-wrapper {
        position: fixed !important;
        top: 0 !important;
        bottom: 0 !important;
        right: 0 !important;
        width: 280px !important;
        min-width: 280px !important;
        max-width: 85vw !important;
        height: 100vh !important;
        transform: translateX(110%) !important;
        visibility: hidden !important;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.3s ease !important;
        background: #ffffff !important;
        border-radius: 0 !important;
        border: none !important;
        border-left: 1px solid #e2e8f0 !important;
        z-index: 1050 !important;
        box-shadow: -5px 0 30px rgba(0, 0, 0, 0.25) !important;
        display: flex !important;
        flex-direction: column !important;
        overflow-y: auto !important;
    }

    #sidebarWrapper.mobile-open, .sidebar-wrapper.mobile-open {
        transform: translateX(0) !important;
        visibility: visible !important;
    }

    /* Hide Desktop Toggle Pin Button on Mobile */
    .sidebar-toggle-pin {
        display: none !important;
    }

    /* Mobile Close (X) Button inside Sidebar */
    .sidebar-mobile-close {
        position: absolute;
        top: 14px;
        left: 14px;
        z-index: 10;
        font-size: 0.85rem;
    }

    /* On mobile, sidebar always displays full brand in drawer */
    body.sidebar-minimized .sidebar-wrapper {
        width: 280px !important;
        min-width: 280px !important;
        max-width: 85vw !important;
    }

    body.sidebar-minimized .sidebar-logo-full {
        display: block !important;
    }

    body.sidebar-minimized .sidebar-logo-mini {
        display: none !important;
    }

    body.sidebar-minimized .sidebar-menu li a > span {
        display: inline-block !important;
    }

    body.sidebar-minimized .sidebar-menu li a::after {
        display: none !important;
    }

    body.sidebar-minimized .sidebar-menu li a .submenu-caret {
        display: inline-block !important;
    }

    body.sidebar-minimized .sidebar-child-menu {
        position: static !important;
        width: 100% !important;
        box-shadow: none !important;
        border: none !important;
        background: #f8fafc !important;
    }

    body.sidebar-minimized .sidebar-user-pill .overflow-hidden,
    body.sidebar-minimized .sidebar-user-pill .pt-1\.5 {
        display: block !important;
    }

    /* Main Container on Mobile: 100% width, no obstruction */
    .page-wrapper {
        padding-right: 0 !important;
        margin-right: 0 !important;
        width: 100% !important;
        max-width: 100vw !important;
    }

    .main-container {
        padding-right: 12px !important;
        padding-left: 12px !important;
        padding-top: 68px !important;
        padding-bottom: 0 !important;
        margin-right: 0 !important;
        margin-left: 0 !important;
        width: 100% !important;
        max-width: 100vw !important;
        min-height: 100vh !important;
        display: flex !important;
        flex-direction: column !important;
        flex: 1 0 auto !important;
        overflow-x: hidden !important;
    }

    body.sidebar-minimized .main-container {
        padding-right: 12px !important;
        margin-right: 0 !important;
    }

    /* Mobile Footer: sticky bottom */
    .app-site-footer {
        position: relative !important;
        right: auto !important;
        left: auto !important;
        bottom: auto !important;
        margin-top: auto !important;
        width: 100% !important;
        flex-shrink: 0 !important;
        padding: 12px 14px !important;
        border-top: 1px solid #e2e8f0 !important;
        background: #ffffff !important;
        box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.03) !important;
    }

    .designer-pill {
        padding: 4px 14px !important;
        font-size: 0.75rem !important;
    }

    /* Responsive Cards & Padding */
    .card {
        border-radius: 12px !important;
        margin-bottom: 14px !important;
    }

    .card-body {
        padding: 14px !important;
    }

    /* Responsive Tables with Smooth Touch Scroll */
    .table-responsive {
        -webkit-overflow-scrolling: touch !important;
        border-radius: 10px !important;
        overflow-x: auto !important;
        max-width: 100% !important;
        margin-bottom: 12px !important;
    }

    /* Responsive Headers and Buttons */
    .page-header-title {
        font-size: 1.25rem !important;
    }
}

/* Extra Mobile Fine-tuning (< 576px) */
@media (max-width: 575.98px) {
    .main-container {
        padding-right: 10px !important;
        padding-left: 10px !important;
        padding-top: 72px !important;
    }

    /* Page headers on mobile */
    .page-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 12px !important;
        margin-bottom: 16px !important;
    }
    .page-header > div:last-child {
        width: 100% !important;
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 8px !important;
    }

    /* KPI Grid on Small Screens */
    .row.g-3 > [class*="col-"] {
        margin-bottom: 8px !important;
    }

    /* Modals on Small Screens */
    .modal-dialog {
        margin: 10px !important;
        max-width: calc(100% - 20px) !important;
    }

    .modal-content {
        border-radius: 14px !important;
    }

    /* Table responsive touch smooth scroll */
    .table-responsive {
        -webkit-overflow-scrolling: touch !important;
        border-radius: 10px !important;
    }
}

/* ========================================================
   HIGH-END APP-LIKE MOBILE RESPONSIVE SUITE
   ======================================================== */
@media (max-width: 991.98px) {
    /* Prevent body side-scrolling */
    html, body {
        overflow-x: hidden !important;
        position: relative !important;
        width: 100% !important;
        max-width: 100vw !important;
    }

    .page-wrapper {
        overflow-x: hidden !important;
        width: 100% !important;
        max-width: 100vw !important;
    }

    .main-container {
        padding-top: 74px !important;
        padding-right: 12px !important;
        padding-left: 12px !important;
        padding-bottom: 24px !important;
        width: 100% !important;
        max-width: 100vw !important;
        overflow-x: hidden !important;
    }

    /* Page Header on Mobile */
    .page-header {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 12px !important;
        margin-bottom: 16px !important;
        padding: 0 4px !important;
    }
    .page-header > div:last-child {
        width: 100% !important;
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 8px !important;
    }
    .page-header > div:last-child .btn {
        flex: 1 1 auto !important;
        justify-content: center !important;
    }

    /* Smooth, Touch-Friendly Responsive Tables */
    .table-responsive {
        -webkit-overflow-scrolling: touch !important;
        border-radius: 12px !important;
        margin-bottom: 0 !important;
    }
    .table-responsive table th, 
    .table-responsive table td {
        white-space: nowrap !important;
        padding: 10px 12px !important;
    }

    /* Cards on Mobile */
    .card, .card-vivo {
        border-radius: 14px !important;
        margin-bottom: 16px !important;
    }
    .card-header, .card-vivo .card-header {
        padding: 14px 16px !important;
    }
    .card-body, .card-vivo .card-body {
        padding: 14px !important;
    }

    /* Form Inputs on Mobile */
    .form-control, .form-select {
        font-size: 0.9rem !important;
        border-radius: 10px !important;
    }

    /* Modal dialogs */
    .modal-dialog {
        margin: 12px auto !important;
        max-width: calc(100vw - 24px) !important;
    }
    .modal-content {
        border-radius: 16px !important;
    }
}

/* Sticky Footer - Always pinned at bottom across all screens */
@media (min-width: 992px) {
    .mobile-topbar, .sidebar-mobile-backdrop, .sidebar-mobile-close {
        display: none !important;
    }
}

.app-site-footer {
    position: relative !important;
    margin-top: auto !important;
    width: 100% !important;
    flex-shrink: 0 !important;
    bottom: auto !important;
    left: auto !important;
    right: auto !important;
    padding: 12px 24px !important;
    background: #ffffff !important;
    border-top: 1px solid #e2e8f0 !important;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.02) !important;
    z-index: 10 !important;
}

.designer-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 50px;
    padding: 6px 22px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    font-size: 0.82rem;
    color: #4b5563;
    transition: all 0.2s ease;
}

.designer-pill:hover {
    border-color: #0f59c9;
    box-shadow: 0 4px 12px rgba(15, 89, 201, 0.1);
}

.designer-brand-text {
    font-weight: 800;
    color: #0f59c9;
    letter-spacing: 0.3px;
}

/* ==============================================================================
   ZERO WHITE-ON-WHITE / ULTRA-HIGH CONTRAST ENFORCEMENT RULES (حظر الأبيض على الأبيض نهائياً)
   ============================================================================== */

/* 1. All text-muted and text-secondary must be dark, clear slate instead of pale washed out gray */
.text-muted {
    color: #334155 !important; /* Dark Slate Gray instead of pale #6c757d */
}
.text-secondary {
    color: #1e293b !important;
}

/* 2. Table Headers must always have dark, bold, sharp text */
thead.table-light,
thead.table-light th,
thead.table-light tr th,
.table-light th,
.table-light td {
    color: #0f172a !important;
    font-weight: 700 !important;
}

/* 3. Badges on any light, warning, secondary, or subtle backgrounds MUST NEVER BE WHITE */
.badge {
    --bs-badge-color: #0f172a;
    font-weight: 700;
}

.badge.bg-warning,
.badge.bg-warning-subtle,
.badge.text-warning,
.bg-warning-subtle {
    color: #78350f !important; /* Rich Dark Amber */
    background-color: #fef08a !important;
    border: 1.5px solid #eab308 !important;
    font-weight: 800 !important;
}

.badge.bg-secondary,
.badge.bg-secondary-subtle,
.badge.text-secondary {
    color: #0f172a !important;
    background-color: #e2e8f0 !important;
    border: 1px solid #cbd5e1 !important;
    font-weight: 700 !important;
}

.badge.bg-light,
.badge.bg-white {
    color: #0f172a !important;
    background-color: #f1f5f9 !important;
    border: 1px solid #cbd5e1 !important;
    font-weight: 700 !important;
}

.badge.bg-info-subtle,
.badge.text-info {
    color: #0369a1 !important;
    background-color: #e0f2fe !important;
    border: 1px solid #7dd3fc !important;
    font-weight: 700 !important;
}

.badge.bg-success-subtle,
.badge.text-success {
    color: #065f46 !important;
    background-color: #d1fae5 !important;
    border: 1px solid #6ee7b7 !important;
    font-weight: 700 !important;
}

.badge.bg-danger-subtle,
.badge.text-danger {
    color: #991b1b !important;
    background-color: #fee2e2 !important;
    border: 1px solid #fca5a5 !important;
    font-weight: 700 !important;
}

/* 4. Strict prohibition: No text-white inside light containers */
.bg-light .text-white,
.bg-white .text-white,
.bg-warning-subtle .text-white,
.card:not(.bg-primary):not(.bg-dark):not(.bg-danger) .text-white:not(.btn):not(.badge-dark) {
    color: #0f172a !important;
}

/* 5. Monospace numbers & codes inside tables & cards must be dark and sharp */
.font-monospace {
    color: #0f172a;
    font-weight: 700;
}

code {
    color: #0f172a !important;
    background-color: #f1f5f9 !important;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
}
