/*========================
====Tuotelistaus (block)==
==========================*/

.ts-product-list {
    position: relative;

    /* Sits between the page base (#191919) and the palette's background
       (#343434), which reads too light behind the table. Defined once so the
       filter bar and heading row stay in step. */
    --ts-pl-panel: #232323;
}

/* The category strip above the list is hidden on desktop, but the column's flow
   layout still spaces the list off it, leaving a gap that pushes the table
   below the sidebar. The gap comes back where the strip shows (≤900px). */
.ts-catalog__main > .ts-product-list {
    margin-block-start: 0;
}

/* ---- Filter bar ---- */

.ts-product-list__filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 24px;
    margin-bottom: 20px;
    padding: 14px 18px;
    background-color: var(--ts-pl-panel);
    border: solid 1px #444444;
}

.ts-pl__filter {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* The element selector is needed to outweigh WooCommerce's own
   `.woocommerce-page label { margin-bottom: .7em }`, which otherwise lifts the
   label off the select's centre line. */
.ts-product-list label.ts-pl__filter-label {
    margin: 0;
}

.ts-pl__filter-label {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: #fff;
}

/*
 * The browser's own arrow is drawn at the select's right edge and can't be
 * repositioned, so the native widget is switched off and the chevron drawn as a
 * background image instead — that makes its colour, size and inset ours.
 */
.ts-pl__filter-select {
    appearance: none;
    -webkit-appearance: none;
    padding: .55em 2.6em .55em .9em;
    border: solid 1px #444444;
    background-color: var(--wp--preset--color--base, #191919);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5' stroke='%23ffffff' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    background-size: 12px 8px;
    color: #fff;
    font-family: "Space Grotesk", sans-serif;
}

/*
 * One focus treatment for everything tabbable in the list. The theme's default
 * outline is near-black and effectively invisible on this panel, and
 * appearance:none drops the select's native ring entirely.
 */
.ts-product-list a:focus-visible,
.ts-product-list button:focus-visible,
.ts-product-list select:focus-visible {
    outline: solid 2px var(--wp--preset--color--accent, #EE003C);
    outline-offset: 2px;
}

/*
 * Something further up the cascade outlines plain :focus, so clicking a control
 * with the mouse left a ring behind. Keyboard focus keeps the ring above;
 * pointer focus gets none.
 */
.ts-product-list a:focus:not(:focus-visible),
.ts-product-list button:focus:not(:focus-visible),
.ts-product-list select:focus:not(:focus-visible) {
    outline: none;
}

/*
 * The native dropdown popup takes its colours from the option elements. Leaving
 * them transparent means the OS paints the list white, and the inherited white
 * text disappears — so both are set explicitly here.
 */
.ts-pl__filter-select option {
    background-color: var(--wp--preset--color--base, #191919);
    color: #fff;
}

/* Pushed to the far end of the bar, with Tyhjennä (when present) after it. */
.ts-pl__count {
    margin-left: auto;
    color: #9A9A9A;
    font-size: 13px;
    white-space: nowrap;
}

.ts-pl__clear {
    padding: .55em 1.1em;
    border: solid 1px #7E7E7E;
    color: #fff;
    font-size: 13px;
    letter-spacing: .08em;
    text-transform: uppercase;
    text-decoration: none;
}

.ts-pl__clear:hover,
.ts-pl__clear:focus-visible {
    border-color: var(--wp--preset--color--accent, #EE003C);
    color: var(--wp--preset--color--accent, #EE003C);
}

/* ---- Empty state ----
   Given the same panel treatment as the filter bar and footer, so a category
   with nothing in it still looks built rather than broken. */

.ts-product-list__empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 56px 24px;
    background-color: var(--ts-pl-panel);
    border: solid 1px #444444;
    color: #9A9A9A;
    text-align: center;
}

.ts-pl__empty-icon {
    margin-bottom: 6px;
    color: #5A5A5A;
}

/* WooCommerce's own paragraph margins outrank a lone class selector here, the
   way they did for the filter labels — hence the extra qualification. */
.ts-product-list .ts-product-list__empty p {
    margin: 0;
}

.ts-pl__empty-title {
    color: #fff;
    font-size: 17px;
    font-weight: 700;
}

.ts-pl__empty-text {
    max-width: 42ch;
    font-size: 14px;
}

.ts-pl__empty-action {
    margin-top: 10px;
    padding: .55em 1.4em;
    border: solid 1px #7E7E7E;
    color: #fff;
    font-size: 13px;
    letter-spacing: .08em;
    text-transform: uppercase;
    text-decoration: none;
}

.ts-pl__empty-action:hover,
.ts-pl__empty-action:focus-visible {
    border-color: var(--wp--preset--color--accent, #EE003C);
    color: var(--wp--preset--color--accent, #EE003C);
}

/* Dimmed while a sort or page change is in flight. */
.ts-product-list__results[aria-busy="true"] {
    opacity: .5;
}

@media (prefers-reduced-motion: no-preference) {
    .ts-product-list__results {
        transition: opacity .15s ease;
    }
}

.ts-product-list__table {
    width: 100%;
    border-collapse: collapse;
    font-family: "Space Grotesk", sans-serif;
}

/* ---- Heading row ----
   Outlined like the footer, so the table reads as one panel top to bottom. The
   accent underline outranks the grey along the bottom edge (wider border wins
   in the collapsed model). */

.ts-product-list__table thead tr {
    border: solid 1px #444444;
}

.ts-product-list__table thead th {
    padding: 12px 16px;
    background-color: var(--ts-pl-panel);
    border-bottom: solid 2px var(--wp--preset--color--accent, #EE003C);
    text-align: left;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    white-space: nowrap;
}

/* The price column is right-aligned, so its heading follows. */
.ts-product-list__table thead th.ts-pl__col--hinta {
    text-align: right;
}

.ts-pl__sort {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #fff;
    text-decoration: none;
}

.ts-pl__sort:hover,
.ts-pl__sort:focus-visible,
.ts-pl__sort.is-active {
    color: var(--wp--preset--color--accent, #EE003C);
}

.ts-pl__arrow {
    font-size: 11px;
    opacity: .55;
}

.ts-pl__sort.is-active .ts-pl__arrow {
    opacity: 1;
}

/* ---- Rows ---- */

.ts-pl__row {
    border-bottom: solid 1px #2E2E2E;
}

/* The footer's own top border closes the table instead, so the two don't stack
   into a double rule. */
.ts-pl__row:last-child {
    border-bottom: none;
}

.ts-pl__row:hover {
    background-color: #232323;
}

.ts-pl__cell {
    padding: 12px 16px;
    vertical-align: middle;
    font-size: 15px;
}

.ts-pl__cell--product {
    display: flex;
    align-items: center;
    gap: 16px;
}

.ts-pl__thumb {
    flex: 0 0 auto;
    width: 48px;
    height: 40px;
    display: block;
    border: solid 1px #3A3A3A;
    overflow: hidden;
}

.ts-pl__thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.ts-pl__titles {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.ts-pl__name {
    color: #fff;
    font-weight: 700;
    text-decoration: none;
}

.ts-pl__name:hover,
.ts-pl__name:focus-visible {
    color: var(--wp--preset--color--accent, #EE003C);
}

.ts-pl__meta {
    color: #9A9A9A;
    font-size: 13px;
}

/* Monospaced so codes of the same profile family line up digit for digit and a
   transposed number is visible at a glance. The site loads no mono webfont, so
   this is the platform's own. */
.ts-pl__cell--koodi {
    color: #D6D6D6;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 13px;
    white-space: nowrap;
}

.ts-pl__cell--varasto {
    white-space: nowrap;
}

.ts-pl__dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-right: 8px;
    border-radius: 50%;
    background-color: #35C46A;
    vertical-align: middle;
}

/* Four states: a thin stock reads as a warning, an orderable out-of-stock item
   (Tilaustuote) as a ring. Thresholds live in inc/stock-display. */
.ts-pl__dot.is-low {
    background-color: #F0A000;
}

.ts-pl__dot.is-out {
    background-color: #8A8A8A;
}

.ts-pl__dot.is-order {
    background-color: transparent;
    box-shadow: inset 0 0 0 2px #8A8A8A;
}

.ts-pl__cell--hinta {
    text-align: right;
    white-space: nowrap;
}

.ts-pl__amount {
    display: block;
    font-size: 18px;
    font-weight: 700;
}

.ts-pl__tax {
    display: block;
    color: #9A9A9A;
    font-size: 12px;
}
.ts-pl__cell--action {
    text-align: right;
    white-space: nowrap;
}

.ts-pl__button {
    display: inline-block;
    padding: 10px 14px;
    background-color: var(--wp--preset--color--accent, #EE003C);
    border: none;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    text-decoration: none;
    white-space: nowrap;
}

.ts-pl__button:hover,
.ts-pl__button:focus-visible {
    background-color: #FF3D68;
    color: #fff;
}

/* ---- Footer summary ---- */

.ts-product-list__footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px 16px;
    padding: 14px 16px;
    background-color: var(--ts-pl-panel);
    border: solid 1px #444444;
    color: #9A9A9A;
    font-size: 13px;
}

.ts-pl__updated {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ---- Hover preview ---- */

.ts-product-list__preview {
    position: absolute;
    z-index: 20;
    width: 260px;
    padding: 8px;
    background-color: #1B1B1B;
    border: solid 1px #3A3A3A;
    box-shadow: 0 12px 32px rgba(0, 0, 0, .55);
    pointer-events: none;
}

.ts-product-list__preview[hidden] {
    display: none;
}

.ts-product-list__preview img {
    display: block;
    width: 100%;
    height: auto;
}

.ts-product-list__preview-caption {
    display: block;
    margin-top: 6px;
    color: #9A9A9A;
    font-family: "IBM Plex Mono", ui-monospace, monospace;
    font-size: 11px;
}

/* ---- Pagination ---- */

.ts-product-list__pagination {
    margin-top: 24px;
}

.ts-product-list__pagination .page-numbers {
    display: inline-block;
    padding: 6px 12px;
    margin-right: 4px;
    border: solid 1px #3A3A3A;
    color: #fff;
    text-decoration: none;
}

.ts-product-list__pagination .page-numbers.current,
.ts-product-list__pagination .page-numbers:hover {
    border-color: var(--wp--preset--color--accent, #EE003C);
    color: var(--wp--preset--color--accent, #EE003C);
}

/* The sort dropdown is mobile-only; on desktop the column headings do the job. */
.ts-pl__filter--sort {
    display: none;
}

.ts-product-list__filters--sort-only {
    display: none;
}

/* ---- Narrow screens ----
   Each row becomes a three-line card: image beside the title, then code, stock
   and price on one line. Labels are dropped since the values read for
   themselves, and the whole row becomes the tap target. */

@media (max-width: 900px) {
    .ts-catalog__main > .ts-product-list {
        margin-block-start: var(--wp--style--block-gap);
    }

    .ts-pl__filter--sort,
    .ts-product-list__filters--sort-only {
        display: flex;
    }

    .ts-product-list__filters {
        gap: 10px 16px;
    }

    .ts-pl__filter {
        flex: 1 1 100%;
    }

    .ts-pl__filter-select {
        flex: 1 1 auto;
    }

    .ts-product-list__table thead {
        display: none;
    }

    .ts-product-list__table,
    .ts-product-list__table tbody {
        display: block;
        width: 100%;
    }

    .ts-pl__row {
        position: relative;
        display: grid;
        grid-template-columns: auto auto 1fr;
        align-items: center;
        gap: 6px 14px;
        padding: 14px 0;
    }

    .ts-pl__cell {
        display: block;
        padding: 0;
    }

    .ts-pl__cell--product {
        grid-column: 1 / -1;
        display: flex;
        align-items: center;
        gap: 14px;
    }

    /* Bigger than the desktop thumb, same 6:5 crop, so the two views frame the
       profile identically. */
    .ts-pl__thumb {
        width: 64px;
        height: 54px;
    }

    .ts-pl__cell--koodi {
        grid-column: 1;
        font-size: 14px;
    }

    .ts-pl__cell--varasto {
        grid-column: 2;
    }

    .ts-pl__cell--hinta {
        grid-column: 3;
        text-align: right;
    }

    /* The row is tappable instead, so the button is redundant here. */
    .ts-pl__cell--action {
        display: none;
    }

    .ts-pl__amount {
        font-size: 17px;
    }

    /* Stretches the product link across the whole row, so tapping anywhere
       opens the product while the link itself stays the keyboard target. */
    .ts-pl__name::after {
        content: "";
        position: absolute;
        inset: 0;
    }
}
