/**
 * AI Knowledge Search - Floating Widget
 * Intercom-style floating chat interface
 */

/* Move the article submission button to the left */
#mkb-floating-button,
.mkb-floating-button {
    left: 20px !important;
    right: auto !important;
}

/* Widget Container - Bottom Right */
.aiks-floating-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Toggle Button - Circular, bottom-right */
.aiks-widget-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #1d8dcd 0%, #66c1d4 100%);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15), 0 2px 4px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.aiks-widget-toggle:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2), 0 3px 6px rgba(0, 0, 0, 0.15);
}

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

/* Toggle Icon */
.aiks-toggle-icon {
    width: 28px;
    height: 28px;
    color: #ffffff;
    transition: all 0.3s ease;
}

/* Rotate X icon when open */
.aiks-widget-toggle.is-open .aiks-toggle-icon {
    transform: rotate(180deg);
}

/* Notification badge */
.aiks-widget-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    background: #ff4757;
    color: white;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    font-size: 11px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
    display: none; /* Hidden by default */
}

/* Chat Window */
.aiks-widget-window {
    position: absolute;
    bottom: 75px;
    right: 0;
    width: 380px;
    height: 600px;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.15), 0 4px 8px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

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

/* Header */
.aiks-widget-header {
    background: linear-gradient(135deg, #1d8dcd 0%, #66c1d4 100%);
    color: white;
    padding: 18px 20px;
    border-radius: 16px 16px 0 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.aiks-widget-header-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.aiks-widget-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.aiks-widget-header-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.aiks-widget-title {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.2;
    margin: 0;
}

.aiks-widget-subtitle {
    font-size: 12px;
    opacity: 0.9;
    line-height: 1.2;
}

.aiks-widget-close {
    background: none;
    border: none;
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
    flex-shrink: 0;
    padding: 0;
}

.aiks-widget-close:hover {
    background: rgba(255, 255, 255, 0.15);
}

.aiks-widget-close svg {
    width: 18px;
    height: 18px;
}

/* Messages Container */
.aiks-widget-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Custom scrollbar */
.aiks-widget-messages::-webkit-scrollbar {
    width: 6px;
}

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

.aiks-widget-messages::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 3px;
}

.aiks-widget-messages::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

/* Welcome Message */
.aiks-welcome-message {
    background: white;
    padding: 16px;
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.aiks-welcome-title {
    font-size: 14px;
    font-weight: 600;
    color: #1a202c;
    margin: 0 0 6px 0;
}

.aiks-welcome-text {
    font-size: 13px;
    color: #4a5568;
    line-height: 1.5;
    margin: 0;
}

/* Message Bubble - User */
.aiks-message-user {
    align-self: flex-end;
    background: #1d8dcd;
    color: white;
    padding: 10px 14px;
    border-radius: 16px 16px 4px 16px;
    max-width: 80%;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Message Bubble - Assistant */
.aiks-message-assistant {
    align-self: flex-start;
    background: white;
    color: #1a202c;
    padding: 12px 14px;
    border-radius: 16px 16px 16px 4px;
    max-width: 85%;
    font-size: 13px;
    line-height: 1.6;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.aiks-message-assistant p {
    margin: 0 0 8px 0;
}

.aiks-message-assistant p:last-child {
    margin-bottom: 0;
}

/* Sources */
.aiks-message-sources {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #e2e8f0;
}

.aiks-sources-title {
    font-size: 11px;
    font-weight: 600;
    color: #718096;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0 0 8px 0;
}

.aiks-source-link {
    display: block;
    padding: 8px 10px;
    background: #f7fafc;
    border-radius: 6px;
    text-decoration: none;
    color: #1d8dcd;
    font-size: 12px;
    transition: background 0.2s ease;
    margin-bottom: 6px;
    border: 1px solid #e2e8f0;
}

.aiks-source-link:last-child {
    margin-bottom: 0;
}

.aiks-source-link:hover {
    background: #edf2f7;
    border-color: #cbd5e0;
}

.aiks-source-title {
    font-weight: 500;
    margin-bottom: 2px;
    display: block;
}

.aiks-source-excerpt {
    color: #718096;
    font-size: 11px;
    line-height: 1.4;
}

/* Loading indicator */
.aiks-loading {
    align-self: flex-start;
    display: flex;
    align-items: center;
    gap: 8px;
    background: white;
    padding: 10px 14px;
    border-radius: 16px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.aiks-loading-dots {
    display: flex;
    gap: 4px;
}

.aiks-loading-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #cbd5e0;
    animation: aiks-bounce 1.4s infinite ease-in-out;
}

.aiks-loading-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.aiks-loading-dot:nth-child(2) {
    animation-delay: -0.16s;
}

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

/* Input Container */
.aiks-widget-input-container {
    padding: 16px;
    background: white;
    border-top: 1px solid #e2e8f0;
    flex-shrink: 0;
}

.aiks-widget-input-wrapper {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.aiks-widget-input {
    flex: 1;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    max-height: 100px;
    min-height: 40px;
    transition: border-color 0.2s ease;
    outline: none;
}

.aiks-widget-input:focus {
    border-color: #1d8dcd;
    box-shadow: 0 0 0 3px rgba(29, 141, 205, 0.1);
}

.aiks-widget-input::placeholder {
    color: #a0aec0;
}

.aiks-widget-send {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: #1d8dcd;
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.aiks-widget-send:hover:not(:disabled) {
    background: #1670a8;
    transform: translateY(-1px);
}

.aiks-widget-send:active:not(:disabled) {
    transform: translateY(0);
}

.aiks-widget-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.aiks-widget-send svg {
    width: 18px;
    height: 18px;
}

/* Error message */
.aiks-message-error {
    background: #fff5f5;
    color: #c53030;
    padding: 12px 14px;
    border-radius: 10px;
    font-size: 13px;
    border: 1px solid #feb2b2;
}

/* Responsive - Mobile */
@media (max-width: 480px) {
    .aiks-widget-window {
        width: calc(100vw - 20px);
        height: calc(100vh - 100px);
        max-height: 600px;
        right: 10px;
    }

    .aiks-floating-widget {
        right: 10px;
        bottom: 10px;
    }

    .aiks-widget-toggle {
        width: 56px;
        height: 56px;
    }
}

/* Tablet adjustments */
@media (max-width: 768px) and (min-width: 481px) {
    .aiks-widget-window {
        width: 360px;
        height: 550px;
    }
}

/* Animations */
@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.aiks-message-user,
.aiks-message-assistant,
.aiks-loading {
    animation: slideInUp 0.3s ease;
}
