/* ==========================================================================
   SISTEMA DE DISEÑO (Variables globales para mantener uniformidad)
   ========================================================================== */
:root {
    /* Paleta de colores - Tema Claro en Tonos Azules */
    --bg-pagina: #eff6ff;           /* Azul hielo muy suave para el fondo */
    --bg-tarjeta: #ffffff;          /* Blanco puro para tarjetas y contenedores */
    --bg-suave: #f8fafc;            /* Gris azulado para cajas internas */
    
    --azul-primario: #2563eb;       /* Azul vibrante para acciones principales */
    --azul-hover: #1d4ed8;          /* Azul más intenso al pasar el mouse */
    --azul-oscuro: #0e1936;         /* Azul marino para títulos */
    --azul-claro-borde: #bfdbfe;    /* Borde azul sutil */
    
    --texto-principal: #0f172a;     /* Azul noche casi negro para lectura cómoda */
    --texto-secundario: #475569;    /* Gris pizarra para subtítulos */
    --borde-neutral: #cbd5e1;       /* Borde estándar de elementos */
    --peligro: #dc2626;             /* Rojo para eliminar sillas o errores */

    /* Estándares visuales uniformes para todos los bloques */
    --radio-tarjeta: 16px;
    --radio-boton: 10px;
    --sombra-tarjeta: 0 10px 25px -5px rgba(30, 58, 138, 0.08), 0 4px 10px -2px rgba(30, 58, 138, 0.04);
}

/* ==========================================================================
   RESET Y REGLAS BASE
   ========================================================================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Garantiza que el atributo HTML 'hidden' siempre gane sobre display: grid/flex */
[hidden] {
    display: none !important;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-pagina);
    color: var(--texto-principal);
    line-height: 1.5;
    min-height: 100vh;
}

/* ==========================================================================
   BLOQUE 1: LAYOUT PRINCIPAL (#vista-teatro)
   ========================================================================== */
#vista-teatro {
    max-width: 1200px;
    margin: 0 auto;
    display: grid;
    /* Columna izquierda flexible para el mapa SVG, columna derecha fija de 350px para el carrito */
    grid-template-columns: 1fr 350px;
    gap: 1.5rem 2rem;
    align-items: start;
    padding: 1rem;
}

/* El título y subtítulo ocupan todo el ancho superior (ambas columnas) */
#vista-teatro > h1 {
    grid-column: 1 / -1;
    text-align: left;
    color: var(--azul-oscuro);
    font-size: 2.25rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    text-transform: uppercase;
}

#vista-teatro > p {
    grid-column: 1 / -1;
    text-align: left;
    color: var(--texto-secundario);
    font-size: 1.05rem;
    margin-top: -1rem;
    margin-bottom: 0.5rem;
}

/* Lienzo del Mapa SVG */
#mapaTeatro {
    width: 100%;
    height: auto;
    display: block;
    background-color: var(--bg-tarjeta);
    border-radius: var(--radio-tarjeta);
    border: 1px solid var(--azul-claro-borde);
    box-shadow: var(--sombra-tarjeta);
    cursor: grab;
}

#mapaTeatro:active {
    cursor: grabbing;
}

#mapaTeatro [data-asiento] {
    transform-box: fill-box;      /* Toma la propia caja de la silla como referencia */
    transform-origin: center;     /* Crece desde su propio centro sin desplazarse */
    transition: transform 0.18s ease, filter 0.18s ease;
}

/* Sillas disponibles: crecen suavemente y muestran manito */
#mapaTeatro [data-asiento]:not(.vendido) {
    cursor: pointer;
}

#mapaTeatro [data-asiento]:not(.vendido):hover {
    transform: scale(1.28);
    filter: brightness(1.1);
}

/* Sillas ya vendidas: no crecen y muestran cursor de bloqueado */
#mapaTeatro [data-asiento].vendido {
    cursor: not-allowed;
}

/* Responsividad: En pantallas menores a 880px, el carrito baja debajo del mapa */
@media (max-width: 880px) {
    #vista-teatro {
        grid-template-columns: 1fr;
    }
}

/* ==========================================================================
   BLOQUE 2: PANEL LATERAL DEL CARRITO (.lista-carrito)
   ========================================================================== */
.lista-carrito {
    background-color: var(--bg-tarjeta);
    border-radius: var(--radio-tarjeta);
    border: 1px solid var(--azul-claro-borde);
    box-shadow: var(--sombra-tarjeta);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.lista-carrito h3 {
    color: var(--azul-oscuro);
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid var(--bg-pagina);
    text-transform: uppercase;
}

/* Lista dinámica de sillas seleccionadas */
#sillas-agregadas {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    max-height: 300px;
    overflow-y: auto; /* Permite hacer scroll si seleccionan muchas sillas */
    padding-right: 0.25rem;
}

