html, body {
    height: 100%;
    max-width: 100vw;
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
    background: #f5f7fb;
}

*, *::before, *::after {
    box-sizing: border-box;
}

body.app-body {
    background: #f5f7fb;
    color: #172033;
}

.app-wrapper,
.main-content,
.page-content,
.content-wrapper,
main {
    background: #f5f7fb;
}

.app-wrapper {
    display: flex;
    min-height: 100vh;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.page-content {
    flex: 1;
}

.footer {
    text-align: center;
    padding: 10px;
    font-size: 13px;
    color: #888;
}

.app-navbar {
    min-height: 64px;
    z-index: 1020;
    box-shadow: 0 0.35rem 1rem rgba(15, 23, 42, .04);
}

[dir="rtl"] .app-navbar {
    direction: rtl;
}

.navbar-brand {
    font-weight: 800;
    letter-spacing: -.02em;
    color: #0f172a;
}

/* Sidebar column as flex container so sidebar can stretch without affecting inner grids/forms */
.page-content > .container-fluid > .row > .col-lg-2.px-0 {
    display: flex;
    flex-direction: column;
    align-self: stretch;
}

.app-sidebar {
    min-height: 100vh;
    flex: 1;
    background: linear-gradient(180deg, #0f172a 0%, #111827 100%);
    color: #e5e7eb;
    box-shadow: 0.75rem 0 2rem rgba(15, 23, 42, .08);
}

.brand-box {
    color: #fff;
    font-weight: 800;
    font-size: 1.05rem;
}

.app-sidebar-nav .nav-link,
.app-sidebar-nav .nav-dropdown-toggle {
    width: 100%;
    border: 0;
    border-radius: .75rem;
    background: transparent;
    color: #cbd5e1;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: .65rem;
    padding: .7rem .85rem;
    text-align: inherit;
    transition: background-color .2s ease, color .2s ease, transform .2s ease;
}

.app-sidebar-nav .nav-link span,
.app-sidebar-nav .nav-dropdown-toggle span {
    display: inline-flex;
    align-items: center;
    gap: .65rem;
}

.app-sidebar-nav .nav-dropdown-toggle > i:last-child {
    margin-inline-start: auto;
}

.app-sidebar-nav .nav-link:hover,
.app-sidebar-nav .nav-dropdown-toggle:hover,
.app-sidebar-nav .nav-link.active,
.app-sidebar-nav .nav-dropdown-toggle.active {
    color: #fff;
    background: rgba(59, 130, 246, .22);
}

.app-sidebar-nav .nav-link.active {
    box-shadow: inset 3px 0 0 #60a5fa;
}

[dir="rtl"] .app-sidebar-nav .nav-link.active {
    box-shadow: inset -3px 0 0 #60a5fa;
}

.nav-group-label {
    color: #94a3b8;
    font-size: .72rem;
    font-weight: 800;
    letter-spacing: .08em;
    margin: 1rem .85rem .35rem;
    text-transform: uppercase;
}

.submenu {
    margin: .35rem 0 .35rem 1rem;
    padding-inline-start: .55rem;
    border-inline-start: 1px solid rgba(148, 163, 184, .25);
}

.submenu .nav-link {
    font-size: .92rem;
    padding: .55rem .75rem;
}

.content-wrapper { min-height: 100vh; }

.kpi-card,
.filter-card,
.section-card,
.card.border-0.shadow-sm {
    border: 0 !important;
    border-radius: 1rem;
    box-shadow: 0 .65rem 1.5rem rgba(15, 23, 42, .07) !important;
}

.kpi-card {
    height: 100%;
    min-height: 112px;
}

.kpi-card .card-body {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 112px;
}

.toolbar-actions,
main .d-flex.gap-2 {
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
}

.empty-state {
    padding: 2rem;
    text-align: center;
    color: #6c757d;
}

.table > :not(caption) > * > * {
    vertical-align: middle;
}

.dashboard-best-worst-card .card-body {
    padding-top: .9rem;
    padding-bottom: .9rem;
}

.trade-snapshot-card {
    min-height: 70px;
}

.trade-snapshot-card .fw-bold {
    font-size: .92rem;
    line-height: 1.25;
}

.sector-chart-box {
    height: 175px;
}

.chart-container {
    position: relative;
    width: 100%;
    height: 260px;
}

.sector-chart-box canvas {
    max-height: 100%;
}

.language-switcher .btn {
    font-weight: 700;
}

.dashboard-pdf-page {
    background: #f5f7fb;
}

.fund-dashboard-pdf-page {
    background: #f5f7fb;
}

.investment-committee-pdf-page {
    background: #f5f7fb;
}

.investment-committee-flow-report {
    background: #f5f7fb;
}

.ic-screen-report-header {
    display: flex;
    align-items: stretch;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
    overflow: hidden;
    border-radius: .9rem;
    background: #0b1f3a;
    color: #fff;
    box-shadow: 0 .65rem 1.5rem rgba(15, 23, 42, .08);
}

.ic-screen-report-header > div:first-child {
    padding: .85rem 1rem;
}

.ic-screen-report-header .pdf-report-meta {
    align-items: center;
    border-inline-start: 2px solid #d6b45f;
    background: rgba(255, 255, 255, .98);
}

.ic-action-group {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    flex-wrap: wrap;
}

.ic-action-group-nowrap {
    flex-wrap: nowrap;
    white-space: nowrap;
}

.ic-actions-col {
    min-width: 172px;
    width: 172px;
    white-space: nowrap;
}

.ic-action-form {
    display: inline-flex;
    margin: 0;
}

.ic-action-btn,
.ic-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    min-height: 38px;
    border-radius: .65rem !important;
    font-weight: 700;
    line-height: 1;
    white-space: nowrap;
}

.ic-action-btn {
    padding: .5rem .85rem;
}

.ic-action-btn-sm {
    min-height: 32px;
    padding: .38rem .6rem;
    font-size: .82rem;
}

.ic-icon-btn {
    width: 34px;
    height: 34px;
    min-height: 34px;
    padding: 0;
}

.ic-action-btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    min-width: 34px;
    min-height: 34px;
    padding: 0;
    border-radius: .65rem !important;
    line-height: 1;
}

