/* ================================================================
   COD Checkout Form — v1.6.6
   ================================================================ */

/* Neutralize theme interference on hidden attribute */
#cof-overlay [hidden],
#cof-overlay *[hidden] { display: none !important; }

/* ----------------------------------------------------------------
   Overlay
   ---------------------------------------------------------------- */
.cof-overlay {
    position: fixed;
    inset: 0;
    background: var(--cof-overlay, rgba(0,0,0,.65));
    z-index: 999999;
    display: flex;
    align-items: flex-end;       /* slides up from bottom on mobile */
    justify-content: center;
    font-family: var(--cof-font, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif);
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}
.cof-overlay[hidden] { display: none !important; }

/* Desktop: centered with padding */
@media (min-width: 600px) {
    .cof-overlay { align-items: center; padding: 20px; }
}

/* ----------------------------------------------------------------
   Modal shell
   ---------------------------------------------------------------- */
.cof-modal {
    position: relative;
    background: var(--cof-bg, #fff);
    color: var(--cof-text, #1a202c);
    width: 100%;
    max-width: 480px;
    /* Use svh (small viewport height) so the modal never exceeds the visible
       area when the iOS keyboard is open. Falls back to vh for older browsers. */
    max-height: 94vh;
    max-height: 94svh;
    overflow: hidden;          /* children handle scroll */
    box-sizing: border-box;
    display: flex;
    flex-direction: column;

    /* Mobile: only round top corners, flush to screen edges.
       height: 95svh forces the modal to fill the screen, removing the large
       dark-overlay gap at the top (svh = small-viewport-height, iOS-safe). */
    border-radius: var(--cof-radius, 16px) var(--cof-radius, 16px) 0 0;
    box-shadow: 0 -4px 40px rgba(0,0,0,.22);
    animation: cof-slide-up .26s cubic-bezier(.4,0,.2,1);
    height: 95vh;
    height: 95svh;
}
@media (min-width: 600px) {
    .cof-modal {
        border-radius: var(--cof-radius, 16px); /* all corners on desktop */
        box-shadow: 0 16px 56px rgba(0,0,0,.28);
        animation: cof-fade-scale .2s cubic-bezier(.4,0,.2,1);
    }
}

@keyframes cof-slide-up  { from { transform:translateY(70px); opacity:0; } to { transform:translateY(0); opacity:1; } }
@keyframes cof-fade-scale { from { opacity:0; transform:scale(.96); } to { opacity:1; transform:scale(1); } }

/* ----------------------------------------------------------------
   Sticky header (never scrolls away)
   ---------------------------------------------------------------- */
.cof-header {
    flex-shrink: 0;
    position: sticky;   /* stays visible even if iOS bounce shifts the modal */
    top: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px 14px;
    border-bottom: 1px solid #efefef;
    background: var(--cof-bg, #fff);
    z-index: 10;
    /* Force GPU layer — prevents iOS from clipping the header during scroll */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}
.cof-header-title {
    font-size: 15px;
    font-weight: 700;
    line-height: 1.35;
    flex: 1;
    padding-right: 12px;
}
.cof-close {
    width: 30px;
    height: 30px;
    border: none;
    background: none;
    font-size: 22px;
    line-height: 1;
    color: #9ca3af;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    flex-shrink: 0;
    padding: 0;
    transition: background .15s, color .15s;
}
.cof-close:hover { background: #f3f4f6; color: #374151; }

/* ----------------------------------------------------------------
   Scrollable body — UNIFORM safe spacing on ALL sides
   ---------------------------------------------------------------- */
.cof-modal-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    /* Prevent iOS bounce from propagating to parent and clipping the header */
    overscroll-behavior-y: contain;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    box-sizing: border-box;
    scrollbar-width: thin;
    scrollbar-color: #d1d5db transparent;
}
@media (max-width: 599px) {
    .cof-modal-body { padding: 16px; gap: 12px; }

    /* iOS Safari zooms in on any input with font-size < 16px — force 16px to prevent it */
    .cof-input,
    .cof-textarea,
    .cof-select-field { font-size: 16px !important; }
}

/* ----------------------------------------------------------------
   Quantity Offer rows
   ---------------------------------------------------------------- */
.cof-offers-list { display: flex; flex-direction: column; gap: 8px; }

.cof-offer-row {
    display: flex;
    align-items: center;
    gap: 12px;
    border: 2px solid #e5e7eb;
    border-radius: 10px;
    padding: 10px 14px;
    cursor: pointer;
    background: #fff;
    box-sizing: border-box;
    transition: border-color .15s, background .15s;
}
.cof-offer-row:hover,
.cof-offer-row.cof-offer-active {
    border-color: var(--cof-offer-sel-border, #0a6640);
    background: var(--cof-offer-sel-bg, #f0faf5);
}
.cof-offer-img {
    width: 52px;
    height: 52px;
    object-fit: cover;
    border-radius: 6px;
    flex-shrink: 0;
}
.cof-offer-body { flex: 1; min-width: 0; }
.cof-offer-qty-label { font-size: 14px; font-weight: 700; color: #111827; }
.cof-offer-badge {
    display: inline-block;
    background: var(--cof-offer-badge-bg, #0a6640);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 20px;
    margin-left: 6px;
    vertical-align: middle;
}
.cof-offer-price-wrap { text-align: right; flex-shrink: 0; }
.cof-offer-old-price { font-size: 12px; color: #9ca3af; text-decoration: line-through; display: block; line-height: 1.2; }
.cof-offer-price { font-size: 15px; font-weight: 700; color: #111827; }

/* ----------------------------------------------------------------
   Summary box — strong selectors to resist theme overrides
   ---------------------------------------------------------------- */
#cof-overlay .cof-summary-box {
    display: block !important;
    border: 1px solid #e5e7eb !important;
    border-radius: 10px !important;
    overflow: hidden !important;
    background: #fff !important;
    box-sizing: border-box !important;
}
#cof-overlay .cof-summary-row {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    padding: 10px 16px !important;
    font-size: 14px !important;
    border-bottom: 1px solid #f3f4f6 !important;
    box-sizing: border-box !important;
    margin: 0 !important;
}
#cof-overlay .cof-summary-row:last-child { border-bottom: none !important; }
#cof-overlay .cof-summary-label { color: #6b7280 !important; }
#cof-overlay .cof-summary-total {
    font-size: 16px !important;
    font-weight: 700 !important;
    background: #f9fafb !important;
}
#cof-overlay .cof-discount-row .cof-summary-label,
#cof-overlay .cof-discount-row span:last-child { color: #059669 !important; }

/* ----------------------------------------------------------------
   Shipping options
   ---------------------------------------------------------------- */
.cof-section-label {
    font-size: 13px;
    font-weight: 700;
    color: #374151;
    margin: 0 0 8px;
}
.cof-shipping-list { display: flex; flex-direction: column; gap: 8px; }
.cof-shipping-option {
    display: flex;
    align-items: center;
    gap: 12px;
    border: 2px solid #e5e7eb;
    border-radius: 10px;
    padding: 10px 14px;
    cursor: pointer;
    box-sizing: border-box;
    transition: border-color .15s, background .15s;
}
.cof-shipping-option:hover,
.cof-shipping-option.cof-shipping-active {
    border-color: var(--cof-primary, #0a6640);
    background: var(--cof-offer-sel-bg, #f0faf5);
}
.cof-shipping-radio {
    width: 18px; height: 18px;
    border: 2px solid #d1d5db;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color .15s;
}
.cof-shipping-active .cof-shipping-radio { border-color: var(--cof-primary, #0a6640); }
.cof-shipping-active .cof-shipping-radio::after {
    content: '';
    width: 9px; height: 9px;
    border-radius: 50%;
    background: var(--cof-primary, #0a6640);
}
.cof-shipping-info { flex: 1; }
.cof-shipping-name { font-size: 14px; font-weight: 600; }
.cof-shipping-desc { font-size: 12px; color: #6b7280; }
.cof-shipping-price { font-size: 14px; font-weight: 700; flex-shrink: 0; }

/* ----------------------------------------------------------------
   Variant selectors
   ---------------------------------------------------------------- */
.cof-variant-group { margin-bottom: 10px; }
.cof-variant-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.cof-variant-options { display: flex; flex-wrap: wrap; gap: 6px; }
.cof-variant-btn {
    border: 1px solid #d1d5db;
    background: #fff;
    border-radius: 6px;
    padding: 6px 14px;
    font-size: 13px;
    cursor: pointer;
    transition: all .15s;
}
.cof-variant-btn.cof-variant-active {
    border-color: var(--cof-primary, #0a6640);
    background: var(--cof-primary, #0a6640);
    color: #fff;
}

/* ----------------------------------------------------------------
   Quantity control
   ---------------------------------------------------------------- */
.cof-qty-control {
    display: inline-flex;
    align-items: center;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    overflow: hidden;
}
.cof-qty-btn {
    background: #f9fafb;
    border: none;
    padding: 8px 18px;
    font-size: 20px;
    cursor: pointer;
    line-height: 1;
    color: #374151;
    transition: background .15s;
}
.cof-qty-btn:hover { background: #e5e7eb; }
.cof-qty-input {
    width: 52px;
    border: none;
    border-left: 1px solid #e5e7eb;
    border-right: 1px solid #e5e7eb;
    text-align: center;
    font-size: 16px;
    font-weight: 700;
    padding: 8px 0;
    -moz-appearance: textfield;
    background: #fff;
}
.cof-qty-input::-webkit-inner-spin-button,
.cof-qty-input::-webkit-outer-spin-button { -webkit-appearance: none; }

/* ----------------------------------------------------------------
   Above-form text
   ---------------------------------------------------------------- */
.cof-above-text {
    font-size: 13px;
    color: #4b5563;
    line-height: 1.55;
    text-align: center;
}

/* ----------------------------------------------------------------
   Form
   ---------------------------------------------------------------- */
.cof-form { display: contents; }

/* Fields list — flex column, consistent gap between every field */
.cof-fields-list { display: flex; flex-direction: column; gap: 12px; }

/*
 * FIELD WRAP
 * label  → rendered ABOVE the input (separate element, separate value)
 * placeholder → rendered INSIDE the input (separate attribute, separate value)
 * These two are ALWAYS independent — CSS never merges or derives one from the other.
 */
.cof-field-wrap { display: flex; flex-direction: column; gap: 0; }

.cof-label {
    font-size: 13px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 5px;
    display: flex;
    align-items: center;
    gap: 3px;
    line-height: 1.3;
}
.cof-required { color: #ef4444; }

/* Input wrapper handles icon positioning */
.cof-input-wrap { position: relative; }

.cof-field-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 15px;
    line-height: 1;
    pointer-events: none;
    /* keep icon vertically centered regardless of input height */
}
.cof-textarea-wrap .cof-field-icon { top: 14px; transform: none; }

/* Input & Textarea — base */
.cof-input,
.cof-textarea {
    width: 100%;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    background: #fff;
    color: var(--cof-text, #1a202c);
    box-sizing: border-box;
    transition: border-color .15s, box-shadow .15s;
    -webkit-appearance: none;
    appearance: none;
    padding: 11px 14px;        /* default (no icon) */
}
.cof-input.cof-has-icon,
.cof-textarea.cof-has-icon { padding-left: 36px; }  /* icon offset */

.cof-input::placeholder,
.cof-textarea::placeholder { color: #9ca3af; }
.cof-input:focus,
.cof-textarea:focus {
    outline: none;
    border-color: var(--cof-primary, #0a6640);
    box-shadow: 0 0 0 3px rgba(10,102,64,.12);
}
.cof-input.cof-error-field,
.cof-textarea.cof-error-field { border-color: #ef4444; box-shadow: none; }
.cof-field-error { font-size: 11px; color: #ef4444; margin-top: 3px; }
/* Textarea matches the same visual height as regular inputs */
.cof-textarea { resize: none; min-height: 44px; }

/* ----------------------------------------------------------------
   Province / City select dropdowns
   ---------------------------------------------------------------- */
.cof-select-field {
    cursor: pointer;
    /* Custom arrow */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7280' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px !important;
    -webkit-appearance: none;
    appearance: none;
}
.cof-select-field.cof-has-icon {
    padding-left: 36px;
    padding-right: 36px !important;
}
.cof-select-field:disabled {
    background-color: #f3f4f6;
    color: #9ca3af;
    cursor: not-allowed;
    opacity: 1;
}
.cof-select-field option { color: #1a202c; }

/* ----------------------------------------------------------------
   Upsells
   ---------------------------------------------------------------- */
.cof-upsells-list { display: flex; flex-direction: column; gap: 8px; }
.cof-upsell-item {
    display: flex;
    align-items: center;
    gap: 12px;
    border: 1.5px solid #e5e7eb;
    border-radius: 10px;
    padding: 10px 12px;
    cursor: pointer;
    box-sizing: border-box;
    transition: border-color .15s, background .15s;
}
.cof-upsell-item.cof-upsell-added { border-color: var(--cof-primary, #0a6640); background: var(--cof-offer-sel-bg, #f0faf5); }
.cof-upsell-checkbox {
    width: 20px; height: 20px;
    border: 2px solid #d1d5db;
    border-radius: 4px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: #fff;
    transition: all .15s;
}
.cof-upsell-added .cof-upsell-checkbox { background: var(--cof-primary, #0a6640); border-color: var(--cof-primary, #0a6640); }
.cof-upsell-img { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; flex-shrink: 0; }
.cof-upsell-info { flex: 1; min-width: 0; }
.cof-upsell-name { font-size: 13px; font-weight: 600; line-height: 1.3; }
.cof-upsell-price { font-size: 13px; font-weight: 700; color: var(--cof-primary, #0a6640); flex-shrink: 0; }

/* ----------------------------------------------------------------
   Verification banner
   ---------------------------------------------------------------- */
.cof-verify-banner {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    border-radius: 10px;
    padding: 14px 16px;
    color: #fff;
    box-sizing: border-box;
    margin-top: 4px;
}
.cof-verify-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255,255,255,.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}
.cof-verify-content { flex: 1; }
.cof-verify-title {
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .4px;
    line-height: 1.3;
    margin-bottom: 4px;
}
.cof-verify-text { font-size: 11px; line-height: 1.5; opacity: .9; }

/* ----------------------------------------------------------------
   Error
   ---------------------------------------------------------------- */
.cof-error {
    background: #fef2f2;
    border: 1px solid #fca5a5;
    color: #b91c1c;
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 13px;
    line-height: 1.5;
    box-sizing: border-box;
}

/* ----------------------------------------------------------------
   Submit button
   ---------------------------------------------------------------- */
.cof-btn-submit {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    background: var(--cof-btn-bg, #0a6640);
    color: var(--cof-btn-color, #fff);
    border: none;
    border-radius: var(--cof-btn-radius, 8px);
    padding: 15px 20px;
    cursor: pointer;
    gap: 3px;
    box-sizing: border-box;
    transition: opacity .15s, transform .1s;
    margin-top: 4px;
}
.cof-btn-submit:hover { opacity: .9; }
.cof-btn-submit:active { transform: scale(.98); }
.cof-btn-submit:disabled { opacity: .6; cursor: not-allowed; }
.cof-btn-main {
    font-size: 15px;
    font-weight: 800;
    letter-spacing: .5px;
    text-transform: uppercase;
    line-height: 1;
}
.cof-btn-sub {
    font-size: 11px;
    font-weight: 500;
    opacity: .82;
    text-transform: uppercase;
    letter-spacing: .5px;
    line-height: 1;
}
@keyframes cof-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(10,102,64,.45); }
    70%  { box-shadow: 0 0 0 14px rgba(10,102,64,0); }
    100% { box-shadow: 0 0 0 0 rgba(10,102,64,0); }
}
.cof-btn-submit.cof-loading .cof-btn-main::after {
    content: '';
    display: inline-block;
    width: 13px; height: 13px;
    border: 2px solid rgba(255,255,255,.35);
    border-top-color: #fff;
    border-radius: 50%;
    vertical-align: middle;
    margin-left: 8px;
    animation: cof-spin .7s linear infinite;
}
@keyframes cof-spin { to { transform: rotate(360deg); } }

/* ----------------------------------------------------------------
   Trust / COD section
   ---------------------------------------------------------------- */
.cof-trust-section {
    border: 2px solid var(--cof-primary, #0a6640);
    border-radius: 10px;
    padding: 14px 16px;
    text-align: center;
    box-sizing: border-box;
}
.cof-trust-title {
    font-size: 14px;
    font-weight: 800;
    color: var(--cof-primary, #0a6640);
    text-transform: uppercase;
    letter-spacing: .5px;
    margin-bottom: 2px;
}
.cof-trust-subtitle { font-size: 12px; color: #6b7280; margin-bottom: 12px; }
.cof-trust-steps {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.cof-trust-step { text-align: center; }
.cof-trust-step-icon { font-size: 26px; display: block; margin-bottom: 4px; }
.cof-trust-step-label { font-size: 11px; font-weight: 700; color: #374151; text-transform: uppercase; letter-spacing: .3px; }
.cof-trust-arrow { font-size: 18px; color: #9ca3af; margin-bottom: 14px; }

/* ----------------------------------------------------------------
   Success
   ---------------------------------------------------------------- */
.cof-success { text-align: center; padding: 48px 20px; }
.cof-success-icon {
    width: 68px; height: 68px;
    background: var(--cof-primary, #0a6640);
    color: #fff;
    border-radius: 50%;
    font-size: 34px;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 20px;
    animation: cof-pop .32s cubic-bezier(.4,0,.2,1);
}
@keyframes cof-pop { from { transform:scale(0); opacity:0; } to { transform:scale(1); opacity:1; } }
.cof-success-msg { font-size: 16px; color: #374151; line-height: 1.6; }

/* ----------------------------------------------------------------
   Buy Now (product page)
   ---------------------------------------------------------------- */
.cof-buy-now {
    display: block !important;
    width: 100% !important;
    background: var(--cof-btn-bg, #0a6640) !important;
    color: var(--cof-btn-color, #fff) !important;
    border-color: transparent !important;
    border-radius: var(--cof-btn-radius, 8px) !important;
    padding: 14px 20px !important;
    font-size: 15px !important;
    font-weight: 700 !important;
    text-align: center !important;
    margin: 8px 0 0 0 !important;
    box-sizing: border-box !important;
}

/* ----------------------------------------------------------------
   Sticky buy bar (mobile only)
   ---------------------------------------------------------------- */
.cof-sticky-bar {
    display: none; /* hidden on desktop; JS shows/hides on mobile */
}
@media (max-width: 599px) {
    .cof-sticky-bar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 99998; /* below modal overlay (999999) */
        background: #fff;
        padding: 12px 16px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
        box-shadow: 0 -2px 20px rgba(0,0,0,.15);
        box-sizing: border-box;
        /* hidden by default — JS toggles via display */
    }
    .cof-sticky-bar-btn {
        display: flex !important;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        width: 100%;
        background: var(--cof-btn-bg, #0a6640);
        color: var(--cof-btn-color, #fff);
        border: none;
        border-radius: var(--cof-btn-radius, 8px);
        padding: 14px 20px;
        font-size: 16px;
        font-weight: 800;
        text-transform: uppercase;
        letter-spacing: .5px;
        cursor: pointer;
        box-sizing: border-box;
        line-height: 1;
        gap: 3px;
    }
    .cof-sticky-bar-sub {
        font-size: 11px;
        font-weight: 500;
        opacity: .82;
        text-transform: uppercase;
        letter-spacing: .5px;
        line-height: 1;
    }
}
