/*
 * Checkout CSS - Mobile First
 * Usa variables de Rasti (variables.css)
 * Sistema de 3 pasos con validación server-side
 */

/* ============================================
   LAYOUT PRINCIPAL
   ============================================ */
.checkout-page {
    min-height: calc(100vh - var(--navbar-height, 72px));
    padding: calc(var(--navbar-height, 72px) + 1rem) 1rem 1rem;
    background: var(--gray-50);
}

.checkout-container {
    max-width: 100%;
}

.checkout-layout {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* ============================================
   INDICADOR DE PASOS
   ============================================ */
.checkout-steps {
    background: var(--white);
    padding: 1rem;
    margin-bottom: 1rem;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    border-radius: var(--radius-md);
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.step-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    opacity: 0.4;
    transition: opacity 0.3s ease;
}

.step-item.active {
    opacity: 1;
}

.step-number {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--gray-200);
    color: var(--gray-800);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.3s ease;
}

.step-number.active {
    background: var(--primary);
    color: var(--white);
    transform: scale(1.1);
}

.step-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
    text-align: center;
}

.step-line {
    width: 24px;
    height: 2px;
    background: var(--gray-200);
    flex-shrink: 0;
}

.step-line.completed {
    background: var(--primary);
}

/* ============================================
   CONTENIDO PRINCIPAL
   ============================================ */
.checkout-content {
    background: var(--white);
    border-radius: var(--radius-md);
    padding: 1.5rem 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.checkout-step {
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.step-header {
    margin-bottom: 1.5rem;
}

.step-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-strong);
    margin: 0 0 0.5rem 0;
}

.step-subtitle {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin: 0;
}

.step-content h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-strong);
    margin: 1.5rem 0 1rem 0;
}

.step-content h3:first-child {
    margin-top: 0;
}

/* ============================================
   ITEMS DEL CARRITO
   ============================================ */
.cart-item {
    display: flex;
    gap: 1rem;
    padding: 1rem;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    margin-bottom: 0.75rem;
    background: var(--white);
    transition: box-shadow 0.2s ease;
}

.cart-item:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.cart-item-image {
    width: 60px;
    height: 60px;
    border-radius: var(--radius-sm);
    background: var(--gray-100);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--text-muted);
}

.cart-item-image-mini {
    width: 40px;
    height: 40px;
}

.cart-item-mini {
    padding: 0.75rem;
}

.cart-item-details {
    flex: 1;
    min-width: 0;
}

.cart-item-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-strong);
    margin-bottom: 0.25rem;
}

.cart-item-meta {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.cart-item-total {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary);
    align-self: center;
    flex-shrink: 0;
}

/* Carrito vacío */
.empty-cart {
    text-align: center;
    padding: 3rem 1rem;
}

.empty-cart svg {
    margin-bottom: 1rem;
}

.empty-cart h3 {
    margin-bottom: 0.5rem;
}

.empty-cart p {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

/* ============================================
   CUPÓN DE DESCUENTO
   ============================================ */
.coupon-section {
    background: var(--gray-50);
    padding: 1rem;
    border-radius: var(--radius-md);
    margin: 1.5rem 0;
}

.coupon-section h3 {
    font-size: 1rem;
    margin: 0 0 0.75rem 0 !important;
}

.coupon-input-group {
    display: flex;
    gap: 0.5rem;
    align-items: stretch;
}

.coupon-input-group input {
    flex: 1;
    text-transform: uppercase;
    min-width: 220px;
    min-height: 52px;
    font-size: 1rem;
    padding: 1rem 1.1rem;
}

.coupon-message {
    margin-top: 0.5rem;
    font-size: 0.9rem;
    min-height: 20px;
}

.coupon-message.success {
    color: #22c55e;
}

.coupon-message.error {
    color: #ef4444;
}

/* ============================================
   FORMULARIO
   ============================================ */
.form-section {
    margin-bottom: 1.5rem;
}

.form-row {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-strong);
}

.input-field {
    width: 100%;
    padding: 0.875rem;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius-md);
    font-size: 16px; /* Evita zoom en iOS */
    font-family: inherit;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    background: var(--white);
    color: var(--text-strong);
}

.input-field:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(189, 61, 117, 0.1);
}

.input-field.error {
    border-color: #ef4444;
}

.input-field.success {
    border-color: #22c55e;
}

.input-field:disabled {
    background: var(--gray-100);
    cursor: not-allowed;
}

.field-error {
    display: block;
    color: #ef4444;
    font-size: 0.85rem;
    margin-top: 0.25rem;
    min-height: 18px;
}

.field-success {
    display: block;
    color: #22c55e;
    font-size: 0.85rem;
    margin-top: 0.25rem;
}

/* ============================================
   BOTONES
   ============================================ */
.checkout-page .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.875rem 1.5rem;
    border: none;
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
}

.checkout-page .btn:active {
    transform: scale(0.98);
}

.checkout-page .btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.checkout-page .btn-primary {
    background: var(--primary);
    color: var(--white);
}

