/* ============================================
   CHAT WIDGET - Diseño Premium Ultra Moderno
   Glassmorphism + Micro-animaciones + Responsive
   ============================================ */

/* Variables CSS */
:root {
    --chat-primary: #ff006e;
    --chat-primary-rgb: 255, 0, 110;
    --chat-secondary: #8338ec;
    --chat-secondary-rgb: 131, 56, 236;
    --chat-gradient: linear-gradient(135deg, #ff006e 0%, #8338ec 100%);
    --chat-gradient-soft: linear-gradient(135deg, rgba(255, 0, 110, 0.08) 0%, rgba(131, 56, 236, 0.08) 100%);
    --chat-white: #ffffff;
    --chat-bg: #f8fafc;
    --chat-bg-alt: #f1f5f9;
    --chat-text: #1e293b;
    --chat-text-light: #64748b;
    --chat-text-muted: #94a3b8;
    --chat-border: #e2e8f0;
    --chat-border-light: #f1f5f9;
    --chat-shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
    --chat-shadow: 0 10px 40px rgba(0, 0, 0, 0.12);
    --chat-shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.15);
    --chat-radius: 20px;
    --chat-radius-sm: 12px;
    --chat-ease: cubic-bezier(0.4, 0, 0.2, 1);
    --chat-ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --chat-font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ============================================
   BOTÓN FLOTANTE
   ============================================ */
.chat-trigger {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    background: var(--chat-gradient);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow:
        0 4px 16px rgba(var(--chat-primary-rgb), 0.35),
        0 0 0 0 rgba(var(--chat-primary-rgb), 0.2);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.4s var(--chat-ease-spring);
    animation: triggerEntrance 0.6s var(--chat-ease-spring) 0.5s both;
}

@keyframes triggerEntrance {
    from {
        opacity: 0;
        transform: scale(0) rotate(-180deg);
    }
    to {
        opacity: 1;
        transform: scale(1) rotate(0deg);
    }
}

.chat-trigger::before {
    content: '';
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    background: var(--chat-gradient);
    opacity: 0;
    z-index: -1;
    transition: all 0.4s var(--chat-ease);
    animation: triggerRing 3s ease-in-out infinite;
}

@keyframes triggerRing {
    0%, 100% {
        opacity: 0;
        transform: scale(1);
    }
    50% {
        opacity: 0.3;
        transform: scale(1.15);
    }
}

.chat-trigger:hover {
    transform: scale(1.1) translateY(-2px);
    box-shadow:
        0 8px 28px rgba(var(--chat-primary-rgb), 0.45),
        0 0 0 4px rgba(var(--chat-primary-rgb), 0.1);
}

.chat-trigger:active {
    transform: scale(0.92);
}

.trigger-icon {
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    transition: all 0.4s var(--chat-ease-spring);
}

.trigger-icon svg {
    display: block;
}

.trigger-icon-open {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

.trigger-icon-close {
    opacity: 0;
    transform: rotate(90deg) scale(0);
}

.chat-trigger.is-active .trigger-icon-open {
    opacity: 0;
    transform: rotate(-90deg) scale(0);
}

.chat-trigger.is-active .trigger-icon-close {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

.chat-trigger.is-active::before {
    animation: none;
    opacity: 0;
}

/* Badge */
.trigger-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    background: #ef4444;
    border: 2.5px solid white;
    border-radius: 11px;
    color: white;
    font-size: 11px;
    font-weight: 800;
    font-family: var(--chat-font);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: badgePulse 2s ease-in-out infinite;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.5);
}

@keyframes badgePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

/* ============================================
   CONTENEDOR DEL CHAT
   ============================================ */
.chat-widget {
    position: fixed;
    bottom: 96px;
    right: 24px;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 560px;
    max-height: calc(100vh - 130px);
    background: rgba(255, 255, 255, 0.97);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-radius: var(--chat-radius);
    border: 1px solid rgba(255, 255, 255, 0.6);
    box-shadow:
        var(--chat-shadow-lg),
        0 0 0 1px rgba(0, 0, 0, 0.04),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transform: translateY(16px) scale(0.96);
    transform-origin: bottom right;
    transition: all 0.35s var(--chat-ease);
    z-index: 9998;
    overflow: hidden;
    font-family: var(--chat-font);
}

.chat-widget.is-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* ============================================
   HEADER - Gradient Premium
   ============================================ */
.chat-header {
    background: var(--chat-gradient);
    padding: 18px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}

/* Efecto de luz sutil en header */
.chat-header::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at 30% 50%, rgba(255, 255, 255, 0.12) 0%, transparent 50%);
    pointer-events: none;
}

