/* ============================================================
   GLOSSARY INDEX — page-specific styles
   Inherits from /styles.css for body, nav, footer, a11y panel,
   and global CSS variables (--bg-blue, --yellow, --white, etc.).
   All selectors prefixed `.gloss-index-` to avoid conflicts with
   the entry page (glossary.css).
   ============================================================ */

/* The [hidden] attribute must override display: flex/grid/block.
   Browser default for [hidden] has low specificity. */
.gloss-index-panel[hidden],
.gloss-index-sheet[hidden],
.gloss-index-backdrop[hidden] {
    display: none !important;
}

/* ============================================================
   PAGE WRAPPER
   ============================================================ */
.gloss-index-page {
    min-height: 100vh;
    background-color: var(--bg-blue);
    color: var(--white);
}

/* ============================================================
   HERO — centered, mirrors library page
   ============================================================ */
.gloss-index-hero {
    text-align: center;
    padding: calc(var(--nav-height) + 3.5rem) 2rem 1.5rem;
    max-width: 780px;
    margin: 0 auto;
}

.gloss-index-hero__title {
    font-family: 'Fira Sans', sans-serif;
    font-weight: 600;
    font-size: 2.4rem;
    margin: 0 0 0.75rem;
    letter-spacing: -0.01em;
    color: var(--white);
    line-height: 1.15;
}

.gloss-index-hero__title em {
    color: var(--yellow);
    font-style: normal;
}

.gloss-index-hero__sub {
    font-family: 'Fira Sans', sans-serif;
    font-weight: 400;
    font-size: 1.02rem;
    color: rgba(255, 255, 255, 0.78);
    line-height: 1.7;
    max-width: 650px;
    margin: 0 auto;
}

/* ============================================================
   SEARCH + FILTER BAR — mirrors library .sfbar
   Wrapped in a sticky container so it stays accessible while
   the user scrolls through the alphabetized list.
   ============================================================ */
.gloss-index-sfbar-sticky {
    position: sticky;
    top: var(--nav-height);
    z-index: 100;
    background: var(--bg-blue);
    margin-top: 1.5rem;
    padding: 0.75rem 0;
}

.gloss-index-sfbar {
    max-width: 680px;
    margin: 0 auto;
    padding: 0 2rem;
    position: relative;
}

.gloss-index-sfbar__row {
    display: flex;
    gap: 0.75rem;
    align-items: stretch;
}

.gloss-index-search-wrap {
    flex: 1;
    position: relative;
    min-width: 0;
}

.gloss-index-search-wrap input {
    width: 100%;
    padding: 0.8rem 2.5rem 0.8rem 2.75rem;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid #D1D5DB;
    border-radius: 8px;
    color: var(--white);
    font-family: 'Fira Sans', sans-serif;
    font-size: 0.92rem;
    font-weight: 300;
    outline: none;
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.gloss-index-search-wrap input::placeholder {
    color: rgba(255, 255, 255, 0.3);
}

.gloss-index-search-wrap input:focus {
    border-color: rgba(253, 210, 13, 0.4);
}

.gloss-index-search-icon {
    position: absolute;
    left: 0.9rem;
    top: 50%;
    transform: translateY(-50%);
    color: rgba(255, 255, 255, 0.3);
    pointer-events: none;
}

.gloss-index-search-clear {
    position: absolute;
    right: 0.6rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.4);
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
    padding: 0.25rem 0.5rem;
    display: none;
}

.gloss-index-search-clear--show {
    display: block;
}

.gloss-index-search-clear:hover {
    color: rgba(255, 255, 255, 0.8);
}

/* Filter button */
.gloss-index-filter-btn {
    padding: 0.8rem 1.1rem;
    background: #F4F6F9;
    border: 1px solid #D1D5DB;
    border-radius: 8px;
    color: #374151;
    font-family: 'Fira Sans', sans-serif;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: border-color 0.2s, color 0.2s, background 0.2s;
    white-space: nowrap;
    letter-spacing: 0.04em;
}

.gloss-index-filter-btn:hover {
    border-color: rgba(253, 210, 13, 0.5);
    color: #1F2937;
    background: #E8ECF1;
}

