/************* Wine list *************/

/* The shared list every wine list page is built from (store, grape, region,
   country and producer pages so far): the filter rail beside the results, the
   results toolbar, the one wine row (specs/wine-row.md) and the numbered
   pagination. The markup comes from filter-rail.js, list-toolbar.js and
   wine-row.js; the selectors below follow its order. On a phone the rail is a
   full-screen sheet the toolbar's Filters button opens. */

/************* Layout *************/

/* the rail's 236px column beside the results, as the design boards draw it */
#listLayout {
    display: grid;
    grid-template-columns: 236px minmax(0, 1fr);
    gap: 44px;
    align-items: start;
    margin-top: 28px;
}

/* no rail (a page whose filters are not ready yet): the results take the row */
#listLayout.noRail {
    grid-template-columns: minmax(0, 1fr);
}

/************* Filter rail *************/

#filterRail {
    display: flex;
    flex-direction: column;
    font-size: 15px;
}

/* while a choice navigates, the rail dims so a second tap reads as pending */
#filterRail.loading {
    opacity: .6;
    pointer-events: none;
}

#filterRailHead {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--hairline);
}

#filterRailHeadTitle {
    flex: 1;
    font-size: var(--font-size-h3);
    font-weight: 800;
}

#filterRailHeadClear {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    color: var(--primary);
    font-size: 14px;
    font-weight: 700;
}

#filterRailHeadClear:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

/* the close control only belongs to the phone sheet */
#filterRailHeadClose {
    display: none;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    margin-right: -10px;
    border-radius: var(--radius);
    color: var(--black);
}

.filterRailHeadCloseIcon {
    flex: none;
}

/* A fieldset draws its legend in its own top edge, so the group's top space sits
   on the legend and the fieldset only pads its bottom. */
.filterRailFormGroup {
    display: flex;
    flex-direction: column;
    min-width: 0;
    margin: 0;
    padding: 0 0 16px;
    border: 0;
    border-bottom: 1px solid var(--hairline);
}

.filterRailFormGroupLegend {
    float: left;
    width: 100%;
    margin-bottom: 8px;
    padding: 16px 0 0;
    font-size: 14px;
    font-weight: 800;
}

/* the "Find a grape" box: a 36px field with a search icon inside it */
.filterRailFormGroupFind {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 36px;
    margin-bottom: 6px;
    padding: 0 10px;
    border: 1px solid var(--control-border);
    border-radius: var(--radius);
    color: var(--muted);
    font-size: 14px;
}

.filterRailFormGroupFind:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 1px var(--primary);
}

.filterRailFormGroupFindIcon {
    flex: none;
}

/* the field inside draws no box of its own; the label is the box */
.filterRailFormGroupFindInput {
    flex: 1;
    min-width: 0;
    height: 100%;
    padding: 0;
    border: 0;
    background: none;
    color: var(--black);
    font-size: 14px;
    outline: none;
}

.filterRailFormGroupFindInput::placeholder {
    color: var(--muted);
    opacity: 1;
}

/* one option: a 36px row, the box, the label and the count pushed right */
.filterRailFormGroupOption {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 36px;
    cursor: pointer;
}

.filterRailFormGroupOption.active {
    font-weight: 700;
}

/* a find box search hides the options that don't match */
.filterRailFormGroupOption.filteredOut {
    display: none;
}

.filterRailFormGroupOptionInput {
    flex: none;
    width: 18px;
    height: 18px;
    margin: 0;
    accent-color: var(--primary);
    cursor: pointer;
}

.filterRailFormGroupOptionLabel {
    min-width: 0;
    overflow-wrap: anywhere;
}

.filterRailFormGroupOptionCount {
    margin-left: auto;
    padding-left: 8px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 400;
}

/* "Show all": a disclosure, so the fold opens with no JS; the extra options
   open under the toggle, which then reads "Show fewer" */
.filterRailFormGroupMore {
    min-width: 0;
}

