/**
 * H2W Catalog System - Frontend Styles
 *
 * Catalog components on the light page body: series and product cards, the
 * Series product table, the product spec panel, gallery and downloads.
 *
 * The page frame (dark title band, breadcrumb, sections, long-form copy) is
 * styled by the theme in assets/css/site.css. Brand tokens come from the
 * theme's brand.css; the hex after each comma is the fallback used only when
 * the plugin runs without that theme.
 *
 * Block style.css files in blocks/ are intentionally empty; everything the
 * catalog renders on the front end is styled here.
 *
 * @package H2W_Catalog
 */

/* ==========================================================================
   Tokens
   ========================================================================== */

:root {
    --pm-ink: var(--h2w-ink, #1a2233);
    --pm-ink-muted: var(--h2w-ink-muted, #5a6475);
    --pm-ink-faint: #8a93a3;
    --pm-line: var(--h2w-line-light, #d5dbe5);
    --pm-line-soft: #e6eaf0;
    --pm-paper: var(--h2w-paper, #f3f5f8);
    --pm-head: #f6f8fb;
    --pm-hover: #f1f5fc;
    --pm-card: #fff;
    --pm-blue: var(--h2w-blue, #0032a0);
    --pm-blue-hover: var(--h2w-blue-hover, #0a3fb8);
    --pm-display: var(--h2w-font-display, Saira, sans-serif);
    --pm-body: var(--h2w-font-body, "IBM Plex Sans", sans-serif);
    --pm-mono: var(--h2w-font-mono, "IBM Plex Mono", ui-monospace, monospace);
    --pm-radius: 6px;
}

.screen-reader-text {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Dashicons are not loaded for visitors; the cards carry text labels instead */
.wp-block-h2w-catalog-term .dashicons,
.wp-block-h2w-product-pdf .dashicons,
.wp-block-h2w-product-technical-drawing .dashicons {
    display: none;
}

/* ==========================================================================
   Spec values

   Values are data: mono with tabular figures so digits line up down a column.
   The alternate unit sits under the primary one in tables, beside it in the
   spec panel, and is quieter so the eye can follow one unit system.
   ========================================================================== */

.spec-v,
.spec-alt {
    font-family: var(--pm-mono);
    font-variant-numeric: tabular-nums;
}

.spec-v {
    color: var(--pm-ink);
}

.spec-alt {
    color: var(--pm-ink-muted);
}

.spec-empty {
    color: var(--pm-ink-faint);
}

/* ==========================================================================
   Series cards (Family pages)
   ========================================================================== */

.series-cards-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1.25rem;
}

.series-card {
    margin: 0;
    background: var(--pm-card);
    border: 1px solid var(--pm-line);
    border-radius: var(--pm-radius);
    overflow: hidden;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.series-card:hover,
.series-card:focus-within {
    border-color: var(--pm-blue);
    box-shadow: 0 4px 16px rgba(26, 34, 51, 0.08);
}

.series-card-link {
    display: flex;
    flex-direction: column;
    height: 100%;
    color: inherit;
    text-decoration: none;
}

.series-card-image {
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 4 / 3;
    padding: 1.25rem;
    background: #fff;
    border-bottom: 1px solid var(--pm-line-soft);
}

.series-card-image img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    transition: transform 0.25s ease;
}

.series-card:hover .series-card-image img {
    transform: scale(1.03);
}

.series-card-image.placeholder {
    background:
        repeating-linear-gradient(135deg, transparent 0 10px, rgba(26, 34, 51, 0.035) 10px 11px),
        var(--pm-head);
}

.series-card-content {
    display: flex;
    flex: 1;
    flex-direction: column;
    padding: 1.25rem 1.25rem 1.125rem;
}

.series-card-title {
    margin: 0;
    color: var(--pm-ink);
    font-family: var(--pm-display);
    font-size: 1.1875rem;
    font-weight: 600;
    line-height: 1.25;
}

.series-card:hover .series-card-title {
    color: var(--pm-blue);
}

.series-card-description {
    display: -webkit-box;
    margin-top: 0.5rem;
    overflow: hidden;
    color: var(--pm-ink-muted);
    font-size: 0.9375rem;
    line-height: 1.55;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
}

.series-card-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: auto;
    padding-top: 1rem;
}

.series-card .product-count {
    color: var(--pm-ink-muted);
    font-family: var(--pm-mono);
    font-size: 0.8125rem;
    font-variant-numeric: tabular-nums;
}

.series-card-arrow {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
}

.series-card-meta::after {
    content: "\2192";
    color: var(--pm-blue);
    font-size: 1.125rem;
    line-height: 1;
    transition: transform 0.15s ease;
}

.series-card:hover .series-card-meta::after {
    transform: translateX(3px);
}

/* ==========================================================================
   Product cards (Families with products but no Series)
   ========================================================================== */

.products-cards-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1.25rem;
}

.product-card {
    margin: 0;
    background: var(--pm-card);
    border: 1px solid var(--pm-line);
    border-radius: var(--pm-radius);
    overflow: hidden;
    transition: border-color 0.15s ease;
}

.product-card:hover,
.product-card:focus-within {
    border-color: var(--pm-blue);
}

.product-card-link {
    display: block;
    color: inherit;
    text-decoration: none;
}

.product-card-image {
    aspect-ratio: 1;
    padding: 1rem;
    background: #fff;
    border-bottom: 1px solid var(--pm-line-soft);
}

.product-card-image img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.product-card-image.placeholder {
    background: var(--pm-head);
}

.product-card-title {
    margin: 0;
    padding: 0.875rem 1rem;
    color: var(--pm-ink);
    font-family: var(--pm-mono);
    font-size: 0.9375rem;
    font-weight: 500;
}

.product-card:hover .product-card-title {
    color: var(--pm-blue);
}

/* ==========================================================================
   Series product table
   ========================================================================== */

.wp-block-h2w-series-datatable {
    background: var(--pm-card);
    border: 1px solid var(--pm-line);
    border-radius: var(--pm-radius);
    overflow: hidden;
}

.datatable-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--pm-line);
}

.datatable-controls-left {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem 1rem;
}

.datatable-controls-left {
    flex: 1 1 auto;
}

.datatable-search {
    flex: 0 1 360px;
}

.datatable-search-input {
    box-sizing: border-box;
    width: 100%;
    min-height: 40px;
    padding: 0.5rem 0.75rem 0.5rem 2.25rem;
    background:
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='%235a6475' stroke-width='1.6'%3E%3Ccircle cx='8.5' cy='8.5' r='5.5'/%3E%3Cpath d='M13 13l4 4' stroke-linecap='round'/%3E%3C/svg%3E")
        no-repeat 0.75rem center / 16px,
        #fff;
    border: 1px solid #b9c2d0;
    border-radius: 3px;
    color: var(--pm-ink);
    font-family: var(--pm-body);
    font-size: 0.9375rem;
}

.datatable-search-input:focus-visible {
    outline: 2px solid var(--pm-blue);
    outline-offset: 1px;
    border-color: var(--pm-blue);
}

.datatable-count {
    color: var(--pm-ink-muted);
    font-family: var(--pm-mono);
    font-size: 0.8125rem;
}

/* Wide tables scroll inside their card, never the page */
.datatable-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.h2w-series-table {
    width: 100%;
    margin: 0;
    border-collapse: separate;
    border-spacing: 0;
    color: var(--pm-ink);
    font-family: var(--pm-body);
    font-size: 0.875rem;
    line-height: 1.4;
}

.h2w-series-table thead th {
    position: relative;
    padding: 0.75rem 1rem;
    background: var(--pm-head);
    border-bottom: 1px solid var(--pm-line);
    color: var(--pm-ink-muted);
    font-family: var(--pm-mono);
    font-size: 0.6875rem;
    font-weight: 500;
    letter-spacing: 0.06em;
    line-height: 1.35;
    text-align: left;
    text-transform: uppercase;
    vertical-align: bottom;
    min-width: 7.5rem;
    max-width: 12rem;
}

.h2w-series-table tbody td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--pm-line-soft);
    vertical-align: middle;
    white-space: nowrap;
}

