/**
 * AI Widget CSS
 * ==============
 * 前端 AI 客服聊天浮动窗口样式
 * 设计规格：浮动按钮(56px圆形)、聊天面板(380x540)、移动端全屏适配
 * 配色方案：主色 #0F3460, 强调色 #E94560
 */

/* ==========================================================================
   Container & toggle button
   ========================================================================== */
#ai-widget {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: #333;
}

/* Floating toggle button */
#ai-widget-toggle {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 2147483645;

    width: 56px;
    height: 56px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, #0F3460, #1a4d8c);
    color: #fff;
    font-size: 24px;
    cursor: pointer;

    box-shadow: 0 4px 16px rgba(15, 52, 96, 0.35);
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.3s ease;
}

#ai-widget-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(15, 52, 96, 0.45);
}

#ai-widget-toggle:active {
    transform: scale(0.95);
}

#ai-widget-toggle:focus-visible {
    outline: 2px solid #E94560;
    outline-offset: 2px;
}

/* ==========================================================================
   Chat panel
   ========================================================================== */
#ai-widget-panel {
    position: fixed;
    bottom: 92px;
    right: 24px;
    z-index: 2147483646;

    display: flex;
    flex-direction: column;

    width: 380px;
    max-width: calc(100vw - 32px);
    height: 540px;
    max-height: calc(100vh - 120px);

    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.18);

    transform-origin: bottom right;
    opacity: 0;
    transform: scale(0.85) translateY(16px);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

#ai-widget-panel.ai-widget-open {
    opacity: 1;
    transform: scale(1) translateY(0);
    pointer-events: auto;
}

/* ==========================================================================
   Header
   ========================================================================== */
#ai-widget-header {
    display: flex;
    align-items: center;
    justify-content: space-between;

    padding: 14px 18px;
    background: linear-gradient(135deg, #0F3460, #1a4d8c);
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    border-radius: 16px 16px 0 0;
    user-select: none;
}

#ai-widget-close {
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
    font-size: 18px;
    line-height: 28px;
    text-align: center;
    cursor: pointer;
    transition: background 0.2s ease;
}

#ai-widget-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ==========================================================================
   Messages area
   ========================================================================== */
#ai-widget-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f5f6f8;

    /* Scrollbar styling */
    scrollbar-width: thin;
    scrollbar-color: #c1c5ce #f5f6f8;
}

#ai-widget-messages::-webkit-scrollbar {
    width: 5px;
}

#ai-widget-messages::-webkit-scrollbar-track {
    background: #f5f6f8;
}

#ai-widget-messages::-webkit-scrollbar-thumb {
    background: #c1c5ce;
    border-radius: 3px;
}

#ai-widget-messages::-webkit-scrollbar-thumb:hover {
    background: #a8adb8;
}

/* ==========================================================================
   Chat bubbles
   ========================================================================== */
.ai-widget-bubble {
    max-width: 80%;
    padding: 10px 14px;
    margin-bottom: 10px;
    border-radius: 14px;
    word-wrap: break-word;
    white-space: pre-wrap;
    position: relative;
    animation: aiWidgetFadeIn 0.2s ease;
}

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

/* User bubble (right) */
.ai-widget-bubble.ai-widget-user {
    margin-left: auto;
    background: #0F3460;
    color: #fff;
    border-bottom-right-radius: 4px;
}

/* Bot bubble (left) */
.ai-widget-bubble.ai-widget-bot {
    margin-right: auto;
    background: #eef0f4;
    color: #333;
    border-bottom-left-radius: 4px;
}

/* Timestamp inside bubble */
.ai-widget-time {
    display: block;
    font-size: 11px;
    color: #999;
    margin-top: 4px;
    text-align: right;
}

.ai-widget-bubble.ai-widget-bot .ai-widget-time {
    text-align: left;
    color: #aaa;
}

.ai-widget-bubble.ai-widget-user .ai-widget-time {
    color: rgba(255, 255, 255, 0.65);
}

/* ==========================================================================
   Typing indicator
   ========================================================================== */
.ai-widget-typing {
    display: none;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
    margin-bottom: 10px;
    margin-right: auto;
    max-width: 70px;
    background: #eef0f4;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
}

.ai-widget-typing.ai-widget-active {
    display: flex;
}

.ai-widget-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #999;
    display: inline-block;
    animation: aiWidgetDotBounce 1.3s ease-in-out infinite;
}

.ai-widget-typing span:nth-child(2) {
    animation-delay: 0.15s;
}

.ai-widget-typing span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes aiWidgetDotBounce {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-5px);
        background: #666;
    }
}

/* ==========================================================================
   Input area
   ========================================================================== */
#ai-widget-input-area {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-top: 1px solid #e8eaed;
    background: #fff;
    border-radius: 0 0 16px 16px;
}

#ai-widget-input {
    flex: 1;
    height: 38px;
    padding: 0 12px;
    border: 1px solid #d9dce1;
    border-radius: 8px;
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s ease;
}

#ai-widget-input:focus {
    border-color: #0F3460;
    box-shadow: 0 0 0 2px rgba(15, 52, 96, 0.12);
}

#ai-widget-input::placeholder {
    color: #aaa;
}

#ai-widget-send {
    flex-shrink: 0;
    height: 38px;
    padding: 0 18px;
    border: none;
    border-radius: 8px;
    background: linear-gradient(135deg, #0F3460, #1a4d8c);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s ease, transform 0.15s ease;
}

#ai-widget-send:hover {
    opacity: 0.9;
}

#ai-widget-send:active {
    transform: scale(0.96);
}

#ai-widget-send:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
}

/* ==========================================================================
   Connection error banner
   ========================================================================== */
.ai-widget-error {
    padding: 8px 14px;
    margin-bottom: 10px;
    background: #fef0f0;
    border: 1px solid #f5c6cb;
    color: #cc3344;
    border-radius: 10px;
    font-size: 13px;
    text-align: center;
    animation: aiWidgetFadeIn 0.2s ease;
}

/* ==========================================================================
   Mobile responsive: full-screen on small devices
   ========================================================================== */
@media (max-width: 480px) {
    #ai-widget-toggle {
        bottom: 16px;
        right: 16px;
        width: 52px;
        height: 52px;
        font-size: 22px;
    }

    #ai-widget-panel {
        bottom: 0;
        right: 0;
        left: 0;
        top: 0;

        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;

        border-radius: 0;
        box-shadow: none;
    }

    #ai-widget-header {
        border-radius: 0;
        padding: 12px 16px;
    }

    #ai-widget-input-area {
        border-radius: 0;
        padding-bottom: max(10px, env(safe-area-inset-bottom, 10px));
    }
}
