/* CatGPT — ChatGPT-like dark theme */
* { box-sizing: border-box; }
:root {
  --bg: #212121;
  --bg-2: #303030;
  --bg-3: #2f2f2f;
  --side: #171717;
  --side-hover: #212121;
  --border: #3d3d3d;
  --text: #ececec;
  --text-dim: #9a9a9a;
  --accent: #10a37f;
  --user-bubble: #2f2f2f;
  --danger: #ef4146;
  --radius: 12px;
}
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text); overflow: hidden;
}
#app { display: flex; height: 100vh; }

/* ── 侧边栏 ── */
#sidebar {
  width: 268px; flex-shrink: 0; background: var(--side);
  display: flex; flex-direction: column; border-right: 1px solid var(--border);
}
.side-head { padding: 12px; }
.brand { font-weight: 700; font-size: 15px; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.brand .logo { color: var(--accent); }
.btn-new {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); background: transparent;
  color: var(--text); border-radius: var(--radius); font-size: 14px; cursor: pointer; text-align: left;
}
.btn-new:hover { background: var(--side-hover); }
.thread-list { flex: 1; overflow-y: auto; padding: 4px 8px; }
.thread-empty { color: var(--text-dim); font-size: 13px; padding: 12px; }
.thread-item {
  display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: 8px;
  cursor: pointer; color: var(--text-dim); font-size: 14px; white-space: nowrap; overflow: hidden;
}
.thread-item:hover { background: var(--side-hover); color: var(--text); }
.thread-item.active { background: var(--bg-2); color: var(--text); }
.thread-ico { opacity: .6; font-size: 13px; }
.thread-title { overflow: hidden; text-overflow: ellipsis; }
.side-foot { padding: 10px 12px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 8px; }
.status-pill { font-size: 12px; flex: 1; }
.status-pill.ok { color: var(--accent); }
.status-pill.bad { color: var(--danger); }
.status-pill.checking { color: var(--text-dim); }
.user-name { font-size: 12px; color: var(--text-dim); margin-left: auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 120px; }

/* 重新登录横幅 */
.relogin-banner {
  background: #3a1d1d; color: #ffb4b4; padding: 10px 16px; font-size: 13px;
  border-bottom: 1px solid #5a2a2a; text-align: center;
}
.relogin-banner a { color: #ff8a8a; text-decoration: underline; }
.relogin-banner.hidden { display: none; }

/* ── 主区 ── */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 52px; border-bottom: 1px solid var(--border); display: flex; align-items: center;
  padding: 0 16px; gap: 10px; background: var(--bg);
}
.chat-title { font-weight: 600; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.model-badge { font-size: 12px; color: var(--text-dim); border: 1px solid var(--border); padding: 3px 8px; border-radius: 20px; }
.icon-btn {
  background: transparent; border: none; color: var(--text-dim); cursor: pointer; font-size: 18px;
  padding: 6px 8px; border-radius: 8px;
}
.icon-btn:hover { background: var(--bg-2); color: var(--text); }
a.icon-btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }

.messages { flex: 1; overflow-y: auto; padding: 24px 0; }
.empty-state { text-align: center; color: var(--text-dim); margin-top: 12vh; }
.empty-state .empty-logo { font-size: 44px; color: var(--accent); margin-bottom: 8px; }
.empty-state h1 { color: var(--text); margin: 6px 0; font-size: 26px; }
.empty-state p { margin: 4px 0; font-size: 14px; }

