/* latin-ext */
@font-face {
  font-family: 'Outfit';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('fonts/outfit-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
/* latin */
@font-face {
  font-family: 'Outfit';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('fonts/outfit-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
    --bg-color: #f8fafc;
    --surface: rgba(255, 255, 255, 0.75); /* Glass surface */
    --surface-2: rgba(241, 245, 249, 0.6);
    --border: rgba(226, 232, 240, 0.6);
    --accent: #0f172a;
    --accent-glow: rgba(15, 23, 42, 0.08);
    --success: #10b981;
    --danger: #be123c;
    --warning: #f59e0b;
    --wa: #10b981;
    --text: #0f172a;
    --text-2: #334155;
    --text-3: #64748b;
    --radius: 16px;
    --radius-sm: 8px;
    --shadow-lg: 0 10px 40px -10px rgba(0, 0, 0, 0.1); 
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
    height: 100%;
    background-color: #f1f5f9;
}

body {
    min-height: 100%;
    font-family: 'Outfit', sans-serif;
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    position: relative;
    z-index: 0;
    overflow-x: hidden;
    background: transparent;
}

body::before {
    content: "";
    position: fixed;
    top: -20%;
    left: -10%;
    width: 70%;
    height: 70%;
    background: radial-gradient(circle, rgba(56, 189, 248, 0.4) 0%, rgba(56, 189, 248, 0) 70%);
    z-index: -1;
    filter: blur(60px);
}

body::after {
    content: "";
    position: fixed;
    bottom: -20%;
    right: -10%;
    width: 70%;
    height: 70%;
    background: radial-gradient(circle, rgba(16, 185, 129, 0.25) 0%, rgba(16, 185, 129, 0) 70%);
    z-index: -1;
    filter: blur(60px);
}

body {
    padding: 16px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow-y: auto;
}

/* ══════════════════════════════
   CONTENEDOR PRINCIPAL
══════════════════════════════ */
.card {
    background: var(--surface);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    width: 100%;
    max-width: 480px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255,255,255,0.6);
    padding: 24px 20px;
    margin-top: 10px;
    margin-bottom: 40px;
    overflow: hidden; /* Evitar que cualquier hijo se salga del borde redondeado */
    box-sizing: border-box;
}

.generator-header { text-align: center; margin-bottom: 28px; }

.logo-box {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    color: white;
    padding: 16px 24px;
    border-radius: var(--radius);
    margin-bottom: 16px;
}

.logo-box h2 { font-size: 24px; font-weight: 700; letter-spacing: 1px; margin: 0; font-family: 'Outfit', sans-serif; }
.logo-box p { font-size: 11px; font-weight: 500; letter-spacing: 0.5px; opacity: 0.9; }

h1 { font-size: 20px; font-weight: 600; color: var(--text); }

/* ══════════════════════════════
   FORMULARIO
══════════════════════════════ */
.form-group { margin-bottom: 20px; }
label { 
    display: block; 
    font-size: 12px;
    font-weight: 600;
    color: var(--text-2);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 6px;
}

input, textarea {
    width: 100%;
    padding: 13px 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 15px;
    font-family: inherit;
    line-height: 1.5;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
    resize: none;
    -webkit-appearance: none;
}

input:focus, textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}
input::placeholder, textarea::placeholder { color: var(--text-3); opacity: 1; }

/* ══════════════════════════════
   BOTONES
══════════════════════════════ */
.button-grid-row {
    display: flex;
    gap: 8px;
    width: 100%;
    box-sizing: border-box;
}
.button-grid-row button {
    flex: 1;
    min-width: 0;       /* Permite que flex shrink funcione bien */
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.pc-button-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 24px;
}

.mobile-button-panel {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 16px;
    width: 100%;
    box-sizing: border-box;
}

.pc-preview-actions-grid {
    display: none;
}

button {
    width: 100%;
    padding: 12px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    -webkit-tap-highlight-color: transparent;
}

button:active { transform: scale(0.97); }

.btn-primary {
    background: var(--accent);
    color: white;
    box-shadow: 0 2px 4px rgba(15, 23, 42, 0.08);
}
.btn-primary:hover {
    background: #1e293b;
    box-shadow: 0 4px 10px rgba(15, 23, 42, 0.15);
}

.btn-secondary {
    background: #ffffff;
    color: var(--text-2);
    border: 1px solid #cbd5e1;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}
.btn-secondary:hover {
    background: #f8fafc;
    border-color: #94a3b8;
    color: var(--text);
}

.btn-download {
    background: var(--accent);
    color: white;
    box-shadow: 0 2px 4px rgba(15, 23, 42, 0.08);
}
.btn-download:hover {
    background: #1e293b;
    box-shadow: 0 4px 10px rgba(15, 23, 42, 0.15);
}

.btn-whatsapp {
    background: #16a34a;
    color: white;
    box-shadow: 0 2px 4px rgba(22, 163, 74, 0.15);
}
.btn-whatsapp:hover {
    background: #15803d;
    box-shadow: 0 4px 8px rgba(22, 163, 74, 0.25);
}

.btn-corregir {
    background: #dc2626;
    color: white;
    box-shadow: 0 2px 4px rgba(220, 38, 38, 0.15);
}
.btn-corregir:hover {
    background: #b91c1c;
    box-shadow: 0 4px 8px rgba(220, 38, 38, 0.25);
}

/* ══════════════════════════════
   ESTADOS DE CARGA Y PREVIEW
   (Controlados dinámicamente por clases de estado en el body)
══════════════════════════════ */
#loading, #preview-container, #empty-state {
    display: none;
}

#loading { text-align: center; padding: 40px 20px; }
.spinner {
    width: 40px; height: 40px; 
    border: 3px solid var(--border); 
    border-top-color: var(--accent);
    border-radius: 50%; 
    animation: spin 0.8s linear infinite; 
    margin: 0 auto 20px;
}
@keyframes spin { to { transform: rotate(360deg); } }

#preview-container { animation: fadeIn 0.4s ease-out; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

#document-container {
    background: #ffffff; /* El PDF se ve mejor con fondo blanco para contraste */
    border: 1px solid var(--border); 
    border-radius: var(--radius-sm);
    overflow: auto; 
    margin-bottom: 24px; 
    height: 60vh; 
    min-height: 400px;
    -webkit-overflow-scrolling: touch;
}