.chat-header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
}

.chat-avatar {
    width: 44px;
    height: 44px;
    background: rgba(255, 255, 255, 0.18);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    flex-shrink: 0;
    transition: transform 0.3s var(--chat-ease);
}

.chat-avatar:hover {
    transform: scale(1.05);
}

.chat-avatar svg {
    display: block;
    width: 22px;
    height: 22px;
}

.chat-avatar::after {
    content: '';
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 13px;
    height: 13px;
    background: #10b981;
    border: 2.5px solid rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    animation: statusPulse 2.5s ease-in-out infinite;
}

@keyframes statusPulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
    }
    50% {
        box-shadow: 0 0 0 5px rgba(16, 185, 129, 0);
    }
}

.chat-info {
    flex: 1;
    min-width: 0;
}

.chat-title {
    font-size: 15px;
    font-weight: 700;
    color: white;
    margin: 0 0 3px 0;
    letter-spacing: -0.01em;
    font-family: var(--chat-font);
}

.chat-status {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.85);
    margin: 0;
    display: flex;
    align-items: center;
    font-weight: 500;
    font-family: var(--chat-font);
}

.chat-status svg {
    flex-shrink: 0;
}

.chat-close {
    width: 34px;
    height: 34px;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.25s var(--chat-ease);
    backdrop-filter: blur(10px);
    flex-shrink: 0;
}

.chat-close:hover {
    background: rgba(255, 255, 255, 0.22);
    transform: rotate(90deg) scale(1.05);
}

.chat-close svg {
    display: block;
    width: 16px;
    height: 16px;
}

/* ============================================
   BODY - MENSAJES
   ============================================ */
.chat-body {
    flex: 1;
    padding: 20px 16px;
    background: var(--chat-bg);
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
    scroll-behavior: smooth;
}

/* Fondo con patrón sutil de gradientes */
.chat-body::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background:
        radial-gradient(ellipse at 10% 20%, rgba(var(--chat-primary-rgb), 0.03) 0%, transparent 50%),
        radial-gradient(ellipse at 90% 80%, rgba(var(--chat-secondary-rgb), 0.03) 0%, transparent 50%);
    pointer-events: none;
}

/* Custom scrollbar */
.chat-body::-webkit-scrollbar {
    width: 5px;
}

.chat-body::-webkit-scrollbar-track {
    background: transparent;
}

.chat-body::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.08);
    border-radius: 10px;
}

.chat-body::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.14);
}

/* Welcome */
.chat-welcome {
    text-align: center;
    padding: 32px 16px;
    position: relative;
    z-index: 1;
}

.welcome-icon {
    width: 72px;
    height: 72px;
    margin: 0 auto 16px;
    background: var(--chat-gradient);
    border-radius: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 24px rgba(var(--chat-primary-rgb), 0.3);
    animation: welcomeFloat 4s ease-in-out infinite;
    position: relative;
}

.welcome-icon::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 26px;
    background: var(--chat-gradient);
    opacity: 0.15;
    z-index: -1;
    animation: welcomeGlow 4s ease-in-out infinite;
}

@keyframes welcomeFloat {
    0%, 100% {
        transform: translateY(0) rotate(0deg);
    }
    50% {
        transform: translateY(-6px) rotate(2deg);
    }
}

@keyframes welcomeGlow {
    0%, 100% { transform: scale(1); opacity: 0.15; }
    50% { transform: scale(1.1); opacity: 0.25; }
}

