/* ===== 全局 ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
    --bg: #f4f6fa;
    --panel: #ffffff;
    --border: #e5e9f0;
    --text: #1f2937;
    --text-soft: #6b7280;
    --text-mute: #9ca3af;
    --primary: #2563eb;
    --primary-soft: #eff6ff;
    --dealer: #ea580c;
    --dealer-soft: #fff7ed;
    --end: #0f766e;
    --end-soft: #f0fdfa;
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --radius: 12px;
}
html, body { height: 100%; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.6;
}

/* ===== 布局 ===== */
.app { display: flex; height: 100vh; overflow: hidden; }

/* ===== 侧边栏 ===== */
.sidebar {
    width: 300px;
    min-width: 300px;
    background: var(--panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 18px 18px 16px;
    border-bottom: 1px solid var(--border);
}
.brand-logo {
    width: 40px; height: 40px;
    border-radius: 10px;
    background: linear-gradient(135deg, #2563eb, #7c3aed);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; font-weight: 700;
}
.brand-text h1 { font-size: 15px; font-weight: 600; }
.brand-text p { font-size: 12px; color: var(--text-mute); margin-top: 2px; }

/* 面板 */
.panel { padding: 16px 18px; border-bottom: 1px solid var(--border); }
.panel-title {
    display: flex; justify-content: space-between; align-items: center;
    font-size: 13px; font-weight: 600; color: var(--text-soft);
    margin-bottom: 12px;
}
.mini-btn {
    background: var(--primary); color: #fff;
    border: none; border-radius: 6px;
    padding: 4px 10px; font-size: 12px; cursor: pointer;
    transition: opacity .15s;
}
.mini-btn:hover { opacity: .88; }
.mini-btn.danger { background: #ef4444; }

.discount-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.discount-row label { font-size: 13px; color: var(--text); }
.discount-input { display: flex; align-items: center; gap: 8px; }
.discount-input input {
    width: 70px; padding: 6px 8px;
    border: 1px solid var(--border); border-radius: 6px;
    font-size: 13px; text-align: center; color: var(--text);
    background: #fff;
}
.discount-input input:focus { outline: none; border-color: var(--primary); }
.discount-hint { font-size: 12px; color: var(--dealer); font-weight: 600; }
.panel-tip { font-size: 11px; color: var(--text-mute); margin-top: 6px; }

/* 历史 */
.history-panel { flex: 1; overflow: hidden; display: flex; flex-direction: column; padding-bottom: 8px; }
.history-list { flex: 1; overflow-y: auto; }
.history-item {
    padding: 9px 10px; margin: 0 6px 4px;
    border-radius: 8px; cursor: pointer;
    transition: background .15s;
    border: 1px solid transparent;
}
.history-item:hover { background: var(--primary-soft); border-color: #dbeafe; }
.history-item .h-kw { font-size: 13px; font-weight: 600; color: var(--primary); }
.history-item .h-meta { font-size: 11px; color: var(--text-mute); margin-top: 2px; }
.empty-tip { font-size: 12px; color: var(--text-mute); text-align: center; padding: 20px 0; }

/* 侧边栏底部 */
.sidebar-footer { padding: 12px 18px; border-top: 1px solid var(--border); }
.reload-btn {
    width: 100%; padding: 9px;
    background: var(--primary-soft); color: var(--primary);
    border: 1px solid #dbeafe; border-radius: 8px;
    font-size: 13px; cursor: pointer; transition: all .15s;
}
.reload-btn:hover { background: #dbeafe; }
.reload-icon { display: inline-block; }
.data-count { font-size: 11px; color: var(--text-mute); text-align: center; margin-top: 8px; }

/* ===== 聊天区 ===== */
.chat { flex: 1; display: flex; flex-direction: column; background: var(--bg); min-width: 0; }
.chat-header {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 20px; background: var(--panel);
    border-bottom: 1px solid var(--border);
}
.menu-btn { display: none; background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text); }
.chat-title { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; box-shadow: 0 0 0 3px rgba(34,197,94,.15); }

.messages { flex: 1; overflow-y: auto; padding: 24px 0; }

/* 消息气泡 */
.msg { display: flex; margin: 0 24px 16px; max-width: 760px; }
.msg.user { flex-direction: row-reverse; margin-left: auto; }
.msg-avatar {
    width: 36px; height: 36px; border-radius: 9px;
    display: flex; align-items: center; justify-content: center;
    font-size: 16px; flex-shrink: 0;
}
.msg.bot .msg-avatar { background: linear-gradient(135deg, #2563eb, #7c3aed); color: #fff; margin-right: 12px; }
.msg.user .msg-avatar { background: #e5e7eb; color: var(--text-soft); margin-left: 12px; }
.msg-body { min-width: 0; }
.msg.user .msg-body { display: flex; flex-direction: column; align-items: flex-end; }
.bubble {
    padding: 10px 14px; border-radius: 14px;
    font-size: 14px; word-break: break-word;
    max-width: 560px;
}
.msg.bot .bubble { background: var(--panel); border: 1px solid var(--border); border-top-left-radius: 4px; }
.msg.user .bubble { background: var(--primary); color: #fff; border-top-right-radius: 4px; }
.msg-time { font-size: 11px; color: var(--text-mute); margin-top: 4px; padding: 0 4px; }

/* 报价卡片 */
.quote-card {
    background: var(--panel); border: 1px solid var(--border);
    border-radius: 12px; overflow: hidden; margin-top: 4px;
    box-shadow: var(--shadow); width: 460px; max-width: 100%;
}
.qc-head {
    padding: 12px 16px; background: linear-gradient(135deg, #eff6ff, #f5f3ff);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.qc-id { font-size: 16px; font-weight: 700; color: var(--primary); }
.qc-name { font-size: 14px; font-weight: 600; color: var(--text); }
.qc-tag {
    font-size: 11px; padding: 2px 8px; border-radius: 10px;
    background: #e0e7ff; color: #4338ca;
}
.qc-body { padding: 14px 16px; }
.qc-row { display: flex; margin-bottom: 8px; font-size: 13px; }
.qc-row:last-child { margin-bottom: 0; }
.qc-label { color: var(--text-mute); width: 64px; flex-shrink: 0; }
.qc-value { color: var(--text); }
.qc-price-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
    margin: 12px 0; 
}
.qc-price-box {
    padding: 10px 12px; border-radius: 8px; border: 1px solid;
}
.qc-price-box.end { background: var(--end-soft); border-color: #ccfbf1; }
.qc-price-box.dealer { background: var(--dealer-soft); border-color: #fed7aa; }
.qc-price-label { font-size: 11px; color: var(--text-mute); margin-bottom: 4px; }
.qc-price-num { font-size: 18px; font-weight: 700; }
.qc-price-box.end .qc-price-num { color: var(--end); }
.qc-price-box.dealer .qc-price-num { color: var(--dealer); }
.qc-price-unit { font-size: 12px; color: var(--text-mute); font-weight: 400; margin-left: 2px; }
.qc-lead {
    display: flex; align-items: center; gap: 6px;
    padding: 8px 12px; background: #fef9c3; border-radius: 8px;
    font-size: 13px; color: #854d0e; margin-top: 10px;
}
.qc-desc {
    margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border);
    font-size: 12px; color: var(--text-soft); line-height: 1.6;
}

/* 多结果列表 */
.match-list { width: 460px; max-width: 100%; }
.match-list .bubble-tip { font-size: 13px; color: var(--text-soft); margin-bottom: 10px; }
.match-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 10px 14px; background: var(--panel);
    border: 1px solid var(--border); border-radius: 10px;
    margin-bottom: 8px; cursor: pointer; transition: all .15s;
}
.match-item:hover { border-color: var(--primary); background: var(--primary-soft); transform: translateX(2px); }
.match-item .mi-left { min-width: 0; }
.match-item .mi-id { font-size: 13px; font-weight: 700; color: var(--primary); }
.match-item .mi-name { font-size: 12px; color: var(--text-soft); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.match-item .mi-price { font-size: 13px; font-weight: 600; color: var(--dealer); flex-shrink: 0; margin-left: 10px; }
.match-item .mi-arrow { color: var(--text-mute); margin-left: 6px; }

/* 欢迎卡片 */
.welcome-card {
    background: var(--panel); border: 1px solid var(--border);
    border-radius: 14px; padding: 24px; margin: 0 24px;
    box-shadow: var(--shadow); max-width: 560px;
}
.welcome-card h3 { font-size: 16px; margin-bottom: 12px; color: var(--text); }
.welcome-card ul { list-style: none; padding: 0; }
.welcome-card li { padding: 6px 0; font-size: 13px; color: var(--text-soft); display: flex; align-items: flex-start; gap: 8px; }
.welcome-card li::before { content: "•"; color: var(--primary); font-weight: 700; }
.welcome-card .eg {
    margin-top: 14px; padding: 10px 12px; background: var(--bg);
    border-radius: 8px; font-size: 12px; color: var(--text-soft);
}
.welcome-card .eg code { background: #e0e7ff; color: #4338ca; padding: 2px 6px; border-radius: 4px; font-family: Consolas, monospace; }

/* 打字状态 */
.typing { display: flex; gap: 4px; padding: 4px 0; }
.typing span {
    width: 7px; height: 7px; border-radius: 50%; background: var(--text-mute);
    animation: blink 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* 输入栏 */
.input-bar {
    display: flex; gap: 10px; padding: 14px 20px;
    background: var(--panel); border-top: 1px solid var(--border);
}
.input-bar input {
    flex: 1; padding: 12px 16px; font-size: 14px;
    border: 1px solid var(--border); border-radius: 10px;
    background: var(--bg); color: var(--text);
    transition: border-color .15s;
}
.input-bar input:focus { outline: none; border-color: var(--primary); background: #fff; }
.send-btn {
    padding: 0 22px; background: var(--primary); color: #fff;
    border: none; border-radius: 10px; font-size: 14px; font-weight: 600;
    cursor: pointer; transition: opacity .15s;
}
.send-btn:hover { opacity: .9; }
.send-btn:disabled { opacity: .5; cursor: not-allowed; }

/* 滚动条 */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }
::-webkit-scrollbar-track { background: transparent; }

/* ===== 数据概览面板 ===== */
.stat-row { display: flex; gap: 10px; margin-bottom: 12px; }
.stat-item { flex: 1; background: var(--bg); border-radius: 8px; padding: 10px 6px; text-align: center; }
.stat-num { font-size: 20px; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 11px; color: var(--text-mute); margin-top: 2px; }
.brand-list { display: flex; flex-wrap: wrap; gap: 6px; }
.brand-tag { font-size: 11px; padding: 3px 8px; border-radius: 10px; background: #e0e7ff; color: #4338ca; }
.data-tip { font-size: 11px; color: var(--text-mute); text-align: center; margin-top: 8px; line-height: 1.5; }

/* ===== 报价卡片扩展 ===== */
.qc-brand { font-size: 11px; padding: 2px 8px; border-radius: 10px; background: #f3e8ff; color: #7c3aed; font-weight: 600; }
.qc-list-price { font-size: 13px; color: var(--text-soft); margin-bottom: 10px; padding: 8px 12px; background: #f8fafc; border-radius: 8px; }
.qc-list-price b { color: var(--text); font-size: 16px; }
.qc-price-disc { font-size: 11px; color: var(--text-mute); margin-top: 3px; }
.qc-price-box.highlight { transform: scale(1.02); }
.qc-price-box.dealer.highlight { box-shadow: 0 0 0 2px var(--dealer) inset; }
.qc-price-box.end.highlight { box-shadow: 0 0 0 2px var(--end) inset; }
.match-item .mi-brand { font-size: 11px; color: #7c3aed; background: #f3e8ff; padding: 1px 6px; border-radius: 8px; margin-left: 6px; font-weight: 400; }
.match-item .mi-price small { font-size: 10px; color: var(--text-mute); margin-right: 3px; }

/* ===== 可复制文本报价块 ===== */
.quote-text-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    margin-top: 6px;
    box-shadow: var(--shadow);
    width: 420px;
    max-width: 100%;
}
.qtc-head {
    display: flex; justify-content: space-between; align-items: center;
    padding: 8px 12px;
    background: linear-gradient(135deg, #eff6ff, #f5f3ff);
    border-bottom: 1px solid var(--border);
}
.qtc-title { font-size: 12px; font-weight: 600; color: var(--text-soft); }
.qtc-copy-btn {
    background: var(--primary); color: #fff;
    border: none; border-radius: 6px;
    padding: 4px 12px; font-size: 12px; cursor: pointer;
    transition: opacity .15s, background .15s;
}
.qtc-copy-btn:hover { opacity: .88; }
.qtc-copy-btn.copied { background: #22c55e; opacity: 1; }
.qtc-text {
    margin: 0; padding: 14px 16px;
    font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", Consolas, monospace;
    font-size: 13.5px; line-height: 1.9;
    color: var(--text); white-space: pre-wrap; word-break: break-word;
    background: #fafbfd;
}
.qtc-copy-all-wrap { margin-top: 4px; margin-bottom: 4px; }
.qtc-copy-all-btn {
    background: var(--primary-soft); color: var(--primary);
    border: 1px solid #dbeafe; border-radius: 8px;
    padding: 6px 14px; font-size: 12px; cursor: pointer;
    transition: all .15s;
}
.qtc-copy-all-btn:hover { background: #dbeafe; }
.qtc-copy-all-btn.copied { background: #dcfce7; color: #16a34a; border-color: #bbf7d0; }

/* 响应式 */
@media (max-width: 820px) {
    .sidebar {
        position: fixed; left: 0; top: 0; bottom: 0; z-index: 50;
        transform: translateX(-100%); transition: transform .25s;
    }
    .sidebar.open { transform: translateX(0); box-shadow: 2px 0 12px rgba(0,0,0,.1); }
    .menu-btn { display: block; }
    .msg { margin: 0 14px 14px; }
    .quote-card, .match-list, .quote-text-card { width: 100%; }
    .welcome-card { margin: 0 14px; }
    .qc-price-grid { grid-template-columns: 1fr; }
}

/* ===== 自动更新提示 toast ===== */
.auto-update-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: #1f2937;
    color: #fff;
    padding: 10px 18px;
    border-radius: 999px;
    font-size: 13px;
    box-shadow: 0 4px 16px rgba(0,0,0,.18);
    opacity: 0;
    pointer-events: none;
    transition: opacity .3s, transform .3s;
    z-index: 999;
    cursor: pointer;
    max-width: 90vw;
}
.auto-update-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
}
