* {
  -webkit-tap-highlight-color: transparent;
}

button:focus:not(:focus-visible),
a:focus:not(:focus-visible),
summary:focus:not(:focus-visible),
label:focus:not(:focus-visible) {
  outline: none;
}

:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f4f4f6;
  --sidebar-bg: #f9fafb;
  --sidebar-text: #111827;
  --sidebar-muted: #6b7280;
  --sidebar-hover: #eef2f6;
  --sidebar-active: #e0e7ff;
  --sidebar-border: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #4d6bfe;
  --primary-hover: #3b5bdb;
  --primary-soft: #eef2ff;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --success: #16a34a;
  --success-soft: #f0fdf4;
  --warning: #d97706;
  --warning-soft: #fffbeb;
  --user-bubble: #eff6ff;
  --user-bubble-text: #111827;
  --code-bg: #1e293b;
  --code-text: #f8fafc;
  --shadow: 0 8px 28px rgba(15, 23, 42, 0.08);
}

body.dark {
  --bg: #0f1117;
  --surface: #161922;
  --surface-2: #1f2430;
  --sidebar-bg: #12141c;
  --sidebar-text: #f3f4f6;
  --sidebar-muted: #9ca3af;
  --sidebar-hover: rgba(255, 255, 255, 0.06);
  --sidebar-active: rgba(77, 107, 254, 0.24);
  --sidebar-border: #1f2430;
  --text: #f3f4f6;
  --muted: #9ca3af;
  --border: #252a36;
  --primary-soft: rgba(77, 107, 254, 0.18);
  --danger-soft: rgba(220, 38, 38, 0.16);
  --success-soft: rgba(22, 163, 74, 0.16);
  --warning-soft: rgba(217, 119, 6, 0.16);
  --user-bubble: #1e293b;
  --user-bubble-text: #f3f4f6;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.startup-status {
  padding: 24px;
  text-align: center;
}

.startup-status p {
  color: var(--muted);
}

.startup-status a {
  display: inline-block;
  text-decoration: none;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.danger-text {
  color: var(--danger) !important;
}

.success-text {
  color: var(--success) !important;
}

/* WeChat Banner */
.wechat-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 2000;
  background: #fef3c7;
  color: #92400e;
  border-bottom: 1px solid #fcd34d;
  padding: 10px 14px;
  font-size: 13px;
}

.wechat-banner-inner {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

/* Buttons & Inputs */
button {
  font-family: inherit;
  cursor: pointer;
}

input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(77, 107, 254, 0.15);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  transition: background 0.15s, opacity 0.15s;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
}

.btn-secondary:hover {
  border-color: var(--primary);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
}

.btn-ghost-sm {
  background: transparent;
  border: 1px solid currentColor;
  color: inherit;
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 12px;
  white-space: nowrap;
}

.btn-lg {
  padding: 11px 18px;
  font-size: 15px;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
  border-radius: 7px;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text);
  border-radius: 10px;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.icon-btn:hover {
  background: var(--surface-2);
}

.link-btn {
  background: none;
  border: none;
  padding: 0;
  color: var(--muted);
  font-size: 12px;
  text-decoration: none;
}

.link-btn:hover {
  color: var(--primary);
}

/* Auth / Setup Shells */
.center-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--bg);
}

.spinner {
  width: 30px;
  height: 30px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
}

.setup-card {
  max-width: 540px;
}

.brand-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}

.brand-head-center {
  flex-direction: column;
  text-align: center;
  gap: 8px;
}

.brand-head h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
}

.brand-head p {
  margin: 2px 0 0;
}

.brand-logo-svg {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  flex-shrink: 0;
}

.stack-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field > span {
  font-size: 13px;
  font-weight: 600;
}

.field-hint {
  font-size: 12px;
  min-height: 16px;
}

.input-with-btn {
  display: flex;
  gap: 8px;
}

.input-with-btn input {
  flex: 1;
  min-width: 0;
}

.advanced-fold {
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
}

.advanced-fold summary {
  cursor: pointer;
  font-weight: 500;
  color: var(--muted);
}

.seg-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--surface-2);
  padding: 4px;
  border-radius: 12px;
  margin-bottom: 16px;
}

.seg-tab {
  border: none;
  background: transparent;
  padding: 8px;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}

.seg-tab.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.info-callout {
  margin-top: 14px;
  background: var(--primary-soft);
  border: 1px solid rgba(77, 107, 254, 0.2);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 13px;
}

.info-callout p {
  margin: 0;
}

.auth-actions-foot {
  margin-top: 14px;
  text-align: center;
}

.compliance-line {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  font-size: 11px;
  color: var(--muted);
}

/* Main Workspace */
.workspace {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
}

.sidebar {
  width: 268px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--sidebar-border);
  z-index: 40;
}

.sidebar-top {
  padding: 14px 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 4px;
}

.mini-logo-svg {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  flex-shrink: 0;
}

.brand-title {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.new-chat-pill {
  width: 100%;
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px solid rgba(77, 107, 254, 0.22);
  border-radius: 12px;
  padding: 9px 12px;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  transition: background 0.15s;
}

.new-chat-pill:hover {
  background: rgba(77, 107, 254, 0.16);
}

.search-box input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 10px;
  font-size: 13px;
  border-radius: 10px;
}

.conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.conv-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 9px 10px;
  border-radius: 10px;
  cursor: pointer;
  color: var(--sidebar-text);
  transition: background 0.12s;
}

.conv-item:hover {
  background: var(--sidebar-hover);
}

.conv-item.active {
  background: var(--sidebar-active);
  color: var(--primary);
  font-weight: 600;
}

.conv-title-wrap {
  min-width: 0;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
}

.conv-title {
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.conv-item:hover .conv-actions,
.conv-item.active .conv-actions {
  opacity: 1;
}

.conv-act-btn {
  background: none;
  border: none;
  color: var(--sidebar-muted);
  padding: 2px 5px;
  font-size: 12px;
  border-radius: 5px;
}

.conv-act-btn:hover {
  background: rgba(0, 0, 0, 0.08);
  color: var(--text);
}

/* Sidebar Bottom User Menu (Balance hidden inside menu) */
.sidebar-bottom {
  padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--sidebar-border);
}

.user-menu-fold {
  position: relative;
}

.user-menu-trigger {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 12px;
  cursor: pointer;
  user-select: none;
}

.user-menu-trigger::-webkit-details-marker {
  display: none;
}

.user-menu-trigger:hover {
  background: var(--sidebar-hover);
}

.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-meta-col {
  flex: 1;
  min-width: 0;
}

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

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

.user-chevron {
  color: var(--sidebar-muted);
  font-size: 16px;
}

.user-menu-panel {
  margin-top: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  box-shadow: var(--shadow);
}

.menu-list-item {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: left;
}

.menu-list-item:hover {
  background: var(--surface-2);
}

.menu-sub-val {
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
}

.menu-list-item.admin-item {
  color: #d97706;
  font-weight: 600;
}

