/* 全局样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Microsoft YaHei', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

/* 聊天容器 */
.chat-container {
    width: 100%;
    max-width: 800px;
    height: 80vh;
    max-height: 700px;
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* 顶部导航栏 */
.chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.header-content {
    display: flex;
    align-items: center;
    gap: 15px;
}

.logo {
    font-size: 32px;
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.title h1 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 5px;
}

.title p {
    font-size: 14px;
    opacity: 0.9;
}

.status {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
}

.online-indicator {
    width: 10px;
    height: 10px;
    background: #4ade80;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.7;
        transform: scale(1.2);
    }
}

/* 聊天消息区域 */
.chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* 滚动条样式 */
.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* 消息样式 */
.message {
    display: flex;
    margin-bottom: 15px;
    animation: fadeIn 0.3s ease;
}

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

.user-message {
    justify-content: flex-end;
}

.bot-message {
    justify-content: flex-start;
}

.message-content {
    max-width: 70%;
    padding: 12px 16px;
    border-radius: 18px;
    position: relative;
    word-wrap: break-word;
}

.user-message .message-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-bottom-right-radius: 6px;
}

.bot-message .message-content {
    background: white;
    color: #334155;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.message-time {
    font-size: 11px;
    opacity: 0.7;
    display: block;
    margin-top: 5px;
    text-align: right;
}

.bot-message .message-time {
    text-align: left;
}

/* 人工客服消息:必须和机器人明显区分开。
   学员在等客服时最怕的就是"不知道这条是谁说的" —— 所以这里既换了配色(绿色系,
   和机器人的灰白气泡、学员的紫蓝气泡都不同),又在气泡上方直接标出"客服"和姓名。 */
.agent-message {
    justify-content: flex-start;
}

.agent-message .message-content {
    background: #f0fdf4;
    color: #14532d;
    border: 1px solid #bbf7d0;
    border-bottom-left-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.agent-message .message-time {
    text-align: left;
}

.agent-tag {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: #15803d;
    margin-bottom: 4px;
}

/* 提示条:转人工 / 网络异常共用一套外壳(DOM 由 script.js 动态插入)。
   两者可以同时存在(转人工期间网络恰好抖了一下),所以是两个独立元素,不互相顶掉。 */
.notice-bar {
    display: none;
    align-items: center;
    gap: 8px;
    margin: 0 20px 10px;
    padding: 9px 12px;
    border-radius: 10px;
    font-size: 13px;
    line-height: 1.5;
}

.handover-bar {
    display: none;
    background: #fff7ed;
    border: 1px solid #fed7aa;
    color: #9a3412;
}

.net-bar {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #b91c1c;
}

.net-bar .dot {
    flex: 0 0 auto;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #ef4444;
    animation: pulse 1.4s ease-in-out infinite;
}

.handover-bar .dot {
    flex: 0 0 auto;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #f97316;
    animation: pulse 1.4s ease-in-out infinite;
}

/* 学员称呼:首次进入时问一句,填完自己消失。
   做成输入条而不是弹窗 —— 弹窗会挡住欢迎语,学员第一眼看到的是个"要填表"的框。 */
.name-bar {
    background: #eef2ff;
    border: 1px solid #c7d2fe;
    color: #3730a3;
    flex-wrap: wrap;
}

.name-bar input {
    flex: 1;
    min-width: 120px;
    padding: 7px 12px;
    border: 1px solid #c7d2fe;
    border-radius: 8px;
    font-size: 14px;      /* ≥16px 防 iOS 缩放只在主输入框必要;这里逐字输入,14 够用且不放大 */
    outline: none;
    background: #fff;
    color: #1e1b4b;
}

.name-bar input:focus { border-color: #667eea; }

.name-bar button {
    flex: 0 0 auto;
    padding: 7px 14px;
    border: none;
    border-radius: 8px;
    background: #667eea;
    color: #fff;
    font-size: 14px;
    cursor: pointer;
}

.name-bar button:disabled { opacity: .5; cursor: default; }

.name-bar .name-skip {
    background: none;
    color: #6366f1;
    padding: 7px 4px;
    font-size: 13px;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: .45; transform: scale(.8); }
}

/* 输入区域 */
.chat-input-container {
    padding: 20px;
    background: white;
    border-top: 1px solid #e2e8f0;
}

.input-wrapper {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

#userInput {
    flex: 1;
    padding: 15px 20px;
    border: 2px solid #e2e8f0;
    border-radius: 25px;
    font-size: 16px;
    transition: all 0.3s ease;
    outline: none;
}

#userInput:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.send-btn {
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 20px;      /* 内联 SVG 用 1em 取尺寸,图标大小由这里决定 */
    font-size: 18px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    justify-content: center;
    align-items: center;
}

