/* Toolbox Hub — 移动优先，单一断点 768px。主色沿用现有站点 teal #0f766e。
   布局：单列为主。桌面端只把订阅的两块并排，余额卡保持整行——
   避免出现「左侧卡片比右侧矮 200px」的空白。 */

:root {
  --accent: #0f766e;
  --accent-soft: #14b8a6;
  --bg: #f6f8f7;
  --card: #ffffff;
  --border: #dbe5e0;
  --text: #172b26;
  --muted: #5b6f68;
  --ok: #0f766e;
  --warn: #b45309;
  --error: #b91c1c;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 55, 45, .04), 0 8px 24px rgba(20, 55, 45, .05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #2dd4bf;
    --accent-soft: #5eead4;
    --bg: #0e1614;
    --card: #16211e;
    --border: #24352f;
    --text: #e6efeb;
    --muted: #93a8a0;
    --ok: #2dd4bf;
    --warn: #fbbf24;
    --error: #f87171;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }

/* display:flex/grid 会覆盖 UA 的 [hidden]{display:none}，
   这让 el.hidden = true 静默失效（.source-panel / .kv 都踩了这个坑）。 */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;          /* 页脚贴底，不再浮在内容中间 */
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC",
               "Source Han Sans SC", "WenQuanYi Micro Hei", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

.inner {
  width: 100%;
  max-width: 880px;
  margin-inline: auto;
  padding-inline: 1rem;
}

/* ── 顶栏 ─────────────────────────────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding-block: .6875rem;
}

.brand {
  font-weight: 700;
  color: var(--accent);
  letter-spacing: .02em;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: .5rem;
  min-width: 0;
}

.who {
  color: var(--muted);
  font-size: .8125rem;
  max-width: 11rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── 主区 ─────────────────────────────────────────────── */

.main {
  flex: 1 0 auto;
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  padding-block: 1rem;
  align-content: start;
}

@media (min-width: 768px) {
  .main { gap: 1.25rem; padding-block: 1.5rem; }
}

/* ── 卡片 ─────────────────────────────────────────────── */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.125rem;
}

@media (min-width: 768px) {
  .card { padding: 1.375rem 1.5rem; }
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  margin-bottom: .875rem;
}

.card-head h2 {
  margin: 0;
  font-size: .9375rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: .03em;
}

/* ── 余额卡 ───────────────────────────────────────────── */

.balance-main {
  display: flex;
  align-items: baseline;
  gap: .5rem;
  flex-wrap: wrap;
}

.balance-value {
  font-size: 2.5rem;
  font-weight: 700;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
}

@media (min-width: 768px) {
  .balance-value { font-size: 3rem; }
}

.balance-cur {
  font-size: .9375rem;
  color: var(--muted);
  font-weight: 500;
}

.tag {
  align-self: center;
  font-size: .6875rem;
  font-weight: 700;
  padding: .125rem .375rem;
  border-radius: 5px;
  background: rgba(180, 83, 9, .14);
  color: var(--warn);
  letter-spacing: .04em;
}

/* 赠送 / 充值 两栏：把余额卡右侧的空白填成信息 */
.kv {
  margin: .875rem 0 0;
  display: flex;
  gap: 2rem;
  flex-wrap: wrap;
}

.kv > div {
  display: flex;
  flex-direction: column;
  gap: .125rem;
  min-width: 4.5rem;
}

.kv dt {
  font-size: .75rem;
  color: var(--muted);
}

.kv dd {
  margin: 0;
  font-size: .9375rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.meta {
  margin: .75rem 0 0;
  color: var(--muted);
  font-size: .8125rem;
}

/* ── 订阅 ─────────────────────────────────────────────── */

.sub-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
}

@media (min-width: 768px) {
  .sub-list {
    grid-template-columns: 1fr 1fr;
    gap: 0 1.5rem;
  }
}

/* 用分隔线代替卡片套卡片：去掉三层边框 */
.sub-item {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  padding-block: .875rem;
  border-top: 1px solid var(--border);
}

.sub-item:first-child { border-top: 0; padding-top: 0; }
.sub-item:last-child { padding-bottom: 0; }

@media (min-width: 768px) {
  /* 桌面并排时，用竖线分隔，且都不留上边框 */
  .sub-item {
    border-top: 0;
    padding-block: 0;
    padding-inline: 0;
  }
  .sub-item + .sub-item {
    border-left: 1px solid var(--border);
    padding-left: 1.5rem;
  }
}

.sub-top {
  display: flex;
  align-items: center;
  gap: .5rem;
}

.sub-name {
  font-weight: 600;
  font-size: .9375rem;
}

.sub-meta {
  margin: 0;
  color: var(--muted);
  font-size: .8125rem;
  font-variant-numeric: tabular-nums;
}

/* ── 上游地址设置 ─────────────────────────────────────── */

.source {
  border-top: 1px dashed var(--border);
  padding-top: .5rem;
  margin-top: .125rem;
}

.source-toggle {
  display: flex;
  align-items: center;
  gap: .5rem;
  width: 100%;
  background: none;
  border: 0;
  padding: .25rem 0;
  min-height: 32px;
  font: inherit;
  font-size: .8125rem;
  color: var(--muted);
  cursor: pointer;
  text-align: left;
}

.source-toggle:hover .source-label { color: var(--accent); }
.source-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

