:root {
  --app-height: 100dvh;   /* 雷C：JS按visualViewport.height实时覆盖，键盘弹出时收窄，composer不被顶飞 */
  --bg: #F5F3EE;
  --bg-warm: #EDEAE3;
  --surface: #FFFFFF;
  --surface-soft: #ECEAE4;
  --line: #EDE9E0;
  --text: #1A1815;
  --text-soft: #48453E;
  --muted: #9A958B;
  --muted-soft: #B8B3A8;
  --shadow-soft: 0 2px 6px rgba(43, 38, 30, .05);
  --shadow-float: 0 10px 30px -10px rgba(43, 38, 30, .07);
  --bubble-user-bg: #ECEAE4;
  --error: #B3543F;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* 雷C根因（第二轮才抓对）：只收窄.app、不收窄html/body，body还是原尺寸（跟着layout viewport，
   键盘不影响它），.app变成悬在一个更高的body里的小盒子——body剩下的空间虽然overflow:hidden
   盖住了，但Safari判断输入框"没在文档可见范围里"，照样触发一次视口平移，把小盒子canvas拱得
   更偏。根治：连html/body的高度也跟着visualViewport收窄，整个文档不多不少刚好等于可见区，
   Safari找不到任何理由去平移——input本来就在文档唯一有的那块地方。 */
html, body { margin: 0; padding: 0; height: var(--app-height); }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", "Helvetica Neue", sans-serif;
  overflow: hidden;
  letter-spacing: -0.01em;
}

.app { height: 100%; display: flex; }

/* ---- chat column ---- */
.chat { flex: 1; min-width: 0; display: flex; flex-direction: column; height: 100%; position: relative; transition: margin-left .2s ease; }

.chat-header {
  flex: none;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}
.chat-title-wrap { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.chat-title { font-size: 16px; font-weight: 600; color: var(--text); }
.chat-model { font-size: 11px; color: var(--muted-soft); font-weight: 500; letter-spacing: .3px; min-height: 13px; }
.icon-btn-spacer { width: 40px; height: 40px; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--surface); border: none;
  box-shadow: 0 0 0 1px rgba(43, 38, 30, .05), var(--shadow-soft);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}

.messages {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 18px 18px 8px;
  display: flex; flex-direction: column; gap: 28px;
  scrollbar-width: none;
}
.messages::-webkit-scrollbar { display: none; }

.msg { display: flex; flex-direction: column; animation: fadeUp .3s ease both; }
.msg.user { align-items: flex-end; }
.msg.assistant { align-items: flex-start; }

.bubble {
  font-size: 16px; line-height: 1.75; letter-spacing: -0.008em;
  white-space: pre-wrap; word-break: break-word;
}
.msg.user .bubble {
  background: var(--bubble-user-bg); color: var(--text);
  border-radius: 20px; padding: 12px 16px; max-width: 78%;
}
.msg.assistant .bubble { color: var(--text); max-width: 100%; padding: 0; }
.msg.assistant.error .bubble { color: var(--error); }

/* ---- 折叠区（thinking/tool，B3.2）：安静、次要，默认折起，收起行用固定文案不做智能摘要 ---- */
.fold { margin-bottom: 12px; }
.fold-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  border: none; background: transparent; padding: 0; cursor: pointer; font-family: inherit;
  font-size: 13.5px; color: var(--muted); font-weight: 500;
}
.fold-chevron { display: inline-block; transition: transform .2s ease; font-size: 11px; color: var(--muted-soft); }
.fold.open .fold-chevron { transform: rotate(90deg); }
.fold-body {
  margin-top: 10px; padding-left: 13px; border-left: 2px solid var(--line);
  font-size: 14px; line-height: 1.7; color: var(--muted); white-space: pre-wrap; word-break: break-word;
}
.fold-body[hidden] { display: none; }

/* ---- 断线补显（B3.3雷B）：不当硬错误，只是软提示，等visibilitychange补显后自动消失 ---- */
.broken-note { margin-top: 6px; font-size: 12.5px; color: var(--muted); }

.typing-dots { display: flex; gap: 4px; padding: 6px 0 2px; }
.typing-dots span {
  width: 5px; height: 5px; border-radius: 50%; background: var(--muted-soft);
  animation: dots 1.4s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: .15s; }
.typing-dots span:nth-child(3) { animation-delay: .3s; }

@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes dots { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }

/* ---- 健康横幅（B5.2：网络/OAuth状态，只显示不需要操作按钮） ---- */
.health-banner {
  flex: none; margin: 0 14px 8px; padding: 12px 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow-soft);
  font-size: 13.5px; line-height: 1.6; color: var(--text-soft);
  animation: fadeUp .3s ease both;
}
.health-banner[hidden] { display: none; }
.health-banner.alarm { border-color: var(--error); color: var(--error); }

/* ---- 续杯提示条 ---- */
.rollover-banner {
  flex: none; margin: 0 14px 8px; padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: var(--shadow-float);
  display: flex; flex-direction: column; gap: 10px;
  animation: fadeUp .3s ease both;
}
.rollover-banner[hidden] { display: none; }
.rollover-text { font-size: 14px; line-height: 1.6; color: var(--text-soft); }
.rollover-actions { display: flex; justify-content: flex-end; gap: 10px; }
.rollover-dismiss {
  border: none; background: transparent; color: var(--muted); font-size: 13.5px;
  cursor: pointer; font-family: inherit; padding: 6px 10px;
}
.rollover-confirm {
  border: none; background: var(--text); color: var(--bg); border-radius: 16px;
  font-size: 13.5px; font-weight: 500; cursor: pointer; font-family: inherit; padding: 8px 16px;
}
.rollover-confirm:disabled, .rollover-dismiss:disabled { opacity: .5; cursor: default; }

