/* 颜色全部跟 Telegram 主题变量走;浏览器里打开时用后面的兜底值,并按系统深浅色切换。
   老客户端没有 section_bg_color / section_separator_color 时退到 bg_color / hint,深色主题下不会出现白卡片。 */
:root {
  --fb-card: #ffffff; --fb-sep: rgba(0, 0, 0, 0.08);
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f2f3f7);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, var(--fb-card)));
  --text: var(--tg-theme-text-color, #111318);
  --hint: var(--tg-theme-hint-color, #6b7280);
  --link: var(--tg-theme-link-color, #2f6fed);
  --accent: var(--tg-theme-button-color, #5b5bf0);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --sep: var(--tg-theme-section-separator-color, var(--fb-sep));
  /* 文字用的颜色在白底上对比度都 ≥ 4.5:1 */
  --danger: #c62828;
  --ok: #1e7b45;
  --warn: #d98c1f;        /* 只做边框 / 底色 */
  --warn-text: #995a00;   /* 文字 */
  --radius: 14px;
  --gutter: 16px;
  --tab-h: 58px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not(.tg) {
    --bg: #17212b; --bg2: #0f1720; --card: #1f2b38; --text: #f1f3f5; --hint: #8a98a8;
    --link: #6ab2f2; --accent: #5288c1; --accent-text: #fff; --sep: rgba(255, 255, 255, 0.08);
    --danger: #ff7b72; --ok: #4cc27a; --warn-text: #f0b45a;
  }
}
:root.tg-dark {
  color-scheme: dark;
  --fb-card: #1f2b38; --fb-sep: rgba(255, 255, 255, 0.08);
  --danger: #ff7b72; --ok: #4cc27a; --warn-text: #f0b45a;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg2);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Noto Sans CJK SC", sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--tab-h) + var(--safe-b));
  min-height: 100vh;
}
body.no-tabs { padding-bottom: calc(var(--safe-b) + 16px); }
a { color: var(--link); text-decoration: none; }
button { font: inherit; }
[hidden] { display: none !important; }

/* 顶栏 */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  height: 48px; padding: 0 var(--gutter);
  background: var(--bg); border-bottom: 1px solid var(--sep);
}
.topbar-title { font-weight: 600; font-size: 16px; }
.back-btn {
  border: 0; background: transparent; color: var(--link);
  font-size: 30px; line-height: 1; padding: 0 8px 4px 0; cursor: pointer;
  min-width: 44px; min-height: 44px; margin-left: -8px;
}

/* 内容区 */
.view { padding: 12px var(--gutter) 24px; max-width: 640px; margin: 0 auto; }
.page-title { font-size: 24px; font-weight: 700; margin: 6px 0 2px; }
.page-sub { color: var(--hint); margin: 0 0 14px; font-size: 14px; }
.eyebrow { color: var(--accent); font-size: 12px; font-weight: 600; letter-spacing: .04em; margin-bottom: 2px; }
.section-title { font-size: 13px; color: var(--hint); margin: 18px 0 8px; text-transform: none; }

.card {
  background: var(--card); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 12px;
  box-shadow: 0 1px 0 var(--sep);
}
.card-title { font-weight: 600; font-size: 16px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card-sub { color: var(--hint); font-size: 13px; margin-top: 2px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.mt8 { margin-top: 8px; } .mt12 { margin-top: 12px; } .mt16 { margin-top: 16px; }
.muted { color: var(--hint); } .small { font-size: 13px; } .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.danger-text { color: var(--danger); } .ok-text { color: var(--ok); }

/* 统计 */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 12px 14px; }
.stat .k { color: var(--hint); font-size: 12px; }
.stat .v { font-size: 26px; font-weight: 700; line-height: 1.2; }

/* 按钮 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border-radius: 12px; padding: 10px 14px; border: 1px solid var(--sep);
  background: var(--bg); color: var(--text); cursor: pointer; font-weight: 500;
  min-height: 44px; white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn-danger { color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--link); padding-left: 6px; padding-right: 6px; }
.btn-block { width: 100%; }
.btn-lg { min-height: 52px; font-size: 16px; }
.btn-sm { min-height: 34px; padding: 6px 10px; font-size: 13px; border-radius: 10px; position: relative; }
.btn-sm::after { content: ""; position: absolute; inset: -5px -2px; } /* 点击区域 ≥ 44px,外观不变 */
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.btn-row .btn { flex: 1 1 auto; }
.fallback-main {
  position: fixed; left: 0; right: 0; bottom: calc(var(--tab-h) + var(--safe-b));
  padding: 10px var(--gutter); background: var(--bg); border-top: 1px solid var(--sep); z-index: 6;
}
body.has-main { padding-bottom: calc(var(--tab-h) + var(--safe-b) + 70px); }
body.no-tabs .fallback-main { bottom: 0; padding-bottom: calc(10px + var(--safe-b)); }
body.no-tabs.has-main { padding-bottom: calc(var(--safe-b) + 80px); }

/* 徽标 */
.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; font-weight: 600; line-height: 1.5; }
.badge-draft { background: rgba(107, 114, 128, .15); color: var(--hint); }
.badge-active { background: rgba(46, 158, 91, .15); color: var(--ok); }
.badge-suspended { background: rgba(217, 140, 31, .15); color: var(--warn-text); }
.badge-expired { background: rgba(217, 83, 79, .15); color: var(--danger); }
.pill { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--bg2); color: var(--hint); }

/* 表单 */
.field { margin-bottom: 14px; }
.field label, .field .label { display: block; font-size: 13px; color: var(--hint); margin-bottom: 6px; }
.input, textarea.input, select.input {
  width: 100%; border: 1px solid var(--sep); border-radius: 12px; padding: 10px 12px;
  background: var(--bg); color: var(--text); font: inherit; outline: none; min-height: 44px;
}
.input[readonly], .input:disabled { color: var(--hint); }
.input:focus { border-color: var(--accent); }
.input.invalid { border-color: var(--danger); }
textarea.input { min-height: 96px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; }
.hint { font-size: 12px; color: var(--hint); margin-top: 5px; }
.error { font-size: 12px; color: var(--danger); margin-top: 5px; }
.input-row { display: flex; gap: 8px; align-items: center; }
.input-row .input { flex: 1; }
input[type="color"].swatch { width: 44px; height: 42px; padding: 2px; border: 1px solid var(--sep); border-radius: 10px; background: var(--bg); }

.switch-row { cursor: pointer; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--sep); }
.switch-row:last-child { border-bottom: 0; }
.switch-row .t { font-weight: 500; }
.switch-row .d { font-size: 12px; color: var(--hint); }
.switch { position: relative; width: 48px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch .knob { position: absolute; inset: 0; border-radius: 999px; background: rgba(120, 120, 128, .32); transition: .15s; }
.switch .knob::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: .15s; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); }
.switch input:checked + .knob { background: var(--ok); }
.switch input:checked + .knob::after { transform: translateX(20px); }

