/* Importar fuentes del main.css para consistencia */
@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;500;600;700&family=Source+Sans+Pro:wght@300;400;500;600&display=swap');

/* Variables CSS - Sacred Minimalism con Máxima Legibilidad */
:root {
    --primary-bg: #FDFBF6;
    --accent-purple: #4B0082;
    --accent-gold: #D4AF37;
    --text-primary: #1a1a1a;        /* Negro suave para máximo contraste */
    --text-secondary: #4a4a4a;      /* Gris oscuro legible */
    --text-light: #666666;          /* Gris medio */
    --text-white: #ffffff;          /* Blanco puro para texto sobre fondo oscuro */
    --bg-light: #FFFEFA;
    --chat-bg: #f8f9fa;
    --assistant-bg: #ffffff;        /* Fondo blanco puro */
    --user-bg: #4B0082;             /* Púrpura oscuro */
    --user-text: #ffffff;           /* Texto blanco sobre púrpura */
    --border-light: rgba(0, 0, 0, 0.12);
    --shadow-soft: 0 2px 12px rgba(0, 0, 0, 0.08);
    --shadow-message: 0 1px 3px rgba(0, 0, 0, 0.15);
    --border-radius: 16px;
    --border-radius-small: 8px;
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Chat Container Principal */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 900px;
    margin: 0 auto;
    background: var(--primary-bg);
    box-shadow: var(--shadow-soft);
    position: relative;
    overflow: hidden;
}

/* Header del Chat */
.chat-header {
    background: var(--accent-purple);
    color: white;
    padding: 1.5rem 2rem;
    text-align: center;
    box-shadow: var(--shadow-soft);
    position: relative;
    z-index: 10;
}

.chat-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(circle at center, transparent 0%, rgba(0, 0, 0, 0.1) 100%);
}

.chat-header-content {
    position: relative;
    z-index: 2;
}

.chat-header h1 {
    font-family: 'Playfair Display', serif;
    font-size: 1.8rem;
    margin: 0 0 0.5rem 0;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.95);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.chat-header .subtitle {
    font-size: 0.95rem;
    opacity: 1;
    margin: 0;
    font-weight: 400;
    color: rgba(255, 255, 255, 0.9);
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}

.chat-status {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(255, 255, 255, 0.15);
    padding: 0.3rem 1rem;
    border-radius: 20px;
    font-size: 0.85rem;
    margin-top: 0.5rem;
}

.status-dot {
    width: 8px;
    height: 8px;
    background: #4ade80;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Área de Mensajes - Scroll moderno */
.chat-messages {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    overflow-x: hidden;
    background: var(--primary-bg);
    display: flex;
    flex-direction: column;
    gap: 1rem;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.15) transparent;
}

/* Scroll moderno para webkit */
.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 4px;
    border: 2px solid transparent;
    background-clip: content-box;
    transition: all 0.2s ease;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.25);
    background-clip: content-box;
}

.chat-messages::-webkit-scrollbar-thumb:active {
    background: rgba(0, 0, 0, 0.35);
    background-clip: content-box;
}

/* Mensajes Individuales */
.chat-message {
    display: flex;
    max-width: 80%;
    animation: messageSlide 0.3s ease-out;
}

@keyframes messageSlide {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-bubble {
    padding: 1rem 1.25rem;
    border-radius: var(--border-radius);
    line-height: 1.6;
    font-size: 0.95rem;
    box-shadow: var(--shadow-message);
    position: relative;
    word-wrap: break-word;
    max-width: 100%;
    border: 1px solid var(--border-light);
}

/* Avatar y metadata */
.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    margin: 0 0.75rem;
    flex-shrink: 0;
    align-self: flex-end;
}

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

.message-time {
    font-size: 0.75rem;
    opacity: 0.6;
    margin-top: 0.5rem;
    text-align: right;
}

/* Burbuja del Asistente (Párroco) */
.assistant-message {
    align-self: flex-start;
    flex-direction: row;
}

.assistant-message .message-avatar {
    background: var(--accent-gold);
    color: white;
    order: 1;
    align-self: flex-start;
    margin-top: 0.5rem;
}

.assistant-message .message-content {
    order: 2;
}

