.msc-departments {
    clear: both;
    margin: 1.25rem 0 2rem;
}

.msc-departments__desktop { display: block; }
.msc-departments__mobile { display: none; }

.msc-departments__desktop-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 22px;
    position: relative;
}

.msc-department {
    min-width: 0;
    background: #fff;
    border: 1px solid rgba(0, 0, 0, 0.12);
    border-radius: 7px;
}

.msc-department--desktop {
    position: relative;
    overflow: visible;
    z-index: 1;
}

.msc-department--desktop.is-open { z-index: 30; }

.msc-department__primary-link,
.msc-department__mobile-primary {
    color: inherit;
    text-decoration: none;
}

.msc-department__primary-link {
    display: block;
    overflow: hidden;
    border-radius: 7px;
    background: #fff;
}

.msc-department__primary-link:hover .msc-department__title,
.msc-department__primary-link:focus .msc-department__title {
    text-decoration: underline;
}

.msc-department__image {
    display: block;
    overflow: hidden;
    background: #f6f4f1;
}

.msc-department__image--desktop {
    aspect-ratio: 4 / 3;
    padding: 8px;
}

.msc-department__img,
.msc-department__image img,
.msc-department__term-img {
    display: block;
    width: 100%;
    height: 100%;
    margin: 0;
    object-fit: contain;
}

.msc-department__desktop-title-row,
.msc-department__mobile-title-row {
    display: flex;
    min-width: 0;
    flex-direction: column;
    justify-content: center;
}

.msc-department__desktop-title-row {
    min-height: 58px;
    padding: 12px 48px 12px 14px;
}

.msc-department__title {
    font-size: 17px;
    line-height: 1.25;
    font-weight: 700;
}

.msc-department__desktop-toggle,
.msc-department__mobile-toggle {
    border: 0;
    background: transparent;
    color: inherit;
    cursor: pointer;
}

.msc-department__desktop-toggle {
    position: absolute;
    right: 0;
    bottom: 0;
    z-index: 2;
    display: flex;
    width: 46px;
    height: 58px;
    align-items: center;
    justify-content: center;
    border-left: 1px solid rgba(0, 0, 0, .08);
}

.msc-department__desktop-toggle:hover,
.msc-department__desktop-toggle:focus,
.msc-department__mobile-toggle:hover,
.msc-department__mobile-toggle:focus {
    background: rgba(0, 0, 0, .05);
}

.msc-department__chevron {
    width: 10px;
    height: 10px;
    flex: 0 0 auto;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg) translateY(-2px);
    transition: transform .18s ease;
}

.msc-department.is-open .msc-department__chevron {
    transform: rotate(225deg) translate(-2px, -2px);
}

/* Desktop mega flyout. It floats over the grid so opening it does not shift the page. */
.msc-department__desktop-panel {
    position: absolute;
    z-index: 50;
    top: calc(100% + 10px);
    left: 0;
    width: min(650px, calc(100vw - 48px));
    padding: 18px;
    border: 1px solid rgba(0, 0, 0, .16);
    border-radius: 9px;
    background: #fff;
    box-shadow: 0 14px 35px rgba(0, 0, 0, .20);
    opacity: 0;
    transform: translateY(8px);
    transition: opacity .16s ease, transform .16s ease;
}

.msc-department--desktop:nth-child(3n+2) .msc-department__desktop-panel {
    left: 50%;
    transform: translate(-50%, 8px);
}

.msc-department--desktop:nth-child(3n) .msc-department__desktop-panel {
    right: 0;
    left: auto;
}

.msc-department--desktop.is-open .msc-department__desktop-panel {
    opacity: 1;
    transform: translateY(0);
}

.msc-department--desktop:nth-child(3n+2).is-open .msc-department__desktop-panel {
    transform: translate(-50%, 0);
}


/* Viewport-aware desktop flyouts can open above cards in the bottom rows. */
.msc-department--desktop.opens-up .msc-department__desktop-panel {
    top: auto;
    bottom: calc(100% + 10px);
    transform: translateY(-8px);
}

.msc-department--desktop:nth-child(3n+2).opens-up .msc-department__desktop-panel {
    transform: translate(-50%, -8px);
}

.msc-department--desktop.opens-up.is-open .msc-department__desktop-panel {
    transform: translateY(0);
}

.msc-department--desktop:nth-child(3n+2).opens-up.is-open .msc-department__desktop-panel {
    transform: translate(-50%, 0);
}

.msc-department__desktop-panel[hidden] { display: none !important; }

.msc-department__desktop-panel-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
    margin-bottom: 14px;
    padding-bottom: 14px;
    border-bottom: 1px solid rgba(0, 0, 0, .10);
}

.msc-department__desktop-panel-header > div {
    min-width: 0;
}

.msc-department__panel-heading {
    min-width: 0;
    font-size: 20px;
    line-height: 1.2;
    font-weight: 700;
    word-break: normal;
    overflow-wrap: break-word;
    white-space: normal;
}

.msc-department__panel-help {
    margin-top: 4px;
    color: #666;
    font-size: 13px;
}

.msc-department__shop-all-button,
.msc-department__mobile-shop-all {
    font-weight: 700;
    text-decoration: none;
}

