/*
   CraftGrid One — responsive final polish
   Visual-only corrections based on the approved desktop + mobile mockup.
   Loaded after the existing brand layers. No routes, permissions, or workflows.
*/

/* Keep the existing navy top bar, but replace the legacy tricolour underline
   with the approved single sky-blue brand accent. */
.craftgrid-authenticated-shell .craftgrid-topbar::after {
    background: #38BDF8 !important;
    background-image: none !important;
    opacity: .92 !important;
    height: 2px !important;
}

/* The same nine-square yellow mark is used by login, the top bar and drawer. */
.craftgrid-authenticated-shell .craftgrid-topbar .craftgrid-brand-icon.cg-brand-grid-mark,
.craftgrid-authenticated-shell .craftgrid-mobile-sidebar .craftgrid-mobile-sidebar-brand-mark.cg-brand-grid-mark {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    grid-template-rows: repeat(3, minmax(0, 1fr)) !important;
    gap: 3px !important;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    overflow: visible !important;
}

.craftgrid-authenticated-shell .craftgrid-topbar .craftgrid-brand-icon.cg-brand-grid-mark > i,
.craftgrid-authenticated-shell .craftgrid-mobile-sidebar .craftgrid-mobile-sidebar-brand-mark.cg-brand-grid-mark > i {
    display: block !important;
    min-width: 0 !important;
    min-height: 0 !important;
    border-radius: 3px !important;
    background: #FFC629 !important;
}

