/* ─────────────────────────────────────────────────────────────────────────────
   Searchable menu
   Colour follows override.css: navy #00273a is the app's --bs-secondary and the
   ink for every label; #1A3263 is the section heading; #547792 the icon accent;
   #61737d the faint meta text; green #1EBA62 carries focus, as it does on form
   controls; amber #F5A623 marks a starred page. Lighter steps are navy at an
   opacity, never a grey from another palette.
   ───────────────────────────────────────────────────────────────────────────── */

.smenu-overlay,
.smenu-panel {
    --sm-navy:          #00273a;
    --sm-ink:           #00273a;
    --sm-heading:       #1A3263;
    --sm-icon:          #547792;
    --sm-faint:         #61737d;
    --sm-line:          rgba(0, 39, 58, 0.12);
    --sm-bg:            #ffffff;
    --sm-sunk:          #eef2f4;
    --sm-head:          #f6f8f9;
    --sm-hover:         rgba(0, 39, 58, 0.04);
    --sm-selected:      rgba(0, 39, 58, 0.06);
    --sm-pill-border:   rgba(0, 39, 58, 0.16);
    --sm-mark:          rgba(0, 39, 58, 0.14);
    --sm-focus:         #1EBA62;
    --sm-focus-ring:    rgba(30, 186, 98, 0.35);
    --sm-star:          #F5A623;
    --sm-skeleton:      rgba(0, 39, 58, 0.08);
    --sm-overlay:       rgba(0, 39, 58, 0.55);
    --sm-shadow:        0 12px 40px rgba(0, 39, 58, 0.28);
    /* Header bar: navy chrome with light ink. */
    --sm-top-bg:        #00273a;
    --sm-top-ink:       rgba(255, 255, 255, 0.92);
    --sm-top-faint:     rgba(255, 255, 255, 0.62);
    --sm-search-bg:     rgba(255, 255, 255, 0.08);
    --sm-search-border: rgba(255, 255, 255, 0.22);
}

