/* ============================================================
   童儿私人小站 · 前台样式
   ============================================================ */

:root {
  --accent: #ff7a2f;
  --accent-strong: #ff6a00;
  --accent-soft: rgba(255, 122, 47, 0.14);
  --accent-text: #ffb27a;
  --danger: #ff6568;
  --success: #4ade80;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans SC", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: dark;
}

html[data-theme="dark"] {
  --bg: #171717;
  --bg-elev: #1d1d1d;
  --sidebar: #111111;
  --panel: #232323;
  --panel-2: #2c2c2c;
  --panel-3: #383838;
  --border: rgba(255, 255, 255, 0.085);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #ededed;
  --text-soft: #c8c8c8;
  --muted: #8e8e8e;
  --user-bubble: #2b2b2b;
  --code-bg: #101010;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
  --scrim: rgba(0, 0, 0, 0.55);
  color-scheme: dark;
}

html[data-theme="light"] {
  --bg: #ffffff;
  --bg-elev: #fafaf8;
  --sidebar: #f7f7f4;
  --panel: #f2f2ee;
  --panel-2: #e9e9e4;
  --panel-3: #dededa;
  --border: rgba(0, 0, 0, 0.085);
  --border-strong: rgba(0, 0, 0, 0.16);
  --text: #1e1e1f;
  --text-soft: #3c3c3f;
  --muted: #71717a;
  --user-bubble: #efefeb;
  --code-bg: #f7f7f4;
  --accent-text: #c45000;
  --accent-soft: rgba(245, 106, 0, 0.1);
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.12);
  --scrim: rgba(0, 0, 0, 0.28);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}

button,
input,
textarea {
  font-family: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

a {
  color: var(--accent-text);
}

svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  stroke-width: 1.8;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.hidden {
  display: none !important;
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 8px;
}
::-webkit-scrollbar-track {
  background: transparent;
}

/* ------------------------------- 布局 ------------------------------- */

.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
}

.sidebar {
  width: 274px;
  flex: 0 0 274px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 12px 10px 10px;
  gap: 8px;
  transition: width 0.22s ease, flex-basis 0.22s ease, padding 0.22s ease;
  z-index: 30;
}

.app.collapsed .sidebar {
  width: 0;
  flex-basis: 0;
  padding-left: 0;
  padding-right: 0;
  border-right: 0;
  overflow: hidden;
}

.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 6px 6px;
  min-height: 38px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.logo-mark {
  width: 28px;
  height: 28px;
  flex: none;
  display: inline-flex;
  border-radius: 9px;
  overflow: hidden;
  box-shadow: 0 3px 12px rgba(255, 106, 0, 0.28);
}

.logo-mark svg {
  width: 100%;
  height: 100%;
  stroke: none;
}

.logo-mark.big {
  width: 54px;
  height: 54px;
  border-radius: 15px;
}

.brand-name {
  font-size: 15.5px;
  font-weight: 650;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  transition: background 0.16s, color 0.16s;
}

.icon-btn:hover {
  background: var(--panel);
  color: var(--text);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

.menu-btn {
  margin-right: 4px;
}

.app:not(.collapsed) .menu-btn {
  display: none;
}

/* 新对话 */
.new-chat {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 14px;
  font-weight: 550;
  text-align: left;
  transition: background 0.16s, border-color 0.16s;
}

.new-chat:hover {
  background: var(--panel-2);
  border-color: var(--border-strong);
}

.new-chat svg {
  width: 17px;
  height: 17px;
  color: var(--accent);
}

.new-chat kbd {
  margin-left: auto;
  font-family: var(--font);
  font-size: 10.5px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 2px 5px;
}

/* 搜索 */
.search-box {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 10px;
  height: 35px;
  border-radius: 9px;
  background: transparent;
  border: 1px solid transparent;
  transition: background 0.16s, border-color 0.16s;
}

.search-box:focus-within {
  background: var(--panel);
  border-color: var(--border);
}

.search-box svg {
  width: 15px;
  height: 15px;
  color: var(--muted);
  flex: none;
}

.search-box input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 13px;
}

