/**
 * N8N Chatbot Frontend Styles
 */

/* CSS Custom Properties (set dynamically via PHP) */
:root {
    --n8n-primary-color: #0073aa;
    --n8n-secondary-color: #ffffff;
    --n8n-text-color: #333333;
    --n8n-bot-message-bg: #f1f1f1;
    --n8n-user-message-bg: #0073aa;
    --n8n-chat-width: 350px;
    --n8n-chat-height: 500px;
}

/* Container */
.n8n-chatbot-container {
    position: fixed;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    font-size: 14px;
    line-height: 1.5;
    box-sizing: border-box;
}

.n8n-chatbot-container *,
.n8n-chatbot-container *::before,
.n8n-chatbot-container *::after {
    box-sizing: inherit;
}

/* Positioning */
.n8n-position-bottom-right {
    bottom: 20px;
    right: 20px;
}

.n8n-position-bottom-left {
    bottom: 20px;
    left: 20px;
}

.n8n-position-top-right {
    top: 20px;
    right: 20px;
}

.n8n-position-top-left {
    top: 20px;
    left: 20px;
}

/* Toggle Button */
.n8n-chatbot-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--n8n-primary-color);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    padding: 0;
    outline: none;
}

.n8n-chatbot-toggle:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.n8n-chatbot-toggle:focus {
    outline: 2px solid var(--n8n-primary-color);
    outline-offset: 2px;
}

.n8n-chatbot-icon {
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
}

.n8n-chatbot-icon img {
    width: 28px;
    height: 28px;
    object-fit: contain;
}

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

/* Chat Window */
.n8n-chatbot-window {
    position: absolute;
    width: var(--n8n-chat-width);
    height: var(--n8n-chat-height);
    max-height: calc(100vh - 100px);
    background: var(--n8n-secondary-color);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: n8n-slide-up 0.3s ease;
}

.n8n-position-bottom-right .n8n-chatbot-window,
.n8n-position-bottom-left .n8n-chatbot-window {
    bottom: 70px;
}

.n8n-position-top-right .n8n-chatbot-window,
.n8n-position-top-left .n8n-chatbot-window {
    top: 70px;
}

.n8n-position-bottom-right .n8n-chatbot-window,
.n8n-position-top-right .n8n-chatbot-window {
    right: 0;
}

.n8n-position-bottom-left .n8n-chatbot-window,
.n8n-position-top-left .n8n-chatbot-window {
    left: 0;
}

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

/* Header */
.n8n-chatbot-header {
    background: var(--n8n-primary-color);
    color: #fff;
    padding: 15px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.n8n-chatbot-title {
    font-weight: 600;
    font-size: 16px;
}

.n8n-chatbot-header-actions {
    display: flex;
    gap: 8px;
}

.n8n-chatbot-header-actions button {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: #fff;
    width: 28px;
    height: 28px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
    padding: 0;
}

.n8n-chatbot-header-actions button:hover {
    background: rgba(255, 255, 255, 0.3);
}

.n8n-chatbot-header-actions button svg {
    width: 16px;
    height: 16px;
}

/* Pre-chat Form */
.n8n-chatbot-prechat {
    padding: 20px;
    flex: 1;
    overflow-y: auto;
}

.n8n-chatbot-form-group {
    margin-bottom: 15px;
}

.n8n-chatbot-form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: var(--n8n-text-color);
}

.n8n-chatbot-form-group input[type="text"],
.n8n-chatbot-form-group input[type="email"] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.2s ease;
}

.n8n-chatbot-form-group input[type="text"]:focus,
.n8n-chatbot-form-group input[type="email"]:focus {
    outline: none;
    border-color: var(--n8n-primary-color);
}

.n8n-chatbot-gdpr {
    font-size: 13px;
}

.n8n-chatbot-gdpr input[type="checkbox"] {
    margin-right: 8px;
}

.n8n-chatbot-start-btn {
    width: 100%;
    padding: 12px;
    background: var(--n8n-primary-color);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s ease;
}

.n8n-chatbot-start-btn:hover {
    opacity: 0.9;
}

/* Messages Container */
.n8n-chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

/* Message Bubbles */
.n8n-chatbot-message {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    position: relative;
    word-wrap: break-word;
    animation: n8n-message-in 0.2s ease;
}