.ic-action-btn i,
.ic-icon-btn i,
.ic-action-btn-icon i {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    line-height: 1;
}

.ic-action-btn-sm i {
    font-size: .92rem;
}

.allocation-total-badge {
    min-width: 110px;
    padding: .55rem .85rem;
    border-radius: 999px;
    background: #fee2e2;
    color: #991b1b;
    font-weight: 800;
    text-align: center;
}

.allocation-total-badge.is-valid {
    background: #dcfce7;
    color: #166534;
}

.allocation-total-badge.is-invalid {
    background: #fee2e2;
    color: #991b1b;
}

.institutional-report-hero {
    border-inline-start: 5px solid #d6b45f !important;
}

.ic-report-summary-card .card-body {
    padding: 1rem 1.15rem;
}

.ic-report-summary-main {
    flex: 1 1 560px;
    min-width: 0;
}

.ic-report-summary-main h2 {
    line-height: 1.15;
}

.ic-executive-summary-line {
    line-height: 1.45;
}

.ic-allocation-status-line {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: .65rem;
    min-height: 30px;
    padding-top: 1.35rem;
    white-space: nowrap;
}

.ic-allocation-status-line .badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: .35rem .55rem;
}

.ic-chart-box {
    height: 330px;
}

.section-title-navy {
    padding-bottom: .5rem;
    border-bottom: 2px solid #d6b45f;
    color: #0b1f3a;
    font-weight: 800;
}

.report-narrative {
    color: #344054;
    font-size: .98rem;
    line-height: 1.8;
    white-space: normal;
}

.pdf-report-header {
    display: none;
    margin-bottom: .9rem;
    overflow: hidden;
    border-radius: .75rem;
    background: #0b1f3a;
    color: #fff;
    box-shadow: 0 .65rem 1.5rem rgba(15, 23, 42, .08);
}

