/* Chat Widget Styles */
.n8n-chat-widget {
    --chat--color-primary: var(--n8n-chat-primary-color, #854fff);
    --chat--color-secondary: var(--n8n-chat-secondary-color, #6b3fd4);
    --chat--color-background: var(--n8n-chat-background-color, #ffffff);
    --chat--color-font: var(--n8n-chat-font-color, #333333);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    -webkit-text-size-adjust: 100%;
}

/* Chat Container */
.n8n-chat-widget .chat-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    display: none;
    width: 580px;
    height: 650px;
    background: var(--chat--color-background);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(133, 79, 255, 0.15);
    border: 1px solid rgba(133, 79, 255, 0.2);
    overflow: hidden;
    font-family: inherit;
    transition: transform 0.3s ease, opacity 0.3s ease;
    transform: translateY(20px);
    opacity: 0;
    -webkit-overflow-scrolling: touch;
    touch-action: manipulation;
}

/* Estado maximizado del chat */
.n8n-chat-widget .chat-container.maximized {
    width: 90vw;
    height: 90vh;
    left: 5vw;
    right: auto;
    bottom: 5vh;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.3);
}

/* Chat Toggle Button */
.n8n-chat-widget .chat-toggle {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: white;
    border: none;
    border-radius: 35px;
    padding: 16px 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    transition: transform 0.3s, box-shadow 0.3s;
    min-width: 278px;
    z-index: 999;
    -webkit-tap-highlight-color: transparent; /* Eliminar efecto de tap en iOS */
}

.n8n-chat-widget .chat-toggle:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 28px rgba(0, 0, 0, 0.15);
}

.n8n-chat-widget .chat-toggle.position-left {
    right: auto;
    left: 20px;
}

.n8n-chat-widget .logo {
    width: 40px;
    height: 45px;
    border-radius: 50%;
    overflow: hidden;
}

.n8n-chat-widget .logo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.n8n-chat-widget .content {
    flex: 1;
}

.n8n-chat-widget .title {
    font-size: 14px;
    font-weight: 600;
    color: #000;
    margin: 0;
    text-align: left;
}

.n8n-chat-widget .call-button {
    background: #efebe9;
    color: #000000;
    border: none;
    border-radius: 100px;
    padding: 12px 24px;
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 7px;
    cursor: pointer;
    transition: background-color 0.2s;
    -webkit-tap-highlight-color: transparent; /* Eliminar efecto de tap en iOS */
}

.n8n-chat-widget .call-button:hover {
    background: #333;
}

.n8n-chat-widget .call-button svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

@media (max-width: 480px) {
    .n8n-chat-widget {
        padding: 0;
        margin: 0;
    }
    .n8n-chat-widget .chat-container {
        width: 100%;
        height: 100%;
        bottom: 0;
        right: 0;
        left: 0;
        border-radius: 0;
        margin: 0;
        transform: translateY(100%);
    }
    
    .n8n-chat-widget .chat-container.open {
        transform: translateY(0) !important;
    }
    
    .n8n-chat-widget .chat-container.position-left {
        right: 0;
        left: auto;
    }
    
    .n8n-chat-widget .chat-toggle {
        width: 270px;
        min-width: 0;
        bottom: 10px;
        right: 10px;
        left: 10px;
    }
    
    .n8n-chat-widget .chat-toggle.position-left {
        right: 10px;
        left: 10px;
    }
}

.n8n-chat-widget .chat-container.position-left {
    right: auto;
    left: 20px;
}

.n8n-chat-widget .chat-container.open {
    display: flex;
    flex-direction: column;
    transform: translateY(0);
    opacity: 1;
}

/* Brand Header */
.n8n-chat-widget .brand-header {
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(133, 79, 255, 0.1);
    position: relative;
    background: var(--chat--color-background);
    z-index: 2;
}

/* Botones de control en la cabecera */
.n8n-chat-widget .header-controls {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    gap: 8px;
}

/* Ocultar bot��n de maximizar */
.n8n-chat-widget .maximize-button {
    display: none !important;
}

.n8n-chat-widget .maximize-button,
.n8n-chat-widget .close-button {
    background: none;
    border: none;
    color: var(--chat--color-font);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
    font-size: 20px;
    opacity: 0.6;
    -webkit-tap-highlight-color: transparent; /* Eliminar efecto de tap en iOS */
}

.n8n-chat-widget .maximize-button:hover,
.n8n-chat-widget .close-button:hover {
    opacity: 1;
    background-color: rgba(133, 79, 255, 0.1);
}

.n8n-chat-widget .close-button {
    padding: 8px;
}

.n8n-chat-widget .brand-header img {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    object-fit: cover;
}

.n8n-chat-widget .brand-header span {
    font-size: 18px;
    font-weight: 500;
    color: var(--chat--color-font);
}

/* New Conversation */
.n8n-chat-widget .new-conversation {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 0px;
    text-align: center;
    width: 100%;
    max-width: 300px;
}

.n8n-chat-widget .welcome-text {
    font-size: 20px;
    font-weight: 600;
    color: var(--chat--color-font);
    margin-bottom: 24px;
    line-height: 1.3;
}

.n8n-chat-widget .new-chat-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 16px 24px;
    background: #efebe9;
    color: rgb(0, 0, 0);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    transition: transform 0.3s, box-shadow 0.3s;
    font-weight: 500;
    font-family: inherit;
    margin-bottom: 12px;
    box-shadow: 0 4px 12px rgba(133, 79, 255, 0.2);
    -webkit-tap-highlight-color: transparent; /* Eliminar efecto de tap en iOS */
}

