/* ===== Tri-body AI 二次元动漫风格 ===== */
:root {
  --bg: #fff5f8;
  --bg-grad: radial-gradient(1200px 600px at 15% -10%, #ffe3ee 0%, transparent 60%),
             radial-gradient(1000px 500px at 110% 110%, #e6e3ff 0%, transparent 55%),
             radial-gradient(800px 400px at 50% 120%, #ffeef6 0%, transparent 60%),
             #fff5f8;
  --panel: #ffffff;
  --field-bg: #ffffff;
  --sidebar-bg: linear-gradient(180deg, #ff9ec7 0%, #ff7fb0 30%, #b388ff 100%);
  --sidebar-text: #fff8fb;
  --sidebar-active: rgba(255, 255, 255, .22);
  --accent: #ff7fb0;
  --accent-2: #b388ff;
  --accent-hover: #ff6ba3;
  --text: #4a3841;
  --text-light: #8a6676;
  --border: #ffe0ec;
  --user-bubble: linear-gradient(135deg, #ff8fc0, #b388ff);
  --user-text: #ffffff;
  --ai-bubble: #ffffff;
  --danger: #ff5c7a;
  --radius: 18px;
  --grad-main: linear-gradient(135deg, #ff8fc0, #b388ff);
  --overlay-bg: linear-gradient(135deg, #ffd6e8, #e8dcff);
  --soft-bg: #fff0f6;
  --soft-bg-hover: #ffe4ef;
  --border-soft: #ffd0e4;
  --shadow-color: rgba(255, 143, 192, 1);
  --shadow-color-2: rgba(179, 136, 255, 1);
  --disabled-bg: #ffc6dd;
  --code-inline-bg: #ffe4ef;
  --thinking-bg: #fff6fb;
  --shadow-sm: 0 2px 8px rgba(255, 143, 192, .12);
  --shadow-md: 0 8px 28px rgba(255, 143, 192, .18);
  --shadow-lg: 0 18px 50px rgba(179, 136, 255, .22);
}

/* ===== 蓝色主题 ===== */
:root[data-theme="blue"] {
  --bg: #eaf3ff;
  --bg-grad: radial-gradient(1200px 600px at 15% -10%, #cfe4ff 0%, transparent 60%),
             radial-gradient(1000px 500px at 110% 110%, #d4d6ff 0%, transparent 55%),
             radial-gradient(800px 400px at 50% 120%, #dcecff 0%, transparent 60%),
             #eaf3ff;
  --sidebar-bg: linear-gradient(180deg, #6ec5ff 0%, #3d9bff 30%, #5a6bff 100%);
  --accent: #3d9bff;
  --accent-2: #5a6bff;
  --accent-hover: #2f8bef;
  --text: #25365a;
  --text-light: #52679a;
  --border: #c9ddff;
  --user-bubble: linear-gradient(135deg, #4aa2ff, #5a6bff);
  --grad-main: linear-gradient(135deg, #4aa2ff, #5a6bff);
  --overlay-bg: linear-gradient(135deg, #c4e0ff, #d4d0ff);
  --soft-bg: #dcecff;
  --soft-bg-hover: #cfe3ff;
  --border-soft: #bcd7ff;
  --shadow-color: rgba(61, 155, 255, 1);
  --shadow-color-2: rgba(90, 107, 255, 1);
  --disabled-bg: #a8d0ff;
  --code-inline-bg: #cfe3ff;
  --thinking-bg: #e4f0ff;
  --shadow-sm: 0 2px 8px rgba(61, 155, 255, .18);
  --shadow-md: 0 8px 28px rgba(61, 155, 255, .25);
  --shadow-lg: 0 18px 50px rgba(90, 107, 255, .3);
}

/* ===== 绿色主题 ===== */
:root[data-theme="green"] {
  --bg: #e9f9ef;
  --bg-grad: radial-gradient(1200px 600px at 15% -10%, #cdf3de 0%, transparent 60%),
             radial-gradient(1000px 500px at 110% 110%, #d4f5e6 0%, transparent 55%),
             radial-gradient(800px 400px at 50% 120%, #dcf8ec 0%, transparent 60%),
             #e9f9ef;
  --sidebar-bg: linear-gradient(180deg, #6fe0a6 0%, #2fc683 30%, #1f9a6b 100%);
  --accent: #2fc683;
  --accent-2: #1f9a6b;
  --accent-hover: #27b374;
  --text: #224233;
  --text-light: #4a735e;
  --border: #c6ecda;
  --user-bubble: linear-gradient(135deg, #2fc683, #1f9a6b);
  --grad-main: linear-gradient(135deg, #2fc683, #1f9a6b);
  --overlay-bg: linear-gradient(135deg, #c4ecd8, #ccf0e0);
  --soft-bg: #d8f3e4;
  --soft-bg-hover: #c9edda;
  --border-soft: #b6e6cd;
  --shadow-color: rgba(47, 198, 131, 1);
  --shadow-color-2: rgba(31, 154, 107, 1);
  --disabled-bg: #a5e3c4;
  --code-inline-bg: #c9edda;
  --thinking-bg: #e2f8ec;
  --shadow-sm: 0 2px 8px rgba(47, 198, 131, .18);
  --shadow-md: 0 8px 28px rgba(47, 198, 131, .25);
  --shadow-lg: 0 18px 50px rgba(31, 154, 107, .3);
}

/* ===== 紫色主题 ===== */
:root[data-theme="purple"] {
  --bg: #f6f1ff;
  --bg-grad: radial-gradient(1200px 600px at 15% -10%, #e9d8ff 0%, transparent 60%),
             radial-gradient(1000px 500px at 110% 110%, #e0d9ff 0%, transparent 55%),
             radial-gradient(800px 400px at 50% 120%, #f0e8ff 0%, transparent 60%),
             #f6f1ff;
  --sidebar-bg: linear-gradient(180deg, #c79bff 0%, #9d6bff 30%, #7c4dff 100%);
  --accent: #9d6bff;
  --accent-2: #7c4dff;
  --accent-hover: #8f5af5;
  --text: #3a2d52;
  --text-light: #6e5c8e;
  --border: #e4d6ff;
  --user-bubble: linear-gradient(135deg, #a97bff, #7c4dff);
  --grad-main: linear-gradient(135deg, #a97bff, #7c4dff);
  --overlay-bg: linear-gradient(135deg, #e6d4ff, #ddd4ff);
  --soft-bg: #eee4ff;
  --soft-bg-hover: #e4d6ff;
  --border-soft: #d8c4ff;
  --shadow-color: rgba(157, 107, 255, 1);
  --shadow-color-2: rgba(124, 77, 255, 1);
  --disabled-bg: #c9b0ff;
  --code-inline-bg: #e4d6ff;
  --thinking-bg: #f5f0ff;
  --shadow-sm: 0 2px 8px rgba(157, 107, 255, .18);
  --shadow-md: 0 8px 28px rgba(157, 107, 255, .25);
  --shadow-lg: 0 18px 50px rgba(124, 77, 255, .3);
}

/* ===== 灰白主题 ===== */
:root[data-theme="orange"] {
  --bg: #f7f7f9;
  --bg-grad: radial-gradient(1200px 600px at 15% -10%, #eceef2 0%, transparent 60%),
             radial-gradient(1000px 500px at 110% 110%, #e8eaef 0%, transparent 55%),
             radial-gradient(800px 400px at 50% 120%, #f1f2f5 0%, transparent 60%),
             #f7f7f9;
  --sidebar-bg: linear-gradient(180deg, #9aa0ab 0%, #6f7683 30%, #4a505c 100%);
  --accent: #6f7683;
  --accent-2: #4a505c;
  --accent-hover: #5d6470;
  --text: #2f3339;
  --text-light: #676c75;
  --border: #e2e4e8;
  --user-bubble: linear-gradient(135deg, #7d8490, #4a505c);
  --grad-main: linear-gradient(135deg, #7d8490, #4a505c);
  --overlay-bg: linear-gradient(135deg, #e6e8ec, #e0e2e8);
  --soft-bg: #edeef1;
  --soft-bg-hover: #e2e4e9;
  --border-soft: #d5d8de;
  --shadow-color: rgba(111, 118, 131, 1);
  --shadow-color-2: rgba(74, 80, 92, 1);
  --disabled-bg: #b9bdc5;
  --code-inline-bg: #e2e4e9;
  --thinking-bg: #f2f3f5;
  --shadow-sm: 0 2px 8px rgba(111, 118, 131, .18);
  --shadow-md: 0 8px 28px rgba(111, 118, 131, .25);
  --shadow-lg: 0 18px 50px rgba(74, 80, 92, .3);
}

/* ===== 黑色主题 ===== */
:root[data-theme="teal"] {
  --bg: #141519;
  --panel: #1c1f26;
  --field-bg: #262a33;
  --ai-bubble: #1f232b;
  --bg-grad: radial-gradient(1200px 600px at 15% -10%, #1e2128 0%, transparent 60%),
             radial-gradient(1000px 500px at 110% 110%, #1a1e26 0%, transparent 55%),
             radial-gradient(800px 400px at 50% 120%, #191c22 0%, transparent 60%),
             #141519;
  --sidebar-bg: linear-gradient(180deg, #2b2f38 0%, #1e222b 30%, #12141a 100%);
  --accent: #8a8f9c;
  --accent-2: #5a5f6b;
  --accent-hover: #9aa0ad;
  --text: #e6e8ec;
  --text-light: #b0b6c2;
  --border: #2e323b;
  --user-bubble: linear-gradient(135deg, #464b57, #262a33);
  --grad-main: linear-gradient(135deg, #6a7080, #3a3f4a);
  --overlay-bg: linear-gradient(135deg, #1e2128, #1a1e26);
  --soft-bg: #262a32;
  --soft-bg-hover: #2e333d;
  --border-soft: #3a404b;
  --shadow-color: rgba(138, 143, 156, 1);
  --shadow-color-2: rgba(90, 95, 107, 1);
  --disabled-bg: #3a3f49;
  --code-inline-bg: #2e333d;
  --thinking-bg: #1e222b;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, .35);
  --shadow-md: 0 8px 28px rgba(0, 0, 0, .5);
  --shadow-lg: 0 18px 50px rgba(0, 0, 0, .6);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", sans-serif;
  background: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text);
  overflow: hidden;
  transition: background .8s ease, color .8s ease;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* 主题切换平滑过渡 */
#app, #sidebar, #main-header, #chat-area, #input-wrap, .msg .bubble,
.msg .avatar, .btn-small, .btn-send, .btn-primary, .btn-plain, .btn-attach,
.login-box, .modal-box, .empty-icon {
  transition: background .8s ease, box-shadow .8s ease, border-color .8s ease, color .8s ease;
}

.hidden { display: none !important; }

#app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }

/* ===== 登录遮罩 ===== */
#login-overlay,
#settings-auth-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: var(--overlay-bg);
  display: flex; align-items: center; justify-content: center;
}
.login-box {
  background: var(--panel); border: 2px solid var(--border-soft); border-radius: 22px;
  padding: 40px 34px; width: 320px; max-width: 90vw;
  display: flex; flex-direction: column; gap: 14px; text-align: center;
  box-shadow: 0 24px 70px color-mix(in srgb, var(--shadow-color) 35%, transparent); backdrop-filter: blur(12px);
  animation: modalIn .3s ease both;
}
.login-logo {
  font-size: 28px; font-weight: 800; color: #fff;
  background: var(--grad-main);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.login-sub { font-size: 13px; color: var(--text-light); margin-top: -6px; }
#login-password {
  background: var(--field-bg); border: 2px solid var(--border-soft); color: var(--text);
  padding: 12px 14px; border-radius: 12px; font-size: 14px; outline: none;
}
#login-password:focus { border-color: var(--accent); }
.btn-block { width: 100%; padding: 12px; font-size: 14px; }
.login-error { color: var(--danger); font-size: 13px; }

/* ===== 侧边栏 ===== */
#sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  box-shadow: 6px 0 24px color-mix(in srgb, var(--shadow-color) 20%, transparent);
}
.sidebar-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }

.logo { display: flex; align-items: center; gap: 8px; }
.logo-mark {
  width: 34px; height: 34px; border-radius: 12px;
  object-fit: cover; display: block;
  box-shadow: 0 4px 12px color-mix(in srgb, var(--shadow-color) 40%, transparent);
}
.logo-text {
  color: #fff; font-weight: 700; font-size: 16px;
  text-shadow: 0 2px 6px rgba(0,0,0,.12);
}

.btn-new-chat {
  background: rgba(255, 255, 255, .28);
  color: #fff; border: 2px solid rgba(255,255,255,.5);
  padding: 8px 12px; border-radius: 12px; cursor: pointer;
  font-size: 13px; font-weight: 600; transition: all .2s;
  box-shadow: 0 4px 12px color-mix(in srgb, var(--shadow-color) 30%, transparent);
  backdrop-filter: blur(4px);
}
.btn-new-chat:hover { background: rgba(255,255,255,.4); transform: translateY(-1px); box-shadow: 0 6px 16px color-mix(in srgb, var(--shadow-color) 45%, transparent); }
.btn-new-chat:active { transform: translateY(0); }

.conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.conv-list::-webkit-scrollbar { width: 6px; }
.conv-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,.3); border-radius: 3px; }

.conv-item {
  padding: 10px 12px; border-radius: 12px; cursor: pointer;
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; font-size: 13px; transition: background .15s;
}
.conv-item:hover { background: var(--sidebar-active); }
.conv-item.active { background: rgba(255,255,255,.3); color: #fff; }
.conv-item .conv-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item .conv-del {
  background: none; border: none; color: var(--sidebar-text);
  cursor: pointer; font-size: 14px; opacity: 0; transition: opacity .15s;
}
.conv-item:hover .conv-del { opacity: 1; }
.conv-item .conv-del:hover { color: #fff; }

.sidebar-footer { border-top: 1px solid rgba(255,255,255,.3); padding-top: 12px; display: flex; align-items: center; justify-content: space-between; }
.footer-btns { display: flex; align-items: center; gap: 2px; }
.status-bar { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--sidebar-text); }
.status-bar .dot { width: 8px; height: 8px; border-radius: 50%; background: #7dffb0; box-shadow: 0 0 8px #7dffb0; }
.btn-icon {
  background: none; border: none; color: var(--sidebar-text);
  cursor: pointer; font-size: 13px; padding: 6px 8px; border-radius: 8px;
}
.btn-icon:hover { background: var(--sidebar-active); color: #fff; }

/* ===== 主区域 ===== */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }

#main-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; background: var(--panel); border-bottom: 1px solid var(--border);
  gap: 12px; box-shadow: 0 2px 12px color-mix(in srgb, var(--shadow-color) 8%, transparent); position: relative; z-index: 5;
}
.btn-menu {
  display: none; background: var(--soft-bg); border: 2px solid var(--border);
  border-radius: 12px; width: 36px; height: 36px; cursor: pointer; font-size: 18px;
  color: var(--accent); flex-shrink: 0;
}
.btn-menu:hover { background: var(--soft-bg-hover); }
.model-select { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
#model-box { display: flex; align-items: center; gap: 8px; }

select, input[type="text"], input[type="password"], textarea {
  font-family: inherit; font-size: 13px; color: var(--text);
  border: 2px solid var(--border); border-radius: 12px; padding: 8px 10px;
  background: var(--field-bg); outline: none; transition: border-color .2s;
}
select:focus, input:focus, textarea:focus { border-color: var(--accent); }

#provider-select { min-width: 150px; }
#model-select { min-width: 220px; }
#model-input { width: 220px; }

.btn-small {
  background: var(--soft-bg); border: 2px solid var(--border); color: var(--accent);
  padding: 7px 12px; border-radius: 12px; cursor: pointer; font-size: 12px;
  font-weight: 600; transition: all .2s;
}
.btn-small:hover { background: var(--soft-bg-hover); border-color: var(--accent); transform: translateY(-1px); }

/* ===== 聊天区 ===== */
#chat-area { flex: 1; overflow-y: auto; padding: 24px; min-height: 0; }
#chat-area::-webkit-scrollbar { width: 8px; }
#chat-area::-webkit-scrollbar-thumb { background: var(--border-soft); border-radius: 4px; }

#empty-state {
  height: 100%; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; gap: 12px;
}
.empty-icon {
  font-size: 56px;
  filter: drop-shadow(0 6px 16px color-mix(in srgb, var(--shadow-color) 40%, transparent));
  animation: float 3s ease-in-out infinite;
  cursor: pointer; user-select: none;
  transition: transform .3s ease;
}
.empty-icon:hover { transform: scale(1.1) rotate(10deg); }
.empty-icon:active { transform: scale(.92); }
@keyframes float {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-10px) rotate(6deg); }
}
#empty-state h2 {
  font-size: 24px; font-weight: 800;
  background: var(--grad-main);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
#empty-state p { color: var(--text-light); }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-width: 640px; margin-top: 8px; }
.chip {
  background: var(--field-bg); border: 2px solid var(--border); border-radius: 20px;
  padding: 8px 14px; font-size: 13px; cursor: pointer; color: var(--text);
  transition: all .2s; box-shadow: var(--shadow-sm);
}
.chip:hover { border-color: var(--accent); color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow-md); }

#messages { max-width: 860px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px; min-height: 0; width: 100%; }

.msg { display: flex; gap: 12px; animation: msgIn .3s ease both; min-width: 0; }
@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.msg .avatar {
  min-width: 40px; max-width: 52px; height: 40px; border-radius: 12px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; line-height: 1.15; text-align: center;
  padding: 2px 4px; box-sizing: border-box;
  box-shadow: var(--shadow-sm);
}
.msg.user { flex-direction: row-reverse; }
.msg.user .avatar { background: var(--user-bubble); color: #fff; }
.msg.assistant .avatar { background: var(--grad-main); color: #fff; }

.msg .bubble {
  max-width: 80%; padding: 12px 16px; border-radius: var(--radius);
  line-height: 1.75; font-size: 15px; word-break: break-word;
  font-weight: 450; min-width: 0;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
.msg.user .bubble {
  background: var(--user-bubble); color: var(--user-text); border-top-right-radius: 6px;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--shadow-color) 25%, transparent);
  text-shadow: 0 1px 2px rgba(0,0,0,.22);
}
.msg.assistant .bubble {
  background: var(--ai-bubble); border: 2px solid var(--border); border-top-left-radius: 6px;
  box-shadow: 0 2px 14px color-mix(in srgb, var(--shadow-color) 14%, transparent);
}

.msg .bubble p { margin: 0 0 8px; }
.msg .bubble p:last-child { margin-bottom: 0; }
.msg .bubble ul, .msg .bubble ol { margin: 8px 0 8px 20px; }
.msg .bubble pre {
  background: #1e1b26; color: #f2f0f7; padding: 0; border-radius: 12px;
  overflow: hidden; margin: 8px 0; font-size: 13px;
  border: 1px solid rgba(255,255,255,.12);
  box-shadow: 0 4px 16px rgba(0,0,0,.22);
}
.msg .bubble pre code {
  display: block; padding: 12px 14px; overflow-x: auto;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", "Courier New", monospace;
  line-height: 1.6; font-size: 13px; tab-size: 4;
}
.msg .bubble :not(pre) > code {
  background: var(--code-inline-bg); padding: 2px 6px; border-radius: 6px; font-size: 13px; color: var(--accent);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

/* 代码块头部栏 */
.msg .bubble .code-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 10px 6px 14px;
  background: rgba(255,255,255,.04);
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.msg .bubble .code-lang {
  font-size: 11px; font-weight: 600; letter-spacing: .3px;
  color: #b8b3c9; text-transform: uppercase;
  user-select: none;
}
.msg .bubble .copy-code {
  display: inline-flex; align-items: center; gap: 5px;
  background: rgba(255,255,255,.06); color: #e2deef;
  border: 1px solid rgba(255,255,255,.16); border-radius: 6px;
  padding: 3px 9px; font-size: 11px; cursor: pointer; line-height: 1.4;
  transition: background .15s, color .15s, border-color .15s;
}
.msg .bubble .copy-code:hover {
  background: rgba(255,255,255,.14); color: #fff; border-color: rgba(255,255,255,.25);
}
.msg .bubble .copy-code:active { transform: scale(.96); }
.msg .bubble .copy-code.copied {
  background: rgba(46,200,113,.18); color: #7fe0a8; border-color: rgba(46,200,113,.4);
}
.msg .bubble .copy-code svg { flex-shrink: 0; }
.msg .bubble blockquote { border-left: 3px solid var(--accent); padding-left: 12px; color: var(--text); margin: 8px 0; }
.msg .bubble audio { border-radius: 8px; background: rgba(0,0,0,.08); }
.msg .bubble table { border-collapse: collapse; margin: 8px 0; }
.msg .bubble th, .msg .bubble td { border: 1px solid var(--border); padding: 6px 10px; }
.msg .bubble a { color: var(--accent); }

.msg .bubble .thinking {
  background: var(--thinking-bg); border-left: 3px solid #ffb020; border-radius: 8px;
  padding: 8px 12px; margin: 8px 0; color: var(--text); font-size: 13px;
}

.msg .bubble .cursor { display: inline-block; width: 8px; height: 16px; background: var(--accent); animation: blink 1s infinite; vertical-align: text-bottom; }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

.msg .actions { margin-top: 6px; display: flex; gap: 8px; }
.msg .actions button {
  background: none; border: 2px solid var(--border); border-radius: 8px;
  padding: 4px 10px; font-size: 12px; cursor: pointer; color: var(--text-light);
}
.msg .actions button:hover { color: var(--accent); border-color: var(--accent); }

/* ===== 输入区 ===== */
#input-area { padding: 12px 24px 28px; background: var(--panel); border-top: 1px solid var(--border); }
.input-wrap {
  max-width: 860px; margin: 0 auto; display: flex; flex-direction: column;
  border: 2px solid var(--border); border-radius: 18px; background: var(--field-bg);
  padding: 10px 12px; transition: all .25s; box-shadow: var(--shadow-sm);
}
.input-wrap:focus-within {
  border-color: var(--accent); box-shadow: 0 8px 30px color-mix(in srgb, var(--shadow-color) 18%, transparent);
}
#user-input {
  border: none; outline: none; resize: none; font-size: 14px; line-height: 1.6;
  max-height: 160px; padding: 4px; background: transparent;
}
.input-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 6px; }
#input-hint { font-size: 12px; color: var(--text-light); flex: 1; }

/* 附件工具栏 */
.input-toolbar { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.btn-attach {
  background: transparent; color: var(--accent); border: 2px solid var(--border);
  border-radius: 10px; padding: 4px 12px; cursor: pointer; font-size: 12px;
  transition: all .2s;
}
.btn-attach:hover { border-color: var(--accent); background: var(--soft-bg); }
.attach-name {
  font-size: 12px; color: var(--text-light); background: var(--soft-bg);
  border: 1px solid var(--border); border-radius: 8px; padding: 3px 10px;
  max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.btn-attach-clear {
  background: transparent; color: var(--text-light); border: none; cursor: pointer;
  font-size: 14px; line-height: 1; padding: 2px 6px; border-radius: 4px;
}
.btn-attach-clear:hover { color: var(--danger); background: rgba(255, 92, 122, .1); }

.btn-send {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; border: none; border-radius: 12px;
  padding: 8px 18px; cursor: pointer; font-size: 13px; font-weight: 700;
  transition: all .2s; box-shadow: 0 4px 12px color-mix(in srgb, var(--shadow-color) 35%, transparent);
}
.btn-send:hover { background: linear-gradient(135deg, var(--accent-hover), var(--accent-2)); transform: translateY(-1px); box-shadow: 0 6px 16px color-mix(in srgb, var(--shadow-color) 45%, transparent); }
.btn-send:active { transform: translateY(0); }
.btn-send:disabled { background: var(--disabled-bg); cursor: not-allowed; box-shadow: none; transform: none; }

.btn-stop {
  background: var(--danger); color: #fff; border: none; border-radius: 12px;
  padding: 8px 14px; cursor: pointer; font-size: 13px; transition: all .2s;
}
.btn-stop:hover { background: #f04a68; transform: translateY(-1px); }

.btn-send.recording {
  background: var(--danger) !important;
  animation: pulseSend 1.2s infinite;
}
@keyframes pulseSend {
  0% { box-shadow: 0 0 0 0 rgba(255,92,122,.45); }
  70% { box-shadow: 0 0 0 10px rgba(255,92,122,0); }
  100% { box-shadow: 0 0 0 0 rgba(255,92,122,0); }
}
.btn-mic {
  background: transparent; color: var(--accent); border: 2px solid var(--border);
  border-radius: 50%; width: 38px; height: 38px; cursor: pointer; font-size: 16px;
  display: inline-flex; align-items: center; justify-content: center;
  transition: all .2s;
}
.btn-mic:hover { border-color: var(--accent); background: var(--soft-bg); }
.btn-mic.recording {
  background: var(--danger); color: #fff; border-color: var(--danger);
  animation: pulseMic 1.2s infinite;
}
.btn-mic:disabled { opacity: .45; cursor: not-allowed; }
@keyframes pulseMic {
  0% { box-shadow: 0 0 0 0 rgba(255,92,122,.45); }
  70% { box-shadow: 0 0 0 10px rgba(255,92,122,0); }
  100% { box-shadow: 0 0 0 0 rgba(255,92,122,0); }
}
#input-hint.recording-hint { color: var(--danger); font-weight: 600; }
.btn-send.recording {
  background: var(--danger) !important;
  animation: pulseSend 1.2s infinite;
}
@keyframes pulseSend {
  0% { box-shadow: 0 0 0 0 rgba(255,92,122,.45); }
  70% { box-shadow: 0 0 0 10px rgba(255,92,122,0); }
  100% { box-shadow: 0 0 0 0 rgba(255,92,122,0); }
}

.btn-mute {
  background: transparent; color: var(--text-light); border: 2px solid var(--border);
  border-radius: 12px; padding: 7px 12px; cursor: pointer; font-size: 13px;
  transition: all .2s;
}
.btn-mute:hover { border-color: var(--accent); color: var(--accent); }
.btn-mute.muted { color: var(--danger); border-color: var(--danger); }

/* 画图按钮与下拉菜单 */
.image-gen-wrap { position: relative; }
.btn-image {
  background: transparent; color: var(--accent); border: 2px solid var(--border);
  border-radius: 12px; padding: 7px 12px; cursor: pointer; font-size: 13px;
  transition: all .2s; display: inline-flex; align-items: center; gap: 4px;
}
.btn-image:hover { border-color: var(--accent); background: var(--soft-bg); }
.btn-image:disabled { opacity: .45; cursor: not-allowed; }
.btn-image.image-key-missing {
  border-color: var(--danger); color: var(--danger);
  animation: pulseKeyMissing 1.6s infinite;
}
@keyframes pulseKeyMissing {
  0% { box-shadow: 0 0 0 0 rgba(255, 92, 122, .35); }
  70% { box-shadow: 0 0 0 8px rgba(255, 92, 122, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 92, 122, 0); }
}
.dropdown-menu {
  position: absolute; bottom: calc(100% + 8px); right: 0;
  background: var(--panel); border: 2px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow-lg); min-width: 200px; padding: 6px; z-index: 50;
  display: flex; flex-direction: column; gap: 2px;
  animation: dropdownIn .18s ease both;
}
@keyframes dropdownIn {
  from { opacity: 0; transform: translateY(6px) scale(.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.dropdown-menu button {
  background: transparent; border: none; border-radius: 10px; padding: 10px 12px;
  text-align: left; font-size: 13px; color: var(--text); cursor: pointer;
  transition: background .15s;
}
.dropdown-menu button:hover { background: var(--soft-bg); color: var(--accent); }
.dropdown-divider { height: 1px; background: var(--border); margin: 4px 6px; }

/* 画图结果 */
.image-loading {
  color: var(--text-light); font-size: 14px; padding: 16px 4px;
  display: flex; align-items: center; gap: 8px;
}
.image-loading::before {
  content: ""; width: 16px; height: 16px; border: 2px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.image-result { display: flex; flex-direction: column; gap: 8px; max-width: min(420px, 70vw); }
.image-result img {
  max-width: 100%; border-radius: 14px; cursor: zoom-in;
  box-shadow: 0 6px 20px color-mix(in srgb, var(--shadow-color) 25%, transparent);
  border: 2px solid var(--border-soft);
}
.image-caption { font-size: 12px; color: var(--text-light); line-height: 1.5; }
.image-meta { font-size: 11px; color: var(--text-light); opacity: .8; }
.image-error {
  color: var(--danger); background: rgba(255, 92, 122, .08);
  border: 1px solid rgba(255, 92, 122, .25); border-radius: 10px;
  padding: 10px 12px; font-size: 13px;
}

/* ===== 弹窗 ===== */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.modal-mask { position: absolute; inset: 0; background: color-mix(in srgb, var(--shadow-color) 25%, transparent); animation: fadeIn .2s ease both; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-panel {
  position: relative; background: var(--panel); border-radius: 20px; width: 480px; max-width: 92vw;
  max-height: 90vh; max-height: 90dvh; overflow-y: auto; overflow-x: hidden; box-shadow: var(--shadow-lg);
  border: 2px solid var(--border);
  animation: modalIn .25s ease both;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(16px) scale(.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-header h3 {
  font-size: 16px;
  background: var(--grad-main);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.modal-close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--text-light); }
.modal-body { padding: 18px 22px; display: flex; flex-direction: column; gap: 16px; }
.form-row { display: flex; flex-direction: column; gap: 6px; }
.form-row label { font-size: 13px; font-weight: 600; color: var(--text); }
.form-row input[type="range"] { accent-color: var(--accent); }
.key-input { display: flex; gap: 8px; }
.key-input input { flex: 1; }
.key-input button { background: var(--soft-bg); border: 2px solid var(--border); border-radius: 10px; padding: 0 12px; cursor: pointer; }
.modal-note { font-size: 12px; color: var(--text-light); }
.model-input { display: flex; gap: 8px; align-items: center; }
.model-input input,
.model-input select { flex: 1; }
.model-input button {
  background: var(--soft-bg); border: 2px solid var(--border); border-radius: 10px;
  padding: 0 12px; cursor: pointer; font-size: 14px;
}
.model-input button:disabled { opacity: .6; cursor: not-allowed; }
.field-hint { font-size: 12px; color: var(--text-light); }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 22px; border-top: 1px solid var(--border); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; border: none; border-radius: 12px; padding: 9px 20px; cursor: pointer;
  font-size: 13px; font-weight: 700; transition: all .2s;
  box-shadow: 0 4px 12px color-mix(in srgb, var(--shadow-color) 35%, transparent);
}
.btn-primary:hover { background: linear-gradient(135deg, var(--accent-hover), var(--accent-2)); transform: translateY(-1px); box-shadow: 0 6px 16px color-mix(in srgb, var(--shadow-color) 45%, transparent); }
.btn-plain { background: var(--soft-bg); border: 2px solid var(--border); border-radius: 12px; padding: 9px 20px; cursor: pointer; font-size: 13px; transition: all .2s; }
.btn-plain:hover { background: var(--soft-bg-hover); }

/* ===== 滚动条美化 ===== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border-soft); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

/* ===== 樱花 logo 点击切换主题 ===== */
#logo-theme { cursor: pointer; user-select: none; }
#logo-theme:active { transform: scale(.95); }
#logo-theme .logo-mark {
  transition: transform .6s ease, box-shadow .6s ease;
}
#logo-theme:hover .logo-mark { transform: rotate(20deg) scale(1.08); }

/* ===== 鼠标特效 ===== */
/* 鼠标跟随光晕 */
#mouse-glow {
  position: fixed; top: 0; left: 0; width: 220px; height: 220px;
  border-radius: 50%; pointer-events: none; z-index: 9999;
  background: radial-gradient(circle,
    color-mix(in srgb, var(--shadow-color) 18%, transparent) 0%,
    color-mix(in srgb, var(--shadow-color-2) 8%, transparent) 40%,
    transparent 65%);
  transform: translate(-50%, -50%);
  transition: opacity .4s ease;
  opacity: 0;
  will-change: left, top;
}
#mouse-glow.active { opacity: 1; }

/* 鼠标点击涟漪 */
#click-ripple-layer {
  position: fixed; inset: 0; pointer-events: none; z-index: 9998; overflow: hidden;
}
.ripple {
  position: fixed; border-radius: 50%; pointer-events: none;
  transform: translate(-50%, -50%) scale(0);
  border: 2px solid color-mix(in srgb, var(--shadow-color) 60%, transparent);
  animation: rippleAnim .6s ease-out forwards;
}
@keyframes rippleAnim {
  0% { transform: translate(-50%, -50%) scale(0); opacity: .9; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 0; }
}

/* 鼠标跟随樱花粒子 */
#petal-layer {
  position: fixed; inset: 0; pointer-events: none; z-index: 9997; overflow: hidden;
}
.petal {
  position: fixed; pointer-events: none; user-select: none;
  font-size: 16px; line-height: 1;
  transform: translate(-50%, -50%);
  animation: petalFloat .9s ease-out forwards;
  filter: drop-shadow(0 2px 6px color-mix(in srgb, var(--shadow-color) 40%, transparent));
}
@keyframes petalFloat {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(.6) rotate(0deg); }
  100% { opacity: 0; transform: translate(calc(-50% + 40px), calc(-50% - 60px)) scale(1.1) rotate(30deg); }
}

/* 移动端隐藏鼠标特效，节省性能 */
@media (hover: none), (max-width: 768px) {
  #mouse-glow, #click-ripple-layer, #petal-layer { display: none; }
}

/* ===== 响应式 ===== */
@media (max-width: 768px) {
  #sidebar {
    display: flex;
    position: fixed; left: 0; top: 0; bottom: 0; width: 78vw; max-width: 300px;
    z-index: 60; transform: translateX(-100%); transition: transform .3s ease;
    box-shadow: none;
  }
  #sidebar.sidebar-open { transform: translateX(0); box-shadow: 6px 0 24px color-mix(in srgb, var(--shadow-color) 25%, transparent); }
  body.menu-open::after {
    content: ""; position: fixed; inset: 0; z-index: 55;
    background: color-mix(in srgb, var(--shadow-color) 30%, transparent);
  }
  #btn-menu, #btn-menu.hidden { display: inline-flex !important; align-items: center; justify-content: center; }
  #main-header { padding: 12px 16px; }
  #chat-area { padding: 16px; }
  #input-area { padding: 10px 16px 24px; }
  .msg .bubble { max-width: 92%; }

  /* 手机端允许页面整体滚动，适配不同屏幕高度和虚拟键盘 */
  body { overflow-y: auto; }
  #app { min-height: 100dvh; }
  .model-select { flex-wrap: wrap; }

  /* ===== 设置弹窗手机端适配 ===== */
  .modal { align-items: flex-end; justify-content: stretch; }
  .modal-panel {
    width: 100%; max-width: 100vw; max-height: 88vh; max-height: 88dvh;
    border-radius: 20px 20px 0 0;
    display: flex; flex-direction: column;
  }
  .modal-header { padding: 16px 18px; flex-shrink: 0; }
  .modal-body { padding: 16px 18px; gap: 14px; flex: 1; overflow-y: auto; min-height: 0; }
  .modal-footer { padding: 14px 18px; flex-shrink: 0; }
  .modal-footer .btn-primary, .modal-footer .btn-plain { flex: 1; text-align: center; }
  .key-input button { padding: 0 14px; }

  /* ===== 登录/设置验证遮罩手机端适配 ===== */
  #login-overlay, #settings-auth-overlay { align-items: flex-end; padding: 0; }
  #login-overlay .login-box, #settings-auth-overlay .login-box {
    width: 100%; max-width: 100vw; max-height: 78vh; max-height: 78dvh;
    border-radius: 22px 22px 0 0; padding: 32px 24px 28px;
    overflow-y: auto;
  }
}
