/* ============================================================================
   PR 7 - sidebar
   Per DOCS/ci3-theme-migration/LAYOUT_RECONSTRUCTION_GUIDE.md § 4.2.
   Scoped under body.theme-new so the legacy admin (flag off) is untouched.
   ============================================================================ */

body.theme-new .app-sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    width: var(--sidebar-width);
    height: calc(100vh - var(--header-height));
    overflow-y: auto;
    overflow-x: hidden;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-soft);
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.25);
    z-index: 1020;
    transition: width var(--transition-speed) ease,
                transform var(--transition-speed) ease;
}

body.theme-new .app-sidebar__inner {
    padding: 12px 0 24px;
}

/* ----- Search ----- */
body.theme-new .app-sidebar__search {
    position: relative;
    margin: 4px 12px 12px;
}
body.theme-new .app-sidebar__search i {
    position: absolute;
    left: 10px; top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 13px;
    pointer-events: none;
}
body.theme-new .app-sidebar__search input {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    color: var(--text-main);
    border-radius: var(--radius-sm);
    padding: 7px 10px 7px 32px;
    font-size: 13px;
    outline: 0;
    transition: border-color var(--transition-speed) ease,
                box-shadow var(--transition-speed) ease;
}
body.theme-new .app-sidebar__search input::placeholder {
    color: var(--input-placeholder);
}
body.theme-new .app-sidebar__search input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-focus);
}

/* ----- Section title ----- */
body.theme-new .app-sidebar__section-title {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    padding: 14px 20px 6px;
}

/* ----- Lists ----- */
body.theme-new .app-sidebar__list {
    list-style: none;
    margin: 0;
    padding: 0;
}

/* ----- Items ----- */
body.theme-new .app-sidebar__item {
    position: relative;
}

body.theme-new .app-sidebar__link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    margin: 2px 8px;
    color: var(--text-main);
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    transition: background var(--transition-speed) ease,
                color var(--transition-speed) ease;
    white-space: nowrap;
}
body.theme-new .app-sidebar__link:hover,
body.theme-new .app-sidebar__link:focus {
    background: var(--primary-tint);
    color: var(--primary-color);
    text-decoration: none;
}

body.theme-new .app-sidebar__icon {
    font-size: 16px;
    width: 18px;
    text-align: center;
    flex-shrink: 0;
}

body.theme-new .app-sidebar__icon-img,
body.theme-new .app-sidebar__icon-lord {
    width: 22px !important;
    height: 22px !important;
    flex-shrink: 0;
    object-fit: contain;
}