#pdf-frame {
    width: 100%;
    border: none;
    min-height: 600px;
    display: block;
    transform-origin: top left;
    touch-action: pan-x pan-y pinch-zoom;
}

@media (min-width: 640px) {
    .button-group { flex-direction: row; }
}

/* ── Pantallas muy estrechas (< 380px): botones más compactos ── */
@media (max-width: 379px) {
    .card {
        padding: 20px 14px;
    }
    button {
        padding: 10px 8px;
        font-size: 11.5px;
        letter-spacing: 0.2px;
        gap: 5px;
    }
    .button-grid-row {
        gap: 6px;
    }
}

/* ══════════════════════════════
   ESTILOS DE EMPTY STATE
══════════════════════════════ */
.empty-state {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 24px;
    background: var(--surface-2);
    border: 2px dashed var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-2);
    min-height: 400px;
    height: 100%;
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.7;
    animation: pulse 2.5s infinite ease-in-out;
}

.empty-state h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text);
}

.empty-state p {
    font-size: 14px;
    max-width: 320px;
    line-height: 1.5;
    color: var(--text-2);
}

@keyframes pulse {
    0% { transform: scale(1); opacity: 0.6; }
    50% { transform: scale(1.08); opacity: 0.9; }
    100% { transform: scale(1); opacity: 0.6; }
}

/* ══════════════════════════════
   VISIBILIDAD Y DISEÑO DE ESTADOS
══════════════════════════════ */

