/*
 * Matrix Detail Block
 *
 * Hero + spec table. Keep the markup recognizable: a matrix page is an
 * interactive version of a printed catalog page, so the table reads
 * like a catalog — rows of variants with their specs, ending in price
 * and an action column.
 */

.ims-matrix-detail {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin: 0 0 3rem;
}

/* -----------------------------------------------------------------------
 * Archive layout collapse on a matrix-swapped category page
 * -----------------------------------------------------------------------
 *
 * The product archive template (templates/archive-product.html) lays
 * out a two-column grid: a filter sidebar on the left and the product
 * loop on the right. On a matrix-swapped category the filters block
 * bails (it doesn't apply — the matrix-detail block has its own per-
 * spec dropdowns) but the surrounding `ims-filter-sidebar-wrapper`
 * group still renders as an empty column. Body-class targeting lets
 * us collapse that wrapper and stretch the products column full
 * width without touching the template markup itself.
 */
body.ims-matrix-view .ims-filter-sidebar-wrapper {
    display: none;
}
body.ims-matrix-view .ims-product-listing-layout {
    display: block;
}
body.ims-matrix-view .ims-products-main {
    width: 100%;
}

/* Matrix-mode header. The standard header collapses to a slim bar
 * with only the view toggle (matrix / grid / list) — title, count and
 * sort are owned by the matrix-detail block below. Right-align the
 * toggle since there's no title to balance it on the left.
 */
.ims-product-listing-header--matrix .ims-page-title-row {
    justify-content: flex-end;
    padding-top: 6px;
    padding-bottom: 6px;
    border-bottom: 0;
}

/* -----------------------------------------------------------------------
 * Hero
 * ----------------------------------------------------------------------- */

.ims-matrix-hero {
    display: grid;
    grid-template-columns: minmax(0, 220px) 1fr;
    gap: 2rem;
    align-items: start;
    padding: 0.75rem 0 0.75rem;
    border-bottom: 1px solid #e5e7eb;
}

/* No image set on the term — collapse to a single full-width column so
 * the title/blurb don't get jammed into the (empty) media slot. */
.ims-matrix-hero--no-media {
    grid-template-columns: 1fr;
}

.ims-matrix-hero-media {
    display: flex;
    align-items: flex-start;
    justify-content: center;
}

.ims-matrix-hero-img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    background: #fff;
    border: 1px solid #e5e7eb;
    padding: 12px;
}