.search-box input::placeholder {
  color: var(--muted);
}

.search-box input::-webkit-search-cancel-button {
  filter: grayscale(1) opacity(0.5);
}

/* 会话列表 */
.conv-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 2px 2px 8px;
  margin: 0 -2px;
}

.conv-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 10px 3px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.conv-count {
  min-width: 19px;
  height: 18px;
  padding: 0 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0;
}

.conv-group-label {
  padding: 9px 10px 5px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.conv-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 8px 8px 8px 10px;
  margin-bottom: 1px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text-soft);
  font-size: 13.5px;
  text-align: left;
  transition: background 0.14s, color 0.14s;
}

.conv-item:hover {
  background: var(--panel);
  color: var(--text);
}

.conv-item.active {
  background: var(--panel-2);
  color: var(--text);
}

.conv-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 9px;
  bottom: 9px;
  width: 2.5px;
  border-radius: 3px;
  background: var(--accent);
}

.conv-item svg {
  width: 15px;
  height: 15px;
  color: var(--muted);
  flex: none;
}

.conv-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conv-actions {
  display: none;
  gap: 1px;
  flex: none;
}

.conv-item:hover .conv-actions,
.conv-item.active .conv-actions {
  display: flex;
}

.conv-action {
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}

.conv-action:hover {
  background: var(--panel-3);
  color: var(--text);
}

.conv-action.danger:hover {
  color: var(--danger);
}

.conv-action svg {
  width: 13px;
  height: 13px;
}

.conv-empty {
  padding: 26px 12px;
  text-align: center;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.7;
}

/* 侧栏底部用户 */
.side-foot {
  position: relative;
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 7px 8px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  transition: background 0.16s;
}

.user-chip:hover {
  background: var(--panel);
}

.avatar {
  width: 30px;
  height: 30px;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: linear-gradient(135deg, #ffa45c, #ff6a00);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

.user-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.user-name {
  font-size: 13px;
  font-weight: 550;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-role {
  font-size: 11px;
  color: var(--muted);
}

.more-dots {
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  padding: 0 4px;
}

.user-menu {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 58px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 5px;
  box-shadow: var(--shadow);
  z-index: 40;
  animation: pop 0.14s ease;
}

.user-menu button {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-soft);
  font-size: 13px;
  text-align: left;
}

.user-menu button:hover {
  background: var(--panel-2);
  color: var(--text);
}

.user-menu button.danger:hover {
  color: var(--danger);
}

/* ------------------------------- 主区域 ------------------------------- */

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg);
}

.topbar {
  flex: none;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 18px;
  z-index: 20;
}

.topbar-left {
  display: flex;
  align-items: center;
  min-width: 0;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.model-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  max-width: 260px;
  height: 34px;
  padding: 0 11px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--text);
  font-size: 13.5px;
  font-weight: 600;
  transition: background 0.16s, border-color 0.16s;
}

.model-btn:hover {
  background: var(--panel);
  border-color: var(--border);
}

.model-btn span:nth-child(2) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-dot {
  width: 7px;
  height: 7px;
  flex: none;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.12);
}

.chevron {
  width: 14px;
  height: 14px;
  color: var(--muted);
  flex: none;
}

.model-menu {
  position: absolute;
  top: 50px;
  left: 18px;
  min-width: 268px;
  max-width: calc(100vw - 36px);
  max-height: min(420px, calc(100dvh - 90px));
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 6px;
  box-shadow: var(--shadow);
  z-index: 45;
  animation: pop 0.14s ease;
}

.model-option {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-soft);
  text-align: left;
}

.model-option:hover {
  background: var(--panel-2);
  color: var(--text);
}

.model-option.active {
  background: var(--accent-soft);
  color: var(--text);
}

.model-option .check {
  margin-left: auto;
  color: var(--accent);
  width: 16px;
  height: 16px;
  opacity: 0;
}

.model-option.active .check {
  opacity: 1;
}

