/**
 * Universal n8n Chat - Stylesheet
 * Version 2.3.0
 * Removed: dark mode styles, emoji picker styles, settings panel styles, command suggestions styles.
 * Only admin-controlled colors. Header has download + clear buttons.
 *
 * @package UnivN8nChat
 */

/* ============================================
   CSS CUSTOM PROPERTIES (Variables)
   ============================================ */
:root {
    /* Color Palette */
    --chat--color-primary: #6366f1;
    --chat--color-primary-shade-50: #4f46e5;
    --chat--color-primary-shade-100: #4338ca;
    --chat--color-secondary: #8b5cf6;
    --chat--color-secondary-shade-50: #7c3aed;

    --chat--color-white: #ffffff;
    --chat--color-light: #f1f5f9;
    --chat--color-light-shade-50: #e2e8f0;
    --chat--color-light-shade-100: #cbd5e1;

    --chat--color-medium: #94a3b8;
    --chat--color-dark: #1e293b;
    --chat--color-darker: #0f172a;

    /* Status Colors */
    --chat--color-success: #22c55e;
    --chat--color-warning: #f59e0b;
    --chat--color-error: #ef4444;
    --chat--color-info: #3b82f6;

    /* Typography */
    --chat--font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --chat--font-size-base: 0.95rem;
    --chat--font-size-sm: 0.875rem;
    --chat--font-size-lg: 1rem;
    --chat--line-height: 1.5;

    /* Spacing */
    --chat--spacing-xs: 0.5rem;
    --chat--spacing-sm: 0.75rem;
    --chat--spacing: 1rem;
    --chat--spacing-lg: 1.5rem;
    --chat--spacing-xl: 2rem;

    /* Border Radius */
    --chat--border-radius: 16px;
    --chat--border-radius-sm: 8px;
    --chat--border-radius-lg: 24px;
    --chat--border-radius-full: 9999px;

    /* Shadows */
    --chat--shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --chat--shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --chat--shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --chat--shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    --chat--shadow-xl: 0 25px 50px -12px rgba(0, 0, 0, 0.25);

    /* Transitions */
    --chat--transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --chat--transition-fast: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);

    /* Window Dimensions */
    --chat--window--width: 380px;
    --chat--window--height: 550px;
    --chat--window--z-index: 99999;

    /* Bubble / Toggle */
    --chat--toggle--size: 60px;

    /* Message Styles */
    --chat--message--font-size: 0.95rem;
    --chat--message--padding: 12px 16px;
    --chat--message--border-radius: var(--chat--border-radius);
    --chat--message--margin-bottom: 10px;
}

/* ============================================
   ADMIN PANEL STYLES
   ============================================ */

/* Reset & Base */
.univ-chat-admin-wrap {
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    background: #f0f0f1;
    padding: 20px;
    margin: -20px;
}

.univ-chat-admin-wrap *,
.univ-chat-admin-wrap *::before,
.univ-chat-admin-wrap *::after {
    box-sizing: inherit;
}

/* Header */
.univ-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    background: #fff;
    padding: 20px 30px;
    border-radius: 12px;
    box-shadow: var(--chat--shadow-sm);
}

.univ-chat-header h1 {
    margin: 0;
    font-size: 1.75rem;
    color: #1e293b;
    display: flex;
    align-items: center;
    gap: 12px;
}

.univ-chat-header h1 i {
    color: var(--chat--color-primary);
}

.univ-chat-header .version {
    font-size: 0.875rem;
    color: #64748b;
    font-weight: 400;
    margin-left: 10px;
    padding: 4px 10px;
    background: #f1f5f9;
    border-radius: 20px;
}

/* Main Container */
.univ-chat-container {
    display: flex;
    gap: 30px;
    align-items: flex-start;
}

/* Settings Panel */
.univ-chat-settings-panel {
    flex: 1;
    min-width: 400px;
    background: #fff;
    border-radius: 12px;
    box-shadow: var(--chat--shadow);
    overflow: hidden;
}

