/* ============================================
   Responsive Internal App Shell
   ============================================
   Makes the LeptonX "side-menu" layout responsive down to ~375px.
   Mirrors the PortalLayout approach: sticky top bar, hamburger toggle,
   user area collapsing, and content that fills available width.

   Breakpoint key (shared with Bootstrap):
     375px  – narrow phone baseline
     576px  – sm
     768px  – md  (LeptonX sidebar collapses natively here)
     992px  – lg
     1200px – xl
     1400px – xxl

   LeptonX already hides the sidebar at < 992px and shows a hamburger.
   These rules refine the topbar, user area, and content at smaller sizes.
   ======================================== */

/* ── Top Bar ── */

/* Ensure top bar items don't overflow at narrow widths */
.lpx-topbar {
    min-height: 56px;
    flex-wrap: nowrap;
    gap: 0.25rem;
}

.mobile-app-header {
    display: none;
    position: sticky;
    top: 0;
    z-index: 99;
    min-height: 56px;
    padding: 0.375rem 1rem;
    align-items: center;
    justify-content: space-between;
    background: #0b0b0c;
    border-bottom: 2px solid #d85b0a;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
}

.mobile-app-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
}

.mobile-app-header img {
    height: 34px;
    object-fit: contain;
}

.mobile-app-title {
    color: #fff;
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}
.table-responsive {
    min-height:100px !important;
}
.custom-card-spacing {
    padding: 0.5rem !important;
}

@media (min-width: 768px) {
    .custom-card-spacing {
        padding: 1rem !important;
    }
}

@media (max-width: 767.98px) {
    .lpx-topbar-container {
        display: none !important;
    }

    .mobile-app-header {
        display: flex !important;
    }
}

/* ── Mobile bottom-bar controls: make them "clickable" for iOS ── */

/* The Menu, Settings and Profile tabs render as <a> with no href; Blazor handles their
   @onclick through one delegated listener. iOS Safari only dispatches a click to a delegated
   listener from an element it considers clickable, and an href-less <a> with the default
   `cursor: auto` is not one - so on iPhones those tabs (including the one that opens the whole
   menu) did nothing. `cursor: pointer` is the signal iOS looks for. Desktop never showed the
   problem, which is why it went unnoticed. The pointer cursor is also correct on desktop. */