.n8n-chat-widget .new-chat-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(133, 79, 255, 0.3);
}

.n8n-chat-widget .message-icon {
    width: 20px;
    height: 20px;
}

.n8n-chat-widget .response-text {
    font-size: 14px;
    color: var(--chat--color-font);
    opacity: 0.7;
    margin: 0;
}

/* Chat Interface */
.n8n-chat-widget .chat-interface {
    display: none;
    flex-direction: column;
    height: 100%;
    background: var(--chat--color-background);
}

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

.n8n-chat-widget .chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: var(--chat--color-background);
    display: flex;
    flex-direction: column;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

.n8n-chat-widget .chat-messages::-webkit-scrollbar {
    width: 6px;
}

.n8n-chat-widget .chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.n8n-chat-widget .chat-messages::-webkit-scrollbar-thumb {
    background: rgba(133, 79, 255, 0.2);
    border-radius: 3px;
}

/* Chat Messages */
.n8n-chat-widget .chat-message {
    padding: 12px 16px;
    margin: 8px 0;
    border-radius: 12px;
    max-width: 80%;
    word-wrap: break-word;
    font-size: 14px;
    line-height: 1.5;
    animation: messageAppear 0.3s ease-out;
    position: relative;
    touch-action: manipulation;
}

/* Timestamp styles */
.n8n-chat-widget .message-timestamp {
    font-size: 10px;
    color: rgba(51, 51, 51, 0.6);
    margin-top: 4px;
    text-align: right;
}

.n8n-chat-widget .chat-message.user .message-timestamp {
    color: rgba(255, 255, 255, 0.7);
}

/* Quick Reply Buttons - Ubicados arriba del input */
.n8n-chat-widget .quick-replies-container {
    padding: 10px 16px;
    border-top: 1px solid rgba(133, 79, 255, 0.1);
    display: none; /* Oculto por defecto */
}

.n8n-chat-widget .quick-replies-container.visible {
    display: none;
    animation: fadeIn 0.3s ease-out;
}

.n8n-chat-widget .quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.n8n-chat-widget .quick-reply-button {
    padding: 8px 16px;
    background: transparent;
    color: var(--chat--color-primary);
    border: 1px solid var(--chat--color-primary);
    border-radius: 16px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    max-width: 200px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent; /* Eliminar efecto de tap en iOS */
}

.n8n-chat-widget .quick-reply-button:hover {
    background: rgba(133, 79, 255, 0.1);
    transform: translateY(-1px);
}

.n8n-chat-widget .quick-reply-button.active {
    background: linear-gradient(135deg, var(--chat--color-primary) 0%, var(--chat--color-secondary) 100%);
    color: white;
    border-color: transparent;
}

