/* The settings layout: a section list on a rail at the left, one pane
   per section at the right, and the action bar under them where the
   form's Save lives. templates/components/settings_layout.html renders
   the rail and the panes; the page supplies the bar. The page runs in
   the pane shell (data-shell="pane", components/table-pane.css): the
   window holds still and the open section scrolls, so the rail and the
   bar stay on screen while a long form moves under them. The rows inside
   a pane are components/settings.css. Colors are tokens only. */

/* ------------------------------------------------------------------ */
/* Action bar: the fixed row under a pane's scrolling region, where a  */
/* form's Save lives. Its seam mirrors the strip's above.              */
/* ------------------------------------------------------------------ */

.pane-actions {
    flex: none;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem 0.75rem;
    padding-top: 0.75rem;
    margin-top: 0.75rem;
    border-top: 1px solid var(--border-normal);
}

.pane-actions__end {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-left: auto;
}

/* Under md a group wider than the bar wraps, its rows kept at the end. */
@media (max-width: 767.98px) {
    .pane-actions__end {
        flex-wrap: wrap;
        justify-content: flex-end;
        gap: 0.5rem 0.75rem;
    }
}

/* --- Unsaved changes ----------------------------------------------- */

/* While settings-defaults.js flags the pane (`data-dirty="true"` on
   the tab pane) the bar says so three ways: a chip with a pinging dot
   at its start, a Discard beside Save, and a ring pulsing off Save.
   Amber for the chip: "not saved" is a different fact from a row's
   blue "off its default" marker, and reads as pending rather than
   wrong. Every piece is CSS off the one attribute, so it survives the
   pane's re-render. */
.unsaved-chip {
    display: none;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3rem 0.8rem 0.3rem 0.65rem;
    border: 1px solid rgba(var(--color-orange-rgb), 0.3);
    border-radius: 999px;
    background: rgba(var(--color-orange-rgb), 0.1);
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.2;
    color: var(--color-orange);
}

.unsaved-chip__dot {
    position: relative;
    flex: none;
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: var(--color-orange);
}

/* The ping: a copy of the dot swelling out and fading, over and over. */
.unsaved-chip__dot::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: inherit;
    animation: unsaved-ping 1.8s cubic-bezier(0, 0, 0.2, 1) infinite;
}

.unsaved-discard {
    display: none;
}

[data-dirty="true"] .unsaved-chip {
    display: inline-flex;
    animation: unsaved-in 0.25s ease-out;
}

[data-dirty="true"] .unsaved-discard {
    display: inline-flex;
    animation: unsaved-in 0.25s ease-out;
}

[data-dirty="true"] .unsaved-save {
    animation: unsaved-pulse 2s ease-out infinite;
}