.pdf-report-header-main {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .65rem .85rem .5rem;
}

.pdf-system-name {
    color: #d6b45f;
    font-size: .72rem;
    font-weight: 800;
    letter-spacing: .08em;
    line-height: 1.1;
    text-transform: uppercase;
}

.pdf-report-title {
    margin-top: .12rem;
    font-size: 1.18rem;
    font-weight: 800;
    line-height: 1.1;
}

.pdf-page-number {
    flex: 0 0 auto;
    color: #e5e7eb;
    font-size: .82rem;
    font-weight: 700;
}

.pdf-gold-line {
    height: 2px;
    background: #d6b45f;
}

.pdf-report-meta {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: .5rem 1.25rem;
    padding: .45rem .85rem .55rem;
    background: #fff;
    color: #344054;
    font-size: .78rem;
}

.pdf-report-meta strong {
    color: #0f2a44;
}

.dashboard-pdf-page .card,
.dashboard-pdf-page .kpi-card,
.fund-dashboard-pdf-page .card,
.fund-dashboard-pdf-page .kpi-card,
.investment-committee-pdf-page .card {
    break-inside: avoid;
    page-break-inside: avoid;
}

.dashboard-pdf-loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(245, 247, 251, .82);
    backdrop-filter: blur(3px);
}

.dashboard-pdf-loading-card {
    min-width: 280px;
    max-width: 420px;
    padding: 2rem;
    border-radius: 1rem;
    background: #fff;
    box-shadow: 0 1rem 3rem rgba(15, 23, 42, .18);
}

body.dashboard-pdf-exporting .dashboard-pdf-page {
    background: #ffffff !important;
    box-sizing: border-box !important;
    padding: 0;
    transform: none !important;
    width: 100% !important;
    zoom: 1 !important;
}

body.dashboard-pdf-exporting .fund-dashboard-pdf-page {
    background: #ffffff !important;
    box-sizing: border-box !important;
    padding: 0;
    transform: none !important;
    width: 100% !important;
    zoom: 1 !important;
}

body.investment-committee-pdf-exporting .investment-committee-pdf-page {
    background: #ffffff !important;
    box-sizing: border-box !important;
    padding: 0;
    transform: none !important;
    width: 100% !important;
    zoom: 1 !important;
}

body.investment-committee-pdf-exporting .investment-committee-flow-report {
    background: #ffffff !important;
    box-sizing: border-box !important;
    padding: 0;
    transform: none !important;
    width: 100% !important;
    zoom: 1 !important;
}

body.dashboard-pdf-exporting,
body.dashboard-pdf-exporting .page-content,
body.dashboard-pdf-exporting main,
body.dashboard-pdf-exporting .dashboard-pdf-page .row,
body.dashboard-pdf-exporting .fund-dashboard-pdf-page .row,
body.investment-committee-pdf-exporting .investment-committee-pdf-page .row,
body.investment-committee-pdf-exporting .investment-committee-flow-report .row {
    background: #ffffff !important;
}

body.investment-committee-pdf-exporting .ic-screen-report-header {
    display: none !important;
}

body.investment-committee-pdf-exporting .investment-committee-pdf-page .card-body,
body.investment-committee-pdf-exporting .investment-committee-flow-report .card-body {
    padding: 1rem !important;
}

body.investment-committee-pdf-exporting .investment-committee-pdf-page .mb-4,
body.investment-committee-pdf-exporting .investment-committee-flow-report .mb-4 {
    margin-bottom: .95rem !important;
}

body.investment-committee-pdf-exporting .avoid-section-break {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
}

body.investment-committee-pdf-exporting .avoid-section-break .section-title-navy {
    break-after: avoid !important;
    page-break-after: avoid !important;
}

body.funds-dashboard-pdf-exporting .fund-dashboard-pdf-page .card-body {
    padding: .85rem !important;
}

body.funds-dashboard-pdf-exporting .fund-dashboard-pdf-page .row.g-3 {
    --bs-gutter-y: .7rem;
}

