/* ============ 基础 ============ */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.65;
  color: var(--txt);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --line: #e5eaf3;
  --line-soft: #eef1f7;
  --txt: #1b2333;
  --sub: #7b8698;
  --acc: #2f6bff;
  --acc-dk: #1e53d8;
  --acc-soft: #eef3ff;
  --user-bg: #2f6bff;
  --code-bg: #f6f8fc;
  --danger: #d93b3b;
  --ok: #17a06a;
  --side-w: 268px;
}

button, textarea, select, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }

/* 必须放在所有 display 规则之前也无效——用 !important 兜住：
   下面 .send/.stop 的 display:flex 会盖掉 [hidden] 的 display:none */
[hidden] { display: none !important; }

/* ============ 骨架 ============ */
.app {
  display: flex;
  height: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ============ 侧栏 ============ */
.side {
  width: var(--side-w);
  min-width: var(--side-w);
  background: #fbfcfe;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  height: 100%;
}

.side-hd { padding: 16px 14px 10px; }

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 2px 4px 14px;
}
.logo {
  width: 30px; height: 30px;
  border-radius: 9px;
  background: linear-gradient(140deg, #4b83ff, #2f6bff 60%, #1e53d8);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 700;
  flex: 0 0 auto;
  box-shadow: 0 2px 8px rgba(47, 107, 255, .3);
}
.brand-txt { font-size: 16px; font-weight: 700; letter-spacing: .2px; }

.new-btn {
  width: 100%;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--acc);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: background .15s;
  box-shadow: 0 2px 8px rgba(47, 107, 255, .22);
}
.new-btn:hover { background: var(--acc-dk); }
.new-btn .plus { font-size: 17px; line-height: 1; margin-top: -1px; }

