/* ==========================================================================
   Address Book – Checkout selector, Manage button & Modal
   Loaded on both checkout and My Account pages.
   ========================================================================== */

/* ---- Hide native WooCommerce address blocks when custom blocks are active ---- */
body.ims-address-book-active .wp-block-woocommerce-checkout-shipping-address-block,
body.ims-address-book-active .wp-block-woocommerce-checkout-billing-address-block,
body.ims-address-book-active [data-block-name="woocommerce/checkout-shipping-address-block"],
body.ims-address-book-active [data-block-name="woocommerce/checkout-billing-address-block"],
body.ims-address-book-active .wc-block-checkout__shipping-fields,
body.ims-address-book-active .wc-block-checkout__billing-fields {
    display: none !important;
}

/* ---- Checkout address selector ---- */
.ims-address-selector {
    margin-bottom: 1.25rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid #e5e7eb;
}

.ims-address-selector label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: #374151;
    margin-bottom: 0.35rem;
}

.ims-address-selector select {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.9rem;
    color: #111827;
    background: #fff;
}

.ims-address-selector select:focus {
    outline: none;
    border-color: #374151;
    box-shadow: 0 0 0 2px rgba(55, 65, 81, 0.1);
}

/* ---- Selector row (dropdown + manage button side by side) ---- */
.ims-address-selector__row {
    display: flex;
    gap: 0.5rem;
    align-items: stretch;
}

.ims-address-selector__row .ims-address-select {
    flex: 1;
    min-width: 0;
}

.ims-address-manage-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.6rem 1rem;
    background: #f3f4f6;
    color: #374151;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.ims-address-manage-btn:hover {
    background: #e5e7eb;
    border-color: #9ca3af;
    color: #111827;
}

/* ---- Block heading ---- */
.ims-checkout-address-block__heading {
    font-size: 1rem;
    font-weight: 600;
    color: #1e1e1e;
    margin: 0 0 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #e5e7eb;
}

/* ---- Block checkout variant ---- */
.ims-address-selector--block {
    border-bottom-color: #c3c4c7;
    margin-bottom: 1em;
    padding-bottom: 1em;
}

.ims-address-selector--block .ims-address-selector__label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: #1e1e1e;
    font-family: inherit;
    margin-bottom: 0.35rem;
}

/* ---- Custom div-based dropdown ---- */
.ims-address-dropdown {
    position: relative;
    flex: 1;
    min-width: 0;
}

.ims-address-dropdown__trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.65em 0.75em;
    border: 1px solid #c3c4c7;
    border-radius: 6px;
    background: #fff;
    font-size: 0.875rem;
    font-family: inherit;
    color: #1e1e1e;
    cursor: pointer;
    text-align: left;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    gap: 0.5rem;
}

.ims-address-dropdown__trigger:hover {
    border-color: #949494;
}

.ims-address-dropdown__trigger:focus {
    outline: none;
    border-color: #949494;
    box-shadow: 0 0 0 1px #949494;
}