[data-bs-theme=dark] .smenu-overlay,
[data-bs-theme=dark] .smenu-panel {
    --sm-ink:           rgba(255, 255, 255, 0.92);
    --sm-heading:       rgba(255, 255, 255, 0.96);
    --sm-icon:          rgba(255, 255, 255, 0.72);
    --sm-faint:         rgba(255, 255, 255, 0.62);
    --sm-line:          rgba(255, 255, 255, 0.12);
    --sm-bg:            color-mix(in srgb, #00273a 88%, black);
    --sm-sunk:          color-mix(in srgb, #00273a 94%, black);
    --sm-head:          color-mix(in srgb, #00273a 80%, black);
    --sm-hover:         rgba(255, 255, 255, 0.05);
    --sm-selected:      rgba(255, 255, 255, 0.09);
    --sm-pill-border:   rgba(255, 255, 255, 0.18);
    --sm-mark:          rgba(255, 255, 255, 0.22);
    --sm-skeleton:      rgba(255, 255, 255, 0.08);
    --sm-overlay:       rgba(0, 0, 0, 0.65);
    --sm-shadow:        0 12px 40px rgba(0, 0, 0, 0.55);
    --sm-top-bg:        color-mix(in srgb, #00273a 70%, black);
}

/* Dark surfaces take the light ink for the active rail rule too. */
[data-bs-theme=dark] .smenu-rail-item.active,
[data-bs-theme=dark] .smenu-item.is-selected {
    border-left-color: var(--sm-ink);
}

/* ── Overlay ── */
.smenu-overlay {
    position: fixed;
    inset: 0;
    background: var(--sm-overlay);
    z-index: 1020;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.smenu-overlay.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

body.modal-open .smenu-overlay {
    pointer-events: none !important;
    z-index: 1020 !important;
}

body.modal-open .smenu-panel {
    pointer-events: none !important;
}

/* ── Panel: drops from the top, centred ── */
.smenu-panel {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%) translateY(-100%);
    width: min(1100px, 100vw);
    max-height: 88vh;
    background: var(--sm-bg);
    color: var(--sm-ink);
    border-radius: 0 0 12px 12px;
    box-shadow: var(--sm-shadow);
    z-index: 1052;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.smenu-panel.active {
    transform: translateX(-50%) translateY(0);
}

.smenu-panel:focus {
    outline: 0;
}

/* ── Header ── */
.smenu-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    background: var(--sm-top-bg);
    color: var(--sm-top-ink);
    flex-shrink: 0;
}

.smenu-btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    background: transparent;
    border: 0;
    color: var(--sm-top-faint);
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    padding: 0;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s, transform 0.15s;
}

.smenu-btn-icon:hover {
    background: rgba(255, 255, 255, 0.13);
    color: #ffffff;
}

.smenu-btn-icon:active {
    transform: scale(0.96);
}

.smenu-btn-icon:focus-visible {
    outline: 0;
    box-shadow: 0 0 0 2px var(--sm-focus);
}

.smenu-search-wrap {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
}

.smenu-search-icon {
    position: absolute;
    left: 11px;
    color: var(--sm-top-faint);
    font-size: 13px;
    pointer-events: none;
}

.smenu-search-input {
    width: 100%;
    padding: 8px 36px 8px 32px;
    background: var(--sm-search-bg);
    border: 1.5px solid var(--sm-search-border);
    border-radius: 6px;
    color: #ffffff;
    font-size: 0.9375rem;
    line-height: 1.4;
    transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
}

.smenu-search-input::placeholder {
    color: var(--sm-top-faint);
}

.smenu-search-input:focus {
    outline: 0;
    border-color: var(--sm-focus);
    background: rgba(255, 255, 255, 0.11);
    box-shadow: 0 0 0 2px var(--sm-focus-ring);
}

.smenu-clear-btn {
    position: absolute;
    right: 2px;
    width: 30px;
    height: 30px;
    font-size: 13px;
}

/* ── Body ── */
.smenu-body {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* ── Search results ── */
.smenu-results {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 6px;
}

.smenu-results-bar {
    position: sticky;
    top: 0;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 18px;
    background: var(--sm-head);
    border-bottom: 1px solid var(--sm-line);
    font-size: 0.75rem;
    color: var(--sm-faint);
}

.smenu-kbd-hints {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}

.smenu-kbd {
    display: inline-block;
    min-width: 18px;
    padding: 1px 5px;
    border: 1px solid var(--sm-pill-border);
    border-radius: 4px;
    font-size: 0.6875rem;
    line-height: 1.3;
    text-align: center;
    color: var(--sm-ink);
    background: var(--sm-bg);
}

.smenu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 18px 9px 15px;
    cursor: pointer;
    border-left: 3px solid transparent;
    transition: background 0.15s, border-color 0.15s;
}

.smenu-item:hover {
    background: var(--sm-hover);
}

.smenu-item:active {
    transform: scale(0.995);
}

.smenu-item.is-selected {
    background: var(--sm-selected);
    border-left-color: var(--sm-navy);
}

.smenu-item-icon {
    width: 26px;
    text-align: center;
    flex-shrink: 0;
    color: var(--sm-icon);
    font-size: 0.9375rem;
}

.smenu-item-body {
    flex: 1;
    min-width: 0;
}

.smenu-item-title {
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--sm-ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.35;
}

.smenu-item.is-selected .smenu-item-title {
    font-weight: 600;
}

.smenu-mark {
    background: var(--sm-mark);
    color: inherit;
    padding: 0 2px;
    border-radius: 2px;
}

.smenu-item-crumb {
    font-size: 0.75rem;
    color: var(--sm-faint);
    margin-top: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.smenu-item-arrow {
    color: var(--sm-faint);
    font-size: 11px;
    flex-shrink: 0;
    transition: transform 0.15s, color 0.15s;
}

.smenu-item:hover .smenu-item-arrow,
.smenu-item.is-selected .smenu-item-arrow {
    transform: translateX(2px);
    color: var(--sm-ink);
}

/* ── Empty states ── */
.smenu-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 56px 24px;
    color: var(--sm-faint);
    text-align: center;
    gap: 8px;
}

.smenu-empty-full {
    flex: 1;
}

.smenu-empty i {
    color: var(--sm-icon);
    opacity: 0.6;
}

.smenu-empty p {
    margin: 0;
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--sm-ink);
}

.smenu-empty small {
    font-size: 0.8125rem;
}

.smenu-overflow-note {
    text-align: center;
    padding: 10px;
    font-size: 0.75rem;
    color: var(--sm-faint);
    border-top: 1px solid var(--sm-line);
    margin-top: 4px;
}

/* ── Browse layout: rail + pane ── */
.smenu-browse {
    flex: 1;
    display: flex;
    overflow: hidden;
    min-height: 0;
}

.smenu-rail {
    width: 230px;
    flex-shrink: 0;
    background: var(--sm-sunk);
    border-right: 1px solid var(--sm-line);
    padding: 12px 10px 12px 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.smenu-rail-module {
    margin-bottom: 6px;
}

.smenu-rail-module-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 10px 6px 16px;
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--sm-navy);
    opacity: 0.62;
}

[data-bs-theme=dark] .smenu-rail-module-head {
    color: var(--sm-ink);
}

.smenu-rail-module-head i {
    width: 16px;
    text-align: center;
    flex-shrink: 0;
    font-size: 0.8125rem;
}

/* Rows are buttons, so the reset and the font size land on them directly. */
.smenu-rail-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 12px 8px 13px;
    border: 0;
    border-left: 3px solid transparent;
    border-radius: 0 6px 6px 0;
    background: transparent;
    text-align: left;
    font-size: 0.9375rem;
    font-weight: 500;
    line-height: 1.35;
    color: var(--sm-ink);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, transform 0.15s;
}

