/* @define CollapsibleSection */
.CollapsibleSection {
    border: 1px solid #ced4da;
    border-radius: 4px;
    margin-bottom: 15px;
}

.CollapsibleSection-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
}

.CollapsibleSection-header.is-enabled {
    cursor: pointer;
}

.CollapsibleSection-sectionHeaderLeft {
    display: flex;
    align-items: center;
}

.CollapsibleSection-expanderButton,
.CollapsibleSection-expanderButton:hover,
.CollapsibleSection-expanderButton:active {
    color: inherit !important; /* Would otherwise be overridden by Btn.css */
    padding: 3px 0 0;
    flex-shrink: 0;
}

.CollapsibleSection-chevron {
    font-size: 19px;
    transform: rotate(0);
    transition: transform 0.2s;
}

.CollapsibleSection-expanded .CollapsibleSection-chevron {
    transform: rotate(90deg);
}

.CollapsibleSection-headerText {
    margin: 0 0 0 5px;
    line-clamp: 2;
    -webkit-line-clamp: 2;
    overflow: hidden;
    text-wrap: wrap;
    display: -webkit-box;
    -webkit-box-orient: vertical;
}

.CollapsibleSection-headerContent {
    display: flex;
    align-items: center;
    min-width: 0;
}

.CollapsibleSection-validationIndicator {
    margin-left: 8px;
    flex-shrink: 0;
}

.CollapsibleSection-sectionHeaderRight {
    cursor: default;
    flex-shrink: 0;
}

.CollapsibleSection-body {
    padding: 0 15px 15px;
}

/** Card variant overrides **/
.CollapsibleSection-card {
    background-color: var(--surface-default);
    border: 0;
    border-left: var(--border-sm) solid var(--border-dayshape);
    border-radius: var(--border-radius-lg);
    box-shadow: 0 1px 2px rgb(0 0 0 / 8%);
    margin-bottom: 0;
}

.CollapsibleSection-card .CollapsibleSection-header {
    padding: var(--padding-sm) var(--padding-lg);
}

/* 4px top + header's 12px bottom = 16px title-to-body gap (spacing-4-P3). */
.CollapsibleSection-card .CollapsibleSection-body {
    padding: var(--padding-xxs) var(--padding-lg) var(--padding-lg);
}

/* CSS-only flex reorder — chevron visually appears on the RIGHT of the header
   text for the card variant. DOM structure is unchanged so existing tests and
   accessibility semantics are preserved. The sectionHeaderRight slot is a
   sibling of sectionHeaderLeft and is unaffected. */
.CollapsibleSection-card .CollapsibleSection-sectionHeaderLeft {
    flex-direction: row-reverse;
    justify-content: space-between;
    flex: 1;
}

/* With row-reverse the headerText sits visually to the LEFT of the chevron,
   so flip the existing left margin onto the right side to preserve spacing. */
.CollapsibleSection-card .CollapsibleSection-headerText {
    margin: 0 5px 0 0;
    font-size: var(--font-size-h4);
    color: var(--text-default);
}

/* Suppress the global rotate(90deg) for the card variant — the card uses
   class-swap (fa-chevron-down / fa-chevron-up) for its expanded-state icon,
   so the chevron element should never be rotated. */
.CollapsibleSection-card .CollapsibleSection-chevron {
    transform: none;
}

/* In the card variant the chevron reads as a self-contained icon button, so it gets a
   square hit area with a subtle hover/active surface instead of the underline it would
   otherwise inherit from the "link" Btn variant. Padding is repeated on the interactive
   states so it isn't reset by the base :hover/:active rule above. */
.CollapsibleSection-card .CollapsibleSection-expanderButton,
.CollapsibleSection-card .CollapsibleSection-expanderButton:hover,
.CollapsibleSection-card .CollapsibleSection-expanderButton:active,
.CollapsibleSection-card .CollapsibleSection-expanderButton:focus {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border-radius: var(--border-radius-default);
    text-decoration: none;
}

/* !important is required to beat the `bg-transparent` utility the link Btn variant applies. */
.CollapsibleSection-card .CollapsibleSection-expanderButton:hover {
    background-color: var(--surface-container-hover) !important;
}

.CollapsibleSection-card .CollapsibleSection-expanderButton:active {
    background-color: var(--surface-container-selected) !important;
}

/* Mouse users get the hover surface only; keyboard users still get a clear focus ring. */
.CollapsibleSection-card .CollapsibleSection-expanderButton:focus {
    box-shadow: none;
    outline: none;
}

.CollapsibleSection-card .CollapsibleSection-expanderButton:focus-visible {
    box-shadow: 0 0 0 2px var(--primary);
    outline: none;
}

/** Sidebar variant overrides **/
.CollapsibleSection-sidebar {
    border-radius: 0;
    margin-bottom: 0;
    border-width: 1px 0 0;
    border-color: var(--border-subtle);
}

.CollapsibleSection-sidebar:last-child {
    border-bottom-width: 1px; /* gives the last list item a bottom border */
}

.CollapsibleSection-sidebar .CollapsibleSection-header {
    padding: 12px 0.5rem;
    align-items: baseline;
    color: var(--text-accent);
    text-transform: uppercase;
}

.CollapsibleSection-sidebar .CollapsibleSection-header.is-enabled:hover {
    background-color: var(--border-subtle);
}

.CollapsibleSection-sidebar .CollapsibleSection-header:not(.is-enabled) {
    background-color: var(--text-white);
    color: var(--text-disabled);
}

.CollapsibleSection-sidebar .CollapsibleSection-sectionHeaderLeft {
    align-items: baseline;
}

.CollapsibleSection-sidebar .CollapsibleSection-chevron {
    font-size: 1rem;
}

.CollapsibleSection-sidebar .CollapsibleSection-header:not(.is-enabled) .CollapsibleSection-chevron {
    visibility: hidden;
}

.CollapsibleSection-sidebar .CollapsibleSection-body {
    padding: 0;
}
