/**
 * Frontend styles for n8n Chat Widget
 */

/* CSS Custom Properties for theming */
:root {
    --n8n-chat-header-bg: #007cba;
    --n8n-chat-header-text: #ffffff;
    --n8n-chat-submit-bg: #007cba;
    --n8n-chat-submit-text: #ffffff;
    --n8n-chat-border-radius: 8px;
    --n8n-chat-shadow: rgba(0, 0, 0, 0.1);
    --n8n-chat-font-family: inherit;
    --n8n-chat-z-index: 9999;
}

/* Main widget container */
.n8n-chat-widget {
    position: fixed;
    z-index: var(--n8n-chat-z-index);
    font-family: var(--n8n-chat-font-family);
    font-size: 14px;
    line-height: 1.4;
    color: #333;
    box-sizing: border-box;
}

.n8n-chat-widget *,
.n8n-chat-widget *::before,
.n8n-chat-widget *::after {
    box-sizing: border-box;
}

/* Position variants */
.n8n-chat-widget-bottom-right {
    bottom: 20px;
    right: 20px;
}

.n8n-chat-widget-bottom-left {
    bottom: 20px;
    left: 20px;
}

/* Size variants */
.n8n-chat-widget-small .n8n-chat-widget-panel {
    width: 300px;
    height: 400px;
}

.n8n-chat-widget-medium .n8n-chat-widget-panel {
    width: 350px;
    height: 500px;
}

.n8n-chat-widget-large .n8n-chat-widget-panel {
    width: 400px;
    height: 600px;
}

/* Widget container */
.n8n-chat-widget-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

/* Toggle button */
.n8n-chat-widget-toggle {
    width: 60px;
    height: 60px;
    background: var(--n8n-chat-header-bg);
    color: var(--n8n-chat-header-text);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px var(--n8n-chat-shadow);
    transition: all 0.3s ease;
    position: relative;
    border: none;
    outline: none;
}

.n8n-chat-widget-toggle:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 16px var(--n8n-chat-shadow);
}

.n8n-chat-widget-toggle:active {
    transform: scale(0.95);
}

.n8n-chat-widget-toggle svg {
    width: 24px;
    height: 24px;
    transition: all 0.3s ease;
}

.n8n-chat-icon-open,
.n8n-chat-icon-close {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

/* Badge for notifications */
.n8n-chat-widget-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #dc3545;
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: bold;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* Chat panel */
.n8n-chat-widget-panel {
    background: white;
    border-radius: var(--n8n-chat-border-radius);
    box-shadow: 0 8px 24px var(--n8n-chat-shadow);
    margin-bottom: 10px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s ease;
    pointer-events: none;
}

.n8n-chat-widget.open .n8n-chat-widget-panel {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* Header */
.n8n-chat-widget-header {
    background: var(--n8n-chat-header-bg);
    color: var(--n8n-chat-header-text);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: var(--n8n-chat-border-radius) var(--n8n-chat-border-radius) 0 0;
}

.n8n-chat-widget-title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    flex: 1;
}

.n8n-chat-widget-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.n8n-chat-widget-new-chat {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: rgba(255, 255, 255, 0.9);
    height: 28px;
    padding: 0 10px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    outline: none;
    gap: 4px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
}

.n8n-chat-widget-new-chat:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.5);
    color: rgba(255, 255, 255, 1);
}

.n8n-chat-widget-new-chat svg {
    width: 14px;
    height: 14px;
}

.n8n-chat-button-text {
    line-height: 1;
}


/* Messages area */
.n8n-chat-widget-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
}

.n8n-chat-widget-messages::-webkit-scrollbar {
    width: 6px;
}

