/*
 * Enhanced Chat Widget Styles for AI Website Plugin
 * Modern, responsive design with animations and themes
 */

/* ==== BASE STYLES ==== */
.aiw-chat-container {
    position: fixed;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    font-size: 14px;
    line-height: 1.4;
    color: #333;
    box-sizing: border-box;
}

.aiw-chat-container *,
.aiw-chat-container *::before,
.aiw-chat-container *::after {
    box-sizing: border-box;
}

/* ==== POSITIONING ==== */
.aiw-chat-bottom-right {
    bottom: 20px;
    right: 20px;
}

.aiw-chat-bottom-left {
    bottom: 20px;
    left: 20px;
}

.aiw-chat-top-right {
    top: 20px;
    right: 20px;
}

.aiw-chat-top-left {
    top: 20px;
    left: 20px;
}

/* ==== CHAT TOGGLE BUTTON ==== */
.aiw-chat-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    transition: all 0.3s ease;
    position: relative;
    outline: none;
    overflow: hidden;
}

.aiw-chat-toggle:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 25px rgba(0, 0, 0, 0.2);
}

.aiw-chat-toggle:active {
    transform: scale(0.95);
}

.aiw-chat-toggle-icon {
    position: relative;
    width: 24px;
    height: 24px;
    transition: transform 0.3s ease;
}

.aiw-chat-icon-message,
.aiw-chat-icon-close {
    position: absolute;
    top: 0;
    left: 0;
    width: 24px;
    height: 24px;
    transition: all 0.3s ease;
}

.aiw-chat-icon-close {
    opacity: 0;
    transform: rotate(180deg) scale(0.8);
}

.aiw-chat-open .aiw-chat-icon-message {
    opacity: 0;
    transform: rotate(-180deg) scale(0.8);
}

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

/* ==== NOTIFICATION BADGE ==== */
.aiw-chat-notification-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff4757;
    color: white;
    border-radius: 50%;
    min-width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: bold;
    animation: aiwChatPulse 2s infinite;
}

.aiw-chat-badge-count {
    line-height: 1;
}

@keyframes aiwChatPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* ==== CHAT WINDOW ==== */
.aiw-chat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    height: 500px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: 1px solid #e2e8f0;
}

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

.aiw-chat-minimized .aiw-chat-window {
    height: 60px;
    overflow: hidden;
}

.aiw-chat-inline {
    position: static;
    transform: none;
    opacity: 1;
    visibility: visible;
    width: 100%;
    height: 100%;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

/* ==== CHAT HEADER ==== */
.aiw-chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.aiw-chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.aiw-chat-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.aiw-chat-info {
    flex: 1;
}

.aiw-chat-title {
    font-weight: 600;
    font-size: 16px;
    margin-bottom: 2px;
}

.aiw-chat-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    opacity: 0.9;
}

.aiw-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #00d4aa;
    animation: aiwStatusPulse 2s infinite;
}

.aiw-status-offline .aiw-status-dot {
    background: #8e8e8e;
    animation: none;
}

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

.aiw-chat-header-actions {
    display: flex;
    gap: 8px;
}

.aiw-chat-minimize,
.aiw-chat-close {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease;
}

.aiw-chat-minimize:hover,
.aiw-chat-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ==== CHAT MESSAGES ==== */
.aiw-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #f8fafc;
    scroll-behavior: smooth;
}

.aiw-chat-messages::-webkit-scrollbar {
    width: 4px;
}

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

.aiw-chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 2px;
}

.aiw-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

.aiw-chat-message {
    display: flex;
    margin-bottom: 16px;
    animation: aiwMessageSlide 0.3s ease;
}

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

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

.aiw-chat-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin: 0 8px;
}

.aiw-chat-message-bot .aiw-chat-message-avatar {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.aiw-chat-message-user .aiw-chat-message-avatar {
    background: #4299e1;
    color: white;
}

.aiw-chat-message-content {
    max-width: 70%;
    display: flex;
    flex-direction: column;
}

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

.aiw-chat-message-bubble {
    background: white;
    padding: 12px 16px;
    border-radius: 18px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    word-wrap: break-word;
    position: relative;
}

.aiw-chat-message-user .aiw-chat-message-bubble {
    background: #4299e1;
    color: white;
    border-bottom-right-radius: 6px;
}

.aiw-chat-message-bot .aiw-chat-message-bubble {
    border-bottom-left-radius: 6px;
}

.aiw-chat-message-time {
    font-size: 11px;
    color: #718096;
    margin-top: 4px;
    padding: 0 8px;
}

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

/* ==== QUICK REPLIES ==== */
.aiw-chat-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 16px 0;
    animation: aiwFadeIn 0.5s ease;
}