.assistant-bubble {
    background: var(--assistant-bg);
    color: var(--text-primary);
    border: 1px solid var(--border-light);
    position: relative;
    font-weight: 400;
}

/* Burbuja del Usuario */
.user-message {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.user-message .message-avatar {
    background: var(--user-bg);
    color: white;
    order: 1;
    align-self: flex-start;
    margin-top: 0.5rem;
}

.user-message .message-content {
    order: 2;
}

.user-bubble {
    background: var(--user-bg);
    color: var(--text-white);
    position: relative;
    font-weight: 500;
}

.user-message .message-time {
    text-align: left;
    color: rgba(255, 255, 255, 0.9);
    font-weight: 400;
}

/* Mensaje de bienvenida especial */
.welcome-message {
    text-align: center;
    margin: 1.5rem 0;
    padding: 1.5rem;
    background: linear-gradient(135deg, rgba(75, 0, 130, 0.05) 0%, rgba(212, 175, 55, 0.05) 100%);
    border-radius: var(--border-radius);
    border: 1px solid var(--accent-gold);
    max-width: 90%;
    align-self: center;
}

.welcome-message .welcome-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    color: var(--accent-gold);
}

.welcome-message h3 {
    font-family: 'Playfair Display', serif;
    color: var(--text-primary);
    margin-bottom: 1rem;
    font-size: 1.5rem;
}

.welcome-message p {
    color: var(--text-secondary);
    font-size: 1.05rem;
    margin: 0;
    line-height: 1.6;
}

/* Input Container - Estilo moderno ChatGPT */
.chat-input-container {
    padding: 1rem 1.5rem 1.5rem;
    background: var(--primary-bg);
    border-top: 1px solid var(--border-light);
    position: sticky;
    bottom: 0;
    z-index: 10;
}

.chat-input-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--accent-gold), transparent);
    opacity: 0.3;
}

.chat-input {
    max-width: 768px;
    margin: 0 auto;
    position: relative;
    display: flex;
    align-items: flex-end;
    background: white;
    border-radius: 24px;
    border: 1px solid var(--border-light);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    transition: var(--transition);
    overflow: hidden;
}

.chat-input:focus-within {
    border-color: var(--accent-purple);
    box-shadow: 0 4px 16px rgba(75, 0, 130, 0.15);
}

.input-wrapper {
    flex: 1;
    position: relative;
    min-height: 52px;
    display: flex;
    align-items: center;
}

.chat-input textarea {
    width: 100%;
    min-height: 24px;
    max-height: 200px;
    padding: 14px 60px 14px 20px;
    border: none;
    resize: none;
    font-family: 'Source Sans Pro', sans-serif;
    font-size: 16px;
    line-height: 1.5;
    background: transparent;
    outline: none;
    color: var(--text-primary);
    overflow-y: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.chat-input textarea::-webkit-scrollbar {
    display: none;
}

.chat-input textarea::placeholder {
    color: rgba(0, 0, 0, 0.45);
    font-weight: 400;
}

/* Botón de envío moderno integrado */
.send-button {
    position: absolute;
    right: 6px;
    bottom: 6px;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 20px;
    background: var(--accent-purple);
    color: white;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    box-shadow: 0 2px 8px rgba(75, 0, 130, 0.2);
    z-index: 2;
}

.send-button:hover:not(:disabled) {
    background: #3a0066;
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(75, 0, 130, 0.3);
}

.send-button:active:not(:disabled) {
    transform: scale(0.95);
}

.send-button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background: #ccc;
    box-shadow: none;
    transform: none;
}

/* Indicador de caracteres (opcional) */
.char-counter {
    position: absolute;
    bottom: -20px;
    right: 0;
    font-size: 12px;
    color: rgba(0, 0, 0, 0.4);
    display: none;
}

/* Indicador de escritura */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem 1.25rem;
    background: var(--assistant-bg);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-light);
    max-width: 80px;
    align-self: flex-start;
    margin: 0 0 1rem 3rem;
    opacity: 0;
    animation: fadeInUp 0.3s ease-out forwards;
}

