/*
 * Creative Tagger application shell v2.
 *
 * The class gate preserves the current 232px text-sidebar fallback while the
 * classic-script decomposition is underway. 10-shell-v2.js applies the class
 * before boot whenever the v2 flag is on.
 */

.ctv2-rail-logo-wrap,
.ctv2-rail-account {
    display: none;
}

#appMain.ctv2-shell-enabled {
    background: var(--color-paper, #ffffff);
}

/* Creatives owns its own desktop scrollports. Clip the shell itself so the
 * Library's internal rail/content overflow cannot become a second page-level
 * scroll past the viewport bottom. Other screens retain the shared shell's
 * normal overflow behavior. */
#appMain.ctv2-shell-enabled[data-active-screen="creatives"] {
    overflow: hidden;
}

html.ctv2-creatives-viewport-lock {
    overflow-y: hidden;
}

html.ctv2-creatives-viewport-lock body {
    overflow: hidden;
}

#appMain.ctv2-shell-enabled #sidebar {
    width: 64px;
    min-width: 64px;
    z-index: 60;
    align-items: center;
    overflow: visible;
    border-right: 0;
    background: var(--color-panel, #FFFFFF);
    box-shadow: 3px 0 14px rgba(0, 0, 0, .07);
}

#appMain.ctv2-shell-enabled [data-legacy-rail-header] {
    display: none;
}

#appMain.ctv2-shell-enabled .ctv2-rail-logo-wrap {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 16px 0 12px;
}

#appMain.ctv2-shell-enabled .ctv2-logo-tile {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: var(--color-ink, #1b1b1b);
    color: var(--color-paper, #ffffff);
    font-size: 13px;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
}

#appMain.ctv2-shell-enabled .ctv2-logo-tile:focus-visible,
#appMain.ctv2-shell-enabled .navlink:focus-visible,
#appMain.ctv2-shell-enabled .ctv2-account-button:focus-visible {
    outline: 2px solid var(--color-cobalt, #2357D9);
    outline-offset: 2px;
}

#appMain.ctv2-shell-enabled .ctv2-rail-wordmark {
    display: none;
}

#appMain.ctv2-shell-enabled #primaryNavigation {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: 100%;
    min-height: 0;
    padding: 0 0 12px;
    overflow-x: visible;
    overflow-y: auto;
}

#appMain.ctv2-shell-enabled #primaryNavigation .nav-section {
    display: none;
}

#appMain.ctv2-shell-enabled #primaryNavigation .navlink {
    position: relative;
    display: flex;
    flex: 0 0 36px;
    align-items: center;
    justify-content: center;
    gap: 0;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--color-ash, #5c5c5c);
    font-size: 0;
    line-height: 1;
}

#appMain.ctv2-shell-enabled #primaryNavigation .navlink.hidden {
    display: none;
}

#appMain.ctv2-shell-enabled #primaryNavigation .navlink:hover {
    background: var(--color-cream, #f5f5f5);
    color: var(--color-charcoal, #3a3a3a);
}

#appMain.ctv2-shell-enabled #primaryNavigation .navlink.nav-active {
    background: var(--color-cobalt-soft, #E2E9FF);
    color: var(--color-cobalt-ink, #1740A3);
}

#appMain.ctv2-shell-enabled #primaryNavigation .navlink.nav-active .nav-ico {
    color: currentColor;
}

#appMain.ctv2-shell-enabled #primaryNavigation .nav-ico {
    width: 16px;
    height: 16px;
    color: currentColor;
}

/*
 * Rail sequence is real DOM order: prepareAppShellV2() reorders the nav
 * nodes to Home / Creatives / Strategy / Brain / Strategist at boot, so
 * keyboard Tab order matches what the rail shows. CSS `order` overrides
 * used to re-sort visually while leaving focus on the markup order.
 */
#appMain.ctv2-shell-enabled #primaryNavigation [data-screen="brand"] {
    margin-top: 4px;
}

#appMain.ctv2-shell-enabled #primaryNavigation [data-screen="connect"],
#appMain.ctv2-shell-enabled #primaryNavigation > a[href*="creativetagger.ai/help"] {
    display: none;
}