.msc-department__shop-all-button {
    justify-self: start;
    max-width: 100%;
    padding: 10px 14px;
    border: 1px solid currentColor;
    border-radius: 5px;
    color: inherit;
    line-height: 1.3;
    white-space: normal;
    overflow-wrap: break-word;
}

.msc-department__shop-all-button:hover,
.msc-department__shop-all-button:focus {
    background: rgba(0, 0, 0, .06);
}

.msc-department__term-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    max-height: 470px;
    overflow-y: auto;
    padding: 2px;
}

.msc-department__term-tile {
    display: grid;
    grid-template-columns: 72px minmax(0, 1fr);
    min-height: 78px;
    overflow: hidden;
    border: 1px solid rgba(0, 0, 0, .10);
    border-radius: 6px;
    color: inherit;
    text-decoration: none;
    background: #fff;
}

.msc-department__term-tile:hover,
.msc-department__term-tile:focus {
    border-color: rgba(0, 0, 0, .32);
    background: rgba(0, 0, 0, .025);
}

.msc-department__term-image {
    display: block;
    min-height: 78px;
    padding: 5px;
    background: #f6f4f1;
}

.msc-department__term-copy {
    display: flex;
    min-width: 0;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    padding: 9px 10px;
}

.msc-department__term-name {
    font-size: 14px;
    line-height: 1.25;
    font-weight: 650;
}

.msc-department__count {
    color: #666;
    font-size: 12px;
}

/* Mobile is a separate split-action component: tap the main area to shop all,
   or the arrow to browse subcategories. */
@media (max-width: 900px) {
    .msc-departments__desktop { display: none !important; }

    .msc-departments__mobile {
        display: grid !important;
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .msc-department--mobile { overflow: hidden; }

    .msc-department__mobile-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) 62px;
        min-height: 110px;
    }

    .msc-department__mobile-primary {
        display: grid;
        grid-template-columns: 118px minmax(0, 1fr);
        min-width: 0;
    }

    .msc-department__mobile-primary:hover .msc-department__title,
    .msc-department__mobile-primary:focus .msc-department__title {
        text-decoration: underline;
    }

    .msc-department__image--mobile {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 118px;
        min-height: 110px;
        padding: 7px;
        border-right: 1px solid rgba(0, 0, 0, 0.08);
    }

    .msc-department__image--mobile .msc-department__img,
    .msc-department__image--mobile img {
        width: 100%;
        height: 100%;
        max-height: 104px;
        object-fit: contain;
    }

    .msc-department__mobile-title-row {
        min-height: 110px;
        padding: 15px 16px;
    }

    .msc-department__mobile-title-row .msc-department__title {
        font-size: 18px;
    }

    .msc-department__shop-all-hint {
        margin-top: 7px;
        color: #666;
        font-size: 12px;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: .03em;
    }

    .msc-department__mobile-toggle {
        display: flex;
        width: 62px;
        align-items: center;
        justify-content: center;
        border-left: 1px solid rgba(0, 0, 0, .10);
    }

    .msc-department__mobile-panel {
        border-top: 1px solid rgba(0, 0, 0, 0.1);
        background: #fff;
    }

    .msc-department__mobile-panel[hidden] { display: none !important; }

    .msc-department__mobile-shop-all {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        padding: 14px 16px;
        border-bottom: 1px solid rgba(0, 0, 0, .10);
        color: inherit;
        background: rgba(0, 0, 0, .035);
    }

    .msc-department__mobile-links {
        list-style: none;
        margin: 0;
        padding: 0;
    }

    .msc-department__mobile-links li { margin: 0; padding: 0; }

    .msc-department__mobile-links a {
        display: grid;
        grid-template-columns: 54px minmax(0, 1fr) auto;
        align-items: center;
        gap: 12px;
        min-height: 62px;
        padding: 7px 14px 7px 8px;
        border-bottom: 1px solid rgba(0, 0, 0, .08);
        color: inherit;
        text-decoration: none;
    }

    .msc-department__mobile-links li:last-child a { border-bottom: 0; }

    .msc-department__mobile-links a:hover,
    .msc-department__mobile-links a:focus {
        background: rgba(0, 0, 0, .04);
    }

    .msc-department__mobile-term-image {
        display: block;
        width: 54px;
        height: 48px;
        padding: 3px;
        background: #f6f4f1;
    }

    .msc-department__mobile-term-image img {
        width: 100%;
        height: 100%;
        object-fit: contain;
    }

    .msc-department__mobile-term-name {
        min-width: 0;
        font-weight: 600;
        line-height: 1.25;
    }
}

@media (max-width: 420px) {
    .msc-department__mobile-row {
        grid-template-columns: minmax(0, 1fr) 54px;
        min-height: 94px;
    }

    .msc-department__mobile-primary {
        grid-template-columns: 96px minmax(0, 1fr);
    }

    .msc-department__image--mobile {
        width: 96px;
        min-height: 94px;
        padding: 6px;
    }

    .msc-department__image--mobile .msc-department__img,
    .msc-department__image--mobile img { max-height: 88px; }

    .msc-department__mobile-title-row {
        min-height: 94px;
        padding: 12px 14px;
    }

    .msc-department__mobile-toggle { width: 54px; }
}