.model-option .m-name {
  display: block;
  font-size: 13.5px;
  font-weight: 550;
}

.model-option .m-id {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-top: 1px;
}

.usage-pill {
  font-size: 11.5px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

#themeBtn .icon-moon {
  display: none;
}

html[data-theme="light"] #themeBtn .icon-sun {
  display: none;
}

html[data-theme="light"] #themeBtn .icon-moon {
  display: block;
}

/* 公告 */
.notice {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 18px 4px;
  padding: 9px 12px;
  border: 1px solid rgba(255, 122, 47, 0.22);
  background: var(--accent-soft);
  border-radius: 10px;
  color: var(--accent-text);
  font-size: 12.5px;
}

.notice svg {
  width: 15px;
  height: 15px;
  flex: none;
}

.notice span {
  flex: 1;
}

.notice button {
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 17px;
  line-height: 1;
  padding: 0 2px;
  opacity: 0.7;
}

/* 聊天滚动区 */
.chat-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
}

.thread {
  max-width: 800px;
  margin: 0 auto;
  padding: 12px 24px 34px;
  min-height: 100%;
}

/* 欢迎页 */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: clamp(40px, 11vh, 110px) 0 30px;
  animation: fadeUp 0.4s ease both;
}

.welcome-logo {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 14px 40px rgba(255, 106, 0, 0.3);
  margin-bottom: 22px;
}

.welcome-logo svg {
  width: 100%;
  height: 100%;
  stroke: none;
}

.welcome h1 {
  margin: 0 0 9px;
  font-size: clamp(24px, 3.2vw, 31px);
  font-weight: 650;
  letter-spacing: -0.02em;
}

.welcome-sub {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
  max-width: 520px;
}

.chips {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  width: min(560px, 100%);
  margin-top: 30px;
}

.chip {
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: color-mix(in srgb, var(--panel) 70%, transparent);
  color: var(--text-soft);
  font-size: 13px;
  text-align: left;
  transition: background 0.16s, border-color 0.16s, transform 0.16s;
}

.chip:hover {
  background: var(--panel-2);
  border-color: var(--border-strong);
  transform: translateY(-1px);
  color: var(--text);
}

/* 消息 */
.messages {
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.msg {
  display: flex;
  gap: 13px;
  animation: fadeUp 0.22s ease both;
}

.msg.user {
  justify-content: flex-end;
}

.msg-avatar {
  width: 30px;
  height: 30px;
  flex: none;
  margin-top: 2px;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 4px 14px rgba(255, 106, 0, 0.22);
}

.msg-avatar svg {
  width: 100%;
  height: 100%;
  stroke: none;
}

.msg-body {
  flex: 1;
  min-width: 0;
}

.msg.user .bubble {
  max-width: min(80%, 620px);
  padding: 10px 15px;
  border-radius: 17px 17px 5px 17px;
  background: var(--user-bubble);
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* Markdown */
.md {
  font-size: 15px;
  line-height: 1.76;
  overflow-wrap: anywhere;
}

.md > :first-child {
  margin-top: 0;
}

.md > :last-child {
  margin-bottom: 0;
}

.md p {
  margin: 0 0 13px;
}

.md h1,
.md h2,
.md h3,
.md h4,
.md h5,
.md h6 {
  margin: 22px 0 10px;
  font-weight: 650;
  line-height: 1.35;
  letter-spacing: -0.01em;
}

.md h1 {
  font-size: 1.45em;
}
.md h2 {
  font-size: 1.3em;
}
.md h3 {
  font-size: 1.14em;
}
.md h4,
.md h5,
.md h6 {
  font-size: 1em;
}

.md ul,
.md ol {
  margin: 0 0 13px;
  padding-left: 1.45em;
}

.md li {
  margin: 4px 0;
}

.md li::marker {
  color: var(--muted);
}

.md blockquote {
  margin: 14px 0;
  padding: 2px 0 2px 14px;
  border-left: 3px solid var(--accent);
  color: var(--muted);
}

.md blockquote p:last-child {
  margin-bottom: 0;
}

.md hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

.md a {
  color: var(--accent-text);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.md strong {
  font-weight: 650;
  color: var(--text);
}

.md code.inline-code {
  font-family: var(--mono);
  font-size: 0.88em;
  padding: 2px 5px;
  border-radius: 5px;
  background: var(--panel-2);
  color: var(--accent-text);
}

.md table {
  border-collapse: collapse;
  margin: 14px 0;
  font-size: 13.5px;
  display: block;
  max-width: 100%;
  overflow-x: auto;
}

.md th,
.md td {
  border: 1px solid var(--border);
  padding: 7px 11px;
  text-align: left;
  white-space: nowrap;
}

.md th:last-child,
.md td:last-child {
  white-space: normal;
  min-width: 150px;
}

.md th {
  background: var(--panel);
  font-weight: 600;
}

.code-block {
  margin: 14px 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--code-bg);
}

.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--panel) 55%, transparent);
  color: var(--muted);
  font-size: 11.5px;
  letter-spacing: 0.02em;
}

