/**
 * Correo Argentino Pro — Checkout Styles
 * Agency selector modal with search, Leaflet map, geolocation.
 */

/* ========================================
   Inline selector (below shipping rate)
   ======================================== */
.cap-agency-selector {
    margin: 8px 0 0px 0px;
    font-size: 14px;
    line-height: 1.4;
    max-width: 100%;
    box-sizing: border-box;
    overflow: hidden;
}

/* "Elegir sucursal" button */
.cap-open-modal-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    font-size: 13px;
    font-weight: 600;
    color: #0073aa;
    background: #f0f6fc;
    border: 1px dashed #0073aa;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    width: 100%;
    justify-content: center;
}

.cap-open-modal-btn .cap-btn-icon {
    flex-shrink: 0;
    display: block;
}

.cap-open-modal-btn:hover {
    background: #e1eef9;
    border-style: solid;
}

/* Selected agency bar */
.cap-agency-selector__selected {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: #e7f3ff;
    border: 1px solid #b8daff;
    border-radius: 8px;
    max-width: 100%;
    box-sizing: border-box;
    overflow: hidden;
    word-break: break-word;
}

.cap-selected-check {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    background: #0073aa;
    color: #fff;
    border-radius: 50%;
}

.cap-selected-agency-info {
    flex: 1;
    font-size: 13px;
    color: #1d2327;
    min-width: 0;
}

.cap-selected-agency-info strong {
    display: block;
    margin-bottom: 2px;
}

.cap-selected-agency-info span {
    font-size: 12px;
    color: #555;
}

.cap-change-agency-btn {
    flex-shrink: 0;
    padding: 5px 12px;
    font-size: 12px;
    font-weight: 600;
    color: #0073aa;
    background: #fff;
    border: 1px solid #0073aa;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.cap-change-agency-btn:hover {
    background: #0073aa;
    color: #fff;
}

/* ========================================
   Modal overlay
   ======================================== */
.cap-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 999999;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: cap-fadeIn 0.2s ease;
}

@keyframes cap-fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ========================================
   Modal container
   ======================================== */
.cap-modal {
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
    width: 100%;
    max-width: 960px;
    height: 85vh;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: cap-slideUp 0.25s ease;
}

@keyframes cap-slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ========================================
   Modal header
   ======================================== */
.cap-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #eee;
}

.cap-modal__header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    color: #1d2327;
    display: flex;
    align-items: center;
    gap: 8px;
}

.cap-modal__header h3 svg {
    color: #0073aa;
}

.cap-modal__close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    background: #f0f0f0;
    border-radius: 50%;
    cursor: pointer;
    color: #555;
    transition: background 0.15s, color 0.15s;
}

.cap-modal__close:hover {
    background: #ddd;
    color: #1d2327;
}

/* ========================================
   Modal toolbar (province + search + geo)
   ======================================== */
.cap-modal__toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    background: #fafbfc;
    border-bottom: 1px solid #eee;
}

.cap-province-select {
    width: 200px;
    flex-shrink: 0;
    padding: 8px 12px;
    border: 1px solid #d0d5dd;
    border-radius: 8px;
    font-size: 13px;
    background: #fff;
    appearance: auto;
    color: #1d2327;
}

.cap-province-select:focus {
    border-color: #0073aa;
    outline: none;
    box-shadow: 0 0 0 2px rgba(0, 115, 170, 0.15);
}

.cap-search-wrapper {
    flex: 1;
    position: relative;
    min-width: 0;
}

.cap-search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #999;
    pointer-events: none;
    z-index: 1;
}

.cap-agency-search {
    width: 100%;
    padding: 8px 12px 8px 38px !important;
    border: 1px solid #d0d5dd;
    border-radius: 8px;
    font-size: 13px;
    box-sizing: border-box;
    background: #fff;
    color: #1d2327;
}

.cap-agency-search:focus {
    border-color: #0073aa;
    outline: none;
    box-shadow: 0 0 0 2px rgba(0, 115, 170, 0.15);
}

.cap-search-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    flex-shrink: 0;
    padding: 0 16px;
    height: 38px;
    border: 1px solid #0073aa;
    border-radius: 8px;
    background: #0073aa;
    color: #fff !important;
    font-size: 13px;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    box-sizing: border-box;
    white-space: nowrap;
}

.cap-search-btn svg {
    stroke: #fff !important;
    fill: none !important;
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    display: block;
}

.cap-search-btn:hover {
    background: #005a87;
    border-color: #005a87;
}

.cap-geolocate-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    flex-shrink: 0;
    padding: 0;
    border: 1px solid #d0d5dd;
    border-radius: 8px;
    background: #fff;
    color: #555;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.cap-geolocate-btn:hover {
    background: #f0f6fc;
    border-color: #0073aa;
    color: #0073aa;
}

.cap-geolocate-btn--loading {
    pointer-events: none;
    animation: cap-spin 0.8s linear infinite;
}

/* ========================================
   Modal body: list + map side by side
   ======================================== */