.checkout-page .btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.checkout-page .btn-secondary {
    background: var(--white);
    color: var(--text-strong);
    border: 2px solid var(--gray-200);
}

.checkout-page .btn-secondary:hover:not(:disabled) {
    background: var(--gray-50);
}

.checkout-page .btn-large {
    width: 100%;
    padding: 1rem 1.5rem;
    font-size: 1.1rem;
}

.step-actions {
    display: flex;
    flex-direction: column-reverse;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

/* ============================================
   SIDEBAR DE RESUMEN
   ============================================ */
.checkout-sidebar {
    background: var(--white);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.checkout-sidebar h3 {
    font-size: 1.2rem;
    margin: 0 0 1rem 0;
    color: var(--text-strong);
}

.summary-item {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--gray-100);
    font-size: 0.9rem;
}

.summary-item:last-child {
    border-bottom: none;
}

.summary-item-name {
    color: var(--text-strong);
}

.summary-item-qty {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-left: 0.5rem;
}

.summary-item-price {
    font-weight: 600;
    color: var(--text-strong);
}

.summary-details {
    margin: 1rem 0;
}

.summary-row {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    color: var(--text-muted);
    font-size: 0.95rem;
}

.summary-total {
    display: flex;
    justify-content: space-between;
    padding: 1rem 0;
    margin-top: 0.5rem;
    border-top: 2px solid var(--gray-200);
}

.total-label {
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--text-strong);
}

.total-amount {
    font-weight: 700;
    font-size: 1.5rem;
    color: var(--primary);
}

.text-success {
    color: #22c55e !important;
}

/* ============================================
   CONFIRMACIÓN
   ============================================ */
.confirmation-section {
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--gray-200);
}

.confirmation-section:last-of-type {
    border-bottom: none;
}

.confirmation-items .cart-item {
    background: var(--gray-50);
}

.shipping-address-box {
    background: var(--gray-50);
    padding: 1rem;
    border-radius: var(--radius-md);
    line-height: 1.6;
    font-size: 0.95rem;
}

.shipping-address-box p {
    margin: 0;
}

.confirmation-summary {
    background: var(--gray-50);
    padding: 1rem;
    border-radius: var(--radius-md);
}

/* ============================================
   LOADING / ESTADOS
   ============================================ */
.loading-spinner {
    border: 3px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 1rem;
}

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

.loading-container,
.redirect-container,
.error-container,
.success-container,
.failure-container,
.pending-container {
    text-align: center;
    padding: 3rem 1.5rem;
}

.loading-text {
    color: var(--text-muted);
}

/* ============================================
   SUCCESS PAGE (Checkout)
   ============================================ */
.checkout-success {
    min-height: calc(100vh - var(--navbar-height));
    padding: calc(var(--navbar-height) + 2.5rem) 1.5rem 3.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(circle at 12% 18%, rgba(242, 158, 120, 0.2), transparent 45%),
        radial-gradient(circle at 88% 12%, rgba(189, 61, 117, 0.16), transparent 45%),
        linear-gradient(180deg, #ffffff 0%, #fff5f8 100%);
    position: relative;
    overflow: hidden;
}

.checkout-success::before {
    content: "";
    position: absolute;
    inset: 10% -10% auto auto;
    width: 320px;
    height: 320px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(242, 158, 120, 0.18), transparent 70%);
    pointer-events: none;
}

.checkout-success-card {
    width: min(720px, 100%);
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 22px;
    padding: 3rem 2.5rem;
    text-align: center;
    box-shadow: 0 24px 60px rgba(17, 24, 39, 0.08), 0 10px 20px rgba(189, 61, 117, 0.12);
    position: relative;
    z-index: 1;
}

.checkout-success-icon {
    width: 84px;
    height: 84px;
    margin: 0 auto 1.25rem;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: rgba(34, 197, 94, 0.12);
}

.checkout-success-icon-svg {
    color: #22c55e;
}

.checkout-success-title {
    font-family: var(--font-display);
    font-size: clamp(2.2rem, 4vw, 3rem);
    font-weight: 400;
    color: var(--primary);
    margin-bottom: 0.75rem;
}

.checkout-success-subtitle {
    font-size: 1.1rem;
    color: var(--text-strong);
    margin-bottom: 0.5rem;
}