#appMain.ctv2-shell-enabled .nav-badge {
    position: absolute;
    top: -4px;
    right: -5px;
    min-width: 20px;
    height: 20px;
    margin: 0;
    padding: 0 4px;
    border-color: rgba(35, 87, 217, .24);
    background: var(--color-panel, #FFFFFF);
    color: var(--color-cobalt-ink, #1740A3);
    font-size: 11px;
    line-height: 18px;
    text-align: center;
}

#appMain.ctv2-shell-enabled .ctv2-rail-account {
    position: relative;
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 8px 0 20px;
}

#appMain.ctv2-shell-enabled .ctv2-account-button {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    padding: 0;
    border: 1px solid var(--color-rule, #efefef);
    border-radius: 999px;
    background: var(--color-cream, #f5f5f5);
    color: var(--color-charcoal, #3a3a3a);
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
}

#appMain.ctv2-shell-enabled .ctv2-account-button.nav-active {
    border-color: var(--color-cobalt, #2357D9);
    box-shadow: 0 0 0 2px var(--color-cobalt-soft, #E2E9FF);
}

#appMain.ctv2-shell-enabled .ctv2-account-menu {
    position: fixed;
    left: 72px;
    bottom: 16px;
    z-index: 80;
    width: min(300px, calc(100vw - 96px));
    padding: 10px;
    border: 1px solid var(--color-rule, #efefef);
    border-radius: 12px;
    background: var(--color-panel, #FFFFFF);
    box-shadow: 0 22px 56px rgba(30, 28, 25, .18);
}

#appMain.ctv2-shell-enabled .ctv2-account-menu.hidden {
    display: none;
}

#appMain.ctv2-shell-enabled .ctv2-account-menu [data-shell-workspace] {
    padding: 8px 8px 12px;
}

#appMain.ctv2-shell-enabled .ctv2-account-menu [data-shell-workspace] select {
    min-height: 44px;
    background: var(--color-paper, #ffffff);
}

#appMain.ctv2-shell-enabled .ctv2-account-menu [data-shell-account-details] {
    padding: 12px 8px;
    border-top: 1px solid var(--color-rule, #efefef);
}

#appMain.ctv2-shell-enabled .ctv2-account-menu [data-shell-account-details] button {
    display: inline-flex;
    min-width: 44px;
    min-height: 44px;
    align-items: center;
    justify-content: center;
}

#appMain.ctv2-shell-enabled .ctv2-account-actions {
    display: grid;
    gap: 2px;
    padding-top: 8px;
    border-top: 1px solid var(--color-rule, #efefef);
}

#appMain.ctv2-shell-enabled .ctv2-account-actions button,
#appMain.ctv2-shell-enabled .ctv2-account-actions a {
    display: flex;
    width: 100%;
    min-height: 44px;
    align-items: center;
    padding: 9px 8px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--color-charcoal, #3a3a3a);
    font-size: 13px;
    font-weight: 500;
    line-height: 1.2;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

#appMain.ctv2-shell-enabled .ctv2-account-actions button:hover,
#appMain.ctv2-shell-enabled .ctv2-account-actions a:hover {
    background: var(--color-cream, #f5f5f5);
    color: var(--color-ink, #1b1b1b);
}

#appMain.ctv2-shell-enabled #appViewport {
    width: 100%;
    max-width: none;
}

#appMain.ctv2-shell-enabled #appTab-creatives [data-ctv2-empty-kind="first-run"] [data-ctv2-empty-toprow],
#appMain.ctv2-shell-enabled #screen-reports [data-ctv2-empty-kind="first-run"] [data-ctv2-empty-toprow] {
    display: none !important;
}

#appMain.ctv2-shell-enabled #appTab-creatives [data-ctv2-empty-kind="first-run"],
#appMain.ctv2-shell-enabled #screen-reports [data-ctv2-empty-kind="first-run"] {
    padding: 40px 32px 44px !important;
}

#appMain.ctv2-shell-enabled .ctv2-screen-topbar {
    box-sizing: border-box;
    display: flex;
    min-width: 0;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 28px;
    padding: 0 0 16px;
    border-bottom: 1px solid var(--color-rule, #efefef);
}

#appMain.ctv2-shell-enabled .ctv2-screen-breadcrumb {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 8px;
    color: var(--color-charcoal, #3a3a3a);
    font-size: 13px;
}