/* ---- composer ---- */
.composer { flex: none; padding: 8px 14px 14px; }
.composer-box {
  background: #FBFAF7; border: 1px solid var(--line); border-radius: 24px;
  padding: 8px 8px 8px 18px;
  display: flex; align-items: flex-end; gap: 8px;
  box-shadow: 0 1px 3px rgba(43, 38, 30, .04);
}
#input {
  flex: 1; border: none; background: transparent; resize: none; outline: none;
  font-family: inherit; font-size: 16px; color: var(--text);
  max-height: 120px; padding: 9px 0; line-height: 1.5;
}
#input::placeholder { color: var(--muted-soft); font-weight: 300; }
.send-btn {
  flex: none; width: 40px; height: 40px; border-radius: 50%;
  background: var(--text); border: none;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.send-btn:disabled { opacity: .4; cursor: default; }

/* ---- drawer ---- */
.scrim {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .12); z-index: 90;
  opacity: 0; pointer-events: none; transition: opacity .15s ease;
}
.scrim.open { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed; left: 0; top: 0; bottom: 0; width: 280px; max-width: 82vw;
  background: var(--bg); z-index: 100; display: flex; flex-direction: column;
  box-shadow: 6px 0 24px rgba(0, 0, 0, .06);
  transform: translateX(-100%); transition: transform .2s ease;
}
.drawer.open { transform: none; }

.drawer-header { padding: 24px 20px 4px; }
.drawer-title { font-size: 19px; font-weight: 600; color: var(--text); }

.btn-new {
  margin: 18px 16px 4px;
  display: flex; align-items: center; gap: 8px;
  background: var(--text); color: var(--bg); border: none; border-radius: 20px;
  padding: 10px 16px; font-size: 14px; font-weight: 500; cursor: pointer; font-family: inherit;
}

.drawer-label { padding: 22px 20px 8px; font-size: 12px; color: var(--muted-soft); font-weight: 600; letter-spacing: 1px; }
.drawer-list { flex: 1; min-height: 0; overflow-y: auto; padding: 0 12px 16px; }
.conv-item {
  padding: 11px 12px; border-radius: 10px; font-size: 14.5px; color: var(--text-soft);
  cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-item:hover, .conv-item.active { background: var(--surface); }

/* 宽屏（claude.ai网页版式）：点一下常驻打开、点一下关闭，不因为点了聊天区就自动收起——
   抽屉本身还是原来那套position:fixed+transform滑动机制（跟手机端同一份代码），
   宽屏只多两条：不铺遮罩（scrim），抽屉打开时把chat区推让出280px。 */
@media (min-width: 720px) {
  .scrim { display: none; }
  .drawer { box-shadow: none; border-right: 1px solid var(--line); }
  .drawer.open ~ .chat { margin-left: 280px; }
}

/* ---- 新对话·选模型 bottom sheet ---- */
.sheet-scrim {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .18); z-index: 190;
  opacity: 0; pointer-events: none; transition: opacity .15s ease;
}
.sheet-scrim.open { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 200;
  background: var(--bg-warm); border-radius: 16px 16px 0 0;
  padding: 12px 20px calc(24px + env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform .25s ease;
}
.sheet.open { transform: none; }

.sheet-handle { width: 36px; height: 4px; border-radius: 2px; background: #D1CCC2; margin: 0 auto 16px; }
.sheet-title { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 14px; }

.model-options {
  display: flex; flex-direction: column; gap: 10px;
  max-height: 50vh; overflow-y: auto;
}
.model-option {
  display: flex; flex-direction: column; align-items: flex-start; gap: 3px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 13px 16px; text-align: left; cursor: pointer; font-family: inherit;
}
.model-option:active { background: var(--surface-soft); }
.model-name { font-size: 15px; font-weight: 600; color: var(--text); }
.model-desc { font-size: 12.5px; color: var(--muted); }

/* ---- 登录页（B3.4） ---- */
.login-screen {
  height: 100%; display: flex; align-items: center; justify-content: center;
  padding: 24px; overflow-y: auto;
}
.login-card {
  width: 100%; max-width: 320px;
  background: var(--surface); border-radius: 20px; box-shadow: var(--shadow-float);
  padding: 32px 26px; text-align: center;
}
.login-title { font-size: 20px; font-weight: 600; color: var(--text); }
.login-sub { font-size: 13.5px; color: var(--muted); margin-top: 6px; }
.login-form { display: flex; flex-direction: column; gap: 12px; margin-top: 24px; }
.login-input {
  width: 100%; border: 1px solid var(--line); background: #FBFAF7; border-radius: 14px;
  padding: 13px 16px; font-family: inherit; font-size: 16px; color: var(--text); outline: none;
}
.login-input::placeholder { color: var(--muted-soft); font-weight: 300; }
.login-btn {
  border: none; background: var(--text); color: var(--bg); border-radius: 14px;
  padding: 13px; font-family: inherit; font-size: 15px; font-weight: 500; cursor: pointer;
}
.login-btn:disabled { opacity: .5; cursor: default; }
.login-error { margin-top: 14px; font-size: 13px; color: var(--error); }
.login-error[hidden] { display: none; }