.ims-matrix-hero-body {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.ims-matrix-hero-sku {
    font-family: ui-monospace, 'SF Mono', Menlo, monospace;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: #6b7280;
    margin: 0;
}

.ims-matrix-hero-title {
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    line-height: 1.1;
    margin: 0;
    color: #111827;
}

.ims-matrix-hero-blurb {
    font-size: 1rem;
    color: #4b5563;
    line-height: 1.5;
    margin: 0.25rem 0 0;
}

.ims-matrix-hero-count {
    font-size: 0.875rem;
    color: #6b7280;
    margin: 0.25rem 0 0;
}

/* -----------------------------------------------------------------------
 * Long description
 * ----------------------------------------------------------------------- */

.ims-matrix-long-desc {
    font-size: 0.95rem;
    line-height: 1.6;
    color: #374151;
}

.ims-matrix-long-desc p:first-child { margin-top: 0; }
.ims-matrix-long-desc p:last-child  { margin-bottom: 0; }

/* -----------------------------------------------------------------------
 * Filter meta bar
 *
 * Slim strip above the table holding the result count and Clear button.
 * Dropdowns live IN the table thead (below), aligned per column.
 * ----------------------------------------------------------------------- */

.ims-matrix-filter-meta {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 0.75rem;
    padding: 0 0.25rem 0.25rem;
}

.ims-matrix-filter-count {
    font-size: 0.8rem;
    color: #6b7280;
}

.ims-matrix-filter-clear {
    font-size: 0.72rem;
    font-weight: 600;
    color: #4f46e5;
    background: transparent;
    border: 1px solid #c7d2fe;
    border-radius: 6px;
    padding: 0.3rem 0.6rem;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.ims-matrix-filter-clear:hover {
    background: #eef2ff;
    border-color: #a5b4fc;
}

/* -----------------------------------------------------------------------
 * Thead filter row (dropdowns aligned per column)
 * ----------------------------------------------------------------------- */

.ims-matrix-filter-row {
    background: #f3f4f6;
}

.ims-matrix-filter-cell {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid #e5e7eb;
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
}

.ims-matrix-filter-cell--empty {
    padding: 0.5rem;
}

.ims-matrix-filter-select {
    width: 100%;
    min-width: 5rem;
    padding: 0.4rem 0.55rem;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #fff;
    font-size: 0.85rem;
    color: #111827;
    line-height: 1.2;
}

.ims-matrix-filter-select:focus {
    outline: 2px solid #6366f1;
    outline-offset: 1px;
    border-color: #6366f1;
}

.ims-matrix-filter-select option[disabled] {
    color: #d1d5db;
}

.ims-matrix-filter-static-value {
    display: inline-block;
    font-size: 0.8rem;
    color: #6b7280;
    font-style: italic;
}

/* Rows hidden by the filter. Using display:none instead of visibility
 * so their height collapses — the table reflows as if the rows were
 * removed. */
.ims-matrix-row.is-filtered-out {
    display: none;
}

/* -----------------------------------------------------------------------
 * Table
 * ----------------------------------------------------------------------- */

.ims-matrix-table-wrap {
    width: 100%;
    overflow-x: auto;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

.ims-matrix-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.ims-matrix-table thead {
    background: #f9fafb;
    border-bottom: 1px solid #e5e7eb;
}

.ims-matrix-th {
    text-align: left;
    font-weight: 600;
    color: #374151;
    padding: 0.55rem 0.75rem;
    white-space: nowrap;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid #e5e7eb;
}

.ims-matrix-unit {
    font-weight: 400;
    color: #9ca3af;
    margin-left: 0.25rem;
    text-transform: none;
    letter-spacing: 0;
}

/* Sortable column header.
 *
 * The <button> is transparent and inherits typography from the <th> so it
 * reads as a plain column label. It's inline-flex so the label + indicator
 * stay on one line; the th's `text-align` controls which side of the cell
 * the whole button sits on (right-aligned for O.D., etc.). */
.ims-matrix-sort-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0;
    margin: 0;
    background: transparent;
    border: 0;
    font: inherit;
    color: inherit;
    text-transform: inherit;
    letter-spacing: inherit;
    cursor: pointer;
    line-height: 1.1;
}

.ims-matrix-sort-btn:hover .ims-matrix-sort-label {
    color: #111827;
}

.ims-matrix-sort-btn:focus-visible {
    outline: 2px solid #6366f1;
    outline-offset: 2px;
    border-radius: 3px;
}

.ims-matrix-sort-indicator {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    opacity: 0.45;
    transition: opacity 120ms ease;
}

.ims-matrix-sort-btn:hover .ims-matrix-sort-indicator {
    opacity: 0.8;
}

.ims-matrix-sort-icon {
    display: block;
}

/* Default both arrows dimmed; active direction gets darkened via state
 * classes below. `currentColor` + per-path opacity lets us keep one SVG. */
.ims-matrix-sort-icon-up,
.ims-matrix-sort-icon-down {
    opacity: 0.45;
}

.ims-matrix-th--sortable.is-sorted-asc .ims-matrix-sort-indicator,
.ims-matrix-th--sortable.is-sorted-desc .ims-matrix-sort-indicator {
    opacity: 1;
}

.ims-matrix-th--sortable.is-sorted-asc .ims-matrix-sort-icon-up {
    opacity: 1;
    color: #4f46e5;
}

.ims-matrix-th--sortable.is-sorted-desc .ims-matrix-sort-icon-down {
    opacity: 1;
    color: #4f46e5;
}

.ims-matrix-td {
    padding: 0.4rem 0.75rem;
    border-bottom: 1px solid #f3f4f6;
    color: #111827;
    vertical-align: middle;
    white-space: nowrap;
    font-size: 0.85rem;
    line-height: 1.3;
}

.ims-matrix-row:last-child .ims-matrix-td {
    border-bottom: 0;
}

.ims-matrix-row:hover {
    background: #fafafa;
}

/* Highlight the row currently shown in the quick-info modal. Mirrors
 * the card highlight in product-listing-grid/style.css so the user sees
 * which row they're previewing as they arrow-key through the table. */
.ims-matrix-row.qv-active,
.ims-matrix-row.qv-active:hover {
    background: var(--color-gold-light, #fff4d6);
    box-shadow: inset 3px 0 0 var(--color-cta, #FAB000);
}

.ims-matrix-align-left   { text-align: left; }
.ims-matrix-align-right  { text-align: right; }
.ims-matrix-align-center { text-align: center; }

.ims-matrix-td--sku {
    font-size: 0.85rem;
    color: #374151;
}

/* Site-wide part-number badge, compacted for the table context. Keeps
 * the gold pill + shield icon + "Item #" label so it reads as the same
 * component used in cart/quote drawers and checkout — just sized down
 * to fit the tighter row height. */
/* Matrix table sku link inherits sizing from the canonical
   .ims-part-number-badge (mini cart size) — only link-specific styles here. */
.ims-matrix-sku-link.ims-part-number-badge {
    text-decoration: none;
    transition: filter 120ms ease;
}

.ims-matrix-sku-link.ims-part-number-badge:hover {
    filter: brightness(0.96);
}

.ims-matrix-td--price {
    font-weight: 600;
    color: #111827;
}

.ims-matrix-empty-val {
    color: #cbd5e1;
}

/* Actions cell — single-line compact control strip. Buttons reuse the
 * site-wide .ims-add-to-cart / .ims-add-to-quote classes so the global
 * click handlers bind without extra wiring; the overrides below scope
 * ONLY to the matrix context via `.ims-matrix-atc`. */

.ims-matrix-td--actions {
    white-space: nowrap;
    padding: 0.3rem 0.6rem;
    text-align: right;
}

.ims-matrix-atc {
    display: inline-flex;
    gap: 0.35rem;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: nowrap;
    margin: 0;
}

/* Compact quantity selector — reuses .ims-quantity-wrapper visuals
 * (rounded 1px border, dividers between cells) from product-listing.css
 * but shrinks the touch targets. */
.ims-matrix-atc .ims-quantity-wrapper {
    display: inline-flex;
    align-items: center;
    border: 1px solid var(--color-border, #d1d5db);
    border-radius: 4px;
    overflow: hidden;
    background: #fff;
    height: 1.75rem;
}

.ims-matrix-atc .ims-quantity-btn {
    width: 1.5rem;
    height: 1.75rem;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #f3f4f6;
    border: 0;
    cursor: pointer;
    color: #111827;
    line-height: 1;
}
.ims-matrix-atc .ims-quantity-btn:hover { background: #e5e7eb; }
.ims-matrix-atc .ims-quantity-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.ims-matrix-atc .ims-quantity-input {
    width: 2rem;
    height: 1.75rem;
    padding: 0;
    border: 0;
    border-left: 1px solid var(--color-border, #d1d5db);
    border-right: 1px solid var(--color-border, #d1d5db);
    border-radius: 0;
    text-align: center;
    font-size: 0.8rem;
    font-weight: 600;
    color: #111827;
    background: #fff;
    -moz-appearance: textfield;
}
.ims-matrix-atc .ims-quantity-input::-webkit-outer-spin-button,
.ims-matrix-atc .ims-quantity-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* Cart + Quote buttons — override the 180px-wide, 0.625rem/1.5rem padding
 * default from product-listing.css. Keep the same colours/border so they
 * read as the same buttons, just compact. */

.ims-matrix-atc .ims-add-to-cart,
.ims-matrix-atc .ims-add-to-quote {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    min-width: 0;
    width: auto;
    padding: 0 0.6rem;
    height: 1.75rem;
    font-size: 0.7rem;
    font-weight: 600;
    line-height: 1;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

.ims-matrix-btn-icon {
    display: block;
    flex: 0 0 auto;
}

.ims-matrix-btn-label {
    display: inline-block;
}

/* -----------------------------------------------------------------------
 * Empty / preview
 * ----------------------------------------------------------------------- */

.ims-matrix-empty {
    padding: 2rem;
    text-align: center;
    color: #6b7280;
    border: 1px dashed #e5e7eb;
    border-radius: 10px;
    background: #fafafa;
}

.ims-matrix-preview-note {
    margin: 0;
    font-size: 0.8rem;
    color: #6b7280;
    font-style: italic;
}

.ims-matrix-detail--preview {
    outline: 1px dashed #c7d2fe;
    outline-offset: 4px;
}

/* -----------------------------------------------------------------------
 * Responsive
 *
 * Below the breakpoint, the hero stacks and the table keeps its
 * horizontal scroll (.ims-matrix-table-wrap handles overflow). On very
 * narrow screens the action column's ATC row reflows under the qty
 * controls so buttons don't get clipped.
 * ----------------------------------------------------------------------- */

@media (max-width: 768px) {
    .ims-matrix-hero {
        grid-template-columns: 1fr;
        gap: 1.25rem;
    }

    .ims-matrix-hero-media {
        justify-content: flex-start;
    }

    .ims-matrix-hero-img {
        max-width: 180px;
    }

    .ims-matrix-hero-title {
        font-size: 1.5rem;
    }

    .ims-matrix-th,
    .ims-matrix-td {
        padding: 0.7rem 0.75rem;
    }
}

@media (max-width: 520px) {
    /* Hide the button text on tiny screens; the icon + aria-label still
     * convey the action. */
    .ims-matrix-btn-label {
        display: none;
    }

    .ims-matrix-atc .ims-add-to-cart,
    .ims-matrix-atc .ims-add-to-quote {
        padding: 0 0.45rem;
    }

    .ims-matrix-filter-select {
        font-size: 0.8rem;
        padding: 0.35rem 0.5rem;
    }
}

/* =============================================================
 * Per-product NetSuite Minimum Order Quantity inline note.
 * Sits in the same actions cell as the matrix row's qty stepper,
 * directly below .ims-matrix-atc (which is inline-flex / nowrap
 * and would clip the note if nested inside it). Each row resolves
 * the message off its own product id so siblings render
 * independently — empty cells contribute no extra height.
 * ============================================================= */
.ims-matrix-td--actions .ims-matrix-min-note {
    display: block;
    margin-top: 4px;
    font-size: 0.7rem;
    line-height: 1.3;
    color: #6b7280;
    text-align: right;
}
