/* =========================================================================
   AI API 中转站 · 手机端 H5 用户站样式
   -------------------------------------------------------------------------
   全部样式集中在本文件，无外部依赖。
   想换主题色：只改 :root 里的 --brand / --brand-2 / --brand-soft 即可。
   ========================================================================= */

/* ----------------------------------------------------------- 设计变量 */
:root {
  --brand: #3d6df5;
  --brand-2: #6b8cff;
  --brand-soft: #eef2ff;
  --brand-text: #2f5be0;
  --brand-ring: rgba(61, 109, 245, .16);
  --brand-glow: rgba(61, 109, 245, .45);

  --bg-blur: rgba(244, 245, 249, .86);
  --card-blur: rgba(255, 255, 255, .92);

  --bg: #f4f5f9;
  --card: #ffffff;
  --text: #14161f;
  --text-2: #4c5364;
  --muted: #858da1;
  --line: #eceef4;
  --line-2: #f4f5f9;

  --ok: #12b76a;
  --ok-soft: #e7f8f0;
  --warn: #f79009;
  --warn-soft: #fff5e6;
  --danger: #f04438;
  --danger-soft: #fdeceb;

  --radius: 16px;
  --radius-sm: 10px;
  --radius-lg: 22px;
  --shadow: 0 1px 2px rgba(20, 22, 31, .04), 0 8px 24px -12px rgba(20, 22, 31, .14);
  --shadow-pop: 0 12px 40px -8px rgba(20, 22, 31, .28);

  --max-w: 520px;
  --tab-h: 58px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);

  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --brand: #5b83ff;
    --brand-2: #86a2ff;
    --brand-soft: #1c2440;
    --brand-text: #a8bcff;
    --brand-ring: rgba(91, 131, 255, .22);
    --brand-glow: rgba(0, 0, 0, .6);

    --bg-blur: rgba(15, 17, 22, .88);
    --card-blur: rgba(24, 27, 35, .94);

    --bg: #0f1116;
    --card: #181b23;
    --text: #eff1f6;
    --text-2: #b8bfd0;
    --muted: #7d8598;
    --line: #262a34;
    --line-2: #1e222b;

    --ok-soft: #10301f;
    --warn-soft: #33260f;
    --danger-soft: #3a1b19;

    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px -14px rgba(0, 0, 0, .7);
    --shadow-pop: 0 12px 40px -8px rgba(0, 0, 0, .75);
  }
}

/* ----------------------------------------------------------- 基础重置 */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
               "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

h1, h2, h3, h4, p, ul, ol, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
a { color: var(--brand-text); text-decoration: none; }
button, input, textarea, select { font: inherit; color: inherit; }
svg { width: 1em; height: 1em; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }
code, pre, .mono { font-family: var(--mono); }
.noscript { padding: 40px 20px; text-align: center; color: var(--muted); }

/* ----------------------------------------------------------- 外壳布局 */
.app {
  position: relative;
  max-width: var(--max-w);
  min-height: 100vh;
  margin: 0 auto;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

/* 顶部栏 */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(12px + var(--safe-t)) 16px 12px;
  background: var(--bg-blur);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid transparent;
  transition: border-color .2s;
}
.topbar.is-stuck { border-bottom-color: var(--line); }
.topbar-main { flex: 1; min-width: 0; }
.topbar-title { font-size: 19px; font-weight: 700; letter-spacing: .2px; }
.topbar-sub {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-height: 18px;
}
.topbar-btn {
  width: 36px; height: 36px;
  flex: none;
  display: grid; place-items: center;
  border: none; border-radius: 50%;
  background: var(--card);
  color: var(--text-2);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .15s, color .15s;
}
.topbar-btn svg { width: 18px; height: 18px; }
.topbar-btn:active { transform: scale(.92); color: var(--brand); }
.topbar-btn.is-spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* 内容区 */
.page {
  flex: 1;
  padding: 4px 16px calc(var(--tab-h) + var(--safe-b) + 26px);
}
.page.is-plain { padding-bottom: calc(28px + var(--safe-b)); }