.convs {
  flex: 1;
  overflow-y: auto;
  padding: 6px 10px 12px;
}
.convs::-webkit-scrollbar { width: 6px; }
.convs::-webkit-scrollbar-thumb { background: #dfe4ee; border-radius: 3px; }

.conv {
  display: flex; align-items: center; gap: 6px;
  padding: 9px 10px;
  border-radius: 9px;
  margin-bottom: 2px;
  cursor: pointer;
  transition: background .12s;
}
.conv:hover { background: #eef1f8; }
.conv.on { background: var(--acc-soft); }
.conv-t {
  flex: 1;
  min-width: 0;
  font-size: 13.5px;
  color: #3b4658;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv.on .conv-t { color: var(--acc-dk); font-weight: 600; }
.conv-del {
  flex: 0 0 auto;
  width: 22px; height: 22px;
  border-radius: 6px;
  color: #9aa4b5;
  font-size: 15px;
  line-height: 1;
  opacity: 0;
  transition: opacity .12s, background .12s;
}
.conv:hover .conv-del { opacity: 1; }
.conv-del:hover { background: #e3e8f2; color: var(--danger); }

.convs-empty {
  padding: 22px 12px;
  text-align: center;
  font-size: 13px;
  color: #a3adbd;
}

.side-ft {
  border-top: 1px solid var(--line-soft);
  padding: 11px 14px 13px;
}
.status {
  display: flex; align-items: center; gap: 7px;
  font-size: 12.5px; color: var(--sub);
}
.dot {
  width: 7px; height: 7px; border-radius: 50%;
  flex: 0 0 auto; background: #c3cbd8;
}
.dot-ok { background: var(--ok); box-shadow: 0 0 0 3px rgba(23, 160, 106, .15); }
.dot-warn { background: #e5a01a; box-shadow: 0 0 0 3px rgba(229, 160, 26, .15); }
.dot-err { background: var(--danger); box-shadow: 0 0 0 3px rgba(217, 59, 59, .15); }
.dot-wait { background: #b9c2d0; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: .35 } 50% { opacity: 1 } }

.foot-note {
  margin-top: 8px;
  font-size: 11.5px;
  color: #aab3c1;
}

.mask {
  display: none;
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0;
  background: rgba(20, 28, 44, .38);
  z-index: 40;
}

/* ============ 主区 ============ */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--panel);
}

.topbar {
  flex: 0 0 auto;
  height: 58px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line-soft);
  display: flex; align-items: center; gap: 10px;
  background: #fff;
}
.ttl {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-r { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }

.icon-btn {
  padding: 6px 11px;
  border-radius: 8px;
  font-size: 13px;
  color: #5c6a80;
  border: 1px solid var(--line);
  background: #fff;
  transition: background .12s, border-color .12s;
}
.icon-btn:hover { background: #f4f7fd; border-color: #d3dcec; color: var(--acc-dk); }
.menu-btn { font-size: 17px; padding: 4px 10px; }

.sel-wrap { position: relative; display: inline-flex; }
.model-sel {
  appearance: none;
  -webkit-appearance: none;
  padding: 6px 28px 6px 11px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 13px;
  color: #43506b;
  max-width: 220px;
  cursor: pointer;
}
.sel-wrap::after {
  content: "▾";
  position: absolute;
  right: 10px; top: 50%;
  transform: translateY(-50%);
  font-size: 10px;
  color: #93a0b5;
  pointer-events: none;
}

.warn {
  flex: 0 0 auto;
  margin: 10px 18px 0;
  padding: 11px 14px;
  border-radius: 10px;
  background: #fff8ec;
  border: 1px solid #f3dcae;
  color: #8a6212;
  font-size: 13px;
  line-height: 1.6;
}
.warn b { color: #6d4d07; }
.warn code {
  background: #fdf1d8;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
}

/* ============ 消息区 ============ */
.scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
}
.scroll::-webkit-scrollbar { width: 8px; }
.scroll::-webkit-scrollbar-thumb { background: #dfe4ee; border-radius: 4px; }
.scroll::-webkit-scrollbar-thumb:hover { background: #ccd4e2; }

.msgs {
  max-width: 780px;
  margin: 0 auto;
  padding: 26px 20px 12px;
}

.row { display: flex; gap: 12px; margin-bottom: 22px; }
.row-me { flex-direction: row-reverse; }

.ava {
  flex: 0 0 auto;
  width: 32px; height: 32px;
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700;
  margin-top: 1px;
}
.ava-ai {
  background: linear-gradient(140deg, #4b83ff, #2f6bff 60%, #1e53d8);
  color: #fff;
  box-shadow: 0 2px 7px rgba(47, 107, 255, .26);
}
.ava-me { background: #e8edf7; color: #5c6a80; }

.bub {
  max-width: 76%;
  min-width: 0;
  padding: 11px 15px;
  border-radius: 14px;
  word-wrap: break-word;
  overflow-wrap: break-word;
}
.bub-ai {
  background: #f6f8fc;
  border: 1px solid var(--line-soft);
  border-top-left-radius: 5px;
  color: var(--txt);
}
.bub-me {
  background: var(--user-bg);
  color: #fff;
  border-top-right-radius: 5px;
  box-shadow: 0 2px 10px rgba(47, 107, 255, .22);
}
.bub-err {
  background: #fdf1f1;
  border: 1px solid #f4d4d4;
  color: #a52f2f;
  border-top-left-radius: 5px;
}

/* 打字光标 */
.caret {
  display: inline-block;
  width: 7px; height: 15px;
  background: var(--acc);
  border-radius: 1px;
  vertical-align: -2px;
  margin-left: 2px;
  animation: blink .9s steps(1) infinite;
}
@keyframes blink { 0%,50% { opacity: 1 } 51%,100% { opacity: 0 } }

/* ============ 空状态 ============ */
.empty {
  max-width: 780px;
  margin: 0 auto;
  padding: 60px 20px 40px;
  text-align: center;
}
.empty-logo {
  width: 54px; height: 54px;
  margin: 0 auto 16px;
  border-radius: 16px;
  background: linear-gradient(140deg, #4b83ff, #2f6bff 60%, #1e53d8);
  color: #fff;
  font-size: 26px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 20px rgba(47, 107, 255, .3);
}
.empty-h { font-size: 21px; font-weight: 700; color: #1b2333; margin-bottom: 6px; }
.empty-p { font-size: 13.5px; color: var(--sub); margin-bottom: 22px; }
.chips {
  display: flex; flex-wrap: wrap; gap: 9px;
  justify-content: center;
  max-width: 620px;
  margin: 0 auto;
}
.chip {
  padding: 9px 15px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 13px;
  color: #4a576e;
  transition: all .14s;
}
.chip:hover {
  border-color: #b9ccff;
  background: var(--acc-soft);
  color: var(--acc-dk);
  transform: translateY(-1px);
}

/* ============ 输入区 ============ */
.composer {
  flex: 0 0 auto;
  padding: 10px 20px 14px;
  background: #fff;
  border-top: 1px solid var(--line-soft);
}
.box {
  max-width: 780px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 8px 8px 15px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.box:focus-within {
  border-color: #a9c0ff;
  box-shadow: 0 0 0 3px rgba(47, 107, 255, .09);
}
#input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  resize: none;
  background: none;
  padding: 6px 0;
  max-height: 190px;
  min-height: 26px;
  line-height: 1.6;
  font-size: 15px;
  overflow-y: auto;
}
#input::placeholder { color: #b3bccb; }

.send, .stop {
  flex: 0 0 auto;
  width: 34px; height: 34px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, opacity .15s;
}
.send { background: var(--acc); color: #fff; }
.send:hover:not(:disabled) { background: var(--acc-dk); }
.send:disabled { background: #dbe1ec; color: #a6b0c2; cursor: not-allowed; }
.stop { background: #f0f3f9; color: #5c6a80; }
.stop:hover { background: #e4e9f3; }

.hint {
  max-width: 780px;
  margin: 8px auto 0;
  text-align: center;
  font-size: 11.5px;
  color: #a9b2c1;
  min-height: 16px;
}

/* ============ Markdown ============ */
.bub p { margin: 0 0 10px; }
.bub p:last-child { margin-bottom: 0; }
.bub h1, .bub h2, .bub h3, .bub h4 {
  margin: 16px 0 9px;
  line-height: 1.4;
  font-weight: 700;
}
.bub h1 { font-size: 19px; }
.bub h2 { font-size: 17px; }
.bub h3 { font-size: 15.5px; }
.bub h4 { font-size: 14.5px; }
.bub > *:first-child { margin-top: 0; }
.bub ul, .bub ol { margin: 0 0 10px; padding-left: 22px; }
.bub li { margin: 3px 0; }
.bub li > p { margin: 0 0 4px; }
.bub blockquote {
  margin: 10px 0;
  padding: 2px 0 2px 12px;
  border-left: 3px solid #cfd9ec;
  color: #5d6a80;
}
.bub hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.bub a { color: var(--acc-dk); text-decoration: none; border-bottom: 1px solid #b9ccff; }
.bub a:hover { border-bottom-color: var(--acc); }
.bub strong { font-weight: 700; }
.bub del { color: #98a2b3; }

.bub code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Courier New", monospace;
  font-size: 13px;
  background: #eceff6;
  padding: 1.5px 5px;
  border-radius: 4px;
}
.bub-me code { background: rgba(255, 255, 255, .2); color: #fff; }

.cb {
  margin: 11px 0;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid #e3e8f2;
  background: var(--code-bg);
}
.cb-hd {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 12px;
  background: #eef1f7;
  border-bottom: 1px solid #e3e8f2;
}
.cb-lang {
  font-size: 11.5px;
  color: #8592a6;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  text-transform: lowercase;
}
.cb-cp {
  font-size: 11.5px;
  color: #6b7891;
  padding: 2px 9px;
  border-radius: 5px;
  border: 1px solid #dde3ee;
  background: #fff;
  transition: all .12s;
}
.cb-cp:hover { color: var(--acc-dk); border-color: #b9ccff; background: var(--acc-soft); }
.cb pre {
  margin: 0;
  padding: 12px 14px;
  overflow-x: auto;
}
.cb pre code {
  background: none;
  padding: 0;
  font-size: 12.8px;
  line-height: 1.62;
  color: #263045;
  white-space: pre;
}

/* ============ 设置弹窗 ============ */
.modal {
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-mask {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  background: rgba(20, 28, 44, .45);
}
.modal-box {
  position: relative;
  width: 100%;
  max-width: 520px;
  max-height: 86%;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 18px 50px rgba(15, 25, 45, .22);
  overflow: hidden;
}
.modal-hd {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 15px 18px;
  border-bottom: 1px solid var(--line-soft);
}
.modal-ttl { font-size: 15.5px; font-weight: 700; }
.modal-x {
  width: 28px; height: 28px;
  border-radius: 8px;
  font-size: 19px; line-height: 1;
  color: #94a0b3;
}
.modal-x:hover { background: #f1f4fa; color: #46536b; }

.modal-bd { flex: 1; overflow-y: auto; padding: 18px; }

.fld { margin-bottom: 18px; }
.fld > label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #3b4658;
  margin-bottom: 7px;
}
.fld input[type="text"],
.fld input[type="password"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 13.5px;
  outline: 0;
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.fld input:focus {
  border-color: #a9c0ff;
  box-shadow: 0 0 0 3px rgba(47, 107, 255, .1);
}
.key-wrap { position: relative; display: flex; }
.key-wrap input { padding-right: 64px; }
.key-eye {
  position: absolute;
  right: 6px; top: 50%;
  transform: translateY(-50%);
  padding: 5px 10px;
  border-radius: 7px;
  font-size: 12px;
  color: #6b7891;
  border: 1px solid var(--line);
  background: #fff;
}
.key-eye:hover { color: var(--acc-dk); border-color: #b9ccff; background: var(--acc-soft); }

.fld-note {
  margin-top: 7px;
  font-size: 12px;
  line-height: 1.65;
  color: #8592a6;
}
.fld-note b { color: #5c6a80; }
.fld-warn { margin-top: 6px; color: #a4842f; }

.chk {
  display: flex; align-items: center; gap: 8px;
  font-size: 13.5px; color: #43506b;
  cursor: pointer;
}
.chk input { width: 15px; height: 15px; accent-color: var(--acc); }

.modal-ft {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  padding: 13px 18px;
  border-top: 1px solid var(--line-soft);
  background: #fbfcfe;
}
.btn-primary {
  padding: 9px 20px;
  border-radius: 10px;
  background: var(--acc);
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
}
.btn-primary:hover { background: var(--acc-dk); }
.btn-ghost {
  padding: 9px 15px;
  border-radius: 10px;
  font-size: 13.5px;
  color: #6b7891;
  border: 1px solid var(--line);
  background: #fff;
}
.btn-ghost:hover { color: var(--danger); border-color: #f0c9c9; background: #fdf3f3; }

.btn-test {
  padding: 8px 15px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 13px;
  color: #43506b;
  transition: all .13s;
}
.btn-test:hover { border-color: #b9ccff; background: var(--acc-soft); color: var(--acc-dk); }
.btn-test:disabled { opacity: .55; cursor: default; }
.btn-row { display: block; margin-top: 9px; }
.fld-sep { padding-top: 16px; border-top: 1px solid var(--line-soft); }

.probe-out {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 12.5px;
  line-height: 1.65;
  word-break: break-all;
  border: 1px solid var(--line);
  background: #f7f9fc;
  color: #4a576e;
}
.probe-ok { border-color: #bfe6d4; background: #f1fbf6; color: #14724f; }
.probe-bad { border-color: #f2cccc; background: #fdf3f3; color: #a52f2f; }
.probe-run { border-color: #cddbff; background: #f3f6ff; color: #3a58a8; }
.probe-ul {
  margin: 7px 0 0;
  padding: 0;
  list-style: none;
  font-size: 12px;
}
.probe-ul li {
  padding: 2px 0;
  line-height: 1.6;
}
.probe-ul b { font-weight: 700; }

.probe-out code {  display: block;
  margin-top: 6px;
  padding: 7px 9px;
  border-radius: 7px;
  background: rgba(0, 0, 0, .045);
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-all;
}

.msg-detail {
  display: block;
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, .045);
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ============ 响应式 ============ */
.only-mobile { display: none; }

@media (max-width: 820px) {
  :root { --side-w: 254px; }

  .only-mobile { display: inline-flex; align-items: center; }

  .side {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: 2px 0 18px rgba(20, 28, 44, .12);
  }
  .side.open { transform: translateX(0); }
  .mask.show { display: block; }

  .topbar { padding: 0 12px; height: 54px; }
  .msgs { padding: 18px 13px 10px; }
  .bub { max-width: 84%; }
  .empty { padding: 40px 14px 30px; }
  .empty-h { font-size: 18px; }
  .composer { padding: 9px 12px 12px; }
  .model-sel { max-width: 138px; font-size: 12.5px; }
}

@media (max-width: 430px) {
  /* 顶部要挤下：菜单 + 模型下拉 + 设置 + 清空 */
  .topbar { padding: 0 10px; gap: 7px; }
  .icon-btn { padding: 6px 9px; font-size: 12.5px; }
  .model-sel { max-width: 100px; font-size: 12px; padding: 6px 22px 6px 9px; }
  .sel-wrap::after { right: 7px; }
  .modal { padding: 12px; }
  .modal-box { max-height: 92%; }
}

@media (max-width: 400px) {
  .ava { width: 28px; height: 28px; font-size: 12px; }
  .bub { max-width: 88%; padding: 10px 13px; }
}