.source-label { flex: 0 0 auto; }

.source-current {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .75rem;
  color: var(--text);
}

.source-current.is-empty { color: var(--warn); }
.source-toggle::after { content: '▾'; flex: 0 0 auto; font-size: .6875rem; }
.source-toggle[aria-expanded="true"]::after { content: '▴'; }

.source-panel {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  padding: .625rem 0 .25rem;
}

.source-field {
  display: flex;
  flex-direction: column;
  gap: .3125rem;
}

.source-field-label {
  font-size: .75rem;
  color: var(--muted);
}

.source-input {
  font: inherit;
  font-size: .8125rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--text);
  /* 输入框用纯白底 + 明显边框，与只读的灰底当前值区分开 */
  background: var(--card);
  border: 1px solid var(--text);
  border-radius: 8px;
  padding: .5625rem .625rem;
  min-height: 42px;
  width: 100%;
}

.source-input::placeholder { color: var(--muted); opacity: .7; }

.source-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, .18);
}

.source-hint {
  margin: 0;
  font-size: .75rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}

/* 当前值单独一行，且可选中复制，便于核对而非只能看截断的省略号 */
.source-now {
  margin: 0;
  font-size: .75rem;
  color: var(--muted);
  overflow-wrap: anywhere;
  word-break: break-all;
}

.source-now code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .6875rem;
  color: var(--text);
  background: var(--bg);
  padding: .0625rem .25rem;
  border-radius: 4px;
  user-select: all;
}

.source-actions {
  display: flex;
  gap: .5rem;
  padding-bottom: .625rem;
  /* 「保存/取消」这组属于编辑表单，用一条细线与下面的订阅操作分开 */
  border-bottom: 1px solid var(--border);
}

.source-actions .btn { flex: 1 1 0; }

/* 「生成」是写操作且耗时，与「保存地址」并置会抢主次：
   这里降为描边，主色只留给当前表单的主操作。 */
.sub-actions .btn-primary {
  background: transparent;
  border-color: var(--accent);
  color: var(--accent);
}

.sub-actions .btn-primary:hover:not(:disabled) {
  background: rgba(15, 118, 110, .08);
  color: var(--accent);
}

.sub-actions {
  display: grid;
  gap: .5rem;
  margin-top: .25rem;
  /* 移动端：主操作整行独占，两个次操作并排 —— 三个并排会挤到没有内边距 */
  grid-template-columns: 1fr 1fr;
}

.sub-actions .btn-primary {
  grid-column: 1 / -1;
}

@media (min-width: 768px) {
  /* 桌面有指针，三个并排不挤 */
  .sub-actions {
    display: flex;
    flex-wrap: wrap;
  }
}

/* ── 按钮 ─────────────────────────────────────────────── */

.btn {
  font: inherit;
  font-size: .875rem;
  font-weight: 600;
  border-radius: 9px;
  border: 1px solid var(--border);
  padding: .625rem 1rem;
  min-height: 44px;
  cursor: pointer;
  transition: background-color .15s, border-color .15s, opacity .15s;
  text-align: center;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--text);
  white-space: nowrap;
}

.btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* 主操作填色，让「生成」在三个按钮里唯一可辨 */
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-soft);
  border-color: var(--accent-soft);
  color: #fff;
}

.btn-ghost { background: transparent; }

.btn-sm {
  font-size: .8125rem;
  padding: .375rem .75rem;
  min-height: 44px;   /* 移动端触控目标 */
}

@media (min-width: 768px) {
  /* 桌面用指针，36px 足够，且能排成一行 */
  .btn-sm { min-height: 36px; }
}

/* ── 提示 ─────────────────────────────────────────────── */

.notice {
  margin: .75rem 0 0;
  font-size: .8125rem;
  padding: .625rem .75rem;
  border-radius: 8px;
  background: rgba(180, 83, 9, .1);
  color: var(--warn);
  overflow-wrap: anywhere;
}

.notice-error {
  background: rgba(185, 28, 28, .1);
  color: var(--error);
}

/* ── 页脚 ─────────────────────────────────────────────── */

.foot {
  flex: 0 0 auto;
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  align-items: center;
  padding-block: 1rem 1.5rem;
  padding-bottom: calc(1.5rem + env(safe-area-inset-bottom));
  color: var(--muted);
  font-size: .8125rem;
}

.foot a { color: var(--muted); text-decoration: none; }
.foot a:hover { color: var(--accent); text-decoration: underline; }

/* ── 登录页 ───────────────────────────────────────────── */

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1.25rem;
}

.login-wrap { width: 100%; max-width: 23rem; }

.login-card {
  display: flex;
  flex-direction: column;
  gap: .875rem;
  padding: 1.5rem;
  margin: 0;
}

.login-title {
  margin: 0;
  font-size: 1.375rem;
  font-weight: 700;
  color: var(--accent);
  text-align: center;
}

.login-sub {
  margin: -.375rem 0 .25rem;
  text-align: center;
  color: var(--muted);
  font-size: .875rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: .375rem;
  font-size: .8125rem;
  color: var(--muted);
}

.field input {
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: .6875rem .75rem;
  min-height: 44px;
  width: 100%;
}

.field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, .15);
}

.login-hint {
  margin: .25rem 0 0;
  text-align: center;
  color: var(--muted);
  font-size: .75rem;
}