/* ========================================================
   VARIABLES Y ESTILOS GLOBALES
   ======================================================== */
:root {
    --primary-red: #d90429;
    --primary-red-hover: #b80022;
    --primary-pink: #ffe5ec;
    --primary-pink-card: #ffd1dc;
    --primary-pink-border: #ffb3c6;
    --text-dark: #222222;
    --text-muted: #6c757d;
    --text-light: #ffffff;
    --bg-app: #ffffff;
    --bg-page: #f2f4f8;
    --border-color: #f0f0f0;
    --font-main: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
    --shadow-soft: 0 10px 30px rgba(217, 4, 41, 0.08);
    --shadow-frame: 0 15px 40px rgba(0, 0, 0, 0.12);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: var(--font-main);
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-page);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px;
    color: var(--text-dark);
}

/* ========================================================
   CONTENEDOR DISPOSITIVO MÓVIL
   ======================================================== */
.mobile-wrapper {
    width: 100%;
    max-width: 440px;
    height: 92vh;
    height: 92dvh;
    max-height: 880px;
    background: var(--bg-app);
    border-radius: 36px;
    box-shadow: var(--shadow-frame);
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    border: 1px solid rgba(0, 0, 0, 0.04);
}

.app-container {
    width: 100%;
    height: 100%;
    position: relative;
    overflow: hidden;
}

/* ========================================================
   ESTILOS DE PANTALLAS (TRANSICIONES)
   ======================================================== */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
    padding: 24px 24px 30px;
    background: var(--bg-app);
    overflow-y: auto;
    z-index: 1;
}

.screen.active {
    display: flex;
    animation: fadeInSlide 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes fadeInSlide {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.99);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ========================================================
   ENCABEZADO COMÚN
   ======================================================== */
.app-header {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    height: 48px;
    margin-bottom: 12px;
    position: relative;
    z-index: 10;
}

.app-header.has-back {
    gap: 16px;
}

.btn-back {
    background: none;
    border: none;
    color: var(--primary-red);
    font-size: 1.35rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 6px;
    transition: transform 0.15s ease;
}

.btn-back:hover {
    transform: translateX(-3px);
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.45rem;
    font-weight: 700;
    color: var(--text-dark);
    letter-spacing: -0.5px;
}

.logo-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background-color: var(--primary-red);
    color: #fff;
    border-radius: 50% 50% 0 50%;
    transform: rotate(45deg);
    font-size: 0.95rem;
}

.logo-icon i {
    transform: rotate(-45deg);
}

.logo strong {
    color: var(--primary-red);
    font-weight: 800;
}

/* ========================================================
   CUERPO Y ELEMENTOS DE PANTALLA 1 & 2
   ======================================================== */
.content-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 5;
}

.content-body.center-content {
    align-items: center;
    text-align: center;
    justify-content: center;
}

.illustration-box {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 15px 0 25px;
}

.illustration-box img {
    max-width: 220px;
    height: auto;
    object-fit: contain;
    filter: drop-shadow(0 8px 20px rgba(217, 4, 41, 0.12));
}

.illustration-box.small {
    margin: 10px 0 20px;
}

/* Corazón estilizado pantalla 2 */
.heart-badge {
    position: relative;
    width: 110px;
    height: 90px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.main-heart {
    font-size: 5rem;
    color: var(--primary-red);
    filter: drop-shadow(0 6px 14px rgba(217, 4, 41, 0.25));
}

.sub-heart {
    position: absolute;
    font-size: 2.6rem;
    color: #ff85a1;
    bottom: -5px;
    right: 5px;
    border: 4px solid var(--bg-app);
    border-radius: 50%;
}

.main-title {
    font-size: 2.1rem;
    font-weight: 800;
    line-height: 1.15;
    color: var(--text-dark);
    margin-bottom: 16px;
    letter-spacing: -0.6px;
}

.brand-highlight {
    color: var(--primary-red);
}

.description {
    font-size: 0.95rem;
    line-height: 1.55;
    color: var(--text-muted);
    max-width: 320px;
    margin: 0 auto;
}

.section-title {
    font-size: 1.7rem;
    font-weight: 800;
    color: var(--primary-red);
    text-align: center;
    margin-bottom: 8px;
    letter-spacing: -0.4px;
}

.section-subtitle {
    font-size: 0.92rem;
    color: var(--text-muted);
    text-align: center;
    margin-bottom: 24px;
    line-height: 1.45;
}

/* ========================================================
   TARJETA PREGUNTA Y INPUTS
   ======================================================== */
.question-card {
    background-color: var(--primary-pink);
    border-radius: 20px;
    padding: 24px 20px;
    margin-bottom: 22px;
    border: 1px solid var(--primary-pink-border);
    box-shadow: 0 4px 14px rgba(255, 117, 143, 0.15);
}

.question-card p {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-dark);
    line-height: 1.35;
    text-align: left;
}