#appMain.ctv2-shell-enabled .ctv2-screen-breadcrumb-brand {
    min-width: 0;
    max-width: min(42vw, 440px);
    overflow: hidden;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#appMain.ctv2-shell-enabled .ctv2-screen-breadcrumb-separator {
    color: var(--color-stone, #6c6c6c);
}

#appMain.ctv2-shell-enabled .ctv2-screen-breadcrumb-section {
    flex: 0 0 auto;
    color: var(--color-ash, #5c5c5c);
}

#appMain.ctv2-shell-enabled .ctv2-screen-topbar-controls,
#appMain.ctv2-shell-enabled .ctv2-screen-topbar-status {
    display: flex;
    min-width: 0;
    align-items: center;
    justify-content: flex-end;
    gap: 10px 14px;
}

#appMain.ctv2-shell-enabled .ctv2-screen-topbar-controls {
    flex: 0 1 auto;
    flex-wrap: wrap;
}

#appMain.ctv2-shell-enabled .ctv2-screen-topbar button,
#appMain.ctv2-shell-enabled .ctv2-screen-topbar select,
#appMain.ctv2-shell-enabled .ctv2-screen-topbar .ct-daterange-summary,
#appMain.ctv2-shell-enabled #screen-home .ct-daterange-summary {
    min-height: 36px;
}

#appMain.ctv2-shell-enabled .ctv2-screen-topbar button:focus-visible,
#appMain.ctv2-shell-enabled .ctv2-screen-topbar select:focus-visible,
#appMain.ctv2-shell-enabled .ctv2-screen-topbar .ct-daterange-summary:focus-visible {
    outline: 2px solid var(--color-cobalt, #2357D9);
    outline-offset: 2px;
}

@media (min-width: 901px) {
    #appMain.ctv2-shell-enabled #screen-home {
        margin-right: 8px;
        margin-left: 8px;
        padding-bottom: 16px;
    }

    #appMain.ctv2-shell-enabled .ctv2-shell-topbar {
        box-sizing: border-box;
        min-height: 56px;
        margin-top: -28px;
        margin-right: -32px;
        margin-left: -32px;
        padding: 0 32px !important;
        flex-wrap: nowrap !important;
    }

    #appMain.ctv2-shell-enabled #screen-home .ctv2-shell-topbar {
        margin-right: -40px;
        margin-bottom: 40px;
        margin-left: -40px;
        padding-right: 40px !important;
        padding-left: 40px !important;
    }

    #appMain.ctv2-shell-enabled #appTab-creatives .ctv2-shell-topbar {
        padding-right: 28px !important;
        padding-left: 28px !important;
    }

    /*
     * A populated Library is the handoff's three-column shell. Promote its
     * existing 216px report list into the shell grid without changing the
     * screen producer or its mobile one-column fallback.
     */
    #appMain.ctv2-shell-enabled #libraryV2Root.ctv2-lib-loaded {
        display: grid;
        grid-template-columns: 216px minmax(0, 1fr);
        grid-template-rows: auto minmax(0, 1fr);
        height: 100vh;
        min-height: 0;
        margin: -28px -32px;
        overflow: hidden;
    }

    #appMain.ctv2-shell-enabled #libraryV2Root.ctv2-lib-loaded > .ctv2-shell-topbar {
        grid-column: 2;
        grid-row: 1;
        min-width: 0;
        margin: 0 !important;
    }

    #appMain.ctv2-shell-enabled #libraryV2Root.ctv2-lib-loaded > .ctv2-lib-grid {
        display: contents !important;
    }

    #appMain.ctv2-shell-enabled #libraryV2Root.ctv2-lib-loaded > .ctv2-lib-grid > .ctv2-lib-rail {
        grid-column: 1;
        grid-row: 1 / span 2;
        height: 100%;
        min-height: 0;
        overflow-y: auto;
    }

    #appMain.ctv2-shell-enabled #libraryV2Root.ctv2-lib-loaded > .ctv2-lib-grid > :last-child {
        grid-column: 2;
        grid-row: 2;
        min-width: 0;
        min-height: 0;
        padding-right: 32px !important;
        overflow-y: auto;
    }
}