/* Chat Stage */
.chat-stage {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--bg);
}

.chat-header {
  height: 52px;
  flex-shrink: 0;
  padding-inline: max(12px, env(safe-area-inset-left)) max(12px, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
}

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

.model-dropdown {
  --model-picker-text-size: 15px;
  position: relative;
}

.model-picker-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 6px 10px;
  font-size: var(--model-picker-text-size);
  font-weight: 600;
  border-radius: 10px;
  white-space: nowrap;
}

.model-picker-btn:hover {
  background: var(--surface-2);
}

.model-picker-btn:disabled {
  opacity: 1;
  cursor: default;
}

.model-picker-btn:disabled svg {
  display: none;
}

button.attach-menu-item {
  border: 0;
  background: transparent;
  color: inherit;
  width: 100%;
  text-align: left;
}

.model-picker-menu {
  position: absolute;
  top: calc(100% + 3px);
  left: 0;
  width: max-content;
  min-width: 168px;
  max-width: min(250px, calc(100vw - 64px));
  max-height: 60vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  box-shadow: var(--shadow);
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.model-option-item {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 4px 8px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
  font-size: var(--model-picker-text-size);
  line-height: 1.2;
}

.model-option-item:hover {
  background: var(--surface-2);
}

.model-option-item.active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}

.model-option-preview {
  color: var(--muted);
}

.model-option-sub {
  font-size: 11px;
  color: var(--muted);
  font-weight: 400;
}

.model-option-meta {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.model-option-original-rate {
  color: var(--muted);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.model-option-rate {
  font-size: 12px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  padding: 2px 5px;
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--text);
}

.model-option-rate.less {
  color: var(--success);
}

.model-option-rate.more {
  color: var(--warning);
}

.model-rate-basis {
  padding: 4px 6px 1px;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

#disclaimer-bar .disclaimer-hide-btn {
  font-size: 11px;
  padding: 3px 8px;
  border-color: var(--border);
  color: var(--muted);
}

.announcement-bar {
  background: var(--primary-soft);
  color: var(--primary);
  padding: 6px 14px;
  font-size: 13px;
  text-align: center;
}

.messages-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 8px;
  display: flex;
  flex-direction: column;
}

.empty-state {
  margin: auto;
  text-align: center;
  padding: 20px 12px;
}

.empty-logo-svg {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  margin-bottom: 10px;
}

.empty-state h2 {
  margin: 0;
  font-size: 19px;
  font-weight: 500;
  letter-spacing: 0.1px;
  color: var(--text);
}

.messages-list {
  width: 100%;
  max-width: 780px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.load-earlier-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 2px 0 4px;
}

.load-earlier-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
  line-height: 1;
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.load-earlier-btn:hover:not(:disabled) {
  background: var(--surface-hover, rgba(127, 127, 127, 0.08));
  border-color: var(--primary);
}

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

.load-earlier-hint {
  font-size: 11px;
  color: var(--muted);
}

.msg-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.msg-row.user {
  align-items: flex-end;
}

.msg-row.assistant {
  align-items: flex-start;
}

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

.msg-media {
  display: block;
  width: 100%;
  max-width: 360px;
  border-radius: 12px;
  margin-bottom: 8px;
  background: #000;
}

.msg-media[src=""] {
  display: none;
}

.msg-row.user .msg-bubble {
  background: var(--user-bubble);
  color: var(--user-bubble-text);
  border-radius: 18px;
  border-bottom-right-radius: 6px;
  padding: 10px 15px;
  white-space: pre-wrap;
}

.msg-row.assistant .msg-bubble {
  background: transparent;
  padding: 2px 0;
  width: 100%;
  max-width: 100%;
}

.thinking-box {
  background: transparent;
  border: none;
  padding: 0;
  margin: 0 0 12px 0;
  font-size: 13px;
}

.thinking-box summary {
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 400;
  color: var(--muted);
  user-select: none;
  padding: 2px 0;
}

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

.thinking-chevron {
  transition: transform 0.18s ease;
  flex-shrink: 0;
}

.thinking-box[open] .thinking-chevron {
  transform: rotate(180deg);
}

.thinking-body {
  position: relative;
  margin-top: 8px;
  margin-left: 4px;
  padding-left: 14px;
  border-left: 1.5px solid var(--border);
  color: var(--muted);
  font-size: 13px;
  white-space: pre-wrap;
  line-height: 1.65;
}

.thinking-body::before {
  content: '';
  position: absolute;
  left: -3.5px;
  top: 7px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--muted);
  opacity: 0.65;
}

.thinking-status {
  font-size: 13px;
}

.msg-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
}

.copy-icon-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 4px 6px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0.72;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}

.copy-icon-btn:hover {
  opacity: 1;
  background: var(--surface-2);
  color: var(--primary);
}

/* Markdown Styling */
.md-body p:first-child { margin-top: 0; }
.md-body p:last-child { margin-bottom: 0; }
.md-body h1, .md-body h2, .md-body h3, .md-body h4 {
  margin: 14px 0 8px;
  line-height: 1.35;
}
.md-body ul, .md-body ol {
  padding-left: 20px;
  margin: 8px 0;
}
.md-body blockquote {
  margin: 8px 0;
  padding: 6px 12px;
  border-left: 3px solid var(--primary);
  background: var(--surface-2);
  border-radius: 6px;
}
.md-body code.inline-code {
  background: var(--surface-2);
  padding: 2px 5px;
  border-radius: 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
}
.code-block-wrap {
  margin: 10px 0;
  border-radius: 12px;
  overflow: hidden;
  background: var(--code-bg);
  color: var(--code-text);
}
.code-block-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 12px;
  color: #94a3b8;
}
.copy-code-btn {
  background: rgba(255, 255, 255, 0.12);
  color: #e2e8f0;
  border: none;
  border-radius: 5px;
  padding: 3px 8px;
  font-size: 11px;
}
.code-block-wrap pre {
  margin: 0;
  padding: 12px;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.5;
}
.md-body table {
  border-collapse: collapse;
  width: 100%;
  margin: 10px 0;
  font-size: 13px;
}
.md-body th, .md-body td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}
.md-body th {
  background: var(--surface-2);
}

@media (max-width: 768px) {
  .md-table-scroll {
    max-width: 100%;
    overflow-x: auto;
    margin: 10px 0;
  }

  .md-table-scroll table {
    margin: 0;
  }

  .md-table-scroll th,
  .md-table-scroll td {
    padding: 5px 8px;
    white-space: nowrap;
  }

  .md-table-scroll .md-table-long {
    min-width: 150px;
    max-width: 240px;
    white-space: normal;
    overflow-wrap: anywhere;
  }
}

/* Official-style Pill Composer */
.composer-area {
  flex-shrink: 0;
  padding: 8px 14px calc(10px + env(safe-area-inset-bottom));
  background: var(--bg);
}

.composer-box {
  max-width: 780px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 12px 14px 10px;
  box-shadow: 0 2px 14px rgba(15, 23, 42, 0.06);
}

