/*
 * Copyright (c) 2026.  SimplyMetadata LLC
 *
 * The list pages' filter, sort and columns dialogs (partials/filter_modal,
 * sort_modal, columns_modal), shared by busterapp and archiveapp. Colours
 * come from the app's variables (colors.css and the app theme): the
 * archive names (--surface-card, --hairline, --brand) fall back to the
 * shared ones (--border, --accent).
 */

/* ====================================
   Filter dialog — one filter per row
   ==================================== */

.bstr-filter-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 16px;
    max-height: 65vh;
    overflow-y: auto;
    padding-right: 4px;
}

/* Desktop: [label op] | value controls on one line; a fixed head column
   (room for a label and its op select) so every value starts at the
   same x across rows. */
.bstr-filter-row {
    display: grid;
    grid-template-columns: 15rem 1fr;
    align-items: center;
    gap: 8px 12px;
    padding: 4px 0;
    border-bottom: 1px solid var(--hairline, var(--border, rgba(128, 128, 128, 0.2)));
}

.bstr-filter-row:last-child {
    border-bottom: none;
}

/* The label with its op select beside it, left-justified */
.bstr-filter-head {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    min-width: 7rem;
}

.bstr-filter-head > select {
    margin-bottom: 0;
}

.bstr-filter-label {
    margin: 0;
    font-family: "Space Mono", ui-monospace, monospace;
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-light, #888);
}

.bstr-filter-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-start;
    gap: 6px 8px;
    min-width: 0;
}

.bstr-filter-controls > input,
.bstr-filter-controls > bstr-tags,
.bstr-filter-value2 > input {
    margin-bottom: 0;
}

.bstr-filter-op {
    width: auto;
    flex: 0 0 auto;
    min-width: 6rem;
}

.bstr-filter-controls > input[type="text"],
.bstr-filter-controls > bstr-tags {
    flex: 1 1 12rem;
    min-width: 8rem;
}

/* Numeric and date inputs are compact so a between's two bounds share
   one line ("1942 and 1946") */
.bstr-filter-controls input[type="number"] {
    flex: 0 0 7rem;
    width: 7rem;
}

.bstr-filter-controls input[type="date"] {
    flex: 0 0 9.5rem;
    width: 9.5rem;
}

.bstr-filter-controls input[type="datetime-local"] {
    flex: 0 0 12.5rem;
    width: 12.5rem;
}

.bstr-filter-controls > input[type="checkbox"] {
    margin: 0;
}

.bstr-filter-value2 {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
}

.bstr-filter-value2[hidden] {
    display: none;
}

.bstr-filter-value2 > input {
    flex: 0 0 auto;
}

.bstr-filter-range-sep {
    color: var(--text-light, #888);
    font-size: 0.85rem;
}

/* Mobile: the label and op on one line, the value controls underneath,
   left-justified */
@media (max-width: 768px) {
    .bstr-filter-row {
        display: block;
        padding: 8px 0;
    }

    .bstr-filter-head {
        margin-bottom: 4px;
    }

    .bstr-filter-controls {
        justify-content: flex-start;
    }
}

/* ====================================
   Sort dialog — draggable rows with a none / asc / desc control
   ==================================== */

.bstr-sort-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 20px;
    max-height: 60vh;
    overflow-y: auto;
}

.bstr-sort-item {
    display: flex !important;
    align-items: center;
    padding: 8px 12px;
    background: var(--surface-card, var(--pico-card-background-color, transparent));
    border: 1px solid var(--hairline, var(--border, rgba(128, 128, 128, 0.25)));
    border-radius: 10px;
    margin: 0 !important;
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease,
                border-color 0.2s ease;
    cursor: grab;
}

/* Highlight rows that take part in the sort */
.bstr-sort-item:has(input[value="asc"]:checked),
.bstr-sort-item:has(input[value="desc"]:checked) {
    border-color: color-mix(in srgb, var(--brand, var(--accent, #c33)) 45%,
                            var(--hairline, var(--border, transparent)));
    background: color-mix(in srgb, var(--brand, var(--accent, #c33)) 5%,
                          var(--surface-card, transparent));
}

.bstr-sort-item.dragging {
    opacity: 0.4;
    border: 1px dashed var(--brand, var(--accent, #e91e63));
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.bstr-sort-item:active {
    cursor: grabbing;
}

.bstr-sort-item-drag-handle {
    display: flex;
    align-items: center;
    color: var(--text-light, #888);
    user-select: none;
}

.bstr-sort-item-drag-handle i {
    cursor: grab;
    font-size: 20px;
    margin: 0;
}

.bstr-sort-item-content {
    flex-grow: 1;
    margin-left: 12px;
    font-weight: 500;
}

/* Segmented none / asc / desc control */
.bstr-sort-seg {
    display: inline-flex;
    border: 1px solid var(--hairline, var(--border, rgba(128, 128, 128, 0.3)));
    border-radius: 999px;
    overflow: hidden;
}

.bstr-sort-seg label {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    padding: 5px 0;
    margin: 0;
    cursor: pointer;
    transition: background 140ms ease, color 140ms ease;
}

.bstr-sort-seg label + label {
    border-left: 1px solid var(--hairline, var(--border, rgba(128, 128, 128, 0.3)));
}

.bstr-sort-seg input[type="radio"] {
    display: none;
}

.bstr-sort-seg i {
    font-size: 18px;
    margin: 0;
    color: var(--text-light, #999);
}

.bstr-sort-seg label:hover i {
    color: var(--brand-strong, var(--brand, var(--accent, #c33)));
}

.bstr-sort-seg label:has(input:checked) {
    background: var(--brand, var(--accent, #c33));
}

.bstr-sort-seg label:has(input:checked) i {
    color: #fff;
}

/* 'Not sorted' selected: keep it quiet rather than brand-coloured */
.bstr-sort-seg label:has(input[value=""]:checked) {
    background: var(--surface-sunken, var(--button-bar-bg, rgba(128, 128, 128, 0.12)));
}

.bstr-sort-seg label:has(input[value=""]:checked) i {
    color: var(--text-light, #888);
}

/* ====================================
   Columns dialog — draggable rows with a checkbox
   ==================================== */

.bstr-columns-list {
    gap: 6px;
}

.bstr-columns-item {
    gap: 10px;
    padding: 6px 12px;
}

.bstr-columns-item:has(input:checked) {
    border-color: color-mix(in srgb, var(--brand, var(--accent, #c33)) 45%,
                            var(--hairline, var(--border, transparent)));
    background: color-mix(in srgb, var(--brand, var(--accent, #c33)) 5%,
                          var(--surface-card, transparent));
}

.bstr-columns-item input[type="checkbox"] {
    margin: 0;
}

.bstr-columns-item-label {
    flex-grow: 1;
    margin: 0;
    font-weight: 500;
    cursor: pointer;
}