.h2w-series-table tbody tr:last-child td {
    border-bottom: 0;
}

.h2w-series-table tbody tr {
    background: #fff;
}

.h2w-series-table tbody tr:hover td {
    background: var(--pm-hover);
}

/* Numbers align on the right so magnitudes compare at a glance */
.h2w-series-table .numeric-cell {
    text-align: right;
}

.h2w-series-table .spec-v,
.h2w-series-table .spec-alt {
    display: block;
}

.h2w-series-table .spec-alt {
    margin-top: 0.125rem;
    font-size: 0.75rem;
}

.h2w-series-table td:not(.numeric-cell) .spec-v {
    font-family: var(--pm-body);
}

/* Thumbnail and part number stay put while the specs scroll sideways */
.h2w-series-table .thumbnail-cell {
    position: sticky;
    left: 0;
    z-index: 1;
    width: 48px;
    min-width: 0;
    padding-right: 0.25rem;
}

.h2w-series-table .product-number {
    position: sticky;
    left: 68px; /* thumbnail column: 48px image + 1rem + 0.25rem padding */
    z-index: 1;
    min-width: 0;
    box-shadow: inset -1px 0 0 var(--pm-line-soft);
}

.h2w-series-table tbody .thumbnail-cell,
.h2w-series-table tbody .product-number {
    background: inherit;
}

