/* AIinWebs 智能助手 - 前台样式 */

#aiinwebs-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 99999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

#aiinwebs-toggle {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    color: white;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
    font-size: 24px;
}

#aiinwebs-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

#aiinwebs-panel {
    position: absolute;
    bottom: 70px;
    right: 0;
    width: 420px;
    height: 580px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: aiinwebs-slide-up 0.3s ease;
}

@keyframes aiinwebs-slide-up {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.aiinwebs-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 14px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    font-size: 15px;
    flex-shrink: 0;
}

.aiinwebs-header .aiinwebs-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.aiinwebs-header .aiinwebs-actions button {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.aiinwebs-header .aiinwebs-actions button:hover {
    background: rgba(255,255,255,0.3);
}

#aiinwebs-close {
    background: none;
    border: none;
    color: white;
    font-size: 22px;
    cursor: pointer;
    opacity: 0.8;
    line-height: 1;
}

#aiinwebs-close:hover { opacity: 1; }

#aiinwebs-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f5f7fb;
    scroll-behavior: smooth;
}

#aiinwebs-messages::-webkit-scrollbar { width: 4px; }
#aiinwebs-messages::-webkit-scrollbar-thumb { background: #ccc; border-radius: 2px; }

/* 消息样式 */
.aiinwebs-msg { margin-bottom: 16px; animation: aiinwebs-fade-in 0.3s ease; }

@keyframes aiinwebs-fade-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.aiinwebs-msg-label {
    font-size: 11px;
    color: #999;
    margin-bottom: 4px;
    font-weight: 500;
    letter-spacing: 0.3px;
}

.aiinwebs-msg-content {
    padding: 12px 16px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.7;
    word-break: break-word;
}

/* 用户消息 */
.aiinwebs-msg-user .aiinwebs-msg-label { text-align: right; }
.aiinwebs-msg-user .aiinwebs-msg-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    margin-left: 40px;
    border-bottom-right-radius: 4px;
}

/* AI消息 */
.aiinwebs-msg-assistant .aiinwebs-msg-content {
    background: white;
    color: #333;
    margin-right: 40px;
    border: 1px solid #e8ecf1;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

/* 流式输出光标 */
.aiinwebs-streaming::after {
    content: '▋';
    animation: aiinwebs-blink 1s infinite;
    color: #667eea;
    margin-left: 2px;
}

@keyframes aiinwebs-blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* AI消息内的Markdown样式 */
.aiinwebs-msg-assistant .aiinwebs-msg-content h1,
.aiinwebs-msg-assistant .aiinwebs-msg-content h2,
.aiinwebs-msg-assistant .aiinwebs-msg-content h3 {
    margin: 12px 0 6px;
    font-size: 15px;
    font-weight: 600;
    color: #222;
}

.aiinwebs-msg-assistant .aiinwebs-msg-content p { margin: 6px 0; }

.aiinwebs-msg-assistant .aiinwebs-msg-content ul,
.aiinwebs-msg-assistant .aiinwebs-msg-content ol {
    margin: 6px 0;
    padding-left: 20px;
}

.aiinwebs-msg-assistant .aiinwebs-msg-content li { margin: 3px 0; }

.aiinwebs-msg-assistant .aiinwebs-msg-content code {
    background: #f0f2f5;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
    color: #e83e8c;
}

.aiinwebs-msg-assistant .aiinwebs-msg-content pre {
    background: #1e1e2e;
    color: #cdd6f4;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 12px;
    margin: 8px 0;
}

.aiinwebs-msg-assistant .aiinwebs-msg-content pre code {
    background: none;
    color: inherit;
    padding: 0;
}

.aiinwebs-msg-assistant .aiinwebs-msg-content blockquote {
    border-left: 3px solid #667eea;
    margin: 8px 0;
    padding: 4px 12px;
    color: #666;
    background: #f8f9fc;
    border-radius: 0 6px 6px 0;
}

.aiinwebs-msg-assistant .aiinwebs-msg-content strong { color: #222; }

.aiinwebs-msg-assistant .aiinwebs-msg-content a {
    color: #667eea;
    text-decoration: none;
}

.aiinwebs-msg-assistant .aiinwebs-msg-content a:hover { text-decoration: underline; }

/* 图片预览 */
.aiinwebs-msg-content .aiinwebs-img-preview {
    margin: 10px 0;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid #e8ecf1;
    cursor: pointer;
    transition: transform 0.2s;
}

.aiinwebs-msg-content .aiinwebs-img-preview:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.aiinwebs-msg-content .aiinwebs-img-preview img {
    width: 100%;
    display: block;
    max-height: 250px;
    object-fit: cover;
}

/* 状态消息 */
.aiinwebs-msg-status .aiinwebs-msg-content {
    background: #e8f4fd;
    color: #0c5460;
    font-size: 12px;
    padding: 8px 12px;
    border-radius: 8px;
    margin-left: 0;
    margin-right: 0;
}

/* 加载动画 */
.aiinwebs-msg-loading .aiinwebs-msg-content {
    background: #fff8e1;
    color: #856404;
    font-size: 13px;
    padding: 10px 14px;
    border-radius: 10px;
}

.aiinwebs-msg-loading .aiinwebs-msg-content::after {
    content: '';
    animation: aiinwebs-dots 1.5s infinite;
}

@keyframes aiinwebs-dots {
    0% { content: '.'; }
    33% { content: '..'; }
    66% { content: '...'; }
}

/* 错误消息 */
.aiinwebs-msg-error .aiinwebs-msg-content {
    background: #fef2f2;
    color: #991b1b;
    font-size: 13px;
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid #fecaca;
}

/* 输入区域 */
.aiinwebs-input-area {
    padding: 12px 14px;
    border-top: 1px solid #e8ecf1;
    display: flex;
    gap: 8px;
    background: white;
    flex-shrink: 0;
}

#aiinwebs-input {
    flex: 1;
    border: 1.5px solid #e0e4ea;
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 14px;
    resize: none;
    outline: none;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
    min-height: 20px;
    max-height: 80px;
}

#aiinwebs-input:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

#aiinwebs-input::placeholder { color: #aaa; }

#aiinwebs-send {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 10px;
    padding: 10px 20px;
    font-size: 14px;
    cursor: pointer;
    font-weight: 500;
    white-space: nowrap;
    transition: opacity 0.2s, transform 0.1s;
}

#aiinwebs-send:hover { opacity: 0.9; }
#aiinwebs-send:active { transform: scale(0.96); }
#aiinwebs-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* 响应式 - 移动端优化 */
@media (max-width: 768px) {
    #aiinwebs-widget {
        bottom: 130px;
        left: 16px;
        right: auto;
    }

    #aiinwebs-panel {
        width: calc(100vw - 16px);
        height: calc(100dvh - 210px);
        left: 8px;
        right: auto;
        bottom: 140px;
        border-radius: 12px;
    }

    #aiinwebs-toggle {
        width: 50px;
        height: 50px;
    }

    .aiinwebs-input-area {
        padding: 10px 12px;
    }

    #aiinwebs-input {
        min-height: 44px;
        font-size: 16px;
    }

    #aiinwebs-send {
        min-height: 44px;
        min-width: 60px;
        padding: 10px 16px;
    }

    .aiinwebs-msg-content {
        font-size: 14px;
        line-height: 1.65;
    }

    #aiinwebs-messages {
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }
}

/* 超小屏幕 */
@media (max-width: 360px) {
    #aiinwebs-panel {
        width: calc(100vw - 8px);
        right: 4px;
    }

    .aiinwebs-header {
        padding: 10px 14px;
        font-size: 14px;
    }
}
