/* Oreem Block Checkout Field Editor — frontend layout helpers */

/* ----- Block checkout: half-width for custom additional fields -----
   Block checkout's address form is a 2-column CSS grid where each child
   grid item defaults to grid-column: 1 / -1 (full row). To make a field
   half-width, we override its grid-column to "span 1".

   Custom fields carry the attribute data-oreem-half="1" on their input/
   textarea/select element. The wrapper element varies by field type, but
   it is always a direct child of a grid container. We use :has() to find
   the wrapper and override its grid-column. */

.wc-block-components-address-form > *:has(input[data-oreem-half="1"]),
.wc-block-components-address-form > *:has(textarea[data-oreem-half="1"]),
.wc-block-components-address-form > *:has(select[data-oreem-half="1"]),
.wc-block-checkout fieldset > *:has(input[data-oreem-half="1"]),
.wc-block-checkout fieldset > *:has(textarea[data-oreem-half="1"]),
.wc-block-checkout fieldset > *:has(select[data-oreem-half="1"]) {
    grid-column: span 1 !important;
}

/* For non-grid containers (e.g. contact / order sections that may use
   flex or block layout in some themes), force flex/inline-block layout. */
.wc-block-components-form .wc-block-components-text-input:has(input[data-oreem-half="1"]),
.wc-block-components-form .wc-block-components-text-input:has(textarea[data-oreem-half="1"]),
.wc-block-components-form .wc-block-components-select:has(select[data-oreem-half="1"]) {
    display: inline-block !important;
    width: calc(50% - 8px) !important;
    vertical-align: top !important;
}

/* Mobile: stack everything single-column */
@media (max-width: 600px) {
    .wc-block-components-address-form > *:has(input[data-oreem-half="1"]),
    .wc-block-components-address-form > *:has(textarea[data-oreem-half="1"]),
    .wc-block-components-address-form > *:has(select[data-oreem-half="1"]),
    .wc-block-checkout fieldset > *:has(input[data-oreem-half="1"]),
    .wc-block-checkout fieldset > *:has(textarea[data-oreem-half="1"]),
    .wc-block-checkout fieldset > *:has(select[data-oreem-half="1"]) {
        grid-column: 1 / -1 !important;
    }
    .wc-block-components-form .wc-block-components-text-input:has(input[data-oreem-half="1"]),
    .wc-block-components-form .wc-block-components-text-input:has(textarea[data-oreem-half="1"]),
    .wc-block-components-form .wc-block-components-select:has(select[data-oreem-half="1"]) {
        display: block !important;
        width: 100% !important;
    }
}

/* ----- Classic checkout: half-width via .oreem-bcfe-half class on form-row ----- */
.oreem-bcfe-active .form-row.oreem-bcfe-half {
    width: calc(50% - 8px);
    display: inline-block;
    margin-right: 8px;
    float: none;
    vertical-align: top;
}
.oreem-bcfe-active .form-row.oreem-bcfe-half + .form-row.oreem-bcfe-half {
    margin-right: 0;
}
@media (max-width: 600px) {
    .oreem-bcfe-active .form-row.oreem-bcfe-half {
        width: 100%;
        display: block;
        margin-right: 0;
    }
}
