/**
 * CUPON MANAGER - Frontend Styles
 * COMPLETAMENTE REESCRITO DESDE CERO
 * Diseño limpio, simple y funcional
 */

/* ===== RESET Y BASE ===== */
.cupon-manager-container {
    padding: 20px 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    max-width: 1200px;
    margin: 0 auto;
}

.cupon-manager-container * {
    box-sizing: border-box;
}

/* ===== GRID PRINCIPAL ===== */
.cupon-manager-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(500px, 1fr));
    gap: 24px;
    margin: 20px auto;
    width: 100%;
    justify-content: center;
}

/* Vista en lista */
.cupon-manager-grid.list-view {
    grid-template-columns: 1fr;
    max-width: 600px;
}

/* ===== CONTENEDOR DEL CUPÓN ===== */
.cupon-manager-item {
    width: 100%;
    height: 340px;
    min-width: 500px;
    max-width: 600px;
    margin: 0 auto;
    perspective: 1000px;
    -webkit-perspective: 1000px;
    -moz-perspective: 1000px;
    cursor: pointer;
    position: relative;
    border-radius: 12px;
    background: transparent;
}

/* Contenedor interno para el efecto 3D */
.cupon-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.6s ease-in-out;
    transform-style: preserve-3d;
    -webkit-transform-style: preserve-3d;
    -moz-transform-style: preserve-3d;
    transform: rotateY(0deg);
}

/* Estado volteado */
.cupon-manager-item.flipped .cupon-inner {
    transform: rotateY(180deg);
}

/* Asegurar que las caras se muestren correctamente */
.cupon-manager-item.flipped .cupon-front {
    z-index: 1;
}

.cupon-manager-item.flipped .cupon-back {
    z-index: 2;
}

/* ===== CARAS DEL CUPÓN ===== */
.cupon-front,
.cupon-back {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    -moz-backface-visibility: hidden;
    
    /* Layout horizontal */
    display: flex;
    flex-direction: row;
    align-items: stretch;
    
    /* Efectos visuales */
    border-radius: 12px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    
    /* Forzar aceleración por hardware */
    will-change: transform;
    
    /* Prevenir selección de texto */
    user-select: none;
    -webkit-user-select: none;
}

/* Cara frontal - posición inicial */
.cupon-front {
    transform: rotateY(0deg);
    z-index: 2;
}

/* Cara trasera - rotada 180 grados */
.cupon-back {
    transform: rotateY(180deg);
    z-index: 1;
}

/* ===== SECCIÓN IMAGEN ===== */
.cupon-image-section {
    width: 120px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 15px;
    background: rgba(0, 0, 0, 0.1);
    position: relative;
}

.cupon-image {
    width: 90px;
    height: 90px;
    object-fit: cover;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    background: rgba(255, 255, 255, 0.1);
}

/* Placeholder cuando no hay imagen */
.cupon-image-section.no-image {
    background: linear-gradient(135deg, rgba(255,255,255,0.1), rgba(255,255,255,0.05));
}

.cupon-image-section.no-image::before {
    content: '🎫';
    font-size: 32px;
    opacity: 0.3;
}

/* ===== SECCIÓN CONTENIDO ===== */
.cupon-content-section {
    flex: 1;
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    color: white;
    position: relative;
    height: 100%;
}

.cupon-title {
    margin: 0 0 12px 0;
    font-size: 22px;
    font-weight: bold;
    line-height: 1.2;
    color: white;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.4);
    word-wrap: break-word;
}

.cupon-text-content {
    margin: 8px 0;
    font-size: 14px;
    line-height: 1.4;
    color: rgba(255, 255, 255, 0.95);
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
    word-wrap: break-word;
}

.cupon-validity-info {
    margin-top: 12px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    display: inline-block;
    max-width: fit-content;
}

.cupon-validity-info.expiring-soon {
    background: rgba(255, 193, 7, 0.25);
    border-color: rgba(255, 193, 7, 0.4);
    animation: pulse-warning 2s infinite;
}

@keyframes pulse-warning {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.8; }
}

/* ===== INDICADOR DE FLIP ===== */
.cupon-flip-indicator {
    position: absolute;
    bottom: 16px;
    right: 16px;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 20px;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    transition: all 0.3s ease;
    pointer-events: none;
    z-index: 10;
    white-space: nowrap;
}