.ims-address-dropdown__text {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ims-address-dropdown__chevron {
    flex-shrink: 0;
    color: #6b7280;
    transition: transform 0.2s ease;
}

.ims-address-dropdown.is-open .ims-address-dropdown__chevron {
    transform: rotate(180deg);
}

.ims-address-dropdown__menu {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 9999;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    max-height: 260px;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.ims-address-dropdown.is-open .ims-address-dropdown__menu {
    display: block;
}

.ims-address-dropdown__option {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    padding: 0.65rem 0.85rem;
    cursor: pointer;
    border-bottom: 1px solid #f3f4f6;
    transition: background 0.1s ease;
}

.ims-address-dropdown__option:last-child {
    border-bottom: none;
}

.ims-address-dropdown__option:hover {
    background: #f3f4f6;
}

.ims-address-dropdown__option.is-selected {
    background: #eef2ff;
}

.ims-address-dropdown__option-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: #374151;
    line-height: 1.3;
}

.ims-address-dropdown__option-summary {
    font-size: 0.78rem;
    color: #6b7280;
    line-height: 1.4;
    white-space: normal;
    word-break: break-word;
}

/* ---- Dropdown validation error state ---- */
.ims-address-dropdown.has-error .ims-address-dropdown__trigger {
    border-color: #cc1818;
    box-shadow: 0 0 0 1px #cc1818;
}

.ims-address-dropdown__error {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 0.4rem;
    padding: 0.55rem 0.75rem;
    background: #fcf0f0;
    color: #cc1818;
    font-size: 0.82rem;
    font-weight: 500;
    border: 1px solid #f5c6c6;
    border-radius: 6px;
}

.ims-address-dropdown__error::before {
    content: '';
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    background: #cc1818;
    border-radius: 50%;
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z'/%3E%3C/svg%3E");
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z'/%3E%3C/svg%3E");
    -webkit-mask-size: contain;
    mask-size: contain;
}

/* ---- Custom read-only address preview card ---- */
.ims-address-preview {
    margin-top: 0.75rem;
    padding: 1rem;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #f9fafb;
    font-size: 0.88rem;
    line-height: 1.5;
    color: #374151;
}

.ims-address-preview--empty {
    text-align: center;
    color: #9ca3af;
    font-style: italic;
    padding: 1.25rem 1rem;
}

.ims-address-preview__label {
    display: inline-block;
    padding: 0.1rem 0.5rem;
    background: #e5e7eb;
    border-radius: 9999px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #374151;
    margin-bottom: 0.4rem;
}

.ims-address-preview__name {
    font-weight: 600;
    font-size: 0.9rem;
    color: #111827;
}

.ims-address-preview__company {
    font-size: 0.82rem;
    color: #6b7280;
}

.ims-address-preview__address {
    font-size: 0.85rem;
    color: #374151;
    margin: 0.15rem 0;
}

.ims-address-preview__phone {
    font-size: 0.82rem;
    color: #6b7280;
    margin-top: 0.25rem;
}

.ims-address-preview__email {
    font-size: 0.82rem;
    color: #6b7280;
}

/* ---- Empty block state ----
   Rendered when the user has no saved addresses of this type. Shows the
   block heading, a short intro line, and an inline Add Address form
   mounted by JS into `.ims-address-empty-form`. */
.ims-checkout-address-block--empty {
    padding: 0;
}

.ims-checkout-address-block--empty .ims-checkout-address-block__heading {
    margin-bottom: 0.5rem;
}

.ims-checkout-address-block__empty-msg {
    color: #4b5563;
    font-size: 0.88rem;
    line-height: 1.5;
    margin: 0 0 1rem;
}

.ims-address-empty-form,
.ims-address-add-form-inline {
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #fafafa;
    padding: 1rem;
}

.ims-address-add-form-inline {
    margin-top: 0.85rem;
}

.ims-address-empty-form .ims-ab-modal__form,
.ims-address-add-form-inline .ims-ab-modal__form {
    gap: 0.85rem;
}

.ims-address-empty-form .ims-ab-modal__form-actions,
.ims-address-add-form-inline .ims-ab-modal__form-actions {
    justify-content: flex-end;
    padding-top: 0.25rem;
}

@media (max-width: 768px) {
    .ims-address-empty-form .ims-ab-modal__form-actions .ims-ab-modal__save-btn,
    .ims-address-add-form-inline .ims-ab-modal__form-actions .ims-ab-modal__save-btn {
        width: 100%;
    }
}

/* ====================================================================
   Address Book Modal
   ==================================================================== */

.ims-ab-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0);
    transition: background 0.2s ease;
    padding: 1rem;
}

.ims-ab-modal-overlay.is-open {
    background: rgba(0, 0, 0, 0.45);
}

.ims-ab-modal {
    position: relative;
    width: 100%;
    max-width: 560px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    opacity: 0;
    transform: translateY(12px) scale(0.97);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.ims-ab-modal-overlay.is-open .ims-ab-modal {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.ims-ab-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0;
}

.ims-ab-modal__header h3 {
    font-size: 1.1rem;
    font-weight: 700;
    color: #111827;
    margin: 0;
}

.ims-ab-modal__close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: none;
    border: none;
    border-radius: 6px;
    color: #6b7280;
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease;
}

.ims-ab-modal__close:hover {
    background: #f3f4f6;
    color: #111827;
}

.ims-ab-modal__body {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem 1.5rem;
}

/* ---- Modal card list ---- */
.ims-ab-modal__grid {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.ims-ab-modal__card {
    padding: 1rem;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    transition: border-color 0.12s ease;
}

.ims-ab-modal__card:hover {
    border-color: #9ca3af;
}

.ims-ab-modal__card .ims-address-card__type-badge {
    margin-bottom: 0.5rem;
}

.ims-ab-modal__card-label {
    display: inline-block;
    padding: 0.1rem 0.5rem;
    background: #f3f4f6;
    border-radius: 9999px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #374151;
    margin-bottom: 0.5rem;
}

.ims-ab-modal__card-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: #111827;
}

