:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --text: #1d2330;
  --muted: #6b7280;
  --line: #e3e7ef;
  --primary: #2456d6;
  --primary-dark: #1b43a8;
  --danger: #c62828;
  --user-bubble: #2456d6;
  --assistant-bubble: #ffffff;
  --shadow: 0 8px 30px rgba(20, 30, 60, 0.08);
}

* { box-sizing: border-box; }

/* 关键：确保 hidden 属性优先于各组件的 display 规则 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans CJK SC", "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  font-size: 15px;
}

button { font: inherit; cursor: pointer; }

input, textarea {
  font: inherit;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
  outline: none;
}
input:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(36, 86, 214, 0.12); }

.primary {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
}
.primary:hover { background: var(--primary-dark); }
.primary:disabled { opacity: 0.5; cursor: not-allowed; }
.wide { width: 100%; }

.link {
  background: none;
  border: none;
  color: var(--primary);
  padding: 4px 6px;
}
.link:hover { text-decoration: underline; }
.link.danger { color: var(--danger); }

.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; margin: 0; }
.card { background: var(--panel); border-radius: 16px; box-shadow: var(--shadow); }

/* 登录 */
.login-wrap { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 100%; max-width: 380px; padding: 32px; display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { margin: 0; font-size: 28px; letter-spacing: 0.5px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }

/* 布局 */
.app { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 280px;
  flex: 0 0 280px;
  background: #101728;
  color: #dfe6f5;
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 12px;
}
.brand { font-size: 20px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.badge {
  font-size: 11px;
  font-weight: 500;
  color: #9fb4e8;
  border: 1px solid #33456e;
  border-radius: 999px;
  padding: 2px 8px;
}
.conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; margin: 4px -4px; }
.conv-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 9px;
  cursor: pointer;
  color: #cdd7ee;
  font-size: 14px;
}
.conv-item:hover { background: #1a2440; }
.conv-item.active { background: #23325a; color: #fff; }
.conv-item .title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item .del {
  opacity: 0;
  background: none;
  border: none;
  color: #8fa2c9;
  padding: 0 2px;
}
.conv-item:hover .del { opacity: 1; }
.conv-item .del:hover { color: #ff9d9d; }

.sidebar-foot { border-top: 1px solid #25314f; padding-top: 10px; font-size: 13px; }
.current-user { margin-bottom: 6px; color: #9fb4e8; }
.foot-actions { display: flex; flex-wrap: wrap; gap: 2px 8px; }
.foot-actions .link { color: #aebfe4; padding: 2px 0; }
.foot-actions .link.danger { color: #ff9d9d; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-head {
  height: 56px;
  flex: 0 0 56px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,0.85);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  font-weight: 600;
}
.toggle { font-weight: 400; font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }

.messages { flex: 1; overflow-y: auto; padding: 24px 20px 12px; display: flex; flex-direction: column; gap: 16px; }
.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.bubble {
  max-width: min(760px, 82%);
  padding: 12px 16px;
  border-radius: 14px;
  line-height: 1.65;
  word-break: break-word;
  white-space: normal;
}
.msg.user .bubble { background: var(--user-bubble); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant .bubble { background: var(--assistant-bubble); box-shadow: 0 1px 3px rgba(20,30,60,0.08); border-bottom-left-radius: 4px; }
.bubble p { margin: 0 0 10px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble pre {
  background: #0f1729;
  color: #e6edf7;
  padding: 12px 14px;
  border-radius: 10px;
  overflow-x: auto;
  font-size: 13px;
}
.bubble code { background: rgba(36,86,214,0.08); padding: 1px 5px; border-radius: 5px; font-size: 0.92em; }
.bubble pre code { background: none; padding: 0; }
.msg.user .bubble code { background: rgba(255,255,255,0.18); }

.reasoning {
  margin-bottom: 10px;
  color: #64748b;
  font-size: 13.5px;
  border-left: 3px solid #c7d2e8;
  padding-left: 10px;
}
.reasoning summary { cursor: pointer; color: #475569; }
.reasoning div { margin-top: 6px; white-space: pre-wrap; }

.composer { display: flex; gap: 10px; padding: 14px 20px 20px; align-items: flex-end; }
.composer textarea {
  flex: 1;
  resize: none;
  max-height: 200px;
  min-height: 46px;
  line-height: 1.5;
}
.composer .primary { height: 46px; }

/* 弹窗 */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 16, 30, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.modal { width: 100%; max-width: 680px; max-height: 86vh; overflow-y: auto; padding: 22px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h2 { margin: 0; font-size: 18px; }

.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th, .table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { color: var(--muted); font-weight: 500; }
.key-secret {
  display: block;
  background: #f1f4fa;
  border: 1px dashed #b9c5dd;
  border-radius: 8px;
  padding: 10px 12px;
  margin: 10px 0;
  word-break: break-all;
  font-family: ui-monospace, monospace;
  font-size: 13px;
}
.form-row { display: flex; gap: 8px; margin: 10px 0; flex-wrap: wrap; }
.form-row input { flex: 1; min-width: 140px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.small { font-size: 12.5px; }
.section { margin: 18px 0 8px; font-weight: 600; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #101728;
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 100;
  box-shadow: var(--shadow);
}

@media (max-width: 760px) {
  .sidebar { width: 210px; flex-basis: 210px; padding: 12px; }
  .bubble { max-width: 92%; }
  .chat-head { padding: 0 12px; }
  .messages { padding: 16px 12px 8px; }
  .composer { padding: 10px 12px 14px; }
}
