:root {
  --bg: #0b0e14;
  --surface: #131722;
  --surface-2: #1b2130;
  --border: rgba(255, 255, 255, 0.08);
  --text: #eef1f8;
  --muted: #8b95ad;
  --accent: #4d6bfe;
  --accent-2: #22d3ee;
  --green: #2ec27e;
  --red: #e5484d;
  --amber: #f0a92e;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

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

[hidden] {
  display: none !important;
}

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

/* ── 2FA 锁屏 ── */
.auth-gate {
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px 22px;
  text-align: center;
}

.auth-logo img {
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(77, 107, 254, 0.25);
}

.auth-card h1 {
  margin: 12px 0 6px;
  font-size: 20px;
}

.auth-sub {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 13px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.totp-input {
  width: 100%;
  height: 52px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  text-align: center;
  font-size: 26px;
  letter-spacing: 8px;
  font-weight: 600;
  outline: none;
}

.totp-input:focus {
  border-color: var(--accent);
}

.auth-error {
  margin-top: 12px;
  color: var(--red);
  font-size: 13px;
}

/* ── 主框架 ── */
.app-shell {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  flex: 0 0 auto;
  padding-top: var(--safe-top);
  min-height: calc(44px + var(--safe-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: 6px;
  padding-right: 6px;
  gap: 6px;
  user-select: none;
}

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

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

.topbar-title {
  flex: 1 1 auto;
  min-width: 0;
  border: none;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 4px;
  cursor: pointer;
}

.title-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
  font-size: 15px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  flex: 0 0 auto;
  animation: pulse 1.4s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

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

/* ── 对话区 ── */
.view-chat {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.messages-list {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 12px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.empty-state {
  margin: auto;
  color: var(--muted);
  text-align: center;
  font-size: 14px;
  padding: 24px;
}

.msg-card {
  border-radius: 14px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  position: relative;
}

.msg-user {
  align-self: flex-end;
  max-width: 88%;
  background: rgba(77, 107, 254, 0.16);
  border-color: rgba(77, 107, 254, 0.32);
}

.msg-assistant {
  background: var(--surface);
  width: 100%;
}

.msg-tool {
  background: rgba(255, 255, 255, 0.025);
  padding: 8px 10px;
  font-size: 13px;
}

.msg-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  user-select: none;
}

.msg-role {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

.copy-btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  border-radius: 8px;
  padding: 2px 8px;
  font-size: 11px;
  cursor: pointer;
  user-select: none;
}

.copy-btn:active {
  color: var(--text);
}

.msg-body {
  user-select: text;
  -webkit-user-select: text;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.msg-body p {
  margin: 0 0 8px;
}

.msg-body p:last-child {
  margin-bottom: 0;
}

.msg-body > :first-child {
  margin-top: 0;
}

.msg-body > :last-child {
  margin-bottom: 0;
}

.msg-body h1,
.msg-body h2,
.msg-body h3,
.msg-body h4,
.msg-body h5,
.msg-body h6 {
  margin: 14px 0 6px;
  font-weight: 600;
  line-height: 1.35;
  color: #f7f9ff;
}

.msg-body h1 { font-size: 18px; }
.msg-body h2 { font-size: 16.5px; }
.msg-body h3 { font-size: 15.5px; color: #dbe6ff; }
.msg-body h4,
.msg-body h5,
.msg-body h6 { font-size: 14.5px; color: #cbd5f5; }

.msg-body ul,
.msg-body ol {
  margin: 6px 0 8px;
  padding-left: 20px;
}

.msg-body li {
  margin: 3px 0;
  line-height: 1.55;
}

.msg-body li > ul,
.msg-body li > ol {
  margin: 3px 0 4px;
  padding-left: 16px;
}

.msg-body blockquote {
  margin: 8px 0;
  padding: 7px 11px;
  border-left: 3px solid var(--accent);
  background: rgba(77, 107, 254, 0.08);
  border-radius: 0 8px 8px 0;
  color: #cfd7ec;
  font-size: 14px;
}

.msg-body blockquote > p {
  margin: 0 0 4px;
}

.msg-body blockquote > p:last-child {
  margin-bottom: 0;
}

.msg-body hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 12px 0;
}

.msg-body a.md-link {
  color: var(--accent-2);
  text-decoration: underline;
  text-decoration-color: rgba(34, 211, 238, 0.45);
  text-underline-offset: 2px;
  word-break: break-all;
}

.msg-body .md-file-ref {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 6px;
  margin: 0 1px;
  border: 1px solid rgba(77, 107, 254, 0.35);
  border-radius: 5px;
  background: rgba(77, 107, 254, 0.14);
  color: #b8c7ff;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.4;
  cursor: pointer;
  vertical-align: baseline;
}

.msg-body .md-file-ref:active {
  background: rgba(77, 107, 254, 0.28);
}

.msg-body del {
  color: var(--muted);
  text-decoration: line-through;
}

.msg-body .table-wrapper {
  margin: 8px 0;
  overflow: auto;
  max-inline-size: 100%;
  max-block-size: min(420px, 65dvh);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(8, 10, 15, 0.55);
  -webkit-overflow-scrolling: touch;
}

.msg-body .table-wrapper table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
  line-height: 1.45;
}

.msg-body .table-wrapper thead {
  position: sticky;
  inset-block-start: 0;
  z-index: 1;
}

.msg-body .table-wrapper th {
  background: #1a2030;
  color: #f3f6ff;
  font-weight: 600;
  white-space: nowrap;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.msg-body .table-wrapper th,
.msg-body .table-wrapper td {
  padding: 7px 10px;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  vertical-align: top;
}

.msg-body .table-wrapper th:last-child,
.msg-body .table-wrapper td:last-child {
  border-right: 0;
}

.msg-body .table-wrapper td {
  min-width: 84px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.msg-body .table-wrapper tbody tr:last-child td {
  border-bottom: 0;
}

.msg-body .table-wrapper tbody tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.02);
}

.msg-body pre {
  margin: 8px 0;
  background: #080a0f;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.code-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 10px;
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  color: var(--muted);
  user-select: none;
}

.msg-body pre code {
  display: block;
  padding: 10px;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.45;
  user-select: text;
  -webkit-user-select: text;
}

.msg-body code:not(pre code) {
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 5px;
  border-radius: 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.think-details {
  margin-bottom: 8px;
  border-left: 2px solid rgba(77, 107, 254, 0.45);
  padding-left: 8px;
  color: var(--muted);
  font-size: 12px;
}

.think-details summary {
  cursor: pointer;
  user-select: none;
}

.proc-list {
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.proc-item {
  display: flex;
  align-items: baseline;
  gap: 6px;
  word-break: break-all;
}

.proc-item span {
  flex: 0 0 auto;
  color: var(--accent-2);
}

.think-text {
  margin-top: 6px;
  line-height: 1.45;
}

.tool-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.tool-cmd {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--accent-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tool-output {
  margin: 8px 0 0;
  padding: 8px;
  background: #080a0f;
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11.5px;
  max-height: 220px;
  overflow: auto;
  white-space: pre-wrap;
  user-select: text;
}

/* ── 待审批悬浮条 ── */
.pending-bar {
  background: #1b1710;
  border-top: 1px solid rgba(240, 169, 46, 0.4);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pending-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--amber);
}

.pending-detail {
  font-size: 12px;
  color: var(--text);
  background: rgba(0, 0, 0, 0.35);
  padding: 6px 8px;
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  max-height: 90px;
  overflow: auto;
  word-break: break-all;
}

.pending-actions {
  display: flex;
  gap: 8px;
}

/* ── 输入区（16px 防 iOS 缩放） ── */
.composer {
  position: relative;
  flex: 0 0 auto;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 8px 10px calc(8px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-input {
  width: 100%;
  min-height: 40px;
  max-height: 140px;
  resize: none;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 16px;
  line-height: 1.4;
  outline: none;
}

.chat-input:focus {
  border-color: var(--accent);
}

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

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 1 1 0;
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  white-space: nowrap;
}

.tool-icon-btn {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}

.tool-icon-btn:active {
  background: rgba(148, 163, 184, 0.2);
}

.tool-slash-btn {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 700;
  font-size: 15px;
  color: var(--accent-2);
}

.model-select {
  flex: 1 1 0;
  width: 0;
  min-width: 0;
  max-width: 100%;
  height: 34px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  padding: 0 8px;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mode-pill {
  flex: 0 0 auto;
  height: 34px;
  padding: 0 10px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.mode-pill.planning {
  color: var(--accent-2);
  border-color: rgba(34, 211, 238, 0.4);
}

.btn-send, .btn-stop, .btn-primary, .btn-secondary, .btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  flex-shrink: 0;
  height: 36px;
  padding: 0 14px;
  border: none;
  border-radius: 10px;
  font-weight: 600;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

.btn-send, .btn-stop {
  min-width: 58px;
}

.attachments-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 120px;
  overflow-y: auto;
}

.att-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 220px;
  padding: 4px 8px;
  border-radius: 9px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 12px;
}

.att-thumb {
  width: 28px;
  height: 28px;
  border-radius: 5px;
  object-fit: cover;
  flex-shrink: 0;
}

.att-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}

.att-remove {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  padding: 0 2px;
  cursor: pointer;
  flex-shrink: 0;
}

.slash-menu {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: calc(100% + 4px);
  max-height: 260px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 -8px 28px rgba(0, 0, 0, 0.45);
  z-index: 35;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.slash-menu[hidden] {
  display: none;
}

.slash-item {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  border-radius: 8px;
  padding: 7px 9px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.slash-item:hover,
.slash-item:active {
  background: rgba(77, 107, 254, 0.16);
  border-color: rgba(77, 107, 254, 0.35);
}

.slash-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
}

.slash-item-cmd {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--accent-2);
}

.slash-item-tag {
  font-size: 10.5px;
  font-weight: 500;
  color: var(--muted);
  background: rgba(148, 163, 184, 0.14);
  padding: 1px 6px;
  border-radius: 999px;
  flex-shrink: 0;
}

.slash-item-desc {
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg-attachments {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.msg-att-img {
  max-width: 180px;
  max-height: 180px;
  border-radius: 8px;
  border: 1px solid var(--border);
  object-fit: cover;
  cursor: pointer;
}

.msg-att-file {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 7px;
  background: rgba(148, 163, 184, 0.12);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--text);
}

.btn-send, .btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-stop, .btn-danger {
  background: var(--red);
  color: #fff;
}

.btn-secondary {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-ghost, .btn-ghost-sm {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 13px;
  cursor: pointer;
}

.btn-ghost-sm {
  padding: 3px 8px;
  font-size: 12px;
  color: var(--muted);
}

.full-w {
  width: 100%;
}

/* ── Token 用量页面 ── */
.view-usage {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 12px calc(24px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.usage-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.usage-meta {
  font-size: 12px;
  color: var(--muted);
}

.range-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  flex-shrink: 0;
}

.range-tab {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 13px;
  cursor: pointer;
}

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

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  flex-shrink: 0;
}

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

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

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

.kpi-sub {
  margin-top: 2px;
  font-size: 11px;
  color: var(--muted);
}

.card-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  flex-shrink: 0;
}

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

.card-section h2 {
  margin: 0;
  font-size: 14px;
}

.daily-row {
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

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

.daily-top {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
}

.daily-bar-wrap {
  height: 6px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
}

.daily-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 999px;
}

.daily-sub {
  font-size: 11.5px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
}

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

.model-card {
  width: 100%;
  text-align: left;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 10px;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
}

.model-card.active {
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.12);
}

.model-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.model-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.model-right {
  flex-shrink: 0;
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.model-share {
  font-size: 11.5px;
  color: var(--accent-2);
}

.model-bar {
  background: linear-gradient(90deg, #38bdf8, #818cf8);
}

.source-bar {
  background: linear-gradient(90deg, #34d399, #38bdf8);
}

.usage-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.source-badge {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.14);
  color: var(--muted);
}

.source-badge.ok {
  background: rgba(16, 185, 129, 0.14);
  color: #34d399;
}

.source-badge.offline {
  background: rgba(239, 68, 68, 0.14);
  color: #f87171;
}

.source-note {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.35;
}

/* ── 用量页实时状态胶囊 & API 等值金额订阅对比 ── */
.capsule-head-left {
  display: flex;
  align-items: center;
  gap: 6px;
}

.conv-select-pwa {
  max-width: 150px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 3px 6px;
  font-size: 12px;
}

.capsule-body-pwa,
.cost-body-pwa {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pool-list-pwa {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.pool-pill-pwa {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 7px 9px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-variant-numeric: tabular-nums;
}

.pool-top-pwa {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--muted);
}

.pool-top-pwa strong {
  color: var(--text);
}

.pool-reset-pwa {
  font-size: 11px;
  color: var(--accent-2);
}

.ctx-box-pwa {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ctx-box-pwa.near {
  border-color: rgba(224, 122, 95, 0.7);
}

.ctx-head-pwa {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.ctx-bar-pwa-wrap {
  height: 7px;
  background: rgba(148, 163, 184, 0.16);
  border-radius: 999px;
  overflow: hidden;
}

.ctx-bar-pwa-fill {
  height: 100%;
  border-radius: 999px;
}

.ctx-bar-pwa-fill.sage {
  background: linear-gradient(90deg, #52b788, #81b29a);
}

.ctx-bar-pwa-fill.amber {
  background: linear-gradient(90deg, #d4a373, #e9c46a);
}

.ctx-bar-pwa-fill.coral {
  background: linear-gradient(90deg, #e07a5f, #ef4444);
}

.metrics-line-pwa {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  font-size: 12px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.capsule-alert-pwa {
  padding: 6px 9px;
  border-radius: 8px;
  font-size: 11.5px;
  line-height: 1.4;
}

.capsule-alert-pwa.warn {
  background: rgba(224, 122, 95, 0.16);
  border: 1px solid rgba(224, 122, 95, 0.45);
  color: #fca5a5;
}

.capsule-alert-pwa.info {
  background: rgba(56, 189, 248, 0.14);
  border: 1px solid rgba(56, 189, 248, 0.35);
  color: var(--accent-2);
}

.currency-tabs-pwa {
  display: flex;
  align-items: center;
  gap: 5px;
}

.pill-pwa {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 11.5px;
  cursor: pointer;
}

.pill-pwa.active {
  background: rgba(77, 107, 254, 0.25);
  border-color: var(--accent);
  color: var(--text);
  font-weight: 600;
}

.roi-grid-pwa {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
}

.roi-cell-pwa {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 8px;
}

.roi-label-pwa {
  font-size: 11px;
  color: var(--muted);
}

.roi-val-pwa {
  margin-top: 2px;
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.roi-val-pwa.ok {
  color: #34d399;
}

.roi-sub-pwa {
  margin-top: 2px;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.sub-config-pwa {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 11.5px;
  color: var(--muted);
}

.sub-field-pwa {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.sub-input-pwa {
  width: 56px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 6px;
  font-size: 12px;
  text-align: right;
}

.item-cost-pwa {
  font-size: 11.5px;
  font-weight: 600;
  color: #34d399;
  margin-left: 4px;
}

.reset-banner-pwa {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 9px;
  background: rgba(77, 107, 254, 0.14);
  border: 1px solid rgba(77, 107, 254, 0.35);
  font-size: 12px;
  color: var(--text);
}

.reset-banner-pwa[hidden] {
  display: none;
}

/* ── 抽屉与弹窗 ── */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.58);
  z-index: 40;
  display: flex;
}

.drawer-panel {
  width: 88%;
  max-width: 360px;
  height: 100%;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

.drawer-head, .modal-head {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.drawer-head-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.conversation-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.conv-item {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: var(--surface-2);
  border-radius: 11px;
  padding: 10px 12px;
  cursor: pointer;
}

.conv-item.active {
  border-color: var(--accent);
  background: rgba(77, 107, 254, 0.14);
}

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

.conv-meta {
  margin-top: 3px;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.drawer-foot {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
}

.modal-body {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 70dvh;
  overflow-y: auto;
}

.modal-foot {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
}

.field-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.field-select, .field-textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 10px;
  color: var(--text);
  font-size: 16px;
}

.device-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  gap: 8px;
}

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

.qr-wrap {
  background: #fff;
  padding: 12px;
  border-radius: 12px;
  text-align: center;
}

.qr-wrap svg {
  width: 180px;
  height: 180px;
}

.qr-guide {
  color: #1f2937;
  font-size: 12px;
  line-height: 1.5;
  text-align: left;
  margin-top: 8px;
}

.qr-secret-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
  padding: 6px 8px;
  background: #f3f4f6;
  border-radius: 8px;
}

.qr-secret-code {
  color: #111827;
  font-size: 11px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  word-break: break-all;
  text-align: left;
}

.qr-copy-btn {
  flex-shrink: 0;
  padding: 4px 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
  color: #111827;
  font-size: 12px;
  cursor: pointer;
}

.toast {
  position: fixed;
  bottom: calc(82px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20, 25, 38, 0.96);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 80;
}