/*
 * Home desktop composition. The rails themselves are breakpoint-independent:
 * the design handoff (screens/home.md §5–6) specifies one rail layout at every
 * width and card count — a left-aligned flex row of `flex: 0 0 244px` cards
 * with a 14px gap that scrolls horizontally — so nothing here may re-lay-out
 * `.ctv2-rail` or resize its cards. A previous wide-screen variant paired the
 * rails two-up and turned each rail into an auto-fit grid; at >=1200px that
 * halved the rail to ~558px and wrapped the cards into rows of two, which is
 * the opposite of the single scrollable row the screen is built around.
 * What stays width-dependent is only the outer measure: the body is capped so
 * it does not sprawl across a large monitor, and the scoreboard is capped
 * independently so With spend / Winning / Losing / Launched do not stretch
 * into four oversized bands.
 */
@media (min-width: 1200px) {
    #appMain.ctv2-shell-enabled #screen-home [data-ctv2-home="1"] {
        max-width: 1216px;
        margin-right: auto;
        margin-left: auto;
    }

    #appMain.ctv2-shell-enabled #screen-home [data-ctv2-home-scoreboard] {
        max-width: 1080px;
        margin-right: auto !important;
        margin-left: auto !important;
        /* Wider desktop columns only — wrapped rows keep the inline 12px gap. */
        column-gap: 16px !important;
    }
}

@media (min-width: 901px) and (max-width: 1199px) {
    #appMain.ctv2-shell-enabled #libraryV2Root.ctv2-lib-loaded {
        grid-template-rows: auto minmax(0, 1fr);
    }

    #appMain.ctv2-shell-enabled #libraryV2Root.ctv2-lib-loaded > .ctv2-shell-topbar {
        padding: 8px 28px !important;
    }

    /* Keep the Library header as one quiet toolbar at tablet widths. The
     * shelf disclosure now lives beside its sort control, so the header can
     * keep search/date/status/settings together without a second wrapped
     * band. */
    #appMain.ctv2-shell-enabled #libraryV2Root .ctv2-lib-header-controls {
        flex-wrap: nowrap;
    }

    #appMain.ctv2-shell-enabled #libraryV2Root .ctv2-lib-search {
        flex: 1 1 160px;
        min-width: 150px !important;
        max-width: 200px;
    }
}

@media (min-width: 1200px) {
    /*
     * The loaded-Library topbar lives in a viewport-locked 56px grid row.
     * Up to ~1440px the controls cluster (status + Table settings + filter
     * + date range) used to wrap internally to a second flex line, and with
     * the bar centered inside 56px the first line rendered clipped above
     * the viewport. Keep one line while preserving the real Meta status;
     * the Search input is the only flexible control and may contract to a
     * compact field. The !important on its min-width beats the renderer's
     * inline min-width:210px.
     */
    #appMain.ctv2-shell-enabled #libraryV2Root .ctv2-shell-topbar {
        flex-wrap: nowrap !important;
    }

    #appMain.ctv2-shell-enabled #libraryV2Root .ctv2-lib-header-breadcrumb {
        flex: 0 1 auto;
        min-width: 0;
        white-space: nowrap;
    }

    #appMain.ctv2-shell-enabled #libraryV2Root .ctv2-lib-header-controls {
        flex: 1 1 0;
        flex-wrap: nowrap !important;
        justify-content: flex-end;
        min-width: 0;
    }

    #appMain.ctv2-shell-enabled #libraryV2Root .ctv2-lib-search {
        flex: 1 1 210px;
        min-width: 64px !important;
        max-width: 240px;
    }

    #appMain.ctv2-shell-enabled #libraryV2Root .ctv2-lib-header-controls [data-ctv2-empty-status] {
        flex: 0 0 auto;
        white-space: nowrap;
    }

    #appMain.ctv2-shell-enabled #libraryV2Root .ctv2-lib-header-controls .ctv2-lib-settings-button {
        flex: 0 0 auto;
    }

    #appMain.ctv2-shell-enabled #libraryV2Root .ctv2-lib-header-controls .ct-daterange {
        flex: 0 0 auto;
    }
}