@keyframes n8n-message-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.n8n-chatbot-message.n8n-bot-message {
    background: var(--n8n-bot-message-bg);
    color: var(--n8n-text-color);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.n8n-chatbot-message.n8n-user-message {
    background: var(--n8n-user-message-bg);
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.n8n-chatbot-message.n8n-error-message {
    background: #fee2e2;
    color: #991b1b;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.n8n-message-text {
    margin: 0;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Rendered content styles for bot messages */
.n8n-bot-message .n8n-message-text {
    white-space: normal;
}

.n8n-user-message .n8n-message-text {
    white-space: pre-wrap;
}

/* Links in messages */
.n8n-message-text a {
    color: inherit;
    text-decoration: underline;
    word-break: break-all;
}

.n8n-message-text a:hover {
    opacity: 0.8;
}

.n8n-bot-message .n8n-message-text a {
    color: #0066cc;
}

.n8n-user-message .n8n-message-text a {
    color: #fff;
}

/* Bold and italic */
.n8n-message-text strong {
    font-weight: 600;
}

.n8n-message-text em {
    font-style: italic;
}

/* Inline code */
.n8n-message-text code {
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'SF Mono', Consolas, Monaco, 'Andale Mono', monospace;
    font-size: 0.9em;
}

.n8n-user-message .n8n-message-text code {
    background: rgba(255, 255, 255, 0.2);
}

/* Lists in messages */
.n8n-message-text ul,
.n8n-message-text ol {
    margin: 8px 0;
    padding-left: 20px;
}

.n8n-message-text li {
    margin: 4px 0;
}

.n8n-message-text ul {
    list-style-type: disc;
}

.n8n-message-text ol {
    list-style-type: decimal;
}

/* Paragraphs and line breaks */
.n8n-message-text p {
    margin: 0 0 8px 0;
}

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

.n8n-message-text br + br {
    display: block;
    content: '';
    margin-top: 8px;
}

/* Blockquotes */
.n8n-message-text blockquote {
    margin: 8px 0;
    padding: 8px 12px;
    border-left: 3px solid rgba(0, 0, 0, 0.2);
    background: rgba(0, 0, 0, 0.05);
}

/* Preformatted text */
.n8n-message-text pre {
    background: rgba(0, 0, 0, 0.1);
    padding: 8px 12px;
    border-radius: 4px;
    overflow-x: auto;
    font-family: 'SF Mono', Consolas, Monaco, 'Andale Mono', monospace;
    font-size: 0.9em;
    margin: 8px 0;
}

/* Headings in messages */
.n8n-message-text h1,
.n8n-message-text h2,
.n8n-message-text h3,
.n8n-message-text h4,
.n8n-message-text h5,
.n8n-message-text h6 {
    margin: 8px 0 4px 0;
    font-weight: 600;
}

.n8n-message-text h1 { font-size: 1.3em; }
.n8n-message-text h2 { font-size: 1.2em; }
.n8n-message-text h3 { font-size: 1.1em; }
.n8n-message-text h4,
.n8n-message-text h5,
.n8n-message-text h6 { font-size: 1em; }

.n8n-message-time {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 4px;
    display: block;
}

.n8n-user-message .n8n-message-time {
    text-align: right;
}

/* Typing Indicator */
.n8n-chatbot-typing {
    padding: 0 15px 10px;
}

.n8n-typing-dots {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--n8n-bot-message-bg);
    padding: 12px 16px;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
}

.n8n-typing-dots span {
    width: 8px;
    height: 8px;
    background: #999;
    border-radius: 50%;
    animation: n8n-typing-bounce 1.4s infinite ease-in-out both;
}

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

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

@keyframes n8n-typing-bounce {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Input Area */
.n8n-chatbot-input-area {
    padding: 12px 15px;
    border-top: 1px solid #eee;
    background: #fafafa;
    flex-shrink: 0;
}

.n8n-chatbot-form {
    display: flex;
    gap: 8px;
    align-items: center;
}

.n8n-chatbot-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #ddd;
    border-radius: 20px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s ease;
}

.n8n-chatbot-input:focus {
    border-color: var(--n8n-primary-color);
}

.n8n-chatbot-input:disabled {
    background: #f5f5f5;
    cursor: not-allowed;
}

.n8n-chatbot-send {
    width: 40px;
    height: 40px;
    min-width: 40px;
    background: var(--n8n-primary-color);
    color: #fff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, transform 0.2s ease;
    padding: 0;
}

.n8n-chatbot-send:hover {
    opacity: 0.9;
    transform: scale(1.05);
}

.n8n-chatbot-send:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

.n8n-chatbot-send svg {
    width: 18px;
    height: 18px;
}

/* Powered By */
.n8n-chatbot-powered {
    text-align: center;
    padding: 8px;
    background: #f9f9f9;
    border-top: 1px solid #eee;
    flex-shrink: 0;
}

.n8n-chatbot-powered small {
    color: #999;
    font-size: 11px;
}

/* Inline Mode */
.n8n-chatbot-inline .n8n-chatbot-container {
    position: relative;
    bottom: auto;
    right: auto;
    left: auto;
    top: auto;
}

.n8n-chatbot-inline .n8n-chatbot-toggle {
    display: none;
}

.n8n-chatbot-inline .n8n-chatbot-window {
    position: relative;
    display: flex !important;
    bottom: auto;
    animation: none;
}

/* Mobile Responsive */
@media screen and (max-width: 480px) {
    .n8n-chatbot-container {
        bottom: 10px;
        right: 10px;
        left: 10px;
    }
    
    .n8n-position-bottom-left,
    .n8n-position-top-left {
        left: 10px;
        right: 10px;
    }
    
    .n8n-chatbot-window {
        width: calc(100vw - 20px);
        max-width: none;
        left: 0 !important;
        right: 0 !important;
    }
    
    .n8n-chatbot-toggle {
        width: 50px;
        height: 50px;
    }
    
    .n8n-chatbot-icon svg {
        width: 24px;
        height: 24px;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .n8n-chatbot-window {
        border: 2px solid #000;
    }
    
    .n8n-chatbot-input {
        border-width: 2px;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .n8n-chatbot-window,
    .n8n-chatbot-message,
    .n8n-chatbot-toggle {
        animation: none;
        transition: none;
    }
    
    .n8n-typing-dots span {
        animation: none;
        opacity: 1;
    }
}

/* Print styles */
@media print {
    .n8n-chatbot-container {
        display: none !important;
    }
}

/* Scrollbar styling */
.n8n-chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

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

.n8n-chatbot-messages::-webkit-scrollbar-thumb {
    background: #ddd;
    border-radius: 3px;
}

.n8n-chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: #ccc;
}
