/* ==========================================================================
   PDP bundle components panel
   Paired with front-end/pdp-bundle-components.php

   LAYOUT MATTERS HERE, and getting it wrong is not cosmetic.

   WC Product Bundles renders the component list three ways and puts the choice
   on the form as `layout_default`, `layout_tabular` or `layout_grid`:

     default  <div class="bundled_product">           10 published labs bundles
     tabular  <table><tr class="bundled_product">     36 published labs bundles
     grid     <ul><li class="bundled_product">        none published

   `.bundled_product` is on all three, so a `display: flex` written for the
   default layout also lands on a <tr>, which the browser resolves by wrapping
   the row in an anonymous cell in column one. The thead then floats right over
   empty space and the table reads as broken. That is the majority of the bundle
   catalogue on both stores, so every rule that touches ROW STRUCTURE is scoped
   to its layout and only the layout-independent rules (panel, heading, stock
   line, dot) are left unscoped. Caught in correctness review before deploy; the
   first cut of this file had the flex rules unscoped.

   The grid layout is deliberately left to WC PB's own CSS inside the panel. It
   is unused on both stores, so styling it would be untested code shipped for a
   case that does not exist. It still gets the panel, heading and stock colours.

   Everything is scoped under body.single-product .bundle_form .ksec-bc, which
   keeps it off the cart and composite renderings of the same classes, and
   out-specifies the older bundle rules that live in the WP Customizer's
   Additional CSS rather than in this repo. Those load after this stylesheet, so
   winning is a specificity question, not an order one.

   Colours are the theme's tokens with literal fallbacks, so the panel still
   renders correctly on a store whose theme does not define them.

   Deliberately additive: nothing here hides an element.
   ========================================================================== */

/* ==========================================================================
   Panel and heading, layout independent
   ========================================================================== */

