/* Kimi Web 样式 —— 仿 Kimi 网页版简洁浅色风 */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #4e6ef2;
  --bg: #ffffff;
  --sidebar-bg: #f7f7f8;
  --border: #e5e5e5;
  --text: #1f2329;
  --text-2: #6b7280;
  --bubble-user: #eef2ff;
  --thinking-bg: #f6f7f9;
  --card-bg: #ffffff;
  --hover-bg: #ececee;
  --active-bg: #e3e8f9;
  --code-bg: #fbfbfb;
  --code-header-bg: #f0f0f2;
  --limits-bg: #eef6f0;
  --ok-color: #237804;
  --mask-bg: rgba(0, 0, 0, .4);
}

:root[data-theme="dark"] {
  --primary: #86a0ff;
  --bg: #191a1e;
  --sidebar-bg: #23252a;
  --border: #3b3e46;
  --text: #e6e8ed;
  --text-2: #a5aab5;
  --bubble-user: #2d3b61;
  --thinking-bg: #25272d;
  --card-bg: #27292f;
  --hover-bg: #34373f;
  --active-bg: #35446d;
  --code-bg: #1d1f24;
  --code-header-bg: #2c2f36;
  --limits-bg: #25392d;
  --ok-color: #8bd69a;
  --mask-bg: rgba(0, 0, 0, .64);
}

html, body, #app { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
}
button { cursor: pointer; font-family: inherit; }

.loading { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--text-2); }