.gloss-index-filter-btn span {
    text-transform: uppercase;
}

/* Active-count badge */
.gloss-index-badge {
    background: #1D4ED8;
    color: white;
    font-size: 0.65rem;
    font-weight: 600;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    letter-spacing: 0;
    text-transform: none;
}

.gloss-index-badge--show {
    display: flex;
}

/* ============================================================
   DESKTOP FILTER PANEL — drops below sfbar inline
   ============================================================ */
.gloss-index-panel {
    margin-top: 0.5rem;
    background: #F4F6F9;
    border: 1px solid #D1D5DB;
    border-radius: 12px;
    padding: 1.25rem 1.5rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    display: none;
}

.gloss-index-panel--open {
    display: block;
    animation: gloss-index-panel-down 0.18s ease;
}

@keyframes gloss-index-panel-down {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

.gloss-index-panel__label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: #6B7280;
    margin-bottom: 0.6rem;
    font-weight: 600;
}

.gloss-index-panel__chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.gloss-index-panel__actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid #D1D5DB;
}

/* ============================================================
   ACTIVE FILTER PILLS (atags)
   Shown below the panel when one or more filters are applied.
   Each atag mirrors the active chip styling but adds an X to
   remove the individual filter without opening the panel.
   ============================================================ */
.gloss-index-atags {
    display: none;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.5rem;
}

.gloss-index-atags--show {
    display: flex;
}

.gloss-index-atag {
    padding: 0.3rem 0.5rem 0.3rem 0.75rem;
    border-radius: 20px;
    font-family: 'Fira Sans', sans-serif;
    font-size: 0.75rem;
    font-weight: 500;
    line-height: 1.4;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    border: 1.5px solid transparent;
    /* background, color, border-color set inline by JS */
}

.gloss-index-atag__remove {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    line-height: 0.7;
    padding: 0 2px;
    margin-right: -2px;
    opacity: 0.6;
    color: inherit;
    font-family: inherit;
    transition: opacity 0.15s;
}

.gloss-index-atag__remove:hover,
.gloss-index-atag__remove:focus {
    opacity: 1;
}

/* ============================================================
   FILTER CHIPS — shared between desktop panel and mobile sheet
   Cluster colors set inline by JS via style attribute.
   ============================================================ */
.gloss-index-chip {
    padding: 0.3rem 0.75rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 400;
    border: 1.5px solid transparent;
    cursor: pointer;
    user-select: none;
    font-family: 'Fira Sans', sans-serif;
    transition: opacity 0.15s, border-color 0.15s, font-weight 0.15s;
    line-height: 1.4;
}

.gloss-index-chip--active {
    font-weight: 500;
    /* border-color set inline by JS to cluster's text color */
}

.gloss-index-chip--muted {
    opacity: 0.4;
}

.gloss-index-chip:hover {
    opacity: 0.85;
}

.gloss-index-chip--active:hover {
    opacity: 1;
}

/* Clear filters affordance — hidden until at least one filter active */
.gloss-index-clear {
    background: none;
    border: none;
    color: #6B7280;
    font-family: 'Fira Sans', sans-serif;
    font-size: 0.78rem;
    cursor: pointer;
    transition: color 0.2s;
    padding: 0.2rem 0;
    display: none;
}

.gloss-index-clear:hover {
    color: #1D4ED8;
}

.gloss-index-clear--show {
    display: inline-block;
}

/* ============================================================
   MOBILE BOTTOM SHEET + BACKDROP
   Hidden on desktop entirely.
   ============================================================ */
.gloss-index-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    display: none;
}

.gloss-index-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #F4F6F9;
    border-radius: 18px 18px 0 0;
    padding: 0.75rem 1.5rem 1.5rem;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.3);
    z-index: 210;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    display: none;
    max-height: 85vh;
    overflow-y: auto;
}

.gloss-index-sheet__handle {
    width: 36px;
    height: 4px;
    background: #C8CCD2;
    border-radius: 2px;
    margin: 0 auto 0.75rem;
}

.gloss-index-sheet__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.875rem;
}

