:root {
  --font-sans: "Inter", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-serif: "Copernicus", "Times New Roman", serif;
  --font-mono: "JetBrains Mono", "Cascadia Code", "SFMono-Regular", Consolas, monospace;

  --bg-primary: #f7f5f1;
  --bg-secondary: #f1ede5;
  --bg-tertiary: #ebe4d8;
  --bg-elevated: #fffdfa;
  --bg-user-msg: #efe7d8;

  --text-primary: #24201a;
  --text-secondary: #5f5648;
  --text-tertiary: #8a7f6d;

  --border-subtle: #ece4d8;
  --border-default: #ddd2c2;
  --border-strong: #c9baa4;

  --claude-orange: #d27a4a;
  --claude-orange-hover: #be6637;
  --claude-orange-light: rgba(210, 122, 74, 0.18);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 22px;

  --shadow-sm: 0 2px 10px rgba(36, 32, 26, 0.06);
  --shadow-md: 0 10px 24px rgba(36, 32, 26, 0.1);
  --shadow-lg: 0 18px 40px rgba(36, 32, 26, 0.14);

  --sidebar-width: 286px;
  --content-max-width: 860px;

  --code-bg: #fbfaf7;
  --code-toolbar-bg: rgba(247, 244, 238, 0.94);
  --code-border: #e6ded1;
  --code-text: #27231c;
  --code-toolbar-text: #6a6155;
  --code-copy-bg: #ffffff;
  --code-copy-border: #ddd4c8;
  --code-copy-hover: #f3eee6;
  --code-scrollbar: #cfc4b2;
}

[data-theme="dark"] {
  --bg-primary: #181613;
  --bg-secondary: #23201c;
  --bg-tertiary: #2d2824;
  --bg-elevated: #211e1b;
  --bg-user-msg: #312920;

  --text-primary: #ebe5d8;
  --text-secondary: #aba291;
  --text-tertiary: #7f7668;

  --border-subtle: #2d2924;
  --border-default: #3c3731;
  --border-strong: #544d43;

  --claude-orange: #e08a5a;
  --claude-orange-hover: #ec9b6c;
  --claude-orange-light: rgba(224, 138, 90, 0.22);

  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.26);
  --shadow-md: 0 10px 24px rgba(0, 0, 0, 0.34);
  --shadow-lg: 0 18px 40px rgba(0, 0, 0, 0.46);

  --code-bg: #10100f;
  --code-toolbar-bg: rgba(18, 18, 18, 0.95);
  --code-border: #2a2825;
  --code-text: #ece7dc;
  --code-toolbar-text: #b1a999;
  --code-copy-bg: #1c1b19;
  --code-copy-border: #34312d;
  --code-copy-hover: #262420;
  --code-scrollbar: #4a453f;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
}

html {
  transition: background-color 0.25s ease;
}

