/**
 * AI Knowledge Assistant - Frontend Widget Styles
 */

/* Reset and base */
.kai-widget,
.kai-widget * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
}

/* Widget container */
.kai-widget {
    position: fixed;
    z-index: 999999;
}

.kai-position-bottom-right {
    right: var(--kai-offset-x, 20px);
    bottom: var(--kai-offset-y, 20px);
}

.kai-position-bottom-left {
    left: var(--kai-offset-x, 20px);
    bottom: var(--kai-offset-y, 20px);
}

/* Trigger button (collapsed state) */
.kai-trigger {
    width: var(--kai-trigger-size, 80px);
    height: var(--kai-trigger-size, 80px);
    border-radius: 50%;
    cursor: pointer;
    overflow: hidden;
    position: relative;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    background: var(--kai-primary, #6366f1);
}

.kai-trigger:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(0, 0, 0, 0.25);
}

.kai-trigger:focus {
    outline: 3px solid var(--kai-primary, #6366f1);
    outline-offset: 3px;
}

.kai-trigger-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Hover effects */
.kai-trigger-pulse {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 50%;
    pointer-events: none;
}

/* Pulse effect */
.kai-widget[data-hover="pulse"] .kai-trigger:hover .kai-trigger-pulse {
    animation: kai-pulse 1.5s ease-out infinite;
}

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

/* Glow effect */
.kai-widget[data-hover="glow"] .kai-trigger:hover {
    box-shadow: 0 0 30px var(--kai-primary, #6366f1), 0 4px 20px rgba(0, 0, 0, 0.2);
}

/* Bounce effect */
.kai-widget[data-hover="bounce"] .kai-trigger:hover {
    animation: kai-bounce 0.5s ease;
}

@keyframes kai-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

/* Scale effect */
.kai-widget[data-hover="scale"] .kai-trigger:hover {
    transform: scale(1.15);
}

/* Ripple effect */
.kai-widget[data-hover="ripple"] .kai-trigger:hover .kai-trigger-pulse::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 10px;
    height: 10px;
    background: rgba(255, 255, 255, 0.4);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    animation: kai-ripple 0.6s ease-out;
}

@keyframes kai-ripple {
    to {
        width: 200%;
        height: 200%;
        opacity: 0;
    }
}

/* Chat window */
.kai-chat-window {
    display: none;
    flex-direction: column;
    width: var(--kai-window-width, 400px);
    height: var(--kai-window-height, 500px);
    background: var(--kai-bg, #ffffff);
    border-radius: var(--kai-radius, 16px);
    box-shadow: var(--kai-shadow, 0 8px 24px rgba(0, 0, 0, 0.2));
    overflow: hidden;
    position: absolute;
    bottom: 0;
    transform-origin: bottom right;
}

.kai-position-bottom-left .kai-chat-window {
    transform-origin: bottom left;
}

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

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

/* Expanded state */
.kai-widget[data-state="expanded"] .kai-trigger {
    display: none;
}

.kai-widget[data-state="expanded"] .kai-chat-window {
    display: flex;
}

/* Animation styles */
.kai-widget[data-animation="smooth"] .kai-chat-window {
    animation: kai-expand-smooth 0.3s ease-out;
}

.kai-widget[data-animation="spring"] .kai-chat-window {
    animation: kai-expand-spring 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.kai-widget[data-animation="instant"] .kai-chat-window {
    animation: none;
}

@keyframes kai-expand-smooth {
    from {
        opacity: 0;
        transform: scale(0.8) translateY(20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

@keyframes kai-expand-spring {
    0% {
        opacity: 0;
        transform: scale(0.5);
    }
    60% {
        transform: scale(1.05);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Chat header */
.kai-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    background: linear-gradient(135deg, var(--kai-primary, #6366f1), var(--kai-secondary, #4f46e5));
    color: white;
}

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

.kai-header-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.kai-header-title {
    font-weight: 600;
    font-size: 16px;
}

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

.kai-header-actions button {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.kai-header-actions button:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Messages area */
.kai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #f9fafb;
}

.kai-message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 16px;
    line-height: 1.5;
    font-size: 14px;
    word-wrap: break-word;
}

.kai-message-user {
    align-self: flex-end;
    background: var(--kai-primary, #6366f1);
    color: white;
    border-bottom-right-radius: 4px;
}

.kai-message-assistant {
    align-self: flex-start;
    background: white;
    color: var(--kai-text, #1f2937);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Thinking indicator */
.kai-message-thinking {
    background: white;
    color: #6b7280;
}

.kai-thinking-dots {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.kai-thinking-dots span {
    width: 8px;
    height: 8px;
    background: #9ca3af;
    border-radius: 50%;
    animation: kai-thinking 1.4s infinite ease-in-out both;
}

.kai-thinking-dots span:nth-child(1) { animation-delay: -0.32s; }
.kai-thinking-dots span:nth-child(2) { animation-delay: -0.16s; }
.kai-thinking-dots span:nth-child(3) { animation-delay: 0; }

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

/* Sources */
.kai-sources {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #e5e7eb;
    font-size: 12px;
    color: #6b7280;
}

.kai-sources-title {
    font-weight: 600;
    margin-bottom: 4px;
}

.kai-source-item {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 2px 0;
}

.kai-source-item::before {
    content: '📄';
    font-size: 10px;
}

/* Input area */
.kai-chat-input {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 16px;
    background: white;
    border-top: 1px solid #e5e7eb;
}

.kai-input-field {
    flex: 1;
    border: 1px solid #d1d5db;
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 14px;
    resize: none;
    max-height: 120px;
    line-height: 1.4;
    font-family: inherit;
    transition: border-color 0.2s;
}

.kai-input-field:focus {
    outline: none;
    border-color: var(--kai-primary, #6366f1);
}

.kai-input-field::placeholder {
    color: #9ca3af;
}

.kai-send-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 10px;
    background: var(--kai-primary, #6366f1);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.1s;
    flex-shrink: 0;
}

.kai-send-btn:hover {
    background: var(--kai-secondary, #4f46e5);
}

.kai-send-btn:active {
    transform: scale(0.95);
}

.kai-send-btn:disabled {
    background: #d1d5db;
    cursor: not-allowed;
}

/* Welcome message */
.kai-welcome {
    text-align: center;
    padding: 20px;
    color: #6b7280;
}

.kai-welcome-icon {
    font-size: 40px;
    margin-bottom: 12px;
}

.kai-welcome-text {
    font-size: 14px;
    line-height: 1.5;
}

/* Error message */
.kai-error {
    background: #fef2f2;
    color: #dc2626;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 13px;
    text-align: center;
}

/* Mobile responsiveness */
@media (max-width: 480px) {
    .kai-chat-window {
        width: calc(100vw - 20px);
        height: calc(100vh - 100px);
        max-height: 600px;
        right: 10px !important;
        left: 10px !important;
        bottom: calc(var(--kai-trigger-size, 80px) + var(--kai-offset-y, 20px) + 10px);
    }
    
    .kai-trigger {
        width: 60px;
        height: 60px;
    }
}

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

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

.kai-chat-messages::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

.kai-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .kai-widget *,
    .kai-widget *::before,
    .kai-widget *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
