/* ==========================================================================
   CF AI Assistant - Frontend Styles
   A distinctive, modern chat widget with glassmorphism and fluid animations
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:opsz,wght@9..40,400;9..40,500;9..40,600;9..40,700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
    --wcfai-primary: #0f172a;
    --wcfai-accent: #f97316;
    --wcfai-accent-light: #fed7aa;
    --wcfai-bg: #ffffff;
    --wcfai-surface: #f8fafc;
    --wcfai-border: #e2e8f0;
    --wcfai-text: #1e293b;
    --wcfai-text-muted: #64748b;
    --wcfai-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    --wcfai-shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --wcfai-radius: 24px;
    --wcfai-radius-sm: 16px;
    --wcfai-font: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --wcfai-font-mono: 'JetBrains Mono', monospace;
}

/* Widget Container */
.wcfai-widget {
    position: fixed;
    z-index: 999999;
    font-family: var(--wcfai-font);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.wcfai-widget.position-bottom-right {
    bottom: 24px;
    right: 24px;
}

.wcfai-widget.position-bottom-left {
    bottom: 24px;
    left: 24px;
}

/* Toggle Button */
.wcfai-toggle {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--wcfai-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--wcfai-shadow);
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
    overflow: hidden;
}

.wcfai-toggle::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, var(--wcfai-accent), #fb923c);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.wcfai-toggle:hover {
    transform: scale(1.08);
}

.wcfai-toggle:hover::before {
    opacity: 1;
}

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

.wcfai-toggle svg {
    width: 28px;
    height: 28px;
    color: white;
    position: relative;
    z-index: 1;
    transition: transform 0.3s ease;
}

.wcfai-toggle.is-open svg.icon-chat {
    transform: rotate(90deg) scale(0);
}

.wcfai-toggle svg.icon-close {
    position: absolute;
    transform: rotate(-90deg) scale(0);
}

.wcfai-toggle.is-open svg.icon-close {
    transform: rotate(0) scale(1);
}

/* Pulse animation for attention */
.wcfai-toggle:not(.is-open)::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    background: var(--wcfai-accent);
    animation: wcfai-pulse 2s ease-out infinite;
    z-index: -1;
}

@keyframes wcfai-pulse {
    0% {
        transform: scale(1);
        opacity: 0.4;
    }
    100% {
        transform: scale(1.5);
        opacity: 0;
    }
}

/* Chat Window */
.wcfai-chat-window {
    position: absolute;
    bottom: 80px;
    width: 400px;
    max-width: calc(100vw - 48px);
    height: 600px;
    max-height: calc(100vh - 140px);
    background: var(--wcfai-bg);
    border-radius: var(--wcfai-radius);
    box-shadow: var(--wcfai-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    border: 1px solid var(--wcfai-border);
}

.wcfai-widget.position-bottom-right .wcfai-chat-window {
    right: 0;
}

.wcfai-widget.position-bottom-left .wcfai-chat-window {
    left: 0;
}

.wcfai-widget.is-open .wcfai-chat-window {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* Header */
.wcfai-header {
    background: var(--wcfai-primary);
    padding: 20px 24px;
    display: flex;
    align-items: center;
    gap: 14px;
    position: relative;
    overflow: hidden;
}

.wcfai-header::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -20%;
    width: 200px;
    height: 200px;
    background: radial-gradient(circle, var(--wcfai-accent) 0%, transparent 70%);
    opacity: 0.15;
}

.wcfai-avatar {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--wcfai-accent), #fb923c);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    position: relative;
}

.wcfai-avatar svg {
    width: 22px;
    height: 22px;
    color: white;
}

.wcfai-avatar::after {
    content: '';
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 14px;
    height: 14px;
    background: #22c55e;
    border: 3px solid var(--wcfai-primary);
    border-radius: 50%;
}

.wcfai-header-info {
    flex: 1;
    min-width: 0;
}

.wcfai-header-name {
    font-size: 17px;
    font-weight: 600;
    color: white;
    margin: 0 0 2px 0;
}

.wcfai-header-status {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.7);
    display: flex;
    align-items: center;
    gap: 6px;
}

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

