﻿/* ==========================================================================
   Variables y Estilos de Base
   ========================================================================== */
body {
    font-family: Arial, Helvetica, sans-serif;
    background: #f5f5f5;
    color: #222;
    margin: 0;
    padding: clamp(12px, 3vw, 32px);
    line-height: 1.5;
}

/* Contenedor principal de la "página" (Factura o Formulario) */
.page {
    max-width: 900px;
    margin: 0 auto;
    background: #fff;
    padding: clamp(20px, 6vw, 60px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    border-radius: 6px;
    min-height: 450px; /* Evita colapsos visuales durante la carga */
}

/* ==========================================================================
   Cabecera (Logo + Títulos) - Solución al "salto" del logo
   ========================================================================== */
.page-header {
    display: flex;
    justify-content: flex-start;
    align-items: flex-start; /* Alineación arriba para estabilidad */
    gap: clamp(10px, 4vw, 30px);
    margin-bottom: 2vw;
}

.logo {
    /* Dimensiones fijas con clamp para reservar espacio en el DOM */
    width: clamp(80px, 20vw, 200px);
    aspect-ratio: 1 / 1; /* Reserva el hueco cuadrado antes de cargar la imagen */
    object-fit: contain;
    flex-shrink: 0; /* Impide que el logo se aplaste */
    display: block;
}

.page-header-info {
    flex: 1;
    min-width: 0; /* Permite que el truncado de texto funcione */
}

.page-header h1 {
    margin: 0;
    /* Reducimos ligeramente el tamaño máximo y el escalado para que sea más reactivo */
    font-size: clamp(1.1rem, 3.2vw, 1.6rem);
    border-bottom: 2px solid #222;
    padding-bottom: 8px;
    margin-bottom: clamp(8px, 2vw, 24px);
    /* ¡Adiós al nowrap que rompía el flujo antes de los 600px! */
    white-space: normal;
    line-height: 1.2;
    word-wrap: break-word;
}

.page-header-meta div {
    font-size: clamp(12px, 2.2vw, 18px);
    margin-bottom: clamp(6px, 1.2vw, 12px);
}

.tituloPagina {
    text-align: center;
    border-top: 1px solid #ddd;
    border-bottom: 1px solid #ddd;
    margin-top: clamp(10px, 3vw, 20px);
    margin-bottom: clamp(15px, 4vw, 30px);
    padding: clamp(10px, 2.5vw, 20px) 0;
    font-size: clamp(1.1rem, 3.5vw, 0.6rem);
    font-weight: bold;
    color: #333;
    word-wrap: break-word;
    line-height: 1.2;
    text-transform: uppercase;
}

.hidden, .loading {
    display: none !important;
}

/* ==========================================================================
   Tablas de Facturación
   ========================================================================== */
.invoice-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 3vw;
}

    .invoice-table th,
    .invoice-table td {
        padding: clamp(8px, 1.2vw, 16px);
        border-bottom: 1px solid #e6e6e6;
        font-size: clamp(12px, 2.2vw, 16px);
    }

    .invoice-table th {
        text-align: right;
        background: #fafafa;
        font-weight: bold;
    }

/* Estilo por defecto para pantallas grandes */
.invoice-num-wrapper {
    display: inline; /* Se mantiene en la misma línea */
}

.right {
    text-align: right;
}

/* Alineación específica por columnas */
.vat-base, .vat-rate, .vat-amount, .vat-total {
    text-align: right;
}

/* Totales */
.invoice-totals {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    margin-top: 2vw;
}

    .invoice-totals div {
        font-size: clamp(14px, 2.4vw, 20px);
    }

.grand-total {
    border: 1px solid #222;
    padding: 15px 25px;
    margin-top: 15px;
    font-size: clamp(1.2rem, 4vw, 2rem) !important;
    font-weight: bold;
}

/* ==========================================================================
   Formularios (Mis Datos Fiscales)
   ========================================================================== */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

    .form-group.full-width {
        grid-column: span 2;
    }

    .form-group label {
        font-weight: bold;
        font-size: 14px;
    }

    .form-group input {
        padding: 12px;
        border: 1px solid #ccc;
        border-radius: 4px;
        font-size: 16px;
    }

    .form-group select {
        padding: 12px;
        border: 1px solid #ccc;
        border-radius: 4px;
        font-size: 16px;
        background-color: #fff;
        font-family: inherit;
        color: #222;
        width: 100%;
        cursor: pointer;
        /* Eliminar apariencia nativa para consistencia total */
        appearance: none;
        -webkit-appearance: none;
        -moz-appearance: none;
        /* Icono de flecha personalizada (SVG) */
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'%3E%3C/path%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 12px center;
        background-size: 14px;
        padding-right: 40px; /* Espacio para que el texto no pise la flecha */
    }

        /* Estado de enfoque (Focus) */
        .form-group select:focus,
        .form-group input:focus {
            outline: none;
            border-color: #0056b3; /* Azul BDP */
            box-shadow: 0 0 0 3px rgba(0, 86, 179, 0.1);
        }

/* ==========================================================================
   Ajustes para Pantallas Móviles
   ========================================================================== */
