:root {
  color-scheme: light;
  --bg: #ffffff;
  --bg-side: #f9fbff;
  --bg-elevated: #ffffff;
  --bg-soft: #f3f5f9;
  --bg-hover: #edf1f8;
  --bg-active: #e4ecff;
  --user-bubble: #eff4ff;
  --ink: #1f2329;
  --ink-secondary: #4e5969;
  --muted: #86909c;
  --border: #e5e8ef;
  --border-strong: #d0d7e5;
  --primary: #4d6bfe;
  --primary-hover: #3b58eb;
  --primary-soft: #eef2ff;
  --primary-border: #c7d4ff;
  --success: #00a870;
  --wechat: #07c160;
  --alipay: #1677ff;
  --danger: #e03e3e;
  --danger-soft: #fff1f0;
  --warn-bg: #fff9eb;
  --warn-ink: #946200;
  --code-bg: #f6f8fa;
  --code-head: #eef1f6;
  --shadow-sm: 0 2px 8px rgba(31, 35, 41, 0.05);
  --shadow-composer: 0 6px 24px rgba(77, 107, 254, 0.08), 0 2px 8px rgba(15, 23, 42, 0.04);
  --shadow-dialog: 0 20px 60px rgba(15, 23, 42, 0.18);
  --sans: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'HarmonyOS Sans SC', 'Noto Sans CJK SC',
    'Microsoft YaHei', system-ui, sans-serif;
  --mono: 'JetBrains Mono', 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
}

[data-theme='dark'] {
  color-scheme: dark;
  --bg: #15171c;
  --bg-side: #1b1e26;
  --bg-elevated: #212530;
  --bg-soft: #262b38;
  --bg-hover: #292f3d;
  --bg-active: #273357;
  --user-bubble: #263152;
  --ink: #eceff4;
  --ink-secondary: #b8c0cc;
  --muted: #7f8999;
  --border: #2c313f;
  --border-strong: #3a4154;
  --primary: #5e7aff;
  --primary-hover: #738cff;
  --primary-soft: #222c4d;
  --primary-border: #3c4f8a;
  --danger: #ff6b6b;
  --danger-soft: #3a2023;
  --warn-bg: #332a15;
  --warn-ink: #f3c669;
  --code-bg: #1c1f28;
  --code-head: #242936;
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.25);
  --shadow-composer: 0 8px 28px rgba(0, 0, 0, 0.35);
  --shadow-dialog: 0 24px 70px rgba(0, 0, 0, 0.55);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  max-width: 100%;
  overflow-x: clip;
  font: 15px/1.65 var(--sans);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}

button {
  border: 0;
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled {
  opacity: 0.52;
  cursor: not-allowed;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.skip {
  position: fixed;
  top: -100px;
  left: 12px;
  background: var(--primary);
  color: #fff;
  padding: 6px 12px;
  border-radius: 8px;
  z-index: 100;
}
.skip:focus {
  top: 8px;
}

.icon {
  width: 18px;
  height: 18px;
  flex: none;
  vertical-align: middle;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ds-logo {
  width: 32px;
  height: 32px;
  flex: none;
  display: block;
}

/* App Shell */
.ds-shell {
  display: grid;
  grid-template-columns: 268px minmax(0, 1fr);
  min-height: 100dvh;
  transition: grid-template-columns 0.2s ease;
}

@media (min-width: 821px) {
  .ds-shell.sidebar-collapsed {
    grid-template-columns: 0px minmax(0, 1fr);
  }

  .ds-shell.sidebar-collapsed .ds-sidebar {
    transform: translateX(-100%);
    border-right-color: transparent;
    pointer-events: none;
  }
}

/* Sidebar */
.ds-sidebar {
  position: sticky;
  top: 0;
  height: 100dvh;
  width: 268px;
  display: flex;
  flex-direction: column;
  background: var(--bg-side);
  border-right: 1px solid var(--border);
  padding: 14px 12px calc(12px + env(safe-area-inset-bottom, 0px));
  z-index: 20;
  overflow: hidden;
  transition: transform 0.22s ease;
}

.side-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 4px 12px;
}

.brand-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px;
  border-radius: 10px;
  text-align: left;
  min-width: 0;
}

.brand-text strong {
  display: block;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.25;
}

.brand-text small {
  display: block;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.2;
}

.side-cta {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.new-chat-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: 40px;
  border-radius: 12px;
  background: var(--primary);
  color: #ffffff;
  font-weight: 600;
  font-size: 14px;
  box-shadow: 0 3px 10px rgba(77, 107, 254, 0.25);
  transition: background 0.15s, transform 0.1s;
}
.new-chat-btn:hover {
  background: var(--primary-hover);
}

.migrate-cta-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  height: 36px;
  border-radius: 11px;
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px solid var(--primary-border);
  font-weight: 600;
  font-size: 13px;
  transition: background 0.15s;
}
.migrate-cta-btn:hover {
  background: var(--bg-active);
}