.h2w-series-table thead .thumbnail-cell,
.h2w-series-table thead .product-number {
    z-index: 2;
}

.h2w-series-table td.product-number a {
    color: var(--pm-blue);
    font-family: var(--pm-mono);
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    text-decoration: none;
}

.h2w-series-table td.product-number a:hover,
.h2w-series-table td.product-number a:focus-visible {
    text-decoration: underline;
    text-underline-offset: 0.2em;
}

.product-thumbnail-link {
    display: block;
    width: 48px;
    height: 48px;
}

.product-thumbnail-img {
    display: block;
    width: 48px;
    height: 48px;
    object-fit: contain;
    background: #fff;
    border: 1px solid var(--pm-line-soft);
    border-radius: 3px;
}

.h2w-series-table .no-products {
    padding: 2.5rem 1rem;
    color: var(--pm-ink-muted);
    text-align: center;
    white-space: normal;
}

/* Sort affordance (DataTables adds the sorting classes; its CSS is not loaded) */
.h2w-series-table thead th.sorting,
.h2w-series-table thead th.sorting_asc,
.h2w-series-table thead th.sorting_desc {
    padding-right: 1.5rem;
    cursor: pointer;
    user-select: none;
}

.h2w-series-table thead th.sorting::after,
.h2w-series-table thead th.sorting_asc::after,
.h2w-series-table thead th.sorting_desc::after {
    position: absolute;
    right: 0.5rem;
    bottom: 0.8rem;
    font-size: 0.6875rem;
    line-height: 1;
}

.h2w-series-table thead th.sorting::after {
    content: "\2195";
    opacity: 0.35;
}

.h2w-series-table thead th.sorting_asc::after {
    content: "\2191";
    color: var(--pm-blue);
}

.h2w-series-table thead th.sorting_desc::after {
    content: "\2193";
    color: var(--pm-blue);
}

.h2w-series-table thead th.sorting:hover,
.h2w-series-table thead th.sorting_asc,
.h2w-series-table thead th.sorting_desc {
    color: var(--pm-ink);
}

.h2w-series-table thead th:focus-visible {
    outline: 2px solid var(--pm-blue);
    outline-offset: -2px;
}

.datatable-error {
    padding: 1.5rem;
    color: var(--pm-ink-muted);
}

/* ==========================================================================
   Product page
   ========================================================================== */

.h2w-product__layout {
    display: grid;
    grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
    gap: clamp(1.5rem, 3vw, 2.5rem);
    align-items: start;
}

.h2w-product__layout > * {
    margin: 0;
}

.h2w-product__main,
.h2w-product__specs {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.h2w-product__main > *,
.h2w-product__specs > * {
    margin: 0;
}

.h2w-product__downloads {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr));
    gap: 1.25rem;
}

.h2w-product__downloads:empty {
    display: none;
}

/* Gallery */

.product-gallery-container {
    padding: 1rem;
    background: var(--pm-card);
    border: 1px solid var(--pm-line);
    border-radius: var(--pm-radius);
}

.gallery-main-image {
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 4 / 3;
    background: #fff;
}

.gallery-main-image img,
.gallery-main-image .main-image {
    display: block;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.gallery-thumbnails {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--pm-line-soft);
}

.gallery-thumbnails:empty {
    display: none;
}

.thumbnail-item {
    width: 64px;
    height: 64px;
    padding: 0.25rem;
    background: #fff;
    border: 1px solid var(--pm-line);
    border-radius: 3px;
    cursor: pointer;
    transition: border-color 0.15s ease;
}

.thumbnail-item img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.thumbnail-item:hover,
.thumbnail-item:focus-visible {
    border-color: var(--pm-ink-muted);
}

.thumbnail-item.selected {
    border-color: var(--pm-blue);
    box-shadow: 0 0 0 1px var(--pm-blue);
}

/* Overview */

.product-overview-container {
    padding: clamp(1.25rem, 3vw, 1.75rem);
    background: var(--pm-card);
    border: 1px solid var(--pm-line);
    border-radius: var(--pm-radius);
}

.product-overview-title {
    margin: 0 0 0.75rem;
    color: var(--pm-ink);
    font-family: var(--pm-display);
    font-size: 1.375rem;
    font-weight: 700;
}

.product-overview-content {
    color: var(--pm-ink);
    font-size: 1rem;
    line-height: 1.7;
}

.product-overview-content > * {
    margin-block: 0;
}

.product-overview-content > * + * {
    margin-top: 0.9em;
}

.product-overview-content a {
    color: var(--pm-blue);
    text-underline-offset: 0.18em;
}

/* Downloads */