.lpx-mobile-nav-tab > a,
.lpx-mobile-nav-item {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* ── Hamburger / Toggle Button ── */

/* Ensure the hamburger button is always a comfortable tap target */
.lpx-nav-toggler,
.lpx-sidebar-toggler,
button[data-bs-toggle="offcanvas"],
.lpx-topbar .bi-list,
.lpx-topbar [class*="hamburger"] {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

@media (max-width: 767.98px) {
    /* LeptonX defaults the opened phone menu to full-screen. */
    .lpx-mobile-menu {
        left: 0 !important;
        right: 28vw !important;
        width: 72vw !important;
        min-width: 0 !important;
        max-width: 72vw !important;
        overflow-x: hidden !important;
        border-radius: 0 !important;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.35) !important;
    }

    [dir="rtl"] .lpx-mobile-menu {
        left: 28vw !important;
        right: 0 !important;
        border-radius: 0 !important;
        box-shadow: -4px 0 20px rgba(0, 0, 0, 0.35) !important;
    }

    /* Move LeptonX's real menu toggle into the custom header. */
    .lpx-mobile-nav-tab-container
    .lpx-mobile-nav-tabs
    .lpx-mobile-nav-tab:has(.lpx-mobile-hamburger) {
        position: fixed !important;
        top: 0.375rem !important;
        right: 1rem !important;
        bottom: auto !important;
        left: auto !important;
        z-index: 1001;
        width: 44px !important;
        height: 44px !important;
        min-width: 44px !important;
        margin: 0 !important;
        padding: 0 !important;
        background: transparent !important;
    }

    .lpx-mobile-nav-tab:has(.lpx-mobile-hamburger) a {
        display: flex !important;
        width: 44px;
        height: 44px;
        align-items: center;
        justify-content: center;
        color: #fff !important;
    }

    .lpx-mobile-nav-tab:has(.lpx-mobile-hamburger) a:hover,
    .lpx-mobile-nav-tab:has(.lpx-mobile-hamburger)
    a.lpx-mobile-menu-toggle-open {
        color: #fff !important;
        background: rgba(255, 255, 255, 0.1);
        border-radius: 8px;
    }

    .lpx-mobile-nav-tab:has(.lpx-mobile-hamburger) a::after,
    .lpx-mobile-nav-tab:has(.lpx-mobile-hamburger) .mobile-item-text {
        display: none !important;
    }

    .lpx-mobile-nav-tab:has(.lpx-mobile-hamburger)
    .lpx-mobile-hamburger
    .menu-item-icon {
        width: 34px;
        height: 48px !important;
        margin: 0 !important;
        color: #fff !important;
    }

    .lpx-mobile-navbar {
        height: 72px;
        background: #111214;
        border-top: 1px solid rgba(255, 255, 255, 0.08);
        box-shadow: 0 -4px 14px rgba(0, 0, 0, 0.16);
    }

    .lpx-mobile-nav-tab-container .lpx-mobile-nav-tabs {
        height: 100%;
        justify-content: space-around;
    }

    .lpx-mobile-nav-tab-container
    .lpx-mobile-nav-tabs
    .lpx-mobile-nav-tab:not(:has(.lpx-mobile-hamburger)) {
        display: flex;
        flex: 1 1 25%;
        width: auto;
        height: 72px;
        align-items: center;
        justify-content: center;
        margin: 0;
        padding: 0.25rem 0.125rem;
        border-radius: 0;
    }

    .lpx-mobile-nav-tab:not(:has(.lpx-mobile-hamburger)) > a {
        display: flex;
        width: 100%;
        min-width: 0;
        min-height: 60px;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        color: #aeb7c5 !important;
    }

    .lpx-mobile-nav-tab:not(:has(.lpx-mobile-hamburger))
    .menu-item-icon {
        margin: 0 auto 0.35rem !important;
        color: #aeb7c5 !important;
    }

    .lpx-mobile-nav-tab:not(:has(.lpx-mobile-hamburger))
    .mobile-item-text {
        display: block;
        max-width: 100%;
        margin: 0;
        overflow: hidden;
        color: inherit;
        font-size: 0.72rem;
        line-height: 1;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .lpx-mobile-nav-tab:not(:has(.lpx-mobile-hamburger)).selected > a,
    .lpx-mobile-nav-tab:not(:has(.lpx-mobile-hamburger)) > a:hover,
    .lpx-mobile-nav-tab:not(:has(.lpx-mobile-hamburger))
    > a.lpx-mobile-menu-toggle-open {
        color: #fff !important;
    }

    .lpx-mobile-nav-tab:not(:has(.lpx-mobile-hamburger)).selected
    .menu-item-icon,
    .lpx-mobile-nav-tab:not(:has(.lpx-mobile-hamburger))
    > a:hover
    .menu-item-icon,
    .lpx-mobile-nav-tab:not(:has(.lpx-mobile-hamburger))
    > a.lpx-mobile-menu-toggle-open
    .menu-item-icon {
        color: #d85b0a !important;
    }

    .lpx-mobile-nav-tab:not(:has(.lpx-mobile-hamburger)) > a::after {
        width: 32px !important;
        height: 3px !important;
        background-color: #d85b0a !important;
    }

    .lpx-mobile-nav-tab:has(.lpx-avatar) .mobile-item-text {
        font-size: 0 !important;
    }

    .lpx-mobile-nav-tab:has(.lpx-avatar) .mobile-item-text::after {
        content: "Profile";
        font-size: 0.72rem;
    }

}

/* ── Content Area ── */

/* On mobile (< md) kill the LeptonX "floating panel" inset so content is edge-to-edge.
   We target every known wrapper in the LeptonX side-menu layout hierarchy. */
@media (max-width: 767.98px) {
    .lpx-content-wrapper,
    [class*="lpx-content-wrapper"] {
        padding: 0 !important;
        gap: 0 !important;
        margin: 0 !important;
    }

    .lpx-content-container,
    [class*="lpx-content-container"],
    .lpx-footbar-container,
    .lpx-footbar {
        margin: 0 !important;
        padding: 0 !important;
        border-radius: 0 !important;
        gap: 0 !important;
    }

    .lpx-content,
    [class*="lpx-content"]:not(.lpx-content-container):not(.lpx-content-wrapper) {
        padding: 0.5rem !important;
        margin: 0 !important;
    }

    .full,
    .lpx-wrapper,
    [class*="lpx-wrapper"],
    .lpx-main-container,
    .lpx-layout {
        padding: 0 !important;
        margin: 0 !important;
        gap: 0 !important;
    }

    body.abp-application-layout,
    html,
    body {
        padding: 0 !important;
    }

    /* Light and Semi-Dark both keep a light content area by design (see the Semi-Dark Theme
       Parity note below - only Semi-Dark's sidebar is dark), so this light background is
       correct for them. Full Dark is excluded rather than guessing a hex here: this rule and
       LeptonX's own dark body background would otherwise collide (equal !important, and this
       rule wins on selector count), forcing a light page background on the one theme actually
       meant to be dark end-to-end. */
    body.abp-application-layout:not(.lpx-theme-dark),
    html:not(.lpx-theme-dark),
    body:not(.lpx-theme-dark) {
        background: #f8f9fa !important;
    }

    .lpx-content-container .container-fluid,
    .lpx-content .container-fluid {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
    .cards_row .card .card-header {
        padding: 12px 12px !important;
    }
}

/* Prevent ANY element from causing viewport-wide horizontal scroll.
   'clip' instead of 'hidden' avoids creating a scroll container that
   intercepts horizontal touch gestures meant for inner scroll elements. */
.lpx-content-container,
.lpx-content,
.lpx-wrapper {
    overflow-x: clip;
    max-width: 100vw;
}

/* ── Page Header / Breadcrumbs ── */

/* Breadcrumb wrapping on small screens */
@media (max-width: 575.98px) {
    .lpx-content .breadcrumb {
        flex-wrap: wrap;
        font-size: 0.8rem;
    }

    .lpx-content .page-header-title {
        font-size: 1.1rem;
    }
}

/* ============================================
   Dashboard Widget Grid
   ============================================
   Reference grid for the internal dashboard.
   Single column below lg, fluid 2:1 content/sidebar above. */

.dashboard-widget-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}
.th-nowrap table thead th{
    white-space: nowrap;
}
.modal-content {
    max-height: 100% !important;
}
.modal-body {
    max-height: calc(100vh - 300px) !important;
}
.flatdate-group-box .b-tooltip:has(.flatpickr-wrapper) {
    width: 100%;
}

.flatdate-group-box .flatpickr-wrapper input.form-control {
    padding-right: 36px;
}

.flatdate-group-box .b-tooltip:has(.fa-calendar-check) {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: #635c5c;
    display: flex;
    align-items: center;
    justify-content: center;
}

.flatdate-group-box .b-tooltip button:has(.fa-calendar-check) {
    background: transparent !important;
    padding: 0 !important;
    border: none !important;
    color: #635c5c;
}


    @media (min-width: 992px) {
        .dashboard-widget-grid {
            grid-template-columns: 2fr 1fr;
        }
    }

    /* Sticky only at >=992px (lg), matching col-lg-4 — the sidebar column this
       card sits in. Below lg the layout stacks to full-width, so sticking a
       full-width block there would eat viewport height for no benefit.
       The offset comes from --sticky-offset set per host (see .portal-shell in
       PortalLayout.razor); the 65px fallback covers the LeptonX topbar used by
       /information/general/*.
       z-index stays below the portal nav bar's 19 so a stuck sidebar card scrolls
       under the nav pill instead of over it. */
    @media (min-width: 992px) {
        .top-spacing-offset {
            top: var(--sticky-offset, 65px);
            position: sticky;
            z-index: 10;
        }
    }

    @media (min-width: 1400px) {
        .dashboard-widget-grid {
            gap: 1.5rem;
        }
    }
    /* Prevent grid children from overflowing */
    .dashboard-widget-grid > * {
        min-width: 0;
    }
    /* ============================================
   WideTableScroll Component
   ============================================ */

    .wide-table-scroll__container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-x pan-y;
    }
        /* Force the table inside to use its natural width, not shrink to fit */
        .wide-table-scroll__container > .table-responsive,
        .wide-table-scroll__container > .table-responsive > table,
        .wide-table-scroll__container table.b-table,
        .wide-table-scroll__container table {
            min-width: 900px;
        }
    /* Wide grids (18+ columns) need more space */
    .wide-table-scroll--wide .table-responsive > table,
    .wide-table-scroll--wide table.b-table,
    .wide-table-scroll--wide table {
        min-width: 1400px;
    }
    /* Thin scrollbar for the table container */
    .wide-table-scroll__container::-webkit-scrollbar {
        height: 6px;
    }

    .wide-table-scroll__container::-webkit-scrollbar-thumb {
        background-color: rgba(0, 0, 0, 0.2);
        border-radius: 3px;
    }

    .wide-table-scroll__container {
        scrollbar-width: thin;
    }
    /* Advisory text — hidden at md and above */
    .wide-table-scroll__advisory {
        font-style: italic;
        opacity: 0.85;
    }
    /* ============================================
   Viewport-Capped Grid
   ============================================
   For column-heavy Blazorise DataGrids (roughly 18+ columns) where the
   horizontal scrollbar would otherwise render below the last row, forcing
   the user to scroll the page to reach it.

   Opt in by pairing the class with Blazorise's FixedHeader:

     <DataGrid Responsive="true"
               FixedHeader="true"
               FixedHeaderDataGridHeight=""
               FixedHeaderDataGridMaxHeight="calc(100vh - 320px)"
               Class="viewport-capped-grid">

   FixedHeaderDataGridHeight="" is required — Blazorise writes both height
   and max-height inline and defaults height to 500px, which renders a rigid
   box for small result sets. Tune the max-height subtrahend per page to
   account for that page's heading, filters and pager.

   With FixedHeader set, .table-responsive (overflow-x) and
   .table-fixed-header (overflow-y) share ONE container div that scrolls both
   axes. Do not wrap such a grid in WideTableScroll: its outer overflow-x
   container would become the horizontal scroll ancestor and push the
   scrollbar back below the full grid height.

   Class lands on the <table>, hence the :has(>) container selectors. */

    /* Floor the capped box so it stays usable on short viewports.
       Blazorise writes max-height inline, so !important is required. */
    .table-fixed-header:has(> .viewport-capped-grid) {
        min-height: 320px;
        max-height: max(320px, calc(100vh - 320px)) !important;
    }
    /* The horizontal scrollbar is the primary navigation affordance for a
       column-heavy grid, so make it easier to see and grab than the 6px
       used by .wide-table-scroll__container. */
    .table-fixed-header:has(> .viewport-capped-grid)::-webkit-scrollbar {
        height: 12px;
        width: 12px;
    }

    .table-fixed-header:has(> .viewport-capped-grid)::-webkit-scrollbar-thumb {
        background-color: rgba(0, 0, 0, 0.35);
        border-radius: 6px;
    }

        .table-fixed-header:has(> .viewport-capped-grid)::-webkit-scrollbar-thumb:hover {
            background-color: rgba(0, 0, 0, 0.5);
        }
    /* Keep header cells on one line so the frozen header stays compact. */
    .viewport-capped-grid thead th {
        white-space: nowrap;
    }
    /* Sticky cells are transparent by default, so data rows scroll THROUGH
       the frozen header. Blazorise ships background: var(--bs-table-bg, white)
       for this, but --bs-table-bg resolves to transparent on a Bootstrap 5
       table, so the white fallback never applies. Set it explicitly, and
       neutralise the striped/hover accent that also bleeds through.
       Applied to the row as well as the cells so gaps at the seams of
       border-collapse: separate stay opaque too. */
    .table-fixed-header > .viewport-capped-grid > thead,
    .table-fixed-header > .viewport-capped-grid > thead > tr {
        background-color: var(--lpx-content-bg, #fff);
    }

        .table-fixed-header > .viewport-capped-grid > thead > tr > th {
            background-color: var(--lpx-content-bg, #fff) !important;
            --bs-table-accent-bg: transparent;
            background-image: none;
        }
    /* Lift the header above sticky body content. Blazorise uses z-index 10
       for th and up to 12 for fixed-position cells. */
    .table-fixed-header > .viewport-capped-grid > thead > tr > th {
        z-index: 13;
    }
    /* ============================================
   Tap Target Minimums (shell controls)
   ============================================
   44×44px per WCAG 2.5.5 Target Size.
   Applied to primary interactive controls in the shell. */

    .lpx-topbar .btn,
    .lpx-topbar a[role="button"],
    .lpx-topbar button,
    .lpx-topbar .dropdown-toggle {
        min-width: 44px;
        min-height: 44px;
    }
    /* ============================================
   Semi-Dark (Dim) Theme Parity
   ============================================
   LeptonX Semi-Dark has a dark sidebar but light content area.
   Ensure responsive overrides don't break this split. */
    /* Sidebar toggle text in semi-dark: keep contrasting */
    .lpx-theme-dim .lpx-topbar {
        color: inherit;
    }
    /* Ensure .wide-table-scroll__advisory is legible in dim/dark themes */
    .lpx-theme-dim .wide-table-scroll__advisory,
    .lpx-theme-dark .wide-table-scroll__advisory {
        color: var(--bs-secondary-color, #adb5bd);
    }
    /* ============================================
   Analytics Responsive (World Map & Budget)
   ============================================
   Ensures world map and budget analytics pages
   don't overflow at narrow viewports (~375px). */
    /* World map: stack legend below map on narrow screens */
    @media (max-width: 767.98px) {
        .world-map-wrapper {
            flex-direction: column !important;
        }

        .world-map-container {
            height: 280px !important;
            min-height: 280px !important;
            max-height: 280px !important;
        }

            .world-map-container > div,
            .world-map-container .jqvmap-zoomin,
            .world-map-container .jqvmap-zoomout {
                min-height: 280px !important;
                max-height: 280px !important;
            }

            .world-map-container svg {
                min-height: 280px !important;
                max-height: 260px !important;
            }

        .map-legend-panel {
            width: 100% !important;
            min-width: 100% !important;
            max-height: 150px !important;
            border-left: none !important;
            border-top: 1px solid rgba(0,0,0,.08);
        }

        .map-legend-content {
            display: flex;
            flex-wrap: wrap;
            gap: 4px 12px;
        }
        /* Budget analytics: summary stat cards stack full-width */
        .world-map-summary .wm-stat-row {
            flex-direction: column;
        }

        .world-map-summary .wm-stat {
            flex: 1 1 100% !important;
        }
        /* Chart containers at narrow widths */
        .chart-container {
            min-height: 200px !important;
            height: 250px !important;
        }

        .page-content-container {
            padding-bottom: 40px;
        }
        .tabs-mobile-scroll .nav.nav-tabs, body .tabs-mobile-scroll-list {
            white-space: nowrap;
            display: flex;
            flex-wrap: nowrap !important;
            overflow-x: auto;
            padding-bottom: 8px !important;
        }
    }
    /* Extra small: even tighter map */
    @media (max-width: 575.98px) {
        .world-map-container {
            height: 220px !important;
            min-height: 220px !important;
            max-height: 220px !important;
        }

            .world-map-container > div,
            .world-map-container .jqvmap-zoomin,
            .world-map-container .jqvmap-zoomout {
                min-height: 220px !important;
                max-height: 220px !important;
            }

            .world-map-container svg {
                min-height: 220px !important;
                max-height: 200px !important;
            }
    }

    @media (max-width: 767.98px) {
        .modal-content:has(#EditIseAdministratorForm), .modal-content:has(#CreateHrDivisionCoordinatorForm),
        .modal-content:has(#EditHrDivisionCoordinatorForm), .modal-content:has(#StatusForm),
        .modal-content:has(#EditReportChoiceTypeDescForm), .modal-content:has(#CreateReportChoiceTypeDescForm) {
            max-height: 90vh;
            overflow-y: auto;
        }

        .scroll-mobile-btn-group {
            white-space: nowrap;
            overflow-x: auto;
            width: 100%;
            padding-bottom: 8px;
        }
        .logs-input-mobile input.form-control {
            height: 44px;
        }
    }

    @media (min-width: 1600px) {
        .col-xxxl-2 {
            flex: 0 0 auto !important;
            width: 16.66666667% !important;
        }
    }

    /* ============================================
       CmsKit Blog Posts – Mobile Search Fix
       ============================================
       The form uses col-2 / col-10 which breaks on mobile.
       Override to col-12 stacking below md. */
    @media (max-width: 767.98px) {
        .card-body form > .row > .col-2,
        .card-body form > .row > .col-10 {
            flex: 0 0 100% !important;
            max-width: 100% !important;
            margin-bottom: 0.5rem;
        }
    }

/* ============================================
   Collapsed Sidebar Hover-Flyout — Label Truncation
   ============================================
   Not a narrow-viewport concern (LeptonX's own icon-rail + hover-flyout is a
   desktop pattern) but the same shell-override file is the natural home.

   LeptonX's own layout-bundle.css hardcodes nested submenu item labels
   (`.lpx-nav-menu .lpx-inner-menu-item .lpx-menu-item-text`) to a fixed
   148px with `overflow: hidden; text-overflow: ellipsis`, which silently
   truncates longer labels (e.g. HR's "Base-Funded Missionaries",
   "Missionaries Per Status") with no tooltip to recover the full text.
   Top-level items (`.lpx-menu-item-text` at 172px, one level up) are wide
   enough for this app's current top-level labels and are left alone.

   Rather than guess a fixed pixel width that fits every current and future
   label, let the text wrap onto a second line instead of truncating — the
   flyout has vertical room to spare; it doesn't have unlimited horizontal
   room. The row height is switched from a fixed line-height-as-height trick
   to min-height + flex centering so it only grows for labels that actually
   wrap; short labels render at their original 32px.

   !important is required on the overridden properties: LeptonX's own
   bootstrap-{theme}.css/layout-bundle.css loads after this file and wins at
   equal selector specificity otherwise — same reason blazor-global-styles.css
   needs !important on its muted-text-legibility override (see that file's
   "Muted text legibility" comment). */
.lpx-nav-menu .lpx-inner-menu-item .lpx-menu-item-link {
    height: auto !important;
    min-height: 32px !important;
    line-height: 1.3 !important;
    align-items: center;
    padding-top: 4px;
    padding-bottom: 4px;
}

.lpx-nav-menu .lpx-inner-menu-item .lpx-menu-item-text {
    width: 210px !important;
    white-space: normal !important;
    overflow: visible !important;
    overflow-wrap: break-word;
    text-overflow: clip !important;
}