.copy-code {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 11.5px;
  padding: 3px 6px;
  border-radius: 5px;
}

.copy-code:hover {
  background: var(--panel-2);
  color: var(--text);
}

.copy-code svg {
  width: 12px;
  height: 12px;
}

.code-block pre {
  margin: 0;
  padding: 14px 16px;
  overflow-x: auto;
}

.code-block pre code {
  font-family: var(--mono);
  font-size: 12.8px;
  line-height: 1.7;
  white-space: pre;
  color: var(--text-soft);
}

.cursor {
  display: inline-block;
  width: 7px;
  height: 15px;
  margin-left: 2px;
  border-radius: 2px;
  background: var(--accent);
  vertical-align: -2px;
  animation: blink 1s steps(2, start) infinite;
}

/* 思考过程 */
.reasoning {
  margin: 0 0 12px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--panel);
  overflow: hidden;
}

.reasoning summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  list-style: none;
  font-size: 12.5px;
  color: var(--muted);
  user-select: none;
}

.reasoning summary::-webkit-details-marker {
  display: none;
}

.reasoning summary .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.reasoning[open] summary {
  border-bottom: 1px solid var(--border);
}

.reasoning-body {
  padding: 11px 14px;
  max-height: 320px;
  overflow-y: auto;
  color: var(--muted);
  font-size: 12.8px;
  line-height: 1.72;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.reasoning.streaming summary .dot {
  animation: pulse 1.2s ease-in-out infinite;
}

/* 消息底部信息 */
.msg-foot {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 9px;
  min-height: 24px;
  color: var(--muted);
  font-size: 11px;
}

.msg-tokens {
  font-variant-numeric: tabular-nums;
}

.msg-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.16s;
}

.msg:hover .msg-actions {
  opacity: 1;
}

.msg-action {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 11.5px;
  padding: 3px 6px;
  border-radius: 6px;
}

.msg-action:hover {
  background: var(--panel);
  color: var(--text);
}

.msg-action svg {
  width: 13px;
  height: 13px;
}

.msg-error {
  margin-top: 10px;
  padding: 9px 12px;
  border: 1px solid rgba(255, 101, 104, 0.25);
  background: rgba(255, 101, 104, 0.08);
  border-radius: 9px;
  color: #ff9a9c;
  font-size: 12.5px;
  line-height: 1.6;
}

.msg-stopped {
  margin-top: 9px;
  font-size: 11.5px;
  color: var(--muted);
  font-style: italic;
}

/* 等待响应 */
.typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 26px;
}

.typing i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--muted);
  animation: bounce 1.2s ease-in-out infinite;
}

.typing i:nth-child(2) {
  animation-delay: 0.15s;
}
.typing i:nth-child(3) {
  animation-delay: 0.3s;
}

/* ------------------------------- 输入区 ------------------------------- */

