:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --line: #dde1da;
  --text: #1e2420;
  --muted: #6d756f;
  --green: #22c55e;
  --green-strong: #16a34a;
  --mint: #e9f8ef;
  --coral: #f9735b;
  --gold: #f4b740;
  --shadow: 0 18px 50px rgba(35, 44, 38, 0.11);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.app-shell {
  min-height: 100dvh;
}

.auth-screen {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: minmax(360px, 0.95fr) minmax(360px, 1fr);
  align-items: stretch;
}

.auth-visual {
  position: relative;
  overflow: hidden;
}

.auth-visual-fill {
  width: 100%;
  height: 100%;
  min-height: 320px;
  background: linear-gradient(145deg, #6b7cff 0%, #4cc0a8 42%, #7c5cff 100%);
}

.auth-visual::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(30, 36, 32, 0.08), rgba(30, 36, 32, 0.36));
}

.auth-panel {
  align-self: center;
  width: min(460px, calc(100% - 48px));
  margin: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 34px;
  box-shadow: var(--shadow);
}

.brand-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--green);
  color: white;
  font-weight: 800;
}

.bt-entry-link {
  margin-top: 4px;
  font-size: 11px;
  line-height: 1;
  color: #98a19a;
  text-decoration: none;
  letter-spacing: 0.02em;
}

.bt-entry-link:hover {
  color: #6d756f;
}

.bt-admin-shell {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--bg);
}