.input-group {
    width: 100%;
    margin-bottom: 15px;
}

.text-input {
    width: 100%;
    padding: 16px 22px;
    font-size: 1.02rem;
    border: 1.5px solid var(--primary-pink-border);
    border-radius: 999px;
    background: #fff;
    outline: none;
    transition: all 0.2s ease;
    color: var(--text-dark);
}

.text-input:focus {
    border-color: var(--primary-red);
    box-shadow: 0 0 0 3px rgba(217, 4, 41, 0.12);
}

.error-msg {
    color: var(--primary-red);
    font-size: 0.85rem;
    font-weight: 600;
    margin-top: 8px;
    padding-left: 18px;
    display: none;
}

/* ========================================================
   BOTONES
   ======================================================== */
.app-footer {
    width: 100%;
    margin-top: auto;
    padding-top: 15px;
    position: relative;
    z-index: 10;
}

.btn-primary {
    width: 100%;
    padding: 17px 24px;
    background: var(--primary-red);
    color: var(--text-light);
    border: none;
    border-radius: 999px;
    font-size: 1.15rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(217, 4, 41, 0.28);
    transition: all 0.2s ease;
}

.btn-primary:hover {
    background: var(--primary-red-hover);
    transform: translateY(-2px);
    box-shadow: 0 10px 24px rgba(217, 4, 41, 0.35);
}

.btn-primary:active {
    transform: translateY(0);
}

/* ========================================================
   PANTALLA 3: CHAT ESTILO SECURECHAT
   ======================================================== */
.screen-chat {
    padding: 16px 0 0;
    overflow: hidden;
}

.screen-chat .app-header {
    padding: 0 20px;
    margin-bottom: 6px;
}

.chat-intro {
    padding: 0 24px 14px;
    border-bottom: 1px solid var(--border-color);
}

.intro-title-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
}

.intro-heart {
    color: var(--primary-red);
    font-size: 1.25rem;
}

.intro-title-wrap h3 {
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--text-dark);
}

.chat-intro p {
    font-size: 0.86rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    scroll-behavior: smooth;
    background: #fafbfe;
}

/* Burbujas de Chat */
.chat-row {
    display: flex;
    gap: 10px;
    max-width: 86%;
    align-items: flex-end;
}

.chat-row.bot {
    align-self: flex-start;
}

.chat-row.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.avatar-badge {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1rem;
    color: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.chat-row.bot .avatar-badge {
    background-color: var(--primary-red);
}

.chat-row.user .avatar-badge {
    background-color: #3a3b45;
}

.message-content {
    display: flex;
    flex-direction: column;
}

.bubble {
    padding: 14px 18px;
    font-size: 0.95rem;
    line-height: 1.45;
    word-break: break-word;
    white-space: pre-wrap;
}

.chat-row.bot .bubble {
    background-color: var(--primary-pink);
    color: var(--text-dark);
    border-radius: 20px 20px 20px 6px;
    border: 1px solid rgba(255, 179, 198, 0.4);
}

.chat-row.user .bubble {
    background-color: #ffffff;
    color: var(--text-dark);
    border-radius: 20px 20px 6px 20px;
    border: 1px solid #e2e5ec;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.03);
}

.timestamp {
    font-size: 0.72rem;
    color: #9aa0a6;
    margin-top: 4px;
    padding: 0 4px;
}

.chat-row.bot .timestamp {
    text-align: left;
}

.chat-row.user .timestamp {
    text-align: right;
}

/* Indicador de escribiendo */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 18px;
    background: var(--primary-pink);
    border-radius: 20px 20px 20px 6px;
    width: fit-content;
}

.dot {
    width: 7px;
    height: 7px;
    background-color: var(--primary-red);
    border-radius: 50%;
    animation: bounce 1.3s infinite ease-in-out;
}

.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
    40% { transform: translateY(-5px); opacity: 1; }
}

/* Barra de Entrada de Chat */
.chat-input-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 20px 18px;
    background: #ffffff;
    border-top: 1px solid var(--border-color);
    position: relative;
    z-index: 10;
}

.attachment-btn {
    background: none;
    border: none;
    color: var(--primary-red);
    font-size: 1.35rem;
    cursor: pointer;
    padding: 4px 6px;
    transition: transform 0.15s ease;
}

.attachment-btn:hover {
    transform: scale(1.1);
}

