/*
 * Shared collection-control styles for the tracker (/tracker/) and demo (/demo/)
 * pages. Both include tracker/_collection_controls.html, so the chrome around
 * the search box, filters and type chips lives here instead of being duplicated
 * in each template's inline <style>.
 *
 * The card is pinned to the bottom of the viewport at every width; only its
 * shape changes (grid areas do the reordering):
 *   desktop (>720px) - a full-bleed bar: name + count pill on the left,
 *                      search / filter / types / theme on the right, all of it
 *                      always visible.
 *   mobile  (<=720px) - a slim dock (count pill + hamburger) that mirrors the
 *                      fixed top nav, with the filter sheet sliding up over a
 *                      dimmed page.
 *
 * Colour comes from the per-page custom properties (--text, --accent, ...),
 * so this file works unchanged on both light and dark themes.
 */

.dock-backdrop {
    display: none;
}

/*
 * Fixed rather than scrolling away with the grid, so the controls stay reachable
 * from anywhere in a very long list. The bar is full-bleed, but its side padding
 * holds the contents to the grid's own 1400px so the name still lines up with
 * the cards above it.
 */
.top-controls {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 999;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas:
        "ident controls"
        "pill  controls";
    align-items: center;
    column-gap: 1rem;
    row-gap: 0.4rem;
    padding: 0.9rem max(1.25rem, calc((100% - 1400px) / 2));
    margin: 0;
    border-radius: 16px 16px 0 0;
    backdrop-filter: blur(12px);
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.88), rgba(255, 255, 255, 0.72));
    border: none;
    border-top: 1px solid var(--card-border);
    box-shadow: 0 -14px 34px rgba(0, 0, 0, 0.16);
}

/*
 * Room for the bar so the last row of cards is never covered by it.
 * collection-dock.js keeps --dock-height in step with the real height, which
 * moves when the control row wraps; the fallback covers first paint and no-JS.
 */
body {
    padding-bottom: calc(var(--dock-height, 132px) + 1.5rem);
}

body.dark .top-controls {
    background: linear-gradient(135deg, rgba(14, 20, 27, 0.92), rgba(14, 20, 27, 0.82));
}

.cc-identity {
    grid-area: ident;
    font-weight: 700;
}

.control-row {
    grid-area: controls;
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    align-items: center;
}

/* ---------------------------------------------------------------- count pill */

.collection-pill {
    grid-area: pill;
    justify-self: start;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.5rem 1.2rem;
    min-width: 140px;
    border-radius: 10px;
    background: linear-gradient(135deg, rgba(243, 201, 105, 0.25), rgba(15, 118, 110, 0.2));
    border: 1px solid rgba(243, 201, 105, 0.4);
    color: var(--text);
    font-weight: 700;
    font-size: 0.95rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    user-select: none;
    transition: transform 0.15s ease, box-shadow 0.15s ease,
        border-color 0.15s ease, background 0.15s ease;
}

body.dark .collection-pill {
    background: linear-gradient(135deg, rgba(243, 201, 105, 0.2), rgba(15, 118, 110, 0.25));
    border-color: rgba(243, 201, 105, 0.35);
}

.collection-pill:hover {
    transform: translateY(-1px);
    border-color: rgba(243, 201, 105, 0.75);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
}

.collection-pill:active {
    transform: translateY(0);
}

.collection-pill:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.collection-pill.filtered {
    border-color: var(--button-bg);
    box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.3);
}

/* -------------------------------------------------------------- search/filter */

.filter-select,
.search-input {
    padding: 0.65em 1.1em;
    font-size: 1em;
    border-radius: 12px;
    background-color: var(--card-bg);
    color: var(--text);
    border: 1px solid var(--card-border);
    outline: none;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    height: 46px;
}

.filter-select {
    cursor: pointer;
    min-width: 180px;
    padding-right: 2.5em;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%230f172a' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1em center;
    background-size: 12px;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
}