.ims-ab-modal__card-company {
    font-size: 0.82rem;
    color: #6b7280;
}

.ims-ab-modal__card-address {
    font-size: 0.82rem;
    color: #374151;
    line-height: 1.45;
    margin: 0.15rem 0;
}

.ims-ab-modal__card-phone {
    font-size: 0.82rem;
    color: #6b7280;
}

.ims-ab-modal__card-note {
    font-size: 0.8rem;
    font-style: italic;
    color: #6b7280;
    margin-top: 0.35rem;
    padding-top: 0.35rem;
    border-top: 1px dashed #e5e7eb;
}

.ims-ab-modal__select-btn {
    display: block;
    width: 100%;
    margin-top: 0.75rem;
    padding: 0.45rem;
    background: #111827;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease;
}

.ims-ab-modal__select-btn:hover {
    background: #374151;
}

.ims-ab-modal__empty {
    text-align: center;
    color: #9ca3af;
    font-size: 0.9rem;
    padding: 1rem 0;
}

.ims-ab-modal__add-btn {
    width: 100%;
    text-align: center;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.65rem 1.5rem;
    background: #111827;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease;
}

.ims-ab-modal__add-btn:hover {
    background: #374151;
}

/* ---- Modal form ---- */
.ims-ab-modal__back-btn {
    background: none;
    border: none;
    padding: 0;
    color: #6b7280;
    font-size: 0.85rem;
    cursor: pointer;
    margin-bottom: 1rem;
}

.ims-ab-modal__back-btn:hover {
    color: #111827;
    text-decoration: underline;
}

.ims-ab-modal__form {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.ims-ab-modal__field {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.ims-ab-modal__field label {
    font-size: 0.8rem;
    font-weight: 600;
    color: #374151;
}

.ims-ab-modal__field input,
.ims-ab-modal__field select {
    width: 100%;
    padding: 0.55rem 0.7rem;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.88rem;
    color: #111827;
    background: #fff;
    box-sizing: border-box;
}

.ims-ab-modal__field input:focus,
.ims-ab-modal__field select:focus {
    outline: none;
    border-color: #374151;
    box-shadow: 0 0 0 2px rgba(55, 65, 81, 0.1);
}

.ims-ab-modal__form-row--half {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.ims-ab-modal__error {
    background: #fef2f2;
    color: #991b1b;
    font-size: 0.82rem;
    padding: 0.6rem 0.75rem;
    border-radius: 6px;
    border: 1px solid #fecaca;
}

.ims-ab-modal__form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding-top: 0.5rem;
}

.ims-ab-modal__cancel-btn {
    padding: 0.55rem 1rem;
    background: none;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    color: #374151;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.ims-ab-modal__cancel-btn:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
}

.ims-ab-modal__save-btn {
    min-width: 130px;
    text-align: center;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.65rem 1.5rem;
    background: #111827;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease;
}

.ims-ab-modal__save-btn:hover {
    background: #374151;
}

.ims-ab-modal__save-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
    .ims-ab-modal {
        max-height: 95vh;
    }

    .ims-ab-modal__form-row--half {
        grid-template-columns: 1fr;
    }

    .ims-address-selector__row {
        flex-direction: column;
    }

    .ims-address-dropdown__option {
        padding: 0.75rem 0.85rem;
        min-height: 44px;
    }
}

/* ====================================================================
   Address Book – Bill-to / Ship-to type badges (My Account)
   ==================================================================== */

.ims-address-card__type-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.2rem 0.6rem;
    border-radius: 9999px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    line-height: 1;
    margin-bottom: 0.5rem;
}

.ims-address-card__type-badge svg {
    flex-shrink: 0;
}

.ims-address-card__type-badge--bill_to {
    background: #eff6ff;
    color: #1d4ed8;
    border: 1px solid #bfdbfe;
}

.ims-address-card__type-badge--ship_to {
    background: #f0fdf4;
    color: #15803d;
    border: 1px solid #bbf7d0;
}


/* ---- Address Type toggle (Shipping / Billing radio) ---- */
.ims-address-type-toggle {
    margin-bottom: 1rem;
}