.composer-area {
  flex: none;
  padding: 6px 24px 12px;
  background: linear-gradient(180deg, transparent, var(--bg) 26%);
  position: relative;
  z-index: 10;
}

.composer {
  max-width: 800px;
  margin: 0 auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 21px;
  padding: 9px 11px 7px;
  transition: border-color 0.18s, box-shadow 0.18s, background 0.18s;
}

.composer:focus-within {
  border-color: rgba(255, 122, 47, 0.4);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.composer textarea {
  display: block;
  width: 100%;
  max-height: 190px;
  min-height: 26px;
  padding: 5px 6px 3px;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  font-size: 15px;
  line-height: 1.6;
}

.composer textarea::placeholder {
  color: var(--muted);
}

.composer-bottom {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 2px 0;
}

.model-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 210px;
  padding: 5px 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 11.5px;
  transition: background 0.16s, color 0.16s;
}

.model-chip:hover {
  background: var(--panel-2);
  color: var(--text);
}

.model-chip .status-dot {
  width: 5px;
  height: 5px;
  box-shadow: none;
}

.model-chip .chevron {
  width: 12px;
  height: 12px;
}

.composer-hint {
  margin-left: auto;
  color: var(--muted);
  font-size: 10.5px;
  white-space: nowrap;
}

.send-btn {
  width: 34px;
  height: 34px;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  opacity: 0.32;
  pointer-events: none;
  transition: opacity 0.16s, background 0.16s, transform 0.12s;
}

.send-btn svg {
  width: 17px;
  height: 17px;
  stroke-width: 2.1;
}

.send-btn.ready {
  opacity: 1;
  pointer-events: auto;
}

.send-btn.ready:hover {
  background: var(--accent-strong);
}

.send-btn:active {
  transform: scale(0.94);
}

.send-btn .icon-stop {
  display: none;
}

.send-btn.streaming {
  opacity: 1;
  pointer-events: auto;
  background: var(--panel-3);
  color: var(--text);
}

.send-btn.streaming .icon-send {
  display: none;
}

.send-btn.streaming .icon-stop {
  display: block;
}

.composer-foot {
  max-width: 800px;
  margin: 7px auto 0;
  padding: 0 6px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 10.5px;
}

/* ------------------------------- 弹层 ------------------------------- */

.scrim {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 25;
}

.app.sidebar-open .scrim {
  opacity: 1;
  pointer-events: auto;
}

.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 22px;
  overflow-y: auto;
  background:
    radial-gradient(900px 480px at 50% -10%, rgba(255, 122, 47, 0.1), transparent 70%),
    var(--bg);
}

.auth-card {
  width: min(420px, 100%);
  padding: 30px 30px 22px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  animation: fadeUp 0.28s ease both;
}

.auth-brand {
  text-align: center;
  margin-bottom: 22px;
}

.auth-brand .logo-mark {
  margin-bottom: 14px;
}

.auth-brand h2 {
  margin: 0 0 5px;
  font-size: 21px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.auth-brand p {
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
}

.auth-tabs {
  display: flex;
  gap: 4px;
  padding: 3px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 18px;
}

.auth-tabs button {
  flex: 1;
  padding: 7px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 550;
  transition: background 0.16s, color 0.16s;
}

.auth-tabs button.active {
  background: var(--panel-2);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}

.field {
  display: block;
  margin-bottom: 13px;
}

.field > span {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--muted);
}

.field input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--bg-elev);
  outline: 0;
  font-size: 14px;
  transition: border-color 0.16s, box-shadow 0.16s;
}