.side-search-wrap {
  margin-bottom: 8px;
}

.side-search {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 10px;
  color: var(--muted);
}

.side-search .icon {
  width: 15px;
  height: 15px;
}

.side-search input {
  border: 0;
  outline: 0;
  background: transparent;
  width: 100%;
  font-size: 13px;
  color: var(--ink);
}

/* Conversation History Groups */
.side-chats {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 2px;
  margin: 0 -2px;
}

.chat-group-label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  padding: 10px 10px 4px;
}

.side-item {
  display: flex;
  align-items: center;
  border-radius: 10px;
  margin-bottom: 2px;
  transition: background 0.12s;
}

.side-item:hover {
  background: var(--bg-hover);
}

.side-item.active {
  background: var(--bg-active);
}

.side-item-open {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8.5px 10px;
  text-align: left;
  font-size: 13.5px;
  color: var(--ink);
}

.side-item.active .side-item-open {
  color: var(--primary);
  font-weight: 600;
}

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

.side-pin-dot {
  color: var(--primary);
  display: inline-flex;
}
.side-pin-dot .icon {
  width: 13px;
  height: 13px;
}

.side-mem-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--primary);
  flex: none;
}

.side-item-more {
  width: 28px;
  height: 28px;
  margin-right: 4px;
  border-radius: 7px;
  color: var(--muted);
  display: grid;
  place-items: center;
  opacity: 0;
  transition: opacity 0.12s, background 0.12s;
}

.side-item:hover .side-item-more,
.side-item.active .side-item-more,
.side-item-more:focus-visible {
  opacity: 1;
}

@media (hover: none) {
  .side-item-more {
    opacity: 0.85;
  }
}

.side-item-more:hover {
  background: var(--bg-soft);
  color: var(--ink);
}

.side-empty {
  padding: 28px 14px;
  text-align: center;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.7;
}

/* Sidebar Footer */
.side-footer {
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  display: grid;
  gap: 6px;
}

.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 8px;
  border-radius: 10px;
  text-align: left;
}
.user-card:hover {
  background: var(--bg-hover);
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  display: inline-grid;
  place-items: center;
  font-weight: 700;
  font-size: 14px;
  flex: none;
}

.user-meta {
  flex: 1;
  min-width: 0;
}
.user-meta strong {
  display: block;
  font-size: 13.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-meta small {
  display: block;
  font-size: 11.5px;
  color: var(--muted);
}

.side-quick-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}

.quick-foot-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 4px;
  border-radius: 8px;
  font-size: 12px;
  color: var(--ink-secondary);
}
.quick-foot-btn:hover {
  background: var(--bg-hover);
  color: var(--ink);
}
.quick-foot-btn .icon {
  width: 15px;
  height: 15px;
}

/* Stage & Topbar */
.ds-stage {
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  background: var(--bg);
}

.ds-topbar {
  position: sticky;
  top: 0;
  z-index: 12;
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid transparent;
}

