* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body.chat-body {
    font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
    background: #f5f6fa;
    overflow: hidden;
}

.chat-widget {
    display: flex; flex-direction: column;
    height: 100vh; height: 100dvh;  /* 移动端浏览器地址栏适配 */
    background: #fff;
    max-width: 720px;
    margin: 0 auto;
    box-shadow: 0 0 30px rgba(0,0,0,.08);
}

.chat-topbar {
    padding: 14px 16px;
    background: var(--theme, #0084ff);
    color: #fff;
    display: flex; justify-content: space-between; align-items: center;
    flex-shrink: 0;
}
.chat-title { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.online-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: #52c41a; box-shadow: 0 0 0 3px rgba(82,196,26,.25);
}
.chat-lang select {
    background: rgba(255,255,255,.15); color: #fff;
    border: none; padding: 4px 8px; border-radius: 4px;
    font-size: 12px; cursor: pointer; outline: none;
}
.chat-lang select option { color: #000; }

.chat-messages {
    flex: 1; overflow-y: auto; padding: 16px;
    background: #f7f8fa;
    -webkit-overflow-scrolling: touch;
}
.message { display: flex; gap: 8px; margin-bottom: 14px; }
.message.agent { flex-direction: row; }
.message.visitor { flex-direction: row-reverse; }
.message .avatar {
    width: 34px; height: 34px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    background: var(--theme, #0084ff); color: #fff;
    font-size: 15px; flex-shrink: 0;
}
.message.visitor .avatar { background: #bbb; }
.message .bubble {
    max-width: 70%; padding: 10px 14px;
    background: #fff; border-radius: 12px;
    font-size: 14px; line-height: 1.5;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
    word-break: break-word;
}
.message.visitor .bubble { background: var(--theme, #0084ff); color: #fff; }

.chat-input {
    padding: 10px 12px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));  /* iPhone 底部安全区 */
    border-top: 1px solid #e4e6eb;
    display: flex; gap: 8px; align-items: flex-end;
    flex-shrink: 0; background: #fff;
}
.chat-input textarea {
    flex: 1; padding: 10px 12px;
    border: 1px solid #e4e6eb; border-radius: 8px;
    resize: none; font-family: inherit; font-size: 14px;
    max-height: 100px; outline: none;
}
.chat-input textarea:focus { border-color: var(--theme, #0084ff); }
.chat-input button {
    padding: 10px 18px; background: var(--theme, #0084ff);
    color: #fff; border: none; border-radius: 8px;
    cursor: pointer; font-size: 14px; flex-shrink: 0;
}
.chat-input button:disabled { opacity: .5; cursor: not-allowed; }

.chat-input .file-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    font-size: 22px;
    cursor: pointer;
    border-radius: 8px;
    color: #666;
    flex-shrink: 0;
    user-select: none;
    transition: background .15s;
}
.chat-input .file-btn:hover {
    background: #f0f2f5;
}

/* 消息里的图片 */
.message .bubble img {
    max-width: 200px;
    max-height: 200px;
    border-radius: 8px;
    cursor: pointer;
    display: block;
}
.message .bubble a {
    color: inherit;
    text-decoration: underline;
    word-break: break-all;
}
.chat-error {
    height: 100vh; display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    color: #666;
}
.chat-error-icon { font-size: 60px; margin-bottom: 16px; opacity: .4; }

/* 响应式：桌面端悬浮窗形态 */
@media (min-width: 769px) {
    body.chat-body { background: #f0f2f5; }
    .chat-widget {
        height: 90vh; margin-top: 5vh;
        border-radius: 12px; overflow: hidden;
        max-width: 480px;
    }
}

/* 暗色模式 */
@media (prefers-color-scheme: dark) {
    body.chat-body { background: #1a1a1a; }
    .chat-widget { background: #1a1a1a; }
    .chat-messages { background: #262626; }
    .message.agent .bubble { background: #333; color: #eee; }
    .chat-input { background: #1a1a1a; border-color: #333; }
    .chat-input textarea { background: #262626; color: #eee; border-color: #444; }
}