.checkout-success-order {
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.checkout-success-note {
    color: var(--text-muted);
    margin-bottom: 1.75rem;
}

.checkout-success-actions {
    display: flex;
    justify-content: center;
}

.checkout-success .btn-large {
    padding: 1rem 2.5rem;
    font-size: 1.05rem;
}

.checkout-success-help {
    margin-top: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    align-items: center;
    color: var(--text-muted);
    font-size: 0.95rem;
}

.checkout-success-help-text {
    margin: 0;
}

.checkout-success-link {
    color: var(--primary);
    font-weight: 600;
    text-decoration: underline;
}

.checkout-success-link:hover {
    color: var(--primary-dark, #a13464);
}

/* ============================================
   RECOVER EMAIL PAGE
   ============================================ */
.checkout-recover {
    min-height: calc(100vh - var(--navbar-height));
    padding: calc(var(--navbar-height) + 2.5rem) 1.5rem 3.5rem;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    background:
        radial-gradient(circle at 15% 18%, rgba(242, 158, 120, 0.16), transparent 45%),
        radial-gradient(circle at 88% 16%, rgba(189, 61, 117, 0.14), transparent 45%),
        linear-gradient(180deg, #ffffff 0%, #fff5f8 100%);
}

.checkout-recover-card {
    width: min(680px, 100%);
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 22px;
    padding: 2.5rem;
    box-shadow: 0 24px 60px rgba(17, 24, 39, 0.08), 0 10px 20px rgba(189, 61, 117, 0.12);
}

.checkout-recover-title {
    font-family: var(--font-display);
    font-size: clamp(1.9rem, 3vw, 2.4rem);
    font-weight: 400;
    color: var(--primary);
    margin-bottom: 0.5rem;
}

.checkout-recover-subtitle {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

.checkout-recover-form {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.checkout-recover-modal-trigger {
    background: none;
    border: none;
    color: var(--primary);
    font-weight: 600;
    margin-top: 1rem;
    cursor: pointer;
    text-decoration: underline;
    align-self: flex-start;
    padding: 0;
}

.checkout-recover-message {
    margin: 0 0 1rem 0;
    font-size: 0.95rem;
}

.checkout-recover-hint {
    margin-top: 0.35rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.checkout-recover-message.success {
    color: #16a34a;
}

.checkout-recover-message.error {
    color: #ef4444;
}

.checkout-modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    z-index: 999;
}

.checkout-modal.is-open {
    display: flex;
}

.checkout-modal-card {
    width: min(520px, 100%);
    background: #ffffff;
    border-radius: 18px;
    padding: 2rem;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.25);
}

.checkout-modal-title {
    font-size: 1.35rem;
    color: var(--text-strong);
    margin-bottom: 0.75rem;
}

.checkout-modal-list {
    margin: 0 0 1rem 1.1rem;
    color: var(--text-muted);
    line-height: 1.5;
}

.checkout-modal-note {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

@media (max-width: 640px) {
    .checkout-success-card {
        padding: 2.25rem 1.5rem;
    }

    .checkout-success-actions .btn {
        width: 100%;
    }

    .checkout-recover-card {
        padding: 2rem 1.25rem;
    }
}

/* ============================================
   RESPONSIVE - TABLET (768px+)
   ============================================ */
@media (min-width: 768px) {
    .checkout-page {
        padding: calc(var(--navbar-height, 72px) + 1.5rem) 1.5rem 1.5rem;
    }

    .checkout-steps {
        padding: 1.5rem;
        gap: 1rem;
    }

    .step-number {
        width: 36px;
        height: 36px;
        font-size: 1rem;
    }

    .step-label {
        font-size: 0.85rem;
    }

    .step-line {
        width: 60px;
    }

    .checkout-content {
        padding: 2rem;
    }

    .step-title {
        font-size: 1.75rem;
    }

    .form-row {
        flex-direction: row;
    }

    .form-row .form-group {
        flex: 1;
    }

    .step-actions {
        flex-direction: row;
        justify-content: space-between;
    }

    .step-actions .btn-secondary {
        width: auto;
        min-width: 150px;
    }

    .step-actions .btn-primary {
        width: auto;
        min-width: 200px;
    }

    .checkout-page .btn-large {
        width: auto;
        min-width: 250px;
    }
}

/* ============================================
   RESPONSIVE - MOBILE (<=600px)
   ============================================ */
@media (max-width: 600px) {
    .coupon-input-group {
        flex-direction: column;
        align-items: stretch;
    }

    .coupon-input-group .btn {
        width: 100%;
    }
}

/* ============================================
   RESPONSIVE - DESKTOP (1024px+)
   ============================================ */
@media (min-width: 1024px) {
    .checkout-page {
        padding: calc(var(--navbar-height, 72px) + 2rem) 2rem 2rem;
    }

    .checkout-container {
        max-width: 1200px;
        margin: 0 auto;
    }

    .checkout-layout {
        flex-direction: row;
        align-items: flex-start;
    }

    .checkout-content {
        flex: 1;
        order: 1;
    }

    .checkout-sidebar {
        width: 350px;
        flex-shrink: 0;
        position: sticky;
        top: calc(var(--navbar-height, 72px) + 1rem);
        order: 2;
    }

    .checkout-steps {
        gap: 1.5rem;
    }

    .step-number {
        width: 40px;
        height: 40px;
    }

    .step-label {
        font-size: 0.9rem;
    }

    .step-line {
        width: 80px;
    }
}

/* ============================================
   ACCESIBILIDAD
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus visible para navegación con teclado */
.checkout-page .btn:focus-visible,
.checkout-page .input-field:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}