.gloss-index-sheet__title {
    font-family: 'Fira Sans', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    color: #1F2937;
    margin: 0;
}

.gloss-index-sheet__close {
    background: none;
    border: none;
    color: #6B7280;
    cursor: pointer;
    padding: 0.4rem;
    border-radius: 4px;
    line-height: 0;
}

.gloss-index-sheet__close:hover {
    color: #1F2937;
}

.gloss-index-sheet__label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: #6B7280;
    margin-bottom: 0.625rem;
    font-weight: 600;
}

.gloss-index-sheet__chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 1rem;
}

.gloss-index-sheet__actions {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    padding-top: 0.75rem;
    border-top: 1px solid #D1D5DB;
}

/* ============================================================
   CONTENT CARD — letter row + alphabetized list
   ============================================================ */
.gloss-index-content {
    max-width: 720px;
    margin: 1.5rem auto 3rem;
    padding: 0 2rem;
}

.gloss-index-card {
    background: #F4F6F9;
    border: 1px solid #D1D5DB;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    border-radius: 10px;
    padding: 1.5rem 1.75rem;
    color: #2C2C2A;
}

/* Filtered count — appears above letter row only when narrowed */
.gloss-index-count {
    font-family: 'Fira Sans', sans-serif;
    font-size: 0.8125rem;
    font-weight: 400;
    color: #5F5E5A;
    margin: 0 0 0.75rem;
    letter-spacing: 0.01em;
}

.gloss-index-count[hidden] {
    display: none !important;
}

/* Search-match highlight in titles and teasers */
.gloss-index-mark {
    background: rgba(253, 210, 13, 0.32);
    color: inherit;
    padding: 0 1px;
    border-radius: 2px;
}

/* Letter row */
.gloss-index-letter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.gloss-index-letter {
    font-family: 'Fira Sans', sans-serif;
    font-size: 0.82rem;
    padding: 5px 10px;
    border-radius: 4px;
    color: #2C2C2A;
    text-decoration: none;
    min-width: 26px;
    text-align: center;
    line-height: 1.2;
    font-weight: 400;
    transition: background 0.15s, color 0.15s;
}

.gloss-index-letter:hover {
    background: #F1EFE8;
    color: #2C2C2A;
}

.gloss-index-letter--empty {
    color: #B4B2A9;
    cursor: default;
    pointer-events: none;
}

.gloss-index-letter--empty:hover {
    background: transparent;
}

/* List */
.gloss-index-list {
    /* sections render inside */
}

.gloss-index-section + .gloss-index-section {
    margin-top: 1rem;
}

.gloss-index-section__heading {
    font-family: 'Fira Sans', sans-serif;
    font-size: 1.125rem;
    font-weight: 500;
    color: #2C2C2A;
    margin: 0 0 0.5rem;
    letter-spacing: -0.01em;
    /* offset for fixed nav anchor jump */
    scroll-margin-top: calc(var(--nav-height) + 1rem);
}

.gloss-index-section__rows {
    display: flex;
    flex-direction: column;
}

/* List item — anchor wrapping the row, hover state on whole row */
.gloss-index-row {
    padding: 0.75rem 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    text-decoration: none;
    display: block;
    color: inherit;
    transition: background 0.12s;
    margin: 0 -0.5rem;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
    border-radius: 4px;
}

.gloss-index-row:hover {
    background: rgba(255, 255, 255, 0.4);
}

.gloss-index-row:last-child {
    border-bottom: none;
}

.gloss-index-row__head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
    margin-bottom: 0.25rem;
}

.gloss-index-row__title {
    flex: 1;
    min-width: 0;
    font-family: 'Fira Sans', sans-serif;
    font-size: 0.9375rem;
    color: #1D4ED8;
    font-weight: 500;
    line-height: 1.35;
}

.gloss-index-row__pill {
    font-family: 'Fira Sans', sans-serif;
    font-size: 0.75rem;
    padding: 0.3rem 0.75rem;
    border-radius: 20px;
    flex-shrink: 0;
    white-space: nowrap;
    line-height: 1.4;
    font-weight: 400;
    /* background and color set inline by JS */
}