.composer-box textarea {
  width: 100%;
  border: none;
  padding: 4px 2px;
  resize: none;
  max-height: 160px;
  font-size: 15px;
  background: transparent;
  box-shadow: none !important;
}

@media (pointer: coarse) {
  .chat-stage #chat-input:focus {
    font-size: 16px;
  }

  .workspace.chat-keyboard-open {
    position: fixed;
    top: var(--chat-viewport-top, 0px);
    right: 0;
    left: 0;
    height: var(--chat-viewport-height);
  }

  .chat-stage .composer-area {
    padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
  }

  .chat-stage .composer-box {
    padding: 11px 12px 8px;
    min-height: 98px;
  }

  .chat-stage #chat-input {
    display: block;
    margin: 0;
    min-height: 42px;
    font-size: 16px;
  }

  .chat-stage .composer-area > .compliance-line,
  .chat-keyboard-open .composer-area > :is(.context-hint, .context-reminder) {
    display: none;
  }

  .chat-keyboard-open .composer-area {
    padding-bottom: 10px;
  }
}

.composer-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 6px;
  gap: 8px;
}

.composer-tools-left, .composer-tools-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pill-toggle {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 13px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.pill-toggle.active {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
  font-weight: 600;
}

.tool-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  font-size: 18px;
  font-weight: 500;
  border-radius: 50%;
  background: transparent;
  border: 1.5px solid var(--text);
  color: var(--text);
  opacity: 0.78;
  cursor: pointer;
}

.send-circle-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.send-circle-btn:hover {
  background: var(--primary-hover);
}

.send-circle-btn.stop-circle {
  background: var(--danger);
  font-size: 12px;
}

.hidden-input {
  display: none;
}

.attached-files-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
}

.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 8px;
}

.file-chip button {
  background: none;
  border: none;
  color: inherit;
  padding: 0;
  font-weight: 700;
}

/* Modals */
.modal-root {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(15, 23, 42, 0.55);
}

.modal-panel {
  position: relative;
  width: 100%;
  max-width: 820px;
  max-height: 90%;
  max-height: 90dvh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  flex: none;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  margin: 0;
  font-size: 17px;
}

.modal-body {
  min-height: 0;
  padding: 18px;
  overflow-y: auto;
}

/* Admin & Tables */
.admin-modal:not(.admin-chat-fullscreen) > .modal-panel {
  max-width: 1440px;
  height: min(92dvh, 1080px);
  max-height: none;
}

.admin-modal:not(.admin-chat-fullscreen) .modal-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  padding: 0;
}

.admin-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  padding: 12px clamp(16px, 2vw, 28px);
}

#admin-tab-content {
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 18px clamp(16px, 2vw, 28px) 26px;
}

.admin-tab {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 600;
}

.admin-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

@media (max-width: 600px) {
  .admin-modal:not(.admin-chat-fullscreen) {
    padding: 0;
  }

  .admin-modal:not(.admin-chat-fullscreen) > .modal-panel {
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
    border: 0;
  }

  .admin-tabs {
    gap: 5px;
    padding: 8px 10px;
  }

  .admin-tab {
    padding: 6px 8px;
  }

  #admin-tab-content {
    padding: 12px 12px max(18px, env(safe-area-inset-bottom));
  }
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.wallet-kpi-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 4px;
}

.wallet-kpi-grid .kpi-card {
  padding: 8px 11px;
  border-radius: 11px;
  min-width: 0;
}

#wallet-free-quota {
  grid-column: 1 / -1;
  order: 1;
}

.wallet-quota-heading,
.wallet-quota-row {
  display: grid;
  align-items: center;
  gap: 6px;
}

.wallet-quota-heading {
  grid-template-columns: minmax(0, 1fr) auto;
  margin-bottom: 3px;
}

.wallet-quota-row {
  grid-template-columns: minmax(0, 1fr) auto auto 4ch;
  border-top: 1px solid var(--border);
  padding-block: 5px;
  font-size: 13px;
}

.wallet-quota-model {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wallet-vip {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
}

.wallet-vip strong {
  padding: 2px 6px;
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 11px;
}

.wallet-quota-row > :is(.model-option-rate, strong) {
  white-space: nowrap;
  text-align: right;
}

.wallet-quota-row .model-option-rate {
  justify-self: end;
}

.wallet-quota-row > small {
  text-align: right;
  white-space: nowrap;
}

.wallet-quota-hint {
  display: block;
  padding-top: 3px;
}

.wallet-ledger-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 4px 10px;
  align-items: start;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}

.wallet-ledger-entry {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 2px 8px;
  min-width: 0;
  overflow-wrap: anywhere;
}

.wallet-ledger-entry time {
  width: 100%;
  font-size: 12px;
}

.wallet-ledger-model {
  min-width: 0;
  color: var(--muted);
}

.wallet-ledger-amount {
  display: grid;
  text-align: right;
  gap: 2px;
  font-variant-numeric: tabular-nums;
}

.wallet-ledger-note {
  grid-column: 3;
  font-size: 12px;
}

.wallet-ledger-note[open] {
  grid-column: 1 / -1;
}

.wallet-ledger-note summary {
  cursor: pointer;
  color: var(--muted);
  padding: 2px 0;
}

.wallet-history-usage {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.wallet-history-model-toggle,
.wallet-history-model-list button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  min-height: 32px;
  padding: 4px 9px;
  border: 0;
  border-radius: 7px;
  font: inherit;
  font-size: 12px;
  color: var(--text);
}

.wallet-history-model-toggle {
  max-width: 57%;
  background: var(--surface-2);
}

.wallet-history-model-toggle span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wallet-history-model-toggle svg {
  flex: none;
}

.wallet-history-model-toggle[aria-expanded="true"] svg {
  transform: rotate(180deg);
}

.wallet-history-model-list {
  width: min(100%, 248px);
  max-height: 184px;
  margin: 4px 0 6px auto;
  padding: 3px;
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
}

.wallet-history-model-list button {
  width: 100%;
  background: transparent;
  text-align: left;
  overflow-wrap: anywhere;
}

.wallet-history-model-list button[aria-pressed="true"],
.wallet-history-model-list button:hover {
  background: var(--surface);
}

.wallet-history-model-list button[aria-pressed="false"] > :last-child {
  visibility: hidden;
}

.wallet-usage-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 8px 0 5px;
}

.wallet-usage-grid dt {
  color: var(--muted);
  font-size: 11px;
}

.wallet-usage-grid dd {
  margin: 2px 0 0;
  font-size: 12px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.wallet-ledger-note p {
  margin: 3px 0 0;
  overflow-wrap: anywhere;
}

.model-info-title {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px;
}

.wallet-quota-row strong {
  font-variant-numeric: tabular-nums;
}

.wallet-kpi-grid .kpi-value {
  overflow-wrap: anywhere;
}

.wallet-kpi-grid .wallet-wechat-id {
  font-size: 16px;
}

.wallet-kpi-grid #copy-wallet-wechat {
  margin-top: 4px;
}