@media (max-width: 600px) {
    .form-grid {
        grid-template-columns: 1fr;
    }

    .form-group.full-width {
        grid-column: span 1;
    }

    .form-group select {
        font-size: 16px; /* Evita el zoom automático en iOS */
    }

    .page {
        /* Reducimos drásticamente el espacio blanco superior de la factura */
        padding-top: 15px;
    }

    .page-header {
        flex-direction: column;
        align-items: center;
        text-align: center;
        /* Reducimos al mínimo el espacio entre el logo y el texto "Fct. Simplificada" */
        gap: 15px;
        margin-bottom: 15px;
    }

    .logo {
        width: 180px;
        aspect-ratio: auto;
        margin: 0;
        border-radius: 8px;
    }

    .page-header-info {
        width: 100%;
    }

    .page-header h1 {
        white-space: normal;
        line-height: 1.2;
        font-size: 1.4rem;
        margin-bottom: 5px; /* Pegamos el título a la línea divisoria */
    }

    .invoice-num-wrapper {
        display: block;
        margin-top: 4px;
        font-weight: bold;
        word-break: break-all;
    }
}

/* ==========================================================================
   Acciones y Botones
   ========================================================================== */
/* Contenedor de las acciones en el pie del formulario */
.form-actions {
    display: flex;
    gap: 15px;
    margin-top: 30px;
    padding: 20px;
    background: #f9f9f9;
    border-radius: 0 0 8px 8px; /* Redondeado para encajar con el diseño */
}

/* 1. ESTILOS BASE (Comunes a todos los botones) */
.btn-step, .btn-final, .btn-back {
    padding: 15px 25px;
    border-radius: 4px;
    font-weight: bold;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.3s ease;
    flex: 1; /* Se estiran para ocupar todo el ancho disponible */
    text-align: center;
    border: none;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    text-decoration: none;
}

/* 2. BOTÓN PASO 1 (Navegación: "Rellenar Datos") */
.btn-step {
    background-color: #0056b3; /* Azul BDP Original */
    color: white;
    border-bottom: 3px solid #003d80; /* Sutil relieve de acción */
}

    .btn-step:hover {
        background-color: #004494;
        transform: translateY(-1px);
        box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    }

/* 3. BOTÓN PASO 2 (Crítico: "Generar Factura") */
.btn-final {
    /* Verde Esmeralda Oscuro: Indica éxito y cierre legal */
    background-color: #1e8449;
    color: white;
    border-bottom: 3px solid #145a32; /* Relieve que indica importancia */
}

    .btn-final:hover {
        background-color: #27ae60;
        transform: translateY(-1px);
        box-shadow: 0 4px 12px rgba(30, 132, 73, 0.3);
    }

/* 4. BOTÓN VOLVER (Retroceder) */
.btn-back {
    background-color: #ffffff;
    color: #555;
    border: 2px solid #bdc3c7; /* Gris metálico claro */
    box-sizing: border-box; /* Para que el borde no afecte al tamaño */
}

    .btn-back:hover {
        background-color: #f2f2f2;
        border-color: #95a5a6;
        color: #333;
    }

    /* Efecto al presionar cualquier botón */
    .btn-step:active, .btn-final:active, .btn-back:active {
        transform: translateY(2px);
        border-bottom-width: 0;
        margin-bottom: 3px; /* Compensa la pérdida del borde inferior */
    }

/* ==========================================================================
   Loader y Estados
   ========================================================================== */
.loader {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(255,255,255,0.98);
    padding: 20px 30px;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.15);
    z-index: 9999;
}

    .loader.hidden, .template, .hidden {
        display: none !important;
    }

.loader-spinner {
    width: 30px;
    height: 30px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #0056b3;
    border-radius: 50%;
    animation: loader-spin 1s linear infinite;
}

.loader-text {
    font-size: 16px;
    font-weight: bold;
    color: #333;
}

/* El nuevo Overlay */
.loader-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5); /* Mismo tono que el alert */
    backdrop-filter: blur(8px); /* Mismo desenfoque que el alert */
    z-index: 9998; /* Justo debajo del loader (9999) */
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease;
}

    .loader-overlay.active {
        opacity: 1;
        visibility: visible;
    }

@keyframes loader-spin {
    to {
        transform: rotate(360deg);
    }
}

/* Errores */
.message-error {
    text-align: center;
    color: #c70e0e;
    background: #fff1f1;
    padding: 20px;
    border: 1px solid #ecb3b3;
    border-radius: 4px;
    font-weight: bold;
}



/* Contenedor principal */
.alert-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.25s ease;
}

    .alert-overlay.active {
        opacity: 1;
        visibility: visible;
    }

/* Tarjeta */
.alert-card {
    background: white;
    padding: 2rem;
    border-radius: 12px;
    width: 90%;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    transform: scale(0.9);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.alert-overlay.active .alert-card {
    transform: scale(1);
}

.alert-icon {
    width: 60px;
    height: 60px;
    margin: 0 auto 1rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
}

.alert-title {
    color: #1e3a8a;
    margin: 0 0 0.5rem;
    font-family: sans-serif;
}

.alert-msg {
    color: #64748b;
    font-family: sans-serif;
    line-height: 1.5;
    margin-bottom: 0;
}

.alert-btn {
    width: 100%;
    padding: 0.75rem;
    border: none;
    border-radius: 6px;
    font-weight: bold;
    cursor: pointer;
    color: white;
    margin-top: 1.5rem;
}

/* Variantes de estado */
.alert-success .alert-icon {
    background: #e8f5e9;
    color: #2e7d32;
}

.alert-success .alert-btn {
    background: #2e7d32;
}

.alert-error .alert-icon {
    background: #ffebee;
    color: #c62828;
}

.alert-error .alert-btn {
    background: #c62828;
}

.alert-warning .alert-icon {
    background: #fff8e1;
    color: #f9a825;
}

.alert-warning .alert-btn {
    background: #f9a825;
}

.alert-info .alert-icon {
    background: #e3f2fd;
    color: #1565c0;
}

.alert-info .alert-btn {
    background: #1565c0;
}