body.theme-new .app-sidebar__label {
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Right-side badge */
body.theme-new .app-sidebar__badge {
    margin-left: auto;
    font-size: 10px !important;
    font-weight: 600;
    padding: 2px 7px !important;
    border-radius: 999px;
}

/* Chevron rotates when expanded (BS3 sets aria-expanded automatically).
   Synced with the submenu's 0.55s ease-out-soft for a unified feel. */
body.theme-new .app-sidebar__chevron {
    font-size: 10px;
    color: var(--text-muted);
    margin-left: 6px;
    transition: transform 0.55s var(--ease-out-soft);
}
body.theme-new .app-sidebar__link[aria-expanded="true"] .app-sidebar__chevron {
    transform: rotate(180deg);
}

/* ----- Active state ----- */
body.theme-new .app-sidebar__item.is-active > .app-sidebar__link,
body.theme-new .app-sidebar__item.active > .app-sidebar__link {
    background: var(--primary-color);
    color: #fff;
    box-shadow: 0 4px 12px var(--primary-focus);
}
body.theme-new .app-sidebar__item.is-active > .app-sidebar__link .app-sidebar__icon,
body.theme-new .app-sidebar__item.is-active > .app-sidebar__link .app-sidebar__chevron,
body.theme-new .app-sidebar__item.active > .app-sidebar__link .app-sidebar__icon,
body.theme-new .app-sidebar__item.active > .app-sidebar__link .app-sidebar__chevron {
    color: #fff;
}

body.theme-new .app-sidebar__list--sub .app-sidebar__item.is-active > .app-sidebar__link,
body.theme-new .app-sidebar__list--sub .app-sidebar__item.active > .app-sidebar__link {
    background: var(--primary-700);
    color: #fff;
}

/* ----- Submenu (BS3 .collapse) -----
   Override BS3's default `.collapsing { transition: height .35s ease }`
   with a softer ease-out so the menu unfurls instead of snapping. */
body.theme-new .app-sidebar__submenu {
    position: relative;
    margin: 2px 16px 6px 28px;
}

body.theme-new .app-sidebar__submenu.collapsing {
    transition: height 0.55s var(--ease-out-soft) !important;
}

body.theme-new .app-sidebar__submenu::before {
    content: '';
    position: absolute;
    left: -8px; top: 4px; bottom: 4px;
    width: 2px;
    background: var(--primary-color);
    opacity: 0.35;
    border-radius: 2px;
    transform-origin: top;
    transform: scaleY(0);
    transition: transform 0.6s var(--ease-out-soft);
}
body.theme-new .app-sidebar__submenu.in::before,
body.theme-new .app-sidebar__submenu.collapsing::before {
    transform: scaleY(1);
}

/* Items inside the submenu fade + slide in once expanded.
   Use BS3's `.in` class as the trigger. Longer duration + bigger
   nth-child step so the cascade is visible instead of a quick blur. */
body.theme-new .app-sidebar__submenu .app-sidebar__item {
    opacity: 0;
    transform: translateX(-6px);
    transition: opacity 0.4s var(--ease-out-soft),
                transform 0.4s var(--ease-out-soft);
}
body.theme-new .app-sidebar__submenu.in .app-sidebar__item {
    opacity: 1;
    transform: translateX(0);
}
body.theme-new .app-sidebar__submenu.in .app-sidebar__item:nth-child(1)  { transition-delay: 0.08s; }
body.theme-new .app-sidebar__submenu.in .app-sidebar__item:nth-child(2)  { transition-delay: 0.13s; }
body.theme-new .app-sidebar__submenu.in .app-sidebar__item:nth-child(3)  { transition-delay: 0.18s; }
body.theme-new .app-sidebar__submenu.in .app-sidebar__item:nth-child(4)  { transition-delay: 0.23s; }
body.theme-new .app-sidebar__submenu.in .app-sidebar__item:nth-child(5)  { transition-delay: 0.28s; }
body.theme-new .app-sidebar__submenu.in .app-sidebar__item:nth-child(6)  { transition-delay: 0.33s; }
body.theme-new .app-sidebar__submenu.in .app-sidebar__item:nth-child(7)  { transition-delay: 0.38s; }
body.theme-new .app-sidebar__submenu.in .app-sidebar__item:nth-child(n+8) { transition-delay: 0.43s; }

body.theme-new .app-sidebar__link--sub {
    padding: 7px 10px;
    margin: 1px 0;
    font-size: 13.5px;
    color: var(--text-muted);
}
body.theme-new .app-sidebar__link--sub:hover {
    color: var(--primary-color);
    background: transparent;
}

/* ----- Collapsed (desktop icon-rail) ----- */
body.theme-new.sidebar-collapsed .app-sidebar { width: var(--sidebar-collapsed-width); }
body.theme-new.sidebar-collapsed .app-sidebar:hover { width: var(--sidebar-width); }

body.theme-new.sidebar-collapsed .app-sidebar:not(:hover) .app-sidebar__label,
body.theme-new.sidebar-collapsed .app-sidebar:not(:hover) .app-sidebar__badge,
body.theme-new.sidebar-collapsed .app-sidebar:not(:hover) .app-sidebar__chevron,
body.theme-new.sidebar-collapsed .app-sidebar:not(:hover) .app-sidebar__section-title,
body.theme-new.sidebar-collapsed .app-sidebar:not(:hover) .app-sidebar__search,
body.theme-new.sidebar-collapsed .app-sidebar:not(:hover) .app-sidebar__submenu { display: none; }


body.theme-new.sidebar-collapsed .app-sidebar:not(:hover) .app-sidebar__link {
    justify-content: center;
    padding: 12px 10px;
    margin: 2px 8px;
}

/* Hover-fly-out tooltip when collapsed (label appears on hover) */
body.theme-new.sidebar-collapsed .app-sidebar__link {
    position: relative;
}
body.theme-new.sidebar-collapsed .app-sidebar:not(:hover) .app-sidebar__link[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 8px);
    top: 50%;
    transform: translateY(-50%);
    background: var(--bg-card);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 12px;
    white-space: nowrap;
    box-shadow: var(--shadow-soft);
    z-index: 1050;
    pointer-events: none;
}

/* ----- Mobile drawer ----- */
@media (max-width: 991.98px) {
    body.theme-new .app-sidebar {
        left: -100% !important;
        width: 100% !important;
        top: var(--header-height-mobile) !important;
        height: calc(100vh - var(--header-height-mobile)) !important;
        transform: none !important;
        transition: left var(--transition-speed) ease !important;
    }
    body.theme-new.sidebar-open .app-sidebar {
        left: 0 !important;
    }
}

