/* ==========================================================================
   Parts catalog (E1): brand chooser, model lists and the car's catalog
   (groups → subgroups → sections). Views: wpc/index, wpc/brand, wpc/year,
   wpc_saab/cars, wpc_saab/car + _car_browse, wpc/_searchbar.
   Open/close uses sp/disclosure.js through assets/js/sp/catalog.js.
   ========================================================================== */

.sp-cat { padding-bottom: var(--sp-section); }
.sp-cat-back { min-height: var(--sp-hit); }
.sp-cat-title { margin: 4px 0 0; }
.sp-cat-subtitle { margin: 8px 0 0; color: var(--sp-ink-soft); font-size: var(--sp-fs-lg); }
.sp-cat-lead { max-width: 640px; margin: 12px 0 0; color: var(--sp-ink-soft); font-size: var(--sp-fs-lg); }
.sp-cat-hint { margin: 12px 0 0; color: var(--sp-ink-soft); font-size: var(--sp-fs-ui); }
.sp-cat .sp-empty { margin-top: 16px; }
.sp-cat .sp-empty p + a { display: inline-block; margin-top: 10px; }
.sp-cat-notice { margin: 0 0 16px; }

/* --- Toolbar: search the car's catalog + filter button -------------------- */
.sp-cat-toolbar { display: flex; align-items: center; gap: 8px; margin: 24px 0 12px; }
.sp-cat-find { flex: 1; min-width: 0; max-width: 560px; }