body.dark .filter-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23e5e7eb' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
}

.filter-select:hover,
.search-input:focus {
    border-color: var(--accent);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
}

.search-input {
    flex: 1;
    min-width: 240px;
    cursor: text;
}

/* ----------------------------------------------------------------- type chips */

.type-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.type-filters-label {
    font-weight: 700;
    font-size: 0.74rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}

/*
 * Each chip is a label wrapping a visually hidden checkbox, so the whole pill
 * is the hit target and the checked state stays in the native form control
 * that both pages' scripts already read and write.
 */
.type-chip {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    min-height: 36px;
    padding: 0.35rem 0.9rem;
    border-radius: 999px;
    border: 1.5px solid var(--card-border);
    background: rgba(255, 255, 255, 0.55);
    color: var(--muted);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    user-select: none;
    transition: background 0.18s ease, border-color 0.18s ease,
        color 0.18s ease, transform 0.12s ease;
}

.type-chip::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.3;
    transition: opacity 0.18s ease, box-shadow 0.18s ease;
}

.type-chip input[type="checkbox"] {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: 0;
    opacity: 0;
    pointer-events: none;
}

.type-chip:has(input:checked) {
    background: linear-gradient(135deg, rgba(15, 118, 110, 0.16), rgba(243, 201, 105, 0.18));
    border-color: rgba(15, 118, 110, 0.5);
    color: var(--text);
}

.type-chip:has(input:checked)::before {
    opacity: 1;
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.18);
}

.type-chip:has(input:focus-visible) {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.type-chip:active {
    transform: scale(0.97);
}

.type-chip:has(input:disabled) {
    opacity: 0.5;
    cursor: not-allowed;
}

body.dark .type-chip {
    background: rgba(31, 41, 55, 0.55);
    border-color: rgba(148, 163, 184, 0.22);
}

body.dark .type-chip:has(input:checked) {
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.2), rgba(243, 201, 105, 0.16));
    border-color: rgba(34, 197, 94, 0.5);
}

/* Without :has() the pill can't reflect its checkbox, so show the real box. */
@supports not selector(:has(*)) {
    .type-chip::before {
        display: none;
    }

    .type-chip input[type="checkbox"] {
        position: static;
        width: 16px;
        height: 16px;
        opacity: 1;
        pointer-events: auto;
        accent-color: var(--button-bg);
    }
}

/* ---------------------------------------------------------------- theme toggle */

.dark-toggle {
    border-radius: 12px;
    padding: 0.65rem 1.2rem;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    text-decoration: none;
    color: var(--text);
    background: rgba(255, 255, 255, 0.75);
    border: 1px solid var(--card-border);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
    white-space: nowrap;
    min-width: fit-content;
    height: 46px;
}

body.dark .dark-toggle {
    background: rgba(31, 41, 55, 0.85);
    border-color: rgba(243, 201, 105, 0.25);
}

.dark-toggle:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15);
}

/* ------------------------------------------------------------------ hamburger */

.hamburger-btn {
    grid-area: burger;
    display: none;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    background: linear-gradient(135deg, rgba(15, 118, 110, 0.16), rgba(243, 201, 105, 0.16));
    border: 1.5px solid rgba(15, 118, 110, 0.45);
    border-radius: 9px;
    color: var(--text);
    font-size: 1.2rem;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    transition: transform 0.2s ease, background 0.2s ease, border-color 0.2s ease;
}

.hamburger-btn:hover {
    transform: scale(1.05);
    background: linear-gradient(135deg, rgba(15, 118, 110, 0.28), rgba(243, 201, 105, 0.28));
    border-color: rgba(15, 118, 110, 0.65);
}

body.dark .hamburger-btn {
    background: rgba(31, 41, 55, 0.85);
    border-color: rgba(243, 201, 105, 0.35);
    color: #fdf7e3;
}

body.dark .hamburger-btn:hover {
    background: rgba(31, 41, 55, 0.95);
    border-color: rgba(243, 201, 105, 0.55);
}