.send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

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

/* 顶部图标与发送图标,原先是 Font Awesome 的 <i>。现在换成内联 SVG(见 index.html):
   去掉了一个国内连不上、还会阻塞渲染的 CDN 样式表。
   1em 取尺寸 → 跟着所在容器的 font-size 走(.logo 桌面 32px / 手机 22px 自动适配),
   fill 用 currentColor → 颜色跟着继承,不用给 SVG 单独设色。 */
.logo svg,
.send-btn svg {
    display: block;
    width: 1em;
    height: 1em;
}

/* 快速提问 */
.quick-questions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.quick-questions p {
    font-size: 14px;
    color: #64748b;
    margin-right: 5px;
}

.quick-btn {
    padding: 8px 16px;
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-radius: 15px;
    color: #334155;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.quick-btn:hover {
    background: #e2e8f0;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* ================= 手机端(≤768px):满屏 app 形态 =================
   学员绝大多数用手机,这一档才是主场景:去掉装饰、吃掉整屏、处理键盘与安全区。 */
@media (max-width: 768px) {
    body {
        /* 关键:桌面端 body 有 20px 内边距,而容器高度是 100vh/100dvh。
           两者相加会超出视口 40px —— 页面多滚一次、底部输入区被推出屏幕。
           手机端必须把内边距清零。 */
        padding: 0;
        min-height: 100dvh;
        background: #f8fafc;      /* 满屏后渐变只在边缘露一条,不如用底色 */
    }

    .chat-container {
        /* ① dvh:Chrome 108+ / Safari 15.4+ 会跟着键盘收缩;
           ② --app-h:由 script.js 用 visualViewport 写入,兜老 iOS(不认 dvh)。 */
        height: var(--app-h, 100dvh);
        max-height: none;
        max-width: none;
        border-radius: 0;
        box-shadow: none;
    }

    /* 头部瘦身:手机上每一行高度都是学员能多看一条消息的空间 */
    .chat-header {
        padding: calc(11px + env(safe-area-inset-top)) 14px 11px;
    }
    .header-content { gap: 10px; }
    .logo { width: 36px; height: 36px; font-size: 22px; }
    .title h1 { font-size: 18px; margin-bottom: 0; }
    .title p { display: none; }          /* 副标题在手机上只是占地方 */
    .status { font-size: 12px; gap: 6px; }

    .chat-messages { padding: 14px 12px; gap: 12px; }
    .message { margin-bottom: 0; }
    .message-content { max-width: 86%; padding: 10px 14px; }

    .chat-input-container {
        /* 安全区:全面屏底部手势条 / 横屏时的刘海,都得让开 */
        padding: 10px calc(12px + env(safe-area-inset-right))
                 calc(10px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left));
    }
    .input-wrapper { margin-bottom: 8px; gap: 8px; }
    #userInput { padding: 12px 16px; }
    .send-btn { width: 46px; height: 46px; flex: 0 0 auto; }

    /* 快速提问改横向滚动:原来手机上是竖排四行,白白占掉消息区一大块高度 */
    .quick-questions {
        flex-wrap: nowrap;
        overflow-x: auto;
        align-items: center;
        gap: 8px;
        padding-bottom: 2px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .quick-questions::-webkit-scrollbar { display: none; }
    .quick-questions p { flex: 0 0 auto; margin-right: 0; font-size: 13px; }
    .quick-btn { flex: 0 0 auto; padding: 7px 12px; }
    .quick-btn:hover { transform: none; box-shadow: none; }   /* 手机上没有 hover,省掉重绘 */

    .notice-bar { margin: 0 12px 8px; }
}

/* 加载动画 */
.typing-indicator {
    display: flex;
    gap: 5px;
    padding: 12px 16px;
    background: white;
    border-radius: 18px;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 6px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: #94a3b8;
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* 多行回复自动换行 */
.message-content p {
    white-space: pre-wrap;
    word-break: break-word;
    margin: 0;
}