.product-pdf-card,
.product-drawing-card {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    height: 100%;
    padding: 1.25rem;
    box-sizing: border-box;
    background: var(--pm-card);
    border: 1px solid var(--pm-line);
    border-radius: var(--pm-radius);
}

.pdf-content > *,
.drawing-content > * {
    margin: 0;
}

.pdf-title,
.drawing-title {
    color: var(--pm-ink);
    font-family: var(--pm-display);
    font-size: 1.0625rem;
    font-weight: 600;
}

.pdf-description,
.drawing-description {
    margin-top: 0.25rem !important;
    color: var(--pm-ink-muted);
    font-size: 0.875rem;
}

.pdf-download-button,
.drawing-download-button {
    align-self: flex-start;
    margin-top: 0.875rem;
    padding: 0.5rem 0.875rem;
    border: 1px solid var(--pm-blue);
    border-radius: 3px;
    color: var(--pm-blue);
    font-family: var(--pm-display);
    font-size: 0.875rem;
    font-weight: 600;
    text-decoration: none;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.pdf-download-button:hover,
.pdf-download-button:focus-visible,
.drawing-download-button:hover,
.drawing-download-button:focus-visible {
    background: var(--pm-blue);
    color: #fff;
}

/* ==========================================================================
   Spec panel (product page)
   ========================================================================== */

.h2w-product-specifications {
    margin: 0;
}

.product-specs-container {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.spec-group {
    background: var(--pm-card);
    border: 1px solid var(--pm-line);
    border-radius: var(--pm-radius);
    overflow: hidden;
}

.spec-group-title {
    margin: 0;
    padding: 0.875rem 1.25rem;
    background: var(--pm-head);
    border-bottom: 1px solid var(--pm-line);
    color: var(--pm-ink);
    font-family: var(--pm-mono);
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.spec-table {
    width: 100%;
    margin: 0;
    border-collapse: collapse;
    font-size: 0.875rem;
    line-height: 1.45;
}

.spec-row + .spec-row > * {
    border-top: 1px solid var(--pm-line-soft);
}

.spec-label,
.spec-value {
    padding: 0.625rem 1.25rem;
    vertical-align: top;
}

.spec-label {
    width: 48%;
    color: var(--pm-ink-muted);
    font-weight: 400;
    text-align: left;
}

.spec-value {
    color: var(--pm-ink);
    overflow-wrap: anywhere;
}

/* In the panel the alternate unit sits on the same line, quieter */
.spec-value .spec-alt {
    margin-left: 0.625rem;
    font-size: 0.8125rem;
}

.spec-row:hover > * {
    background: var(--pm-hover);
}

.specs-preview-message,
.specs-preview-note {
    padding: 1rem;
    background: var(--pm-head);
    border: 1px solid var(--pm-line);
    border-radius: var(--pm-radius);
    color: var(--pm-ink-muted);
    text-align: center;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 1024px) {
    .series-cards-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .products-cards-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .h2w-product__layout {
        grid-template-columns: minmax(0, 1fr);
    }
}

@media (max-width: 768px) {
    .hide-on-mobile {
        display: none;
    }

    .h2w-series-table .thumbnail-cell {
        display: none;
    }

    .h2w-series-table .product-number {
        left: 0;
    }

    .datatable-search {
        flex-basis: 100%;
    }

    .datatable-controls-left {
        width: 100%;
    }
}

@media (max-width: 600px) {
    .series-cards-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .products-cards-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .spec-label,
    .spec-value {
        padding-inline: 1rem;
    }
}

/* ==========================================================================
   Print: a clean spec sheet
   ========================================================================== */

@media print {
    .datatable-controls,
    .gallery-thumbnails,
    .pdf-download-button,
    .drawing-download-button {
        display: none;
    }

    .series-card,
    .spec-group,
    .wp-block-h2w-series-datatable {
        break-inside: avoid;
        border-color: #999;
    }

    .h2w-series-table .thumbnail-cell,
    .h2w-series-table .product-number {
        position: static;
    }
}

/* ==========================================================================
   Empty catalog state
   ========================================================================== */

.catalog-empty {
    max-width: 60ch;
    padding: clamp(1.5rem, 4vw, 2.25rem);
    background: var(--pm-card);
    border: 1px solid var(--pm-line);
    border-radius: var(--pm-radius);
}

.catalog-empty > * {
    margin: 0;
}

.catalog-empty h2 {
    color: var(--pm-ink);
    font-family: var(--pm-display);
    font-size: 1.375rem;
}

.catalog-empty p {
    margin-top: 0.75rem;
    color: var(--pm-ink-muted);
    line-height: 1.6;
}

.catalog-empty .h2w-btn {
    margin-top: 1.25rem;
}