.ds-stage.has-messages .ds-topbar {
  border-bottom-color: var(--border);
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.nav-trigger {
  display: none;
}
.ds-shell.sidebar-collapsed .nav-trigger {
  display: inline-grid;
}

.top-title-btn {
  font-size: 15px;
  font-weight: 600;
  padding: 5px 8px;
  border-radius: 8px;
  max-width: min(46vw, 420px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.top-title-btn:hover {
  background: var(--bg-soft);
}

.memory-badge-btn,
.top-pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 500;
  background: var(--bg-soft);
  color: var(--ink-secondary);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.memory-badge-btn.active {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: var(--primary-border);
}
.memory-badge-btn .icon,
.top-pill-btn .icon {
  width: 14px;
  height: 14px;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  display: inline-grid;
  place-items: center;
  color: var(--ink-secondary);
  transition: background 0.12s, color 0.12s;
}
.icon-btn:hover {
  background: var(--bg-soft);
  color: var(--ink);
}

/* Main Workspace */
.ds-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.ds-workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  padding: 0 18px;
}

/* Centered DeepSeek Welcome State */
.ds-hero {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 28px 0 48px;
  gap: 22px;
}

.hero-brand {
  text-align: center;
  display: grid;
  justify-items: center;
  gap: 10px;
}

.hero-title-row {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

.hero-title-row .ds-logo {
  width: 40px;
  height: 40px;
}

.hero-title-row h1 {
  margin: 0;
  font-size: clamp(23px, 3vw, 29px);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.hero-sub {
  margin: 0;
  color: var(--ink-secondary);
  font-size: 14px;
  max-width: 540px;
  line-height: 1.6;
}

.hero-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.hero-card {
  text-align: left;
  padding: 14px 15px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-sm);
  display: grid;
  gap: 5px;
  transition: border-color 0.15s, transform 0.15s, background 0.15s;
}
.hero-card:hover {
  border-color: var(--primary-border);
  background: var(--bg-soft);
  transform: translateY(-1px);
}
.hero-card-head {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13.5px;
  font-weight: 650;
  color: var(--ink);
}
.hero-card-head .icon {
  color: var(--primary);
  width: 16px;
  height: 16px;
}
.hero-card p {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.55;
}

/* Conversation Thread */
.thread {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 20px 0 28px;
}

.thread-tools {
  display: flex;
  justify-content: center;
}

.msg {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* User Message Bubble (Right-aligned like DeepSeek Web & App) */
.msg.user {
  align-items: flex-end;
}

.msg.user .msg-bubble {
  background: var(--user-bubble);
  color: var(--ink);
  padding: 11px 16px;
  border-radius: 18px 18px 4px 18px;
  max-width: min(86%, 640px);
  font-size: 15px;
  line-height: 1.72;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* Assistant Message (Left-aligned with DeepSeek Avatar) */
.msg.assistant,
.msg.system {
  align-items: flex-start;
}

.msg-assistant-row {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  gap: 12px;
  width: 100%;
}

.msg-ds-avatar {
  padding-top: 2px;
}
.msg-ds-avatar .ds-logo {
  width: 28px;
  height: 28px;
}

.msg-main {
  min-width: 0;
}

/* DeepSeek Collapsible Reasoning Card */
.reason-card {
  margin: 0 0 12px;
  border-radius: 12px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  overflow: hidden;
}

.reason-card summary {
  list-style: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  padding: 8px 13px;
  font-size: 13px;
  font-weight: 550;
  color: var(--ink-secondary);
  user-select: none;
}
.reason-card summary::-webkit-details-marker {
  display: none;
}
.reason-card summary .icon {
  width: 15px;
  height: 15px;
  color: var(--primary);
}
.reason-body {
  padding: 0 14px 11px;
  border-left: 2px solid var(--border-strong);
  margin: 0 12px 10px;
  font-size: 13.5px;
  line-height: 1.72;
  color: var(--muted);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* Markdown Body */
.msg-markdown {
  font-size: 15.5px;
  line-height: 1.82;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.msg-markdown > * {
  margin: 0 0 0.78em;
}
.msg-markdown > :last-child {
  margin-bottom: 0;
}

.msg-markdown h2,
.msg-markdown h3,
.msg-markdown h4 {
  margin-top: 1.1em;
  margin-bottom: 0.45em;
  line-height: 1.4;
  font-weight: 700;
}
.msg-markdown h2 {
  font-size: 1.22em;
}
.msg-markdown h3 {
  font-size: 1.1em;
}
.msg-markdown h4 {
  font-size: 1.02em;
}

.msg-markdown ul,
.msg-markdown ol {
  padding-left: 1.5em;
}
.msg-markdown li {
  margin-bottom: 0.3em;
}

.msg-markdown blockquote {
  border-left: 3px solid var(--primary);
  background: var(--bg-soft);
  margin-left: 0;
  margin-right: 0;
  padding: 8px 14px;
  border-radius: 0 8px 8px 0;
  color: var(--ink-secondary);
}

.msg-markdown hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 1.2em 0;
}

.msg-markdown code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--code-bg);
  padding: 0.15em 0.38em;
  border-radius: 5px;
}

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

.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: var(--code-head);
  font-size: 12px;
  color: var(--muted);
}

.code-lang {
  font-family: var(--mono);
}

.code-copy {
  font-size: 12px;
  color: var(--ink-secondary);
  padding: 2px 7px;
  border-radius: 5px;
}
.code-copy:hover {
  background: var(--bg-hover);
  color: var(--primary);
}

.code-block pre {
  margin: 0;
  padding: 12px 14px;
  overflow-x: auto;
  font-size: 13.5px;
  line-height: 1.6;
}
.code-block pre code {
  background: transparent;
  padding: 0;
}

.md-table-wrap {
  overflow-x: auto;
}
.md-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.md-table th,
.md-table td {
  border: 1px solid var(--border);
  padding: 7px 10px;
  text-align: left;
}
.md-table th {
  background: var(--bg-soft);
}

/* Message Action Bar */
.msg-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
  opacity: 0.72;
  transition: opacity 0.15s;
}
.msg:hover .msg-actions {
  opacity: 1;
}

.act-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 7px;
  border-radius: 7px;
  font-size: 12px;
  color: var(--muted);
}
.act-btn:hover {
  background: var(--bg-soft);
  color: var(--ink);
}
.act-btn .icon {
  width: 14px;
  height: 14px;
}

.msg-meta-tag {
  font-size: 11.5px;
  color: var(--muted);
  margin-left: 4px;
}

/* Inline Edit Box */
.inline-edit-box {
  width: min(100%, 640px);
  background: var(--bg-elevated);
  border: 1.5px solid var(--primary);
  border-radius: 14px;
  padding: 10px 12px;
  display: grid;
  gap: 8px;
}
.inline-edit-box textarea {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  resize: vertical;
  min-height: 68px;
  font-size: 15px;
  line-height: 1.6;
}

/* Sources list */
.sources-box {
  margin-top: 10px;
  font-size: 12.5px;
}
.sources-box summary {
  cursor: pointer;
  color: var(--primary);
  font-weight: 500;
}
.sources-box ul {
  margin: 6px 0 0;
  padding-left: 18px;
}

/* DeepSeek Capsule Composer */
.composer-dock {
  position: sticky;
  bottom: 0;
  z-index: 10;
  background: linear-gradient(to top, var(--bg) 78%, transparent);
  padding: 8px 0 calc(12px + env(safe-area-inset-bottom, 0px));
}

.composer-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 22px;
  padding: 12px 14px 10px;
  box-shadow: var(--shadow-composer);
  transition: border-color 0.16s, box-shadow 0.16s;
}
.composer-card:focus-within {
  border-color: var(--primary);
}