.welcome-icon svg {
    display: block;
    width: 34px;
    height: 34px;
}

.chat-welcome h3 {
    font-size: 18px;
    font-weight: 800;
    color: var(--chat-text);
    margin: 0 0 6px 0;
    letter-spacing: -0.02em;
    font-family: var(--chat-font);
}

.chat-welcome p {
    font-size: 14px;
    color: var(--chat-text-light);
    margin: 0;
    font-weight: 500;
    line-height: 1.5;
    font-family: var(--chat-font);
}

/* ============================================
   MENSAJES - DISEÑO PREMIUM
   ============================================ */
.chat-message {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
    animation: messageSlideIn 0.45s var(--chat-ease-spring);
    position: relative;
    z-index: 1;
}

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

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

/* Avatar del mensaje */
.message-avatar {
    width: 30px;
    height: 30px;
    min-width: 30px;
    border-radius: 10px;
    background: var(--chat-gradient);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 800;
    font-family: var(--chat-font);
    box-shadow: 0 2px 8px rgba(var(--chat-primary-rgb), 0.2);
    transition: transform 0.3s var(--chat-ease);
    align-self: flex-end;
}

.chat-message:hover .message-avatar {
    transform: scale(1.08);
}

.chat-message.user .message-avatar {
    background: linear-gradient(135deg, #475569 0%, #334155 100%);
    box-shadow: 0 2px 8px rgba(71, 85, 105, 0.2);
}

/* Contenedor del mensaje */
.message-content {
    flex: 1;
    max-width: 78%;
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}

.chat-message.user .message-content {
    align-items: flex-end;
}

/* Burbuja del mensaje */
.message-bubble {
    background: white;
    padding: 10px 14px;
    border-radius: 16px 16px 16px 4px;
    font-size: 13.5px;
    line-height: 1.55;
    color: var(--chat-text);
    box-shadow: var(--chat-shadow-sm);
    word-wrap: break-word;
    word-break: break-word;
    position: relative;
    transition: all 0.25s var(--chat-ease);
    border: 1px solid rgba(0, 0, 0, 0.04);
    font-family: var(--chat-font);
}

/* Burbuja del usuario */
.chat-message.user .message-bubble {
    background: var(--chat-gradient);
    color: white;
    border-radius: 16px 16px 4px 16px;
    border: none;
    box-shadow: 0 3px 14px rgba(var(--chat-primary-rgb), 0.25);
}

/* Hover effect */
.message-bubble:hover {
    transform: translateY(-1px);
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.08);
}

.chat-message.user .message-bubble:hover {
    box-shadow: 0 5px 18px rgba(var(--chat-primary-rgb), 0.35);
}

/* Timestamp */
.message-time {
    font-size: 10px;
    color: var(--chat-text-muted);
    padding: 0 4px;
    display: flex;
    align-items: center;
    gap: 4px;
    opacity: 0;
    transform: translateY(-4px);
    transition: all 0.25s var(--chat-ease);
    font-family: var(--chat-font);
    font-weight: 500;
}

.chat-message:hover .message-time {
    opacity: 0.7;
    transform: translateY(0);
}

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

/* Estado del mensaje */
.message-status {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 10px;
    color: var(--chat-text-muted);
}

.message-status i {
    font-size: 9px;
}

.message-status.sent {
    color: #10b981;
}

.message-status.delivered {
    color: #3b82f6;
}

/* Loading indicator */
.chat-loading {
    display: flex;
    gap: 5px;
    padding: 8px 12px;
    align-items: center;
}

.chat-loading span {
    width: 7px;
    height: 7px;
    background: linear-gradient(135deg, var(--chat-primary), var(--chat-secondary));
    border-radius: 50%;
    animation: loadingBounce 1.4s ease-in-out infinite;
}

.chat-loading span:nth-child(1) { animation-delay: 0s; }
.chat-loading span:nth-child(2) { animation-delay: 0.2s; }
.chat-loading span:nth-child(3) { animation-delay: 0.4s; }