/* --- Filter pills: brand page inline, car catalog in the filter dialog ---- */
.sp-cat-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 16px; }
.sp-cat-filter {
    position: relative; display: flex; min-width: 120px; max-width: 300px;
    border-radius: var(--sp-r-ctl); background: var(--sp-surface);
    transition: background var(--sp-fast), box-shadow var(--sp-fast);
}
.sp-cat-filter:hover { background: var(--sp-t1); }
.sp-cat-filter.is-set { background: var(--sp-paper); box-shadow: inset 0 0 0 1px var(--sp-t3); }
.sp-cat-filter.is-locked { opacity: .7; }
.sp-cat-filter:focus-within { outline: 3px solid var(--sp-focus); outline-offset: 2px; }
.sp-cat-filter > label {
    position: absolute; top: 8px; left: 14px; right: 40px; pointer-events: none;
    font-size: var(--sp-fs-xs); line-height: 1.3; color: var(--sp-ink-soft);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sp-cat-filter select {
    width: 100%; min-width: 0; min-height: 56px; margin: 0; padding: 24px 42px 8px 14px;
    border: 0; border-radius: var(--sp-r-ctl); background: transparent; box-shadow: none; outline: 0;
    -webkit-appearance: none; appearance: none;
    font: 500 var(--sp-fs-ui)/1.3 var(--sp-font); color: var(--sp-ink);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer;
}
.sp-cat-filter select:disabled { cursor: default; }
.sp-cat-filter-chev {
    position: absolute; right: 14px; top: 50%; width: 16px; height: 16px; margin-top: -8px;
    color: var(--sp-ink-soft); pointer-events: none;
}
.sp-cat-filter-x {
    position: absolute; right: 6px; top: 50%; display: grid; place-items: center;
    width: 36px; height: 36px; margin-top: -18px; padding: 0;
    border: 0; border-radius: 50%; background: none; color: var(--sp-ink-soft); cursor: pointer;
}
.sp-cat-filter-x:hover { background: var(--sp-surface); color: var(--sp-ink); }
.sp-cat-filter-x svg { width: 16px; height: 16px; }
.sp-cat-clear {
    display: inline-flex; align-items: center; min-height: var(--sp-hit); padding: 0 6px;
    color: var(--sp-action); font-weight: 600; font-size: var(--sp-fs-ui);
    text-decoration: underline; text-decoration-color: var(--sp-t2); text-underline-offset: 4px;
}
body.sp .sp-cat-clear:hover { color: var(--sp-action); text-decoration-color: currentColor; }

/* Without the saved car the filters stay on the page */
.sp-cat-filterbox { margin: 0 0 16px; }
.sp-cat-group-empty { margin: 0; padding: 4px 16px 14px; color: var(--sp-ink-soft); }
.sp-cat-filterbox .sp-check-row { margin-bottom: 12px; }
.sp-cat-filterbox .sp-cat-filters { margin: 0; }

/* One column in the dialog, so long values (badge, gearbox) read in full */
.sp-cat-filter-dialog .sp-cat-filters { display: grid; grid-template-columns: minmax(0, 1fr); margin: 16px 0 0; }
.sp-cat-filter-dialog .sp-cat-filter { max-width: none; min-width: 0; }
.sp-cat-filter-dialog .sp-cat-clear { margin-top: 8px; padding: 0; }

/* --- Catalog tree ----------------------------------------------------------- */
#wpc-browse.htmx-request .sp-cat-tree { opacity: .55; transition: opacity var(--sp-fast); }

.sp-cat-group { border-radius: var(--sp-r-ctl); background: var(--sp-surface); transition: background var(--sp-fast); }
.sp-cat-group + .sp-cat-group { margin-top: 6px; }
.sp-cat-group:has(> .sp-cat-group-head[aria-expanded="true"]) { background: var(--sp-surface-2); }
.sp-cat-group-head {
    display: flex; align-items: flex-start; gap: 14px; width: 100%; min-height: 64px; padding: 17px 20px;
    border: 0; border-radius: var(--sp-r-ctl); background: none; color: inherit;
    font: inherit; text-align: left; cursor: pointer;
}
.sp-cat-group-head:hover { background: var(--sp-surface-2); }
.sp-cat-icon { flex: none; width: 24px; height: 24px; margin-top: 2px; color: var(--sp-ink-soft); }
.sp-cat-group-title { flex: 1; min-width: 0; }
.sp-cat-group-name {
    display: block; font-weight: 600; font-size: var(--sp-fs-h3); line-height: 1.3;
    letter-spacing: -0.01em; overflow-wrap: anywhere;
}
.sp-cat-group-subs {
    display: block; margin-top: 4px; color: var(--sp-ink-soft);
    font-size: var(--sp-fs-sm); line-height: 1.5; overflow-wrap: anywhere;
}
.sp-cat .sp-chev {
    flex: none; width: 20px; height: 20px; margin: 3px 0 0 auto; color: var(--sp-ink-soft);
    transition: transform var(--sp-open) var(--sp-ease-open);
}
.sp-cat [aria-expanded="true"] > .sp-chev { transform: rotate(180deg); }
.sp-cat-group.is-misfit .sp-cat-group-name,
.sp-cat-sub.is-misfit .sp-cat-sub-name { color: var(--sp-ink-soft); }

.sp-cat-group-body { padding: 0 20px 12px 58px; }
.sp-cat-sub + .sp-cat-sub { border-top: 1px solid var(--sp-line-strong); }
.sp-cat-sub-head {
    display: flex; align-items: center; gap: 12px; width: 100%; min-height: 48px; padding: 11px 0;
    border: 0; background: none; color: inherit; text-align: left; cursor: pointer;
    font: 600 var(--sp-fs-lg)/1.3 var(--sp-font);
}
.sp-cat-sub-head:hover { color: var(--sp-action); }
.sp-cat-sub-head .sp-chev { margin-top: 0; }
.sp-cat-sub-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.sp-cat-sub-code { margin-right: 6px; font-variant-numeric: tabular-nums; }
.sp-cat-sub-body { padding-bottom: 10px; }

.sp-cat-leaves { display: grid; gap: 5px; margin: 0; padding: 0; list-style: none; }
.sp-cat-leaves > li { scroll-margin: 96px 0 24px; min-width: 0; }
.sp-cat-leaves-head { padding: 10px 2px 2px; color: var(--sp-ink-soft); font-size: var(--sp-fs-sm); font-weight: 600; }
.sp-cat-leaves-head:first-child { padding-top: 0; }
.sp-cat-leaf {
    display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr) 18px; align-items: start; gap: 16px;
    padding: 12px 14px; border-radius: var(--sp-r-sm); background: var(--sp-paper); color: var(--sp-ink);
    text-decoration: none; transition: box-shadow var(--sp-fast);
}
.sp-cat-leaf:hover { box-shadow: inset 0 0 0 1px var(--sp-line-strong); }
.sp-cat-leaf.is-other { background: var(--sp-surface); }
.sp-cat-leaf.is-return { box-shadow: inset 0 0 0 2px var(--sp-t3); }
.sp-cat-leaf-name { min-width: 0; }
.sp-cat-leaf-name strong { display: block; font-weight: 500; font-size: var(--sp-fs-body); line-height: 1.4; overflow-wrap: anywhere; }
.sp-cat-leaf-name .sp-section-product-hidden { margin-top: 3px; }
.sp-cat-leaf-name small { display: block; margin-top: 3px; color: var(--sp-warn); font-size: var(--sp-fs-xs); }
.sp-cat-leaf-axle { display: flex; align-items: center; gap: 6px; margin-top: 4px; color: var(--sp-ink-soft); font-size: var(--sp-fs-xs); font-weight: 500; line-height: 1.2; }
.sp-cat-leaf-axle .sp-side-car { width: 14px; height: 22px; }
.sp-cat-leaf-note { min-width: 0; color: var(--sp-ink-soft); font-size: var(--sp-fs-ui); line-height: 1.5; overflow-wrap: anywhere; }
.sp-cat-leaf-note > span { display: block; }
.sp-cat-leaf-arrow { width: 18px; height: 18px; margin-top: 2px; color: var(--sp-ink-faint); }