.composer-card textarea {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  resize: none;
  min-height: 48px;
  max-height: 32dvh;
  padding: 2px 2px 6px;
  font-size: 16px; /* Prevents iOS Safari auto-zoom */
  line-height: 1.6;
}

.compose-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.compose-pills {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.ds-pill,
.ds-select {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 32px;
  padding: 0 11px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--ink-secondary);
  cursor: pointer;
  transition: all 0.14s;
}
.ds-pill:hover,
.ds-select:hover {
  background: var(--bg-hover);
  color: var(--ink);
}
.ds-pill.on {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: var(--primary-border);
  font-weight: 600;
}
.ds-pill .icon {
  width: 14px;
  height: 14px;
}

.send-circle {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: inline-grid;
  place-items: center;
  flex: none;
  box-shadow: 0 2px 8px rgba(77, 107, 254, 0.35);
  transition: background 0.15s, transform 0.1s;
}
.send-circle:hover:not(:disabled) {
  background: var(--primary-hover);
  transform: scale(1.03);
}
.send-circle .icon {
  width: 17px;
  height: 17px;
  stroke-width: 2.2;
}

.composer-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px 0;
  font-size: 11.5px;
  color: var(--muted);
}

/* Buttons & Forms */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  padding: 7px 15px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 600;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--ink);
  transition: background 0.14s, border-color 0.14s;
}
.btn:hover {
  background: var(--bg-soft);
}
.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn.primary:hover {
  background: var(--primary-hover);
}
.btn.small {
  min-height: 32px;
  padding: 4px 11px;
  font-size: 12.5px;
}
.btn.danger {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 35%, var(--border));
}
.btn.danger.primary {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.plain {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 500;
  padding: 2px 0;
}
.plain:hover {
  text-decoration: underline;
}
.plain .icon {
  width: 14px;
  height: 14px;
}

/* Dialog / Modals */
dialog {
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 32px);
  margin: auto;
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--bg-elevated);
  color: var(--ink);
  box-shadow: var(--shadow-dialog);
  overflow-y: auto;
}
dialog::backdrop {
  background: rgba(15, 23, 42, 0.48);
  backdrop-filter: blur(3px);
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.dialog-head h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
  flex-wrap: wrap;
}