.bt-admin-card {
  width: min(860px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 24px;
  display: grid;
  gap: 16px;
}

.bt-admin-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.bt-admin-head h1 {
  margin: 0 0 8px;
  font-size: 24px;
}

.bt-back-link {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.bt-admin-tip {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.bt-admin-unlock {
  display: grid;
  gap: 10px;
  max-width: 360px;
}

.bt-admin-manager {
  display: grid;
  gap: 12px;
}

.bt-admin-dashboard {
  display: grid;
  gap: 14px;
}

.bt-dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}

.bt-dashboard-tile {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fafbf9;
  text-decoration: none;
  color: inherit;
  display: grid;
  gap: 8px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.bt-dashboard-tile:hover {
  border-color: #b8c4b0;
  box-shadow: var(--shadow);
}

.bt-dashboard-tile h2 {
  margin: 0;
  font-size: 16px;
}

.bt-dashboard-tile p {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.45;
}

.bt-dashboard-footer {
  display: flex;
  justify-content: flex-end;
  padding-top: 4px;
}

.bt-admin-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 10px 0 4px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 4px;
}

.bt-admin-nav-label {
  font-size: 12px;
  color: var(--muted);
  margin-right: 4px;
}

.bt-nav-link {
  font-size: 13px;
  color: #4a6350;
  text-decoration: none;
  padding: 4px 8px;
  border-radius: 6px;
}

.bt-nav-link:hover {
  background: #eef2eb;
}

.bt-nav-current {
  font-weight: 600;
  background: #e4ebe0;
  color: var(--text);
}

.bt-nav-logout {
  margin-left: auto;
  font-size: 12px;
  min-height: 32px;
  padding: 0 12px;
}

.bt-bridge-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.bt-bridge-test-result {
  margin: 0;
  min-height: 1.25em;
  font-size: 13px;
  line-height: 1.45;
  color: var(--muted);
}

.bt-bridge-test-ok {
  color: #2d6a3a;
}

.bt-bridge-test-warn {
  color: #8a5a00;
}

.bt-bridge-test-fail {
  color: #a33;
}

.bt-bridge-section {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 16px;
  display: grid;
  gap: 12px;
  background: #fafbf9;
}

.bt-bridge-section h2 {
  margin: 0;
  font-size: 16px;
}

.bt-bridge-section .bt-settings-note {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

.bt-bridge-section .bt-settings-note code {
  font-size: 11px;
}

.bt-bridge-fields {
  display: grid;
  gap: 10px;
}

.bt-bridge-fields label {
  display: grid;
  gap: 4px;
  font-size: 13px;
}

.bt-bridge-fields input {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 0 10px;
  font-size: 14px;
  background: white;
}

.bt-secret-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.bt-secret-label {
  display: grid;
  gap: 4px;
  font-size: 13px;
  margin: 0;
}

.bt-secret-row .outline-btn {
  min-height: 40px;
  white-space: nowrap;
}

.bt-secret-row input:read-only {
  background: #f3f5f3;
  color: var(--text);
}

.bt-section-divider {
  margin: 4px 0 0;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.bt-section-divider h2 {
  margin: 0 0 10px;
  font-size: 16px;
}

.bt-admin-actions {
  display: grid;
  grid-template-columns: minmax(0, 260px) auto;
  gap: 10px;
  align-items: end;
}

.bt-admin-actions-token {
  grid-template-columns: minmax(0, 1fr) auto auto;
}

@media (max-width: 520px) {
  .bt-admin-actions-token {
    grid-template-columns: 1fr;
  }
}

.bt-admin-list {
  display: grid;
  gap: 8px;
  max-height: 420px;
  overflow: auto;
}

.bt-token-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 10px;
  display: grid;
  gap: 6px;
}

.bt-token-item p {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
}

.bt-token-item p:first-child {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.bt-token-item p:first-child span {
  color: var(--muted);
}

.bt-token-actions {
  display: flex;
  justify-content: flex-end;
}

.bt-token-delete {
  font-size: 12px;
  padding: 4px 10px;
}

.bt-empty {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

h1,
h2,
p {
  margin: 0;
}

.auth-panel h1 {
  margin-top: 22px;
  font-size: 30px;
}

.auth-panel p,
.section-head p,
.chat-header p {
  color: var(--muted);
  line-height: 1.6;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 26px 0 18px;
  padding: 4px;
  background: #eef1eb;
  border-radius: 8px;
}

.auth-tab {
  border: 0;
  border-radius: 6px;
  min-height: 42px;
  background: transparent;
  color: var(--muted);
}

.auth-tab.active {
  background: white;
  color: var(--text);
  box-shadow: 0 4px 14px rgba(35, 44, 38, 0.08);
}

.auth-form,
.simple-form {
  display: none;
  gap: 14px;
}

.auth-form.active,
.simple-form {
  display: grid;
}

label {
  display: grid;
  gap: 7px;
}

label span,
.switch-row span {
  color: #384039;
  font-size: 14px;
  font-weight: 650;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--text);
  padding: 13px 14px;
  outline: none;
}

textarea {
  resize: none;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.15);
}

small {
  min-height: 18px;
  color: var(--coral);
}

.username-inline {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.username-inline input {
  flex: 1;
  min-width: 0;
}

.inline-secondary-btn {
  flex-shrink: 0;
  align-self: stretch;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: white;
  color: var(--text);
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
  white-space: nowrap;
}

.inline-secondary-btn:hover {
  background: #f8faf8;
}

.primary-btn,
.send-btn,
.outline-btn,
.ghost-btn,
.danger-btn,
.icon-btn {
  min-height: 44px;
  border-radius: 8px;
  border: 0;
  padding: 0 16px;
}

.primary-btn,
.send-btn {
  background: var(--green);
  color: white;
  font-weight: 750;
}

.primary-btn:hover,
.send-btn:hover {
  background: var(--green-strong);
}

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

.outline-btn {
  background: white;
  color: var(--text);
  border: 1px solid var(--line);
}

.ghost-btn {
  background: #edf1ec;
  color: var(--text);
}

.danger-btn {
  background: #fff1ef;
  color: #c2412f;
  border: 1px solid #ffd4cc;
}

.chat-app {
  height: 100dvh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  overflow: hidden;
  min-height: 0;
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.82);
}

.profile-tile {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 10px;
  border-radius: 8px;
  background: var(--mint);
}

.profile-tile strong,
.profile-tile span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-tile span {
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  object-fit: cover;
}

.avatar.large {
  width: 92px;
  height: 92px;
}

.menu-list {
  display: grid;
  gap: 8px;
}

.menu-item {
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  padding: 0 12px;
  text-align: left;
}

.menu-item span {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #eef1eb;
  color: var(--text);
  font-weight: 800;
}

.menu-item.active {
  background: #1f2a24;
  color: white;
}

.menu-item.active span {
  background: var(--green);
  color: white;
}

.new-chat-btn {
  width: 100%;
}

.side-actions {
  margin-top: auto;
  display: grid;
  gap: 10px;
}

.side-logout-btn {
  width: 100%;
}

.main-pane {
  position: relative;
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.mobile-topbar {
  display: none;
}

/* 底部移动端导航已由汉堡菜单取代，所有屏幕下都隐藏。 */
.bottom-tabs {
  display: none !important;
}

.panel {
  display: none;
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.panel.active {
  display: flex;
}

.chat-panel {
  flex-direction: column;
  min-height: 0;
}

.chat-header,
.section-head {
  padding: 22px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.88);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding: 22px 28px 24px;
  scroll-behavior: smooth;
}

.empty-state {
  min-height: 100%;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
}

.empty-state img {
  width: min(260px, 72vw);
  border-radius: 8px;
  margin-bottom: 18px;
}

.message-row {
  display: flex;
  gap: 10px;
  margin: 14px 0;
  align-items: flex-start;
}

.message-row.mine {
  flex-direction: row-reverse;
}

.bubble {
  max-width: min(62ch, 68%);
  border-radius: 8px;
  padding: 11px 13px;
  background: white;
  border: 1px solid var(--line);
  line-height: 1.58;
  word-break: break-word;
  box-shadow: 0 8px 24px rgba(35, 44, 38, 0.07);
}

.message-row.mine .bubble {
  background: #95ec69;
  border-color: #82dd58;
}

.bubble.sending {
  opacity: 0.66;
}

.bubble.failed {
  border-color: #ffb4a8;
}

.image-bubble {
  padding: 5px;
  background: white;
}

.image-bubble img {
  display: block;
  width: min(260px, 48vw);
  max-height: 300px;
  object-fit: cover;
  border-radius: 6px;
}

.time-divider {
  width: fit-content;
  margin: 18px auto;
  padding: 4px 10px;
  border-radius: 8px;
  background: #e8ece6;
  color: var(--muted);
  font-size: 12px;
}

.composer {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  padding: 14px 18px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
}

.composer textarea {
  max-height: 128px;
  min-height: 44px;
  line-height: 1.45;
}

.icon-btn {
  width: 44px;
  padding: 0;
  display: grid;
  place-items: center;
  background: white;
  border: 1px solid var(--line);
}

.settings-panel {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
}

.settings-panel.active {
  display: flex;
}

.simple-form {
  width: min(720px, calc(100% - 44px));
  margin: 24px auto 44px;
  padding: 24px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.avatar-editor,
.form-actions,
.switch-row,
.split-head {
  display: flex;
  align-items: center;
  gap: 12px;
}

.form-actions {
  flex-wrap: wrap;
}

.switch-row {
  justify-content: space-between;
  min-height: 48px;
  border-bottom: 1px solid var(--line);
}

.switch-row input {
  width: 22px;
  height: 22px;
  accent-color: var(--green);
}

.url-env-toggle {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.url-env-btn {
  min-width: 68px;
  min-height: 34px;
  border: 0;
  background: #f8fafc;
  color: #475569;
  cursor: pointer;
  padding: 0 12px;
}

.url-env-btn + .url-env-btn {
  border-left: 1px solid var(--line);
}

.url-env-btn.active {
  background: rgba(34, 197, 94, 0.12);
  color: var(--green-strong);
  font-weight: 600;
}

.status-line {
  min-height: 42px;
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border-radius: 8px;
  background: #f0f2ed;
  color: var(--muted);
}

.status-line.ok {
  background: var(--mint);
  color: var(--green-strong);
}

.status-line.bad {
  background: #fff1ef;
  color: #c2412f;
}

.url-edit-row {
  margin-top: 10px;
}

.url-default-line {
  display: block;
  margin-top: 8px;
  color: var(--muted);
}

.url-default-line code {
  color: #334155;
  font-size: 12px;
  word-break: break-all;
}

.clear-wide {
  width: fit-content;
}

.split-head {
  justify-content: space-between;
}

.history-list {
  display: grid;
  gap: 10px;
  width: min(860px, calc(100% - 44px));
  margin: 24px auto 44px;
}

.history-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 14px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.history-item.active {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.12);
}

.history-item strong,
.history-item p {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item p {
  color: var(--muted);
  margin-top: 5px;
}

.history-meta {
  display: grid;
  justify-items: end;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.portrait-wrap {
  width: min(860px, calc(100% - 44px));
  margin: 0 auto 44px;
  padding: 0 4px;
}

.portrait-content {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 20px 22px;
  min-height: 120px;
}

.portrait-content.portrait-muted {
  color: var(--muted);
  line-height: 1.65;
}

.portrait-content.portrait-error {
  background: #fff8f6;
  border-color: #ffd4cc;
  color: #9a3412;
}

.portrait-card {
  display: grid;
  gap: 22px;
}

.portrait-header {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  padding-bottom: 6px;
  border-bottom: 1px solid #eef1eb;
}

.portrait-header-avatar {
  width: 72px;
  height: 72px;
  border-radius: 16px;
  object-fit: cover;
  border: 1px solid var(--line);
  flex-shrink: 0;
  background: var(--bg);
}

.portrait-header-avatar--bot {
  padding: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, #eef0ff, #f3e8ff);
}

.portrait-header-avatar--bot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.portrait-header-text {
  min-width: 0;
  flex: 1;
}

.portrait-header-name {
  margin: 0 0 6px;
  font-size: 1.35rem;
  font-weight: 750;
  letter-spacing: -0.02em;
}

.portrait-header-desc {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.portrait-header-meta {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.portrait-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 650;
  background: var(--mint);
  color: var(--green-strong);
}

.portrait-badge-stage {
  margin-left: 8px;
  vertical-align: middle;
}

.portrait-state-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.portrait-state-badge {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 8px;
  background: #f0f2ed;
  color: #4b554c;
}

.portrait-state-badge--calm {
  background: #e8f4fc;
  color: #0369a1;
}

.portrait-state-badge--active {
  background: #fff4e6;
  color: #c2410c;
}

.portrait-state-badge--pressure-low {
  background: var(--mint);
  color: var(--green-strong);
}

.portrait-state-badge--pressure-mid {
  background: #fff8e6;
  color: #b45309;
}

.portrait-state-badge--pressure-high {
  background: #fff1f0;
  color: #c2412f;
}

.portrait-section {
  margin: 0;
}

.portrait-section-title {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 750;
  color: #2d332e;
}

.portrait-radar-wrap .portrait-section-title {
  margin-bottom: 6px;
}

.portrait-radar-sub {
  margin: 0 0 14px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
}

.portrait-radar-frame {
  display: flex;
  justify-content: center;
  padding: 8px 0 4px;
  background: linear-gradient(180deg, #fafbf9 0%, #ffffff 100%);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.portrait-radar-svg {
  width: 100%;
  max-width: min(340px, 92vw);
  height: auto;
  display: block;
}

.portrait-radar-grid {
  fill: none;
  stroke: #e0e4dc;
  stroke-width: 1;
}

.portrait-radar-axis {
  stroke: #eef1eb;
  stroke-width: 1;
}

.portrait-radar-fill {
  fill: rgba(99, 102, 241, 0.18);
  stroke: none;
}

.portrait-radar-stroke {
  fill: none;
  stroke: #6366f1;
  stroke-width: 2;
  stroke-linejoin: round;
}

.portrait-radar-dot {
  fill: #6366f1;
  stroke: #fff;
  stroke-width: 1.5;
}

.portrait-radar-label {
  font-family: inherit;
  font-size: 11px;
  font-weight: 650;
  fill: #5c655c;
  text-anchor: middle;
  dominant-baseline: middle;
}

.portrait-meters {
  display: grid;
  gap: 12px;
}

.portrait-meter {
  display: grid;
  gap: 6px;
}

.portrait-meter-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13px;
}

.portrait-meter-head span:first-child {
  color: #384039;
  font-weight: 650;
}

.portrait-meter-pct {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-weight: 700;
}

.portrait-meter-track {
  height: 10px;
  border-radius: 999px;
  background: #e8ece6;
  overflow: hidden;
}

.portrait-meter-fill {
  height: 100%;
  border-radius: 999px;
  min-width: 4px;
  transition: width 0.35s ease;
}

.portrait-meter-fill--stress {
  background: linear-gradient(90deg, #fb923c, #ef4444) !important;
}

.portrait-meter-note {
  margin: 4px 0 0;
  font-size: 11px;
  color: var(--muted);
}

.portrait-summary-card {
  padding: 16px 18px;
  border-radius: 12px;
  background: linear-gradient(135deg, #f8faf6 0%, #f0f4ff 100%);
  border: 1px solid #e5e8e2;
}

.portrait-summary-lead {
  margin: 0 0 10px;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.45;
  color: #1e2420;
}

.portrait-summary-body {
  margin: 0;
  font-size: 14px;
  line-height: 1.65;
  color: #4b554c;
}

.portrait-identity-grid {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.portrait-identity-line {
  font-size: 13px;
  line-height: 1.5;
  color: #384039;
}

.portrait-identity-line strong {
  color: var(--muted);
  font-weight: 650;
  margin-right: 6px;
}

.portrait-traits-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
}

.portrait-trait-group {
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fafbf9;
}

.portrait-trait-group h4 {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 700;
  color: #384039;
}

.portrait-trait-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
}

.portrait-trait-list li {
  font-size: 12px;
  line-height: 1.45;
  color: #4b554c;
}

.portrait-trait-list strong {
  display: block;
  color: #2d332e;
  font-size: 12px;
  margin-bottom: 2px;
}

.portrait-categories {
  display: grid;
  gap: 14px;
}

.portrait-cat-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  background: white;
  box-shadow: 0 6px 20px rgba(35, 44, 38, 0.04);
}

.portrait-cat-head {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 750;
  color: #1e2420;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.portrait-cat-count {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  background: #f0f2ed;
  padding: 2px 8px;
  border-radius: 6px;
}

.portrait-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.portrait-chip {
  font-size: 12px;
  line-height: 1.35;
  padding: 6px 10px;
  border-radius: 8px;
  background: #f4f6f2;
  border: 1px solid #e3e6e0;
  color: #384039;
  max-width: 100%;
}

.portrait-chip-more {
  background: #eef1eb;
  color: var(--muted);
  border-style: dashed;
}

.portrait-empty-hint {
  margin: 0;
  padding: 14px;
  border-radius: 10px;
  background: #fafbf9;
  border: 1px dashed var(--line);
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

.portrait-raw-details {
  margin-top: 8px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fafbf9;
  padding: 0 14px;
}

.portrait-raw-details summary {
  cursor: pointer;
  padding: 12px 0;
  font-size: 13px;
  font-weight: 650;
  color: var(--muted);
  list-style: none;
}

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

.portrait-pre--raw {
  max-height: 220px;
  margin-bottom: 12px;
}

.portrait-hero {
  display: flex;
  justify-content: center;
}

.portrait-hero-img {
  width: 96px;
  height: 96px;
  border-radius: 16px;
  object-fit: cover;
  border: 1px solid var(--line);
  background: var(--bg);
}

.portrait-dl {
  margin: 0;
  display: grid;
  gap: 0;
}

.portrait-dl-row {
  display: grid;
  grid-template-columns: minmax(100px, 28%) 1fr;
  gap: 12px 16px;
  padding: 10px 0;
  border-bottom: 1px solid #eef1eb;
  font-size: 14px;
}

.portrait-dl-row:last-child {
  border-bottom: 0;
}

.portrait-dl-row dt {
  margin: 0;
  color: var(--muted);
  font-weight: 600;
}

.portrait-dl-row dd {
  margin: 0;
  color: var(--text);
  word-break: break-word;
}

.portrait-json-block h4 {
  margin: 0 0 8px;
  font-size: 14px;
  color: #384039;
}

.portrait-pre {
  margin: 0;
  padding: 12px 14px;
  border-radius: 8px;
  background: #f4f6f2;
  border: 1px solid var(--line);
  font-size: 12px;
  line-height: 1.5;
  overflow: auto;
  max-height: 280px;
  white-space: pre-wrap;
  word-break: break-word;
}

@media (max-width: 520px) {
  .portrait-dl-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}

.delete-chat {
  min-height: 34px;
  border-radius: 8px;
  border: 0;
  background: #fff1ef;
  color: #c2412f;
  padding: 0 10px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(20px);
  z-index: 30;
  opacity: 0;
  pointer-events: none;
  background: #1f2a24;
  color: white;
  padding: 10px 14px;
  border-radius: 8px;
  transition: 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: rgba(21, 25, 22, 0.82);
  padding: 20px;
}

.modal img {
  max-width: min(920px, 94vw);
  max-height: 84dvh;
  border-radius: 8px;
}

.modal-close {
  position: fixed;
  top: calc(18px + env(safe-area-inset-top));
  right: 18px;
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
}

@media (max-width: 780px) {
  .auth-screen {
    display: block;
    min-height: 100dvh;
    padding: max(18px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom));
  }

  .auth-visual {
    height: 24dvh;
    min-height: 150px;
    border-radius: 8px;
    margin-bottom: 14px;
  }

  .auth-panel {
    width: 100%;
    padding: 22px;
  }

  .auth-panel h1 {
    font-size: 25px;
  }

  .chat-app {
    grid-template-columns: 1fr;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .side-nav {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    width: min(80vw, 300px);
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: var(--shadow);
  }

  .side-nav.open {
    transform: translateX(0);
  }

  /* 抽屉打开后的半透明遮罩层，点外部关闭由 JS 负责。 */
  .side-nav.open::after {
    content: "";
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: min(80vw, 300px);
    background: rgba(12, 20, 15, 0.35);
    z-index: -1;
    pointer-events: none;
    animation: scrimFade 0.18s ease;
  }

  @keyframes scrimFade {
    from { opacity: 0; }
    to { opacity: 1; }
  }

  .main-pane {
    height: 100dvh;
    min-height: 0;
  }

  .mobile-topbar {
    flex-shrink: 0;
    height: calc(48px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) 8px 0;
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr) 40px;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.96);
  }

  .mobile-topbar strong,
  .mobile-topbar span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: center;
  }

  .mobile-topbar strong {
    font-size: 15px;
  }

  .mobile-topbar span {
    color: var(--muted);
    font-size: 11px;
    margin-top: 1px;
  }

  .mobile-topbar .icon-btn {
    min-height: 36px;
    width: 36px;
    padding: 0;
    font-size: 18px;
  }

  .panel {
    flex: 1;
    min-height: 0;
    height: auto;
  }

  .chat-header {
    display: none;
  }

  .messages {
    padding: 10px 9px 12px;
    gap: 8px;
  }

  .message-row {
    margin: 9px 0;
    gap: 7px;
  }

  .bubble {
    max-width: 80%;
    padding: 9px 11px;
    font-size: 13.5px;
    line-height: 1.52;
    box-shadow: 0 3px 12px rgba(35, 44, 38, 0.06);
  }

  .time-divider {
    margin: 11px auto;
    font-size: 11px;
  }

  .image-bubble img {
    width: min(180px, 52vw);
  }

  .composer {
    grid-template-columns: 36px minmax(0, 1fr) 54px;
    gap: 5px;
    padding: 6px 7px calc(7px + env(safe-area-inset-bottom));
  }

  .composer textarea {
    min-height: 38px;
    font-size: 13.5px;
    padding: 8px 11px;
  }

  .composer textarea::placeholder {
    color: transparent;
  }

  .send-btn {
    min-height: 38px;
    font-size: 13px;
    padding: 0 9px;
  }

  .primary-btn,
  .outline-btn,
  .ghost-btn,
  .danger-btn {
    min-height: 40px;
    font-size: 14px;
  }

  .icon-btn.attach-btn {
    min-height: 38px;
    width: 36px;
  }

  .desktop-only {
    display: none;
  }

  .section-head {
    padding: 14px 14px;
  }

  .section-head h2 {
    font-size: 18px;
  }

  .section-head p {
    font-size: 12.5px;
  }

  .simple-form,
  .history-list {
    width: calc(100% - 20px);
    margin: 10px auto 18px;
  }

  .simple-form {
    padding: 14px;
    gap: 10px;
  }

  .simple-form label > span {
    font-size: 12px;
  }

  .simple-form input,
  .simple-form textarea,
  .simple-form select {
    font-size: 14px;
  }

  .split-head {
    align-items: flex-start;
  }

  .history-item {
    min-height: 60px;
    padding: 10px 12px;
  }
}

/* 大屏手机竖屏（含 iPhone 14 Pro 约 393px、15 Pro 等 ≤430）再压一档。 */
@media (max-width: 430px) {
  .messages {
    padding: 7px 6px 9px;
    gap: 7px;
  }

  .message-row {
    margin: 6px 0;
    gap: 6px;
  }

  .bubble {
    max-width: 86%;
    font-size: 12.75px;
    padding: 7px 9px;
    line-height: 1.48;
    border-radius: 7px;
    box-shadow: 0 2px 8px rgba(35, 44, 38, 0.05);
  }

  .image-bubble img {
    width: min(156px, 48vw);
  }

  .time-divider {
    margin: 8px auto;
    padding: 2px 7px;
    font-size: 10px;
  }

  .composer {
    grid-template-columns: 32px minmax(0, 1fr) 48px;
    gap: 4px;
    padding: 5px 5px calc(5px + env(safe-area-inset-bottom));
  }

  .composer textarea {
    min-height: 34px;
    font-size: 12.75px;
    padding: 6px 9px;
    line-height: 1.42;
  }

  .send-btn {
    min-height: 34px;
    font-size: 12px;
    padding: 0 7px;
  }

  .icon-btn.attach-btn {
    min-height: 34px;
    width: 32px;
  }

  .mobile-topbar {
    height: calc(42px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) 6px 0;
    grid-template-columns: 34px minmax(0, 1fr) 34px;
    gap: 6px;
  }

  .mobile-topbar strong {
    font-size: 13.5px;
  }

  .mobile-topbar span {
    font-size: 10px;
  }

  .mobile-topbar .icon-btn {
    min-height: 32px;
    width: 32px;
    font-size: 16px;
  }

  .section-head {
    padding: 12px 12px;
  }

  .section-head h2 {
    font-size: 17px;
  }

  .simple-form,
  .history-list {
    width: calc(100% - 14px);
    margin: 8px auto 14px;
  }

  .simple-form {
    padding: 12px;
  }
}

/* === 数字人卡片（配置中心） === */
.persona-card {
  border: 1px solid var(--line, #e5e7df);
  border-radius: 10px;
  background: #fff;
  padding: 14px 16px;
  margin: 8px 0 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.persona-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}

.persona-card-head strong {
  font-size: 15px;
  font-weight: 650;
  color: var(--text, #1f2320);
  display: block;
}

.persona-attempts {
  display: block;
  color: var(--muted, #6b7063);
  font-size: 12px;
  margin-top: 2px;
}

.persona-card-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.persona-card-actions .primary-btn,
.persona-card-actions .danger-btn {
  min-height: 34px;
  padding: 0 14px;
  font-size: 13px;
}

.persona-empty {
  margin: 0;
  color: var(--muted, #6b7063);
  font-size: 13px;
  line-height: 1.6;
}

.persona-hint {
  margin: 0;
  color: var(--muted, #6b7063);
  font-size: 12px;
  line-height: 1.6;
}

.persona-meta {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px 16px;
}

.persona-meta > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.persona-meta dt {
  font-size: 12px;
  color: var(--muted, #6b7063);
  margin: 0;
}

.persona-meta dd {
  font-size: 13px;
  color: var(--text, #1f2320);
  margin: 0;
  word-break: break-all;
}

/* === 注册数字人弹窗 === */
.modal-dialog {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(21, 25, 22, 0.55);
  padding: 20px;
}

.modal-dialog.hidden {
  display: none !important;
}

.modal-dialog-panel {
  width: min(440px, 100%);
  max-height: min(88dvh, 720px);
  overflow: auto;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.16);
  padding: 18px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

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

.modal-dialog-head .icon-btn {
  min-width: 30px;
  min-height: 30px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
}

.persona-form {
  margin: 0;
  gap: 12px;
}

.persona-modal-hint {
  margin: 0;
  color: var(--muted, #6b7063);
  font-size: 12px;
  line-height: 1.6;
}

body.modal-open {
  overflow: hidden;
}

@media (max-width: 780px) {
  .persona-card {
    padding: 12px 14px;
  }

  .modal-dialog-panel {
    padding: 16px 16px 18px;
  }
}

/* === Token 管理面板 === */
.token-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.token-kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

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

.token-kpi-value {
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
}

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

.token-balance-bar {
  margin-top: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
}

.token-balance-track {
  height: 10px;
  background: #eef2ec;
  border-radius: 999px;
  overflow: hidden;
}

.token-balance-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--green) 0%, var(--green-strong) 100%);
  border-radius: 999px;
  transition: width 0.3s ease;
}

.token-balance-text {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.token-charts {
  margin-top: 16px;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}

.token-chart-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px 10px;
}

.token-chart-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}

.token-chart-head strong {
  font-size: 14px;
  color: var(--text);
}

.token-chart-head span {
  font-size: 12px;
  color: var(--muted);
}

.token-chart-body {
  min-height: 160px;
}

.token-chart-svg {
  width: 100%;
  height: 180px;
  display: block;
}

.token-chart-grid {
  stroke: #e4e9e3;
  stroke-dasharray: 3 3;
  stroke-width: 1;
}

.token-chart-axis {
  fill: var(--muted);
  font-size: 10px;
}

.token-chart-area {
  fill: var(--chart-color, var(--green));
  fill-opacity: 0.12;
  stroke: none;
}

.token-chart-line {
  fill: none;
  stroke: var(--chart-color, var(--green));
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.token-chart-dot {
  fill: var(--chart-color, var(--green));
  stroke: #fff;
  stroke-width: 1.5;
}

.token-chart-bar {
  fill: var(--chart-color, var(--gold));
  rx: 3;
}

.token-chart-bar:hover {
  fill-opacity: 0.8;
}

.token-empty {
  margin: 20px 0;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.token-recharge-card {
  margin-top: 16px;
  background: var(--mint);
  border: 1px solid #c8ebd4;
  border-radius: 14px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
  flex-wrap: wrap;
}

.token-recharge-head {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.token-recharge-head strong {
  font-size: 14px;
  color: var(--green-strong);
}

.token-recharge-head span {
  color: var(--muted);
  font-size: 12px;
}

.token-lists {
  margin-top: 16px;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.token-list-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px 10px;
}

.section-head-sub {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}

.section-head-sub h3 {
  margin: 0;
  font-size: 14px;
  color: var(--text);
}

.section-head-sub span {
  font-size: 12px;
  color: var(--muted);
}

.token-table-wrap {
  overflow-x: auto;
}

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

.token-table th,
.token-table td {
  padding: 8px 6px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.token-table th {
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
}

.token-table tr:last-child td {
  border-bottom: none;
}

.token-table .token-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.token-table .token-strong {
  font-weight: 600;
  color: var(--green-strong);
}

.token-table .token-pos {
  color: var(--green-strong);
}

.token-table .token-neg {
  color: var(--coral);
}

.token-table .token-dim {
  color: var(--muted);
}

.recharge-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: -6px;
  margin-bottom: 4px;
}

.recharge-presets button {
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}

.recharge-presets button:hover {
  background: var(--mint);
  border-color: var(--green);
  color: var(--green-strong);
}

.modal-tip {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

/* === BT 后台 Token 用量管理 === */
.bt-token-usage-totals,
.bt-token-recharge-totals {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.bt-token-usage-totals .token-kpi,
.bt-token-recharge-totals .token-kpi {
  padding: 10px 12px;
}

.bt-token-filter-row select {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  color: var(--text);
  background: var(--surface);
  min-width: 140px;
}

.bt-token-channels-table,
.bt-token-accounts-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.bt-token-channels-table th,
.bt-token-channels-table td,
.bt-token-accounts-table th,
.bt-token-accounts-table td {
  padding: 9px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.bt-token-channels-table th,
.bt-token-accounts-table th {
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
  white-space: nowrap;
}

.bt-token-channels-table .token-num,
.bt-token-accounts-table .token-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.bt-token-filter-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.bt-token-filter-row label {
  display: flex;
  flex-direction: column;
  font-size: 12px;
  color: var(--muted);
  gap: 4px;
  min-width: 180px;
}

.bt-token-filter-row input {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  color: var(--text);
  background: var(--surface);
}

.bt-token-account-actions {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.bt-token-account-actions button {
  padding: 4px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}

.bt-token-account-actions button:hover {
  background: var(--mint);
  border-color: var(--green);
}

.bt-token-usage-section {
  margin-top: 16px;
}

.bt-token-usage-section h3 {
  margin: 0 0 8px;
  font-size: 14px;
  color: var(--text);
}

@media (max-width: 780px) {
  .token-kpis {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .token-kpi {
    padding: 10px 12px;
  }

  .token-kpi-value {
    font-size: 17px;
  }

  .token-kpi-label,
  .token-kpi-sub {
    font-size: 11.5px;
  }

  .token-charts {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .token-chart-svg {
    height: 140px;
  }

  .token-chart-head strong {
    font-size: 14px;
  }
}

@media (max-width: 430px) {
  .token-kpis {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }

  .token-kpi {
    padding: 8px 10px;
  }

  .token-kpi-value {
    font-size: 15.5px;
  }

  .token-chart-svg {
    height: 120px;
  }
}