/* =============================================================== mobile: dock */

@media (max-width: 720px) {
    /*
     * A fixed 45px rather than --dock-height: down here the sheet overlays the
     * page when it opens, so the padding only has to clear the collapsed rail.
     */
    body {
        padding-bottom: calc(45px + env(safe-area-inset-bottom, 0px) + 1rem);
    }

    .dock-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 998;
        background: rgba(6, 10, 14, 0.55);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.25s ease;
    }

    .dock-backdrop.active {
        opacity: 1;
        pointer-events: auto;
    }

    .top-controls {
        padding: 0 0 env(safe-area-inset-bottom, 0px);
        border-top-color: rgba(243, 201, 105, 0.28);
        column-gap: 0.6rem;
        row-gap: 0;
        grid-template-columns: minmax(0, 1fr) auto;
        /* 44px + the 1px border tops out at the top nav's 45px rail. */
        grid-template-rows: auto auto 44px;
        grid-template-areas:
            "ident    ident"
            "controls controls"
            "pill     burger";
        box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.28);
    }

    /*
     * Sheet rows. visibility (not just max-height) so the collapsed controls
     * stay out of the tab order; it flips back instantly on open and only
     * after the collapse animation on close.
     */
    .cc-identity,
    .control-row {
        max-height: 0;
        overflow: hidden;
        opacity: 0;
        visibility: hidden;
        padding-left: 1rem;
        padding-right: 1rem;
        transition: max-height 0.32s ease, opacity 0.2s ease,
            padding 0.32s ease, visibility 0s linear 0.32s;
    }

    /*
     * nowrap matters: the row-oriented default would wrap this bounded-height
     * column into a second column instead of scrolling.
     */
    .control-row {
        flex-direction: column;
        flex-wrap: nowrap;
        align-items: stretch;
        gap: 0.55rem;
    }

    /* Same reason: `flex: 1` grows down the cross axis once stacked. */
    .control-row > * {
        flex: 0 0 auto;
    }

    .top-controls.sheet-open .cc-identity,
    .top-controls.sheet-open .control-row {
        opacity: 1;
        visibility: visible;
        transition-delay: 0s;
    }

    .top-controls.sheet-open .cc-identity {
        max-height: 3rem;
        padding-top: 1rem;
        padding-bottom: 0.35rem;
        font-size: 0.95rem;
    }

    .top-controls.sheet-open .control-row {
        max-height: min(58vh, 430px);
        overflow: hidden auto;
        padding-bottom: 0.9rem;
        border-bottom: 1px solid var(--card-border);
    }

    .search-input,
    .filter-select {
        width: 100%;
        min-width: 0;
        font-size: 0.95rem;
        height: 46px;
    }

    /* A real two-column grid: every pill is the same width, ragged last row
       and all, which reads as deliberate where wrapped flex reads as spill. */
    .type-filters {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.45rem;
        width: 100%;
    }

    .type-filters-label {
        grid-column: 1 / -1;
        margin-bottom: 0.1rem;
    }

    .type-chip {
        justify-content: flex-start;
        min-height: 40px;
    }

    .dark-toggle {
        width: 100%;
        justify-content: center;
        height: 44px;
        font-size: 0.9rem;
    }

    /* Dock row: mirrors the top nav (pill left like the logo, burger right). */
    .collection-pill {
        align-self: center;
        margin: 0 0 0 1rem;
        min-width: 0;
        padding: 0.3rem 0.85rem;
        font-size: 0.85rem;
        border-radius: 9px;
    }

    .hamburger-btn {
        display: inline-flex;
        align-self: center;
        justify-self: end;
        margin-right: 1rem;
    }
}

@media (prefers-reduced-motion: reduce) {

    .cc-identity,
    .control-row,
    .dock-backdrop,
    .type-chip,
    .collection-pill {
        transition: none;
    }
}