.stack {
  display: grid;
  gap: 14px;
}

.row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.field {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
}

.field input:not([type='checkbox']):not([type='radio']),
.field textarea,
.field select,
.text-input {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 9px 12px;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  font-weight: 400;
}
.field textarea {
  resize: vertical;
  line-height: 1.65;
}
.field small,
.hint {
  margin: 0;
  font-size: 12.5px;
  font-weight: 400;
  color: var(--muted);
  line-height: 1.65;
}

.switcher {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 11px;
  background: var(--bg-soft);
}
.switcher button {
  flex: 1;
  padding: 7px 8px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--ink-secondary);
}
.switcher button.active {
  background: var(--bg-elevated);
  color: var(--primary);
  font-weight: 650;
  box-shadow: var(--shadow-sm);
}

.dropzone {
  display: grid;
  place-items: center;
  text-align: center;
  gap: 8px;
  padding: 24px 16px;
  border: 1.5px dashed var(--primary-border);
  border-radius: 14px;
  background: var(--primary-soft);
  cursor: pointer;
  transition: background 0.15s;
}
.dropzone.drag {
  background: var(--bg-active);
  border-color: var(--primary);
}
.dropzone strong {
  font-size: 14.5px;
  color: var(--primary);
}
.dropzone small {
  color: var(--ink-secondary);
  font-size: 12.5px;
}

.file-input {
  max-width: 100%;
  font-size: 12px;
}

.extractor-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  background: var(--bg-soft);
  display: grid;
  gap: 10px;
}
.extractor-steps {
  margin: 0;
  padding-left: 18px;
  font-size: 13px;
  line-height: 1.7;
  color: var(--ink-secondary);
}
.bookmarklet-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff !important;
  font-size: 12.5px;
  font-weight: 600;
  text-decoration: none !important;
}

.select-list {
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--bg);
}
.select-item + .select-item {
  border-top: 1px solid var(--border);
}
.select-line {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 10px 12px;
  cursor: pointer;
}
.select-line input {
  accent-color: var(--primary);
  margin-top: 3px;
}
.select-line strong {
  flex: 1;
  font-size: 13.5px;
  overflow-wrap: anywhere;
}
.select-line small {
  color: var(--muted);
  font-size: 12px;
}
.branch-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px 10px 34px;
  font-size: 12px;
  color: var(--muted);
}
.branch-row select {
  flex: 1;
  min-width: 0;
  padding: 4px 8px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
}

.check-box-card {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--primary-soft);
  border: 1px solid var(--primary-border);
  font-size: 13px;
  cursor: pointer;
}
.check-box-card input {
  accent-color: var(--primary);
  margin-top: 3px;
}

.warn-list {
  margin: 0;
  padding: 10px 14px 10px 28px;
  border-radius: 10px;
  background: var(--warn-bg);
  color: var(--warn-ink);
  font-size: 12px;
  max-height: 120px;
  overflow: auto;
}

.status,
.error {
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 13px;
  overflow-wrap: anywhere;
}
.status {
  background: var(--primary-soft);
  color: var(--primary);
}
.error {
  background: var(--danger-soft);
  color: var(--danger);
}
.status:empty,
.error:empty {
  display: none;
}

/* Wallet & Payment Cards */
.wallet-hero {
  background: linear-gradient(135deg, var(--primary-soft), var(--bg-soft));
  border: 1px solid var(--primary-border);
  border-radius: 14px;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.wallet-amount {
  font-size: 28px;
  font-weight: 750;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}
.amount-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.amt-pill {
  padding: 10px 6px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  text-align: center;
  font-weight: 650;
  font-size: 14px;
}
.amt-pill small {
  display: block;
  font-size: 10.5px;
  font-weight: 400;
  color: var(--muted);
}
.amt-pill.selected {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

.pay-channels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
}
.pay-chan-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  font-size: 13.5px;
  font-weight: 600;
  text-align: left;
}
.pay-chan-btn.selected {
  border-color: var(--primary);
  background: var(--primary-soft);
}
.pay-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
}
.pay-dot.wxpay {
  background: var(--wechat);
}
.pay-dot.alipay {
  background: var(--alipay);
}
.pay-dot.checkout {
  background: var(--primary);
}
.pay-badge {
  margin-left: auto;
  font-size: 10.5px;
  padding: 1px 6px;
  border-radius: 99px;
  background: var(--primary);
  color: #fff;
}