/* Admin tools sit beside the row (wpc-saab-browse-admin.css lays out the li) */
.sp-cat-leaves > li.has-admin-edit > .sp-cat-leaf.wpc-section-link { min-width: 0; }
.sp-cat-group-head .wpc-subgroup-create { margin-left: 10px; vertical-align: 3px; }
.sp-cat .sp-cat-leaves > li.has-admin-edit > .wpc-sec-drag,
.sp-cat .sp-cat-leaves > li.has-admin-edit > .wpc-section-admin-tools { margin-top: 12px; }
@media (max-width: 600px) {
    /* Admin: tools drop under the row so the section name keeps its width */
    .sp-cat .sp-cat-leaves > li.has-admin-edit { grid-template-columns: auto minmax(0, 1fr); }
    .sp-cat .sp-cat-leaves > li.has-admin-edit > .wpc-section-admin-tools { grid-column: 2; justify-self: end; margin-top: 2px; }
}

@media (max-width: 600px) {
    .sp-cat-toolbar { margin-top: 18px; }
    .sp-cat-filters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .sp-cat-filter { max-width: none; min-width: 0; }
    .sp-cat-clear { grid-column: 1 / -1; justify-self: start; }

    .sp-cat-group-head { gap: 11px; min-height: 56px; padding: 14px 12px; }
    .sp-cat-icon { width: 22px; height: 22px; }
    .sp-cat-group-name { font-size: var(--sp-fs-lg); }
    .sp-cat-group-body { padding: 0 12px 10px; }
    .sp-cat-sub-head { font-size: var(--sp-fs-body); }
    .sp-cat-leaf,
    .sp-cat-leaves > li.has-admin-edit > .sp-cat-leaf.wpc-section-link {
        grid-template-columns: minmax(0, 1fr) 16px; gap: 5px 10px; padding: 12px;
    }
    .sp-cat-leaf-name { grid-column: 1; grid-row: 1; }
    .sp-cat-leaf-note { grid-column: 1 / -1; grid-row: 2; font-size: var(--sp-fs-sm); }
    .sp-cat-leaf-note:empty { display: none; }
    .sp-cat-leaf-arrow { grid-column: 2; grid-row: 1; width: 16px; height: 16px; }
}

/* --- OE number search (wpc/_searchbar) --------------------------------------- */
.sp-cat-oe { max-width: 400px; margin-top: 24px; }