/* ===== FRANJA MOBILE PARA FLIP ===== */
.cupon-mobile-flip-strip {
    position: absolute;
    top: 0;
    right: 0;
    width: 32px;
    height: 100%;
    background: rgba(0, 0, 0, 0.15);
    backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    border-top-right-radius: 12px;
    border-bottom-right-radius: 12px;
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 15;
    pointer-events: auto;
}

.cupon-mobile-flip-strip:hover {
    background: rgba(0, 0, 0, 0.25);
    width: 36px;
}

.cupon-mobile-flip-strip:active,
.cupon-mobile-flip-strip.strip-clicking {
    background: rgba(0, 0, 0, 0.35);
    transform: scale(0.98);
}

.cupon-mobile-flip-strip .flip-icon {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: rgba(255, 255, 255, 0.9);
    transition: transform 0.3s ease;
}

.cupon-mobile-flip-strip .flip-icon svg {
    width: 16px;
    height: 16px;
    margin-bottom: 2px;
    transition: transform 0.3s ease;
}

.cupon-mobile-flip-strip .flip-text {
    font-size: 8px;
    font-weight: 500;
    writing-mode: vertical-lr;
    text-orientation: mixed;
    letter-spacing: 0.5px;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}

.cupon-mobile-flip-strip:hover .flip-icon {
    transform: scale(1.1);
}

.cupon-mobile-flip-strip:hover .flip-icon svg {
    transform: rotate(180deg);
}

/* Ocultar franja en el dorso */
.cupon-back .cupon-mobile-flip-strip {
    display: none !important;
}

.cupon-flip-indicator svg {
    width: 12px;
    height: 12px;
    transition: transform 0.3s ease;
}

/* Ocultar indicador en el dorso */
.cupon-back .cupon-flip-indicator {
    display: none;
}

/* ===== EFECTOS HOVER ===== */
.cupon-manager-item:hover {
    transform: translateY(-2px);
    transition: transform 0.3s ease;
}

.cupon-manager-item:hover .cupon-front,
.cupon-manager-item:hover .cupon-back {
    box-shadow: 0 12px 35px rgba(0, 0, 0, 0.2);
}

.cupon-manager-item:hover .cupon-flip-indicator {
    background: rgba(0, 0, 0, 0.7);
    transform: scale(1.05);
}

.cupon-manager-item:hover .cupon-flip-indicator svg {
    transform: rotate(90deg);
}