@keyframes loadingBounce {
    0%, 60%, 100% {
        transform: translateY(0) scale(1);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-8px) scale(1.15);
        opacity: 1;
    }
}

/* Separador de fecha */
.chat-date-separator {
    text-align: center;
    margin: 20px 0 14px;
    position: relative;
    z-index: 1;
}

.chat-date-separator::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--chat-border), transparent);
}

.chat-date-separator span {
    display: inline-block;
    padding: 4px 14px;
    background: var(--chat-bg);
    border-radius: 20px;
    font-size: 10px;
    font-weight: 700;
    color: var(--chat-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    position: relative;
    font-family: var(--chat-font);
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
    animation: messageSlideIn 0.4s var(--chat-ease);
}

.typing-indicator .message-avatar {
    align-self: flex-end;
}

.typing-indicator .message-content {
    max-width: 78%;
}

.typing-indicator .message-bubble {
    padding: 10px 14px;
    background: white;
    box-shadow: var(--chat-shadow-sm);
    border: 1px solid rgba(0, 0, 0, 0.04);
    border-radius: 16px 16px 16px 4px;
}

.typing-indicator .chat-loading {
    padding: 0;
}

/* Mensaje del sistema */
.chat-system-message {
    text-align: center;
    margin: 14px 0;
    padding: 6px 14px;
    background: rgba(59, 130, 246, 0.08);
    border-radius: 10px;
    font-size: 11px;
    color: #3b82f6;
    animation: messageSlideIn 0.4s var(--chat-ease);
    font-weight: 600;
    font-family: var(--chat-font);
    border: 1px solid rgba(59, 130, 246, 0.1);
}

.chat-system-message i {
    margin-right: 5px;
}

/* ============================================
   FOOTER - INPUT PREMIUM
   ============================================ */
.chat-footer {
    padding: 14px 16px 16px;
    background: white;
    border-top: 1px solid var(--chat-border-light);
    flex-shrink: 0;
}

.chat-form {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    padding: 10px 14px;
    border: 2px solid var(--chat-border);
    border-radius: var(--chat-radius-sm);
    font-size: 13.5px;
    font-family: var(--chat-font);
    color: var(--chat-text);
    background: var(--chat-bg);
    transition: all 0.25s var(--chat-ease);
    line-height: 1.4;
    min-height: 42px;
    resize: none;
}

.chat-input:focus {
    outline: none;
    border-color: var(--chat-primary);
    background: white;
    box-shadow: 0 0 0 3px rgba(var(--chat-primary-rgb), 0.08);
}

.chat-input::placeholder {
    color: var(--chat-text-muted);
    font-weight: 400;
}

.chat-send {
    width: 42px;
    height: 42px;
    min-width: 42px;
    background: var(--chat-gradient);
    border: none;
    border-radius: var(--chat-radius-sm);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.25s var(--chat-ease-spring);
    flex-shrink: 0;
}

.chat-send:hover {
    transform: translateY(-2px) scale(1.03);
    box-shadow: 0 4px 14px rgba(var(--chat-primary-rgb), 0.35);
}

.chat-send:active {
    transform: translateY(0) scale(0.95);
}

.chat-send svg {
    display: block;
    width: 18px;
    height: 18px;
}

.chat-disclaimer {
    font-size: 10px;
    color: var(--chat-text-muted);
    text-align: center;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    font-family: var(--chat-font);
    font-weight: 500;
}

.chat-disclaimer svg {
    flex-shrink: 0;
    opacity: 0.6;
}

/* ============================================
   FORMULARIO DE DATOS
   ============================================ */
.chat-info-form {
    animation: messageSlideIn 0.45s var(--chat-ease-spring);
    position: relative;
    z-index: 1;
}

.chat-info-form .chat-message {
    margin-bottom: 16px;
}

.user-info-form {
    background: white;
    padding: 20px;
    border-radius: 16px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
    border: 1px solid rgba(0, 0, 0, 0.06);
}

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

.form-group:last-of-type {
    margin-bottom: 18px;
}

.form-group label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 700;
    color: var(--chat-text);
    margin-bottom: 6px;
    font-family: var(--chat-font);
    letter-spacing: -0.01em;
}