.filterRailFormGroupMoreToggle {
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    min-height: 32px;
    margin-top: 4px;
    color: var(--primary);
    font-size: 14px;
    font-weight: 700;
    list-style: none;
    cursor: pointer;
}

.filterRailFormGroupMoreToggle::-webkit-details-marker {
    display: none;
}

.filterRailFormGroupMoreToggle:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

/* the toggle names the action it takes: show while closed, fewer while open */
.filterRailFormGroupMoreToggleHide {
    display: none;
}

.filterRailFormGroupMore[open] .filterRailFormGroupMoreToggleShow {
    display: none;
}

.filterRailFormGroupMore[open] .filterRailFormGroupMoreToggleHide {
    display: inline;
}

.filterRailFormGroupMoreList {
    display: flex;
    flex-direction: column;
}

/* "No matches" under a find box, only while a search finds nothing */
.filterRailFormGroupEmpty {
    display: none;
    color: var(--muted);
    font-size: 13px;
}

.filterRailFormGroupEmpty.active {
    display: block;
}

/* the typed price range: "$ Min to $ Max" */
.filterRailFormGroupRange {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
    color: var(--muted);
    font-size: 14px;
}

.filterRailFormGroupRangeField {
    display: flex;
    align-items: center;
    gap: 4px;
    width: 88px;
    height: 36px;
    padding: 0 10px;
    border: 1px solid var(--control-border);
    border-radius: var(--radius);
}

.filterRailFormGroupRangeField:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 1px var(--primary);
}

.filterRailFormGroupRangeFieldUnit {
    flex: none;
}

.filterRailFormGroupRangeFieldInput {
    width: 100%;
    min-width: 0;
    height: 100%;
    padding: 0;
    border: 0;
    background: none;
    color: var(--black);
    font-size: 14px;
    outline: none;
    appearance: textfield;
}

.filterRailFormGroupRangeFieldInput::placeholder {
    color: var(--muted);
    opacity: 1;
}

.filterRailFormGroupRangeFieldInput::-webkit-outer-spin-button,
.filterRailFormGroupRangeFieldInput::-webkit-inner-spin-button {
    margin: 0;
    appearance: none;
}

.filterRailFormGroupRangeTo {
    flex: none;
}

/* the form's foot: the no-JS Apply button, and the phone sheet's "Show N wines" */
#filterRailFormFoot {
    padding-top: 16px;
}

#filterRailFormFootShow {
    display: none;
}

/************* Toolbar *************/

#listToolbar {
    padding-bottom: 14px;
    border-bottom: 1px solid var(--hairline);
}

#listToolbarHead {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px 24px;
}

#listToolbarHeadTitle {
    font-size: var(--font-size-h2);
    font-weight: 800;
    line-height: 1.25;
}

#listToolbarHeadAlert {
    flex: none;
}

#listToolbarControls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 16px;
    margin-top: 14px;
}

#listToolbarControlsChips {
    display: flex;
    flex: 1 1 auto;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

#listToolbarControlsChipsClear {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    padding: 0 4px;
    color: var(--primary);
    font-size: 14px;
    font-weight: 700;
}

#listToolbarControlsChipsClear:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

/* the phone's way into the rail's sheet */
#listToolbarControlsFilters {
    display: none;
}

.listToolbarControlsFiltersCount {
    font-weight: 600;
}

#listToolbarControlsSort {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
}

#listToolbarControlsSortLabel {
    flex: none;
    font-size: 14px;
    font-weight: 700;
}

#listToolbarControlsSortSelect {
    width: auto;
    min-width: 180px;
    font-size: 15px;
}

/************* Rows *************/

/* each row restacks on its own width, so a narrow results column works like a phone */
.wineList {
    margin: 0;
    padding: 0;
    list-style: none;
    container-type: inline-size;
}

.wineListRow {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 110px 180px 150px;
    grid-template-areas: "name price status action";
    gap: 20px;
    align-items: center;
    padding: 18px 0;
    border-bottom: 1px solid var(--hairline);
}