.input-wrapper {
    flex: 1;
}

.input-wrapper input {
    width: 100%;
    padding: 12px 18px;
    font-size: 16px;
    border: 1.5px solid var(--primary-pink-border);
    border-radius: 999px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: #fff;
    color: var(--text-dark);
}

.input-wrapper input:focus {
    border-color: var(--primary-red);
}

.btn-send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background-color: var(--primary-red);
    color: #ffffff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.05rem;
    box-shadow: 0 4px 12px rgba(217, 4, 41, 0.28);
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.btn-send:hover {
    background-color: var(--primary-red-hover);
    transform: scale(1.05);
}

/* ========================================================
   GARABATOS / DOODLES DE ESQUINA (REFERENCIA VISUAL)
   ======================================================== */
.corner-doodle {
    position: absolute;
    width: 60px;
    height: 50px;
    pointer-events: none;
    opacity: 0.65;
    z-index: 2;
}

.corner-doodle.bottom-left {
    bottom: 8px;
    left: 8px;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 80"><path d="M10,70 C15,60 30,50 40,40 C50,30 55,15 65,15 C75,15 80,30 70,45 C60,60 40,65 10,70 Z" fill="none" stroke="%23ff4d6d" stroke-width="4"/></svg>');
    background-size: contain;
    background-repeat: no-repeat;
}

.corner-doodle.bottom-right {
    bottom: 8px;
    right: 8px;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 80"><path d="M90,70 C85,60 70,50 60,40 C50,30 45,15 35,15 C25,15 20,30 30,45 C40,60 60,65 90,70 Z" fill="none" stroke="%23ff4d6d" stroke-width="4"/></svg>');
    background-size: contain;
    background-repeat: no-repeat;
}

/* ========================================================
   PREVISUALIZACIÓN DE ARCHIVO ADJUNTO
   ======================================================== */
.attachment-preview-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 18px;
    background: #fff0f3;
    border-top: 1px dashed var(--primary-pink-border);
    position: relative;
    z-index: 10;
    animation: fadeInSlide 0.2s ease-out;
}

.attachment-preview-thumb {
    width: 38px;
    height: 38px;
    border-radius: 8px;
    object-fit: cover;
    border: 1px solid var(--primary-pink-border);
    background: #fff;
}

.attachment-preview-icon {
    width: 38px;
    height: 38px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-pink);
    color: var(--primary-red);
    font-size: 1.1rem;
}

.attachment-preview-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.attachment-preview-name {
    font-size: 0.84rem;
    font-weight: 600;
    color: var(--text-dark);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.attachment-preview-size {
    font-size: 0.72rem;
    color: var(--text-muted);
}

.attachment-preview-remove {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.15rem;
    cursor: pointer;
    padding: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
}

.attachment-preview-remove:hover {
    color: var(--primary-red);
}

/* Elementos adjuntos dentro de la burbuja */
.msg-attachment-img {
    margin-bottom: 8px;
    border-radius: 12px;
    overflow: hidden;
    max-width: 220px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.msg-attachment-img img {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 12px;
    transition: transform 0.2s;
}

.msg-attachment-img img:hover {
    transform: scale(1.02);
}

.msg-attachment-file {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.06);
    border-radius: 10px;
    margin-bottom: 8px;
    font-size: 0.85rem;
    color: inherit;
    text-decoration: none;
    max-width: 100%;
}

.msg-attachment-file i {
    font-size: 1rem;
    color: var(--primary-red);
}

.msg-attachment-file span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 160px;
}

/* Modal de imagen a pantalla completa */
.image-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.88);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 99999;
    padding: 20px;
    backdrop-filter: blur(5px);
    cursor: zoom-out;
}

.image-modal.active {
    display: flex;
}

.image-modal img {
    max-width: 90vw;
    max-height: 85vh;
    border-radius: 12px;
    object-fit: contain;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    animation: fadeInSlide 0.25s ease-out;
}

.modal-close-btn {
    position: absolute;
    top: 20px;
    right: 25px;
    color: #fff;
    font-size: 2.2rem;
    background: none;
    border: none;
    cursor: pointer;
    line-height: 1;
}

/* Formateo de texto en burbujas */
.bubble strong {
    font-weight: 700;
    color: inherit;
}

.bubble em {
    font-style: italic;
}

.bubble ul, .bubble ol {
    padding-left: 20px;
    margin: 6px 0;
}

.bubble li {
    margin-bottom: 4px;
}

.bubble code {
    background: rgba(0, 0, 0, 0.06);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9em;
}