.form-group label i {
    color: var(--chat-primary);
    font-size: 11px;
}

.form-group input {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid var(--chat-border);
    border-radius: 10px;
    font-size: 13.5px;
    font-family: var(--chat-font);
    color: var(--chat-text);
    transition: all 0.25s var(--chat-ease);
    box-sizing: border-box;
    background: var(--chat-bg);
}

.form-group input:focus {
    outline: none;
    border-color: var(--chat-primary);
    background: white;
    box-shadow: 0 0 0 3px rgba(var(--chat-primary-rgb), 0.08);
}

.form-group input::placeholder {
    color: var(--chat-text-muted);
}

.form-submit {
    width: 100%;
    padding: 12px 18px;
    background: var(--chat-gradient);
    border: none;
    border-radius: 10px;
    color: white;
    font-size: 14px;
    font-weight: 700;
    font-family: var(--chat-font);
    cursor: pointer;
    transition: all 0.3s var(--chat-ease-spring);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 4px 14px rgba(var(--chat-primary-rgb), 0.3);
    letter-spacing: -0.01em;
}

.form-submit:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 22px rgba(var(--chat-primary-rgb), 0.4);
}

.form-submit:active {
    transform: translateY(0);
}

.form-submit svg {
    flex-shrink: 0;
}

/* ============================================
   RESPONSIVE - Cobertura completa
   ============================================ */

/* === Large tablets & small desktops (1024px+) === */
@media (min-width: 1025px) {
    .chat-widget {
        width: 400px;
        height: 580px;
    }
}

/* === Tablets landscape & iPad Pro (768px - 1024px) === */
@media (min-width: 768px) and (max-width: 1024px) {
    .chat-trigger {
        bottom: 20px;
        right: 20px;
        width: 56px;
        height: 56px;
    }

    .chat-widget {
        bottom: 88px;
        right: 20px;
        width: 380px;
        height: 540px;
    }
}

/* === iPad Mini portrait, Samsung Tabs (600px - 767px) === */
@media (min-width: 600px) and (max-width: 767px) {
    .chat-trigger {
        bottom: 18px;
        right: 18px;
        width: 54px;
        height: 54px;
    }

    .chat-widget {
        bottom: 84px;
        right: 18px;
        width: 360px;
        max-width: calc(100vw - 36px);
        height: 520px;
    }
}

/* === Large phones (480px - 599px): Galaxy S20 Ultra, iPhone 14 Pro Max === */
@media (min-width: 480px) and (max-width: 599px) {
    .chat-trigger {
        bottom: 16px;
        right: 16px;
        width: 52px;
        height: 52px;
    }

    .chat-trigger .trigger-icon-open svg {
        width: 24px;
        height: 24px;
    }

    .chat-widget {
        bottom: 78px;
        right: 12px;
        left: 12px;
        width: auto;
        max-width: none;
        height: 420px;
        max-height: 65vh;
        border-radius: 18px;
    }

    .chat-header {
        padding: 14px 16px;
    }

    .chat-avatar {
        width: 38px;
        height: 38px;
        border-radius: 12px;
    }

    .chat-avatar svg {
        width: 18px;
        height: 18px;
    }

    .chat-title {
        font-size: 14px;
    }

    .chat-body {
        padding: 14px 12px;
    }

    .chat-footer {
        padding: 10px 12px 12px;
    }

    .chat-input {
        font-size: 16px;
        min-height: 40px;
    }
}

