/**
 * Danna AI Assistant - Estilos Principales CORREGIDOS
 * @version 1.2.1
 * 
 * CORRECCIÓN: Input de chat se escondía detrás de los mensajes
 */

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

:root {
    --primary-color: #007cc9;
    --primary-dark: #0056a0;
    --secondary-color: #6c757d;
    --success-color: #28a745;
    --danger-color: #dc3545;
    --light-gray: #f8f9fa;
    --border-color: #dee2e6;
    --text-color: #2c3e50;
    --shadow: 0 2px 10px rgba(0,0,0,0.1);
    --shadow-lg: 0 4px 20px rgba(0,0,0,0.15);
    --chat-input-height: 70px; /* Nueva variable para altura del input */
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.6;
    color: var(--text-color);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Hero Section */
.hero-section {
    text-align: center;
    padding: 100px 20px 60px;
    color: white;
}

.hero-section h1 {
    font-size: 3rem;
    margin-bottom: 20px;
    font-weight: 700;
    text-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

.hero-section p {
    font-size: 1.3rem;
    margin-bottom: 30px;
    opacity: 0.95;
}

/* Buttons */
.btn-primary {
    background: white;
    color: var(--primary-color);
    border: none;
    padding: 15px 40px;
    font-size: 1.1rem;
    font-weight: 600;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: var(--shadow);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-block {
    width: 100%;
    display: block;
}

/* Features Section */
.features-section {
    background: white;
    padding: 80px 20px;
    border-radius: 30px 30px 0 0;
    margin-top: -30px;
}

.features-section h2 {
    text-align: center;
    font-size: 2.5rem;
    margin-bottom: 50px;
    color: var(--text-color);
}

.features-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 30px;
    margin-top: 40px;
}

.feature-card {
    background: var(--light-gray);
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.feature-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow);
}

.feature-icon {
    font-size: 3rem;
    margin-bottom: 15px;
}

.feature-card h3 {
    font-size: 1.3rem;
    margin-bottom: 10px;
    color: var(--text-color);
}

.feature-card p {
    color: var(--secondary-color);
}

/* Chat Button (Floating) */
.chat-button {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    z-index: 999;
}

.chat-button:hover {
    transform: scale(1.1);
    background: var(--primary-dark);
}

/* ==========================================
   CORRECCIÓN CRÍTICA: Chat Widget Layout
   ========================================== */

/* Chat Widget */
.chat-widget {
    position: fixed;
    bottom: 100px;
    right: 30px;
    width: 400px;
    max-width: calc(100vw - 40px);
    height: 600px;
    max-height: calc(100vh - 150px);
    background: white;
    border-radius: 15px;
    box-shadow: var(--shadow-lg);
    display: none;
    flex-direction: column;
    z-index: 1000;
    overflow: hidden;
}

.chat-widget.active {
    display: flex;
}

.chat-widget.minimized {
    height: 60px;
}

.chat-widget.minimized .contact-form,
.chat-widget.minimized .chat-container {
    display: none !important;
}

/* Chat Header */
.chat-header {
    background: var(--primary-color);
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0; /* No se encoge */
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.assistant-avatar {
    width: 40px;
    height: 40px;
    background: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.assistant-name {
    font-weight: 600;
    font-size: 1.1rem;
}

.assistant-status {
    font-size: 0.85rem;
    opacity: 0.9;
}

.btn-icon {
    background: transparent;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    width: 30px;
    height: 30px;
    border-radius: 5px;
    transition: background 0.2s;
}

.btn-icon:hover {
    background: rgba(255,255,255,0.2);
}

/* Contact Form */
.contact-form {
    padding: 30px;
    overflow-y: auto;
    flex: 1; /* Ocupa el espacio disponible */
}

.contact-form h3 {
    margin-bottom: 10px;
    color: var(--text-color);
}

.contact-form p {
    margin-bottom: 20px;
    color: var(--secondary-color);
    font-size: 0.9rem;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    color: var(--text-color);
    font-size: 0.9rem;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* ==========================================
   CORRECCIÓN CRÍTICA: Chat Container Layout
   ========================================== */

/* Chat Container - Layout corregido */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    flex: 1; /* Ocupa todo el espacio disponible */
    overflow: hidden; /* Evita overflow del contenedor */
    position: relative; /* Para posicionamiento absoluto de hijos si es necesario */
}

/* Chat Messages - Corregido */
.chat-messages {
    flex: 1; /* Ocupa espacio disponible */
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    background: #f5f5f5;
    /* ✅ CORRECCIÓN: Asegurar que no se superponga con el input */
    padding-bottom: 10px;
    min-height: 0; /* Permite que flex funcione correctamente */
}

/* ✅ CORRECCIÓN CRÍTICA: Chat Input Container */
.chat-input-container {
    display: flex;
    gap: 10px;
    padding: 15px;
    background: white;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0; /* ✅ NO SE ENCOGE - Siempre visible */
    min-height: var(--chat-input-height); /* ✅ Altura mínima garantizada */
    z-index: 10; /* ✅ Asegurar que esté por encima */
    position: relative; /* ✅ Posicionamiento relativo */
}

.message {
    margin-bottom: 15px;
    animation: fadeIn 0.3s ease;
}

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

.message.user {
    display: flex;
    justify-content: flex-end;
}

.message.ai {
    display: flex;
    justify-content: flex-start;
}

.message-content {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: 15px;
    word-wrap: break-word;
    line-height: 1.4;
}

.message.user .message-content {
    background: var(--primary-color);
    color: white;
    border-bottom-right-radius: 5px;
}

.message.ai .message-content {
    background: white;
    color: var(--text-color);
    border-bottom-left-radius: 5px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.message.typing .message-content {
    display: flex;
    gap: 5px;
    align-items: center;
    padding: 16px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--secondary-color);
    border-radius: 50%;
    animation: typingAnimation 1.4s infinite;
}

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

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

@keyframes typingAnimation {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* ✅ Chat Input - Mejorado */
#chat-input {
    flex: 1;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    font-size: 1rem;
    resize: none;
    max-height: 100px;
    min-height: 45px; /* ✅ Altura mínima */
    font-family: inherit;
    line-height: 1.4;
}

#chat-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.btn-send {
    width: 45px;
    height: 45px;
    min-width: 45px; /* ✅ Ancho mínimo garantizado */
    min-height: 45px; /* ✅ Altura mínima garantizada */
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0; /* ✅ No se encoge */
}

.btn-send:hover:not(:disabled) {
    background: var(--primary-dark);
    transform: scale(1.05);
}

.btn-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ✅ Estilos para mensajes de estado */
.message.status-warning .message-content {
    background: #fff3cd;
    color: #856404;
    border-left: 3px solid #ffc107;
}

.message.status-error .message-content {
    background: #f8d7da;
    color: #721c24;
    border-left: 3px solid #dc3545;
}

.message.status-success .message-content {
    background: #d4edda;
    color: #155724;
    border-left: 3px solid #28a745;
}

/* Responsive */
@media (max-width: 768px) {
    .hero-section h1 {
        font-size: 2rem;
    }
    
    .hero-section p {
        font-size: 1.1rem;
    }
    
    .features-section h2 {
        font-size: 2rem;
    }
    
    /* ✅ Chat móvil - Correcciones específicas */
    .chat-widget {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }
    
    .chat-button {
        bottom: 20px;
        right: 20px;
    }
    
    /* ✅ CRÍTICO: Asegurar que el input siempre sea visible en móvil */
    .chat-input-container {
        padding: 10px;
        min-height: 60px;
    }
    
    #chat-input {
        font-size: 16px; /* Prevenir zoom en iOS */
    }
}

/* Scrollbar personalizado */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--secondary-color);
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}