.wcfai-header-btn {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.wcfai-header-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.wcfai-header-btn svg {
    width: 18px;
    height: 18px;
    color: white;
}

/* Messages Container */
.wcfai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: var(--wcfai-surface);
    scroll-behavior: smooth;
}

.wcfai-messages::-webkit-scrollbar {
    width: 6px;
}

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

.wcfai-messages::-webkit-scrollbar-thumb {
    background: var(--wcfai-border);
    border-radius: 3px;
}

/* Message Bubble */
.wcfai-message {
    display: flex;
    gap: 12px;
    max-width: 85%;
    animation: wcfai-message-in 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

.wcfai-message.is-user {
    flex-direction: row-reverse;
    align-self: flex-end;
}

.wcfai-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.wcfai-message:not(.is-user) .wcfai-message-avatar {
    background: linear-gradient(135deg, var(--wcfai-accent), #fb923c);
}

.wcfai-message.is-user .wcfai-message-avatar {
    background: var(--wcfai-primary);
}

.wcfai-message-avatar svg {
    width: 16px;
    height: 16px;
    color: white;
}

.wcfai-message-content {
    background: var(--wcfai-bg);
    padding: 14px 18px;
    border-radius: var(--wcfai-radius-sm);
    box-shadow: var(--wcfai-shadow-sm);
    position: relative;
}

.wcfai-message.is-user .wcfai-message-content {
    background: var(--wcfai-primary);
    color: white;
}

.wcfai-message-text {
    margin: 0;
    color: var(--wcfai-text);
    word-wrap: break-word;
}

.wcfai-message.is-user .wcfai-message-text {
    color: white;
}

.wcfai-message-text a {
    color: var(--wcfai-accent);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.wcfai-message.is-user .wcfai-message-text a {
    color: var(--wcfai-accent-light);
}

.wcfai-message-text code {
    font-family: var(--wcfai-font-mono);
    font-size: 13px;
    background: var(--wcfai-surface);
    padding: 2px 6px;
    border-radius: 6px;
}

.wcfai-message.is-user .wcfai-message-text code {
    background: rgba(255, 255, 255, 0.15);
}

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

.wcfai-message-text li {
    margin: 4px 0;
    line-height: 1.5;
}

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

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

/* Strong/bold emphasis */
.wcfai-message-text strong {
    font-weight: 600;
    color: var(--wcfai-text);
}

.wcfai-message.is-user .wcfai-message-text strong {
    color: #fff;
}

/* Italic/em for notes */
.wcfai-message-text em {
    font-style: italic;
    opacity: 0.9;
}

.wcfai-message-time {
    font-size: 11px;
    color: var(--wcfai-text-muted);
    margin-top: 6px;
}

.wcfai-message.is-user .wcfai-message-time {
    color: rgba(255, 255, 255, 0.6);
    text-align: right;
}

/* Sources */
.wcfai-sources {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--wcfai-border);
}

.wcfai-sources-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--wcfai-text-muted);
    margin-bottom: 8px;
}

.wcfai-source-link {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--wcfai-accent);
    text-decoration: none;
    padding: 6px 0;
    transition: opacity 0.2s ease;
}

.wcfai-source-link:hover {
    opacity: 0.7;
}

.wcfai-source-link svg {
    width: 14px;
    height: 14px;
}

/* Typing Indicator */
.wcfai-typing {
    display: flex;
    gap: 4px;
    padding: 8px 0;
}

.wcfai-typing span {
    width: 8px;
    height: 8px;
    background: var(--wcfai-text-muted);
    border-radius: 50%;
    animation: wcfai-bounce 1.4s ease-in-out infinite;
}

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

.wcfai-typing span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes wcfai-bounce {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-6px);
    }
}

/* Input Area */
.wcfai-input-area {
    padding: 16px 20px 20px;
    background: var(--wcfai-bg);
    border-top: 1px solid var(--wcfai-border);
}

.wcfai-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    background: var(--wcfai-surface);
    border: 2px solid var(--wcfai-border);
    border-radius: var(--wcfai-radius-sm);
    padding: 12px 16px;
    transition: all 0.2s ease;
}

.wcfai-input-wrapper:focus-within {
    border-color: var(--wcfai-accent);
    box-shadow: 0 0 0 4px rgba(249, 115, 22, 0.1);
}