/* Mensaje limpio si aún no hay sillas en la lista */
#sillas-agregadas:empty::before {
    content: "Aún no has seleccionado sillas en el mapa.";
    color: var(--texto-secundario);
    font-size: 0.9rem;
    font-style: italic;
    text-align: center;
    padding: 1.5rem 0.5rem;
    display: block;
}

/* Cada fila <li> creada por dibujarCarrito() en teatro.js */
#sillas-agregadas li {
    background-color: var(--bg-suave);
    border: 1px solid var(--borde-neutral);
    border-radius: 8px;
    padding: 0.65rem 0.85rem;
    font-size: 0.95rem;
    font-weight: 500;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}

/* Botón 'X' para eliminar individualmente una silla */
#sillas-agregadas li button {
    background-color: #fee2e2;
    color: var(--peligro);
    border: none;
    border-radius: 6px;
    width: 26px;
    height: 26px;
    font-weight: 700;
    font-size: 0.85rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease, color 0.2s ease;
}

#sillas-agregadas li button:hover {
    background-color: var(--peligro);
    color: #ffffff;
}

/* Zona inferior del total y botón Comprar */
.resumen {
    border-top: 2px solid var(--bg-pagina);
    padding-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.resumen p {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1.05rem;
    color: var(--texto-secundario);
    text-transform: capitalize;
}

#pago-total {
    color: var(--azul-oscuro);
    font-size: 1.4rem;
    font-weight: 800;
}

/* Botón principal "Comprar" */
#comprar {
    width: 100%;
    background-color: var(--azul-primario);
    color: #ffffff;
    border: none;
    border-radius: var(--radio-boton);
    padding: 0.85rem 1.25rem;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
}

#comprar:hover {
    background-color: var(--azul-hover);
}

#comprar:active {
    transform: scale(0.98);
}

/* ==========================================================================
   BLOQUE 3: MODAL DE VALIDACIÓN DE CORREO (<dialog id="modal-checkout">)
   ========================================================================== */
#modal-checkout {
    /* Centrado perfecto para elementos <dialog> nativos */
    margin: auto;
    width: 90%;
    max-width: 440px;
    background-color: var(--bg-tarjeta);
    color: var(--texto-principal);
    border: 1px solid var(--azul-claro-borde);
    border-radius: var(--radio-tarjeta);
    box-shadow: 0 20px 35px -10px rgba(15, 23, 42, 0.25);
    padding: 2rem;
}

/* Fondo oscuro y difuminado detrás del modal cuando se abre con .showModal() */
#modal-checkout::backdrop {
    background-color: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(4px);
}

#modal-checkout h2 {
    color: var(--azul-oscuro);
    font-size: 1.5rem;
    font-weight: 800;
    margin-bottom: 0.4rem;
}

#modal-checkout > p {
    color: var(--texto-secundario);
    font-size: 0.95rem;
    margin-bottom: 1.5rem;
}

/* Estructura del formulario */
#form-checkout {
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
}

/* Grupos de label + input */
#form-checkout > div:not(:last-child) {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

#form-checkout label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--texto-principal);
}

#form-checkout input[type="email"] {
    width: 100%;
    padding: 0.75rem 0.95rem;
    font-size: 0.95rem;
    color: var(--texto-principal);
    background-color: var(--bg-suave);
    border: 1.5px solid var(--borde-neutral);
    border-radius: 8px;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}
#form-checkout input[type="text"] {
    width: 100%;
    padding: 0.75rem 0.95rem;
    font-size: 0.95rem;
    color: var(--texto-principal);
    background-color: var(--bg-suave);
    border: 1.5px solid var(--borde-neutral);
    border-radius: 8px;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

#form-checkout input[type="email"]:focus {
    background-color: var(--bg-tarjeta);
    border-color: var(--azul-primario);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

/* Mensaje de error cuando los correos no coinciden */
#mensaje-error {
    color: var(--peligro);
    background-color: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 8px;
    padding: 0.6rem 0.85rem;
    font-size: 0.88rem;
    font-weight: 600;
}

/* Ocultamos automáticamente la caja roja cuando no hay texto de error */
#mensaje-error:empty {
    display: none;
}

/* Contenedor de botones del modal (Cancelar / Confirmar y Pagar) */
#form-checkout > div:last-child {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

#btn-cancelar,
#form-checkout button[type="submit"] {
    padding: 0.75rem 1.2rem;
    font-size: 0.95rem;
    font-weight: 700;
    border-radius: var(--radio-boton);
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
}

#btn-cancelar {
    background-color: var(--bg-suave);
    color: var(--texto-secundario);
    border: 1px solid var(--borde-neutral);
}

#btn-cancelar:hover {
    background-color: #e2e8f0;
    color: var(--texto-principal);
}

#form-checkout button[type="submit"] {
    background-color: var(--azul-primario);
    color: #ffffff;
    border: none;
}

#form-checkout button[type="submit"]:hover {
    background-color: var(--azul-hover);
}