/* Tabs */
.univ-chat-tabs {
    display: flex;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    padding: 0 20px;
}

.tab-button {
    padding: 16px 20px;
    background: transparent;
    border: none;
    color: #64748b;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative;
    transition: var(--chat--transition-fast);
}

.tab-button:hover {
    color: var(--chat--color-primary);
    background: rgba(99, 102, 241, 0.05);
}

.tab-button.active {
    color: var(--chat--color-primary);
}

.tab-button.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--chat--color-primary);
    border-radius: 3px 3px 0 0;
}

.tab-button i {
    font-size: 1rem;
}

/* Tab Content */
.tab-content {
    display: none;
    padding: 30px;
}

.tab-content.active {
    display: block;
}

/* Settings Section */
.univ-settings-section {
    margin-bottom: 30px;
    padding-bottom: 25px;
    border-bottom: 1px solid #e2e8f0;
}

.univ-settings-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.univ-settings-section h3 {
    margin: 0 0 20px;
    color: #1e293b;
    font-size: 1.125rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}

.univ-settings-section h3::before {
    content: '';
    width: 4px;
    height: 20px;
    background: var(--chat--color-primary);
    border-radius: 2px;
}

/* Form Table */
.univ-settings-section .form-table {
    margin: 0;
}

.univ-settings-section .form-table th {
    width: 200px;
    padding: 12px 20px 12px 0;
    font-weight: 500;
    color: #334155;
}

.univ-settings-section .form-table td {
    padding: 12px 0;
}

/* Template Selector */
.template-selector {
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    padding: 20px;
    border-radius: var(--chat--border-radius-sm);
    border: 1px solid #e2e8f0;
    margin-bottom: 25px;
}

.template-selector label {
    display: block;
    font-weight: 600;
    color: #334155;
    margin-bottom: 10px;
}

.template-selector select {
    max-width: 300px;
}

/* Color Preview */
.color-preview {
    margin-left: 10px;
    font-size: 0.875rem;
    color: #64748b;
}

/* Logs Panel */
.logs-panel {
    background: #1e293b;
    border-radius: var(--chat--border-radius-sm);
    overflow: hidden;
}

.logs-header {
    display: flex;
    gap: 10px;
    padding: 15px;
    background: #0f172a;
    border-bottom: 1px solid #334155;
}

.logs-content {
    max-height: 300px;
    overflow-y: auto;
    padding: 15px;
    font-family: 'Courier New', monospace;
    font-size: 0.875rem;
    line-height: 1.6;
}

.logs-entry {
    padding: 8px 0;
    border-bottom: 1px solid #334155;
}

.logs-entry:last-child {
    border-bottom: none;
}

.logs-time {
    color: #94a3b8;
    margin-right: 10px;
}

.logs-message {
    color: #e2e8f0;
}

.logs-empty {
    color: #64748b;
    text-align: center;
    padding: 30px;
    margin: 0;
}

/* Form Actions */
.form-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 30px;
    background: #f8fafc;
    border-top: 1px solid #e2e8f0;
}

/* Preview Panel */
.univ-chat-preview-panel {
    flex: 0 0 420px;
    background: #fff;
    border-radius: 12px;
    box-shadow: var(--chat--shadow);
    overflow: hidden;
    position: sticky;
    top: 20px;
}

.preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border-bottom: 1px solid #e2e8f0;
}

.preview-header h3 {
    margin: 0;
    font-size: 1rem;
    color: #334155;
    display: flex;
    align-items: center;
    gap: 8px;
}

.preview-badge {
    padding: 4px 12px;
    background: linear-gradient(135deg, var(--chat--color-primary) 0%, var(--chat--color-secondary) 100%);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Preview Container */
#chat-preview-container {
    padding: 30px;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    min-height: 600px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 15px;
}

.preview-info {
    padding: 15px 20px;
    background: #fef3c7;
    border-left: 4px solid #f59e0b;
    margin: 0;
    border-radius: 0 8px 8px 0;
}