.typing-dots {
    display: flex;
    gap: 4px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
    0%, 80%, 100% {
        transform: scale(0);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Responsive Design - Optimizado para móviles */
@media (max-width: 768px) {
    .chat-container {
        max-width: 100%;
        height: 100vh;
        box-shadow: none;
    }

    .chat-messages {
        padding: 1rem;
        gap: 0.75rem;
    }

    .chat-message {
        max-width: 90%;
    }

    .chat-input-container {
        padding: 0.75rem 1rem 1rem;
    }

    .chat-input {
        max-width: 100%;
        border-radius: 20px;
    }

    .chat-input textarea {
        font-size: 16px; /* Evita zoom en iOS */
        padding: 12px 50px 12px 16px;
    }

    .send-button {
        width: 36px;
        height: 36px;
        right: 4px;
        bottom: 4px;
        border-radius: 18px;
    }

    .chat-header {
        padding: 1rem;
    }

    .chat-header h1 {
        font-size: 1.4rem;
    }

    .welcome-message {
        margin: 1rem 0;
        padding: 1.25rem;
    }

    .message-avatar {
        width: 32px;
        height: 32px;
        font-size: 1rem;
        margin: 0 0.5rem;
    }

    .typing-indicator {
        margin: 0 0 0.75rem 2.5rem;
    }
}

@media (max-width: 480px) {
    .chat-messages {
        padding: 0.75rem;
        gap: 0.5rem;
    }

    .chat-input-container {
        padding: 0.5rem 0.75rem 0.75rem;
    }

    .chat-input {
        border-radius: 18px;
        border-width: 1px;
    }

    .chat-input textarea {
        padding: 10px 45px 10px 14px;
        min-height: 20px;
        font-size: 16px;
    }

    .send-button {
        width: 32px;
        height: 32px;
        right: 3px;
        bottom: 3px;
        border-radius: 16px;
        font-size: 14px;
    }

    .message-bubble {
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
    }

    .chat-header h1 {
        font-size: 1.2rem;
    }

    .chat-header .subtitle {
        font-size: 0.8rem;
    }

    .message-avatar {
        width: 28px;
        height: 28px;
        font-size: 0.9rem;
        margin: 0 0.4rem;
    }

    .typing-indicator {
        margin: 0 0 0.5rem 2rem;
    }

    .welcome-message {
        margin: 0.75rem 0;
        padding: 1rem;
    }

    .welcome-message h3 {
        font-size: 1.25rem;
    }

    .welcome-message p {
        font-size: 0.95rem;
    }
}

/* Mejoras adicionales para la experiencia móvil */
@media (max-width: 480px) and (orientation: landscape) {
    .chat-header {
        padding: 0.75rem;
    }
    
    .chat-header h1 {
        font-size: 1.2rem;
    }
    
    .chat-header .subtitle {
        display: none;
    }
    
    .chat-status {
        margin-top: 0.25rem;
    }
}

/* Soporte para notch en dispositivos iOS */
@supports (padding: max(0px)) {
    .chat-input-container {
        padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
    }
}

/* Mejoras adicionales para estilo moderno */
.chat-message p {
    margin: 0 0 0.5rem 0;
}

.chat-message p:last-child {
    margin-bottom: 0;
}

/* Animación suave para el scroll */
.chat-messages {
    scroll-behavior: smooth;
}

/* Mejora en el contraste del texto */
.assistant-bubble {
    color: var(--text-primary);
    font-weight: 400;
}

.user-bubble {
    color: var(--text-white);
    font-weight: 500;
}

/* Asegurar legibilidad en todos los elementos de texto */
.message-bubble p {
    color: inherit;
    font-weight: inherit;
}

.assistant-bubble p {
    color: var(--text-primary);
}

.user-bubble p {
    color: var(--text-white);
}

/* Efecto hover sutil en mensajes */
.message-bubble:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* Mejora en el estado de carga */
.send-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #ccc;
    box-shadow: none;
    transform: none;
}

/* Estilo para mensajes de error */
.error-message .message-bubble {
    background: #fee;
    border-color: #fcc;
    color: #c33;
}

/* Mejora en el indicador de escritura */
.typing-dot {
    background: var(--accent-purple);
}

/* Transiciones suaves para todos los elementos interactivos */
* {
    transition: var(--transition);
}