/* Mobile overlay */
body.theme-new .app-sidebar__overlay {
    position: fixed;
    inset: 0;
    top: var(--header-height);
    background: rgba(0, 0, 0, 0.55);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-speed) ease,
                visibility var(--transition-speed) ease;
    z-index: 1019;
}
@media (max-width: 991.98px) {
    body.theme-new .app-sidebar__overlay { top: var(--header-height-mobile); }
    body.theme-new.sidebar-open .app-sidebar__overlay {
        opacity: 1;
        visibility: visible;
    }
}

/* Custom scrollbar */
body.theme-new .app-sidebar::-webkit-scrollbar { width: 6px; }
body.theme-new .app-sidebar::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 6px;
}

@media (prefers-reduced-motion: reduce) {
    body.theme-new .app-sidebar,
    body.theme-new .app-sidebar__link,
    body.theme-new .app-sidebar__chevron,
    body.theme-new .app-sidebar__overlay,
    body.theme-new .app-sidebar__submenu.collapsing,
    body.theme-new .app-sidebar__submenu::before,
    body.theme-new .app-sidebar__submenu .app-sidebar__item {
        transition: none !important;
    }
    body.theme-new .app-sidebar__submenu .app-sidebar__item {
        opacity: 1 !important;
        transform: none !important;
    }
    body.theme-new .app-sidebar__submenu::before {
        transform: scaleY(1) !important;
    }
}

/* ============================================================================
   PR 7 D.6 - enhanced sidebar search
   Per DOCS/SIDEBAR_SEARCH_HOWTO.md. Adds:
   - clear button (X) inside the input
   - yellow highlight pill on matched substrings
   - "no results" row
   - inline injection of Setup-customizer matches with a green divider
   ============================================================================ */

/* Make the search wrapper positioned so the clear button can absolute */
body.theme-new .app-sidebar__search {
    position: relative;
}

/* Clear button (X) - shown only when input has a value (toggled by layout.js
   via the .is-visible class) */
body.theme-new .app-sidebar__search-clear {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: 0;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 6px;
    font-size: 12px;
    line-height: 1;
    border-radius: 4px;
    display: none;
}
body.theme-new .app-sidebar__search-clear.is-visible {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
body.theme-new .app-sidebar__search-clear:hover {
    color: var(--primary-color);
    background: var(--primary-tint);
}

/* Reserve room on the right of the input so it doesn't overlap the X */
body.theme-new .app-sidebar__search input.is-cleanable,
body.theme-new .app-sidebar__search-clear.is-visible ~ input {
    padding-right: 32px !important;
}
body.theme-new .app-sidebar__search input {
    padding-right: 10px;
}

/* Hidden-by-search swap (replaces the previous style.display = 'none') */
body.theme-new .app-sidebar__item.hidden-by-search,
body.theme-new #setup-menu li.hidden-by-search {
    display: none !important;
}

/* Yellow highlight pill on matched substrings */
body.theme-new mark.sidebar-search-highlight {
    background: #facc15;
    color: #1e293b;
    padding: 1px 3px;
    border-radius: 3px;
    font-weight: 600;
    font-style: normal;
    text-decoration: none;
    line-height: 1;
}

/* "No results found" row at the bottom of the menu list */
body.theme-new .app-sidebar__no-results {
    padding: 16px 14px;
    color: var(--text-muted);
    font-size: 13px;
    font-style: italic;
    text-align: center;
}

/* Inline Setup search results - divider header */
body.theme-new .setup-search-divider {
    padding: 10px 15px 4px;
    margin: 10px 8px 0;
    border-top: 1px solid var(--border-soft);
    pointer-events: none;
    list-style: none;
}
body.theme-new .setup-search-divider-text {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--primary-color);
    opacity: 0.85;
}
body.theme-new .setup-search-divider-text i {
    margin-right: 6px;
    font-size: 11px;
    color: var(--primary-color);
}