.aiw-quick-reply-btn {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 20px;
    padding: 8px 14px;
    font-size: 13px;
    color: #4a5568;
    cursor: pointer;
    transition: all 0.2s ease;
    outline: none;
}

.aiw-quick-reply-btn:hover {
    background: #667eea;
    color: white;
    border-color: #667eea;
    transform: translateY(-1px);
}

.aiw-quick-reply-btn:active {
    transform: translateY(0);
}

/* ==== TYPING INDICATOR ==== */
.aiw-chat-typing {
    display: flex;
    align-items: center;
    padding: 0 20px 16px;
    background: #f8fafc;
}

.aiw-chat-typing-content {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: 8px;
}

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

.aiw-typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #cbd5e0;
    animation: aiwTypingDot 1.4s infinite ease-in-out;
}

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

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

.aiw-typing-text {
    font-size: 12px;
    color: #718096;
    font-style: italic;
}

/* ==== CHAT INPUT ==== */
.aiw-chat-input-container {
    padding: 16px 20px;
    background: white;
    border-top: 1px solid #e2e8f0;
    display: flex;
    align-items: flex-end;
    gap: 12px;
    flex-shrink: 0;
}

.aiw-chat-file-upload {
    flex-shrink: 0;
}

.aiw-chat-file-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: #f7fafc;
    color: #718096;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.aiw-chat-file-btn:hover {
    background: #edf2f7;
    color: #4a5568;
}

.aiw-chat-input-wrapper {
    flex: 1;
    position: relative;
    display: flex;
    align-items: flex-end;
    background: #f7fafc;
    border-radius: 20px;
    border: 1px solid #e2e8f0;
    transition: border-color 0.2s ease;
}

.aiw-chat-input-wrapper:focus-within {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.aiw-chat-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 10px 16px;
    font-size: 14px;
    line-height: 1.4;
    max-height: 120px;
    min-height: 36px;
    resize: none;
    outline: none;
    font-family: inherit;
    color: #2d3748;
}

.aiw-chat-input::placeholder {
    color: #a0aec0;
}

.aiw-chat-emoji-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: #718096;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    margin: 2px 4px 2px 0;
    transition: all 0.2s ease;
}

.aiw-chat-emoji-btn:hover {
    background: #edf2f7;
    color: #4a5568;
}

.aiw-chat-send-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: #667eea;
    color: white;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.aiw-chat-send-btn:hover:not(:disabled) {
    background: #5a67d8;
    transform: translateY(-1px);
}

.aiw-chat-send-btn:active {
    transform: translateY(0);
}

.aiw-chat-send-btn:disabled {
    background: #cbd5e0;
    cursor: not-allowed;
    transform: none;
}

/* ==== CHARACTER COUNTER ==== */
.aiw-chat-char-counter {
    font-size: 11px;
    color: #a0aec0;
    text-align: right;
    padding: 0 20px 8px;
    background: white;
}

.aiw-chat-char-counter.warning {
    color: #ed8936;
}

.aiw-chat-char-counter.error {
    color: #e53e3e;
}

/* ==== BRANDING ==== */
.aiw-chat-branding {
    padding: 8px 20px;
    background: #f7fafc;
    border-top: 1px solid #e2e8f0;
    text-align: center;
    font-size: 11px;
    color: #a0aec0;
}