body.single-product .bundle_form .ksec-bc {
    margin: 0 0 20px;
    padding: 0 16px;
    border: 1px solid #e6e8ec;
    border-left: 3px solid var(--ksec-navy, #0f1419);
    border-radius: 6px;
    background: #f8f9fb;
}

body.single-product .bundle_form .ksec-bc__heading {
    margin: 0;
    padding: 14px 0 12px;
    border-bottom: 1px solid #e6e8ec;
    font-size: 16px;
    font-weight: 700;
    line-height: 1.35;
    color: var(--ksec-navy, #0f1419);
}

/* The thumbnail becomes a lightbox trigger once the JS binds. Applies to every
   layout because the anchor markup is the same in all three. */
body.single-product .bundle_form .ksec-bc .bundled_product_images a.zoom {
    display: block;
    cursor: zoom-in;
}

body.single-product .bundle_form .ksec-bc .bundled_product_images img {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 4px;
}

body.single-product .bundle_form .ksec-bc h4.bundled_product_title {
    margin: 0 0 4px;
    padding: 0;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.35;
    color: #1a1a1a;
}

/* ==========================================================================
   Default layout: each component is a block, laid out as a flex row
   ========================================================================== */

body.single-product .bundle_form.layout_default .ksec-bc .bundled_product {
    display: flex;
    align-items: center;
    gap: 14px;
    margin: 0;
    padding: 12px 0;
    border-bottom: 1px solid #edeff2;
}

body.single-product .bundle_form.layout_default .ksec-bc .bundled_product:last-child {
    border-bottom: 0;
}

/* Fixed image cell so the titles align down the list whatever each thumbnail's
   aspect ratio is. flex-basis rather than width, because the Customizer's
   max-width cap sits on the figure inside. */
body.single-product .bundle_form.layout_default .ksec-bc .bundled_product_images {
    flex: 0 0 64px;
    width: 64px;
    margin: 0;
}

body.single-product .bundle_form.layout_default .ksec-bc .bundled_product_images figure {
    max-width: 64px;
    margin: 0;
}

body.single-product .bundle_form.layout_default .ksec-bc .details {
    flex: 1 1 auto;
    min-width: 0;
}

body.single-product .bundle_form.layout_default .ksec-bc .bundled_item_cart_content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

body.single-product .bundle_form.layout_default .ksec-bc .quantity.quantity_hidden {
    margin: 0;
}

/* ==========================================================================
   Tabular layout: the components are a real table, so style it as one

   The rows keep table display. Separation comes from a border on the <tr>,
   which needs border-collapse on the table to paint.
   ========================================================================== */

body.single-product .bundle_form.layout_tabular .ksec-bc table.bundled_products {
    width: 100%;
    margin: 0;
    border: 0;
    border-collapse: collapse;
    background: transparent;
}

body.single-product .bundle_form.layout_tabular .ksec-bc table.bundled_products thead th {
    padding: 10px 8px 8px 0;
    border: 0;
    border-bottom: 1px solid #e6e8ec;
    background: transparent;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #6b7280;
    text-align: left;
}

body.single-product .bundle_form.layout_tabular .ksec-bc tr.bundled_product {
    border-bottom: 1px solid #edeff2;
    background: transparent;
}

body.single-product .bundle_form.layout_tabular .ksec-bc tbody tr.bundled_product:last-child {
    border-bottom: 0;
}

/* !important is deliberate and is not decoration. The Customizer's Additional
   CSS carries `table.bundled_products td.bundled_item_col { padding: 5px
   !important }`, which no amount of specificity can beat. Matching its weight
   is the only way to give the rows room, and the alternative, editing the
   Customizer, puts the rule somewhere this repo cannot review or roll back. */
body.single-product .bundle_form.layout_tabular .ksec-bc td.bundled_item_col {
    padding: 12px 8px 12px 0 !important;
    border: 0;
    background: transparent;
    vertical-align: middle !important;
}

body.single-product .bundle_form.layout_tabular .ksec-bc td.bundled_item_images_col {
    width: 64px;
}

body.single-product .bundle_form.layout_tabular .ksec-bc td.bundled_item_images_col .bundled_product_images,
body.single-product .bundle_form.layout_tabular .ksec-bc td.bundled_item_images_col figure {
    width: 64px;
    max-width: 64px;
    margin: 0;
}

body.single-product .bundle_form.layout_tabular .ksec-bc td.bundled_item_qty_col {
    width: 1%;
    white-space: nowrap;
    text-align: right;
}

/* ==========================================================================
   Stock line, layout independent

   The dot is injected by the PHP filter. The text carries the state as well as
   the dot, because the request was that the status not read as plain black, and
   because a dot alone is a poor signal at 8px. WooCommerce's own wording states
   the status in words either way, so nothing here is colour-only.
   ========================================================================== */

body.single-product .bundle_form .ksec-bc p.stock,
body.single-product .bundle_form .ksec-bc p.stock.ksec-bc__stock {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    padding: 0;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.4;
    color: #15803d;
}

body.single-product .bundle_form .ksec-bc p.stock .ksec-bc__dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    background: #16a34a;
}

/* Low, matched to the main stock line's amber. */
body.single-product .bundle_form .ksec-bc p.stock.ksec-bc-low {
    color: #b45309;
}
body.single-product .bundle_form .ksec-bc p.stock.ksec-bc-low .ksec-bc__dot {
    background: #ff9900;
}

/* Critical, 1 to 2 left. Same amber as low, deliberately: red is reserved for
   out of stock. A component with 2 left is still buyable, and with backorders on
   the line reads "Only 2 left in stock (More available on order)", where red
   contradicted the words beside it. The band keeps its own class so the
   distinction is still expressible if it is ever wanted back.

   No pulse animation here: the main line pulses because it is the one the buyer
   is deciding on, and five pulsing dots in a parts list is noise. */
body.single-product .bundle_form .ksec-bc p.stock.ksec-bc-critical {
    color: #b45309;
}
body.single-product .bundle_form .ksec-bc p.stock.ksec-bc-critical .ksec-bc__dot {
    background: #ff9900;
}

/* Backorder and out-of-stock are declared last so they win on a line that
   somehow carries both. The PHP now refuses to band a line WC PB did not call
   in-stock, so that should be unreachable; this ordering means a future edit to
   either half cannot produce two state colours on one row. */
body.single-product .bundle_form .ksec-bc p.stock.available-on-backorder {
    color: #1d4ed8;
}
body.single-product .bundle_form .ksec-bc p.stock.available-on-backorder .ksec-bc__dot {
    background: #1d4ed8;
}

/* Out of stock is the only state the shopper cannot buy, so it is the only one
   that earns red. Text is the darker #b91c1c for contrast on the panel. */
body.single-product .bundle_form .ksec-bc p.stock.out-of-stock {
    color: #b91c1c;
}
body.single-product .bundle_form .ksec-bc p.stock.out-of-stock .ksec-bc__dot {
    background: #dc2626;
}

/* Suppress the theme's and WooCommerce's default tick, same reasoning as the
   main stock line: it renders on top of our dot. */
body.single-product .bundle_form .ksec-bc p.stock::before,
body.single-product .bundle_form .ksec-bc p.stock.in-stock::before {
    content: none !important;
    display: none !important;
}

/* ==========================================================================
   Narrow
   ========================================================================== */

@media (max-width: 480px) {
    body.single-product .bundle_form .ksec-bc {
        padding: 0 12px;
    }
    body.single-product .bundle_form.layout_default .ksec-bc .bundled_product {
        gap: 10px;
    }
    body.single-product .bundle_form.layout_default .ksec-bc .bundled_product_images {
        flex: 0 0 52px;
        width: 52px;
    }
    body.single-product .bundle_form.layout_default .ksec-bc .bundled_product_images figure {
        max-width: 52px;
    }
    body.single-product .bundle_form.layout_tabular .ksec-bc td.bundled_item_col {
        padding: 10px 6px 10px 0 !important;
    }
    body.single-product .bundle_form.layout_tabular .ksec-bc td.bundled_item_images_col,
    body.single-product .bundle_form.layout_tabular .ksec-bc td.bundled_item_images_col .bundled_product_images,
    body.single-product .bundle_form.layout_tabular .ksec-bc td.bundled_item_images_col figure {
        width: 52px;
        max-width: 52px;
    }
}