/* Rich Text Formatting para mensajes del bot */
.n8n-chat-widget .message-content {
    overflow-wrap: break-word;
}

/* Estilos para listas */
.n8n-chat-widget .message-content ul, 
.n8n-chat-widget .message-content ol {
    margin-top: 8px;
    margin-bottom: 8px;
    padding-left: 20px;
}

.n8n-chat-widget .message-content ul {
    list-style-type: disc;
}

.n8n-chat-widget .message-content ol {
    list-style-type: decimal;
}

.n8n-chat-widget .message-content li {
    margin-bottom: 4px;
}

/* Estilos para encabezados */
.n8n-chat-widget .message-content h1,
.n8n-chat-widget .message-content h2,
.n8n-chat-widget .message-content h3,
.n8n-chat-widget .message-content h4 {
    margin-top: 12px;
    margin-bottom: 8px;
    font-weight: 600;
}

.n8n-chat-widget .message-content h1 {
    font-size: 18px;
}

.n8n-chat-widget .message-content h2 {
    font-size: 16px;
}

.n8n-chat-widget .message-content h3 {
    font-size: 15px;
}

/* Estilos para párrafos */
.n8n-chat-widget .message-content p {
    margin-bottom: 8px;
}

/* Estilos para formato de texto */
.n8n-chat-widget .message-content strong,
.n8n-chat-widget .message-content b {
    font-weight: 700;
}

.n8n-chat-widget .message-content em,
.n8n-chat-widget .message-content i {
    font-style: italic;
}

.n8n-chat-widget .message-content a {
    color: var(--chat--color-primary);
    text-decoration: underline;
    transition: opacity 0.2s;
}

.n8n-chat-widget .message-content a:hover {
    opacity: 0.8;
}

/* Estilos para bloques de código */
.n8n-chat-widget .message-content pre,
.n8n-chat-widget .message-content code {
    background-color: rgba(0, 0, 0, 0.05);
    border-radius: 4px;
    font-family: 'Courier New', monospace;
}

.n8n-chat-widget .message-content pre {
    padding: 10px;
    overflow-x: auto;
    margin: 8px 0;
}

.n8n-chat-widget .message-content code {
    padding: 2px 4px;
}

/* Estilos para citas */
.n8n-chat-widget .message-content blockquote {
    border-left: 3px solid var(--chat--color-primary);
    padding-left: 12px;
    margin: 8px 0;
    color: rgba(0, 0, 0, 0.7);
    font-style: italic;
}

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

.n8n-chat-widget .chat-message.user {
    background: linear-gradient(135deg, var(--chat--color-primary) 0%, var(--chat--color-secondary) 100%);
    color: white;
    align-self: flex-end;
    box-shadow: 0 4px 12px rgba(133, 79, 255, 0.2);
    border: none;
}