/* ✅ CORRECCIÓN ADICIONAL: Asegurar que todo el contenido sea visible */
.chat-widget.active .chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* ✅ Fix para iOS Safari */
@supports (-webkit-touch-callout: none) {
    .chat-input-container {
        padding-bottom: env(safe-area-inset-bottom, 15px);
    }
}

/* ==========================================
   ESTILOS ADICIONALES PARA CHAT v2.0
   ========================================== */

/* Mensajes del chat - Nuevo formato */
.chat-message {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    animation: fadeIn 0.3s ease;
    align-items: flex-start;
}

.chat-message.user-message {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.user-message .message-avatar {
    background: var(--primary-color);
}

.assistant-message .message-avatar {
    background: white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.message-content {
    max-width: 70%;
    padding: 10px 14px;
    border-radius: 15px;
    word-wrap: break-word;
    line-height: 1.5;
    position: relative;
}

.user-message .message-content {
    background: var(--primary-color);
    color: white;
    border-bottom-right-radius: 5px;
}

.assistant-message .message-content {
    background: white;
    color: var(--text-color);
    border-bottom-left-radius: 5px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.error-message .message-content {
    background: #f8d7da !important;
    color: #721c24 !important;
    border-left: 3px solid #dc3545;
}

.message-time {
    font-size: 0.7rem;
    opacity: 0.6;
    margin-top: 4px;
    text-align: right;
}

.user-message .message-time {
    color: white;
}

.assistant-message .message-time {
    color: var(--secondary-color);
}

/* Indicador de "escribiendo..." */
.typing-indicator {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    align-items: center;
    animation: fadeIn 0.3s ease;
}

.typing-dots {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: white;
    border-radius: 15px;
    border-bottom-left-radius: 5px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

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

.typing-dots span:nth-child(1) {
    animation-delay: 0s;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }
    30% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

/* Links en mensajes */
.message-content a {
    color: inherit;
    text-decoration: underline;
    word-break: break-all;
}

.user-message .message-content a {
    color: white;
}

.assistant-message .message-content a {
    color: var(--primary-color);
}

/* Responsive adicional */
@media (max-width: 768px) {
    .message-content {
        max-width: 80%;
    }
    
    .message-avatar {
        width: 30px;
        height: 30px;
        font-size: 1rem;
    }
}

/* Notificación de sesión restaurada */
.session-restored-notification {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 15px;
    border-radius: 12px;
    margin-bottom: 20px;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
    animation: slideInDown 0.5s ease-out;
    transition: opacity 0.3s ease;
}

.notification-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    flex-wrap: wrap;
}

.notification-icon {
    font-size: 1.5rem;
    animation: rotate 2s linear infinite;
}

.notification-text {
    flex: 1;
    font-weight: 500;
    font-size: 0.95rem;
}

.new-conversation-btn {
    background: white;
    color: var(--primary-color);
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.3s;
    white-space: nowrap;
}

.new-conversation-btn:hover {
    background: rgba(255, 255, 255, 0.9);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

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

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

@keyframes rotate {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* Responsive para notificación */
@media (max-width: 480px) {
    .notification-content {
        flex-direction: column;
        text-align: center;
    }
    
    .new-conversation-btn {
        width: 100%;
    }
}