.wallet-kpi-totals {
  display: grid;
  gap: 6px;
}

.wallet-details-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px 12px;
}

.wallet-details-heading h4 {
  margin: 0;
}

.kpi-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}

.kpi-label {
  font-size: 12px;
  color: var(--muted);
}

.kpi-value {
  font-size: 20px;
  font-weight: 700;
  margin-top: 4px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table.data-table th, table.data-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

table.data-table th {
  background: var(--surface-2);
  font-weight: 600;
}

.tag {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}

.tag-ok { background: var(--success-soft); color: var(--success); }
.tag-bad { background: var(--danger-soft); color: var(--danger); }
.tag-warn { background: var(--warning-soft); color: var(--warning); }
.tag-info { background: var(--primary-soft); color: var(--primary); }

.notice-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  white-space: pre-wrap;
  font-size: 13px;
  line-height: 1.65;
}

.drop-zone {
  border: 2px dashed var(--primary);
  border-radius: 12px;
  padding: 24px 16px;
  text-align: center;
  background: var(--primary-soft);
  cursor: pointer;
}

.toast-root {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: #111827;
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: var(--shadow);
  max-width: 340px;
}

.toast.error {
  background: var(--danger);
}

.toast.success {
  background: var(--success);
}

/* Responsive Mobile Drawer */
.mobile-only {
  display: none;
}

@media (max-width: 1024px) {
  .mobile-only {
    display: inline-flex;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    width: 82%;
    max-width: 300px;
  }

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

  .sidebar-backdrop {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 35;
  }

  .form-row-2 {
    grid-template-columns: 1fr;
  }

  .model-select {
    max-width: 185px;
    font-size: 14px;
  }

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

  .modal-root {
    align-items: flex-end;
    padding: 0;
  }

  .modal-panel {
    border-radius: 22px 22px 0 0;
    max-height: 88%;
    max-height: 88dvh;
    border-bottom: none;
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* Upload menu & image attachments */
.attach-menu-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.attach-menu {
  position: absolute;
  bottom: calc(100% + 10px);
  right: 0;
  min-width: 168px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.14);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 60;
}

.attach-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s ease;
}

.attach-menu-item:hover {
  background: var(--surface-2);
}

.attach-menu-item svg {
  color: var(--muted);
  flex-shrink: 0;
}

.img-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.img-chip img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  display: block;
}

.img-chip button {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: none;
  background: rgba(15, 23, 42, 0.72);
  color: #fff;
  font-size: 12px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}

.msg-images {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
}

.msg-img-thumb {
  max-width: 160px;
  max-height: 160px;
  border-radius: 10px;
  object-fit: cover;
  display: block;
}

/* Dedicated Full-Page Account & Settings View */
.account-page-view {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 48;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.account-page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.account-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  padding: 6px 8px;
  border-radius: 10px;
  cursor: pointer;
}

.account-back-btn:hover {
  background: var(--surface-2);
}

.account-page-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.account-page-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px calc(32px + env(safe-area-inset-bottom));
}

.account-page-container {
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.account-profile-top {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 4px;
}

.user-avatar.account-avatar {
  width: 28px;
  height: 28px;
  font-size: 12px;
  flex-shrink: 0;
}

.account-profile-name {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.account-points-pill {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 2px 6px;
  min-height: 44px;
  max-width: 78%;
  background: var(--primary-soft);
  color: var(--primary);
  border: 0;
  padding: 4px 9px;
  border-radius: 14px;
  flex-shrink: 0;
}

button.account-points-pill {
  cursor: pointer;
}

button.account-points-pill:is(:hover, :focus-visible) .account-points-hint {
  text-decoration: underline;
}

.account-points-label,
.account-points-hint {
  font-size: 12px;
}

.account-points-pill strong {
  font-size: 14px;
  font-weight: 700;
}

.account-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.account-section-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  padding: 0 6px;
}

.account-section-common .account-section-title {
  font-size: 14px;
}

.account-section-common .account-row-btn {
  min-height: 62px;
  padding: 16px;
}

.account-section-common .account-row-title {
  font-size: 17px;
  font-weight: 600;
}

.account-card-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.account-row-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 14px 16px;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  text-align: left;
  cursor: pointer;
  color: var(--text);
  transition: background 0.15s ease;
}

.account-row-btn:last-child {
  border-bottom: none;
}

.account-row-btn:hover {
  background: var(--surface-2);
}

.account-row-left {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.account-row-title {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
}

.account-row-arrow {
  font-size: 18px;
  color: var(--muted);
  flex-shrink: 0;
}

#model-info-body {
  gap: 8px;
}

#model-info-body > p,
#model-info-body > .model-info-card {
  margin: 0;
}

details.model-info-card > summary {
  cursor: pointer;
  list-style: none;
}

.model-info-card > summary::-webkit-details-marker {
  display: none;
}

.model-info-expand {
  margin-inline-start: auto;
  color: var(--muted);
  font-size: 18px;
}

.model-info-card[open] .model-info-expand {
  transform: rotate(90deg);
}

.model-doc-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 12px;
}

.compression-settings.stack-form {
  gap: 8px;
}

.model-info-card p {
  margin: 4px 0 8px;
}

.model-info-prices {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 105px), 1fr));
  gap: 6px 12px;
  margin-top: 6px;
}

.model-info-price {
  min-width: 0;
  display: grid;
  gap: 2px;
  overflow-wrap: anywhere;
}

.account-row-val {
  font-size: 13px;
  color: var(--muted);
  flex-shrink: 0;
}

/* Compact header announcement pill & history modal */
.announce-dot {
  position: absolute;
  top: 14px;
  right: 10px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--danger);
}

.ann-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ann-item {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 14px;
  padding: 12px 14px;
}

.ann-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.ann-item-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.ann-item-date {
  font-size: 12px;
  color: var(--muted);
  flex-shrink: 0;
}

.ann-item-body {
  font-size: 13px;
  color: var(--text);
  line-height: 1.6;
  white-space: pre-wrap;
}

@media (max-width: 768px) {
  .announcement-modal > .modal-panel {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    width: auto;
    height: auto;
    max-width: none;
    max-height: none;
    border-radius: 0;
  }

  .announcement-modal .modal-header {
    padding-top: max(14px, env(safe-area-inset-top));
  }

  .announcement-modal .modal-body {
    flex: 1;
    overscroll-behavior: contain;
  }

  .announcement-modal .ann-item-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
  }

  .announcement-modal .ann-item-body {
    overflow-wrap: anywhere;
  }
}

/* ===== 移动端适配加固：防止系统大字号 / 误触缩放把右侧按钮挤出屏幕 ===== */
html, body {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overflow-x: hidden;
}

.app-header, .chat-header {
  flex-wrap: nowrap;
}

.header-right {
  flex: 0 0 auto;
  gap: 6px;
}

.header-right .icon-btn {
  flex: 0 0 32px;
  width: 32px;
  height: 44px;
  padding: 0;
}

.header-right .icon-btn svg {
  width: 16px;
  height: 16px;
}