.cashier-box {
  border: 1.5px solid var(--primary-border);
  background: var(--bg-soft);
  border-radius: 16px;
  padding: 18px 16px;
  display: grid;
  justify-items: center;
  text-align: center;
  gap: 10px;
}
.cashier-price {
  font-size: 32px;
  font-weight: 800;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}
.cashier-qr-wrap {
  padding: 12px;
  background: #ffffff;
  border-radius: 14px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.cashier-qr-wrap img {
  display: block;
  width: min(220px, 62vw);
  height: min(220px, 62vw);
  object-fit: contain;
}
.import-filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.import-filter-bar input {
  flex: 1;
  min-width: 150px;
}

.wallet-section {
  border-top: 1px solid var(--border);
  padding-top: 13px;
  display: grid;
  gap: 9px;
}
.wallet-section h3 {
  margin: 0;
  font-size: 14px;
}

.price-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
.price-table th,
.price-table td {
  padding: 7px 4px;
  border-bottom: 1px solid var(--border);
  text-align: right;
}
.price-table th:first-child,
.price-table td:first-child {
  text-align: left;
}

.ledger-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
}
.ledger-line strong,
.ledger-line small {
  display: block;
}
.ledger-line small {
  color: var(--muted);
  font-size: 11px;
}
.ledger-line > span {
  white-space: nowrap;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.menu-list {
  display: grid;
  gap: 4px;
}
.menu-item-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  text-align: left;
}
.menu-item-btn:hover {
  background: var(--bg-soft);
}
.menu-item-btn.danger {
  color: var(--danger);
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 12px);
  z-index: 60;
  max-width: 90vw;
  padding: 9px 16px;
  border-radius: 999px;
  background: #1f2329;
  color: #ffffff;
  font-size: 13.5px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.22);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
}
[data-theme='dark'] .toast {
  background: #eceff4;
  color: #15171c;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.scrim {
  display: none;
}

.loader {
  padding: 64px 16px;
  text-align: center;
  color: var(--muted);
}

/* Mobile & Tablet Responsive Polish (DeepSeek App parity) */
@media (max-width: 820px) {
  .ds-shell,
  .ds-shell.sidebar-collapsed {
    display: block;
  }

  .ds-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(286px, 84vw);
    transform: translateX(-105%);
    box-shadow: none;
    pointer-events: auto !important;
  }

  body.drawer-open .ds-shell .ds-sidebar,
  body.drawer-open .ds-sidebar {
    transform: translateX(0);
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.18);
  }

  body.drawer-open .scrim {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(2px);
    z-index: 18;
  }

  .nav-trigger {
    display: inline-grid !important;
  }

  .side-collapse {
    display: none;
  }

  .ds-workspace {
    padding: 0 12px;
  }

  .hero-cards {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .ds-hero {
    padding: 18px 0 28px;
    gap: 16px;
  }

  .msg-assistant-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .msg-ds-avatar {
    display: inline-flex;
    align-items: center;
    gap: 7px;
  }
  .msg-ds-avatar::after {
    content: 'DeepSeek';
    font-size: 12.5px;
    font-weight: 600;
    color: var(--ink-secondary);
  }
  .msg-ds-avatar .ds-logo {
    width: 22px;
    height: 22px;
  }

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

  .composer-card {
    border-radius: 18px;
    padding: 10px 11px 9px;
  }

  .ds-pill,
  .ds-select {
    height: 30px;
    padding: 0 9px;
    font-size: 12px;
  }

  .amount-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  dialog {
    width: calc(100vw - 16px);
    padding: 18px 16px;
    border-radius: 16px;
  }
}

@media (max-width: 600px) {
  .composer-foot > span:last-child {
    display: none;
  }
}

@media (max-width: 480px) {
  .hide-xs {
    display: none;
  }
  .top-title-btn {
    max-width: 44vw;
  }
}