/* === Medium phones (414px - 479px): iPhone XR, iPhone 12 Pro, Pixel 7 === */
@media (min-width: 414px) and (max-width: 479px) {
    .chat-trigger {
        bottom: 16px;
        right: 16px;
        width: 52px;
        height: 52px;
    }

    .chat-trigger .trigger-icon-open svg {
        width: 24px;
        height: 24px;
    }

    .chat-widget {
        bottom: 78px;
        right: 10px;
        left: 10px;
        width: auto;
        max-width: none;
        height: 420px;
        max-height: 65vh;
        border-radius: 18px;
        transform-origin: bottom right;
    }

    .chat-header {
        padding: 14px 16px;
    }

    .chat-avatar {
        width: 38px;
        height: 38px;
        border-radius: 12px;
    }

    .chat-avatar svg {
        width: 18px;
        height: 18px;
    }

    .chat-title {
        font-size: 14px;
    }

    .chat-status {
        font-size: 11px;
    }

    .chat-body {
        padding: 14px 12px;
    }

    .welcome-icon {
        width: 56px;
        height: 56px;
        border-radius: 16px;
    }

    .welcome-icon svg {
        width: 26px;
        height: 26px;
    }

    .chat-welcome {
        padding: 20px 12px;
    }

    .chat-welcome h3 {
        font-size: 16px;
    }

    .chat-welcome p {
        font-size: 13px;
    }

    .message-content {
        max-width: 82%;
    }

    .message-bubble {
        font-size: 13px;
        padding: 9px 12px;
    }

    .chat-footer {
        padding: 10px 12px 12px;
    }

    .chat-input {
        font-size: 16px; /* Prevenir zoom en iOS */
        padding: 9px 12px;
        min-height: 38px;
    }

    .chat-send {
        width: 38px;
        height: 38px;
        min-width: 38px;
    }

    .chat-disclaimer {
        font-size: 9px;
    }

    .message-avatar {
        width: 28px;
        height: 28px;
        min-width: 28px;
        font-size: 10px;
        border-radius: 9px;
    }
}

/* === Small phones (375px - 413px): iPhone SE, Galaxy S8+, Galaxy A51/71 === */
@media (min-width: 375px) and (max-width: 413px) {
    .chat-trigger {
        bottom: 14px;
        right: 14px;
        width: 50px;
        height: 50px;
    }

    .chat-trigger .trigger-icon-open svg {
        width: 22px;
        height: 22px;
    }

    .chat-trigger .trigger-icon-close svg {
        width: 20px;
        height: 20px;
    }

    .chat-widget {
        bottom: 74px;
        right: 10px;
        left: 10px;
        width: auto;
        max-width: none;
        height: 400px;
        max-height: 65vh;
        border-radius: 16px;
        transform-origin: bottom right;
    }

    .chat-header {
        padding: 12px 14px;
        gap: 10px;
    }

    .chat-avatar {
        width: 38px;
        height: 38px;
        border-radius: 11px;
    }

    .chat-avatar svg {
        width: 18px;
        height: 18px;
    }

    .chat-avatar::after {
        width: 11px;
        height: 11px;
        border-width: 2px;
    }

    .chat-title {
        font-size: 13.5px;
    }

    .chat-status {
        font-size: 11px;
    }

    .chat-close {
        width: 32px;
        height: 32px;
    }

    .chat-close svg {
        width: 14px;
        height: 14px;
    }

    .chat-body {
        padding: 14px 12px;
    }

    .chat-welcome {
        padding: 24px 12px;
    }

    .welcome-icon {
        width: 60px;
        height: 60px;
        border-radius: 16px;
    }

    .welcome-icon svg {
        width: 28px;
        height: 28px;
    }

    .chat-welcome h3 {
        font-size: 16px;
    }

    .chat-welcome p {
        font-size: 13px;
    }

    .message-content {
        max-width: 85%;
    }

    .message-bubble {
        font-size: 13px;
        padding: 9px 11px;
        border-radius: 14px 14px 14px 4px;
    }

    .chat-message.user .message-bubble {
        border-radius: 14px 14px 4px 14px;
    }

    .message-avatar {
        width: 26px;
        height: 26px;
        min-width: 26px;
        font-size: 10px;
        border-radius: 8px;
    }

    .chat-message {
        gap: 6px;
        margin-bottom: 12px;
    }

    .chat-footer {
        padding: 10px 12px;
    }

    .chat-form {
        gap: 8px;
        margin-bottom: 6px;
    }

    .chat-input {
        font-size: 16px;
        padding: 9px 12px;
        min-height: 38px;
        border-radius: 10px;
    }

    .chat-send {
        width: 38px;
        height: 38px;
        min-width: 38px;
        border-radius: 10px;
    }

    .chat-send svg {
        width: 16px;
        height: 16px;
    }

    .chat-disclaimer {
        font-size: 9px;
    }

    /* Formulario de datos adaptado */
    .user-info-form {
        padding: 16px;
    }

    .form-group input {
        padding: 9px 12px;
        font-size: 16px;
    }

    .form-submit {
        padding: 11px 16px;
        font-size: 13px;
    }
}