.n8n-chat-widget-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.n8n-chat-widget-messages::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.n8n-chat-widget-messages::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Message bubbles */
.n8n-chat-message {
    max-width: 80%;
    word-wrap: break-word;
    animation: messageSlideIn 0.3s ease;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.n8n-chat-message-content {
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.4;
}

.n8n-chat-message-bot {
    align-self: flex-start;
}

.n8n-chat-message-bot .n8n-chat-message-content {
    background: white;
    color: #333;
    border: 1px solid #e1e5e9;
    border-bottom-left-radius: 6px;
}

.n8n-chat-message-user {
    align-self: flex-end;
}

.n8n-chat-message-user .n8n-chat-message-content {
    background: var(--n8n-chat-header-bg);
    color: var(--n8n-chat-header-text);
    border-bottom-right-radius: 6px;
}

.n8n-chat-message-timestamp {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 4px;
    text-align: right;
}

.n8n-chat-message-bot .n8n-chat-message-timestamp {
    text-align: left;
}

/* Input area */
.n8n-chat-widget-input {
    padding: 16px;
    background: white;
    border-top: 1px solid #e1e5e9;
    border-radius: 0 0 var(--n8n-chat-border-radius) var(--n8n-chat-border-radius);
}

.n8n-chat-form {
    margin: 0;
}

.n8n-chat-input-container {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.n8n-chat-input {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    outline: none;
    transition: border-color 0.2s ease;
    min-height: 40px;
    max-height: 100px;
    line-height: 1.4;
    overflow: hidden;
    box-sizing: border-box;
}

.n8n-chat-input:focus {
    border-color: var(--n8n-chat-header-bg);
    box-shadow: 0 0 0 2px rgba(0, 124, 186, 0.1);
}

.n8n-chat-input::placeholder {
    color: #999;
}

.n8n-chat-send-button {
    background: var(--n8n-chat-submit-bg);
    color: var(--n8n-chat-submit-text);
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    outline: none;
    flex-shrink: 0;
}

.n8n-chat-send-button:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(0, 124, 186, 0.3);
}

.n8n-chat-send-button:active {
    transform: scale(0.95);
}

.n8n-chat-send-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.n8n-chat-send-text {
    display: none;
}

.n8n-chat-send-icon {
    width: 16px;
    height: 16px;
}

/* Loading indicator */
.n8n-chat-widget-loading {
    padding: 16px;
    text-align: center;
    background: rgba(255, 255, 255, 0.95);
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    border-radius: 0 0 var(--n8n-chat-border-radius) var(--n8n-chat-border-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 13px;
    color: #666;
}

.n8n-chat-loading-dots {
    display: flex;
    gap: 4px;
}

.n8n-chat-loading-dots span {
    width: 6px;
    height: 6px;
    background: var(--n8n-chat-header-bg);
    border-radius: 50%;
    animation: loadingDots 1.4s infinite ease-in-out;
}

.n8n-chat-loading-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.n8n-chat-loading-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes loadingDots {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Error states */
.n8n-chat-message-error .n8n-chat-message-content {
    background: #fee;
    color: #c33;
    border-color: #fcc;
}

/* Typing indicator */
.n8n-chat-typing {
    align-self: flex-start;
    max-width: none;
}

.n8n-chat-typing .n8n-chat-message-content {
    background: white;
    border: 1px solid #e1e5e9;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.n8n-chat-typing-dots {
    display: flex;
    gap: 3px;
}

.n8n-chat-typing-dots span {
    width: 4px;
    height: 4px;
    background: #999;
    border-radius: 50%;
    animation: typingDots 1.4s infinite ease-in-out;
}

.n8n-chat-typing-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.n8n-chat-typing-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typingDots {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Mobile responsive - Respects position, responsive sizing for UX */
@media (max-width: 768px) {
    /* Respect position settings on mobile */
    .n8n-chat-widget-bottom-right {
        bottom: 10px;
        right: 10px;
        left: auto;
    }
    
    .n8n-chat-widget-bottom-left {
        bottom: 10px;
        left: 10px;
        right: auto;
    }
    
    /* Responsive sizing for better mobile UX (overrides desktop size settings) */
    .n8n-chat-widget-small .n8n-chat-widget-panel,
    .n8n-chat-widget-medium .n8n-chat-widget-panel,
    .n8n-chat-widget-large .n8n-chat-widget-panel {
        width: 100%;
        max-width: calc(100vw - 20px);
        height: 70vh;
        max-height: 500px;
    }
    
    .n8n-chat-widget-toggle {
        width: 56px;
        height: 56px;
    }
    
    .n8n-chat-widget-toggle svg {
        width: 22px;
        height: 22px;
    }
    
    .n8n-chat-input {
        font-size: 16px; /* Prevent zoom on iOS */
    }
}

@media (max-width: 480px) {
    .n8n-chat-widget-header {
        padding: 12px 16px;
    }
    
    .n8n-chat-widget-title {
        font-size: 15px;
    }
    
    .n8n-chat-widget-new-chat {
        height: 26px;
        padding: 0 8px;
        font-size: 10px;
        gap: 3px;
    }
    
    .n8n-chat-widget-new-chat svg {
        width: 12px;
        height: 12px;
    }
    
    
    .n8n-chat-widget-messages {
        padding: 12px;
    }
    
    .n8n-chat-widget-input {
        padding: 12px;
    }
    
    .n8n-chat-message-content {
        font-size: 13px;
        padding: 8px 12px;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .n8n-chat-widget-panel {
        border: 2px solid #000;
    }
    
    .n8n-chat-input {
        border: 2px solid #000;
    }
    
    .n8n-chat-message-bot .n8n-chat-message-content {
        border: 2px solid #000;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .n8n-chat-widget-toggle,
    .n8n-chat-widget-panel,
    .n8n-chat-message,
    .n8n-chat-send-button {
        transition: none;
        animation: none;
    }
    
    .n8n-chat-widget-badge {
        animation: none;
    }
    
    .n8n-chat-loading-dots span,
    .n8n-chat-typing-dots span {
        animation: none;
        opacity: 1;
    }
}

/* Print styles */
@media print {
    .n8n-chat-widget {
        display: none !important;
    }
}

/* Focus styles for accessibility */
.n8n-chat-widget-toggle:focus,
.n8n-chat-widget-new-chat:focus,
.n8n-chat-send-button:focus {
    outline: 2px solid #005177;
    outline-offset: 2px;
}

.n8n-chat-input:focus {
    outline: none; /* Custom focus style already applied */
}

/* Screen reader only content */
.n8n-chat-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}