/* 底部 Tab */
.tabbar {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  z-index: 40;
  width: 100%;
  max-width: var(--max-w);
  display: flex;
  padding-bottom: var(--safe-b);
  background: var(--card-blur);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-top: 1px solid var(--line);
}
.tab {
  flex: 1;
  height: var(--tab-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--muted);
  font-size: 11px;
  transition: color .15s;
}
.tab svg { width: 22px; height: 22px; }
.tab:active { opacity: .7; }
.tab.is-active { color: var(--brand); }
.tab.is-active svg { stroke-width: 2.1; }

/* ----------------------------------------------------------- 通用卡片 */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-top: 12px;
}
.card.tight { padding: 12px 14px; }
.card.flush { padding: 6px 0; }
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.card-head h2 { font-size: 15px; font-weight: 650; }
.card-head .sub { font-size: 12px; color: var(--muted); }
.card-title { font-size: 13px; color: var(--muted); font-weight: 500; }
.section-title {
  display: flex; align-items: center; gap: 8px;
  margin: 22px 2px 2px;
  font-size: 13px; font-weight: 600; color: var(--muted);
}
.section-title::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* 余额大卡 */
.balance-card {
  position: relative;
  overflow: hidden;
  margin-top: 8px;
  padding: 20px;
  border-radius: var(--radius-lg);
  color: #fff;
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-2) 100%);
  box-shadow: 0 14px 34px -16px var(--brand-glow);
}
.balance-card::after {
  content: "";
  position: absolute;
  right: -46px; top: -56px;
  width: 168px; height: 168px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .14);
}
.balance-card::before {
  content: "";
  position: absolute;
  right: 34px; bottom: -70px;
  width: 118px; height: 118px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .1);
}
.balance-label { position: relative; font-size: 12.5px; opacity: .88; letter-spacing: .3px; }
.balance-value {
  position: relative;
  display: flex;
  align-items: baseline;
  gap: 2px;
  margin: 6px 0 4px;
  font-size: 40px;
  font-weight: 700;
  letter-spacing: -.5px;
  font-variant-numeric: tabular-nums;
}
.balance-value .cny { font-size: 22px; font-weight: 600; opacity: .92; }
.balance-sub { position: relative; font-size: 12px; opacity: .85; }
.balance-actions { position: relative; display: flex; gap: 10px; margin-top: 16px; }
.balance-actions .btn {
  flex: 1;
  background: rgba(255, 255, 255, .18);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, .28);
  box-shadow: none;
  backdrop-filter: blur(4px);
}
.balance-actions .btn:active { background: rgba(255, 255, 255, .3); }