.wineListRowName {
    grid-area: name;
    min-width: 0;
}

.wineListRowNameLink {
    display: block;
    color: var(--black);
    font-size: var(--font-size-body);
    font-weight: 700;
    line-height: 1.35;
    overflow-wrap: anywhere;
}

.wineListRowNameLink:hover {
    color: var(--primary);
    text-decoration: underline;
}

/* on a producer page the producer's part is quieter, still inside the link */
.wineListRowNameLinkProducer {
    color: var(--muted);
}

.wineListRowNameMeta {
    margin-top: 3px;
    color: var(--muted);
    font-size: var(--font-size-meta);
    line-height: 1.45;
}

/* a saved wine: the name and meta on the left, its 44px remove button beside them */
.wineListRowName.removable {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 44px;
    column-gap: 12px;
    align-items: center;
}

.wineListRowName.removable .wineListRowNameLink,
.wineListRowName.removable .wineListRowNameMeta {
    grid-column: 1;
}

.wineListRowNameRemove {
    grid-column: 2;
    grid-row: 1 / span 2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    border-radius: var(--radius);
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}

.wineListRowNameRemove:hover {
    background-color: var(--surface);
    color: var(--danger);
}

.wineListRowNameRemoveIcon {
    flex: none;
}

.wineListRowPrice {
    grid-area: price;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    text-align: right;
}

.wineListRowPriceLabel {
    color: var(--muted);
    font-size: var(--font-size-meta);
}

.wineListRowPriceAmount {
    font-size: 18px;
    font-weight: 800;
    line-height: 1.3;
}

.wineListRowPriceNote {
    color: var(--muted);
    font-size: var(--font-size-meta);
}

/* a price still loading: a grey bar where the amount will be */
.wineListRowPriceSkeleton {
    display: block;
    width: 72px;
    height: 18px;
    margin: 3px 0;
    border-radius: var(--radius-small);
    background-color: var(--track);
    animation: wineListRowPriceSkeletonPulse 1.4s ease-in-out infinite;
}

@keyframes wineListRowPriceSkeletonPulse {
    50% {
        opacity: .5;
    }
}

@media (prefers-reduced-motion: reduce) {
    .wineListRowPriceSkeleton {
        animation: none;
    }
}

/* out of stock: the last price greyed, "Out of stock" under it */
.wineListRowPrice.soldOut .wineListRowPriceAmount {
    color: var(--muted);
}

.wineListRowStatus {
    grid-area: status;
    min-width: 0;
}

.wineListRowAction {
    grid-area: action;
}

/* the 150px column fits "Compare prices" on one line with a slimmer side padding */
.wineListRowActionButton {
    width: 100%;
    padding: 0 12px;
    white-space: nowrap;
}

.wineListNote {
    margin-top: 16px;
    color: var(--muted);
    font-size: var(--font-size-meta);
    line-height: 1.5;
}

/* a narrow column: name and price on top, the pill and the action under them */
@container (max-width: 620px) {
    .wineListRow {
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas:
            "name price"
            "status action";
        gap: 10px 16px;
        padding: 16px 0;
    }

    .wineListRowActionButton {
        width: auto;
    }
}

/************* Empty *************/

#listEmpty {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    margin-top: 20px;
    padding: 28px;
    border: 1px solid var(--hairline);
    border-radius: var(--radius-card);
    background: var(--surface);
}

#listEmptyTitle {
    font-size: var(--font-size-h3);
    font-weight: 700;
}

#listEmptyText {
    color: var(--muted);
    font-size: 15px;
}

#listEmptyChips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 4px;
}

#listEmptyClear {
    margin-top: 6px;
}

/************* Pagination *************/

#listPagination {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px 16px;
    margin-top: 28px;
}

#listPaginationRange {
    color: var(--muted);
    font-size: 14px;
}

#listPaginationPages {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