/* ── MÓVILES Y TABLETS (< 1024px) ── */
@media (max-width: 1023px) {
    /* Estado formulario: muestra columna izquierda y oculta la derecha */
    body.state-form .left-column {
        display: block;
    }
    body.state-form .right-column {
        display: none;
    }

    /* Estado carga: muestra columna derecha (loading) y oculta la izquierda */
    body.state-loading .left-column {
        display: none;
    }
    body.state-loading .right-column {
        display: block;
    }
    body.state-loading #loading {
        display: block;
    }

    /* Estado previsualización: muestra columna derecha (preview) y oculta la izquierda */
    body.state-preview .left-column {
        display: none;
    }
    body.state-preview .right-column {
        display: block;
    }
    body.state-preview #preview-container {
        display: block;
    }

    /* Ampliar contenedor de previsualización en móvil/tablet para legibilidad óptima */
    body.state-preview .card {
        max-width: 900px !important;
        width: 95% !important;
    }
}

/* ── ORDENADORES (>= 1024px) ── */
@media (min-width: 1024px) {
    body {
        height: 100vh;
        overflow: hidden;
        padding: 24px;
        margin: 0;
        display: flex;
        align-items: stretch;
        justify-content: stretch;
        /* Mostrar los orbes en escritorio */
        background-image:
            radial-gradient(circle at 15% 15%, rgba(56, 189, 248, 0.35) 0%, transparent 45%),
            radial-gradient(circle at 85% 85%, rgba(16, 185, 129, 0.25) 0%, transparent 45%);
        background-color: #e8f4fd;
    }

    .card {
        max-width: 100%;
        width: 100%;
        height: 100%;
        min-height: 0;
        max-height: 100%;
        display: grid;
        grid-template-columns: 370px 1fr;
        gap: 0;
        padding: 0;
        margin: 0;
        border-radius: 20px;
        border: 1px solid rgba(255,255,255,0.6);
        box-shadow: 0 20px 60px rgba(0,0,0,0.08), inset 0 1px 0 rgba(255,255,255,0.8);
        background: rgba(255, 255, 255, 0.55);
        backdrop-filter: blur(24px);
        -webkit-backdrop-filter: blur(24px);
        overflow: hidden;
        box-sizing: border-box;
    }

    /* Ambas columnas se vuelven independientes con scroll vertical */
    .left-column {
        display: flex;
        flex-direction: column;
        height: 100%;
        overflow-y: auto;
        border-right: 1px solid rgba(226, 232, 240, 0.5);
        padding: 24px;
        box-sizing: border-box;
        background: rgba(255,255,255,0.3);
    }
    
    .right-column {
        display: flex;
        flex-direction: column;
        height: 100%;
        overflow: hidden;
        padding: 24px;
        box-sizing: border-box;
        background: transparent;
    }

    /* Visibilidad interna de la columna derecha */
    
    /* Estado Formulario SIN preview anterior: muestra Empty State */
    body.state-form:not(.has-preview) #empty-state {
        display: flex;
    }

    /* Estado Formulario CON preview anterior: muestra la preview anterior */
    body.state-form.has-preview #preview-container {
        display: flex;
        flex-direction: column;
        height: 100%;
    }

    /* Estado de Carga: muestra el loading */
    body.state-loading #loading {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        height: 100%;
    }

    /* Estado de Preview: muestra la previsualización */
    body.state-preview #preview-container {
        display: flex;
        flex-direction: column;
        height: 100%;
    }

    #document-container {
        flex: 1;
        height: 100% !important;
        max-height: none !important;
        margin-bottom: 0 !important;
        overflow-y: auto;
    }

    /* Ocultar panel de botones móvil en PC */
    .mobile-button-panel {
        display: none !important;
    }

    /* Ocultar la rejilla de acciones por defecto */
    .pc-preview-actions-grid {
        display: none;
    }

    /* Mostrar rejilla 2x2 en PC cuando hay previsualización activa */
    body.has-preview .pc-preview-actions-grid {
        display: grid !important;
        grid-template-columns: 1fr 1fr;
        gap: 12px;
    }

    /* Ocultar el botón Generar inicial cuando ya hay previsualización */
    body.has-preview #btn-generar-init {
        display: none !important;
    }

    /* Custom thin scrollbar for a sleek premium SaaS feel */
    .left-column::-webkit-scrollbar,
    #document-container::-webkit-scrollbar {
        width: 6px;
        height: 6px;
    }
    .left-column::-webkit-scrollbar-track,
    #document-container::-webkit-scrollbar-track {
        background: transparent;
    }
    .left-column::-webkit-scrollbar-thumb,
    #document-container::-webkit-scrollbar-thumb {
        background: #cbd5e1;
        border-radius: 3px;
    }
    .left-column::-webkit-scrollbar-thumb:hover,
    #document-container::-webkit-scrollbar-thumb:hover {
        background: #94a3b8;
    }
}