body.funds-dashboard-pdf-exporting .fund-dashboard-pdf-page .mb-4 {
    margin-bottom: .8rem !important;
}

body.funds-dashboard-pdf-exporting #fund-pdf-page-3,
body.funds-dashboard-pdf-exporting #fund-pdf-page-4 {
    font-size: .88rem;
}

body.funds-dashboard-pdf-exporting .fund-dashboard-pdf-page .table > :not(caption) > * > * {
    padding: .35rem .45rem;
}

body.dashboard-pdf-exporting #pdf-page-2 .row.g-3 {
    --bs-gutter-y: .65rem;
}

body.dashboard-pdf-exporting #pdf-page-2 .mb-4 {
    margin-bottom: .75rem !important;
}

body.dashboard-pdf-exporting #pdf-page-2 .card-body {
    padding: .85rem !important;
}

body.dashboard-pdf-exporting #pdf-page-2 canvas {
    max-height: 100% !important;
}

body.dashboard-pdf-exporting .pdf-report-header {
    display: block;
}

body.investment-committee-pdf-exporting .pdf-report-header {
    display: block;
}

body.dashboard-pdf-exporting .dashboard-pdf-page .table-responsive {
    overflow: visible !important;
}

body.dashboard-pdf-exporting .fund-dashboard-pdf-page .table-responsive {
    overflow: visible !important;
}

body.investment-committee-pdf-exporting .investment-committee-pdf-page .table-responsive {
    overflow: visible !important;
}

body.investment-committee-pdf-exporting .investment-committee-flow-report .table-responsive {
    overflow: visible !important;
}

body.dashboard-pdf-exporting .dashboard-pdf-page canvas {
    max-width: 100% !important;
}

body.dashboard-pdf-exporting .fund-dashboard-pdf-page canvas {
    max-width: 100% !important;
}

body.investment-committee-pdf-exporting .investment-committee-pdf-page canvas {
    max-width: 100% !important;
}

body.investment-committee-pdf-exporting .investment-committee-flow-report canvas {
    max-width: 100% !important;
}

.mobile-sidebar {
    max-width: 320px;
}

/* ========================================
   RESPONSIVE FIXES FOR MOBILE
   ======================================== */

/* Prevent horizontal overflow globally */
.container-fluid,
.container {
    max-width: 100vw;
}

/* Ensure media elements never overflow */
img, svg, video, canvas, iframe {
    max-width: 100%;
    height: auto;
}