.smenu-rail-item:hover {
    background: var(--sm-hover);
}

.smenu-rail-item:active {
    transform: scale(0.98);
}

.smenu-rail-item:focus-visible {
    outline: 0;
    box-shadow: inset 0 0 0 2px var(--sm-focus);
}

.smenu-rail-item.active {
    background: var(--sm-selected);
    border-left-color: var(--sm-navy);
    font-weight: 600;
}

.smenu-rail-item i {
    width: 20px;
    text-align: center;
    flex-shrink: 0;
    font-size: 0.9375rem;
    color: var(--sm-icon);
}

.smenu-rail-item.active i {
    color: var(--sm-ink);
}

/* Group names such as "Sales and Receivables" are longer than the rail; they wrap to a second
   line rather than being cut, because a truncated name is the one thing a rail must not show. */
.smenu-rail-label {
    flex: 1;
    min-width: 0;
    overflow-wrap: anywhere;
}

.smenu-rail-count {
    flex-shrink: 0;
    min-width: 20px;
    padding: 0 6px;
    border: 1px solid var(--sm-pill-border);
    border-radius: 10px;
    font-size: 0.6875rem;
    font-weight: 600;
    line-height: 1.6;
    text-align: center;
    color: var(--sm-faint);
}

/* Favorites stands on its own above the module sections. When the user has not starred
   anything yet it stays in place as a quiet hint rather than disappearing, so the feature
   can be discovered; the landing view is still the first group. */
.smenu-rail-fav {
    margin-bottom: 8px;
}

.smenu-rail-fav.is-empty {
    cursor: default;
    align-items: flex-start;
}

.smenu-rail-fav.is-empty i {
    margin-top: 3px;
    color: var(--sm-faint);
}

.smenu-rail-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.smenu-rail-fav.is-empty .smenu-rail-label {
    color: var(--sm-faint);
}