.wcfai-input {
    flex: 1;
    border: none;
    background: none;
    font-family: var(--wcfai-font);
    font-size: 15px;
    color: var(--wcfai-text);
    resize: none;
    min-height: 24px;
    max-height: 120px;
    line-height: 1.5;
}

.wcfai-input::placeholder {
    color: var(--wcfai-text-muted);
}

.wcfai-input:focus {
    outline: none;
}

.wcfai-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: var(--wcfai-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.wcfai-send-btn:hover:not(:disabled) {
    background: var(--wcfai-accent);
    transform: scale(1.05);
}

.wcfai-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.wcfai-send-btn svg {
    width: 20px;
    height: 20px;
    color: white;
}

/* Quick Actions */
.wcfai-quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 20px 16px;
    background: var(--wcfai-bg);
}

.wcfai-quick-btn {
    padding: 8px 14px;
    border-radius: 20px;
    background: var(--wcfai-surface);
    border: 1px solid var(--wcfai-border);
    font-family: var(--wcfai-font);
    font-size: 13px;
    color: var(--wcfai-text);
    cursor: pointer;
    transition: all 0.2s ease;
}

.wcfai-quick-btn:hover {
    background: var(--wcfai-primary);
    border-color: var(--wcfai-primary);
    color: white;
}

/* Welcome State */
.wcfai-welcome {
    text-align: center;
    padding: 40px 24px;
}

.wcfai-welcome-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 20px;
    background: linear-gradient(135deg, var(--wcfai-accent), #fb923c);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: wcfai-float 3s ease-in-out infinite;
}

@keyframes wcfai-float {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-8px);
    }
}

.wcfai-welcome-icon svg {
    width: 32px;
    height: 32px;
    color: white;
}

.wcfai-welcome-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--wcfai-text);
    margin: 0 0 8px;
}

.wcfai-welcome-text {
    font-size: 15px;
    color: var(--wcfai-text-muted);
    margin: 0;
    max-width: 280px;
    margin: 0 auto;
}

/* Error State */
.wcfai-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--wcfai-radius-sm);
    padding: 12px 16px;
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.wcfai-error svg {
    width: 20px;
    height: 20px;
    color: #dc2626;
    flex-shrink: 0;
}

.wcfai-error-text {
    font-size: 14px;
    color: #991b1b;
    margin: 0;
}

/* Limit Reached State */
.wcfai-limit-reached {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border: 1px solid #f59e0b;
    border-radius: var(--wcfai-radius-sm);
    padding: 20px;
    text-align: center;
    margin: 16px 0;
}

.wcfai-limit-icon {
    font-size: 32px;
    margin-bottom: 12px;
}

.wcfai-limit-text {
    font-size: 14px;
    color: #92400e;
    margin: 0;
    line-height: 1.5;
}

/* Disabled input state */
.wcfai-input:disabled {
    background: var(--wcfai-surface);
    cursor: not-allowed;
    opacity: 0.7;
}

.wcfai-input:disabled::placeholder {
    color: var(--wcfai-text-muted);
}

/* Mobile Responsive */
@media (max-width: 480px) {
    .wcfai-widget {
        bottom: 16px;
        right: 16px;
        left: 16px;
    }
    
    .wcfai-widget.position-bottom-left,
    .wcfai-widget.position-bottom-right {
        right: 16px;
        left: auto;
    }
    
    .wcfai-chat-window {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-width: 100%;
        height: calc(100vh - 60px);
        max-height: none;
        border-radius: var(--wcfai-radius) var(--wcfai-radius) 0 0;
    }
    
    .wcfai-toggle {
        width: 56px;
        height: 56px;
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    :root {
        --wcfai-bg: #1e293b;
        --wcfai-surface: #0f172a;
        --wcfai-border: #334155;
        --wcfai-text: #f1f5f9;
        --wcfai-text-muted: #94a3b8;
    }
    
    .wcfai-message:not(.is-user) .wcfai-message-content {
        background: #334155;
    }
    
    .wcfai-message-text code {
        background: rgba(0, 0, 0, 0.3);
    }
}

/* Print - Hide widget */
@media print {
    .wcfai-widget {
        display: none !important;
    }
}
