:root {
  --bg: #0f1115; --panel: #171a21; --panel-2: #1f232c; --line: #2a2f3a;
  --text: #e7e9ee; --muted: #8b90a0; --accent: #6c8cff; --user: #2b4cff; --bubble: #232835;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--text);
}

/* 登录页 */
.login-wrap { height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-box { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 32px; width: 320px; display: flex; flex-direction: column; gap: 14px; }
.login-box h1 { font-size: 20px; margin: 0 0 8px; text-align: center; }
.login-box input { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 12px; color: var(--text); font-size: 15px; outline: none; }
.login-box input:focus { border-color: var(--accent); }
.login-err { color: #ff6b6b; font-size: 13px; min-height: 16px; margin: 0; text-align: center; }

/* 主布局 */
#app { display: flex; height: 100vh; }
.sidebar { width: 250px; flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--line); padding: 16px; overflow-y: auto; }
.brand { font-size: 18px; font-weight: 700; margin-bottom: 14px; display: flex; justify-content: space-between; align-items: center; }
.brand button { background: none; border: 1px solid var(--line); color: var(--muted); border-radius: 6px; cursor: pointer; padding: 2px 8px; }

#charList, #sessionList { list-style: none; padding: 0; margin: 12px 0 0; }
#charList li, #sessionList li { padding: 9px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); margin-bottom: 4px; font-size: 14px; }
#charList li:hover, #sessionList li:hover { background: var(--panel-2); color: var(--text); }
#charList li.active, #sessionList li.active { background: var(--panel-2); color: var(--text); }

#sessionPanel { margin-top: 20px; border-top: 1px solid var(--line); padding-top: 12px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--muted); }
.panel-head button { background: none; border: 1px solid var(--accent); color: var(--accent); border-radius: 12px; cursor: pointer; font-size: 12px; padding: 3px 8px; }

.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#chatHeader { padding: 14px 20px; border-bottom: 1px solid var(--line); font-weight: 600; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.model-pick { display: flex; gap: 8px; }
.model-pick select { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font-size: 13px; }

.messages { flex: 1; overflow-y: auto; padding: 20px; }
.msg { display: flex; margin-bottom: 14px; }
.msg .bubble { max-width: 70%; padding: 10px 14px; border-radius: 14px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.msg.model .bubble { background: var(--bubble); border-top-left-radius: 4px; }
.msg.user { justify-content: flex-end; }
.msg.user .bubble { background: var(--user); border-top-right-radius: 4px; cursor: pointer; }
.msg.user .bubble:hover { filter: brightness(1.12); }
.msg.typing .bubble { color: var(--muted); }

.suggestions { display: flex; gap: 8px; flex-wrap: wrap; padding: 0 20px 8px; }
.suggestions button { background: transparent; border: 1px solid var(--accent); color: var(--accent); border-radius: 16px; padding: 6px 12px; font-size: 13px; cursor: pointer; }
.suggestions button:hover { background: var(--accent); color: #fff; }

.edit-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 20px; background: #2a2440; border-top: 1px solid var(--line); font-size: 13px; color: #c9b8ff; }
.edit-bar button { background: none; border: 1px solid #6c5ba8; color: #c9b8ff; border-radius: 8px; padding: 4px 10px; cursor: pointer; font-size: 12px; }

.composer { display: flex; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); }
.composer input { flex: 1; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; color: var(--text); font-size: 15px; outline: none; }
.composer input:focus { border-color: var(--accent); }

button.primary, .composer button { background: var(--accent); color: #fff; border: none; border-radius: 10px; padding: 10px 16px; cursor: pointer; font-size: 14px; }
button.primary { width: 100%; }
button:disabled { opacity: .5; cursor: not-allowed; }

.hidden { display: none; }

/* 菜单按钮 + 遮罩（仅手机用） */
.menu-btn { display: none; background: none; border: 1px solid var(--line); color: var(--text); border-radius: 8px; font-size: 18px; line-height: 1; padding: 6px 10px; cursor: pointer; }
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 20; }
.overlay.hidden { display: none; }

/* ---------- 手机适配 ---------- */
@media (max-width: 768px) {
  /* 侧栏变成从左滑出的抽屉 */
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 30;
    width: 78%; max-width: 300px;
    transform: translateX(-100%); transition: transform .25s ease;
    box-shadow: 2px 0 16px rgba(0,0,0,.4);
  }
  .sidebar.open { transform: translateX(0); }

  .chat { width: 100%; }
  .menu-btn { display: inline-flex; align-items: center; }

  /* 顶栏：菜单 + 标题一行，模型选择换行到下方 */
  #chatHeader { flex-wrap: wrap; gap: 8px 10px; padding: 12px 14px; }
  #chatTitle { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .model-pick { width: 100%; }
  .model-pick select { flex: 1; min-width: 0; }

  .messages { padding: 14px; }
  .msg .bubble { max-width: 85%; }
  .suggestions { padding: 0 14px 8px; }

  .composer { padding: 10px 14px; }
  /* 16px 避免 iOS 聚焦时自动放大 */
  .composer input { font-size: 16px; padding: 11px 13px; }
}

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }
.modal-box { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 24px; width: 440px; max-width: 92vw; }
.modal-box h2 { margin: 0 0 16px; font-size: 18px; }
.modal-box label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 14px; }
.modal-box input, .modal-box textarea { width: 100%; margin-top: 6px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; color: var(--text); font-size: 14px; font-family: inherit; resize: vertical; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
.modal-actions button { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 9px 16px; cursor: pointer; }
.modal-actions button.primary { background: var(--accent); border: none; color: #fff; width: auto; }