body {
  font-family: var(--font-sans);
  background:
    radial-gradient(circle at 2% -10%, #fffaf2 0%, transparent 40%),
    radial-gradient(circle at 110% 110%, #efe3ce 0%, transparent 36%),
    var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
}

body.modal-open {
  touch-action: none;
}

[data-theme="dark"] body {
  background:
    radial-gradient(circle at 2% -10%, #28231d 0%, transparent 40%),
    radial-gradient(circle at 110% 110%, #2b241e 0%, transparent 36%),
    var(--bg-primary);
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  background: none;
  cursor: pointer;
}

input,
textarea {
  outline: none;
}

.hidden {
  display: none !important;
}

/* layout */

.app-shell {
  display: flex;
  width: 100%;
  height: 100%;
}

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #f4efe5 0%, #f0e9de 100%);
  border-right: 1px solid var(--border-default);
  overflow: hidden;
  transition: width 0.25s ease, transform 0.22s ease;
}

[data-theme="dark"] .sidebar {
  background: linear-gradient(180deg, #1d1a17 0%, #191714 100%);
}

.sidebar-header {
  padding: 10px 12px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-toggle-btn {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.sidebar-toggle-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.brand {
  display: flex;
  align-items: center;
}

.brand-logo {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(145deg, #2a251e 0%, #433b30 100%);
  color: #fff7ea;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
}

[data-theme="dark"] .brand-logo {
  background: linear-gradient(145deg, #39332c 0%, #4a4238 100%);
}

.new-chat-btn {
  margin: 8px 12px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  background: var(--bg-elevated);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 500;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
}

.new-chat-btn:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}

.new-chat-btn:active {
  transform: scale(0.99);
}

.sidebar-section {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 12px 12px;
}

.sidebar-section-title {
  padding: 8px 12px 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.chat-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-list-row {
  position: relative;
  display: flex;
  align-items: center;
  border-radius: 10px;
  transition: background-color 0.15s ease;
}

.chat-list-row:hover,
.chat-list-row.active {
  background: var(--bg-tertiary);
}

.chat-list-row.active::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 18px;
  background: var(--claude-orange);
  border-radius: 0 3px 3px 0;
}

.chat-list-item {
  width: 100%;
  flex: 1;
  min-width: 0;
  text-align: left;
  padding: 9px 10px;
  border-radius: 10px;
  color: var(--text-secondary);
}

.chat-item-main {
  min-width: 0;
}

.chat-item-title {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.35;
}

.chat-item-title-text {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-pin {
  font-size: 10px;
  color: var(--claude-orange);
  flex-shrink: 0;
}

.chat-item-time {
  margin-top: 2px;
  font-size: 11px;
  color: var(--text-tertiary);
}

.chat-actions {
  position: relative;
  flex-shrink: 0;
  padding-right: 4px;
}

.chat-actions-btn {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  color: var(--text-tertiary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: background 0.15s ease, color 0.15s ease, opacity 0.15s ease;
}

.chat-list-row:hover .chat-actions-btn,
.chat-list-row.active .chat-actions-btn,
.chat-actions:hover .chat-actions-btn {
  opacity: 1;
  pointer-events: auto;
}

.chat-actions-btn:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.chat-actions-menu {
  position: absolute;
  top: 32px;
  right: 0;
  min-width: 160px;
  padding: 4px;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  background: var(--bg-elevated);
  box-shadow: var(--shadow-md);
  z-index: 30;
  animation: menuIn 0.12s ease-out;
}

.chat-actions-menu button {
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border-radius: 7px;
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
}

.chat-actions-menu button:hover {
  background: var(--bg-secondary);
}

.chat-actions-menu button.danger {
  color: #c55454;
}

.chat-actions-menu button.danger:hover {
  background: rgba(197, 84, 84, 0.08);
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border-subtle);
}

.user-card {
  width: 100%;
  padding: 8px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
}

.user-card:hover {
  background: var(--bg-tertiary);
}

.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--claude-orange);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.user-info {
  flex: 1;
  min-width: 0;
  text-align: left;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.user-plan {
  font-size: 11px;
  color: var(--text-tertiary);
}

.main-panel {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  position: relative;
}

.topbar {
  height: 56px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(247, 245, 241, 0.82);
  backdrop-filter: blur(6px);
  flex-shrink: 0;
}

[data-theme="dark"] .topbar {
  background: rgba(24, 22, 19, 0.82);
}

.topbar-model {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-title {
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 500;
}

.model-badge {
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-default);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

#theme-toggle-btn {
  position: relative;
  overflow: hidden;
}

#theme-toggle-btn svg {
  position: absolute;
  top: 50%;
  left: 50%;
  transition: transform 0.4s ease, opacity 0.25s ease;
}

#theme-icon-sun {
  transform: translate(-50%, -50%) rotate(0deg) scale(1);
  opacity: 1;
  color: #d9a066;
}

#theme-icon-moon {
  transform: translate(-50%, -50%) rotate(-90deg) scale(0);
  opacity: 0;
  color: #a8b3d1;
}

[data-theme="dark"] #theme-icon-sun {
  transform: translate(-50%, -50%) rotate(90deg) scale(0);
  opacity: 0;
}

[data-theme="dark"] #theme-icon-moon {
  transform: translate(-50%, -50%) rotate(0deg) scale(1);
  opacity: 1;
}

.mobile-only {
  display: none;
}

/* messages */

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 26px 20px 40px;
  scroll-behavior: smooth;
}

.message-row {
  max-width: var(--content-max-width);
  margin: 0 auto 22px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  animation: fadeIn 0.22s ease;
}

.message-row.user {
  justify-content: flex-end;
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}

.avatar.user {
  display: none;
}

.avatar.assistant {
  background: linear-gradient(145deg, var(--claude-orange) 0%, #bb6435 100%);
  color: #fff;
  box-shadow: 0 4px 12px rgba(210, 122, 74, 0.22);
}

/* 限制消息卡内容宽度并自动换行 */
.message-card {
  word-break: break-word;      /* 长词强制换行 */
  overflow-wrap: break-word;   /* 避免文字溢出 */
  white-space: pre-wrap;       /* 保留原始换行，同时自动换行 */
}

.message-card.assistant {
  flex: 1;
  padding: 2px 0;
}

.message-card.user {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  background: var(--bg-user-msg);
}

.message-role {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-bottom: 6px;
}

.message-card.user .message-role {
  display: none;
}

.message-content {
  word-break: break-word;
}

.message-meta {
  margin-top: 10px;
  font-size: 11px;
  color: var(--text-tertiary);
  letter-spacing: 0.02em;
}

/* welcome */

.welcome-state {
  position: absolute;
  inset: 56px 0 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  pointer-events: none;
}

.welcome-card {
  width: 100%;
  max-width: 680px;
  text-align: center;
  pointer-events: auto;
}

.welcome-logo {
  color: var(--claude-orange);
  margin-bottom: 20px;
  display: flex;
  justify-content: center;
}

.welcome-card h1 {
  margin: 0 0 8px;
  font-family: var(--font-serif);
  font-size: 38px;
  font-weight: 500;
}

.welcome-wave {
  display: inline-block;
  margin-left: 8px;
}

.welcome-subtitle {
  margin: 0 0 32px;
  font-size: 16px;
  color: var(--text-secondary);
}

.suggestions {
  max-width: 600px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.suggestion-chip {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  color: var(--text-primary);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  font-size: 14px;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.suggestion-chip:hover {
  border-color: var(--border-default);
  background: var(--bg-secondary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.chip-icon {
  font-size: 16px;
  flex-shrink: 0;
}

/* composer */

.composer-wrap {
  padding: 0 20px 20px;
  background: linear-gradient(to bottom, transparent, var(--bg-primary) 30%);
  flex-shrink: 0;
}

.composer-card {
  max-width: var(--content-max-width);
  margin: 0 auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  padding: 12px 14px 10px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.composer-card:focus-within {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}

.composer-card.blocked,
.composer-card.blocked textarea,
.composer-card.blocked button {
  opacity: 0.65;
}

.composer-card.blocked textarea,
.composer-card.blocked button {
  pointer-events: none;
}

#message-input {
  width: 100%;
  border: none;
  resize: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.6;
  max-height: 240px;
  padding: 4px 4px 8px;
}

#message-input::placeholder {
  color: var(--text-tertiary);
}

.composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.composer-left,
.composer-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.composer-tool-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.composer-tool-btn:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.composer-hint {
  font-size: 12px;
  color: var(--text-tertiary);
}

.send-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  background: var(--claude-orange);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, transform 0.1s ease;
}

.send-btn:hover {
  background: var(--claude-orange-hover);
}

.send-btn:active {
  transform: scale(0.95);
}

.send-btn:disabled {
  background: var(--border-default);
  cursor: not-allowed;
}

.send-btn[data-mode="stop"] {
  background: var(--text-primary);
}

.send-btn[data-mode="stop"] svg {
  display: none;
}

.send-btn[data-mode="stop"]::after {
  content: "";
  width: 10px;
  height: 10px;
  background: #fff;
  border-radius: 2px;
  display: block;
}

.composer-footer {
  max-width: var(--content-max-width);
  margin: 8px auto 0;
  text-align: center;
  font-size: 11px;
  color: var(--text-tertiary);
}

/* markdown */

.markdown-body {
  word-break: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
  max-width: 100%;             /* 避免撑出消息卡 */
}

.markdown-body > *:first-child {
  margin-top: 0;
}

.markdown-body > *:last-child {
  margin-bottom: 0;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  font-family: var(--font-sans);
  line-height: 1.28;
  letter-spacing: -0.01em;
  margin: 1.05em 0 0.45em;
  color: var(--text-primary);
}

.markdown-body h1 {
  font-size: 2em;
  font-weight: 700;
}

.markdown-body h2 {
  font-size: 1.52em;
  font-weight: 700;
}

.markdown-body h3 {
  font-size: 1.2em;
  font-weight: 700;
}

.markdown-body h4 {
  font-size: 1em;
  font-weight: 700;
}

.markdown-body p {
  margin: 0 0 10px;
}

.markdown-body ul,
.markdown-body ol {
  margin: 0 0 12px;
  padding-left: 24px;
}

.markdown-body li {
  margin: 4px 0;
}

.markdown-body li > p {
  margin: 2px 0;
}

.markdown-body strong {
  font-weight: 650;
}

.markdown-body em {
  font-style: italic;
}

.markdown-body hr {
  border: 0;
  border-top: 1px solid var(--border-subtle);
  margin: 18px 0;
}

.markdown-body blockquote {
  margin: 12px 0;
  padding: 2px 0 2px 14px;
  border-left: 3px solid var(--border-strong);
  color: var(--text-secondary);
}

.markdown-body a {
  color: #a54f22;
  text-decoration: none;
}

.markdown-body a:hover {
  text-decoration: underline;
}

[data-theme="dark"] .markdown-body a {
  color: #e8a070;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 14px;
  border: 1px solid var(--border-default);
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg-elevated);
  box-shadow: 0 1px 4px rgba(36, 32, 26, 0.04);
}

.markdown-body th,
.markdown-body td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-subtle);
  text-align: left;
  vertical-align: top;
}

.markdown-body th {
  background: var(--bg-secondary);
  font-weight: 600;
}

.markdown-body tr:last-child td {
  border-bottom: none;
}

.markdown-body :not(pre) > code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  padding: 2px 6px;
  border-radius: 6px;
}

/* code block - clean version */

.markdown-body .code-block,
.code-block {
  position: relative;
  min-width: 0;
  max-width: 100%;
  margin: 10px 0 14px;
  border: 1px solid var(--code-border);
  border-radius: 14px;
  overflow: hidden;
  background: var(--code-bg);
  box-shadow: none;
}

.markdown-body .code-block-toolbar,
.code-block-toolbar {
  position: sticky;
  top: 0;
  z-index: 3;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 10px;
  background: var(--code-toolbar-bg);
  border-bottom: 1px solid var(--code-border);
  backdrop-filter: blur(8px);
}

.markdown-body .code-block-lang,
.code-block-lang {
  display: inline-flex;
  align-items: center;
  color: var(--code-toolbar-text);
  font-size: 11px;
  font-weight: 600;
  text-transform: lowercase;
  letter-spacing: 0.01em;
}

.markdown-body .code-copy-btn,
.code-copy-btn {
  position: static;
  height: 26px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--code-copy-border);
  background: var(--code-copy-bg);
  color: var(--code-toolbar-text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  box-shadow: none;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.08s ease;
}

.markdown-body .code-copy-btn:hover,
.code-copy-btn:hover {
  background: var(--code-copy-hover);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.markdown-body .code-copy-btn:active,
.code-copy-btn:active {
  transform: scale(0.98);
}

.markdown-body .code-copy-btn span,
.code-copy-btn span {
  pointer-events: none;
}

.markdown-body .code-block pre,
.code-block pre {
  margin: 0;
  max-width: 100%;
  padding: 10px 12px 12px;
  overflow-x: auto;
  overflow-y: hidden;
  background: var(--code-bg);
  color: var(--code-text);
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.55;
  white-space: pre;
  word-break: normal;
  overflow-wrap: normal;
  border-radius: 0;
  box-shadow: none;
}

.markdown-body .code-block pre code,
.code-block pre code {
  display: block;
  width: max-content;
  min-width: 100%;
  background: transparent !important;
  padding: 0 !important;
  border: 0 !important;
  font-size: inherit;
  color: inherit;
  white-space: inherit;
  word-break: normal;
  overflow-wrap: normal;
}

.markdown-body .code-block pre::-webkit-scrollbar,
.code-block pre::-webkit-scrollbar {
  height: 9px;
  width: 9px;
}

.markdown-body .code-block pre::-webkit-scrollbar-track,
.code-block pre::-webkit-scrollbar-track {
  background: transparent;
}

.markdown-body .code-block pre::-webkit-scrollbar-thumb,
.code-block pre::-webkit-scrollbar-thumb {
  background: var(--code-scrollbar);
  border-radius: 999px;
}

.markdown-body .code-block pre::-webkit-scrollbar-thumb:hover,
.code-block pre::-webkit-scrollbar-thumb:hover {
  filter: brightness(0.94);
}

.markdown-body pre code.hljs {
  background: transparent !important;
}

.hljs {
  background: transparent !important;
}

[data-theme="dark"] .hljs {
  color: #ece7dc !important;
}

[data-theme="dark"] .hljs-keyword,
[data-theme="dark"] .hljs-selector-tag,
[data-theme="dark"] .hljs-built_in {
  color: #e08a5a !important;
}

[data-theme="dark"] .hljs-string,
[data-theme="dark"] .hljs-attr {
  color: #a8c978 !important;
}

[data-theme="dark"] .hljs-number,
[data-theme="dark"] .hljs-literal {
  color: #d9a066 !important;
}

[data-theme="dark"] .hljs-comment,
[data-theme="dark"] .hljs-quote {
  color: #7a7365 !important;
  font-style: italic;
}

[data-theme="dark"] .hljs-function,
[data-theme="dark"] .hljs-title {
  color: #7ab8d6 !important;
}

[data-theme="dark"] .hljs-variable,
[data-theme="dark"] .hljs-name {
  color: #ece7dc !important;
}

[data-theme="dark"] .hljs-tag,
[data-theme="dark"] .hljs-meta {
  color: #c792ea !important;
}

.streaming-cursor {
  display: inline-block;
  margin-left: 2px;
  color: var(--claude-orange);
  font-weight: 600;
  animation: streaming-blink 0.9s steps(2, start) infinite;
}

/* dialogs / drawer / search / gate */

.drawer {
  position: fixed;
  inset: 0;
  z-index: 100;
}

.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(60, 54, 35, 0.4);
  backdrop-filter: blur(4px);
  animation: fadeIn 0.2s ease;
}

[data-theme="dark"] .drawer-backdrop {
  background: rgba(0, 0, 0, 0.58);
}

.drawer-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 580px;
  max-width: 95vw;
  background: var(--bg-elevated);
  border-left: 1px solid var(--border-default);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: slideIn 0.24s ease;
}