/* Mobile drawer header: keep the complete brand visible and the close glyph white. */
@media (max-width: 991.98px) {
    .craftgrid-authenticated-shell .craftgrid-mobile-sidebar .offcanvas-header {
        background: linear-gradient(110deg, #102B40 0%, #123B5E 100%) !important;
        color: #FFFFFF !important;
        min-height: 70px;
        padding: 14px 18px !important;
    }

    .craftgrid-authenticated-shell .craftgrid-mobile-sidebar .craftgrid-mobile-sidebar-brand {
        display: flex !important;
        align-items: center !important;
        gap: 10px !important;
        min-width: 0 !important;
    }

    .craftgrid-authenticated-shell .craftgrid-mobile-sidebar .craftgrid-mobile-sidebar-brand-mark.cg-brand-grid-mark {
        width: 30px !important;
        height: 30px !important;
        min-width: 30px !important;
        flex: 0 0 30px !important;
    }

    .craftgrid-authenticated-shell .craftgrid-mobile-sidebar .craftgrid-mobile-sidebar-brand-name {
        display: inline-block !important;
        color: #FFFFFF !important;
        font-size: 1.12rem !important;
        font-weight: 700 !important;
        letter-spacing: -.035em !important;
        line-height: 1 !important;
        white-space: nowrap !important;
    }

    .craftgrid-authenticated-shell .craftgrid-mobile-sidebar .craftgrid-mobile-sidebar-brand-name em {
        color: #38BDF8 !important;
        font-style: normal !important;
    }

    .craftgrid-authenticated-shell .craftgrid-mobile-sidebar .craftgrid-mobile-sidebar-close,
    .craftgrid-authenticated-shell .craftgrid-mobile-sidebar .offcanvas-header .btn-close {
        flex: 0 0 32px !important;
        width: 32px !important;
        height: 32px !important;
        margin: 0 !important;
        padding: 7px !important;
        border: 0 !important;
        border-radius: 8px !important;
        background-color: transparent !important;
        filter: invert(1) grayscale(1) brightness(200%) !important;
        opacity: 1 !important;
        box-shadow: none !important;
    }

    .craftgrid-authenticated-shell .craftgrid-mobile-sidebar .craftgrid-mobile-sidebar-close:hover,
    .craftgrid-authenticated-shell .craftgrid-mobile-sidebar .craftgrid-mobile-sidebar-close:focus-visible {
        background-color: rgba(56, 189, 248, .16) !important;
        outline: 2px solid rgba(125, 211, 252, .8) !important;
        outline-offset: 1px !important;
    }
}

/* Fix the narrow phone header. Keep the hamburger, complete CraftGrid One wordmark,
   notification, profile and sign-out controls on one line without clipping. */
@media (max-width: 575.98px) {
    body.craftgrid-authenticated-shell:not(.craftgrid-login-layout) .craftgrid-topbar .cg-topbar-layout {
        display: flex !important;
        flex-wrap: nowrap !important;
        align-items: center !important;
        justify-content: space-between !important;
        gap: 5px !important;
        padding-left: 8px !important;
        padding-right: 8px !important;
        min-width: 0 !important;
        overflow: visible !important;
    }

    body.craftgrid-authenticated-shell:not(.craftgrid-login-layout) .craftgrid-topbar .cg-topbar-left-cluster {
        display: flex !important;
        align-items: center !important;
        flex: 1 1 auto !important;
        width: auto !important;
        max-width: none !important;
        min-width: 0 !important;
        margin: 0 2px 0 0 !important;
        gap: 0 !important;
        overflow: visible !important;
    }

    body.craftgrid-authenticated-shell:not(.craftgrid-login-layout) .craftgrid-topbar .cg-topbar-left-cluster > .craftgrid-mobile-menu {
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        flex: 0 0 34px !important;
        width: 34px !important;
        min-width: 34px !important;
        height: 34px !important;
        min-height: 34px !important;
        margin: 0 6px 0 0 !important;
        padding: 0 !important;
    }

    body.craftgrid-authenticated-shell:not(.craftgrid-login-layout) .craftgrid-topbar .cg-topbar-left-cluster > .craftgrid-brand {
        display: inline-flex !important;
        align-items: center !important;
        flex: 0 1 auto !important;
        width: auto !important;
        max-width: none !important;
        min-width: 0 !important;
        gap: 5px !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: visible !important;
        white-space: nowrap !important;
    }

    body.craftgrid-authenticated-shell:not(.craftgrid-login-layout) .craftgrid-topbar .cg-topbar-left-cluster > .craftgrid-brand .cg-brand-grid-mark {
        flex: 0 0 29px !important;
        width: 29px !important;
        min-width: 29px !important;
        height: 29px !important;
        min-height: 29px !important;
    }

    body.craftgrid-authenticated-shell:not(.craftgrid-login-layout) .craftgrid-topbar .cg-topbar-left-cluster > .craftgrid-brand .cg-brand-copy {
        display: block !important;
        flex: 0 0 auto !important;
        width: auto !important;
        min-width: max-content !important;
        max-width: none !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: visible !important;
    }

    body.craftgrid-authenticated-shell:not(.craftgrid-login-layout) .craftgrid-topbar .cg-topbar-left-cluster > .craftgrid-brand .cg-brand-copy strong {
        display: inline-block !important;
        width: auto !important;
        max-width: none !important;
        overflow: visible !important;
        text-overflow: clip !important;
        white-space: nowrap !important;
        font-size: clamp(.76rem, 3.6vw, .89rem) !important;
        line-height: 1 !important;
        letter-spacing: -.045em !important;
    }

    body.craftgrid-authenticated-shell:not(.craftgrid-login-layout) .craftgrid-topbar .cg-topbar-left-cluster > .craftgrid-brand .cg-brand-copy small,
    body.craftgrid-authenticated-shell:not(.craftgrid-login-layout) .craftgrid-topbar .cg-topbar-left-cluster > .craftgrid-brand > .cg-brand-erp-badge {
        display: none !important;
    }

    body.craftgrid-authenticated-shell:not(.craftgrid-login-layout) .craftgrid-topbar .cg-topbar-right-cluster {
        display: flex !important;
        align-items: center !important;
        flex: 0 0 auto !important;
        width: auto !important;
        min-width: max-content !important;
        max-width: none !important;
        margin-left: auto !important;
        gap: 3px !important;
        overflow: visible !important;
    }

    body.craftgrid-authenticated-shell:not(.craftgrid-login-layout) .craftgrid-topbar .cg-topbar-actions {
        display: flex !important;
        align-items: center !important;
        flex: 0 0 auto !important;
        gap: 3px !important;
    }

    body.craftgrid-authenticated-shell:not(.craftgrid-login-layout) .craftgrid-topbar .cg-topbar-actions .craftgrid-icon-button,
    body.craftgrid-authenticated-shell:not(.craftgrid-login-layout) .craftgrid-topbar .cg-topbar-actions .craftgrid-user-button,
    body.craftgrid-authenticated-shell:not(.craftgrid-login-layout) .craftgrid-topbar .cg-header-signout-button {
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        flex: 0 0 34px !important;
        width: 34px !important;
        min-width: 34px !important;
        height: 34px !important;
        min-height: 34px !important;
        padding: 0 !important;
    }

    body.craftgrid-authenticated-shell:not(.craftgrid-login-layout) .craftgrid-topbar .cg-topbar-actions .vr {
        display: none !important;
    }
}

@media (max-width: 359.98px) {
    body.craftgrid-authenticated-shell:not(.craftgrid-login-layout) .craftgrid-topbar .cg-topbar-layout {
        padding-left: 6px !important;
        padding-right: 6px !important;
        gap: 3px !important;
    }

    body.craftgrid-authenticated-shell:not(.craftgrid-login-layout) .craftgrid-topbar .cg-topbar-left-cluster > .craftgrid-mobile-menu {
        flex-basis: 31px !important;
        width: 31px !important;
        min-width: 31px !important;
        height: 31px !important;
        min-height: 31px !important;
        margin-right: 4px !important;
    }

    body.craftgrid-authenticated-shell:not(.craftgrid-login-layout) .craftgrid-topbar .cg-topbar-left-cluster > .craftgrid-brand .cg-brand-grid-mark {
        flex-basis: 27px !important;
        width: 27px !important;
        min-width: 27px !important;
        height: 27px !important;
        min-height: 27px !important;
    }

    body.craftgrid-authenticated-shell:not(.craftgrid-login-layout) .craftgrid-topbar .cg-topbar-actions .craftgrid-icon-button,
    body.craftgrid-authenticated-shell:not(.craftgrid-login-layout) .craftgrid-topbar .cg-topbar-actions .craftgrid-user-button,
    body.craftgrid-authenticated-shell:not(.craftgrid-login-layout) .cg-header-signout-button {
        flex-basis: 31px !important;
        width: 31px !important;
        min-width: 31px !important;
        height: 31px !important;
        min-height: 31px !important;
    }
}

/* ============================================================
   CraftGrid One — focused mobile header + viewport scroll fix
   Based on the 16-Nov mobile screenshots.
   - Slightly enlarge the compact brand wordmark.
   - Move the dropdown chevron into the avatar circle.
   - Remove the duplicate document scrollbar while preserving
     scrolling inside the main content area.
   ============================================================ */
@media (max-width: 575.98px) {
    body.craftgrid-authenticated-shell:not(.craftgrid-login-layout)
        .craftgrid-topbar .cg-topbar-left-cluster > .craftgrid-brand .cg-brand-copy strong {
        font-size: clamp(.94rem, 4vw, 1.02rem) !important;
        font-weight: 750 !important;
        letter-spacing: -.04em !important;
        line-height: 1.05 !important;
        white-space: nowrap !important;
    }

    body.craftgrid-authenticated-shell:not(.craftgrid-login-layout)
        .craftgrid-topbar .cg-topbar-left-cluster > .craftgrid-brand {
        gap: 7px !important;
    }

    /* Bootstrap normally places this caret after the avatar. Hide that
       external caret and draw a smaller one inside the avatar instead. */
    body.craftgrid-authenticated-shell:not(.craftgrid-login-layout)
        .craftgrid-topbar .craftgrid-user-button.dropdown-toggle::after {
        display: none !important;
    }

    body.craftgrid-authenticated-shell:not(.craftgrid-login-layout)
        .craftgrid-topbar .craftgrid-user-button .craftgrid-avatar {
        position: relative !important;
        overflow: visible !important;
    }

    body.craftgrid-authenticated-shell:not(.craftgrid-login-layout)
        .craftgrid-topbar .craftgrid-user-button .craftgrid-avatar::after {
        content: "";
        position: absolute;
        right: 1px;
        bottom: 1px;
        width: 0;
        height: 0;
        border-top: 4px solid #FFFFFF;
        border-right: 4px solid transparent;
        border-left: 4px solid transparent;
        filter: drop-shadow(0 1px 1px rgba(16, 43, 64, .55));
        pointer-events: none;
        z-index: 2;
    }
}

/* On phones, the document and the main content were both scrolling,
   producing two vertical scrollbars side-by-side. Keep the viewport fixed
   and let the existing <main class="overflow-auto"> remain the one page
   scroll container. The menu drawer keeps its own independent scrolling. */
@media (max-width: 767.98px) {
    html:has(> body.craftgrid-authenticated-shell:not(.craftgrid-login-layout)) {
        height: 100% !important;
        overflow: hidden !important;
    }

    body.craftgrid-authenticated-shell:not(.craftgrid-login-layout) {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
        height: 100vh !important;
        height: 100dvh !important;
        min-height: 0 !important;
        overflow: hidden !important;
    }

    body.craftgrid-authenticated-shell:not(.craftgrid-login-layout) > header {
        flex: 0 0 auto !important;
        min-height: 0 !important;
    }

    body.craftgrid-authenticated-shell:not(.craftgrid-login-layout) .craftgrid-app-shell {
        flex: 1 1 auto !important;
        height: auto !important;
        min-height: 0 !important;
        overflow: hidden !important;
    }

    body.craftgrid-authenticated-shell:not(.craftgrid-login-layout) .craftgrid-main-row {
        height: 100% !important;
        min-height: 0 !important;
        overflow: hidden !important;
    }

    body.craftgrid-authenticated-shell:not(.craftgrid-login-layout) .craftgrid-main-row > main {
        height: 100% !important;
        min-height: 0 !important;
        max-height: 100% !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
        overscroll-behavior-y: contain;
        -webkit-overflow-scrolling: touch;
    }
}

/* ============================================================
   Exact mobile header correction — verified against _TopNavbar.cshtml.
   There are two intentional controls in the markup:
   - #craftGridSidebarToggle: desktop sidebar toggle
   - [data-bs-target="#mobileSidebar"]: mobile offcanvas toggle
   The earlier broad display rule made both visible on phones. Hide only
   the desktop control below the lg breakpoint and retain the offcanvas one.
   ============================================================ */
@media (max-width: 991.98px) {
    body.craftgrid-authenticated-shell:not(.craftgrid-login-layout)
        .craftgrid-topbar .cg-topbar-left-cluster > #craftGridSidebarToggle {
        display: none !important;
    }

    body.craftgrid-authenticated-shell:not(.craftgrid-login-layout)
        .craftgrid-topbar .cg-topbar-left-cluster > button.craftgrid-mobile-menu[data-bs-target="#mobileSidebar"] {
        display: inline-flex !important;
    }
}

@media (min-width: 992px) {
    body.craftgrid-authenticated-shell:not(.craftgrid-login-layout)
        .craftgrid-topbar .cg-topbar-left-cluster > #craftGridSidebarToggle {
        display: inline-flex !important;
    }

    body.craftgrid-authenticated-shell:not(.craftgrid-login-layout)
        .craftgrid-topbar .cg-topbar-left-cluster > button.craftgrid-mobile-menu[data-bs-target="#mobileSidebar"] {
        display: none !important;
    }
}

/* Hide the visible scrollbar track on the phone's main content pane while
   retaining native touch/trackpad scrolling. Do not hide the offcanvas menu's
   independent scrollbar or disable vertical scrolling. */
@media (max-width: 767.98px) {
    body.craftgrid-authenticated-shell:not(.craftgrid-login-layout)
        .craftgrid-main-row > main[role="main"] {
        scrollbar-width: none !important;
        -ms-overflow-style: none !important;
    }

    body.craftgrid-authenticated-shell:not(.craftgrid-login-layout)
        .craftgrid-main-row > main[role="main"]::-webkit-scrollbar {
        display: none !important;
        width: 0 !important;
        height: 0 !important;
    }
}