/* === Very small phones (320px - 374px): iPhone SE, Galaxy Z Fold === */
@media (max-width: 374px) {
    .chat-trigger {
        bottom: 12px;
        right: 12px;
        width: 48px;
        height: 48px;
    }

    .chat-trigger .trigger-icon-open svg {
        width: 20px;
        height: 20px;
    }

    .chat-trigger .trigger-icon-close svg {
        width: 18px;
        height: 18px;
    }

    .trigger-badge {
        min-width: 18px;
        height: 18px;
        font-size: 9px;
        padding: 0 4px;
        border-width: 2px;
    }

    .chat-widget {
        bottom: 68px;
        right: 8px;
        left: 8px;
        width: auto;
        max-width: none;
        height: 380px;
        max-height: 60vh;
        border-radius: 14px;
        transform-origin: bottom right;
    }

    .chat-header {
        padding: 10px 12px;
        gap: 8px;
    }

    .chat-avatar {
        width: 34px;
        height: 34px;
        border-radius: 10px;
    }

    .chat-avatar svg {
        width: 16px;
        height: 16px;
    }

    .chat-avatar::after {
        width: 10px;
        height: 10px;
        border-width: 2px;
    }

    .chat-title {
        font-size: 13px;
    }

    .chat-status {
        font-size: 10px;
    }

    .chat-close {
        width: 30px;
        height: 30px;
        border-radius: 8px;
    }

    .chat-close svg {
        width: 13px;
        height: 13px;
    }

    .chat-body {
        padding: 12px 10px;
    }

    .chat-welcome {
        padding: 20px 8px;
    }

    .welcome-icon {
        width: 54px;
        height: 54px;
        border-radius: 14px;
        margin-bottom: 12px;
    }

    .welcome-icon::after {
        border-radius: 18px;
        inset: -3px;
    }

    .welcome-icon svg {
        width: 24px;
        height: 24px;
    }

    .chat-welcome h3 {
        font-size: 15px;
    }

    .chat-welcome p {
        font-size: 12px;
    }

    .message-content {
        max-width: 88%;
    }

    .message-bubble {
        font-size: 12.5px;
        padding: 8px 10px;
        border-radius: 12px 12px 12px 3px;
    }

    .chat-message.user .message-bubble {
        border-radius: 12px 12px 3px 12px;
    }

    .message-avatar {
        width: 24px;
        height: 24px;
        min-width: 24px;
        font-size: 9px;
        border-radius: 7px;
    }

    .chat-message {
        gap: 5px;
        margin-bottom: 10px;
    }

    .chat-footer {
        padding: 8px 10px;
    }

    .chat-form {
        gap: 6px;
        margin-bottom: 5px;
    }

    .chat-input {
        font-size: 16px;
        padding: 8px 10px;
        min-height: 36px;
        border-radius: 9px;
        border-width: 1.5px;
    }

    .chat-send {
        width: 36px;
        height: 36px;
        min-width: 36px;
        border-radius: 9px;
    }

    .chat-send svg {
        width: 15px;
        height: 15px;
    }

    .chat-disclaimer {
        font-size: 8px;
    }

    .chat-disclaimer svg {
        width: 10px;
        height: 10px;
    }

    /* Formulario de datos */
    .user-info-form {
        padding: 14px;
        border-radius: 12px;
    }

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

    .form-group label {
        font-size: 11px;
        gap: 4px;
    }

    .form-group input {
        padding: 8px 10px;
        font-size: 16px;
        border-radius: 8px;
    }

    .form-submit {
        padding: 10px 14px;
        font-size: 12.5px;
        border-radius: 8px;
    }

    .chat-date-separator span {
        font-size: 9px;
        padding: 3px 10px;
    }

    .chat-system-message {
        font-size: 10px;
        padding: 5px 10px;
    }

    .typing-indicator .message-content {
        max-width: 88%;
    }
}