.drawer-header {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 22px 28px 18px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
}

.drawer-title {
  font-family: var(--font-serif);
  font-size: 21px;
  font-weight: 600;
}

.drawer-subtitle {
  margin-top: 4px;
  font-size: 13px;
  color: var(--text-secondary);
}

.account-summary-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 20px 28px 0;
}

.account-summary-pill {
  background: var(--bg-secondary);
  border: 1px solid var(--border-default);
  color: var(--text-primary);
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.28);
}

.account-info {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 20px 28px 28px;
  overflow-y: auto;
}

.account-panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: 20px;
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.account-panel-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: 16px;
}

.account-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.account-overview-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 92px;
  padding: 14px 16px;
  border-radius: 16px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-secondary);
}

.account-row-label {
  color: var(--text-tertiary);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.account-row-value {
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.6;
  font-weight: 600;
  word-break: break-word;
}

.window-breakdown {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.window-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-default);
  border-radius: 18px;
  padding: 16px;
}

.window-card h4 {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 700;
}

.window-metric {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin: 0;
  padding: 10px 0;
}

.window-metric + .window-metric {
  border-top: 1px solid var(--border-subtle);
}

.window-metric-name {
  color: var(--text-secondary);
  font-size: 13px;
}

.window-value {
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 600;
  text-align: right;
}

