/**
 * Product cards — image, name, brand, stock, price, «Legg til» / stepper (SPEC §4–5.2,
 * «Pris og antall på produktkort»). The card never gets wider than its column.
 * Markup: dryhire_product_card_html() in inc/home-sections.php. Tokens only.
 */
.dh-cards--grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: var(--dh-gap);
}

.dh-cards--rail {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(200px, 1fr);
    gap: var(--dh-gap);
    overflow-x: auto;
    padding-bottom: 4px;
    scroll-snap-type: x proximity;
    scrollbar-width: thin;
}

.dh-cards--rail .dh-pcard {
    scroll-snap-align: start;
}

.dh-pcard {
    display: grid;
    grid-template-rows: auto 1fr auto; /* image / info / foot: the foot lines up across a row */
    min-width: 0;
    padding: 8px;
    background: var(--dh-card);
    border: 1px solid var(--dh-border);
    border-radius: var(--dh-radius-2xl);
    box-shadow: var(--dh-shadow-card);
    color: var(--dh-card-foreground);
    transition: opacity var(--dh-ease);
}

.dh-pcard.is-updating {
    opacity: 0.7;
}

.dh-pcard__link {
    display: grid;
    grid-row: 1 / 3;
    grid-template-rows: subgrid;
    min-width: 0;
    color: inherit;
    text-decoration: none;
    border-radius: var(--dh-radius-xl);
}

.dh-pcard__link:focus-visible,
.dh-qty button:focus-visible {
    outline: 3px solid color-mix(in oklch, var(--dh-ring) 50%, transparent);
    outline-offset: 1px;
}

.dh-pcard__img {
    display: grid;
    grid-template: minmax(0, 1fr) / minmax(0, 1fr); /* img height: 100% needs a definite cell, not an auto row */
    place-items: center;
    aspect-ratio: 4 / 3;
    overflow: hidden;
    padding: 9%;
    box-sizing: border-box;
    border-radius: var(--dh-radius-md);
    background: var(--dh-photo);
    box-shadow: inset 0 0 0 1px var(--dh-border); /* edge of the white area, also in dark mode */
}

.dh-pcard__img img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.dh-pcard__info {
    display: grid;
    align-content: start;
    min-width: 0;
    gap: 2px;
    padding: 12px 10px 4px;
}

/* Name always takes two lines and brand one (also when empty), so the stock chip lines up across cards */
.dh-pcard__name {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
    min-height: calc(2em * 1.35);
    font-size: 15px;
    font-weight: 500;
    line-height: 1.35;
}

.dh-pcard__link:hover .dh-pcard__name {
    text-decoration: underline;
    text-underline-offset: 3px;
}

.dh-pcard__brand {
    min-height: calc(1em * 1.4);
    overflow: hidden;
    font-size: 13px;
    line-height: 1.4;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: var(--dh-muted-foreground);
}

/* Stock on cards (SPEC §4 «Lagerstatus på produktkort»): 8 px dot + 13 px text, no chip.
   Plenty: brighter green dot, text in foreground. Few/none: dot and text in the status colour. */
.dh-stock {
    --dh-stock: var(--dh-status-ok-dot);
    justify-self: start;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin-top: 6px;
    color: var(--dh-foreground);
    font-size: 13px;
    line-height: 1.3;
    font-variant-numeric: tabular-nums;
}

.dh-stock:empty {
    display: none;
}

.dh-stock::before {
    content: "";
    flex: none;
    width: 8px;
    height: 8px;
    border-radius: var(--dh-radius-full);
    background: var(--dh-stock);
}

.dh-stock[data-state="warn"] { --dh-stock: var(--dh-status-warn); color: var(--dh-stock); }
.dh-stock[data-state="bad"] { --dh-stock: var(--dh-status-bad); color: var(--dh-stock); }

.dh-pcard__foot {
    display: grid;
    gap: 8px;
    min-width: 0;
    padding: 4px 4px 4px;
}

/* Price alone on its line: number 16/600, «/ dag» small and muted next to it */
.dh-pcard__price {
    min-width: 0;
    overflow: hidden;
    padding-left: 6px;
    font-size: 16px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.dh-pcard__price small {
    font-size: 12.5px;
    font-weight: 400;
    color: var(--dh-muted-foreground);
}

/* «Legg til» (outlined pill, full width) and the stepper share one fixed-height slot */
.dh-qty {
    --dh-qty-h: 36px;
    display: grid;
    min-width: 0;
    height: var(--dh-qty-h);
}

.dh-qty [hidden] {
    display: none !important;
}

.dh-qty .dh-i {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.5;
    stroke-linecap: round;
}

.dh-qty__add {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    height: var(--dh-qty-h);
    padding: 0 12px;
    border: 0;
    border-radius: var(--dh-radius-pill);
    background: var(--dh-card);
    box-shadow: inset 0 0 0 1px var(--dh-border);
    color: var(--dh-foreground);
    font: 500 14px/1 var(--dh-font-sans);
    white-space: nowrap;
    cursor: pointer;
    transition: background-color var(--dh-ease);
}

.dh-qty__add:hover:not(:disabled) {
    background: var(--dh-accent);
}

.dh-qty__add:disabled {
    background: var(--dh-secondary);
    box-shadow: none;
    color: var(--dh-muted-foreground);
    cursor: default;
}

.dh-qty__stepper {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    min-width: 0;
    height: var(--dh-qty-h);
    border-radius: var(--dh-radius-pill);
    background: var(--dh-secondary);
}

.dh-qty__stepper button {
    display: grid;
    place-items: center;
    flex: none;
    width: var(--dh-qty-h);
    height: var(--dh-qty-h);
    padding: 0;
    border: 0;
    border-radius: var(--dh-radius-full);
    background: none;
    color: var(--dh-foreground);
    font: 500 17px/1 var(--dh-font-sans);
    cursor: pointer;
    transition: background-color var(--dh-ease);
}

.dh-qty__stepper button:hover:not(:disabled) {
    background: var(--dh-accent);
}

.dh-qty__stepper button:disabled {
    opacity: 0.35;
    cursor: default;
}

.dh-qty__stepper output {
    min-width: 20px;
    font-size: 14px;
    font-weight: 500;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

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

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

    .dh-pcard__info {
        padding: 10px 6px 2px;
    }

    .dh-pcard__price {
        padding-left: 2px;
    }
}

@media (max-width: 600px) {
    /* Same spacing as the category cards on the front page */
    .dh-cards--grid,
    .dh-cards--rail {
        gap: 8px;
    }

    .dh-pcard {
        padding: 6px;
    }

    .dh-pcard__foot {
        padding: 2px;
    }

    .dh-qty {
        --dh-qty-h: 32px;
    }

    .dh-qty__add {
        font-size: 13px;
    }
}