.field input:focus {
  border-color: rgba(255, 122, 47, 0.5);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field input::placeholder {
  color: var(--muted);
}

.form-error {
  margin: 0 0 11px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(255, 101, 104, 0.09);
  border: 1px solid rgba(255, 101, 104, 0.22);
  color: #ff9a9c;
  font-size: 12px;
  line-height: 1.5;
}

.primary-btn {
  width: 100%;
  height: 42px;
  border: 0;
  border-radius: 10px;
  background: linear-gradient(135deg, #ff9448, #ff6a00);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: filter 0.16s, transform 0.1s;
}

.primary-btn:hover {
  filter: brightness(1.06);
}

.primary-btn:active {
  transform: scale(0.99);
}

.primary-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.auth-foot {
  margin-top: 16px;
  text-align: center;
  font-size: 11.5px;
}

.auth-foot a {
  color: var(--muted);
  text-decoration: none;
}

.auth-foot a:hover {
  color: var(--accent-text);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(3px);
}

.modal {
  width: min(400px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--shadow);
  animation: fadeUp 0.22s ease both;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-head h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
}

.modal-head .icon-btn {
  font-size: 19px;
  line-height: 1;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.modal-actions .primary-btn {
  width: auto;
  height: 36px;
  padding: 0 18px;
  font-size: 13px;
}

.ghost-btn {
  height: 36px;
  padding: 0 15px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: transparent;
  color: var(--text-soft);
  font-size: 13px;
}

.ghost-btn:hover {
  background: var(--panel-2);
}

/* Toast */
.toast-root {
  position: fixed;
  left: 50%;
  bottom: 104px;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  max-width: min(440px, calc(100vw - 40px));
  padding: 9px 15px;
  border-radius: 9px;
  background: var(--panel-3);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 12.5px;
  line-height: 1.5;
  box-shadow: var(--shadow);
  animation: toastIn 0.2s ease both;
}

.toast.error {
  border-color: rgba(255, 101, 104, 0.35);
  color: #ffb3b4;
}

/* ------------------------------- 动画 ------------------------------- */

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(7px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(-4px) scale(0.99);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes blink {
  0%,
  49% {
    opacity: 1;
  }
  50%,
  100% {
    opacity: 0;
  }
}

@keyframes bounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.45;
  }
  30% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.4;
  }
  50% {
    opacity: 1;
  }
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .chat-scroll {
    scroll-behavior: auto;
  }
}

/* ------------------------------- 响应式 ------------------------------- */

@media (hover: none) {
  .msg-actions,
  .conv-actions {
    opacity: 1;
    display: flex;
  }
}

@media (max-width: 880px) {
  .field input,
  .composer textarea {
    font-size: 16px;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 282px;
    flex-basis: 282px;
    transform: translateX(-102%);
    transition: transform 0.24s ease;
    box-shadow: 18px 0 50px rgba(0, 0, 0, 0.28);
  }

  .app.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .app.collapsed .sidebar {
    width: 282px;
    flex-basis: 282px;
    padding-left: 10px;
    padding-right: 10px;
    border-right: 1px solid var(--border);
    overflow: hidden;
  }

  .app:not(.collapsed) .menu-btn,
  .app .menu-btn {
    display: inline-flex;
  }

  .app:not(.collapsed) .sidebar {
    transform: translateX(-102%);
  }

  .app.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .topbar {
    padding: 0 12px;
  }

  .topbar-right .usage-pill {
    display: none;
  }

  .thread {
    padding: 8px 16px 26px;
  }

  .composer-area {
    padding: 4px 12px calc(9px + env(safe-area-inset-bottom));
  }

  .composer-hint {
    display: none;
  }

  .auth-card {
    padding: 26px 22px 18px;
  }
}

@media (max-width: 560px) {
  .welcome {
    padding-top: clamp(26px, 7vh, 60px);
  }

  .welcome-logo {
    width: 54px;
    height: 54px;
    border-radius: 15px;
    margin-bottom: 17px;
  }

  .chips {
    grid-template-columns: 1fr;
    margin-top: 22px;
    gap: 7px;
  }

  .chip {
    padding: 10px 12px;
  }

  .messages {
    gap: 24px;
  }

  .msg.user .bubble {
    max-width: 88%;
  }

  .composer-foot {
    font-size: 10px;
  }

  .composer-foot span:last-child {
    display: none;
  }

  .model-btn {
    max-width: 180px;
  }

  .notice {
    margin: 0 12px 4px;
  }

  .toast-root {
    bottom: 92px;
  }
}