.account-empty-state {
  padding: 18px;
  border: 1px dashed var(--border-default);
  border-radius: 16px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.6;
}

.action-dialog {
  position: fixed;
  inset: 0;
  z-index: 120;
}

.action-dialog-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(40, 32, 21, 0.38);
  backdrop-filter: blur(2px);
  animation: fadeIn 0.18s ease;
}

[data-theme="dark"] .action-dialog-backdrop {
  background: rgba(0, 0, 0, 0.58);
}

.action-dialog-panel {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(460px, calc(100vw - 28px));
  padding: 18px;
  border: 1px solid var(--border-default);
  border-radius: 16px;
  background: var(--bg-elevated);
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.18s ease;
}

.action-dialog-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

.action-dialog-subtitle {
  margin-top: 6px;
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.5;
}

.action-dialog-input {
  margin-top: 14px;
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 14px;
}

.action-dialog-input:focus {
  border-color: var(--claude-orange);
  box-shadow: 0 0 0 3px var(--claude-orange-light);
}

.action-dialog-actions {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.action-secondary-btn {
  padding: 10px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
}

.action-secondary-btn:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.send-btn-primary {
  padding: 10px 20px;
  border-radius: var(--radius-md);
  background: var(--claude-orange);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
}

.send-btn-primary:hover {
  background: var(--claude-orange-hover);
}

.send-btn-danger {
  padding: 10px 16px;
  border-radius: var(--radius-md);
  background: #b64b4b;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
}

.send-btn-danger:hover {
  background: #9f3d3d;
}

.user-card-menu-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(34, 28, 20, 0.2);
  backdrop-filter: blur(2px);
  z-index: 214;
}