#btn-cancelar:active,
#form-checkout button[type="submit"]:active {
    transform: scale(0.98);
}

/* ==========================================================================
   BLOQUE 4: PANTALLA DE RESUMEN, MÉTODO DE PAGO Y QR (#vista-pago)
   ========================================================================== */
#vista-pago {
    max-width: 580px;
    margin: 10px auto;
    background-color: var(--bg-tarjeta);
    border: 1px solid var(--azul-claro-borde);
    border-radius: var(--radio-tarjeta);
    box-shadow: var(--sombra-tarjeta);
    padding: 2.25rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

#vista-pago h2 {
    color: var(--azul-oscuro);
    font-size: 1.65rem;
    font-weight: 800;
    text-align: center;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--bg-pagina);
}

/* Caja interna con correo, lista de sillas y total */
#datos-compra {
    background-color: var(--bg-suave);
    border: 1px solid var(--borde-neutral);
    border-radius: 12px;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

#datos-compra h3 {
    font-size: 0.95rem;
    color: var(--texto-secundario);
    margin-top: 0.25rem;
}

#resumen-sillas {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

#resumen-sillas li {
    background-color: var(--bg-tarjeta);
    border: 1px solid var(--borde-neutral);
    border-radius: 6px;
    padding: 0.5rem 0.75rem;
    font-size: 0.92rem;
    font-weight: 500;
}

/* Fila destacada del total a pagar */
#datos-compra > p:last-child {
    margin-top: 0.5rem;
    padding-top: 0.75rem;
    border-top: 1px dashed var(--borde-neutral);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1.1rem;
}

#resumen-total {
    color: var(--azul-primario);
    font-size: 1.45rem;
    font-weight: 800;
}

/* Grupo de Radio Buttons estilizados como tarjetas clicables */
#opciones-pago {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

#opciones-pago > p {
    color: var(--azul-oscuro);
    font-size: 1rem;
    margin-bottom: 0.2rem;
}

#opciones-pago label {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    background-color: var(--bg-suave);
    border: 1.5px solid var(--borde-neutral);
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.2s ease, background-color 0.2s ease;
}

#opciones-pago label:hover {
    border-color: var(--azul-primario);
    background-color: var(--bg-pagina);
}

/* Resalta automáticamente la tarjeta cuando su radio interno está marcado */
#opciones-pago label:has(input[type="radio"]:checked) {
    border-color: var(--azul-primario);
    background-color: var(--bg-pagina);
    color: var(--azul-oscuro);
}

#opciones-pago input[type="radio"] {
    accent-color: var(--azul-primario);
    width: 18px;
    height: 18px;
    cursor: pointer;
}

/* Bloque generado con el código REF, QR y cronómetro regresivo */
#bloque-qr {
    background-color: var(--bg-pagina);
    border: 2px dashed var(--azul-primario);
    border-radius: 14px;
    padding: 1.5rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

#codigo-referencia {
    color: var(--azul-oscuro);
    font-family: monospace;
    font-size: 1.15rem;
    background-color: var(--bg-tarjeta);
    padding: 0.2rem 0.6rem;
    border-radius: 6px;
    border: 1px solid var(--azul-claro-borde);
}

#valor-qr {
    color: var(--azul-primario);
    font-size: 1.2rem;
    font-weight: 800;
}

#imagen-qr {
    background-color: #ffffff;
    padding: 0.75rem;
    border-radius: 12px;
    border: 1px solid var(--azul-claro-borde);
    box-shadow: 0 4px 12px rgba(30, 58, 138, 0.08);
    margin: 0.4rem 0;
}

/* Cronómetro regresivo */
#temporizador {
    color: var(--peligro);
    font-size: 1.15rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums; /* Evita que el texto brinque al cambiar los números */
}

/* Botones de acción de la vista de pago */
#vista-pago > div:last-child {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 0.5rem;
}

#btn-volver,
#btn-confirmar-pago,
#btn-finalizar-pago {
    padding: 0.85rem 1.35rem;
    font-size: 0.98rem;
    font-weight: 700;
    border-radius: var(--radio-boton);
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
}

#btn-volver {
    background-color: var(--bg-suave);
    color: var(--texto-secundario);
    border: 1px solid var(--borde-neutral);
}

#btn-volver:hover {
    background-color: #e2e8f0;
    color: var(--texto-principal);
}

#btn-confirmar-pago,
#btn-finalizar-pago {
    background-color: var(--azul-primario);
    color: #ffffff;
    border: none;
    flex: 1;
}

#btn-confirmar-pago:hover,
#btn-finalizar-pago:hover {
    background-color: var(--azul-hover);
}

#btn-finalizar-pago {
    width: 100%;
    margin-top: 0.5rem;
}

#btn-volver:active,
#btn-confirmar-pago:active,
#btn-finalizar-pago:active {
    transform: scale(0.98);
}
