/**
 * COD form — the shared field + CTA component.
 *
 * Single source of truth for the cash-on-delivery form's look. Two consumers:
 *
 *   inc/woocommerce/checkout/       single-product Quick Checkout  (the master)
 *   inc/woocommerce/checkout-page/  the Checkout COD page
 *
 * Every value here was lifted verbatim out of the product form's sheet, which
 * is the design reference — the checkout page used to carry its own, slightly
 * different, copy of the same idea (taller inputs, borderless icon column,
 * labels above each field) and the two drifted apart visually. Nothing is
 * redesigned here; the rules simply moved so both pages load the same bytes.
 *
 * Selectors are deliberately unscoped: the product form nests these classes
 * under .opsim-modular-checkout-wrapper, the checkout page does not, and the
 * classes appear nowhere else in the theme. This sheet is only ever enqueued
 * on those two pages.
 *
 * Adding a rule here changes BOTH forms. Anything that should apply to only
 * one of them belongs in that module's own sheet.
 */

/* ── Field ────────────────────────────────────────────────────────────
   Icon column + input, one 42px box. The placeholder is the label; there
   is no separate <label> element in this component. */

.opsim-checkout-input-group {
    display: flex;
    align-items: stretch;
    border: 1px solid #e5e7eb;
    border-radius: var(--opsim-radius);
    background: #fff;
    overflow: hidden;
    height: 42px;
    transition: border-color 0.2s;
}

.opsim-checkout-input-group:focus-within {
    border-color: var(--opsim-brand, #531628);
}

.opsim-icon-section {
    width: 42px;
    background: #f9fafb;
    border-right: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.opsim-icon-section svg {
    width: 16px;
    height: 16px;
    stroke: var(--opsim-brand, #531628);
    fill: none;
}

/* !important throughout: WooCommerce's own form styles and several plugins
   set border/background/padding on bare `input`, and this box draws its
   border on the wrapper instead. */
.opsim-checkout-input-group input {
    flex: 1;
    min-width: 0;
    border: none !important;
    background: transparent !important;
    padding: 0 10px !important;
    font-family: inherit;
    /* 16px is not a typographic choice — anything smaller makes iOS Safari
       zoom the viewport when the field takes focus. */
    font-size: 16px !important;
    color: #111827 !important;
    outline: none !important;
    height: 100% !important;
    margin: 0 !important;
}

.opsim-checkout-input-group input::placeholder {
    color: #9ca3af;
}

.opsim-checkout-input-group.has-error {
    border-color: #dc2626 !important;
}

.opsim-field-error-message {
    color: #dc2626;
    font-size: 0.65rem;
    font-weight: 700;
    margin-top: 4px;
    margin-bottom: 6px;
    margin-left: 10px;
    display: block !important;
    text-align: left;
    width: 100%;
}

.opsim-field-error-message:empty {
    display: none !important;
}

/* ── CTA ──────────────────────────────────────────────────────────────
   Colour, border and radius come from the .opsim-btn contract in
   assets/css/base.css, which lists .opsim-confirm-checkout-btn by name.
   Only size, the two-line content block and the loading state live here. */

.opsim-confirm-checkout-btn {
    width: 100%;
    margin-top: 4px;
}

.opsim-confirm-checkout-btn .opsim-btn-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.opsim-confirm-checkout-btn svg {
    width: 22px;
    height: 22px;
    stroke: none;
    fill: currentColor;
    color: #fff;
    flex-shrink: 0;
}

.opsim-confirm-checkout-btn .opsim-btn-text {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
}

.opsim-confirm-checkout-btn .opsim-main-text {
    font-size: 0.9rem;
    font-weight: 800;
    text-transform: uppercase;
    line-height: 1;
}

.opsim-confirm-checkout-btn .opsim-sub-text {
    font-size: 0.7rem;
    opacity: 0.9;
    font-weight: 400;
    margin-top: 1px;
}

/* ── CTA loading state ────────────────────────────────────────────────
   The product form's JS toggles `.loading`, the checkout page's toggles
   `.is-loading`. Both are honoured rather than renaming one and having to
   touch the other module's script. */

.opsim-confirm-checkout-btn.loading,
.opsim-confirm-checkout-btn.is-loading {
    position: relative;
    cursor: not-allowed;
    pointer-events: none;
}

.opsim-confirm-checkout-btn.loading .opsim-btn-content,
.opsim-confirm-checkout-btn.is-loading .opsim-btn-content {
    visibility: hidden;
    opacity: 0;
}

.opsim-confirm-checkout-btn.loading::after,
.opsim-confirm-checkout-btn.is-loading::after {
    content: "";
    position: absolute;
    width: 20px;
    height: 20px;
    top: calc(50% - 10px);
    left: calc(50% - 10px);
    border: 2.5px solid rgba(255, 255, 255, 0.3);
    border-radius: var(--opsim-radius-circle, 50%);
    border-top-color: #fff;
    animation: opsim-spin 0.6s linear infinite;
}

@keyframes opsim-spin {
    to { transform: rotate(360deg); }
}

/* ── Mobile ───────────────────────────────────────────────────────────
   Same proportions the product form has always used on phones. */

@media (max-width: 767px) {
    .opsim-checkout-input-group {
        height: 38px;
    }

    /* !important here only outranks the .opsim-btn contract in base.css,
       which declares size and radius with !important of its own. Nothing
       about the button's colour or border is overridden. */
    .opsim-confirm-checkout-btn {
        min-height: 40px !important;
        padding: 8px 14px !important;
        border-radius: var(--opsim-radius) !important;
    }

    .opsim-confirm-checkout-btn .opsim-main-text {
        font-size: 0.8rem !important;
        font-weight: 600 !important;
        letter-spacing: 0.3px;
    }

    .opsim-confirm-checkout-btn .opsim-sub-text {
        font-size: 0.65rem !important;
    }

    .opsim-confirm-checkout-btn svg {
        width: 17px !important;
        height: 17px !important;
        stroke: none !important;
        fill: currentColor !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    .opsim-checkout-input-group { transition: none; }
    .opsim-confirm-checkout-btn.loading::after,
    .opsim-confirm-checkout-btn.is-loading::after { animation-duration: 2s; }
}