[data-theme="dark"] .user-card-menu-backdrop {
  background: rgba(0, 0, 0, 0.28);
}

.user-card-menu {
  position: fixed;
  left: 18px;
  bottom: 96px;
  min-width: 260px;
  max-width: min(320px, calc(100vw - 24px));
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 8px;
  z-index: 220;
}

.user-card-menu-header {
  padding: 8px 10px 10px;
}

.user-card-menu-handle {
  display: none;
  width: 42px;
  height: 4px;
  border-radius: 999px;
  background: var(--border-strong);
  margin: 0 auto 12px;
}

.user-card-menu-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
}

.user-card-menu-subtitle {
  margin-top: 4px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-secondary);
}

.user-card-menu-btn {
  width: 100%;
  text-align: left;
  padding: 11px 12px;
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-weight: 500;
}

.user-card-menu-btn:hover {
  background: var(--bg-secondary);
}

.user-card-menu-btn.danger {
  color: #b03b2f;
}

.key-gate {
  position: fixed;
  inset: 0;
  z-index: 260;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.key-gate.hidden {
  display: none !important;
}

.key-gate-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(245, 239, 230, 0.72);
  backdrop-filter: blur(10px);
}

[data-theme="dark"] .key-gate-backdrop {
  background: rgba(15, 15, 18, 0.72);
}