details.adv { border-top: 1px solid var(--sep); margin-top: 8px; padding-top: 8px; }
details.adv summary { cursor: pointer; color: var(--link); font-weight: 500; list-style: none; }
details.adv summary::-webkit-details-marker { display: none; }
.notice { background: rgba(91, 91, 240, .08); border-radius: 12px; padding: 10px 12px; font-size: 13px; color: var(--text); }
.notice.warn { background: rgba(217, 140, 31, .14); }
.notice .btn-row { margin-top: 8px; }
.notice.danger { background: rgba(217, 83, 79, .10); }

/* 步骤条 */
.steps { background: var(--card); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 12px; }
.steps .row { justify-content: space-between; font-size: 13px; }
.steps .bar { height: 6px; background: var(--bg2); border-radius: 999px; margin-top: 8px; overflow: hidden; }
.steps .bar i { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width .2s; }
.step-no { color: var(--accent); font-size: 12px; font-weight: 600; }
.step-title { font-size: 20px; font-weight: 700; margin: 2px 0 4px; }

/* 品牌预览 */
.brand-preview { border-radius: var(--radius); padding: 28px 16px; text-align: center; color: #fff; margin-top: 8px; }
.brand-preview .logo { width: 64px; height: 64px; border-radius: 16px; margin: 0 auto 10px; background: rgba(255, 255, 255, .25); display: flex; align-items: center; justify-content: center; font-size: 28px; font-weight: 700; overflow: hidden; }
.brand-preview .logo img { width: 100%; height: 100%; object-fit: cover; }
.brand-preview .name { font-size: 18px; font-weight: 700; }
.brand-preview .fake-input { margin: 14px auto 0; max-width: 260px; height: 36px; border-radius: 10px; background: rgba(255, 255, 255, .9); }
.brand-preview .fake-btn { margin: 8px auto 0; max-width: 260px; height: 36px; border-radius: 10px; background: rgba(0, 0, 0, .25); }

/* 分享卡 */
.share-code { font-size: 28px; font-weight: 800; letter-spacing: .02em; word-break: break-all; text-align: center; margin: 6px 0; }
.qr { display: block; width: 220px; height: 220px; margin: 10px auto; border-radius: 12px; background: #fff; padding: 8px; }
.howto { counter-reset: s; padding-left: 0; list-style: none; }
.howto li { position: relative; padding-left: 32px; margin: 8px 0; }
.howto li::before { counter-increment: s; content: counter(s); position: absolute; left: 0; top: 0; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: var(--accent-text); font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center; }

/* 探测结果 */
.probe { font-size: 13px; padding: 6px 0; border-bottom: 1px solid var(--sep); }
.probe:last-child { border-bottom: 0; }

/* 图表:SVG 只画柱子(横向拉伸),刻度文字用 HTML,不会被拉变形 */
.chart-wrap { position: relative; padding-left: 30px; }
.chart { width: 100%; height: 120px; display: block; }
.chart .bar { fill: var(--accent); opacity: .85; }
.chart .axis { stroke: var(--sep); vector-effect: non-scaling-stroke; }
.chart-y { position: absolute; left: 0; width: 26px; text-align: right; font-size: 10px; color: var(--hint); line-height: 1; }
.chart-x { display: flex; justify-content: space-between; font-size: 10px; color: var(--hint); margin-top: 4px; }
.chart-empty { height: 120px; display: flex; align-items: center; justify-content: center; color: var(--hint); font-size: 13px; }

/* 列表 */
.list-item { padding: 10px 0; border-bottom: 1px solid var(--sep); }
.list-item:last-child { border-bottom: 0; }

/* 空状态 */
.empty { text-align: center; padding: 32px 10px; color: var(--hint); }
.empty .big { margin-bottom: 8px; display: flex; justify-content: center; color: var(--hint); }
.empty .big.ok-text { color: var(--ok); } .empty .big.danger-text { color: var(--danger); }

/* 底部 tab */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 7;
  height: calc(var(--tab-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--bg); border-top: 1px solid var(--sep);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--hint); font-size: 11px; }
.tabbar a.active { color: var(--accent); }
.tab-icon { width: 22px; height: 22px; display: block; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--safe-b) + 16px); transform: translateX(-50%);
  background: rgba(20, 20, 24, .92); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px;
  z-index: 20; max-width: 90vw; text-align: center;
}
.loading { text-align: center; color: var(--hint); padding: 40px 0; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--sep); border-top-color: var(--accent); border-radius: 50%; margin: 0 auto 8px; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* 浏览器(非 Telegram)里的确认框 */
.modal-mask { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 30; display: flex; align-items: center; justify-content: center; padding: 24px; }
.modal { background: var(--card); color: var(--text); border-radius: 16px; padding: 18px; max-width: 360px; width: 100%; max-height: 80vh; overflow-y: auto; }
.modal p { margin: 0 0 14px; white-space: pre-wrap; }

/* 支付金额:最后 3 位小数(订单专属尾数)单独标出来 */
.amount { font-size: 30px; font-weight: 800; text-align: center; margin: 6px 0; word-break: break-all; user-select: all; -webkit-user-select: all; font-variant-numeric: tabular-nums; }
.amount .suffix { color: var(--danger); background: rgba(217, 83, 79, .12); border-radius: 6px; padding: 0 3px; }
.amount .unit { font-size: 16px; font-weight: 600; margin-left: 6px; color: var(--hint); user-select: none; -webkit-user-select: none; }
.selectable { user-select: all; -webkit-user-select: all; }

/* 充值金额快捷选项 */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--sep); background: transparent; color: var(--text); border-radius: 999px; padding: 6px 12px; font-size: 14px; cursor: pointer; }
.chip.on { border-color: var(--accent); background: var(--accent); color: var(--accent-text); }