/* Keep the app shell flexible, but let page grids/cards size naturally to their content */
.page-content {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.page-content > .container-fluid {
    width: 100%;
}

/* Desktop: ensure sidebar column stretches full height */
@media (min-width: 992px) {
    .page-content > .container-fluid > .row > .col-lg-2.px-0 {
        display: flex;
        flex-direction: column;
        align-self: stretch;
        min-height: 100vh;
    }

    .app-sidebar {
        min-height: 100vh;
        height: 100%;
        flex: 1;
    }
}

/* Cards always readable */
.kpi-card {
    min-height: auto;
}

.kpi-card .card-body {
    min-height: auto;
    padding: 1rem;
}

/* Table responsive inside card only */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Touch-friendly tap targets */
.btn,
.nav-link,
.page-link,
.dropdown-item,
.form-check-input,
.form-control,
.form-select {
    min-height: 44px;
}

.btn-sm,
.btn-group-sm > .btn {
    min-height: 36px;
}

/* Stat values responsive */
.stat-value {
    font-size: clamp(1.1rem, 3vw, 1.75rem);
    font-weight: 700;
}

.stat-label {
    font-size: clamp(0.72rem, 2vw, 0.875rem);
}

/* Reduce chart height on small screens */
@media (max-width: 575.98px) {
    .chart-container {
        height: 200px;
    }
    .sector-chart-box {
        height: 160px;
    }
    .ic-chart-box {
        height: 220px;
    }
}

@media (max-width: 767.98px) {
    .chart-container {
        height: 220px;
    }
    .ic-chart-box {
        height: 260px;
    }
}

@media (min-width: 992px) {
    .app-sidebar {
        position: sticky;
        top: 0;
        overflow-y: auto;
    }
}

@media (max-width: 991.98px) {
    .content-wrapper {
        width: 100%;
    }

    main.p-4 {
        padding: 1rem !important;
    }

    .navbar-brand {
        font-size: .95rem;
        max-width: 52vw;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    main > .d-flex.justify-content-between {
        align-items: flex-start !important;
        flex-direction: column;
        gap: 1rem;
    }

    .kpi-card .card-body {
        padding: .75rem;
    }

    .table {
        font-size: .85rem;
    }
}

@media (max-width: 575.98px) {
    .app-navbar {
        padding-left: .5rem !important;
        padding-right: .5rem !important;
    }

    .language-switcher .btn {
        padding-left: .45rem;
        padding-right: .45rem;
    }

    h1, .h1 {
        font-size: 1.5rem;
    }
    h2, .h2 {
        font-size: 1.25rem;
    }
    h3, .h3 {
        font-size: 1.1rem;
    }
    h4, .h4 {
        font-size: 1rem;
    }

    .card {
        margin-bottom: .75rem;
    }
    .card-body {
        padding: .75rem;
    }

    .container-fluid {
        padding-left: .5rem;
        padding-right: .5rem;
    }

    .row > [class*="col-"] {
        padding-left: .375rem;
        padding-right: .375rem;
    }

    .btn {
        font-size: .85rem;
    }

    .table {
        font-size: .8rem;
    }

    .trade-snapshot-card .fw-bold {
        font-size: .85rem;
    }

    .kpi-card .card-body {
        padding: .65rem;
    }

    .stat-value {
        font-size: clamp(1rem, 4vw, 1.3rem);
    }
    .stat-label {
        font-size: clamp(0.68rem, 2.5vw, 0.78rem);
    }
}

/* ========================================
   iOS SAFE-AREA SUPPORT (PWA STANDALONE)
   ======================================== */

@supports (padding: max(0px)) {
    @media (display-mode: standalone) {
        html,
        body,
        body.app-body,
        .app-wrapper,
        .main-content,
        .page-content,
        .content-wrapper,
        main {
            background: #f5f7fb !important;
        }

        /* Navbar: push content below status bar / notch */
        .app-navbar {
            padding-top: max(0.75rem, env(safe-area-inset-top)) !important;
            padding-left: max(0.75rem, env(safe-area-inset-left)) !important;
            padding-right: max(0.75rem, env(safe-area-inset-right)) !important;
            background: #ffffff !important;
        }

        /* Page content respects left/right safe areas */
        .page-content {
            padding-left: env(safe-area-inset-left);
            padding-right: env(safe-area-inset-right);
            background: #f5f7fb !important;
        }

        /* Mobile sidebar header clear of notch */
        .mobile-sidebar .offcanvas-header {
            padding-top: max(1rem, env(safe-area-inset-top));
            padding-left: max(1rem, env(safe-area-inset-left));
            padding-right: max(1rem, env(safe-area-inset-right));
        }

        /* Mobile sidebar body clear of edges */
        .mobile-sidebar .offcanvas-body {
            padding-left: max(1rem, env(safe-area-inset-left));
            padding-right: max(1rem, env(safe-area-inset-right));
            padding-bottom: env(safe-area-inset-bottom);
        }

        /* Footer clear of home indicator */
        .footer {
            padding-bottom: max(10px, env(safe-area-inset-bottom));
            padding-left: env(safe-area-inset-left);
            padding-right: env(safe-area-inset-right);
            background: #f5f7fb;
        }
    }
}

/* iOS-specific: keep standalone PWA surface aligned with the light app UI */
@supports (-webkit-touch-callout: none) {
    @media (display-mode: standalone) {
        /* Keep body light; safe-area spacing is handled above without a dark filler */
        body.app-body {
            background: #f5f7fb;
        }

        .app-navbar {
            background: rgba(255, 255, 255, 0.98) !important;
            -webkit-backdrop-filter: blur(8px);
            backdrop-filter: blur(8px);
        }
    }
}
