/* ============================================================
   招生智能助手 - 全局样式
   简洁、清爽、现代
   ============================================================ */

/* --- CSS 变量 --- */
:root {
    --c-primary: #576B95;
    --c-green: #07C160;
    --c-red: #FA5151;
    --c-orange: #FF8F1F;
    --c-bg: #EDEDED;
    --c-white: #FFFFFF;
    --c-text: #191919;
    --c-text-2: #666666;
    --c-text-3: #999999;
    --c-border: #E6E6E6;
    --c-fill: #F7F7F7;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* --- 基础重置 --- */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    width: 100%; height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
    font-size: 15px;
    color: var(--c-text);
    background: var(--c-bg);
}

/* ============================================================
   主 Widget 容器
   ============================================================ */
.kf-widget {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    display: flex;
    flex-direction: column;
    background: var(--c-bg);
    overflow: hidden;
}

/* ============================================================
   顶部栏
   ============================================================ */
.kf-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: calc(12px + var(--safe-top)) 16px 12px;
    background: var(--c-white);
    border-bottom: 1px solid var(--c-border);
    flex-shrink: 0;
    user-select: none;
}
.kf-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}
.kf-header-avatar {
    width: 40px; height: 40px;
    border-radius: 6px;
    background: #576B95;
    display: flex;
    align-items: center;
    justify-content: center;
}
.kf-header-info h3 {
    font-size: 17px;
    font-weight: 600;
    color: var(--c-text);
    line-height: 1.2;
}
.kf-header-info span {
    font-size: 12px;
    color: var(--c-text-3);
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 1px;
}
.kf-header-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--c-green);
}
.kf-header-actions {
    display: flex;
    gap: 12px;
}
.kf-header-btn {
    width: 32px; height: 32px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--c-text-2);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}
.kf-header-btn:active { background: var(--c-fill); }
.kf-header-text-btn {
    width: auto;
    padding: 0 10px;
    font-size: 13px;
    font-weight: 500;
    gap: 4px;
}

/* ============================================================
   聊天区域
   ============================================================ */
.kf-body-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px 14px;
    -webkit-overflow-scrolling: touch;
}
.kf-body-scroll::-webkit-scrollbar { width: 0; }
.kf-chat-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ============================================================
   消息气泡
   ============================================================ */
.kf-msg {
    display: flex;
    gap: 8px;
    max-width: 76%;
    animation: msgIn 0.25s ease;
}
@keyframes msgIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
.kf-msg.agent { align-self: flex-start; }
.kf-msg.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}
.kf-msg.system {
    align-self: center;
    max-width: 100%;
}

/* 头像 */
.kf-msg-avatar {
    width: 36px; height: 36px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.kf-msg.agent .kf-msg-avatar {
    background: var(--c-white);
    color: var(--c-primary);
}
.kf-msg.user .kf-msg-avatar {
    background: var(--c-primary);
    color: #fff;
}
.kf-msg.system .kf-msg-avatar {
    width: auto; height: auto;
    background: none;
    font-size: 28px;
}
.kf-msg-name {
    font-size: 11px;
    color: var(--c-text-3);
    margin-bottom: 2px;
    padding: 0 4px;
}
.kf-msg.user .kf-msg-name { text-align: right; }

/* 气泡 */
.kf-msg-bubble {
    padding: 10px 14px;
    border-radius: 4px;
    word-break: break-word;
    font-size: 15px;
    line-height: 1.55;
    position: relative;
}
.kf-msg.agent .kf-msg-bubble {
    background: var(--c-white);
    color: var(--c-text);
}
.kf-msg.user .kf-msg-bubble {
    background: #95EC69;
    color: #000;
}
.kf-msg-bubble a {
    color: var(--c-primary);
    text-decoration: none;
}
.kf-msg-time {
    font-size: 10px;
    color: var(--c-text-3);
    margin-top: 4px;
    padding: 0 4px;
}
.kf-msg.user .kf-msg-time { text-align: right; }

/* 欢迎消息 — 左对齐，像普通助手消息 */
.kf-welcome-msg {
    align-self: flex-start !important;
    max-width: 76% !important;
}
.kf-welcome-msg .kf-msg-bubble {
    text-align: left;
    color: var(--c-text);
    font-size: 15px;
}

/* ============================================================
   推荐问题卡片
   ============================================================ */
/* 推荐问题 — 左对齐但占满宽度 */
#kf-questions-msg {
    max-width: 100% !important;
}
.kf-q-bubble {
    background: var(--c-white);
    padding: 14px 16px;
    border-radius: 8px;
    width: 100%;
}
.kf-q-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}
.kf-q-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--c-text);
}
.kf-q-refresh-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--c-text-3);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    background: none;
    border: none;
    font-family: inherit;
    transition: background 0.15s;
    white-space: nowrap;
}
.kf-q-refresh-btn:active { background: var(--c-fill); }