/* Inline Setup search results - result rows */
body.theme-new .setup-search-result > a {
    display: flex !important;
    align-items: center;
    gap: 8px;
    padding: 7px 14px !important;
    margin: 1px 8px !important;
    color: var(--text-muted) !important;
    font-size: 13px;
    text-decoration: none;
    border-radius: 6px;
    background: transparent !important;
    height: auto !important;
    width: auto !important;
    justify-content: flex-start !important;
    border-radius: 6px !important;
}
body.theme-new .setup-search-result > a:hover,
body.theme-new .setup-search-result > a:focus {
    background: var(--primary-tint) !important;
    color: var(--primary-color) !important;
}
body.theme-new .setup-search-result .app-sidebar__label {
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ============================================================================
   PR 7 PHASE F - sidebar polish
   - F.4 sidebar item cascade entrance on body.pp-mounted
   - F.6 gentle pulse on the active sidebar item
   ============================================================================ */

/* F.4 — Sidebar item cascade ------------------------------------------------
   Each top-level sidebar item slides in from the left with a 40 ms stagger
   once body.pp-mounted lands. The search row, no-results row, and setup
   item are excluded so they don't visually compete. */
body.theme-new .app-sidebar__list > .app-sidebar__item {
    opacity: 0;
    transform: translateX(-14px);
    transition:
        opacity 0.4s var(--ease-out-soft),
        transform 0.4s var(--ease-out-soft);
}
body.theme-new.pp-mounted .app-sidebar__list > .app-sidebar__item {
    opacity: 1;
    transform: translateX(0);
}

body.theme-new.pp-mounted .app-sidebar__list > .app-sidebar__item:nth-child(1)  { transition-delay: 180ms; }
body.theme-new.pp-mounted .app-sidebar__list > .app-sidebar__item:nth-child(2)  { transition-delay: 220ms; }
body.theme-new.pp-mounted .app-sidebar__list > .app-sidebar__item:nth-child(3)  { transition-delay: 260ms; }
body.theme-new.pp-mounted .app-sidebar__list > .app-sidebar__item:nth-child(4)  { transition-delay: 300ms; }
body.theme-new.pp-mounted .app-sidebar__list > .app-sidebar__item:nth-child(5)  { transition-delay: 340ms; }
body.theme-new.pp-mounted .app-sidebar__list > .app-sidebar__item:nth-child(6)  { transition-delay: 380ms; }
body.theme-new.pp-mounted .app-sidebar__list > .app-sidebar__item:nth-child(7)  { transition-delay: 420ms; }
body.theme-new.pp-mounted .app-sidebar__list > .app-sidebar__item:nth-child(8)  { transition-delay: 460ms; }
body.theme-new.pp-mounted .app-sidebar__list > .app-sidebar__item:nth-child(9)  { transition-delay: 500ms; }
body.theme-new.pp-mounted .app-sidebar__list > .app-sidebar__item:nth-child(10) { transition-delay: 540ms; }
body.theme-new.pp-mounted .app-sidebar__list > .app-sidebar__item:nth-child(11) { transition-delay: 580ms; }
body.theme-new.pp-mounted .app-sidebar__list > .app-sidebar__item:nth-child(12) { transition-delay: 620ms; }
body.theme-new.pp-mounted .app-sidebar__list > .app-sidebar__item:nth-child(13) { transition-delay: 660ms; }
body.theme-new.pp-mounted .app-sidebar__list > .app-sidebar__item:nth-child(14) { transition-delay: 700ms; }
body.theme-new.pp-mounted .app-sidebar__list > .app-sidebar__item:nth-child(15) { transition-delay: 740ms; }
body.theme-new.pp-mounted .app-sidebar__list > .app-sidebar__item:nth-child(n+16) { transition-delay: 780ms; }

/* The no-results row never cascades — keep it ready to fire on search */
body.theme-new .app-sidebar__list > #top-search-no-results {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
}

/* F.6 — Active item gentle pulse -------------------------------------------
   The active green pill gets a slow shadow pulse every 5s so the
   current location stays visible even as the user scans the menu.
   Starts only after .pp-mounted to avoid competing with the cascade. */
@keyframes ppActivePulse {
    0%, 100% { box-shadow: 0 4px 12px var(--primary-focus); }
    50%      { box-shadow: 0 4px 22px var(--primary-glow); }
}

body.theme-new.pp-mounted .app-sidebar__item.is-active > .app-sidebar__link,
body.theme-new.pp-mounted .app-sidebar__item.active > .app-sidebar__link {
    animation: ppActivePulse 5s var(--ease-out-soft) infinite;
    animation-delay: 1.2s; /* let the cascade settle before the pulse starts */
}

@media (prefers-reduced-motion: reduce) {
    body.theme-new .app-sidebar__list > .app-sidebar__item {
        opacity: 1 !important;
        transform: none !important;
        transition: none !important;
    }
    body.theme-new .app-sidebar__item.is-active > .app-sidebar__link,
    body.theme-new .app-sidebar__item.active > .app-sidebar__link {
        animation: none !important;
    }
}