.cap-modal__body {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.cap-modal__list {
    width: 380px;
    flex-shrink: 0;
    border-right: 1px solid #eee;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.cap-modal__map {
    flex: 1;
    min-width: 0;
    position: relative;
}

/* ========================================
   Agency list inside modal
   ======================================== */
.cap-agency-list {
    flex: 1;
    overflow-y: auto;
    background: #fff;
}

/* Scrollbar styling */
.cap-agency-list::-webkit-scrollbar {
    width: 6px;
}

.cap-agency-list::-webkit-scrollbar-track {
    background: transparent;
}

.cap-agency-list::-webkit-scrollbar-thumb {
    background: #d0d0d0;
    border-radius: 3px;
}

.cap-agency-list::-webkit-scrollbar-thumb:hover {
    background: #999;
}

/* Agency item */
.cap-agency-item {
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid #f5f5f5;
    transition: background 0.12s;
}

.cap-agency-item:last-child {
    border-bottom: none;
}

.cap-agency-item:hover {
    background: #f7fafc;
}

.cap-agency-item.selected {
    background: #e7f3ff;
    border-left: 3px solid #0073aa;
    padding-left: 13px;
}

.cap-agency-item__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.cap-agency-item__name {
    font-weight: 600;
    font-size: 13px;
    color: #1d2327;
}

.cap-agency-item__distance {
    flex-shrink: 0;
    font-size: 11px;
    font-weight: 500;
    color: #0073aa;
    background: #e7f3ff;
    padding: 2px 8px;
    border-radius: 10px;
    white-space: nowrap;
}

.cap-agency-item__address {
    font-size: 12px;
    color: #757575;
    margin-top: 3px;
}

.cap-agency-item__schedule {
    font-size: 11px;
    color: #999;
    margin-top: 3px;
}

/* Empty state */
.cap-agency-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 16px;
    color: #999;
    text-align: center;
    gap: 10px;
}

.cap-agency-empty p {
    margin: 0;
    font-size: 13px;
}

/* ========================================
   Map (inside modal)
   ======================================== */
.cap-map {
    width: 100%;
    height: 100%;
    min-height: 400px;
    z-index: 1;
}

/* Leaflet tile fix — prevent WC/theme global img styles from breaking tiles */
.cap-map img,
.cap-modal__map img {
    max-width: none !important;
    max-height: none !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    padding: 0 !important;
    border: 0 !important;
}

.cap-map .leaflet-tile-pane,
.cap-map .leaflet-overlay-pane {
    z-index: 1;
}

.cap-map .leaflet-control-zoom {
    z-index: 10;
}

/* Custom marker */
.cap-marker {
    background: transparent !important;
    border: none !important;
}

.cap-marker--selected {
    z-index: 1000 !important;
}

/* Leaflet popup */
.cap-popup {
    font-size: 13px;
    line-height: 1.5;
    min-width: 180px;
}

.cap-popup strong {
    display: block;
    margin-bottom: 4px;
    color: #1d2327;
    font-size: 14px;
}

.cap-popup-select {
    display: inline-block;
    margin-top: 8px;
    padding: 6px 16px;
    font-size: 12px;
    font-weight: 600;
    color: #fff;
    background: #0073aa;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s;
}

.cap-popup-select:hover {
    background: #005a87;
}

/* ========================================
   Loading state (inside modal)
   ======================================== */
.cap-modal__loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 48px;
    color: #757575;
    font-size: 14px;
}

.cap-spinner {
    width: 22px;
    height: 22px;
    border: 2.5px solid #e0e0e0;
    border-top-color: #0073aa;
    border-radius: 50%;
    animation: cap-spin 0.6s linear infinite;
}

@keyframes cap-spin {
    to { transform: rotate(360deg); }
}

/* ========================================
   Shipping destination info card (home delivery)
   ======================================== */
.woocommerce-shipping-destination.cap-dest-styled {
    margin: 8px 0 0;
    padding: 10px 14px;
    background: #f0faf0;
    border: 1px solid #b8e6b8;
    border-radius: 8px;
    font-size: 13px;
    color: #1d2327;
    line-height: 1.5;
}

/* ========================================
   Cart: Agency browse option (table row)
   ======================================== */
.cap-cart-agency-row th {
    vertical-align: top;
    padding-top: 14px;
}

.cap-cart-agency-option {
    padding: 0;
}

.cap-cart-agency-option__desc {
    font-size: 13px;
    color: #666;
    margin: 0 0 10px;
    line-height: 1.4;
}

.cap-cart-agency-option .cap-agency-selector {
    margin: 0;
}

.cap-cart-agency-option .cap-open-modal-btn {
    width: auto;
    display: inline-flex;
    padding: 10px 20px;
}

/* ========================================
   Readonly shipping fields (agency delivery)
   ======================================== */
.cap-readonly {
    background-color: #f0f0f0 !important;
    cursor: not-allowed;
    opacity: 0.7;
}

/* ========================================
   Responsive
   ======================================== */
@media (max-width: 768px) {
    .cap-agency-selector {
        margin-left: 0;
    }

    .cap-modal-overlay {
        padding: 0;
        align-items: flex-end;
    }

    .cap-modal {
        max-width: 100%;
        max-height: 95vh;
        border-radius: 16px 16px 0 0;
    }

    .cap-modal__toolbar {
        flex-wrap: wrap;
    }

    .cap-province-select {
        width: 100%;
    }

    .cap-search-btn span {
        display: none;
    }

    .cap-search-btn {
        width: 38px;
        padding: 0;
    }

    .cap-modal__body {
        flex-direction: column;
    }

    .cap-modal__list {
        width: 100%;
        max-height: 40vh;
        border-right: none;
        border-bottom: 1px solid #eee;
    }

    .cap-modal__map {
        min-height: 250px;
    }

    .cap-agency-selector__selected {
        flex-wrap: wrap;
    }

    .cap-change-agency-btn {
        width: 100%;
        text-align: center;
        margin-top: 4px;
    }
}

@media (max-width: 480px) {
    .cap-modal__header {
        padding: 12px 16px;
    }

    .cap-modal__header h3 {
        font-size: 14px;
    }

    .cap-modal__toolbar {
        padding: 10px 16px;
    }

    .cap-agency-item {
        padding: 10px 12px;
    }

    .cap-popup-select {
        width: 100%;
        text-align: center;
    }
}