@keyframes unsaved-in {
    from {
        opacity: 0;
        transform: translateY(4px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

@keyframes unsaved-ping {
    0% {
        transform: scale(1);
        opacity: 0.7;
    }
    75%, 100% {
        transform: scale(2.8);
        opacity: 0;
    }
}

@keyframes unsaved-pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(var(--color-blue-rgb), 0.6);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(var(--color-blue-rgb), 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(var(--color-blue-rgb), 0);
    }
}

@media (prefers-reduced-motion: reduce) {
    .unsaved-chip__dot::after,
    [data-dirty="true"] .unsaved-chip,
    [data-dirty="true"] .unsaved-discard,
    [data-dirty="true"] .unsaved-save {
        animation: none;
    }
}

/* ------------------------------------------------------------------ */
/* Settings: the section list beside the form, which scrolls alone.    */
/* ------------------------------------------------------------------ */

/* Grows to the open section and no further, so the action bar sits
   under a short section instead of at the foot of the window; a long
   one is capped at the window and scrolls. The same take-what-you-need
   sizing as .pane, and min-height: 0 is what lets it give height back. */
.settings-layout {
    flex: 0 1 auto;
    min-height: 0;
    display: flex;
    gap: 1.5rem;
}

/* The list stands on a rail: a hairline down its right edge, the full
   height of the open section, marks it off from the form. */
.settings-nav {
    flex: 0 0 13.5rem;
    padding: 0.25rem 1rem 0 0;
    border-right: 1px solid var(--border-subtle);
}

.settings-nav .nav {
    flex-direction: column;
    gap: 2px;
}

.settings-nav .nav-link {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.45rem 0.75rem;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.3;
    color: var(--text-tertiary);
    transition: color 0.15s ease, background-color 0.15s ease;
}

.settings-nav .nav-link:hover {
    color: var(--text-secondary);
    background: var(--surface-2);
}

.settings-nav .nav-link.active {
    color: var(--nav-active-fg);
    background: var(--nav-active-bg);
    font-weight: 600;
}

.settings-nav__icon {
    flex: none;
    width: 1.1rem;
    font-size: 0.8rem;
    text-align: center;
    opacity: 0.7;
}

.settings-nav .nav-link.active .settings-nav__icon {
    opacity: 1;
}

/* A section whose fields failed validation. */
.settings-nav__error {
    margin-left: auto;
    font-size: 0.75rem;
    color: var(--color-red);
}

.settings-main {
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

/* The form's scroller. The side padding leaves the inputs' focus rings
   their 3px at the edges instead of clipping them. */
.settings-scroll {
    flex: 0 1 auto;
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
    padding: 0.25rem 0.25rem 1rem;
}

/* Under md the list has no room beside the form: it becomes a row of
   the same items above it, scrolling sideways when they do not fit. */
@media (max-width: 767.98px) {
    .settings-layout {
        flex-direction: column;
        gap: 0.75rem;
    }

    .settings-nav {
        flex: none;
        padding: 0 0 0.5rem;
        border-right: 0;
        border-bottom: 1px solid var(--border-subtle);
    }

    .settings-nav .nav {
        flex-direction: row;
        flex-wrap: nowrap;
        overflow-x: auto;
        gap: 4px;
        padding-bottom: 0.25rem;
    }

    .settings-nav .nav-link {
        white-space: nowrap;
    }
}

/* ------------------------------------------------------------------ */
/* Panes: one per section, each opening with its header.               */
/* ------------------------------------------------------------------ */

.configuration-pane {
    padding-top: 0.25rem;
}

/* A pane's last card carries no trailing margin, whether the card is
   the pane's own child or sits inside a template pane's wrapper. */
.configuration-pane > .settings-group:last-child,
.configuration-pane > [class$="-pane"] > .settings-group:last-child {
    margin-bottom: 0;
}

/* ------------------------------------------------------------------ */
/* Pane header: the tab's name and a sentence on what it holds; on an  */
/* inherited tab, whether its rows match the profile, and the way back. */
/* ------------------------------------------------------------------ */

.pane-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem 1.5rem;
    margin: 0 0 1.25rem;
    padding: 0.25rem 0.25rem 1rem;
    border-bottom: 1px solid var(--border-subtle);
}

.pane-header__text {
    min-width: 0;
}

.pane-header__title {
    margin: 0;
    font-size: 1.125rem;
    font-weight: var(--font-weight-heading);
    letter-spacing: var(--heading-tracking);
    line-height: 1.3;
    color: var(--text-primary);
}

.pane-header__lead {
    margin: 0.2rem 0 0;
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--text-tertiary);
    text-wrap: pretty;
}

.pane-header__status {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-left: auto;
    padding-top: 0.2rem;
    font-size: 0.8125rem;
    white-space: nowrap;
}

.pane-header__same {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--text-muted);
}

.pane-header__same .fa-check {
    font-size: 0.7rem;
}

/* "N settings changed", in the blue of the row dot it counts. */
.pane-header__differs {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: var(--font-weight-strong);
    color: var(--color-blue);
}

.pane-header__dot {
    flex: none;
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: var(--color-blue);
}

/* ------------------------------------------------------------------ */
/* Rail groups, and the marks of a section whose rows are inherited.   */
/* ------------------------------------------------------------------ */

/* A group of sections under a heading: an eyebrow over its sections,
   with room under it for a link the page supplies. A hairline above
   sets it off from the sections before it. */
.settings-nav__group {
    margin: 0.75rem 0 0.35rem;
    padding: 0.85rem 0.75rem 0;
    border-top: 1px solid var(--border-subtle);
}

.settings-nav__heading {
    display: block;
    font-size: 0.6875rem;
    font-weight: var(--font-weight-strong);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
}

/* A group's sections sit in from its heading. */
.settings-nav__group ~ .nav-item .nav-link {
    padding-left: 1.25rem;
}

/* Under md the rail is one row: the group sits in it, set off by a
   hairline at its start. */
@media (max-width: 767.98px) {
    .settings-nav__group {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        margin: 0;
        padding: 0 0.5rem;
        border-top: 0;
        border-left: 1px solid var(--border-subtle);
    }

    .settings-nav__group ~ .nav-item .nav-link {
        padding-left: 0.75rem;
    }
}

/* An inherited tab with nothing overridden reads dimmer than one the
   assistant has made its own. */
.settings-nav .nav-link.settings-nav__inherited[data-override-count="0"]:not(.active) {
    color: var(--text-muted);
}

/* How many of the assistant's overrides fall on a tab, and how many
   an assistant carries on the profile page. Reads with the modified
   dot: blue means "this assistant's own". */
.settings-nav__count {
    margin-left: auto;
    padding: 0.05rem 0.45rem;
    border-radius: 999px;
    font-size: 0.6875rem;
    font-weight: var(--font-weight-strong);
    color: var(--color-blue);
    background: rgba(var(--color-blue-rgb), 0.14);
}

.settings-nav .nav-link.active .settings-nav__count {
    color: var(--nav-active-fg);
    background: rgba(var(--color-blue-rgb), 0.22);
}