.header-pill {
  --pill-border: var(--border);
  --pill-background: var(--surface-2);
  position: relative;
  isolation: isolate;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  flex: 0 0 48px;
  width: 48px;
  height: 44px;
  padding: 0 2px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font: 600 12px/1.15 system-ui, sans-serif;
  white-space: nowrap;
  cursor: pointer;
}

.header-pill::before {
  content: '';
  position: absolute;
  top: 11px;
  right: 0;
  bottom: 11px;
  left: 0;
  z-index: -1;
  pointer-events: none;
  border: 1px solid var(--pill-border);
  border-radius: inherit;
  background: var(--pill-background);
  transition: background-color 180ms ease, border-color 180ms ease;
}

.header-pill:hover {
  text-decoration: underline;
}

.header-pill:focus-visible {
  outline: 2px solid currentColor;
}

.home-recharge-btn {
  --recharge-hue: 136;
  --pill-border: hsl(var(--recharge-hue), 50%, 80%);
  --pill-background: hsl(var(--recharge-hue), 65%, 94%);
  color: hsl(var(--recharge-hue), 68%, 22%);
}

body.dark .home-recharge-btn {
  --pill-border: hsl(var(--recharge-hue), 36%, 41%);
  --pill-background: hsl(var(--recharge-hue), 35%, 20%);
  color: hsl(var(--recharge-hue), 75%, 85%);
}

.chat-header .model-dropdown {
  min-width: 0;
}

.chat-header .model-picker-btn {
  max-width: min(100%, 42vw);
}

#model-picker-label {
  display: block;
  flex: 0 1 auto;
  min-width: 0;
  direction: ltr;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#model-picker-current-rate {
  flex: none;
  white-space: nowrap;
}

#model-picker-current-rate:empty {
  display: none;
}

#model-picker-current-rate .model-option-rate {
  font-size: 10px;
  padding: 1px 3px;
}

.model-picker-btn svg {
  flex-shrink: 0;
}

@media (max-width: 360px) {
  .chat-header {
    padding-inline: max(8px, env(safe-area-inset-left)) max(8px, env(safe-area-inset-right));
    gap: 4px;
  }

  .chat-header .header-right {
    gap: 4px;
  }

  .chat-header .model-picker-btn {
    padding-inline: 4px;
  }

  .header-pill {
    flex-basis: 44px;
    width: 44px;
  }
}

.composer-toolbar {
  flex-wrap: wrap;
  row-gap: 8px;
}

.composer-tools-left {
  min-width: 0;
  flex: 1 1 auto;
  flex-wrap: wrap;
}

.composer-tools-right {
  flex: 0 0 auto;
  margin-left: auto;
}

.send-circle-btn,
.tool-icon-btn,
.pill-toggle {
  flex: 0 0 auto;
  white-space: nowrap;
}

@media (max-width: 340px) {
  .pill-toggle span { display: none; }
  .pill-toggle { padding: 6px 9px; }
}

@media (max-width: 768px) {
  .chat-header {
    height: 54px;
    padding-left: 8px;
    padding-right: 8px;
    border-bottom: 1px solid var(--border);
  }

  .chat-header .header-left {
    flex: 1 1 auto;
    gap: 0;
    margin-right: 4px;
  }

  .chat-header .model-dropdown {
    flex: 1 1 auto;
  }

  .chat-header .model-picker-btn {
    max-width: 100%;
    padding-left: 4px;
    padding-right: 4px;
    text-align: left;
  }

  .chat-header .header-right {
    gap: 0;
  }

  .chat-header .header-right > :not(.hidden) + :not(.hidden) {
    margin-left: 4px;
  }

  .chat-stage .composer-box {
    padding-left: 10px;
    padding-right: 10px;
  }

  .composer-toolbar {
    gap: 0;
  }

  .composer-tools-left,
  .composer-tools-right {
    gap: 0;
  }

  .composer-tools-left > :not(.hidden) + :not(.hidden),
  .composer-tools-right > :not(.hidden) + :not(.hidden) {
    margin-left: 6px;
  }

  .composer-toolbar .pill-toggle {
    padding: 5px 8px;
    font-size: 12px;
    min-height: 30px;
  }

  .md-table-scroll {
    border: 1px solid var(--border);
    border-radius: 10px;
  }

  .md-table-scroll th,
  .md-table-scroll td {
    border: 0;
    border-bottom: 1px solid var(--border);
  }

  .md-table-scroll tbody tr:last-child td {
    border-bottom: 0;
  }

  .md-table-scroll tbody tr:nth-child(even) {
    background: var(--surface-2);
  }

  .dc-dialog-with-choice .dc-dialog-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 6px;
  }

  .dc-dialog-with-choice .dc-dialog-actions .dc-dialog-cancel {
    grid-column: 1 / -1;
    grid-row: 2;
  }
}

.model-option-divider {
  height: 1px;
  background: var(--border);
  margin: 2px 4px;
}

/* 下载按钮：视频 / 图片 */
.msg-media-wrap {
  display: inline-flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
  max-width: 360px;
  width: 100%;
}

.msg-media-save {
  align-self: flex-start;
  font-size: 12px;
  color: var(--primary);
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px;
  background: var(--surface);
}

.msg-media-save:hover {
  background: var(--surface-2);
}

/* iOS 上输入框字号小于 16px 会自动放大页面，导致"点不进输入框" */
@media (max-width: 1024px) {
  input, select, textarea {
    font-size: 16px !important;
  }
}

/* 对话列表：三点菜单 + 多选 */
.conv-item {
  position: relative;
  touch-action: manipulation;
}

.conv-more {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  border: none;
  background: transparent;
  color: var(--sidebar-muted);
  font-size: 16px;
  line-height: 1;
  border-radius: 8px;
  cursor: pointer;
  opacity: 0.65;
}

.conv-more:hover,
.conv-more:active {
  background: var(--sidebar-hover);
  opacity: 1;
}

.conv-item.selected {
  background: var(--sidebar-active);
}

.conv-check {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1.5px solid var(--sidebar-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: #fff;
}

.conv-check.on {
  background: var(--primary);
  border-color: var(--primary);
}

.conv-pin {
  flex: 0 0 auto;
  font-size: 12px;
}

.conv-select-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid var(--sidebar-border);
  background: var(--sidebar-bg);
  font-size: 13px;
  color: var(--sidebar-text);
}

.conv-select-actions {
  display: flex;
  gap: 6px;
}

.conv-action-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.conv-action-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  padding: 13px 12px;
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
}

.conv-action-item:hover,
.conv-action-item:active {
  background: var(--surface-2);
}

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

/* 去掉旧的悬停操作按钮占位 */
.conv-actions {
  display: none;
}

/* 后台表格：操作列固定右侧，横向滚动不再需要拖到底部 */
.table-wrap {
  -webkit-overflow-scrolling: touch;
}