/* Previous and Next: maroon outline when they go somewhere */
.listPaginationPagesStep {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 44px;
    padding: 0 14px;
    border: 1px solid var(--primary);
    border-radius: var(--radius);
    color: var(--primary);
    font-size: 14px;
    font-weight: 700;
}

.listPaginationPagesStep:hover {
    background: var(--tint);
}

/* the end of the list: a quiet, unclickable control */
.listPaginationPagesStep[aria-disabled="true"] {
    border-color: var(--hairline);
    background: none;
    color: var(--muted);
    font-weight: 600;
    cursor: default;
}

.listPaginationPagesStepIcon {
    flex: none;
}

.listPaginationPagesLink {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    height: 44px;
    padding: 0 10px;
    border: 1px solid var(--control-border);
    border-radius: var(--radius);
    color: var(--black);
    font-size: 14px;
    font-weight: 600;
}

.listPaginationPagesLink:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.listPaginationPagesCurrent {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    height: 44px;
    padding: 0 10px;
    border-radius: var(--radius);
    background: var(--primary);
    color: #FFF;
    font-size: 14px;
    font-weight: 700;
}

.listPaginationPagesGap {
    padding: 0 4px;
    color: var(--muted);
    font-size: 14px;
}

/************* Notice *************/

/* "Filters are coming soon for this page" above a list shown without its rail */
#listResultsNotice {
    margin-bottom: 16px;
    padding: 12px 16px;
    border: 1px solid var(--hairline);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--muted);
    font-size: 14px;
}

/************* Phone sheet *************/

/* no scrolling the page behind the open sheet */
.filterRailOpen {
    overflow: hidden;
}

@media (max-width: 800px) {
    /* Each wine is its own white card on a pale maroon band that runs to the screen
       edges (every page using this list has a 16px phone gutter, pulled back here),
       so one wine can't run into the next. The same treatment as the wine page's
       store rows (wines.css). */
    .wineList {
        display: flex;
        flex-direction: column;
        gap: 12px;
        margin: 0 -16px;
        padding: 16px;
        background-color: var(--tint);
    }

    .wineListRow {
        padding: 16px;
        border: 1px solid var(--tint-border);
        border-radius: var(--radius-card);
        background-color: #FFF;
    }

    #listLayout {
        grid-template-columns: minmax(0, 1fr);
        gap: 0;
        margin-top: 20px;
    }

    /* The rail leaves the column. With no JS the toolbar's Filters link shows it
       in place (:target); with JS it opens as a full-screen sheet (.active). */
    #filterRail {
        display: none;
    }

    #filterRail:target {
        display: flex;
        margin-bottom: 24px;
    }

    #filterRail.active {
        display: flex;
        position: fixed;
        inset: 0;
        z-index: var(--z-sheet);
        padding: 0 16px;
        overflow-y: auto;
        overscroll-behavior: contain;
        background: #FFF;
    }

    #filterRail.active #filterRailHead {
        position: sticky;
        top: 0;
        z-index: var(--z-raised);
        padding: 8px 0;
        background: #FFF;
    }

    #filterRailHeadClose {
        display: inline-flex;
    }

    /* bigger taps inside the sheet */
    .filterRailFormGroupOption {
        min-height: 44px;
    }

    /* the sheet's button stays in reach at the bottom */
    #filterRail.active #filterRailFormFoot {
        position: sticky;
        bottom: 0;
        padding: 12px 0 calc(12px + env(safe-area-inset-bottom));
        border-top: 1px solid var(--hairline);
        background: #FFF;
    }

    #filterRail.active #filterRailFormFootShow {
        display: flex;
        min-height: 48px;
    }

    #listToolbarHeadAlert {
        width: 100%;
    }

    #listToolbarControlsFilters {
        display: flex;
    }

    #listToolbarControlsChips {
        flex-basis: 100%;
        order: 2;
    }

    #listToolbarControlsSortSelect {
        min-width: 0;
    }

    #listPagination {
        justify-content: center;
    }
}