.n8n-chat-widget .chat-message.bot {
    background: var(--chat--color-background);
    border: 1px solid rgba(16, 16, 16, 0.2);
    color: var(--chat--color-font);
    align-self: flex-start;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

/* Chat Input */
.n8n-chat-widget .chat-input {
    padding: 16px;
    background: var(--chat--color-background);
    border-top: 1px solid rgba(133, 79, 255, 0.1);
    display: flex;
    gap: 8px;
    position: relative;
}

.n8n-chat-widget .chat-input textarea {
    flex: 1;
    padding: 12px;
    border: 1px solid rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    background: var(--chat--color-background);
    color: var(--chat--color-font);
    resize: none;
    font-family: inherit;
    font-size: 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
    line-height: 1.5;
    max-height: 120px;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.n8n-chat-widget .chat-input textarea:focus {
    outline: none;
    border-color: var(--chat--color-primary);
    box-shadow: 0 0 0 3px rgba(133, 79, 255, 0.1);
}

.n8n-chat-widget .chat-input textarea::placeholder {
    color: var(--chat--color-font);
    opacity: 0.6;
}

.n8n-chat-widget .chat-input button {
    background: black;
    color: white;
    border: none;
    border-radius: 50%;
    width: 45px;
    height: 45px;
    padding: 0;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    font-family: inherit;
    font-weight: 500;
    box-shadow: 0 2px 8px rgba(133, 79, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    -webkit-tap-highlight-color: transparent; /* Eliminar efecto de tap en iOS */
}

.n8n-chat-widget .chat-input button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(133, 79, 255, 0.3);
}

.n8n-chat-widget .chat-input button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.n8n-chat-widget .chat-input button svg {
    width: 20px;
    height: 20px;
}

/* Footer */
.n8n-chat-widget .chat-footer {
    padding: 8px;
    text-align: center;
    background: var(--chat--color-background);
    border-top: 1px solid rgba(133, 79, 255, 0.1);
}

.n8n-chat-widget .chat-footer a {
    color: var(--chat--color-primary);
    text-decoration: none;
    font-size: 12px;
    opacity: 0.8;
    transition: opacity 0.2s;
    font-family: inherit;
}

.n8n-chat-widget .chat-footer a:hover {
    opacity: 1;
}

/* GIF Container */
.n8n-chat-widget .gif-container {
    width: 200px;
    height: 200px;
    margin: 0 auto;
    overflow: hidden;
    text-align: center;
    border-radius: 100px;
    box-shadow: 0 4px 12px rgba(133, 79, 255, 0.15);
}

.n8n-chat-widget .gif-container img {
    max-width: 100%;
    max-height: 100%;
    display: block;
    margin: 0 auto;
    object-fit: contain;
}

/* Typing Indicator with GIF */
.n8n-chat-widget .typing-indicator {
    width: 50px;
    height: 50px;
    margin: 10px;
}

.n8n-chat-widget .typing-indicator img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

@media (max-width: 480px) {
    .n8n-chat-widget {
        padding: 0;
        margin: 0;
    }
    .n8n-chat-widget .chat-container {
        width: 100%;
        height: 100%;
        bottom: 0;
        right: 0;
        left: 0;
        border-radius: 0;
        margin: 0;
        transform: translateY(100%);
    }
    
    .n8n-chat-widget .chat-container.open {
        transform: translateY(0) !important;
    }
    
    .n8n-chat-widget .chat-container.position-left {
        right: 0;
        left: auto;
    }
    
    .n8n-chat-widget .chat-toggle {
        width: 270px;
        min-width: 0;
        bottom: 10px;
        right: 10px;
        left: 10px;
    }
    
    .n8n-chat-widget .chat-toggle.position-left {
        right: 10px;
        left: 10px;
    }
}

@media (max-width: 480px) {
    .n8n-chat-widget .chat-toggle {
        width: 290px;
        min-width: 0;
        bottom: 10px;
        right: 10px;
        left: 10px;
    }
}

/* Safari-specific fixes */
@supports (-webkit-touch-callout: none) {
    .n8n-chat-widget input,
    .n8n-chat-widget textarea,
    .n8n-chat-widget button {
        font-size: 16px; /* Prevent zoom on focus in Safari */
    }
    
    .n8n-chat-widget .chat-input textarea {
        transform: translateZ(0); /* Fix for Safari text selection issues */
    }
    
    .n8n-chat-widget * {
        -webkit-tap-highlight-color: transparent; /* Remove tap highlight */
    }
}

/* Arreglos espec��ficos para iOS */
@supports (-webkit-touch-callout: none) and (not (translate: none)) {
    /* Selector espec��fico para iOS que no soporta la propiedad translate */
    .n8n-chat-widget * {
        cursor: pointer; /* Asegurar que todos los elementos interactivos tengan cursor pointer */
    }
    
    .n8n-chat-widget button {
        padding: 10px; /* Asegurar ��reas de toque m��s grandes */
    }
    
    /* Mejora espec��fica para el bot��n de env��o en iOS */
    .n8n-chat-widget .chat-input button {
        min-width: 45px;
        min-height: 45px;
        transform: translateZ(0);
        will-change: transform;
        z-index: 10;
    }
    
    /* Mejora espec��fica para el bot��n de cierre en iOS */
    .n8n-chat-widget .close-button {
        min-width: 30px;
        min-height: 30px;
        transform: translateZ(0);
        will-change: transform;
        z-index: 10;
        font-size: 24px;
    }
}

/* Overlay para el chat maximizado */
.n8n-chat-widget .chat-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1050;
}

.n8n-chat-widget .chat-overlay.visible {
    display: block;
}