/* --- Brand chooser ---------------------------------------------------------- */
.sp-cat-brands { display: grid; gap: var(--sp-gap); margin-top: 32px; }
@media (min-width: 700px) { .sp-cat-brands { grid-template-columns: 1fr 1fr; } }
.sp-cat-brand {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    min-height: 140px; padding: 28px; border-radius: var(--sp-r-card); background: var(--sp-surface);
    text-decoration: none; transition: box-shadow var(--sp-fast);
}
.sp-cat-brand:hover { box-shadow: inset 0 0 0 1px var(--sp-line-strong); }
.sp-cat-brand strong { display: block; font-weight: 600; font-size: var(--sp-fs-h2); line-height: 1.1; letter-spacing: -0.025em; }
.sp-cat-brand small { display: block; margin-top: 8px; color: var(--sp-ink-soft); font-size: var(--sp-fs-ui); }
.sp-cat-brand svg { flex: none; width: 24px; height: 24px; }

/* --- Model lists -------------------------------------------------------------- */
.sp-cat-models {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); grid-auto-rows: 1fr; gap: 6px;
    margin: 24px 0 0; padding: 0; list-style: none;
}
.sp-cat-model {
    display: flex; align-items: center; gap: 12px; height: 100%; min-height: 56px; padding: 12px 16px;
    border-radius: var(--sp-r-ctl); background: var(--sp-surface); text-decoration: none;
    transition: box-shadow var(--sp-fast);
}
.sp-cat-model:hover { box-shadow: inset 0 0 0 1px var(--sp-line-strong); }
.sp-cat-model.is-car { background: var(--sp-paper); box-shadow: inset 0 0 0 1px var(--sp-t3); }
.sp-cat-model-name { flex: 1; min-width: 0; font-weight: 500; overflow-wrap: anywhere; }
.sp-cat-model-tag {
    display: inline-block; padding: 2px 9px; border-radius: var(--sp-r-pill); white-space: nowrap;
    background: var(--sp-t1); color: var(--sp-action); font-size: var(--sp-fs-xs); font-weight: 600; vertical-align: 1px;
}
.sp-cat-matches { display: flex; flex-wrap: wrap; gap: 8px 20px; margin-top: 24px; }
.sp-cat-match { display: flex; align-items: center; gap: 8px; color: var(--sp-ink-soft); font-size: var(--sp-fs-sm); }
.sp-cat-matches + .sp-cat-models { margin-top: 12px; }
.sp-cat-model-years { flex: none; color: var(--sp-ink-soft); font-size: var(--sp-fs-sm); font-variant-numeric: tabular-nums; white-space: nowrap; }
.sp-cat-model > svg { flex: none; width: 16px; height: 16px; color: var(--sp-ink-faint); }
.sp-cat-models + .sp-cat-hint { margin-top: 16px; }
.sp-cat-brand-filters { margin-top: 24px; }
.sp-cat > .sp-lookup--catalog { max-width: 400px; margin-top: 24px; }
.sp-lookup--catalog .sp-lookup-box { display: flex; align-items: center; gap: 6px; height: 56px; padding-right: 5px; border: 1px solid var(--sp-line-strong); border-radius: var(--sp-r-sm); background: var(--sp-surface); }
.sp-lookup--catalog .sp-lookup-box:focus-within { outline: 2px solid var(--sp-focus); outline-offset: 2px; }
.sp-lookup--catalog .sp-plate { flex: 1; min-width: 0; height: 54px; border-radius: calc(var(--sp-r-sm) - 1px) 0 0 calc(var(--sp-r-sm) - 1px); background: transparent; box-shadow: none; }
.sp-lookup--catalog .sp-plate:focus-within { box-shadow: none; }
.sp-lookup--catalog .sp-lookup-go { flex: none; width: var(--sp-hit); min-height: var(--sp-hit); padding: 0; border-radius: var(--sp-r-pill); }
.sp-lookup--catalog:has(input:placeholder-shown) .sp-lookup-go:not([aria-busy="true"]) { visibility: hidden; }