/* ---------- 登录 ---------- */
.login-wrap { height: 100%; display: flex; align-items: center; justify-content: center; background: var(--sidebar-bg); }
.login-card {
  width: 320px; padding: 40px 32px; background: #fff; border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0,0,0,.08); text-align: center;
}
.login-logo { font-size: 32px; color: var(--primary); margin-bottom: 8px; }
.login-sub { color: var(--text-2); font-size: 14px; margin-bottom: 20px; }
.login-card input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; outline: none; margin-bottom: 12px;
}
.login-card input:focus { border-color: var(--primary); }
.login-btn {
  width: 100%; padding: 10px; border: none; border-radius: 8px;
  background: var(--primary); color: #fff; font-size: 15px;
}
.login-btn:hover { opacity: .9; }
.login-error { color: #d4380d; font-size: 13px; margin-top: 10px; }

/* ---------- 布局 ---------- */
.layout { display: flex; height: 100%; }

.sidebar {
  width: 260px; flex-shrink: 0; background: var(--sidebar-bg);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
}
.sidebar-header { padding: 16px 14px 10px; }
.logo { font-size: 22px; font-weight: 700; color: var(--primary); display: block; margin-bottom: 12px; }
.new-btn {
  width: 100%; padding: 9px; border: 1px solid var(--border); border-radius: 8px;
  background: #fff; font-size: 14px; color: var(--text);
}
.new-btn:hover { border-color: var(--primary); color: var(--primary); }

.conv-list { flex: 1; overflow-y: auto; padding: 4px 8px; }
.conv-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 10px; border-radius: 8px; cursor: pointer; font-size: 14px;
  color: var(--text); margin-bottom: 2px;
}
.conv-item:hover { background: #ececee; }
.conv-item.active { background: #e3e8f9; }
.conv-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-actions { display: none; flex-shrink: 0; margin-left: 6px; }
.conv-item:hover .conv-actions { display: inline-flex; gap: 2px; }
.conv-actions button {
  border: none; background: transparent; color: var(--text-2);
  font-size: 12px; padding: 2px 5px; border-radius: 4px;
}
.conv-actions button:hover { background: #dcdce0; color: var(--text); }
.conv-empty { text-align: center; color: var(--text-2); font-size: 13px; padding: 20px 0; }
.conv-search {
  width: 100%; margin-top: 8px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 7px;
  background: var(--card-bg); color: var(--text); font-size: 13px; outline: none;
}
.conv-search:focus { border-color: var(--primary); }
.pin-badge {
  flex-shrink: 0; color: var(--primary); font-size: 10px; margin-left: 5px;
}

.sidebar-footer { padding: 10px 12px; border-top: 1px solid var(--border); }
.footer-row { display: flex; gap: 8px; }

/* 额度显示条 */
.limits-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-size: 11px; color: var(--text-2); margin-bottom: 8px;
  padding: 5px 8px; background: var(--limits-bg); border-radius: 6px;
}
.limits-item { white-space: nowrap; }
.limits-refresh {
  border: none; background: transparent; color: var(--text-2);
  font-size: 13px; padding: 0 4px; border-radius: 4px; margin-left: auto;
}
.limits-refresh:hover { color: var(--primary); background: var(--hover-bg); }

.provider-limits { color: var(--ok-color); font-size: 12px; margin-top: 4px; }
.provider-limits.muted { color: var(--text-2); }
.model-select {
  flex: 1; min-width: 0; padding: 6px; border: 1px solid var(--border);
  border-radius: 6px; font-size: 12px; background: #fff;
}
.logout-btn {
  padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px;
  background: #fff; font-size: 12px; color: var(--text-2);
}
.logout-btn:hover { color: #d4380d; border-color: #d4380d; }

/* ---------- 聊天区 ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-header {
  height: 52px; flex-shrink: 0; display: flex; align-items: center;
  gap: 10px; padding: 0 24px; border-bottom: 1px solid var(--border);
  background: var(--card-bg);
}
.chat-title {
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; font-size: 14px; font-weight: 600;
}
.chat-header-actions { display: flex; gap: 6px; }
.header-btn, .menu-btn {
  position: relative; border: 1px solid var(--border); border-radius: 6px;
  background: transparent; color: var(--text-2); padding: 6px 9px; font-size: 12px;
}
.header-btn:hover, .menu-btn:hover { border-color: var(--primary); color: var(--primary); }
.menu-btn { display: none; font-size: 16px; line-height: 1; padding: 5px 8px; }
.prompt-dot {
  display: inline-block; width: 5px; height: 5px; margin: 0 0 2px 4px;
  border-radius: 50%; background: var(--primary); vertical-align: middle;
}
.chat-area { flex: 1; overflow-y: auto; padding: 24px 0; }
.welcome { text-align: center; color: var(--text-2); margin-top: 18vh; font-size: 15px; }
.welcome h2 { font-size: 24px; color: var(--text); font-weight: 600; }

.msg { max-width: 800px; margin: 0 auto 20px; padding: 0 24px; }

.user-bubble {
  margin-left: auto; max-width: 75%; background: var(--bubble-user);
  border-radius: 14px; padding: 10px 14px; width: fit-content;
}
.msg.user { display: flex; flex-direction: column; align-items: flex-end; }
.user-text { white-space: pre-wrap; word-break: break-word; font-size: 15px; line-height: 1.7; }
.msg-images img { max-width: 220px; max-height: 160px; border-radius: 8px; margin: 4px 4px 0 0; }

.ai-msg { font-size: 15px; line-height: 1.8; }

/* 思考过程折叠块 */
.thinking {
  background: var(--thinking-bg); border: 1px solid var(--border);
  border-radius: 10px; margin-bottom: 10px; font-size: 13px;
}
.thinking summary {
  padding: 8px 12px; cursor: pointer; color: var(--text-2); user-select: none;
  list-style: none;
}
.thinking summary::before { content: '▸ '; }
.thinking[open] summary::before { content: '▾ '; }
.thinking-body {
  padding: 4px 14px 12px; color: var(--text-2);
  border-top: 1px dashed var(--border);
}

.pending-hint { color: var(--text-2); font-size: 14px; }
.usage { color: #b0b4bb; font-size: 12px; margin-top: 8px; }

.msg-actions {
  display: flex; gap: 4px; margin-top: 5px; opacity: 0;
  transition: opacity .15s ease;
}
.msg:hover .msg-actions, .msg-actions:focus-within { opacity: 1; }
.msg-actions button {
  border: none; background: transparent; color: var(--text-2);
  font-size: 12px; padding: 3px 7px; border-radius: 4px;
}
.msg-actions button:hover { background: var(--hover-bg); color: var(--text); }
.edit-textarea {
  width: 100%; min-width: 220px; border: 1px solid var(--primary);
  border-radius: 7px; padding: 7px 9px; resize: vertical;
  background: var(--card-bg); color: var(--text); font: inherit; line-height: 1.6; outline: none;
}
.edit-actions { display: flex; gap: 6px; justify-content: flex-end; margin-top: 7px; }
.save-mini, .cancel-mini {
  border-radius: 5px; padding: 4px 8px; font-size: 12px;
}
.save-mini { border: none; background: var(--primary); color: #fff; }
.cancel-mini { border: 1px solid var(--border); background: transparent; color: var(--text-2); }

/* ---------- Markdown 排版 ---------- */
.md p { margin: 0 0 10px; }
.md p:last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4 { margin: 16px 0 8px; line-height: 1.4; }
.md ul, .md ol { margin: 8px 0 12px 22px; }
.md li { margin-bottom: 4px; }
.md a { color: var(--primary); text-decoration: none; }
.md a:hover { text-decoration: underline; }
.md blockquote {
  border-left: 3px solid var(--border); padding: 2px 12px; margin: 10px 0;
  color: var(--text-2);
}
.md table { border-collapse: collapse; margin: 10px 0; font-size: 14px; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 12px; }
.md th { background: var(--sidebar-bg); }
.md code:not(.hljs) {
  background: #f0f0f2; padding: 2px 6px; border-radius: 4px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 13px;
}
.md img { max-width: 100%; }
.md hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* 代码块 */
.code-block { margin: 12px 0; border-radius: 10px; overflow: hidden; border: 1px solid #e8e8ea; }
.code-header {
  display: flex; justify-content: space-between; align-items: center;
  background: #f0f0f2; padding: 6px 12px; font-size: 12px; color: var(--text-2);
}
.copy-btn {
  border: none; background: transparent; color: var(--text-2);
  font-size: 12px; padding: 2px 8px; border-radius: 4px;
}
.copy-btn:hover { background: #e0e0e4; color: var(--text); }
.code-block pre { margin: 0; }
.code-block code.hljs {
  display: block; padding: 14px; overflow-x: auto;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 13px; line-height: 1.6; background: var(--code-bg);
}

/* ---------- 输入区 ---------- */
.input-area { padding: 12px 24px 20px; }
.input-box {
  max-width: 800px; margin: 0 auto; border: 1px solid var(--border);
  border-radius: 16px; padding: 12px 14px 8px; background: #fff;
  box-shadow: 0 2px 12px rgba(0,0,0,.05);
}
.input-box:focus-within { border-color: var(--primary); }
.input-box textarea {
  width: 100%; border: none; outline: none; resize: none;
  font-size: 15px; font-family: inherit; line-height: 1.6; background: transparent;
}
.input-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; }
.attach-btn {
  border: none; background: transparent; color: var(--text-2);
  font-size: 13px; padding: 6px 10px; border-radius: 6px;
}
.attach-btn:hover { background: var(--sidebar-bg); color: var(--text); }
.send-btn, .stop-btn {
  border: none; border-radius: 8px; padding: 8px 22px; font-size: 14px; color: #fff;
}
.send-btn { background: var(--primary); }
.send-btn:disabled { background: #c5cbdc; cursor: not-allowed; }
.stop-btn { background: #595959; }
.send-btn:not(:disabled):hover, .stop-btn:hover { opacity: .88; }

.pending-images { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.pending-img { position: relative; }
.pending-img img {
  width: 64px; height: 64px; object-fit: cover; border-radius: 8px;
  border: 1px solid var(--border);
}
.pending-img button {
  position: absolute; top: -6px; right: -6px; width: 18px; height: 18px;
  border-radius: 50%; border: none; background: #595959; color: #fff;
  font-size: 12px; line-height: 1;
}

.error-bar {
  max-width: 800px; margin: 8px auto 0; color: #d4380d; font-size: 13px;
}

/* ---------- 文件附件 ---------- */
.msg-files { margin-bottom: 6px; }
.file-card {
  display: inline-flex; align-items: center; gap: 8px;
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; margin: 0 6px 6px 0; font-size: 13px;
}
.file-card .file-name { font-weight: 500; max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-card .file-size { color: var(--text-2); font-size: 12px; }

.pending-files { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.pending-file {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--sidebar-bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 5px 8px 5px 10px; font-size: 13px;
}
.pending-file.parsing { opacity: .65; }
.pending-file .file-name { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pending-file .file-size, .pending-file .file-status { color: var(--text-2); font-size: 12px; }
.pending-file button {
  border: none; background: transparent; color: var(--text-2);
  font-size: 14px; padding: 0 3px; border-radius: 4px;
}
.pending-file button:hover { color: #d4380d; }

.attach-group { display: flex; gap: 4px; }

/* ---------- 设置弹窗 ---------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal {
  width: 620px; max-width: 94vw; max-height: 86vh; overflow-y: auto;
  background: #fff; border-radius: 14px; padding: 20px 24px 24px;
  box-shadow: 0 12px 48px rgba(0,0,0,.18);
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-header h3 { font-size: 17px; }
.modal-close {
  border: none; background: transparent; font-size: 22px; color: var(--text-2);
  padding: 0 6px; border-radius: 6px; line-height: 1;
}
.modal-close:hover { background: var(--sidebar-bg); color: var(--text); }

.provider-list { margin-bottom: 18px; }
.provider-item {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-bottom: 8px;
}
.provider-info { min-width: 0; flex: 1; }
.provider-name { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.badge {
  background: var(--primary); color: #fff; font-size: 11px;
  padding: 1px 7px; border-radius: 999px;
}
.provider-url { color: var(--text-2); font-size: 12px; margin-top: 3px; word-break: break-all; }
.provider-key { color: var(--text-2); font-size: 12px; font-family: Consolas, monospace; margin-top: 2px; }
.provider-models { color: var(--text-2); font-size: 12px; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.provider-actions { display: flex; flex-direction: column; gap: 6px; flex-shrink: 0; }
.provider-actions button {
  border: 1px solid var(--border); background: #fff; border-radius: 6px;
  font-size: 12px; padding: 5px 10px; color: var(--text); white-space: nowrap;
}
.provider-actions button:hover { border-color: var(--primary); color: var(--primary); }
.provider-actions button.danger:hover { border-color: #d4380d; color: #d4380d; }
.provider-actions button:disabled { opacity: .5; cursor: not-allowed; }

.form-title { font-size: 14px; color: var(--text-2); margin-bottom: 10px; }
.provider-form input, .provider-form select {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 14px; outline: none; margin-bottom: 10px;
  font-family: inherit; background: #fff;
}
.provider-form input:focus, .provider-form select:focus { border-color: var(--primary); }
.form-row { display: flex; gap: 10px; }
.form-row input { flex: 1; }
.preset-select { width: 220px; flex-shrink: 0; color: var(--text-2); }
.form-actions { display: flex; gap: 10px; }
.save-btn {
  padding: 9px 26px; border: none; border-radius: 8px;
  background: var(--primary); color: #fff; font-size: 14px;
}
.save-btn:disabled { opacity: .6; cursor: not-allowed; }
.cancel-btn {
  padding: 9px 18px; border: 1px solid var(--border); border-radius: 8px;
  background: #fff; font-size: 14px; color: var(--text-2);
}
.ok-bar { color: #237804; font-size: 13px; margin-top: 8px; }

.settings-btn {
  padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px;
  background: #fff; font-size: 12px; color: var(--text-2);
}
.settings-btn:hover { color: var(--primary); border-color: var(--primary); }

.welcome-tip {
  margin-top: 14px; font-size: 14px; color: var(--text-2);
  max-width: 460px; line-height: 1.8;
}

/* ---------- OAuth 订阅登录 ---------- */
.oauth-block { margin-bottom: 18px; }
.oauth-btn {
  width: 100%; padding: 10px; border: 1px solid var(--border); border-radius: 8px;
  background: #fff; font-size: 14px; color: var(--text);
}
.oauth-btn:hover { border-color: var(--primary); color: var(--primary); }
.oauth-tip { font-size: 12px; color: var(--text-2); margin-top: 8px; line-height: 1.6; }
.oauth-flow { font-size: 13px; line-height: 1.8; color: var(--text); }
.oauth-flow a { color: var(--primary); }
.device-code {
  font-family: Consolas, monospace; font-size: 26px; font-weight: 700;
  letter-spacing: 4px; text-align: center; padding: 14px; margin: 10px 0;
  background: var(--sidebar-bg); border: 1px dashed var(--border);
  border-radius: 10px; cursor: pointer; user-select: all;
}
.oauth-status { color: var(--text-2); font-size: 13px; margin: 8px 0; }
.badge-oauth { background: #10a37f; }

/* ---------- 提示词弹窗 / 暗色主题 ---------- */
.modal-sm { width: 480px; }
.prompt-tip { color: var(--text-2); font-size: 13px; line-height: 1.6; margin-bottom: 10px; }
.prompt-textarea {
  display: block; width: 100%; margin-bottom: 14px; padding: 9px 10px;
  border: 1px solid var(--border); border-radius: 8px; resize: vertical;
  background: var(--card-bg); color: var(--text); font: inherit; line-height: 1.6; outline: none;
}
.prompt-textarea:focus { border-color: var(--primary); }

:root[data-theme="dark"] .login-card,
:root[data-theme="dark"] .new-btn,
:root[data-theme="dark"] .model-select,
:root[data-theme="dark"] .logout-btn,
:root[data-theme="dark"] .input-box,
:root[data-theme="dark"] .file-card,
:root[data-theme="dark"] .provider-actions button,
:root[data-theme="dark"] .provider-form input,
:root[data-theme="dark"] .provider-form select,
:root[data-theme="dark"] .cancel-btn,
:root[data-theme="dark"] .oauth-btn,
:root[data-theme="dark"] .modal {
  background: var(--card-bg); color: var(--text);
}
:root[data-theme="dark"] .login-card input,
:root[data-theme="dark"] .input-box textarea {
  color: var(--text); background: transparent;
}
:root[data-theme="dark"] .md code:not(.hljs) { background: var(--code-header-bg); }
:root[data-theme="dark"] .code-header { background: var(--code-header-bg); }
:root[data-theme="dark"] .code-block { border-color: var(--border); }
:root[data-theme="dark"] .code-block code.hljs { color: #d6dae3; }
:root[data-theme="dark"] .file-card { background: var(--card-bg); }
:root[data-theme="dark"] .ok-bar { color: var(--ok-color); }

.backdrop { display: none; }

/* 窄屏适配 */
@media (max-width: 768px) {
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 90; width: 282px;
    display: flex; transform: translateX(-105%); transition: transform .2s ease;
    box-shadow: 8px 0 28px rgba(0, 0, 0, .12);
  }
  .sidebar.open { transform: translateX(0); }
  .backdrop {
    display: block; position: fixed; inset: 0; z-index: 80; background: var(--mask-bg);
  }
  .menu-btn { display: inline-block; }
  .chat-header { height: 48px; padding: 0 12px; }
  .chat-header-actions { gap: 4px; }
  .header-btn { padding: 5px 7px; }
  .msg { padding: 0 14px; }
  .user-bubble { max-width: 88%; }
  .input-area { padding: 10px 12px 14px; }
  .msg-actions { opacity: 1; }
  .modal { max-width: 94vw; padding: 17px 18px 20px; }
  .form-row { flex-direction: column; gap: 0; }
  .preset-select { width: 100%; }
}