/* ===== BACKGROUNDS POR DEFECTO ===== */
.cupon-front {
    background: linear-gradient(135deg, #4285F4 0%, #669DF6 100%);
}

.cupon-back {
    background: linear-gradient(135deg, #0F9D58 0%, #34A853 100%);
}

/* ===== FILTROS ===== */
.coupon-filters {
    margin-bottom: 20px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e9ecef;
}

.coupon-filter {
    padding: 8px 12px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    background: white;
    font-size: 14px;
    margin-right: 10px;
}

/* ===== RESPONSIVE DESIGN ===== */

/* Tablet */
@media (max-width: 1024px) {
    .cupon-manager-grid {
        grid-template-columns: 1fr;
        gap: 20px;
        max-width: 500px;
    }
    
    .cupon-manager-item {
        height: 260px;
        min-width: 400px;
        max-width: 480px;
    }
    
    .cupon-inner {
        height: 260px;
    }
    
    .cupon-front, .cupon-back {
        height: 260px;
    }
    
    .cupon-image-section {
        width: 100px;
        padding: 12px;
    }
    
    .cupon-image {
        width: 76px;
        height: 76px;
    }
    
    .cupon-content-section {
        padding: 16px;
    }
    
    .cupon-title {
        font-size: 20px;
        margin-bottom: 10px;
    }
    
    .cupon-text-content {
        font-size: 13px;
    }
    
    .cupon-flip-indicator {
        bottom: 12px;
        right: 12px;
        font-size: 10px;
        padding: 3px 10px;
    }
}

/* Mobile */
@media (max-width: 768px) {
    .cupon-manager-grid {
        grid-template-columns: 1fr;
        gap: 16px;
        max-width: 100%;
        padding: 0 10px;
    }
    
    .cupon-manager-item {
        height: 220px !important;
        min-width: 320px;
        max-width: 100%;
    }
    
    .cupon-inner {
        height: 220px !important;
    }
    
    .cupon-front, .cupon-back {
        height: 220px !important;
    }
    
    .cupon-image-section {
        width: 90px;
        padding: 10px;
    }
    
    .cupon-image {
        width: 70px;
        height: 70px;
    }
    
    .cupon-content-section {
        padding: 12px;
        padding-right: 40px; /* Espacio para la franja móvil */
    }
    
    .cupon-title {
        font-size: 18px;
        margin-bottom: 8px;
    }
    
    .cupon-text-content {
        font-size: 12px;
    }
    
    /* Ocultar indicador tradicional en mobile */
    .cupon-flip-indicator {
        display: none !important;
    }
    
    /* Mostrar franja móvil */
    .cupon-mobile-flip-strip {
        display: flex !important;
    }
    
    .coupon-filters {
        text-align: center;
    }
    
    .coupon-filter {
        display: block;
        width: 100%;
        margin: 5px 0;
    }
}

/* Mobile pequeño */
@media (max-width: 480px) {
    .cupon-manager-container {
        padding: 15px 5px;
    }
    
    .cupon-manager-grid {
        gap: 12px;
        padding: 0 5px;
    }
    
    .cupon-manager-item {
        height: 200px !important;
        min-width: 300px;
        max-width: 100%;
    }
    
    .cupon-inner {
        height: 200px !important;
    }
    
    .cupon-front, .cupon-back {
        height: 200px !important;
    }
    
    .cupon-image-section {
        width: 80px;
        padding: 8px;
    }
    
    .cupon-image {
        width: 64px;
        height: 64px;
    }
    
    .cupon-content-section {
        padding: 10px;
        padding-right: 35px; /* Espacio ajustado para mobile pequeño */
    }
    
    .cupon-title {
        font-size: 16px;
        margin-bottom: 6px;
        line-height: 1.1;
    }
    
    .cupon-text-content {
        font-size: 11px;
        line-height: 1.3;
    }
    
    /* Franja móvil más pequeña para mobile pequeño */
    .cupon-mobile-flip-strip {
        width: 28px;
    }
    
    .cupon-mobile-flip-strip:hover {
        width: 32px;
    }
    
    .cupon-mobile-flip-strip .flip-icon svg {
        width: 14px;
        height: 14px;
    }
    
    .cupon-mobile-flip-strip .flip-text {
        font-size: 7px;
    }
}

/* ===== LOADING STATES ===== */
.cupon-manager-item {
    opacity: 0;
    transform: translateY(20px);
    animation: couponFadeIn 0.6s ease forwards;
}

.cupon-manager-item:nth-child(1) { animation-delay: 0.1s; }
.cupon-manager-item:nth-child(2) { animation-delay: 0.2s; }
.cupon-manager-item:nth-child(3) { animation-delay: 0.3s; }
.cupon-manager-item:nth-child(4) { animation-delay: 0.4s; }
.cupon-manager-item:nth-child(n+5) { animation-delay: 0.5s; }

@keyframes couponFadeIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== LAZY LOADING ===== */
.cupon-back img[data-src] {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.cupon-back img[src] {
    opacity: 1;
}

/* ===== MENSAJES ===== */
.cupon-manager-message {
    padding: 15px;
    background: #f8f9fa;
    border-left: 4px solid #007cba;
    margin: 20px 0;
    border-radius: 4px;
}

.cupon-manager-error {
    padding: 15px;
    background: #f8d7da;
    border-left: 4px solid #dc3545;
    margin: 20px 0;
    color: #721c24;
    border-radius: 4px;
}

/* ===== ACCESIBILIDAD ===== */
.cupon-manager-item:focus {
    outline: none;
}

.cupon-manager-item:focus-visible {
    outline: 2px solid #007cba;
    outline-offset: 2px;
}

/* Mejorar contraste para lectores de pantalla */
@media (prefers-contrast: high) {
    .cupon-title,
    .cupon-text-content {
        text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    }
}

/* Reducción de movimiento */
@media (prefers-reduced-motion: reduce) {
    .cupon-inner {
        transition: transform 0.3s ease !important;
    }
    
    .cupon-manager-item:hover {
        transform: none !important;
    }
    
    .cupon-validity-info.expiring-soon {
        animation: none !important;
    }
}

/* ===== PERFORMANCE ===== */
.cupon-manager-item,
.cupon-inner,
.cupon-front,
.cupon-back {
    will-change: transform;
}

.cupon-manager-item.animating {
    pointer-events: none;
}