/* ============================================================
   AI 对话系统 样式
   ============================================================ */
:root {
    --bg: #f7f8fa;
    --sidebar-bg: #f0f2f5;
    --panel-bg: #ffffff;
    --border: #e5e7eb;
    --text: #1f2329;
    --text-weak: #8a919f;
    --primary: #4d53e8;
    --primary-hover: #3f45d4;
    --user-bubble: #e8ebff;
    --danger: #e5484d;
    --radius: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Microsoft YaHei", sans-serif;
    color: var(--text);
    background: var(--bg);
}

a { color: var(--primary); text-decoration: none; }

/* ---------- 登录 / 注册 ---------- */
.auth-wrap {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 20px;
}
.auth-card {
    width: 100%;
    max-width: 380px;
    background: var(--panel-bg);
    border-radius: 16px;
    padding: 36px 32px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .18);
}
.auth-card h1 { font-size: 22px; margin-bottom: 6px; text-align: center; }
.auth-card .sub { color: var(--text-weak); font-size: 13px; text-align: center; margin-bottom: 24px; }
.auth-field { margin-bottom: 16px; }
.auth-field label { display: block; font-size: 13px; margin-bottom: 6px; color: #4e5969; }
.auth-field input {
    width: 100%; height: 42px; padding: 0 12px;
    border: 1px solid var(--border); border-radius: 8px; font-size: 14px; outline: none;
}
.auth-field input:focus { border-color: var(--primary); }
.auth-btn {
    width: 100%; height: 44px; border: none; border-radius: 8px;
    background: var(--primary); color: #fff; font-size: 15px; cursor: pointer; margin-top: 6px;
}
.auth-btn:hover { background: var(--primary-hover); }
.auth-btn:disabled { opacity: .6; cursor: not-allowed; }
.auth-tip { text-align: center; font-size: 13px; color: var(--text-weak); margin-top: 18px; }
.auth-msg { min-height: 20px; font-size: 13px; color: var(--danger); text-align: center; margin-top: 10px; }

/* ---------- 聊天布局 ---------- */
.chat-app { display: flex; height: 100%; overflow: hidden; }

.sidebar {
    width: 264px; flex-shrink: 0; background: var(--sidebar-bg);
    display: flex; flex-direction: column; border-right: 1px solid var(--border);
}
.sidebar-head { padding: 14px; }
.new-chat-btn {
    width: 100%; height: 40px; border: none; border-radius: 8px; cursor: pointer;
    background: var(--primary); color: #fff; font-size: 14px; display: flex;
    align-items: center; justify-content: center; gap: 6px;
}
.new-chat-btn:hover { background: var(--primary-hover); }
.conv-list { flex: 1; overflow-y: auto; padding: 0 8px 8px; }
.conv-item {
    position: relative; padding: 10px 12px; border-radius: 8px; cursor: pointer;
    font-size: 14px; color: #4e5969; margin-bottom: 2px; display: flex;
    align-items: center; gap: 6px;
}
.conv-item:hover { background: #e4e7ec; }
.conv-item.active { background: #fff; color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.conv-item .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item .pin-flag { color: var(--primary); font-size: 12px; }
.conv-actions { display: none; gap: 4px; }
.conv-item:hover .conv-actions { display: flex; }
.conv-actions button {
    border: none; background: transparent; cursor: pointer; color: var(--text-weak);
    font-size: 12px; padding: 2px 4px; border-radius: 4px;
}
.conv-actions button:hover { background: #d5d9e0; color: var(--text); }
.conv-actions button.del:hover { color: var(--danger); }

.sidebar-foot {
    padding: 12px 14px; border-top: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between; font-size: 13px;
}
.sidebar-foot .uname { color: #4e5969; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-foot a { color: var(--text-weak); }
.sidebar-foot a:hover { color: var(--danger); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--panel-bg); }
.main-head {
    height: 56px; flex-shrink: 0; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; padding: 0 20px; font-size: 15px; font-weight: 600;
}
.main-head .title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.messages { flex: 1; overflow-y: auto; padding: 24px 0; }
.msg-row { display: flex; padding: 8px 20px; }
.msg-row .bubble {
    max-width: 760px; width: 100%; margin: 0 auto; padding: 4px 0; font-size: 15px; line-height: 1.7;
}
.msg-row.user { flex-direction: column; align-items: center; }
.msg-row.user .bubble {
    background: var(--user-bubble); border-radius: var(--radius); padding: 12px 16px;
    max-width: 760px; white-space: pre-wrap; word-break: break-word;
}
.msg-row.assistant .bubble { color: var(--text); }
.msg-row.assistant { flex-direction: column; }
.msg-tools { max-width: 760px; width: 100%; margin: 4px auto 0; display: flex; gap: 8px; }
.copy-btn { border: 1px solid var(--border); background: #fff; color: var(--text-weak); font-size: 12px; padding: 3px 12px; border-radius: 6px; cursor: pointer; transition: all .15s; }
.copy-btn:hover { color: var(--primary); border-color: var(--primary); }
.code-block { position: relative; }
.code-copy { position: absolute; top: 8px; right: 8px; border: 1px solid #4a4a4a; background: #2b2b2b; color: #cfcfcf; font-size: 12px; padding: 2px 10px; border-radius: 5px; cursor: pointer; }
.code-copy:hover { color: #fff; border-color: #777; }
.msg-role {
    max-width: 760px; margin: 0 auto 4px; font-size: 12px; color: var(--text-weak); width: 100%;
}

.empty-tip { text-align: center; color: var(--text-weak); margin-top: 80px; font-size: 14px; }
.empty-tip h2 { color: var(--text); font-size: 20px; margin-bottom: 10px; }

/* Markdown 内容样式 */
.md p { margin: 6px 0; }
.md h1, .md h2, .md h3 { margin: 12px 0 8px; }
.md ul, .md ol { margin: 6px 0 6px 22px; }
.md code { background: #f2f3f5; padding: 2px 5px; border-radius: 4px; font-family: "SFMono-Regular", Consolas, monospace; font-size: 13px; }
.md pre { background: #1e1e1e; color: #e6e6e6; padding: 14px; border-radius: 8px; overflow-x: auto; margin: 10px 0; }
.md pre code { background: transparent; color: inherit; padding: 0; }
.md a { color: var(--primary); }
.md blockquote { border-left: 3px solid var(--border); padding-left: 12px; color: var(--text-weak); margin: 8px 0; }
.md table { border-collapse: collapse; margin: 10px 0; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 10px; }

.typing::after { content: "▋"; animation: blink 1s steps(1) infinite; color: var(--primary); }
@keyframes blink { 50% { opacity: 0; } }

/* 输入区 */
.composer { flex-shrink: 0; border-top: 1px solid var(--border); padding: 14px 20px 18px; }
.composer-tools { max-width: 760px; margin: 0 auto 8px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.model-picker { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-weak, #8a919f); }
.model-picker select {
    border: 1px solid var(--border); border-radius: 8px; padding: 5px 8px;
    font-size: 13px; background: #fff; color: var(--text, #1f2430); cursor: pointer; outline: none; font-family: inherit;
}
.model-picker select:focus { border-color: var(--primary); }
.model-desc { font-size: 12px; color: var(--text-weak, #8a919f); }
/* 附件按钮与待发送预览 */
.attach-btn { border: 1px solid var(--border); background: #fff; color: #4e5969; font-size: 13px; padding: 5px 10px; border-radius: 8px; cursor: pointer; }
.attach-btn:hover { border-color: var(--primary); color: var(--primary); }
.attach-btn:disabled { opacity: .6; cursor: default; }
.att-previews { max-width: 760px; margin: 0 auto 8px; display: flex; flex-wrap: wrap; gap: 8px; }
.att-previews:empty { display: none; }
.att-chip { position: relative; display: flex; align-items: center; gap: 6px; border: 1px solid var(--border); border-radius: 8px; padding: 4px 22px 4px 4px; background: #fff; max-width: 240px; }
.att-chip img { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; }
.att-chip-ic { font-size: 22px; width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; background: #f2f3f5; border-radius: 6px; }
.att-chip-name { font-size: 12px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-chip-x { position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; line-height: 16px; text-align: center; border: none; border-radius: 50%; background: rgba(0,0,0,.5); color: #fff; cursor: pointer; font-size: 13px; padding: 0; }
/* 消息内附件 */
.msg-atts { max-width: 760px; width: 100%; margin: 0 auto 6px; display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.msg-row.assistant .msg-atts { justify-content: flex-start; }
.att-img { max-width: 220px; max-height: 220px; border-radius: 10px; border: 1px solid var(--border); cursor: zoom-in; object-fit: cover; }
.att-file { display: inline-flex; align-items: center; font-size: 13px; color: #4e5969; background: #f2f3f5; border: 1px solid var(--border); border-radius: 8px; padding: 5px 10px; }
.att-file.clickable { cursor: pointer; }
.att-file.clickable:hover { color: var(--primary); border-color: var(--primary); }
.composer-inner { max-width: 760px; margin: 0 auto; display: flex; gap: 10px; align-items: flex-end; }
.composer textarea {
    flex: 1; resize: none; border: 1px solid var(--border); border-radius: 10px;
    padding: 11px 14px; font-size: 15px; line-height: 1.5; max-height: 160px; outline: none;
    font-family: inherit;
}
.composer textarea:focus { border-color: var(--primary); }
.send-btn {
    height: 44px; padding: 0 22px; border: none; border-radius: 10px; cursor: pointer;
    background: var(--primary); color: #fff; font-size: 15px; flex-shrink: 0;
}
.send-btn:hover { background: var(--primary-hover); }
.send-btn:disabled { opacity: .5; cursor: not-allowed; }
.composer-hint { max-width: 760px; margin: 8px auto 0; font-size: 12px; color: var(--text-weak); text-align: center; }

/* 移动端 */
@media (max-width: 768px) {
    .sidebar { width: 200px; }
    .msg-row .bubble, .msg-role, .composer-inner, .composer-hint { max-width: 100%; }
}