.aiw-chat-branding span {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

/* ==== THEME VARIATIONS ==== */
.aiw-chat-theme-dark {
    --aiw-bg-primary: #1a202c;
    --aiw-bg-secondary: #2d3748;
    --aiw-text-primary: #e2e8f0;
    --aiw-text-secondary: #a0aec0;
    --aiw-border: #4a5568;
}

.aiw-chat-theme-dark .aiw-chat-window {
    background: var(--aiw-bg-primary);
    border-color: var(--aiw-border);
    color: var(--aiw-text-primary);
}

.aiw-chat-theme-dark .aiw-chat-messages {
    background: var(--aiw-bg-secondary);
}

.aiw-chat-theme-dark .aiw-chat-message-bubble {
    background: var(--aiw-bg-primary);
    color: var(--aiw-text-primary);
}

.aiw-chat-theme-dark .aiw-chat-input-container,
.aiw-chat-theme-dark .aiw-chat-branding {
    background: var(--aiw-bg-primary);
    border-color: var(--aiw-border);
}

.aiw-chat-theme-dark .aiw-chat-input-wrapper {
    background: var(--aiw-bg-secondary);
    border-color: var(--aiw-border);
}

.aiw-chat-theme-dark .aiw-chat-input {
    color: var(--aiw-text-primary);
}

.aiw-chat-theme-minimal {
    --aiw-primary: #000;
    --aiw-accent: #f0f0f0;
}

.aiw-chat-theme-minimal .aiw-chat-toggle {
    background: var(--aiw-primary);
}

.aiw-chat-theme-minimal .aiw-chat-header {
    background: var(--aiw-primary);
}

.aiw-chat-theme-minimal .aiw-chat-send-btn {
    background: var(--aiw-primary);
}

.aiw-chat-theme-minimal .aiw-chat-message-bot .aiw-chat-message-avatar {
    background: var(--aiw-primary);
}

/* ==== RESPONSIVE DESIGN ==== */
@media (max-width: 480px) {
    .aiw-chat-window {
        width: calc(100vw - 40px);
        height: calc(100vh - 100px);
        bottom: 80px;
        right: 20px;
        left: 20px;
        border-radius: 12px 12px 0 0;
    }
    
    .aiw-chat-bottom-left .aiw-chat-window,
    .aiw-chat-bottom-right .aiw-chat-window {
        right: 20px;
        left: 20px;
    }
    
    .aiw-chat-message-content {
        max-width: 85%;
    }
    
    .aiw-chat-input-container {
        padding: 12px 16px;
    }
    
    .aiw-chat-messages {
        padding: 16px;
    }
}

@media (max-width: 320px) {
    .aiw-chat-toggle {
        width: 50px;
        height: 50px;
    }
    
    .aiw-chat-toggle-icon {
        width: 20px;
        height: 20px;
    }
    
    .aiw-chat-icon-message,
    .aiw-chat-icon-close {
        width: 20px;
        height: 20px;
    }
}

/* ==== ACCESSIBILITY ==== */
@media (prefers-reduced-motion: reduce) {
    .aiw-chat-container *,
    .aiw-chat-container *::before,
    .aiw-chat-container *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

.aiw-chat-container [role="button"]:focus,
.aiw-chat-container button:focus,
.aiw-chat-container input:focus,
.aiw-chat-container textarea:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

/* ==== SHORTCODE STYLES ==== */
.aiw-chat-shortcode {
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    background: white;
}

.aiw-chat-shortcode .aiw-chat-window {
    position: static;
    width: 100%;
    height: 100%;
    box-shadow: none;
    border-radius: 0;
    opacity: 1;
    visibility: visible;
    transform: none;
}

/* ==== BUTTON TRIGGER STYLES ==== */
.aiw-chat-trigger {
    background: #667eea;
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
}

.aiw-chat-trigger:hover {
    background: #5a67d8;
    transform: translateY(-1px);
    color: white;
    text-decoration: none;
}

.aiw-chat-trigger:active {
    transform: translateY(0);
}

.aiw-btn-secondary {
    background: #e2e8f0;
    color: #4a5568;
}

.aiw-btn-secondary:hover {
    background: #cbd5e0;
    color: #2d3748;
}

/* ==== UTILITY ANIMATIONS ==== */
@keyframes aiwFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

@keyframes aiwBounceIn {
    0% {
        opacity: 0;
        transform: scale(0.3) translateY(20px);
    }
    50% {
        opacity: 1;
        transform: scale(1.05) translateY(-5px);
    }
    70% {
        transform: scale(0.95) translateY(0);
    }
    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* ==== LOADING STATES ==== */
.aiw-chat-loading {
    opacity: 0.6;
    pointer-events: none;
}

.aiw-chat-connecting::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid transparent;
    border-top-color: #667eea;
    border-radius: 50%;
    animation: aiwSpin 1s linear infinite;
}

@keyframes aiwSpin {
    to { transform: rotate(360deg); }
}

/* ==== ERROR STATES ==== */
.aiw-chat-error {
    background: #fed7d7;
    color: #c53030;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    margin: 8px 0;
    border: 1px solid #feb2b2;
}

.aiw-chat-success {
    background: #c6f6d5;
    color: #2f855a;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    margin: 8px 0;
    border: 1px solid #9ae6b4;
}

/* ==== DRAG AND DROP ==== */
.aiw-chat-drag-over {
    background: #ebf8ff;
    border: 2px dashed #3182ce;
}

.aiw-chat-file-preview {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #f7fafc;
    border-radius: 6px;
    margin: 8px 0;
    font-size: 12px;
}

.aiw-chat-file-preview .remove {
    color: #e53e3e;
    cursor: pointer;
    font-weight: bold;
}

/* ==== CUSTOM SCROLLBAR ==== */
.aiw-chat-messages {
    scrollbar-width: thin;
    scrollbar-color: #cbd5e0 transparent;
}

/* ==== HIGH CONTRAST MODE ==== */
@media (prefers-contrast: high) {
    .aiw-chat-container {
        --aiw-border: #000;
        --aiw-text: #000;
        --aiw-bg: #fff;
    }
    
    .aiw-chat-window {
        border: 2px solid var(--aiw-border);
    }
    
    .aiw-chat-message-bubble {
        border: 1px solid var(--aiw-border);
    }
}