.data-table th:last-child,
.data-table td:last-child {
  position: sticky;
  right: 0;
  background: var(--surface);
  box-shadow: -6px 0 12px rgba(15, 23, 42, 0.06);
  z-index: 1;
}

.data-table thead th:last-child {
  z-index: 2;
}

table.admin-users-table {
  table-layout: fixed;
}

table.admin-users-table :is(th, td) {
  white-space: normal;
  overflow-wrap: anywhere;
  padding: 8px 12px;
}

.admin-users-table th:first-child {
  width: 44px;
}

.admin-users-table th:nth-child(2) {
  width: 27%;
}

.admin-users-table th.admin-numeric {
  width: 9%;
}

.admin-users-table th:nth-child(7) {
  width: 6%;
}

.admin-users-table th:last-child {
  width: 18%;
}

.admin-users-table :is(th, td).admin-numeric {
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.admin-users-table td.admin-numeric {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.admin-users-table :is(th, td):last-child {
  position: static;
  box-shadow: none;
}

.admin-users-table th:last-child {
  background: var(--surface-2);
}

.admin-overview .kpi-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 145px), 1fr));
}

.admin-model-settings > :is(h4, p) {
  margin: 0;
}

.admin-official-rate {
  max-width: 12rem;
}

.admin-model-table-wrap td {
  white-space: normal;
}

.admin-settings-extra > .stack-form {
  margin-top: 12px;
}

.admin-feature-settings > .stack-form {
  margin-top: 10px;
}

.model-row-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.model-rate-input {
  width: 74px;
}

.route-number {
  width: 88px;
}

.model-stepper {
  position: relative;
  display: inline-flex;
  min-width: 0;
  max-width: 100%;
}

.model-stepper input[type="number"] {
  appearance: textfield;
  padding-right: 20px;
}

.model-stepper input::-webkit-inner-spin-button {
  appearance: none;
}

.model-stepper-arrows {
  position: absolute;
  right: 2px;
  inset-block: 3px;
  display: flex;
  flex-direction: column;
}

.model-stepper-arrows button {
  flex: 1;
  padding: 0;
  width: 16px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
}

.model-stepper-arrows button:hover {
  background: var(--surface-2);
}

.model-name-input {
  width: 170px;
}

.model-line-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.admin-overview .kpi-card {
  min-width: 0;
  padding: 9px 11px;
}

.admin-overview .kpi-value {
  font-size: clamp(15px, 1.6vw, 20px);
  overflow-wrap: anywhere;
}

.admin-overview .data-table :is(th, td) {
  padding: 7px 9px;
}

.admin-overview .data-table :is(th, td):last-child {
  position: static;
  box-shadow: none;
}

.admin-overview .data-table th:last-child {
  background: var(--surface-2);
}

.admin-ledger-table td:last-child {
  min-width: 7rem;
  max-width: 22rem;
  white-space: normal;
  overflow-wrap: anywhere;
}

.admin-user-actions,
.admin-user-meta,
.admin-batch-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px 8px;
}

.admin-user-meta,
.admin-user-template {
  font-size: 12px;
  line-height: 1.5;
  margin-top: 3px;
}

.admin-customer-heading,
.admin-batch-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
}

.admin-customer-heading .input-with-btn {
  flex: 0 1 360px;
}

.admin-batch-bar {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
}

.admin-batch-bar form,
.admin-batch-bar select {
  min-width: 0;
}

#admin-batch-count {
  font-size: 12px;
}

.admin-user-compact {
  display: none;
}

.admin-customer-controls .admin-batch-actions {
  gap: 6px;
}

.admin-sort-labels {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px 8px;
}

.admin-customer-sort-field {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  white-space: nowrap;
}

.admin-sort-arrows {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
}

.sort-label-short {
  display: none;
}

@media (max-width: 880px) {
  .admin-users-table thead .admin-customer-sort-field {
    font-size: 12px;
  }
}

.admin-customer-sort-field button {
  display: grid;
  place-items: center;
  width: 16px;
  height: 15px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.admin-customer-sort-field button:is(:hover, :focus-visible) {
  background: var(--surface-2);
}

.admin-customer-sort-field button[aria-pressed="true"] {
  color: var(--primary);
  background: var(--primary-soft);
}

.admin-customer-sort-field svg {
  width: 12px;
  height: 12px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
}

.admin-user-free {
  display: grid;
  gap: 2px;
  font-size: 12px;
}

.admin-user-free {
  margin-top: 4px;
  color: var(--muted);
}

.admin-user-free strong {
  font-size: 11px;
}

.admin-users-table td.admin-user-note span {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  overflow-wrap: anywhere;
}

#admin-customer-threshold {
  width: 6.4rem;
  min-width: 0;
}

.admin-user-plan,
.admin-user-plan label {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 7px;
}

.admin-user-plan {
  margin-top: 4px;
}

.admin-user-plan .admin-user-template {
  margin-top: 0;
}

.admin-user-plan select {
  width: auto;
  max-width: 100%;
  min-width: 0;
  padding: 3px 6px;
}

.chat-template-model {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
}

.chat-template-model legend {
  overflow-wrap: anywhere;
}

.chat-template-prices {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(115px, 1fr));
  gap: 8px;
  margin-top: 8px;
}

@media (max-width: 880px) {
  .admin-users-table :is(th, td):nth-child(n+7),
  .admin-users-table .sort-label-full {
    display: none;
  }

  .admin-users-table .sort-label-short {
    display: inline;
  }

  .admin-users-table th:first-child {
    width: 27px;
  }

  .admin-users-table th.admin-numeric {
    width: clamp(43px, 13vw, 88px);
  }

  table.admin-users-table :is(th, td).admin-numeric {
    padding-inline: 3px;
    font-size: 12px;
  }

  table.admin-users-table :is(th, td):first-child {
    padding-inline: 5px;
  }

  .admin-users-table .admin-sort-arrows button {
    width: 11px;
    height: 17px;
  }

  .admin-users-table .admin-sort-arrows svg {
    width: 10px;
  }

  .admin-users-table th:nth-child(2) {
    width: auto;
  }

  .admin-user-compact {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
    margin-top: 6px;
  }
}

/* 客户明细里的积分记录表：不做右侧吸附，避免在窄弹窗里盖住其它列 */
.detail-tx-table th:last-child,
.detail-tx-table td:last-child {
  position: static;
  box-shadow: none;
}

/* 对话操作浮层（无 emoji，紧凑） */
.conv-popover {
  position: fixed;
  z-index: 4000;
  min-width: 132px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.16);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.conv-popover button {
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  text-align: left;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
}

.conv-popover button:hover,
.conv-popover button:active {
  background: var(--surface-2);
}

.conv-popover button.danger-text {
  color: var(--danger);
}

.conv-pin-ico {
  flex: 0 0 auto;
  color: var(--muted);
}

/* 选择模式下的操作栏更简洁 */
.conv-select-bar {
  gap: 10px;
  font-size: 12px;
}

.conv-select-bar .btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