.smenu-rail-hint {
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--sm-faint);
    line-height: 1.3;
}

/* ── Pane ── */
.smenu-pane {
    flex: 1;
    overflow-y: auto;
    padding: 20px 28px 28px;
}

.smenu-pane-head {
    margin-bottom: 18px;
}

.smenu-pane-eyebrow {
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--sm-faint);
}

.smenu-pane-title {
    margin: 2px 0 0;
    font-size: 1.125rem;
    font-weight: 600;
    line-height: 1.3;
    color: var(--sm-heading);
}

.smenu-pane-meta {
    margin-top: 2px;
    font-size: 0.75rem;
    color: var(--sm-faint);
}

.smenu-sections {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 24px 32px;
    align-items: start;
}

.smenu-sections-single {
    grid-template-columns: minmax(0, 520px);
}

.smenu-section {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.smenu-section-title {
    margin: 0 0 6px;
    padding: 0 10px 8px;
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.3;
    color: var(--sm-heading);
    border-bottom: 1px solid var(--sm-line);
}

/* A page row is an anchor plus a star side by side; the row owns the hover so the strip
   highlights as one item. */
.smenu-page-row {
    display: flex;
    align-items: center;
    border-radius: 6px;
    transition: background 0.15s, transform 0.15s;
}

.smenu-page-row:hover {
    background: var(--sm-hover);
}

.smenu-page-row:active {
    transform: scale(0.98);
}

.smenu-page,
.smenu-page:hover,
.smenu-page:focus {
    text-decoration: none;
}

.smenu-page {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 0.9375rem;
    font-weight: 500;
    line-height: 1.35;
    color: var(--sm-ink);
    cursor: pointer;
    transition: color 0.15s;
}

.smenu-page:hover {
    color: var(--sm-ink);
}

.smenu-page:focus-visible {
    outline: 0;
    box-shadow: inset 0 0 0 2px var(--sm-focus);
}

.smenu-page i {
    width: 18px;
    text-align: center;
    flex-shrink: 0;
    font-size: 0.9375rem;
    color: var(--sm-icon);
}

.smenu-page-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.smenu-page-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.smenu-page-crumb {
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--sm-faint);
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Star ── */
.smenu-fav-btn {
    flex: 0 0 auto;
    align-self: center;
    background: none;
    border: 0;
    outline: 0;
    box-shadow: none;
    padding: 4px 8px;
    margin: 0;
    line-height: 1;
    cursor: pointer;
    border-radius: 6px;
    color: var(--sm-faint);
    /* Always visible, just faint: hidden-until-hover meant nobody found the feature. Faint
       enough that a column of unstarred pages still reads as a clean list. */
    opacity: 0.4;
    transition: opacity 0.15s, color 0.15s, transform 0.15s;
}

.smenu-page-row:hover .smenu-fav-btn,
.smenu-item:hover .smenu-fav-btn,
.smenu-item.is-selected .smenu-fav-btn,
.smenu-fav-btn:hover,
.smenu-fav-btn:focus-visible,
.smenu-fav-btn.is-fav {
    opacity: 1;
}

.smenu-fav-btn:hover,
.smenu-fav-btn.is-fav {
    color: var(--sm-star);
}

.smenu-fav-btn:active {
    transform: scale(0.9);
}

.smenu-fav-btn:focus-visible {
    box-shadow: 0 0 0 2px var(--sm-focus);
}

/* Only duotone-light is loaded, so there is no solid star to switch to - colour plus a
   filled duotone body is what marks a page as starred. */
.smenu-fav-btn.is-fav i {
    --fa-primary-color: var(--sm-star);
    --fa-secondary-color: var(--sm-star);
    --fa-primary-opacity: 1;
    --fa-secondary-opacity: 0.9;
}

/* Touch devices have no hover, so the star has to stay fully visible. */
@media (hover: none) {
    .smenu-fav-btn {
        opacity: 1;
    }
}

.smenu-item .smenu-fav-btn {
    padding: 4px 2px;
}

/* ── Loading skeleton ── */
.smenu-skeleton {
    flex: 1;
    display: flex;
    min-height: 320px;
}

.smenu-skeleton-rail {
    width: 230px;
    flex-shrink: 0;
    background: var(--sm-sunk);
    border-right: 1px solid var(--sm-line);
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.smenu-skeleton-pane {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 24px 32px;
    padding: 28px;
    align-items: start;
}

.smenu-skeleton-col {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.smenu-skeleton .bar {
    display: block;
    height: 12px;
    border-radius: 6px;
    background: var(--sm-skeleton);
    animation: smenu-pulse 1.4s ease-in-out infinite;
}

.smenu-skeleton .bar.head { height: 16px; width: 55%; margin-bottom: 6px; }
.smenu-skeleton .bar.w-50 { width: 50%; }
.smenu-skeleton .bar.w-60 { width: 60%; }
.smenu-skeleton .bar.w-70 { width: 70%; }
.smenu-skeleton .bar.w-80 { width: 80%; }

@keyframes smenu-pulse {
    50% { opacity: 0.45; }
}

/* ── Scrollbars ── */
.smenu-results::-webkit-scrollbar,
.smenu-rail::-webkit-scrollbar,
.smenu-pane::-webkit-scrollbar {
    width: 5px;
}

.smenu-results::-webkit-scrollbar-track,
.smenu-rail::-webkit-scrollbar-track,
.smenu-pane::-webkit-scrollbar-track {
    background: transparent;
}

.smenu-results::-webkit-scrollbar-thumb,
.smenu-rail::-webkit-scrollbar-thumb,
.smenu-pane::-webkit-scrollbar-thumb {
    background: var(--sm-line);
    border-radius: 3px;
}

/* ── Motion preference ── */
@media (prefers-reduced-motion: reduce) {
    .smenu-overlay,
    .smenu-panel,
    .smenu-btn-icon,
    .smenu-rail-item,
    .smenu-page-row,
    .smenu-page,
    .smenu-item,
    .smenu-item-arrow,
    .smenu-fav-btn {
        transition: none;
    }

    .smenu-skeleton .bar {
        animation: none;
    }
}

/* ── Mobile ── */
@media (max-width: 640px) {
    .smenu-panel {
        width: 100vw;
        border-radius: 0;
    }

    .smenu-rail,
    .smenu-skeleton-rail {
        width: 150px;
    }

    .smenu-rail-item,
    .smenu-page {
        font-size: 0.875rem;
    }

    .smenu-rail-hint {
        display: none;
    }

    .smenu-pane {
        padding: 16px;
    }

    .smenu-sections,
    .smenu-skeleton-pane {
        grid-template-columns: minmax(0, 1fr);
        gap: 20px;
    }

    .smenu-kbd-hints {
        display: none;
    }
}

/* ========================================
   PERSISTENT BACKDROP CLEANUP
   ======================================== */

.lg-backdrop:not(.in),
.lg-backdrop.in:not(.lg-visible) {
    display: none !important;
    pointer-events: none !important;
}

div.swal2-container:not(.swal2-backdrop-show):not(.swal2-center):not(.swal2-shown) {
    display: none !important;
    pointer-events: none !important;
}

.modal-backdrop.fade.show:not([data-active-modal]) {
    opacity: 0 !important;
    pointer-events: none !important;
    z-index: -1 !important;
}

body.modal-open .modal-backdrop.fade.show {
    opacity: 0.5 !important;
    pointer-events: auto !important;
    z-index: 1050 !important;
}

.modal-backdrop.fade.show:empty:not(.modal-backdrop-active) {
    display: none !important;
}

body.modal-open .lg-backdrop,
body.modal-open div.swal2-container:not(.swal2-backdrop-show) {
    z-index: 1040 !important;
}