@media (max-width: 900px) {
    html.ctv2-mobile-nav-open,
    html.ctv2-mobile-nav-open body {
        overflow: hidden;
    }

    #appMain.ctv2-shell-enabled #mobileTopbar {
        padding-right: 18px;
        padding-left: 18px;
    }

    #appMain.ctv2-shell-enabled #mobileMenuButton {
        display: grid;
        min-width: 44px;
        min-height: 44px;
        place-items: center;
        padding: 0;
    }

    #appMain.ctv2-shell-enabled #appViewport {
        padding-right: 18px;
        padding-left: 18px;
    }

    #appMain.ctv2-shell-enabled .ctv2-screen-topbar {
        align-items: flex-start;
        flex-wrap: wrap;
    }

    #appMain.ctv2-shell-enabled .ctv2-screen-breadcrumb {
        max-width: 100%;
    }

    #appMain.ctv2-shell-enabled .ctv2-screen-breadcrumb-brand {
        max-width: min(62vw, 360px);
    }

    #appMain.ctv2-shell-enabled .ctv2-screen-topbar-controls {
        max-width: 100%;
        margin-left: auto;
    }

    /*
     * Home's status + date-range cluster is a nowrap flex row; at 390px its
     * minimum content width exceeded the viewport, so the date-range control
     * (and its open menu) rendered ~55px clipped past the right edge while
     * an ancestor hid the overflow. Let the cluster wrap and never exceed
     * the row, so the date control stays fully visible and tappable.
     */
    #appMain.ctv2-shell-enabled .ctv2-home-topbar-controls {
        flex-wrap: wrap;
        min-width: 0;
        max-width: 100%;
        row-gap: 10px;
    }

    #appMain.ctv2-shell-enabled .ctv2-home-topbar-controls .ct-daterange {
        max-width: 100%;
    }

    #appMain.ctv2-shell-enabled .ctv2-home-topbar-controls .ct-daterange-summary {
        max-width: 100%;
    }

    #appMain.ctv2-shell-enabled .ctv2-screen-topbar button,
    #appMain.ctv2-shell-enabled .ctv2-screen-topbar select,
    #appMain.ctv2-shell-enabled .ctv2-screen-topbar .ct-daterange-summary {
        min-height: 44px;
    }

    #appMain.ctv2-shell-enabled #sidebar {
        width: min(280px, calc(100vw - 40px));
        min-width: min(280px, calc(100vw - 40px));
        align-items: stretch;
        background: var(--color-panel, #FFFFFF);
    }

    #appMain.ctv2-shell-enabled .ctv2-rail-logo-wrap {
        align-items: flex-start;
        justify-content: flex-start;
        padding: 16px 16px 12px;
    }

    #appMain.ctv2-shell-enabled .ctv2-logo-tile {
        width: auto;
        min-width: 44px;
        min-height: 44px;
        gap: 10px;
        padding: 0 10px 0 0;
        background: transparent;
        color: var(--color-ink, #1b1b1b);
    }

    #appMain.ctv2-shell-enabled .ctv2-logo-tile > span:first-child {
        display: grid;
        place-items: center;
        width: 32px;
        height: 32px;
        border-radius: 8px;
        background: var(--color-ink, #1b1b1b);
        color: var(--color-paper, #ffffff);
    }

    #appMain.ctv2-shell-enabled .ctv2-rail-wordmark {
        display: inline;
        font-size: 16px;
        font-weight: 600;
    }

    #appMain.ctv2-shell-enabled #primaryNavigation {
        align-items: stretch;
        gap: 3px;
        padding: 0 12px 12px;
        overflow-y: auto;
    }

    #appMain.ctv2-shell-enabled #primaryNavigation .navlink {
        flex-basis: 44px;
        justify-content: flex-start;
        gap: 12px;
        width: 100%;
        height: 44px;
        padding: 0 12px;
        font-size: 13px;
        line-height: 1.2;
    }

    #appMain.ctv2-shell-enabled #primaryNavigation .navlink[data-screen="brand"] {
        margin-top: 8px;
    }

    #appMain.ctv2-shell-enabled .nav-badge {
        position: static;
        min-width: 20px;
        height: 18px;
        margin-left: auto;
        line-height: 16px;
    }

    #appMain.ctv2-shell-enabled .ctv2-rail-account {
        align-items: flex-start;
        justify-content: flex-start;
        padding: 10px 16px 18px;
        border-top: 1px solid var(--color-rule, #efefef);
    }

    #appMain.ctv2-shell-enabled .ctv2-account-button {
        width: 44px;
        height: 44px;
    }

    #appMain.ctv2-shell-enabled .ctv2-account-menu {
        position: absolute;
        right: 12px;
        bottom: 58px;
        left: 12px;
        width: auto;
        max-height: min(540px, calc(100dvh - 108px));
        overflow-y: auto;
    }
}