/* 弹窗头部：返回按钮（与右上角 ✕ 对称） */
.modal-header-left {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.modal-header-left h3 {
  margin: 0;
  font-size: 17px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#modal-back-btn {
  flex: 0 0 auto;
}

/* 独立轻量对话框（不占用主弹窗） */
.dc-dialog-root {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 5000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.dc-dialog-backdrop {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(15, 23, 42, 0.45);
}

.dc-dialog-panel {
  position: relative;
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.25);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dc-dialog-with-choice .dc-dialog-panel {
  max-width: 390px;
}

.dc-dialog-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.dc-dialog-msg {
  margin: 0;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
  word-break: break-word;
}

.dc-dialog-input {
  width: 100%;
  font-size: 16px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
}

.dc-dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 4px;
}

.dc-dialog-actions button {
  flex: 1;
}

/* 上下文用量提示（对话较长时提醒开新对话） */
.context-hint {
  max-width: 780px;
  margin: 2px auto 0;
  padding: 0 4px;
  font-size: 11px;
  line-height: 1.6;
  color: var(--muted);
  text-align: right;
  min-height: 0;
}

.context-hint:empty {
  display: none;
}

.context-hint.warn {
  color: #d97706;
}

.context-reminder {
  max-width: 780px;
  margin: 4px auto 0;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 12px;
  line-height: 1.55;
}

.context-reminder p {
  margin: 0;
}

.context-reminder-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin-top: 8px;
}

.context-reminder-actions button, .compression-progress button {
  min-height: 40px;
}

#context-dismiss-btn {
  margin-inline-start: auto;
}

.compression-progress p {
  margin: 0 0 8px;
}

.ledger-account-btn {
  padding: 2px 0;
  border: 0;
  background: transparent;
  color: var(--primary);
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.admin-detail-header {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding: 6px 0;
  background: var(--surface);
  overflow-wrap: anywhere;
}

/* 长按消息的紧凑浮层（贴在消息旁边） */
.mini-popover {
  position: fixed;
  z-index: 4500;
  min-width: 124px;
  padding: 5px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.16);
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.mini-popover button {
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  text-align: left;
  padding: 9px 12px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}

.mini-popover button:hover,
.mini-popover button:active {
  background: var(--surface-2);
}

/* 多选样式收敛 */
.conv-select-bar {
  padding: 9px 12px;
  font-size: 12px;
  color: var(--muted);
  gap: 6px;
}

.conv-select-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.conv-select-actions button {
  border: none;
  background: transparent;
  color: var(--primary);
  font-size: 12px;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
}

.conv-select-actions button:hover,
.conv-select-actions button:active {
  background: var(--sidebar-hover);
}

.conv-select-actions .btn-danger {
  color: var(--danger);
  font-weight: 600;
  background: transparent;
}

.conv-check {
  width: 18px;
  height: 18px;
  border-radius: 6px;
  border-width: 1.5px;
  font-size: 11px;
}

.conv-item.selected {
  background: var(--sidebar-hover);
}

/* 对话顶部：已压缩摘要提示 */
.conv-summary-banner {
  margin: 0 auto 10px;
  max-width: 780px;
  padding: 8px 12px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  font-size: 12px;
  color: var(--muted);
}

.conv-summary-banner summary {
  cursor: pointer;
  color: var(--muted);
  list-style: none;
}

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

.conv-summary-text {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  color: var(--text);
  line-height: 1.8;
  white-space: pre-wrap;
  font-size: 13px;
}

/* 长按浮层再收紧一点，减少对下方文字的遮挡 */
.mini-popover {
  padding: 4px;
  min-width: 108px;
  border-radius: 10px;
}

.mini-popover button {
  padding: 7px 10px;
  font-size: 13px;
  line-height: 1.35;
  border-radius: 7px;
}

/* ===== 后台：客户聊天记录 ===== */
.admin-subnav {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.admin-chat-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 46vh;
  overflow: auto;
  padding-right: 2px;
}

.admin-chat-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
  width: 100%;
  text-align: left;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font: inherit;
}

.admin-chat-row:hover {
  border-color: var(--primary);
  background: var(--surface-2);
}

.admin-chat-row-title {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.admin-chat-row-meta {
  font-size: 11px;
  color: var(--muted);
}

.admin-chat-fullscreen {
  padding: 0;
}

.admin-chat-fullscreen .modal-panel {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  max-width: none;
  max-height: none;
  border: 0;
  border-radius: 0;
}

.admin-chat-fullscreen .modal-panel > :is(.modal-header, .modal-body) {
  display: none;
}

.admin-chat-workspace {
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--surface);
}

.admin-chat-toolbar,
.admin-chat-reader-header,
.admin-chat-sidebar-title {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

.admin-chat-toolbar {
  padding-top: max(10px, env(safe-area-inset-top));
}

.admin-chat-toolbar button {
  flex-shrink: 0;
}

.admin-chat-toolbar strong {
  overflow-wrap: anywhere;
  margin-right: 8px;
}

.admin-chat-layout {
  display: grid;
  grid-template-columns: clamp(225px, 25vw, 315px) minmax(0, 1fr);
  flex: 1;
  min-height: 0;
}

.admin-chat-sidebar {
  overflow: auto;
  overscroll-behavior: contain;
  border-right: 1px solid var(--border);
  background: var(--surface-2);
  padding: 0 10px max(10px, env(safe-area-inset-bottom));
}

.admin-chat-sidebar-title {
  position: sticky;
  top: 0;
  z-index: 1;
  justify-content: space-between;
  background: var(--surface-2);
}

.admin-chat-thread-list {
  display: grid;
  gap: 5px;
  padding: 8px 0;
}

.admin-chat-thread-list .admin-chat-row[aria-current="true"] {
  border-color: var(--primary);
}

.admin-chat-reader {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.admin-chat-reader-header strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-chat-message-pane {
  flex: 1;
  min-height: 0;
}

.admin-chat-scroll {
  height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  overflow-anchor: none;
  padding: 16px clamp(12px, 4vw, 48px) max(24px, env(safe-area-inset-bottom));
}

.admin-chat-scroll .messages-list {
  gap: 10px;
}

.admin-chat-scroll [role="status"]:empty {
  display: none;
}

.admin-chat-message-rows {
  display: grid;
  gap: 20px;
}

.admin-chat-message-rows .msg-row {
  min-width: 0;
}

.admin-chat-message-rows .msg-media {
  aspect-ratio: 16 / 9;
  object-fit: contain;
}

.admin-chat-stamp {
  font-size: 11px;
}

.admin-balance-form input,
.admin-balance-form select {
  font-size: 16px;
}

@media (max-width: 720px) {
  .admin-chat-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .admin-chat-sidebar {
    border-right: 0;
  }

  .admin-chat-workspace:not(.has-conversation) .admin-chat-reader,
  .admin-chat-workspace.has-conversation .admin-chat-sidebar {
    display: none;
  }
}

.admin-msg-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 52vh;
  overflow: auto;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
}

.admin-msg {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

.admin-msg-user {
  border-left: 3px solid var(--primary);
}

.admin-msg-assistant {
  border-left: 3px solid var(--border);
}

.admin-msg-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 4px;
  font-size: 11px;
  color: var(--muted);
}

.admin-msg-body {
  max-height: 360px;
  overflow: auto;
  font-size: 13px;
  line-height: 1.75;
  white-space: pre-wrap;
  word-break: break-word;
}

.admin-msg-media {
  margin-bottom: 4px;
  font-size: 12px;
  word-break: break-all;
}

.admin-msg-think {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}

.admin-msg-think summary {
  cursor: pointer;
}

.admin-msg-think > div {
  margin-top: 6px;
  padding-left: 8px;
  max-height: 220px;
  overflow: auto;
  white-space: pre-wrap;
  line-height: 1.7;
  border-left: 2px solid var(--border);
}


.quota-line {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 2px 10px;
  margin: 5px 0;
}

.free-budget-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(70px, 125px) auto;
  align-items: end;
  gap: 8px;
}

