:root {
  color-scheme: light;
  --ink: #202421;
  --muted: #717772;
  --line: #e5e8e5;
  --surface: #ffffff;
  --sidebar: #f5f6f4;
  --hover: #e9ebe8;
  --green: #1e6b48;
  --green-dark: #154f36;
  --green-soft: #e8f2ec;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; overflow: hidden; background: var(--surface); color: var(--ink); }
button, textarea { font: inherit; }
button { color: inherit; cursor: pointer; }

.workspace {
  height: 100dvh;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  background: var(--surface);
  transition: grid-template-columns .24s ease;
}
.workspace.sidebar-collapsed { grid-template-columns: 0 minmax(0, 1fr); }

.sidebar {
  width: 300px;
  min-width: 300px;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  overflow: hidden;
  transition: transform .24s ease, opacity .2s ease;
  z-index: 30;
}
.sidebar-collapsed .sidebar { transform: translateX(-100%); opacity: 0; pointer-events: none; }
.sidebar-head { min-height: 76px; padding: 15px 16px 10px; display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark, .welcome-mark { display: block; object-fit: cover; object-position: 50% 38%; background: var(--green-soft); }
.brand-mark { width: 38px; height: 38px; border-radius: 12px; }
.brand strong { display: block; font-size: 15px; }
.brand small { display: flex; align-items: center; gap: 5px; margin-top: 4px; color: var(--muted); font-size: 11px; }
.brand small i { width: 7px; height: 7px; border-radius: 50%; background: #d79a35; }
.brand small i.online { background: #3da86a; }
.brand small i.offline { background: #d76158; }
.brand small b { font-weight: 500; }

.new-chat-button {
  margin: 4px 12px 10px;
  padding: 11px 13px;
  border: 1px solid #d8dcd8;
  border-radius: 12px;
  background: #fff;
  text-align: left;
  font-weight: 650;
}
.new-chat-button span { margin-right: 8px; font-size: 19px; font-weight: 400; }
.new-chat-button:hover { background: #fafbfa; }

.sidebar-nav { display: grid; gap: 2px; padding: 0 10px 9px; border-bottom: 1px solid var(--line); }
.sidebar-nav button, .project-item, .history-item {
  width: 100%;
  border: 0;
  border-radius: 9px;
  background: transparent;
  text-align: left;
}
.sidebar-nav button { padding: 9px 10px; font-size: 14px; }
.sidebar-nav button span { display: inline-block; width: 24px; font-size: 17px; }
.sidebar-nav button:hover, .project-item:hover, .history-item:hover { background: var(--hover); }
.sidebar-scroll { min-height: 0; overflow-y: auto; padding: 12px 10px; scrollbar-width: thin; }
.sidebar-section + .sidebar-section { margin-top: 22px; }
.section-title { min-height: 28px; padding: 0 7px; display: flex; align-items: center; justify-content: space-between; color: #555b56; font-size: 12px; font-weight: 700; }
.section-title button { border: 0; background: transparent; color: #929792; font-size: 11px; }
.project-list, .history-list { display: grid; gap: 2px; }
.project-list.collapsed { display: none; }
.project-item, .history-item { display: grid; grid-template-columns: 23px minmax(0, 1fr); align-items: center; gap: 4px; padding: 9px 8px; font-size: 13px; }
.project-item.active, .history-item.active { background: #e3e6e2; font-weight: 650; }
.folder-icon { color: #555c57; }
.project-item span:last-child, .history-item span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-item { grid-template-columns: 18px minmax(0, 1fr); }
.history-item::before { content: "◷"; color: #777d78; font-size: 12px; }
.empty-history { margin: 8px; color: #9ba09b; font-size: 12px; }

.user-center {
  margin: 0;
  padding: 12px 14px max(13px, env(safe-area-inset-bottom));
  border: 0;
  border-top: 1px solid var(--line);
  background: var(--sidebar);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  text-align: left;
}
.user-center:hover { background: var(--hover); }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: #cf7d29; color: #fff; font-size: 12px; }
.user-center strong, .user-center small { display: block; }
.user-center strong { font-size: 13px; }
.user-center small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.more-dots { color: var(--muted); }

.chat-panel { position: relative; min-width: 0; height: 100dvh; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; background: #fff; }
.chat-header {
  min-height: 68px;
  padding: 10px 18px;
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  border-bottom: 1px solid rgba(229,232,229,.8);
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(14px);
  z-index: 5;
}
.round-button { width: 42px; height: 42px; border: 0; border-radius: 50%; background: #f5f6f4; font-size: 19px; }
.round-button:hover { background: #e9ebe8; }
.chat-title { justify-self: center; max-width: 65%; border: 0; background: transparent; text-align: center; }
.chat-title strong, .chat-title small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-title strong { font-size: 15px; }
.chat-title small { margin-top: 2px; color: var(--muted); font-size: 11px; font-weight: 400; }
.model-button { height: 36px; margin-right: 8px; padding: 0 10px; display: flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 10px; background: #f7f8f6; color: #434944; font-size: 12px; white-space: nowrap; }
.model-button:hover { background: #ecefeb; }
.model-menu { position: absolute; top: 59px; right: 64px; z-index: 50; width: 278px; padding: 8px; border: 1px solid var(--line); border-radius: 14px; background: #fff; box-shadow: 0 16px 45px rgba(23,34,27,.18); }
.model-menu-title { padding: 7px 9px 9px; color: #777d78; font-size: 11px; font-weight: 700; }
.model-option { width: 100%; min-height: 52px; padding: 8px 10px; display: grid; grid-template-columns: 1fr auto; align-items: center; border: 0; border-radius: 10px; background: transparent; text-align: left; }
.model-option:hover, .model-option.active { background: #f0f2ef; }
.model-option strong, .model-option small { display: block; }
.model-option strong { font-size: 13px; }
.model-option small { margin-top: 3px; color: #8b908c; font-size: 10px; }
.model-option .check { color: var(--green); font-size: 16px; }
.model-menu-foot { margin-top: 5px; padding: 9px; border-top: 1px solid var(--line); color: #999e9a; font-size: 10px; }

.chat-scroll { min-height: 0; overflow-y: auto; padding: 34px max(24px, calc((100% - 820px) / 2)) 42px; scroll-behavior: smooth; }
.welcome { min-height: 58vh; max-width: 720px; margin: 0 auto; display: grid; align-content: center; justify-items: center; text-align: center; }
.welcome-mark { width: 64px; height: 64px; border-radius: 20px; box-shadow: 0 10px 25px rgba(30,107,72,.18); }
.welcome h1 { margin: 18px 0 8px; font-size: clamp(25px, 4vw, 34px); letter-spacing: -.03em; }
.welcome p { max-width: 580px; margin: 0; color: var(--muted); font-size: 14px; line-height: 1.75; }
.quick-questions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 22px; }
.quick-questions button { padding: 10px 13px; border: 1px solid #dce1dc; border-radius: 999px; background: #fafbfa; color: #4a514c; font-size: 13px; }
.quick-questions button:hover { border-color: #abc6b5; background: var(--green-soft); }
.messages { display: grid; gap: 24px; max-width: 820px; margin: 0 auto; }
.message { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 11px; align-items: start; }
.message.user { grid-template-columns: minmax(0, 1fr); justify-items: end; }
.message-avatar { width: 32px; height: 32px; border-radius: 10px; display: block; object-fit: cover; object-position: 50% 38%; background: var(--green-soft); }
.message-label { margin-bottom: 6px; color: #686f69; font-size: 11px; font-weight: 650; }
.bubble { line-height: 1.72; font-size: 15px; white-space: pre-wrap; word-break: break-word; }
.message.user .bubble { max-width: min(78%, 620px); padding: 11px 15px; border-radius: 17px 5px 17px 17px; background: #eef1ee; }
.bubble.loading { color: var(--muted); }
.answer-meta { grid-column: 2; margin-top: -16px; color: #929892; font-size: 10px; }
.answer-actions { grid-column: 2; display: flex; align-items: center; gap: 3px; margin-top: -3px; }
.answer-action { width: 31px; height: 31px; display: grid; place-items: center; border: 0; border-radius: 8px; background: transparent; color: #737a75; }
.answer-action:hover { background: #f0f2ef; color: #26382d; }
.answer-action.active { background: var(--green-soft); color: var(--green); }
.answer-action.done { color: var(--green); }
.answer-action svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.support-qr { display: block; width: 150px; height: 150px; margin-top: 10px; border-radius: 10px; object-fit: contain; border: 1px solid var(--line); }

.composer { padding: 10px max(18px, calc((100% - 820px) / 2)) max(10px, env(safe-area-inset-bottom)); background: linear-gradient(transparent, #fff 18%); }
.composer form { max-width: 820px; min-height: 58px; margin: 0 auto; padding: 7px 8px; display: grid; grid-template-columns: auto 1fr auto; align-items: end; gap: 7px; border: 1px solid #dde1dd; border-radius: 22px; background: #fff; box-shadow: 0 6px 25px rgba(25,39,30,.08); }
.composer textarea { width: 100%; max-height: 130px; min-height: 42px; padding: 10px 4px; resize: none; border: 0; outline: 0; line-height: 1.5; background: transparent; }
.attach-button, #sendButton { width: 42px; height: 42px; border: 0; border-radius: 50%; }
.attach-button { background: transparent; font-size: 27px; font-weight: 300; opacity: .7; }
#sendButton { background: var(--green); color: #fff; font-size: 20px; font-weight: 800; }
#sendButton:disabled { opacity: .4; cursor: not-allowed; }
.composer > p { margin: 6px 0 0; color: #9a9f9a; text-align: center; font-size: 10px; }
.pending-assets { max-width: 820px; margin: 6px auto 0; padding: 7px 12px; border-radius: 9px; background: #eef6f1; color: #356047; font-size: 12px; overflow-wrap: anywhere; }

.sidebar-backdrop { display: none; }
.mobile-only { display: none; }
.user-popover { position: fixed; left: 14px; bottom: 74px; z-index: 80; width: 270px; padding: 16px; border: 1px solid var(--line); border-radius: 14px; background: #fff; box-shadow: 0 16px 45px rgba(20,35,26,.18); }
.user-popover strong, .user-popover span { display: block; }
.user-popover span { margin: 5px 0 13px; color: var(--muted); font-size: 12px; }
.user-popover button { width: 100%; padding: 8px; border: 0; border-radius: 8px; background: var(--sidebar); }
.user-popover label { display: block; margin: 9px 0; color: var(--muted); font-size: 11px; }
.user-popover input { width: 100%; margin-top: 4px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; outline: 0; }
.user-popover .primary { margin-top: 7px; background: var(--green); color: #fff; }
.captcha-row { display: grid; grid-template-columns: 1fr 92px; gap: 7px; align-items: end; }
.captcha-row button { margin-bottom: 9px; }
.auth-error { min-height: 16px; margin: 6px 0; color: #b23b30; font-size: 11px; }
#accountList { display: grid; gap: 6px; margin: 9px 0 12px; }
#accountList button { text-align: left; border: 1px solid transparent; }
#accountList button.active { border-color: var(--green); background: var(--green-soft); }
.selected-account-hint { margin: 8px 0; padding: 8px 10px; border-radius: 8px; background: var(--green-soft); color: var(--green); font-size: 11px; }
#confirmAccountButton:disabled { opacity: .45; }

@media (max-width: 760px) {
  .workspace, .workspace.sidebar-collapsed { display: block; }
  .chat-panel { width: 100%; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(88vw, 370px);
    min-width: 0;
    transform: translateX(-103%);
    opacity: 1;
    box-shadow: 18px 0 45px rgba(19,35,25,.15);
  }
  .workspace.mobile-sidebar-open .sidebar { transform: translateX(0); pointer-events: auto; }
  .workspace.mobile-sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 20; background: rgba(24,31,27,.23); backdrop-filter: blur(2px); }
  .mobile-only { display: block; }
  .chat-header { min-height: 66px; padding: 9px 14px; }
  .chat-title { max-width: 74%; padding: 8px 16px; border-radius: 22px; background: #f7f8f6; }
  .model-button { max-width: 112px; margin-right: 5px; padding: 0 7px; overflow: hidden; }
  .model-button span:first-child { overflow: hidden; text-overflow: ellipsis; }
  .model-menu { top: 61px; right: 12px; width: min(278px, calc(100vw - 24px)); }
  .chat-scroll { padding: 22px 14px 34px; }
  .welcome { min-height: 59vh; padding: 0 10px; }
  .welcome h1 { font-size: 25px; }
  .quick-questions { display: grid; width: 100%; }
  .quick-questions button { text-align: left; border-radius: 13px; }
  .messages { gap: 21px; }
  .message { grid-template-columns: 30px minmax(0,1fr); gap: 9px; }
  .message-avatar { width: 29px; height: 29px; border-radius: 9px; }
  .message.user .bubble { max-width: 88%; }
  .composer { padding: 8px 12px max(9px, env(safe-area-inset-bottom)); }
  .composer form { min-height: 56px; border-radius: 22px; }
  .composer > p { display: none; }
  .user-popover { left: 12px; bottom: 76px; width: calc(min(88vw, 370px) - 24px); }
}