.gloss-index-row__teaser {
    font-family: 'Fira Sans', sans-serif;
    font-size: 0.84rem;
    color: #5F5E5A;
    margin: 0;
    line-height: 1.55;
}

/* ============================================================
   STATES — empty, loading
   ============================================================ */
.gloss-index-loading {
    text-align: center;
    color: #5F5E5A;
    font-family: 'Fira Sans', sans-serif;
    font-size: 0.875rem;
    padding: 2rem 0;
    margin: 0;
}

.gloss-index-empty {
    text-align: center;
    padding: 2rem 1rem;
}

.gloss-index-empty p {
    color: #5F5E5A;
    font-family: 'Fira Sans', sans-serif;
    font-size: 0.95rem;
    margin: 0 0 1rem;
}

.gloss-index-empty__reset {
    background: white;
    border: 1px solid #D1D5DB;
    border-radius: 6px;
    padding: 0.5rem 1rem;
    color: #1D4ED8;
    font-family: 'Fira Sans', sans-serif;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.gloss-index-empty__reset:hover {
    background: #F0F1F3;
    border-color: #B4B2A9;
}

/* ============================================================
   MOBILE
   Breakpoint matches entry page (720px).
   ============================================================ */
@media (max-width: 720px) {

    .gloss-index-hero {
        padding-top: calc(var(--nav-height) + 2.5rem);
    }

    .gloss-index-hero__title {
        font-size: 1.8rem;
    }

    .gloss-index-hero__sub {
        font-size: 0.92rem;
        line-height: 1.65;
    }

    .gloss-index-sfbar {
        padding: 0 1rem;
    }

    .gloss-index-sfbar-sticky {
        padding: 0.5rem 0;
        margin-top: 1rem;
    }

    .gloss-index-sfbar__row {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .gloss-index-search-wrap {
        flex: 1 1 100%;
    }

    .gloss-index-filter-btn {
        flex: 0 0 auto;
        padding: 0.7rem 1rem;
        font-size: 0.78rem;
    }

    /* Hide desktop panel on mobile entirely (sheet replaces it) */
    .gloss-index-panel {
        display: none !important;
    }

    /* Show backdrop and sheet on mobile (their --open classes handle visibility) */
    .gloss-index-backdrop {
        display: block;
    }

    .gloss-index-backdrop--show {
        opacity: 1;
        pointer-events: auto;
    }

    .gloss-index-sheet {
        display: block;
    }

    .gloss-index-sheet--open {
        transform: translateY(0);
    }

    .gloss-index-content {
        padding: 0 1rem;
    }

    .gloss-index-card {
        padding: 1.25rem 1.25rem;
    }

    .gloss-index-letter {
        min-width: 22px;
        padding: 4px 8px;
        font-size: 0.82rem;
    }

    .gloss-index-section__heading {
        font-size: 1.0625rem;
    }

    .gloss-index-row {
        padding: 0.875rem 0;
    }

    /* Title wraps when needed; pill stays anchored top-right */
    .gloss-index-row__head {
        align-items: flex-start;
        gap: 0.625rem;
    }

    .gloss-index-row__title {
        font-size: 0.9rem;
    }

    .gloss-index-row__teaser {
        font-size: 0.8rem;
    }
}

/* Reduced motion: kill animations */
@media (prefers-reduced-motion: reduce) {
    .gloss-index-panel--open,
    .gloss-index-sheet,
    .gloss-index-backdrop,
    .gloss-index-search-wrap input,
    .gloss-index-filter-btn,
    .gloss-index-letter,
    .gloss-index-row,
    .gloss-index-chip,
    .gloss-index-empty__reset {
        animation: none !important;
        transition: none !important;
    }
}

/* ============================================================
   A11Y MODES (additions beyond inherited styles.css)
   ============================================================ */
.a11y-highlight-links .gloss-index-row__title,
.a11y-highlight-links .gloss-index-letter,
.a11y-highlight-links .gloss-index-empty__reset {
    background-color: rgba(253, 210, 13, 0.3);
    padding: 1px 3px;
    border-radius: 3px;
}