/* 消息 */
.msg { max-width: 780px; margin: 0 auto 22px; padding: 0 20px; display: flex; gap: 16px; }
.avatar {
  width: 30px; height: 30px; flex-shrink: 0; border-radius: 6px; display: flex; align-items: center;
  justify-content: center; font-size: 14px; background: var(--accent); color: #fff; font-weight: 700;
}
.msg.user .avatar { background: #5a5a5a; }
.msg-body { flex: 1; min-width: 0; }
.msg-text { line-height: 1.65; font-size: 15px; }
.msg.user .msg-text { background: var(--user-bubble); padding: 10px 14px; border-radius: var(--radius); display: inline-block; }

/* markdown */
.markdown p { margin: 8px 0; }
.markdown h1, .markdown h2, .markdown h3 { margin: 16px 0 8px; line-height: 1.3; }
.markdown ul, .markdown ol { padding-left: 24px; }
.markdown a { color: #7cc7ff; }
.markdown code { background: #0d0d0d; padding: 2px 6px; border-radius: 5px; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 13px; }
.markdown pre { background: #0d0d0d !important; border-radius: 10px; padding: 14px; overflow-x: auto; border: 1px solid var(--border); }
.markdown pre code { background: none; padding: 0; font-size: 13px; line-height: 1.5; }
.markdown table { border-collapse: collapse; margin: 10px 0; }
.markdown th, .markdown td { border: 1px solid var(--border); padding: 6px 10px; }
.markdown blockquote { border-left: 3px solid var(--border); margin: 8px 0; padding-left: 14px; color: var(--text-dim); }

/* 图片画廊 */
.gallery { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.img-card { position: relative; width: 240px; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.img-card img { width: 100%; display: block; cursor: zoom-in; }
.img-dl {
  position: absolute; bottom: 6px; right: 6px; background: rgba(0,0,0,.6); color: #fff;
  font-size: 12px; padding: 3px 8px; border-radius: 6px; text-decoration: none;
}
.img-dl:hover { background: var(--accent); }

/* 打字动画 */
.typing .dots { display: inline-flex; gap: 4px; padding: 6px 0; }
.typing .dots span { width: 8px; height: 8px; background: var(--text-dim); border-radius: 50%; animation: blink 1.4s infinite both; }
.typing .dots span:nth-child(2) { animation-delay: .2s; }
.typing .dots span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* 输入区 */
.composer-wrap { max-width: 780px; margin: 0 auto 18px; padding: 0 20px; width: 100%; }
.attach-preview { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.attach-chip { position: relative; width: 64px; height: 64px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.attach-chip img { width: 100%; height: 100%; object-fit: cover; }
.attach-chip .rm {
  position: absolute; top: 2px; right: 2px; background: rgba(0,0,0,.7); color: #fff;
  width: 16px; height: 16px; border-radius: 50%; font-size: 10px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; line-height: 1;
}
.composer {
  display: flex; align-items: flex-end; gap: 6px; background: var(--bg-3);
  border: 1px solid var(--border); border-radius: 24px; padding: 6px 8px;
}
.composer textarea {
  flex: 1; background: transparent; border: none; resize: none; color: var(--text);
  font-size: 15px; line-height: 1.5; padding: 8px 4px; max-height: 200px; outline: none; font-family: inherit;
}
.btn-send {
  width: 36px; height: 36px; border-radius: 50%; border: none; background: var(--accent);
  color: #fff; font-size: 15px; cursor: pointer; flex-shrink: 0;
}
.btn-send:disabled { background: #3a3a3a; color: var(--text-dim); cursor: not-allowed; }
.composer-hint { text-align: center; color: var(--text-dim); font-size: 12px; margin-top: 8px; }

/* 弹窗 */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal.hidden { display: none; }
.modal-card { background: var(--bg-2); border: 1px solid var(--border); border-radius: 16px; padding: 22px; width: 360px; max-width: 90vw; }
.modal-card h3 { margin: 0 0 14px; }
.modal-card label { font-size: 13px; color: var(--text-dim); display: block; margin-bottom: 6px; }
.modal-card input { width: 100%; padding: 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.btn-primary { background: var(--accent); color: #fff; border: none; padding: 9px 16px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); padding: 9px 16px; border-radius: 8px; cursor: pointer; font-size: 14px; }

/* toast */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #000; color: #fff; padding: 12px 20px; border-radius: 10px; font-size: 14px; z-index: 60; box-shadow: 0 6px 24px rgba(0,0,0,.4); }
.toast.hidden { display: none; }

/* 滚动条 */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #3a3a3a; border-radius: 8px; }

/* 响应式 */
.only-mobile { display: none; }
@media (max-width: 760px) {
  #sidebar { position: absolute; z-index: 30; height: 100%; transform: translateX(-100%); transition: transform .2s; }
  #sidebar.open { transform: translateX(0); }
  .only-mobile { display: inline-block; }
}