/* 标签栏 */
.kf-q-tabs-wrapper {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 10px;
}
.kf-q-tabs-bar {
    flex: 1;
    display: flex;
    gap: 8px;
    overflow-x: auto;
    scroll-behavior: smooth;
    padding: 2px 0;
}
.kf-q-tabs-bar::-webkit-scrollbar { display: none; }
.kf-q-tab {
    padding: 4px 12px;
    font-size: 13px;
    border: none;
    border-radius: 4px;
    background: var(--c-fill);
    color: var(--c-text-2);
    cursor: pointer;
    white-space: nowrap;
    font-family: inherit;
    transition: all 0.15s;
}
.kf-q-tab.active {
    background: var(--c-primary);
    color: #fff;
}
.kf-q-arrow {
    width: 24px; height: 24px;
    flex-shrink: 0;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--c-text-3);
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.kf-q-arrow:active { background: var(--c-fill); }

/* 问题列表 */
.kf-q-list {
    list-style: none;
    display: flex;
    flex-direction: column;
}
.kf-q-item {
    padding: 10px 0;
    font-size: 14px;
    color: var(--c-text-2);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: color 0.15s;
    border-bottom: 1px solid var(--c-fill);
}
.kf-q-item:last-child { border-bottom: none; }
.kf-q-item:active { color: var(--c-primary); }
.kf-q-dot {
    color: var(--c-text-3);
    font-size: 16px;
    line-height: 1;
    flex-shrink: 0;
}

/* ============================================================
   正在输入
   ============================================================ */
.typing-dots {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 14px 16px !important;
}
.typing-dots span {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: #CCC;
    animation: typingBounce 1.4s infinite ease-in-out;
}
.typing-dots span:nth-child(1) { animation-delay: 0s; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
    0%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-5px); }
}

/* ============================================================
   输入区域
   ============================================================ */
.kf-input-area {
    border-top: 1px solid var(--c-border);
    padding: 10px 12px calc(10px + var(--safe-bottom));
    background: var(--c-fill);
    flex-shrink: 0;
}
.kf-input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}
.kf-input-text {
    flex: 1;
    border: none;
    border-radius: 6px;
    padding: 12px 16px;
    font-size: 16px;
    font-family: inherit;
    resize: none;
    outline: none;
    max-height: 144px;
    min-height: 92px;
    line-height: 1.4;
    background: var(--c-white);
    color: var(--c-text);
}
.kf-input-text::placeholder { color: var(--c-text-3); }
.kf-send-btn {
    width: 44px; height: 44px;
    border: none;
    border-radius: 6px;
    background: var(--c-primary);
    color: #fff;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.15s;
}
.kf-send-btn:active { opacity: 0.8; }
.kf-input-tools {
    display: flex;
    gap: 6px;
    padding-top: 8px;
}
.kf-tool-btn {
    padding: 4px 12px;
    font-size: 12px;
    border: none;
    border-radius: 4px;
    background: var(--c-white);
    color: var(--c-text-2);
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s;
}
.kf-tool-btn:active { background: var(--c-border); }

/* ============================================================
   快捷操作条
   ============================================================ */