.key-gate-card {
  position: relative;
  width: min(460px, 100%);
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
  padding: 28px;
}

.key-gate-logo {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: linear-gradient(145deg, #2a251e 0%, #433b30 100%);
  color: #fff7ea;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
}

.key-gate-card h2 {
  margin: 0 0 8px;
  font-size: 28px;
  font-family: var(--font-serif);
}

.key-gate-note {
  margin: 0 0 18px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-full {
  width: 100%;
}

.field span {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.field input,
.field textarea {
  padding: 10px 12px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 14px;
}

.field input:focus,
.field textarea:focus {
  border-color: var(--claude-orange);
  box-shadow: 0 0 0 3px var(--claude-orange-light);
}

.key-gate-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
}

.key-gate-actions .send-btn-primary,
.key-gate-actions .action-secondary-btn {
  min-width: 140px;
}

.key-gate-status,
.key-gate-error {
  margin-top: 14px;
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-size: 14px;
}

.key-gate-status {
  background: rgba(48, 117, 71, 0.12);
  color: #235437;
  border: 1px solid rgba(48, 117, 71, 0.18);
}

.key-gate-error {
  background: rgba(176, 59, 47, 0.08);
  color: #8d2b21;
  border: 1px solid rgba(176, 59, 47, 0.12);
}

[data-theme="dark"] .key-gate-status {
  background: rgba(94, 175, 121, 0.12);
  color: #9ce1b1;
  border-color: rgba(94, 175, 121, 0.22);
}

[data-theme="dark"] .key-gate-error {
  background: rgba(255, 113, 113, 0.12);
  color: #ffb3b3;
  border-color: rgba(255, 113, 113, 0.18);
}

.search-modal {
  position: fixed;
  inset: 0;
  z-index: 240;
}

.search-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(40, 32, 21, 0.28);
  backdrop-filter: blur(4px);
}

.search-modal-panel {
  position: absolute;
  top: 14vh;
  left: 50%;
  transform: translateX(-50%);
  width: min(720px, calc(100vw - 24px));
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.search-modal-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.search-modal-icon {
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.search-modal-input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 15px;
}

.search-modal-esc {
  border: 1px solid var(--border-default);
  border-radius: 7px;
  padding: 3px 7px;
  font-size: 11px;
  color: var(--text-tertiary);
  background: var(--bg-secondary);
}

.search-modal-body {
  max-height: 56vh;
  overflow-y: auto;
}

.search-modal-empty {
  padding: 34px 18px;
  color: var(--text-tertiary);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.search-modal-results {
  display: flex;
  flex-direction: column;
}

.search-result-item {
  width: 100%;
  border-bottom: 1px solid var(--border-subtle);
  background: transparent;
  text-align: left;
  padding: 14px 16px;
  display: block;
}

.search-result-item:hover,
.search-result-item.active {
  background: var(--bg-secondary);
}

.search-result-item:last-child {
  border-bottom: 0;
}

.search-result-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.search-result-snippet {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 6px;
}

.search-result-meta {
  font-size: 12px;
  color: var(--text-tertiary);
}

.search-result-item mark {
  background: rgba(210, 122, 74, 0.18);
  color: inherit;
  padding: 0 2px;
  border-radius: 4px;
}

.search-modal-footer {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-top: 1px solid var(--border-subtle);
  color: var(--text-tertiary);
  font-size: 12px;
}

.search-shortcut-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.search-shortcut-group kbd {
  border: 1px solid var(--border-default);
  border-radius: 7px;
  background: var(--bg-secondary);
  padding: 3px 7px;
  font-size: 11px;
}

/* toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  padding: 10px 18px;
  border-radius: var(--radius-md);
  background: var(--text-primary);
  color: var(--bg-primary);
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  z-index: 300;
  animation: fadeIn 0.2s ease;
}

[data-theme="dark"] .toast {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
}

/* sidebar collapsed */

.sidebar.collapsed {
  width: 56px;
  min-width: 56px;
  padding-left: 8px;
  padding-right: 8px;
}

.sidebar.collapsed .brand,
.sidebar.collapsed #new-chat-btn span,
.sidebar.collapsed .sidebar-section,
.sidebar.collapsed .sidebar-footer {
  display: none;
}

.sidebar.collapsed .sidebar-header {
  justify-content: center;
}

.sidebar.collapsed #new-chat-btn {
  width: 36px;
  height: 36px;
  margin: 8px auto;
  padding: 0;
  justify-content: center;
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}

.sidebar.collapsed #new-chat-btn:hover {
  background: var(--bg-tertiary);
}

.sidebar.collapsed #new-chat-btn svg {
  width: 18px;
  height: 18px;
}