.descripcion-wrapper {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.mic-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin: 12px 0 4px;
    text-align: center;
}
.btn-mic-circle {
    position: relative;
    width: 76px;
    height: 76px;
    border-radius: 50%;
    background: #ffffff;
    border: 2px solid #cbd5e1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.05);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    -webkit-tap-highlight-color: transparent;
}
.btn-mic-circle:hover {
    background: #f8fafc;
    border-color: #94a3b8;
    transform: scale(1.04);
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.08);
}
.btn-mic-circle:active {
    transform: scale(0.96);
}
.btn-mic-circle .mic-status-icon {
    width: 22px;
    height: 22px;
    background: #ef4444;
    border-radius: 50%;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.btn-mic-circle .pulse-ring {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    border-radius: 50%;
    border: 4px solid #ffffff;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s ease;
}
.btn-mic-circle.recording {
    background: #ef4444;
    border-color: #ef4444;
    box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.15), 0 6px 20px rgba(239, 68, 68, 0.25);
}
.btn-mic-circle.recording .pulse-ring {
    animation: pulse-ring-animation 1.5s cubic-bezier(0.215, 0.610, 0.355, 1) infinite;
}
.btn-mic-circle.recording .mic-status-icon {
    background: #ffffff;
    border-radius: 4px;
    width: 18px;
    height: 18px;
}
.btn-mic-circle.processing {
    background: #d97706;
    border-color: #d97706;
    cursor: not-allowed;
    box-shadow: 0 6px 20px rgba(217, 119, 6, 0.2);
}
.btn-mic-circle.processing .mic-status-icon {
    background: #ffffff;
    border-radius: 50%;
    animation: pulse-icon 1.2s infinite ease-in-out;
}
@keyframes pulse-ring-animation {
    0% { transform: scale(0.95); opacity: 0.8; }
    50% { opacity: 0.4; }
    100% { transform: scale(1.45); opacity: 0; }
}
@keyframes pulse-icon {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(0.8); opacity: 0.6; }
}
.mic-label {
    font-size: 13px;
    font-weight: 600;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: color 0.3s ease;
    margin-top: 2px;
}
.btn-mic-circle.recording + .mic-label {
    color: #dc2626;
}
.audio-status {
    font-size: 12px;
    color: #64748b;
    font-style: italic;
    min-height: 18px;
    margin-top: -2px;
}
.audio-status.ok { color: #16a34a; font-style: normal; font-weight: 600; }
.audio-status.error { color: #dc2626; font-style: normal; font-weight: 600; }
#descripcion, #nombre {
    width: 100%;
    box-sizing: border-box;
    font-family: 'Outfit', sans-serif;
    font-size: 14px;
    padding: 12px;
    border: 1.5px solid #ddd;
    border-radius: 10px;
    resize: vertical;
    transition: border-color 0.2s;
    background: #fafafa;
}
#descripcion:focus, #nombre:focus {
    outline: none;
    border-color: #1a3a5a;
    background: #fff;
}
.badge-voz {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: #eff6ff;
    color: #1d4ed8;
    border: 1px solid #93c5fd;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    padding: 3px 10px;
}

button i[data-lucide] {
    width: 18px;
    height: 18px;
}

#loading-msg {
    font-weight: 600;
}