.kf-quick-actions {
    display: flex;
    gap: 8px;
    padding: 10px 14px;
    background: var(--c-fill);
    border-top: 1px solid var(--c-border);
    flex-shrink: 0;
    overflow-x: auto;
}
.kf-quick-actions::-webkit-scrollbar { display: none; }
.kf-action-btn {
    padding: 7px 16px;
    font-size: 13px;
    border: none;
    border-radius: 4px;
    background: var(--c-white);
    color: var(--c-text-2);
    cursor: pointer;
    white-space: nowrap;
    font-family: inherit;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: background 0.15s;
}
.kf-action-btn:active { background: var(--c-border); }

/* ============================================================
   留言按钮（气泡内）
   ============================================================ */
.kf-no-match-bubble { padding-bottom: 6px !important; }
.kf-leave-msg-wrap { margin-top: 10px; display: flex; }
.kf-leave-msg-btn {
    padding: 8px 18px;
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
    font-family: inherit;
    background: var(--c-white);
    color: var(--c-primary);
    border: 1px solid var(--c-border);
    transition: all 0.15s;
    display: flex;
    align-items: center;
    gap: 4px;
}
.kf-leave-msg-btn:active { background: var(--c-fill); }

/* ============================================================
   通用弹窗
   ============================================================ */
.kf-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.25s;
}
.kf-modal-overlay.show { opacity: 1; visibility: visible; }
.kf-modal-box {
    width: 360px;
    max-width: 92vw;
    background: var(--c-white);
    border-radius: 12px;
    overflow: hidden;
    transform: scale(0.95);
    transition: transform 0.25s;
}
.kf-modal-overlay.show .kf-modal-box { transform: scale(1); }
.kf-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--c-border);
}
.kf-modal-header h4 {
    font-size: 16px;
    font-weight: 600;
}
.kf-modal-close {
    width: 28px; height: 28px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--c-text-3);
    cursor: pointer;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.kf-modal-close:active { background: var(--c-fill); }
.kf-modal-body { padding: 20px; }
.kf-modal-field { margin-bottom: 16px; }
.kf-modal-field:last-child { margin-bottom: 0; }
.kf-modal-field label {
    display: block;
    font-size: 13px;
    color: var(--c-text-2);
    margin-bottom: 6px;
    font-weight: 500;
}
.kf-required { color: var(--c-red); }
.kf-modal-field input,
.kf-modal-field textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--c-border);
    border-radius: 4px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    resize: none;
    background: var(--c-white);
    color: var(--c-text);
    transition: border-color 0.15s;
}
.kf-modal-field input:focus,
.kf-modal-field textarea:focus { border-color: var(--c-primary); }
.kf-modal-footer { padding: 0 20px 20px; }
.kf-modal-submit {
    width: 100%;
    padding: 11px 0;
    border-radius: 4px;
    font-size: 15px;
    cursor: pointer;
    font-family: inherit;
    background: var(--c-primary);
    color: #fff;
    border: none;
    font-weight: 500;
    transition: opacity 0.15s;
}
.kf-modal-submit:active { opacity: 0.85; }
.kf-modal-submit:disabled { opacity: 0.5; cursor: not-allowed; }

/* ============================================================
   留言历史面板
   ============================================================ */
.kf-messages-panel {
    position: fixed;
    inset: 0;
    background: var(--c-bg);
    z-index: 999;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.3s ease;
}
.kf-messages-panel.show { transform: translateX(0); }
.kf-msg-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: calc(12px + var(--safe-top)) 16px 12px;
    background: var(--c-white);
    border-bottom: 1px solid var(--c-border);
    flex-shrink: 0;
}
.kf-msg-panel-header h3 {
    font-size: 17px;
    font-weight: 600;
}
.kf-msg-panel-back {
    width: 32px; height: 32px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--c-text-2);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}
.kf-msg-panel-back:active { background: var(--c-fill); }
.kf-msg-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px 14px;
    -webkit-overflow-scrolling: touch;
}