.preview-info p {
    margin: 0;
    font-size: 0.875rem;
    color: #92400e;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Notification Toast */
.notification-toast {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 999999;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: #fff;
    border-radius: var(--chat--border-radius-sm);
    box-shadow: var(--chat--shadow-lg);
    min-width: 300px;
    animation: slideInRight 0.3s ease;
}

.notification-toast.success {
    border-left: 4px solid var(--chat--color-success);
}

.notification-toast.error {
    border-left: 4px solid var(--chat--color-error);
}

.notification-toast.success .notification-icon {
    color: var(--chat--color-success);
}

.notification-toast.error .notification-icon {
    color: var(--chat--color-error);
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ============================================
   CHAT WIDGET STYLES (Frontend)
   ============================================ */

/* Wrapper */
.n8n-chat-wrapper {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 99999;
    pointer-events: none;
}

.n8n-chat-wrapper.left {
    right: auto;
    left: 20px;
}

.n8n-chat-wrapper.right {
    right: 20px;
}

/* Chat Bubble (Floating Icon) */
.n8n-chat-bubble {
    width: 60px;
    height: 60px;
    background: var(--chat--color-primary, #6366f1);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    font-size: 24px;
    transition: all 0.3s ease;
    pointer-events: auto;
    position: relative;
    z-index: 2;
}

.n8n-chat-bubble:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

.n8n-chat-bubble i {
    font-size: 24px;
}

.n8n-chat-bubble img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

/* Chat Window */
.n8n-chat-window {
    position: fixed;
    bottom: 100px;
    width: 380px;
    height: 550px;
    max-width: calc(100vw - 40px);
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: all 0.3s ease;
    z-index: 1;
}

.n8n-chat-window.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.n8n-chat-wrapper.left .n8n-chat-window {
    right: auto;
    left: 0;
}

.n8n-chat-wrapper.right .n8n-chat-window {
    right: 0;
}

/* Header */
.n8n-chat-window .chat-header {
    background: var(--chat--color-dark, #1e293b);
    color: #fff;
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 60px;
}

.n8n-chat-window .chat-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

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

.n8n-chat-window .chat-header-logo {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}

.n8n-chat-window .chat-title {
    font-size: 1.125rem;
    font-weight: 600;
}

.n8n-chat-window .chat-status {
    width: 8px;
    height: 8px;
    background: #22c55e;
    border-radius: 50%;
    animation: statusPulse 2s infinite;
}

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

.n8n-chat-window .chat-close {
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.n8n-chat-window .chat-close:hover {
    opacity: 1;
}

.n8n-chat-window .chat-clear-history,
.n8n-chat-window .chat-download-btn {
    background: none;
    border: none;
    color: #fff;
    font-size: 1rem;
    cursor: pointer;
    opacity: 0.8;
    transition: opacity 0.2s;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.n8n-chat-window .chat-clear-history:hover,
.n8n-chat-window .chat-download-btn:hover {
    opacity: 1;
}

/* Confirmation Dialog */
.n8n-chat-window .chat-confirm-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    backdrop-filter: blur(2px);
}

.n8n-chat-window .chat-confirm-dialog {
    background: #fff;
    border-radius: 12px;
    padding: 24px;
    max-width: 280px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.n8n-chat-window .chat-confirm-dialog p {
    margin: 0 0 20px;
    font-size: 0.95rem;
    color: #1e293b;
    font-weight: 500;
}

.n8n-chat-window .chat-confirm-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.n8n-chat-window .chat-btn-cancel,
.n8n-chat-window .chat-btn-clear {
    padding: 8px 20px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s;
}

.n8n-chat-window .chat-btn-cancel {
    background: #e2e8f0;
    color: #475569;
}

.n8n-chat-window .chat-btn-cancel:hover {
    background: #cbd5e1;
}

.n8n-chat-window .chat-btn-clear {
    background: #ef4444;
    color: #fff;
}

.n8n-chat-window .chat-btn-clear:hover {
    background: #dc2626;
}

/* Body */
.n8n-chat-window .chat-body {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--chat--color-light, #f1f5f9);
}

.n8n-chat-window .chat-body::-webkit-scrollbar {
    width: 6px;
}

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

.n8n-chat-window .chat-body::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

/* Messages */
.n8n-chat-window .msg-row {
    display: flex;
    width: 100%;
    animation: messageSlide 0.3s ease;
}

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

.n8n-chat-window .msg-row.user {
    justify-content: flex-end;
}

.n8n-chat-window .msg-bubble {
    padding: 12px 16px;
    border-radius: 16px;
    max-width: 85%;
    font-size: 0.95rem;
    line-height: 1.5;
    word-wrap: break-word;
}

.n8n-chat-window .bot-msg {
    background: #fff;
    color: var(--chat--color-dark, #1e293b);
    border-bottom-left-radius: 4px;
}

.n8n-chat-window .user-msg {
    background: var(--chat--color-secondary, #8b5cf6);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.n8n-chat-window .error-msg {
    background: #fef2f2 !important;
    color: #991b1b !important;
    border: 1px solid #fecaca !important;
}

/* Typing Indicator */
.n8n-chat-window .typing-indicator .msg-bubble {
    padding: 8px 16px;
}

.n8n-chat-window .typing-dots {
    display: inline-flex;
    gap: 4px;
}

.n8n-chat-window .typing-dots span {
    width: 8px;
    height: 8px;
    background: #94a3b8;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.n8n-chat-window .typing-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.n8n-chat-window .typing-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

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

/* Footer */
.n8n-chat-window .chat-footer {
    padding: 16px;
    background: #fff;
    border-top: 1px solid #e2e8f0;
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.n8n-chat-window .chat-footer-input-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.n8n-chat-window .chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    position: relative;
}

.n8n-chat-window #n8n-chat-input {
    flex: 1;
    resize: none;
    min-height: 44px;
    max-height: 120px;
    overflow-y: auto;
    line-height: 1.5;
    border: 1px solid #e2e8f0;
    padding: 12px 16px;
    background: #f1f5f9;
    border-radius: 8px;
    outline: none;
    color: #1e293b;
    font-size: 0.95rem;
    font-family: inherit;
    transition: all 0.2s;
    box-sizing: border-box;
}

.n8n-chat-window #n8n-chat-input:focus {
    border-color: var(--chat--color-primary, #6366f1);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.n8n-chat-window .chat-footer button {
    background: var(--chat--color-primary, #6366f1);
    color: #fff;
    width: 44px;
    height: 44px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.n8n-chat-window .chat-footer button:hover:not(:disabled) {
    background: var(--chat--color-primary-shade-50, #4f46e5);
    transform: scale(1.05);
}

.n8n-chat-window .chat-footer button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Bubble Animations */
.n8n-chat-bubble.effect-pulse {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.7);
    }
    70% {
        box-shadow: 0 0 0 15px rgba(99, 102, 241, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(99, 102, 241, 0);
    }
}

.n8n-chat-bubble.effect-bounce {
    animation: bounce 2s infinite;
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-12px);
    }
    60% {
        transform: translateY(-6px);
    }
}

.n8n-chat-bubble.effect-wiggle {
    animation: wiggle 2s infinite;
}

@keyframes wiggle {
    0%, 100% {
        transform: rotate(0deg);
    }
    25% {
        transform: rotate(-10deg);
    }
    75% {
        transform: rotate(10deg);
    }
}

/* Responsive */
@media (max-width: 768px) {
    .n8n-chat-window {
        width: calc(100vw - 40px);
        max-width: 380px;
        height: 60vh;
        max-height: 500px;
    }
}

.preview-window {
    opacity: 1;
    transform: none;
    pointer-events: none;
}

/* Header */
.chat-header,
.preview-header {
    background: var(--chat--color-dark);
    color: #fff;
    padding: var(--chat--spacing);
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 60px;
}

.chat-header-left,
.preview-header > div:first-child {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.chat-header-right,
.preview-header > div:last-child {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-header-logo,
.preview-logo-area {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}

.chat-title,
.preview-title {
    font-size: 1.125rem;
    font-weight: 600;
}

.chat-status,
.preview-status {
    width: 8px;
    height: 8px;
    background: #4ade80 !important;
    border-radius: 50%;
    animation: statusPulse 2s infinite;
    box-shadow: 0 0 8px rgba(74, 222, 128, 0.6);
}

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

.chat-close,
.preview-close {
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    opacity: 0.8;
    transition: var(--chat--transition-fast);
}

.chat-close:hover,
.preview-close:hover {
    opacity: 1;
}

/* Body */
.chat-body,
.preview-body {
    flex: 1;
    padding: var(--chat--spacing);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--chat--color-light);
}

.chat-body::-webkit-scrollbar,
.preview-body::-webkit-scrollbar,
.logs-content::-webkit-scrollbar {
    width: 6px;
}

.chat-body::-webkit-scrollbar-track,
.preview-body::-webkit-scrollbar-track,
.logs-content::-webkit-scrollbar-track {
    background: transparent;
}

.chat-body::-webkit-scrollbar-thumb,
.preview-body::-webkit-scrollbar-thumb,
.logs-content::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

.chat-body::-webkit-scrollbar-thumb:hover,
.preview-body::-webkit-scrollbar-thumb:hover,
.logs-content::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

/* Messages */
.msg-row {
    display: flex;
    width: 100%;
    animation: messageSlide 0.3s ease;
}

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

.msg-row.user {
    justify-content: flex-end;
}

.msg-bubble {
    padding: var(--chat--message--padding);
    border-radius: var(--chat--message--border-radius);
    max-width: 85%;
    font-size: var(--chat--message--font-size);
    line-height: var(--chat--line-height);
    word-wrap: break-word;
}

.bot-msg {
    background: var(--chat--color-white);
    color: var(--chat--color-dark);
    border-bottom-left-radius: 4px;
}

.user-msg {
    background: var(--chat--color-secondary);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.error-msg {
    background: #fef2f2 !important;
    color: #991b1b !important;
    border: 1px solid #fecaca !important;
}

/* Typing Indicator */
.typing-indicator .msg-bubble {
    padding: 8px 16px;
}

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

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

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

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

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

/* Footer */
.chat-footer,
.preview-footer {
    padding: var(--chat--spacing);
    background: var(--chat--color-white);
    border-top: 1px solid var(--chat--color-light-shade-50);
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.chat-footer input,
.preview-footer input {
    flex: 1;
    border: 1px solid var(--chat--color-light-shade-50);
    padding: 12px 16px;
    background: var(--chat--color-light);
    border-radius: var(--chat--border-radius-sm);
    outline: none;
    color: var(--chat--color-dark);
    font-size: var(--chat--font-size-base);
    font-family: inherit;
    transition: var(--chat--transition-fast);
}

.chat-footer input:focus {
    border-color: var(--chat--color-primary);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.chat-footer button,
.preview-footer button {
    background: var(--chat--color-primary);
    color: #fff;
    width: 44px;
    height: 44px;
    border-radius: var(--chat--border-radius-sm);
    border: none;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: var(--chat--transition-fast);
    flex-shrink: 0;
}

.chat-footer button:hover:not(:disabled),
.preview-footer button:hover:not(:disabled) {
    background: var(--chat--color-primary-shade-50);
    transform: scale(1.05);
}

.chat-footer button:disabled,
.preview-footer button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Bubble / Toggle */
.univ-chat-bubble,
.preview-bubble {
    width: var(--chat--toggle--size);
    height: var(--chat--toggle--size);
    background: var(--chat--color-primary);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--chat--shadow-md);
    font-size: 1.5rem;
    transition: var(--chat--transition);
    align-self: flex-end;
}

.univ-chat-bubble:hover,
.preview-bubble:hover {
    transform: scale(1.1);
    box-shadow: var(--chat--shadow-lg);
}

.univ-chat-bubble:focus,
.preview-bubble:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.4);
}

/* Animations */
.effect-pulse {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.7);
    }
    70% {
        box-shadow: 0 0 0 15px rgba(99, 102, 241, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(99, 102, 241, 0);
    }
}

.effect-bounce {
    animation: bounce 2s infinite;
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-12px);
    }
    60% {
        transform: translateY(-6px);
    }
}

.effect-wiggle {
    animation: wiggle 2s infinite;
}

@keyframes wiggle {
    0%, 100% {
        transform: rotate(0deg);
    }
    25% {
        transform: rotate(-10deg);
    }
    75% {
        transform: rotate(10deg);
    }
}

/* Switch Toggle */
.switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 26px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #cbd5e1;
    transition: var(--chat--transition);
    border-radius: 26px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: var(--chat--transition);
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

input:checked + .slider {
    background-color: var(--chat--color-primary);
}

input:checked + .slider:before {
    transform: translateX(22px);
}

input:focus + .slider {
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */
@media (max-width: 1200px) {
    .univ-chat-container {
        flex-direction: column;
    }

    .univ-chat-preview-panel {
        flex: 1;
        width: 100%;
        position: static;
    }

    .univ-chat-settings-panel {
        min-width: 100%;
    }
}

@media (max-width: 768px) {
    .univ-chat-admin-wrap {
        padding: 10px;
        margin: -10px;
    }

    .univ-chat-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .tab-button {
        padding: 12px 16px;
        font-size: 0.875rem;
        white-space: nowrap;
    }

    .univ-settings-section .form-table th,
    .univ-settings-section .form-table td {
        display: block;
        padding: 10px 0;
    }

    .univ-settings-section .form-table th {
        width: 100%;
        font-weight: 600;
    }

    /* Chat Widget Mobile */
    .univ-chat-window,
    .preview-window {
        width: calc(100vw - 40px);
        max-width: 380px;
        height: 60vh;
        max-height: 500px;
    }

    #chat-preview-container {
        min-height: 400px;
    }
}

@media (max-width: 480px) {
    .univ-chat-header h1 {
        font-size: 1.25rem;
    }

    .univ-chat-header .version {
        display: none;
    }

    .form-actions {
        flex-direction: column-reverse;
        gap: 10px;
    }

    .form-actions button {
        width: 100%;
    }
}

/* ============================================
   MESSAGE TIMESTAMPS
   ============================================ */

.n8n-chat-window .msg-timestamp {
    display: block;
    font-size: 0.7rem;
    margin-top: 4px;
    text-align: right;
    opacity: 0.8;
}

.n8n-chat-window .user-msg .msg-timestamp {
    color: rgba(255, 255, 255, 0.9);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.n8n-chat-window .bot-msg .msg-timestamp {
    color: #64748b;
}

/* Activity indicator */
.n8n-chat-window .msg-activity {
    display: block;
    font-size: 0.65rem;
    margin-top: 2px;
    text-align: right;
    opacity: 0.8;
}

.n8n-chat-window .user-msg .msg-activity {
    color: rgba(255, 255, 255, 0.85);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.n8n-chat-window .bot-msg .msg-activity {
    color: #64748b;
}

/* ============================================
   COPY TOAST NOTIFICATION
   ============================================ */

.copy-toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: #1e293b;
    color: #fff;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 999999;
    display: none;
    animation: toastSlideUp 0.3s ease;
}

@keyframes toastSlideUp {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* ============================================
   MESSAGE HOVER EFFECTS & COPY BUTTON
   ============================================ */

.n8n-chat-window .bot-msg {
    position: relative;
    transition: background 0.2s;
}

.n8n-chat-window .msg-copy-btn {
    position: absolute;
    bottom: 6px;
    right: 6px;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    color: #64748b;
    cursor: pointer;
    opacity: 0;
    transition: all 0.2s;
    font-size: 0.75rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    z-index: 5;
}

.n8n-chat-window .bot-msg:hover .msg-copy-btn {
    opacity: 1;
}

.n8n-chat-window .msg-copy-btn:hover {
    background: #f8fafc;
    color: var(--chat--color-primary);
    border-color: var(--chat--color-primary);
    transform: scale(1.05);
}

.n8n-chat-window .msg-copy-btn:active {
    transform: scale(0.95);
}

/* Adjust timestamp to not overlap with copy button */
.n8n-chat-window .bot-msg .msg-timestamp {
    padding-right: 28px;
}

.n8n-chat-window .bot-msg .msg-activity {
    padding-right: 28px;
}

/* ============================================
   CODE BLOCKS IN MESSAGES
   ============================================ */

.n8n-chat-window .msg-bubble code {
    background: rgba(0, 0, 0, 0.05);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.85em;
    color: #475569;
}

.n8n-chat-window .user-msg code {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

/* ============================================
   CHARACTER COUNTER
   ============================================ */

.n8n-chat-window .chat-input-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 4px;
}

.n8n-chat-window .char-counter {
    font-size: 0.7rem;
    color: #94a3b8;
    transition: all 0.2s;
}

.n8n-chat-window .char-counter.warning {
    color: #f59e0b;
    font-weight: 600;
}

.n8n-chat-window .char-counter.error {
    color: #ef4444;
    font-weight: 600;
}

/* ============================================
   SCROLL TO BOTTOM BUTTON
   ============================================ */

.n8n-chat-window .chat-scroll-bottom {
    position: absolute;
    bottom: 140px;
    right: 20px;
    width: 36px;
    height: 36px;
    background: var(--chat--color-primary, #6366f1);
    color: #fff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    z-index: 10;
    transition: all 0.2s;
    font-size: 0.875rem;
}

.n8n-chat-window .chat-scroll-bottom:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}

/* ============================================
   QUICK REPLIES
   ============================================ */

.n8n-chat-window .quick-replies-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 16px;
    animation: fadeInUp 0.3s ease;
}

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

.n8n-chat-window .quick-reply-btn {
    padding: 8px 16px;
    background: var(--chat--color-white, #fff);
    border: 1.5px solid var(--chat--color-primary, #6366f1);
    color: var(--chat--color-primary, #6366f1);
    border-radius: 20px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.n8n-chat-window .quick-reply-btn:hover {
    background: var(--chat--color-primary, #6366f1);
    color: #fff;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px color-mix(in srgb, var(--chat--color-primary, #6366f1) 30%, transparent);
}

/* ============================================
   TYPEWRITER EFFECT
   ============================================ */

.n8n-chat-window .typewriter-text {
    display: inline;
}

/* Bot message formatting */
.n8n-chat-window .bot-msg .bot-list-item {
    display: block;
    margin-left: 8px;
    line-height: 1.6;
}

.n8n-chat-window .bot-msg .json-key {
    color: #6366f1;
    font-weight: 600;
    font-family: 'Courier New', monospace;
    font-size: 0.85em;
}

.n8n-chat-window .bot-msg .bot-code-block {
    background: rgba(0, 0, 0, 0.06);
    padding: 10px 14px;
    border-radius: 6px;
    font-family: 'Courier New', monospace;
    font-size: 0.85em;
    overflow-x: auto;
    margin: 8px 0;
    border: 1px solid rgba(0, 0, 0, 0.08);
    white-space: pre-wrap;
    word-break: break-word;
}

/* ============================================
   RESPONSIVE ADJUSTMENTS
   ============================================ */

@media (max-width: 480px) {
    .n8n-chat-window .quick-replies-container {
        padding: 8px;
    }

    .n8n-chat-window .quick-reply-btn {
        padding: 6px 12px;
        font-size: 0.8rem;
    }
}