/* === Foldable devices (Surface Duo, Galaxy Z Fold) === */
@media (min-width: 540px) and (max-width: 599px) and (min-height: 700px) {
    .chat-widget {
        bottom: 80px;
        right: 12px;
        left: 12px;
        width: auto;
        max-width: none;
        height: calc(100vh - 110px);
        border-radius: 18px;
    }

    .chat-trigger {
        width: 54px;
        height: 54px;
    }
}

/* === Landscape phones === */
@media (max-width: 900px) and (max-height: 500px) and (orientation: landscape) {
    .chat-trigger {
        bottom: 10px;
        right: 10px;
        width: 44px;
        height: 44px;
    }

    .chat-trigger .trigger-icon-open svg {
        width: 20px;
        height: 20px;
    }

    .chat-widget {
        position: fixed;
        top: 0;
        bottom: 0;
        right: 0;
        left: auto;
        width: 360px;
        max-width: 60vw;
        height: 100%;
        max-height: 100%;
        border-radius: 16px 0 0 16px;
        transform-origin: right center;
    }

    .chat-widget.is-open {
        border-radius: 16px 0 0 16px;
    }

    .chat-header {
        padding: 10px 14px;
    }

    .chat-avatar {
        width: 32px;
        height: 32px;
        border-radius: 9px;
    }

    .chat-avatar svg {
        width: 16px;
        height: 16px;
    }

    .chat-title {
        font-size: 13px;
    }

    .chat-status {
        font-size: 10px;
    }

    .chat-body {
        padding: 10px;
    }

    .chat-welcome {
        padding: 16px 8px;
    }

    .welcome-icon {
        width: 48px;
        height: 48px;
        border-radius: 14px;
        margin-bottom: 10px;
    }

    .welcome-icon svg {
        width: 22px;
        height: 22px;
    }

    .chat-welcome h3 {
        font-size: 14px;
    }

    .chat-welcome p {
        font-size: 12px;
    }

    .chat-footer {
        padding: 8px 10px;
    }

    .chat-input {
        font-size: 13px;
        min-height: 34px;
        padding: 7px 10px;
    }

    .chat-send {
        width: 34px;
        height: 34px;
        min-width: 34px;
    }

    .chat-disclaimer {
        display: none;
    }

    .message-avatar {
        width: 24px;
        height: 24px;
        min-width: 24px;
        font-size: 9px;
    }

    .message-bubble {
        font-size: 12px;
        padding: 7px 10px;
    }
}

/* === Nest Hub / Nest Hub Max (landscape, large touch) === */
@media (min-width: 1024px) and (max-height: 700px) {
    .chat-widget {
        height: 480px;
        max-height: calc(100vh - 120px);
    }

    .chat-trigger {
        bottom: 16px;
        right: 16px;
    }
}

/* === High DPI / Retina support === */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .chat-widget {
        border: 0.5px solid rgba(255, 255, 255, 0.6);
    }
}

/* === Prefers reduced motion === */
@media (prefers-reduced-motion: reduce) {
    .chat-trigger,
    .chat-trigger::before,
    .chat-widget,
    .trigger-icon,
    .chat-avatar,
    .chat-close,
    .message-bubble,
    .message-avatar,
    .message-time,
    .chat-input,
    .chat-send,
    .welcome-icon,
    .form-submit {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
    }

    .welcome-icon::after,
    .chat-trigger::before {
        animation: none !important;
    }
}

/* Animación fadeOut */
@keyframes fadeOut {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-8px);
    }
}