.ims-address-type-toggle__label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: #374151;
    margin-bottom: 0.4rem;
}

.ims-address-type-toggle__options {
    display: flex;
    gap: 0.5rem;
}

.ims-address-type-toggle__option {
    flex: 1;
    cursor: pointer;
    margin: 0;
}

.ims-address-type-toggle__option input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    pointer-events: none;
}

.ims-address-type-toggle__btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    width: 100%;
    padding: 0.6rem 1rem;
    border: 2px solid #d1d5db;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    color: #6b7280;
    background: #fff;
    transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
    text-align: center;
}

.ims-address-type-toggle__btn:hover {
    border-color: #9ca3af;
    color: #374151;
}

.ims-address-type-toggle__option input[type="radio"]:checked + .ims-address-type-toggle__btn--ship-to {
    border-color: #15803d;
    background: #f0fdf4;
    color: #15803d;
    box-shadow: 0 0 0 1px #15803d;
}

.ims-address-type-toggle__option input[type="radio"]:checked + .ims-address-type-toggle__btn--bill-to {
    border-color: #1d4ed8;
    background: #eff6ff;
    color: #1d4ed8;
    box-shadow: 0 0 0 1px #1d4ed8;
}

.ims-address-type-toggle__btn svg {
    flex-shrink: 0;
}

/* Modal-specific toggle spacing */
.ims-ab-modal__form .ims-address-type-toggle {
    margin-bottom: 0;
}

/* "Managed by NetSuite" notice replacing edit/delete on bill-to cards */
.ims-address-card__managed-notice {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.75rem;
    font-weight: 500;
    color: #6b7280;
    font-style: italic;
}

/* ==========================================================================
   Smarty US Autocomplete — typeahead dropdown
   Anchored to the .ims-ab-modal__field that wraps the address_1 input,
   so it floats below the input and matches the form's width.
   ========================================================================== */

.ims-smarty-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 9999;
    margin-top: 4px;
    max-height: 280px;
    overflow-y: auto;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.16);
    padding: 4px;
}

.ims-smarty-suggestions__item {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    width: 100%;
    padding: 10px 12px;
    border: 0;
    background: transparent;
    text-align: left;
    cursor: pointer;
    border-radius: 6px;
    transition: background-color 0.1s ease;
    font: inherit;
    color: inherit;
}

.ims-smarty-suggestions__item:hover,
.ims-smarty-suggestions__item.is-active,
.ims-smarty-suggestions__item:focus {
    background: #fff8e1;
    outline: none;
}

.ims-smarty-suggestions__primary {
    font-weight: 600;
    color: #111827;
    line-height: 1.3;
}

.ims-smarty-suggestions__secondary {
    font-size: 0.85em;
    color: #6b7280;
    line-height: 1.3;
}

.ims-smarty-suggestions__empty {
    padding: 12px;
    color: #6b7280;
    font-style: italic;
    font-size: 0.9em;
}

/* ==========================================================================
   Smarty verify error banner — appears in form's existing errorEl
   (.ims-ab-modal__error in the modal, .ims-account-form__error on My Account)
   when an address is rejected by USPS.
   ========================================================================== */

.ims-smarty-error {
    background: #fff8f1;
    border: 1px solid #fed7aa;
    border-left: 4px solid #f97316;
    border-radius: 6px;
    padding: 12px 14px;
    color: #7c2d12;
    font-size: 0.92em;
    line-height: 1.45;
}

.ims-smarty-error__heading {
    font-weight: 700;
    color: #7c2d12;
    margin-bottom: 4px;
}

.ims-smarty-error__body {
    color: #9a3412;
}

.ims-smarty-error__detail {
    display: inline-block;
    margin-top: 4px;
    font-size: 0.88em;
    color: #7c2d12;
    font-style: italic;
}

.ims-smarty-error__actions {
    margin-top: 10px;
}

.ims-smarty-error__override {
    display: inline-block;
    padding: 6px 14px;
    border: 1px solid #f97316;
    background: #fff;
    color: #c2410c;
    border-radius: 6px;
    font-size: 0.9em;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.ims-smarty-error__override:hover,
.ims-smarty-error__override:focus {
    background: #f97316;
    color: #fff;
    outline: none;
}

.ims-address-card__managed-notice svg {
    flex-shrink: 0;
    color: #9ca3af;
}