/* 强制代码块和长行自动换行 */
.message-content pre,
.markdown-body pre {
  white-space: pre-wrap;       /* 自动换行，保留原始换行 */
  word-break: break-word;      /* 长词强制换行 */
  overflow-wrap: break-word;   /* 避免溢出 */
  max-width: 100%;             /* 不超出容器 */
}

.code-block pre {
  white-space: pre-wrap !important;
  word-break: break-word !important;
  overflow-wrap: break-word !important;
  max-width: 100%;
}
/* scrollbars */

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: 10px;
  border: 2px solid var(--bg-primary);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-strong);
}

/* animation */

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes menuIn {
  from {
    opacity: 0;
    transform: translateY(-4px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
  }
  to {
    transform: translateX(0);
  }
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: translate(-50%, calc(-50% + 8px));
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%);
  }
}

@keyframes streaming-blink {
  0%,
  49% {
    opacity: 1;
  }
  50%,
  100% {
    opacity: 0;
  }
}

/* responsive */

@media (max-width: 980px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 50;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .mobile-only {
    display: inline-flex;
  }

  .welcome-card h1 {
    font-size: 33px;
  }

  .suggestions {
    grid-template-columns: 1fr;
  }

  .window-breakdown {
    grid-template-columns: 1fr;
  }

  .account-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .topbar {
    padding: 0 12px;
  }

  .messages {
    padding: 16px 10px 24px;
  }

  .message-card.user {
    max-width: 92%;
  }

  .composer-wrap {
    padding: 0 10px 12px;
  }

  .composer-hint {
    display: none;
  }

  .drawer-panel {
    top: auto;
    width: 100%;
    max-width: 100%;
    max-height: 92vh;
    border-left: 0;
    border-top: 1px solid var(--border-default);
    border-radius: 18px 18px 0 0;
    animation: slideUp 0.22s ease;
  }

  .drawer-header {
    padding: 18px 18px 14px;
  }

  .account-summary-strip {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    margin: 18px 18px 0;
  }

  .account-summary-pill {
    padding: 12px 14px;
    border-radius: 16px;
  }

  .account-info {
    gap: 20px;
    margin-left: 18px;
    margin-right: 18px;
    padding: 20px 0 30px;
  }

  .account-panel {
    padding: 18px;
    border-radius: 18px;
  }

  .account-panel-title {
    margin-bottom: 16px;
  }

  .account-grid {
    gap: 12px;
  }

  .account-overview-item {
    min-height: 0;
    padding: 16px;
  }

  .account-row-label {
    margin-bottom: 0;
  }

  .account-row-value {
    font-size: 15px;
    line-height: 1.6;
  }

  .window-card {
    padding: 16px;
  }

  .window-card h4 {
    margin-bottom: 12px;
  }

  .window-metric {
    margin: 10px 0;
  }

  .action-dialog-panel {
    width: calc(100vw - 20px);
    padding: 14px;
  }

  .key-gate-card {
    padding: 22px 18px;
  }

  .key-gate-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .user-card-menu {
    left: 12px;
    right: 12px;
    bottom: 12px;
    top: auto !important;
    min-width: 0;
    max-width: none;
    border-radius: 20px;
    padding: 10px;
  }

  .user-card-menu-handle {
    display: block;
  }

  .markdown-body .code-block-toolbar,
  .code-block-toolbar {
    height: 36px;
    padding: 0 10px;
  }

  .markdown-body .code-block pre,
  .code-block pre {
    padding: 13px 13px 14px;
    font-size: 12px;
  }

  .markdown-body .code-copy-btn,
  .code-copy-btn {
    height: 24px;
    padding: 0 8px;
    font-size: 10.5px;
  }

  .markdown-body .code-block-lang,
  .code-block-lang {
    font-size: 10.5px;
  }
}

.suggestions.hidden {
  display: none !important;
}


@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}