.bubble pre {
    background: rgba(0, 0, 0, 0.06);
    padding: 8px 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
    max-width: 100%;
}

.bubble pre code {
    background: transparent;
    padding: 0;
    border-radius: 0;
    font-size: 0.85em;
}

/* Reproductor de audio dentro de la burbuja */
.msg-attachment-audio {
    width: 100%;
    max-width: 260px;
    margin-bottom: 8px;
    display: block;
}

.msg-attachment-audio audio {
    width: 100%;
    height: 38px;
    border-radius: 20px;
}

/* Accesibilidad Focus Visible */
button:focus-visible, input:focus-visible, a:focus-visible {
    outline: 2px solid var(--primary-red);
    outline-offset: 2px;
}

/* Scrollbar estilizada */
.chat-container::-webkit-scrollbar {
    width: 6px;
}
.chat-container::-webkit-scrollbar-track {
    background: transparent;
}
.chat-container::-webkit-scrollbar-thumb {
    background: rgba(217, 4, 41, 0.2);
    border-radius: 999px;
}
.chat-container::-webkit-scrollbar-thumb:hover {
    background: var(--primary-red);
}

/* ========================================================
   RESPONSIVE PARA TODOS LOS FORMATOS Y PANTALLAS
   ======================================================== */

/* Móviles estándar (ancho <= 480px) */
@media (max-width: 480px) {
    body {
        padding: 0;
        background-color: var(--bg-app);
    }
    .mobile-wrapper {
        max-width: 100%;
        height: 100vh;
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
        box-shadow: none;
        border: none;
    }
    .app-header {
        padding-top: max(8px, env(safe-area-inset-top));
    }
    .app-footer, .chat-input-bar {
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }
}

/* Móviles muy estrechos (iPhone SE 1ra gen, Galaxy Fold, ancho <= 360px) */
@media (max-width: 360px) {
    .screen {
        padding: 16px 14px 20px;
    }
    .main-title {
        font-size: 1.65rem;
    }
    .section-title {
        font-size: 1.4rem;
    }
    .question-card {
        padding: 16px 14px;
    }
    .question-card p {
        font-size: 1.05rem;
    }
    .btn-primary {
        padding: 14px 18px;
        font-size: 1.05rem;
    }
    .chat-row {
        max-width: 92%;
    }
    .bubble {
        padding: 10px 14px;
        font-size: 0.9rem;
    }
}

/* Altura reducida (pantallas con altura <= 720px) - Evita scrolls innecesarios en bienvenida y seguridad */
@media (max-height: 720px) {
    .screen {
        padding: 16px 18px 20px;
    }
    .illustration-box {
        margin: 8px 0 14px;
    }
    .illustration-box img {
        max-width: 150px;
    }
    .main-title {
        font-size: 1.7rem;
        margin-bottom: 8px;
    }
    .description {
        font-size: 0.88rem;
        line-height: 1.4;
    }
    .heart-badge {
        height: 70px;
    }
    .main-heart {
        font-size: 3.8rem;
    }
    .sub-heart {
        font-size: 2rem;
    }
    .section-title {
        font-size: 1.45rem;
        margin-bottom: 4px;
    }
    .section-subtitle {
        margin-bottom: 14px;
        font-size: 0.86rem;
    }
    .question-card {
        padding: 16px 16px;
        margin-bottom: 14px;
    }
    .question-card p {
        font-size: 1.1rem;
    }
    .btn-primary {
        padding: 14px 20px;
        font-size: 1.05rem;
    }
}

/* Teclado abierto o teléfonos pequeños en altura (altura <= 600px) */
@media (max-height: 600px) {
    .chat-intro {
        display: none; /* Da prioridad al 100% del área de mensajes cuando el teclado virtual está visible */
    }
    .corner-doodle {
        display: none;
    }
}

/* Dispositivos en modo horizontal (Landscape, altura <= 540px) */
@media (orientation: landscape) and (max-height: 540px) {
    body {
        padding: 0;
        align-items: stretch;
    }
    .mobile-wrapper {
        max-width: 100%;
        height: 100vh;
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
    }
    .illustration-box {
        margin: 4px 0 8px;
    }
    .illustration-box img {
        max-height: 90px;
        width: auto;
    }
    .main-title {
        font-size: 1.4rem;
        margin-bottom: 4px;
    }
    .description {
        font-size: 0.84rem;
    }
    .heart-badge {
        height: 55px;
    }
    .main-heart {
        font-size: 3.2rem;
    }
    .sub-heart {
        font-size: 1.6rem;
    }
    .chat-intro {
        display: none;
    }
    .corner-doodle {
        display: none;
    }
}