/* 统计格 */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stats.two { grid-template-columns: repeat(2, 1fr); }
.stat {
  background: var(--line-2);
  border-radius: var(--radius-sm);
  padding: 11px 10px;
  text-align: center;
}
@media (prefers-color-scheme: dark) { .stat { background: #1f232c; } }
.stat .k { font-size: 11.5px; color: var(--muted); }
.stat .v { margin-top: 3px; font-size: 16px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat .v.sm { font-size: 14px; }

/* 行 / 键值 */
.kv { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 0; }
.kv + .kv { border-top: 1px solid var(--line-2); }
.kv .k { color: var(--muted); font-size: 13px; flex: none; }
.kv .v { text-align: right; font-size: 13.5px; word-break: break-all; font-variant-numeric: tabular-nums; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 颜色语义 */
.money { font-variant-numeric: tabular-nums; font-weight: 650; }
.money.plus { color: var(--ok); }
.money.minus { color: var(--danger); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
.ok-text { color: var(--ok); }
.danger-text { color: var(--danger); }
.center { text-align: center; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.nowrap { white-space: nowrap; }

/* ----------------------------------------------------------- 按钮 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 44px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: var(--line-2);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .12s, opacity .15s, background .15s;
  white-space: nowrap;
}
@media (prefers-color-scheme: dark) { .btn { background: #232732; } }
.btn:active { transform: scale(.975); }
.btn[disabled], .btn.is-disabled { opacity: .5; pointer-events: none; }
.btn svg { width: 17px; height: 17px; }
.btn-primary {
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-2) 100%);
  color: #fff;
  box-shadow: 0 8px 20px -10px var(--brand-glow);
}
.btn-ghost { background: transparent; border-color: var(--line); color: var(--text-2); }
.btn-soft { background: var(--brand-soft); color: var(--brand-text); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-block { display: flex; width: 100%; }
.btn-sm { height: 34px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.btn-xs { height: 28px; padding: 0 10px; font-size: 12px; border-radius: 8px; gap: 4px; }
.btn-xs svg { width: 14px; height: 14px; }
.btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
  content: "";
  position: absolute;
  width: 17px; height: 17px;
  border: 2px solid currentColor;
  border-radius: 50%;
  border-top-color: transparent;
  color: var(--text);
  animation: spin .7s linear infinite;
}
.btn-primary.is-loading::after { color: #fff; }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { flex: 1; }

/* 分段控件 */
.seg {
  position: relative;
  display: flex;
  padding: 3px;
  border-radius: 12px;
  background: var(--line-2);
}
@media (prefers-color-scheme: dark) { .seg { background: #1f232c; } }
.seg button {
  position: relative;
  z-index: 1;
  flex: 1;
  height: 36px;
  border: none;
  background: transparent;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: color .18s;
}
.seg button.is-active { color: var(--brand-text); background: var(--card); box-shadow: var(--shadow); }

/* ----------------------------------------------------------- 表单 */
.field { margin-top: 14px; }
.field > label { display: block; font-size: 13px; color: var(--text-2); font-weight: 500; margin-bottom: 6px; }
.input, textarea.input {
  width: 100%;
  height: 46px;
  padding: 0 14px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  font-variant-numeric: tabular-nums;
}
@media (prefers-color-scheme: dark) { .input, textarea.input { background: #1f232c; } }
textarea.input { height: auto; min-height: 84px; padding: 12px 14px; resize: vertical; line-height: 1.5; }
.input::placeholder { color: var(--muted); }
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3.5px var(--brand-ring); }
.input.is-error { border-color: var(--danger); }
.input-group { display: flex; gap: 8px; }
.input-group .input { flex: 1; min-width: 0; }
.input-group .btn { flex: none; height: 46px; min-width: 108px; font-size: 14px; }
.field-hint { margin-top: 6px; font-size: 12px; color: var(--muted); }
.field-hint.err { color: var(--danger); }
.field-hint.ok { color: var(--ok); }
.input-prefix { position: relative; }
.input-prefix .input { padding-left: 34px; }
.input-prefix .sign {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-weight: 600; pointer-events: none;
}

/* 金额档位 */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  flex: 1 1 calc(33.333% - 6px);
  min-width: 82px;
  height: 46px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: .15s;
  font-variant-numeric: tabular-nums;
}
@media (prefers-color-scheme: dark) { .chip { background: #1f232c; } }
.chip.is-active { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-text); }

/* 开关 */
.switch {
  position: relative;
  width: 46px; height: 27px;
  flex: none;
  border: none;
  border-radius: 99px;
  background: var(--line);
  cursor: pointer;
  transition: background .2s;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 21px; height: 21px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .25);
  transition: transform .2s;
}
.switch.is-on { background: var(--ok); }
.switch.is-on::after { transform: translateX(19px); }

/* ----------------------------------------------------------- 列表 */
.list-item { padding: 13px 16px; }
.list-item + .list-item { border-top: 1px solid var(--line-2); }
.list-item.tappable { cursor: pointer; }
.list-item.tappable:active { background: var(--line-2); }
.item-title { font-size: 14.5px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.item-sub { margin-top: 3px; font-size: 12px; color: var(--muted); }
.item-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 6px; font-size: 12px; color: var(--text-2); }
.item-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

.badge {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 8px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 600;
  background: var(--line-2);
  color: var(--text-2);
  white-space: nowrap;
}
@media (prefers-color-scheme: dark) { .badge { background: #232732; } }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.brand { background: var(--brand-soft); color: var(--brand-text); }

.log-item { padding: 13px 16px; }
.log-item + .log-item { border-top: 1px solid var(--line-2); }
.log-item.is-error .item-title { color: var(--danger); }
.log-main { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.log-model { font-size: 14.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-error {
  margin-top: 8px;
  padding: 9px 11px;
  border-radius: 9px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 12px;
  word-break: break-all;
  font-family: var(--mono);
  line-height: 1.45;
}

/* 空状态 / 骨架屏 */
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty .icon { font-size: 30px; line-height: 1; opacity: .65; }
.empty .txt { margin-top: 10px; font-size: 13.5px; }
.empty .btn { margin-top: 14px; }
.empty.sm { padding: 26px 16px; }

.skeleton { padding: 14px 16px; }
.sk-line {
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--line-2) 25%, var(--line) 37%, var(--line-2) 63%);
  background-size: 400% 100%;
  animation: sk 1.3s ease-in-out infinite;
}
@media (prefers-color-scheme: dark) { .sk-line { background: linear-gradient(90deg, #1e222b 25%, #2a2f3a 37%, #1e222b 63%); background-size: 400% 100%; } }
.sk-line + .sk-line { margin-top: 10px; }
.sk-line.w40 { width: 40%; }
.sk-line.w60 { width: 60%; }
.sk-line.w75 { width: 75%; }
.sk-block { height: 84px; border-radius: var(--radius); margin-top: 12px; }
@keyframes sk { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ----------------------------------------------------------- 二维码 / 代码 */
.qr-box { text-align: center; }
.qr-frame {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  margin: 4px auto 0;
  border-radius: var(--radius);
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  min-width: 200px;
  min-height: 200px;
}
.qr-frame img { width: 236px; height: 236px; max-width: 68vw; max-height: 68vw; object-fit: contain; display: block; }
.qr-text {
  max-width: 100%;
  margin: 0 auto;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: var(--line-2);
  font-family: var(--mono);
  font-size: 12px;
  word-break: break-all;
  text-align: left;
  max-height: 180px;
  overflow: auto;
}
@media (prefers-color-scheme: dark) { .qr-text { background: #1f232c; } }

.code-block {
  margin: 0;
  padding: 12px 13px;
  border-radius: var(--radius-sm);
  background: #10131b;
  color: #d7e0f5;
  font-size: 11.5px;
  line-height: 1.62;
  overflow-x: auto;
  white-space: pre;
  -webkit-overflow-scrolling: touch;
}
.code-wrap { position: relative; margin-top: 10px; }
.code-wrap .copy-btn { position: absolute; top: 8px; right: 8px; }

.notice {
  display: flex;
  gap: 9px;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  background: var(--warn-soft);
  color: #8a5300;
  font-size: 12.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
@media (prefers-color-scheme: dark) { .notice { color: #f7cf94; } }
.notice .ico { flex: none; }

/* 快捷入口 */
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.quick button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 4px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--line-2);
  color: var(--text-2);
  font-size: 12px;
  cursor: pointer;
  transition: transform .12s;
}
@media (prefers-color-scheme: dark) { .quick button { background: #1f232c; } }
.quick button:active { transform: scale(.95); }
.quick .q-ico {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: var(--brand-soft);
  color: var(--brand-text);
  font-size: 17px;
}
.quick .q-ico svg { width: 18px; height: 18px; }

/* ----------------------------------------------------------- Toast */
.toast-wrap {
  position: fixed;
  left: 0; right: 0;
  top: calc(12px + var(--safe-t));
  z-index: 90;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  pointer-events: none;
}
.toast {
  max-width: min(420px, 100%);
  padding: 11px 15px;
  border-radius: 12px;
  background: rgba(20, 22, 31, .9);
  color: #fff;
  font-size: 13.5px;
  line-height: 1.45;
  box-shadow: var(--shadow-pop);
  display: flex;
  align-items: flex-start;
  gap: 8px;
  word-break: break-word;
  animation: toast-in .22s cubic-bezier(.2, .9, .3, 1.2);
  backdrop-filter: blur(6px);
}
.toast.out { animation: toast-out .2s ease forwards; }
.toast .ico { flex: none; }
.toast.ok { background: rgba(9, 122, 89, .94); }
.toast.err { background: rgba(190, 42, 34, .94); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-14px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-10px) scale(.97); } }

/* ----------------------------------------------------------- 弹窗 */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(12, 14, 20, .45);
  backdrop-filter: blur(2px);
  animation: fade-in .18s ease;
}
.overlay.is-center { align-items: center; padding: 20px; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.sheet {
  width: 100%;
  max-width: var(--max-w);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding-bottom: var(--safe-b);
  animation: sheet-up .26s cubic-bezier(.2, .85, .3, 1);
  overflow: hidden;
}
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: none; } }
.dialog {
  width: 100%;
  max-width: 340px;
  max-height: 84vh;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
  animation: pop-in .2s cubic-bezier(.2, .9, .3, 1.2);
  overflow: hidden;
}
@keyframes pop-in { from { opacity: 0; transform: scale(.92); } to { opacity: 1; transform: none; } }
.sheet-head, .dialog-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px 12px;
  flex: none;
}
.sheet-head h3, .dialog-head h3 { flex: 1; font-size: 16.5px; font-weight: 700; }
.dialog-head h3 { text-align: center; }
.sheet-close {
  flex: none;
  width: 30px; height: 30px;
  border: none;
  border-radius: 50%;
  background: var(--line-2);
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}
.sheet-body, .dialog-body { padding: 0 18px 4px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.dialog-body { padding-top: 2px; }
.sheet-foot, .dialog-foot {
  display: flex;
  gap: 10px;
  padding: 14px 18px calc(16px + var(--safe-b));
  flex: none;
}
.dialog-foot { padding-bottom: 18px; }
.sheet-foot .btn, .dialog-foot .btn { flex: 1; }
.dialog-msg { font-size: 14px; color: var(--text-2); line-height: 1.6; word-break: break-word; }

/* 明文密钥展示 */
.secret-box {
  padding: 14px;
  border-radius: var(--radius-sm);
  background: var(--line-2);
  border: 1px dashed var(--brand);
  font-family: var(--mono);
  font-size: 13.5px;
  word-break: break-all;
  user-select: all;
  -webkit-user-select: all;
}
@media (prefers-color-scheme: dark) { .secret-box { background: #1f232c; } }
.warn-box {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 12.5px;
  line-height: 1.55;
}

/* 桌面端微调 */
@media (min-width: 560px) {
  body { padding: 0 0 24px; }
  .app { min-height: calc(100vh - 24px); margin-top: 24px; border-radius: 24px; overflow: hidden; box-shadow: var(--shadow); }
  .tabbar { bottom: 24px; border-radius: 0 0 24px 24px; }
  .page { padding-left: 20px; padding-right: 20px; }
}

/* =====================================================================
   在线聊天页（#/chat）
   —— 6 个 tab 时也不能换行/裁剪；输入区固定贴在 tabbar 之上，
      左右各留 16px，320 ~ 430px 均不横向溢出。
   ===================================================================== */

.page.is-chat { padding: 0 0 calc(var(--tab-h) + var(--safe-b) + 10px); }

/* 顶部：可用余额 + 模型选择（吸附在顶栏正下方，滚动时始终可见） */
.chat-bar {
  position: sticky;
  top: 0;                        /* 由 JS 设成顶栏高度 */
  z-index: 20;
  padding: 2px 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.chat-bar-info {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-top: 5px;
  font-size: 11px;
  color: var(--muted);
}
.chat-balance { flex: none; color: var(--brand-text); font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.chat-model-price { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-model-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-height: 40px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.chat-model-btn[disabled] { opacity: .6; }
.chat-model-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-model-caret { flex: none; width: 16px; height: 16px; color: var(--muted); }

/* 消息列表 */
.chat-list { padding: 2px 16px 96px; min-height: 42vh; }
.chat-msg { display: flex; flex-direction: column; max-width: 86%; margin-top: 12px; }
.chat-msg.is-user { margin-left: auto; align-items: flex-end; }
.chat-msg.is-ai { margin-right: auto; align-items: flex-start; }
.chat-bubble {
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  color: var(--text);
  font-size: 15px;
  line-height: 1.58;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  box-shadow: var(--shadow);
}
.chat-msg.is-user .chat-bubble {
  border-color: transparent;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff;
}
.chat-meta { margin-top: 4px; padding: 0 4px; font-size: 11px; color: var(--muted); }
.chat-meta:empty { display: none; }
@keyframes chatBlink { 0%, 100% { opacity: 1; } 50% { opacity: .2; } }
.chat-msg[data-state="streaming"] .chat-bubble::after {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-left: 4px;
  border-radius: 50%;
  background: var(--brand);
  vertical-align: middle;
  animation: chatBlink 1s linear infinite;
}
.chat-msg[data-state="stopped"] .chat-bubble { opacity: .72; }

/* 推理模型的思考过程（DeepSeek-R1 / V4-Flash 等）：默认折叠，展开后是暗色小字 */
.chat-think {
  max-width: 100%;
  margin-bottom: 6px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: color-mix(in srgb, var(--card) 70%, transparent);
  font-size: 12px;
  color: var(--muted);
}
.chat-think > summary {
  padding: 6px 10px;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.chat-think > summary::-webkit-details-marker { display: none; }
.chat-think > summary::before { content: '💡 '; }
.chat-think[open] > summary { border-bottom: 1px dashed var(--line); }
.chat-think-n { margin-left: 6px; opacity: .7; }
.chat-think-body {
  max-height: 40vh;
  overflow-y: auto;
  padding: 8px 10px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.chat-typing { opacity: .6; }

/* 系统 / 错误提示：居中（同时带 .chat-msg，这里要盖掉它的 flex 布局） */
.chat-sys {
  display: block;
  max-width: 92%;
  margin: 12px auto;
  padding: 9px 12px;
  border-radius: 12px;
  background: var(--line-2);
  color: var(--text-2);
  font-size: 12.5px;
  line-height: 1.55;
  text-align: center;
  overflow-wrap: anywhere;
}
.chat-sys.is-error { background: var(--danger-soft); color: var(--danger); }
.chat-sys-hint { margin-top: 4px; opacity: .92; }
.chat-sys .btn { margin-top: 8px; }
.chat-sys .btn + .btn { margin-left: 8px; }

/* 空态 / 欢迎 */
.chat-welcome { padding: 30px 10px 8px; text-align: center; }
.chat-welcome-ico { font-size: 34px; line-height: 1; }
.chat-welcome-title { margin-top: 10px; font-size: 16px; font-weight: 650; }
.chat-welcome-sub { margin-top: 6px; font-size: 12.5px; color: var(--muted); line-height: 1.6; }
.chat-welcome-chips { margin-top: 14px; justify-content: center; }
.chat-empty { padding: 46px 16px; text-align: center; color: var(--muted); font-size: 13px; }

/* 底部输入区（fixed，贴在 tabbar 之上；--kb 由 JS 按虚拟键盘高度设置） */
.chat-composer {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tab-h) + var(--safe-b) + var(--kb, 0px));
  z-index: 35;
  width: 100%;
  max-width: var(--max-w);
  transform: translateX(-50%);
  padding: 8px 12px;
  background: var(--card-blur);
  backdrop-filter: saturate(160%) blur(14px);
  border-top: 1px solid var(--line);
}
.chat-composer-inner { display: flex; align-items: flex-end; gap: 8px; }
.chat-input {
  flex: 1;
  min-width: 0;
  max-height: 140px;
  padding: 10px 12px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text);
  font-family: inherit;
  font-size: 16px;              /* 16px：避免 iOS 聚焦时自动放大页面 */
  line-height: 22px;
  resize: none;
  overflow-y: hidden;
  appearance: none;
  -webkit-appearance: none;
}
.chat-input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3.5px var(--brand-ring); }
.chat-input::placeholder { color: var(--muted); font-size: 14px; }
.chat-send {
  flex: none;
  min-width: 68px;
  height: 44px;
  padding: 0 14px;
  border: none;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.chat-send.is-stop { background: var(--danger); }
.chat-send:active { opacity: .88; }

/* 模型选择弹层 */
.chat-model-list { display: flex; flex-direction: column; gap: 8px; padding: 2px 0 6px; }
.chat-model-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 12px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.chat-model-item.is-active { border-color: var(--brand); background: var(--brand-soft); }
.chat-model-item-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.chat-model-item-name { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-model-item-id { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-model-item-price { font-size: 11px; color: var(--muted); }
.chat-model-check { flex: none; color: var(--brand); font-weight: 700; }
.chat-model-none { padding: 26px 10px; text-align: center; color: var(--muted); font-size: 13px; }

/* 6 个 tab：等分且不换行、不裁剪（390px / 320px 都不横向溢出） */
.tabbar .tab { flex: 1 1 0; min-width: 0; }
.tabbar .tab span { white-space: nowrap; }

/* 桌面端：tabbar 上移了 24px，输入区跟着上移 */
@media (min-width: 560px) {
  .chat-composer { bottom: calc(24px + var(--tab-h) + var(--safe-b) + var(--kb, 0px)); }
}