/* Refactored Admin Settings Sub-Tabs & Card Layout */
.admin-settings-shell {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.admin-subtabs {
  position: sticky;
  top: -16px;
  z-index: 6;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 8px 0 10px;
  margin-top: -6px;
  background: var(--surface, var(--bg));
  border-bottom: 1px solid var(--border);
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.admin-subtabs::-webkit-scrollbar {
  display: none;
}

.admin-subtab {
  flex: 0 0 auto;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2, var(--bg));
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.admin-subtab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.admin-settings-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface, var(--bg));
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.admin-settings-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.admin-settings-card-head h4 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

.admin-settings-card-desc {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
}

.admin-tier-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  align-items: start;
}

.admin-tier-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface, var(--bg));
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.admin-tier-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.admin-paid-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) minmax(0, 1.15fr) 60px 52px;
  gap: 6px;
  align-items: center;
  padding: 4px 7px;
  border-radius: 8px;
  background: var(--surface-2, rgba(127, 127, 127, 0.05));
  font-size: 12px;
}

.admin-paid-row[data-cg-row] {
  grid-template-columns: auto minmax(0, 1fr) minmax(0, 1.15fr) 60px 52px;
}

.admin-paid-row select,
.admin-paid-row input[type="number"] {
  padding: 3px 6px;
  font-size: 12px;
  min-width: 0;
  width: 100%;
}

.admin-tier-default {
  justify-content: flex-start;
  align-items: end;
  gap: 12px;
}

.admin-tier-default .field {
  width: 122px;
  flex-shrink: 0;
  margin: 0;
}

.admin-tier-rates {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  column-gap: 12px;
  row-gap: 3px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

.admin-tier-rates output {
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.admin-paid-name {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-free-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 58px 66px auto;
  gap: 6px;
  align-items: end;
  padding: 5px 7px;
  border-radius: 8px;
  background: var(--surface-2, rgba(127, 127, 127, 0.05));
}

.admin-free-row .field {
  margin: 0;
  min-width: 0;
}

.admin-free-row .field span {
  font-size: 11px;
}

.admin-free-row select,
.admin-free-row input {
  padding: 3px 6px;
  font-size: 12px;
  min-width: 0;
  width: 100%;
}

.admin-model-toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.admin-model-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.admin-model-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2, rgba(127, 127, 127, 0.04));
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.admin-model-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  flex-wrap: wrap;
  padding-bottom: 5px;
  border-bottom: 1px dashed var(--border);
}

.admin-model-card-title {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  min-width: 0;
  font-size: 13px;
}

.admin-model-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(77, 107, 254, 0.1);
  color: var(--primary);
}

.admin-model-badge.is-third {
  background: rgba(16, 185, 129, 0.12);
  color: #0f766e;
}

.admin-model-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px 8px;
  align-items: end;
}

.admin-model-grid .field {
  margin: 0;
  min-width: 0;
}

.admin-model-grid .field span {
  font-size: 11px;
}

.admin-model-grid .field input,
.admin-model-grid .field select,
.admin-model-grid .model-stepper {
  width: 100%;
  min-width: 0;
  font-size: 12px;
}

.admin-model-grid .field input,
.admin-model-grid .field select {
  padding: 5px 7px;
}

.admin-model-checks {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--text);
}

.admin-model-checks label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

.admin-settings-sticky-bar {
  position: sticky;
  bottom: -16px;
  z-index: 5;
  margin-top: 2px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface, var(--bg));
  box-shadow: 0 -4px 14px rgba(0, 0, 0, 0.06);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.admin-dirty-hint {
  font-size: 12px;
  color: var(--muted);
}

.admin-dirty-hint.is-dirty {
  color: var(--primary);
  font-weight: 600;
}

.admin-channel-api-drawer {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  background: var(--surface-2, rgba(127, 127, 127, 0.05));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

@media (max-width: 820px) {
  .admin-tier-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .admin-free-row {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
}

.admin-template-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.admin-template-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2, var(--bg));
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.admin-template-pill small {
  font-size: 11px;
  opacity: 0.75;
}

.admin-template-pill.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.admin-template-pill.is-add {
  border-style: dashed;
  color: var(--primary);
}

.admin-template-pill.is-add.active {
  color: #fff;
  border-style: solid;
}

.admin-channel-box {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface, var(--bg));
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.admin-channel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.admin-channel-meta {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

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

.admin-channel-title-row h4 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.admin-channel-url {
  font-size: 12px;
  color: var(--muted);
  word-break: break-all;
}

.admin-channel-quick-add {
  border: 1px dashed var(--primary);
  border-radius: 12px;
  padding: 12px;
  background: rgba(77, 107, 254, 0.04);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.admin-user-rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 20px;
  padding: 0 5px;
  border-radius: 6px;
  background: var(--surface-2, rgba(127, 127, 127, 0.12));
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

@media (max-width: 720px) {
  .admin-model-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .admin-settings-sticky-bar {
    flex-direction: column;
    align-items: stretch;
  }
  .admin-settings-sticky-bar .btn-primary {
    width: 100%;
  }
}

.voice-hold {
  width: 100%;
  min-height: 54px;
  border: 0;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 650;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.voice-status {
  position: fixed;
  z-index: 100;
  bottom: max(108px, calc(env(safe-area-inset-bottom) + 95px));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  width: max-content;
  max-width: 90%;
  padding: 11px 16px;
  border-radius: 14px;
  background: linear-gradient(115deg, #304ba3, #4168cc);
  color: white;
  pointer-events: none;
  font-size: 13px;
  box-shadow: 0 6px 24px #203b7033;
}

.voice-status.voice-cancelling { background: #963a51; }
.voice-signal {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  height: 20px;
}
.voice-signal i {
  width: 3px;
  height: 100%;
  border-radius: 3px;
  background: #dce7ff;
  transform: scaleY(.22);
  transition: transform 80ms ease-out;
}
@media (prefers-reduced-motion: reduce) {
  .voice-signal i { transition: none; }
}
#voice-toggle[aria-pressed="true"] { color: var(--primary); }