/* 查询区 */
.kf-msg-lookup {
    text-align: center;
    padding: 40px 16px 20px;
    animation: msgIn 0.3s ease;
}
.kf-msg-lookup-icon {
    width: 64px; height: 64px;
    border-radius: 12px;
    background: var(--c-fill);
    color: var(--c-text-3);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
}
.kf-msg-lookup-desc {
    font-size: 14px;
    color: var(--c-text-2);
    line-height: 1.6;
    margin-bottom: 24px;
}
.kf-msg-lookup-form {
    display: flex;
    gap: 8px;
    max-width: 340px;
    margin: 0 auto;
}
.kf-msg-lookup-input {
    flex: 1;
    padding: 11px 14px;
    border: 1px solid var(--c-border);
    border-radius: 4px;
    font-size: 16px;
    font-family: inherit;
    outline: none;
    background: var(--c-white);
    color: var(--c-text);
    transition: border-color 0.15s;
}
.kf-msg-lookup-input:focus { border-color: var(--c-primary); }
.kf-msg-lookup-input::placeholder { color: var(--c-text-3); }
.kf-msg-lookup-btn {
    padding: 11px 20px;
    border: none;
    border-radius: 4px;
    background: var(--c-primary);
    color: #fff;
    font-size: 15px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    transition: opacity 0.15s;
}
.kf-msg-lookup-btn:active { opacity: 0.85; }
.kf-msg-lookup-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.kf-msg-lookup-error {
    color: var(--c-red);
    font-size: 13px;
    margin-top: 10px;
    min-height: 18px;
}

/* 结果区 */
.kf-msg-results { animation: msgIn 0.3s ease; }
.kf-msg-results-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    font-size: 14px;
    color: var(--c-text-2);
}
.kf-msg-results-back {
    padding: 4px 12px;
    font-size: 12px;
    border: none;
    border-radius: 4px;
    background: var(--c-white);
    color: var(--c-text-2);
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s;
}
.kf-msg-results-back:active { background: var(--c-border); }

/* 留言列表 */
.kf-msg-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.kf-msg-card {
    background: var(--c-white);
    border-radius: 8px;
    padding: 14px 16px;
    animation: msgIn 0.25s ease;
}
.kf-msg-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}
.kf-msg-card-time {
    font-size: 12px;
    color: var(--c-text-3);
}
.kf-msg-card-badge {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 3px;
    font-weight: 500;
}
.kf-msg-card-badge.pending {
    background: #FFF1E6;
    color: var(--c-orange);
}
.kf-msg-card-badge.replied {
    background: #E8F8EE;
    color: var(--c-green);
}
.kf-msg-card-question {
    font-size: 14px;
    color: var(--c-text);
    line-height: 1.55;
    margin-bottom: 6px;
    word-break: break-word;
}
.kf-msg-card-meta {
    font-size: 12px;
    color: var(--c-text-3);
    margin-bottom: 6px;
}
.kf-msg-card-reply {
    background: var(--c-fill);
    border-radius: 4px;
    padding: 10px 12px;
    margin-top: 6px;
}
.kf-msg-card-reply-label {
    font-size: 12px;
    color: var(--c-primary);
    font-weight: 600;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}
.kf-msg-card-reply-text {
    font-size: 14px;
    color: var(--c-text);
    line-height: 1.55;
    word-break: break-word;
}
.kf-msg-card-reply-time {
    font-size: 11px;
    color: var(--c-text-3);
    margin-top: 4px;
}

/* 空状态 */
.kf-msg-empty {
    text-align: center;
    padding: 40px 16px;
    color: var(--c-text-3);
}
.kf-msg-empty-icon { font-size: 40px; margin-bottom: 10px; }
.kf-msg-empty p { font-size: 14px; }

/* 加载 */
.kf-msg-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 32px 0;
}
.kf-msg-loading span {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: #CCC;
    animation: typingBounce 1.4s infinite ease-in-out;
}
.kf-msg-loading span:nth-child(1) { animation-delay: 0s; }
.kf-msg-loading span:nth-child(2) { animation-delay: 0.2s; }
.kf-msg-loading span:nth-child(3) { animation-delay: 0.4s; }

/* ============================================================
   移动端适配
   ============================================================ */
@media (max-width: 480px) {
    .kf-msg { max-width: 82%; }
    .kf-chat-body { gap: 14px; }
    .kf-modal-overlay { align-items: flex-end; }
    .kf-modal-box {
        width: 100%;
        max-width: 100%;
        border-radius: 12px 12px 0 0;
    }
}
