:root {
  color-scheme: light;
  --bg: #f4f6f3; --panel: #ffffff; --raised: #eef2ee; --line: #d9e0da; --text: #17201b; --muted: #5d6a62;
  --accent: #0b7a4b; --accent-soft: #e0f2e8; --on-accent: #ffffff;
  --warn: #a84a06; --warn-soft: #fdeedc; --danger: #b3261e; --shadow: 0 8px 28px rgba(20, 40, 30, .16);
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, Menlo, monospace;
  --c-red: #d64545; --c-orange: #d97c12; --c-green: #2e9e5b; --c-blue: #3b82c4; --c-purple: #8b5fc7; --c-teal: #1f9aa3;
}
/* 深色：跟随系统（除非手动选了浅色），或手动选了深色 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1512; --panel: #171f1b; --raised: #1e2823; --line: #2a3730; --text: #e6ede8; --muted: #93a299;
    --accent: #4fd08f; --accent-soft: #173a2a; --on-accent: #06200f;
    --warn: #f2ad63; --warn-soft: #3a2a17; --danger: #ff8a80; --shadow: 0 8px 28px rgba(0, 0, 0, .5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1512; --panel: #171f1b; --raised: #1e2823; --line: #2a3730; --text: #e6ede8; --muted: #93a299;
  --accent: #4fd08f; --accent-soft: #173a2a; --on-accent: #06200f;
  --warn: #f2ad63; --warn-soft: #3a2a17; --danger: #ff8a80; --shadow: 0 8px 28px rgba(0, 0, 0, .5);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
button, a.btn {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px;
  padding: 7px 12px; cursor: pointer; white-space: nowrap; color: inherit; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: border-color .15s, background-color .15s;
}
button:hover, a.btn:hover { border-color: var(--accent); }
button:active { background: var(--raised); }
button:disabled { opacity: .45; cursor: default; border-color: var(--line); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
button.ghost, a.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
button.ghost:hover, a.btn.ghost:hover { border-color: var(--line); color: var(--text); }
button.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
button.danger { color: var(--danger); }
button.danger.armed { background: var(--danger); border-color: var(--danger); color: var(--panel); }
button.sm { padding: 3px 9px; font-size: 13px; border-radius: 6px; }
button.icon { padding: 7px; }
svg.i { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
input, select, textarea {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 8px 10px; min-width: 0;
}
textarea { width: 100%; resize: vertical; min-height: 72px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
[hidden] { display: none !important; }

/* 登录过期 */
#login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
#login .gate { width: min(360px, 100%); display: grid; gap: 12px; }
#login h1 { margin: 0; font-size: 22px; }
#login p { margin: 0; color: var(--muted); font-size: 14px; }

/* 主界面 */
#app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
header {
  display: flex; align-items: center; gap: 8px; position: relative; z-index: 5;
  padding: 8px 16px; padding-top: max(8px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line); background: var(--panel);
}
header h1 { margin: 0; font-size: 16px; white-space: nowrap; }
header .balance { margin-left: auto; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
header .balance b { color: var(--text); font-family: var(--mono); }
#menu {
  position: absolute; right: 12px; top: calc(100% + 6px); width: min(300px, calc(100vw - 24px));
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
  padding: 12px; display: grid; gap: 12px;
}
#menu label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
#menu select { font-size: 14px; color: var(--text); }
#menu .seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
#menu .seg button { font-size: 13px; padding: 6px 4px; }
#menu hr { border: none; border-top: 1px solid var(--line); margin: 0; }
#menu > button { justify-content: flex-start; }

main { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(340px, 440px) 1fr; }
#listPane { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); }
.bar { display: flex; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); align-items: center; }
.bar select, .bar input[type=search] { flex: 1; }
.chips { display: flex; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.chips button { padding: 3px 10px; font-size: 13px; border-radius: 99px; }
.chips button b { font-family: var(--mono); font-weight: 400; color: var(--muted); }

#numbers { flex: 1; overflow-y: auto; margin: 0; padding: 0; list-style: none; overscroll-behavior: contain; }
#numbers li.group {
  position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: 8px; cursor: pointer;
  padding: 7px 12px; background: var(--raised); border-bottom: 1px solid var(--line); font-size: 13px; font-weight: 600;
}
#numbers li.group .gname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#numbers li.group small { font-weight: 400; color: var(--muted); font-size: 12px; white-space: nowrap; }
#numbers li.group svg { transition: transform .15s; color: var(--muted); }
#numbers li.group.closed svg { transform: rotate(-90deg); }
.odot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
#numbers li.row {
  padding: 8px 12px 8px 9px; border-bottom: 1px solid var(--line); border-left: 3px solid transparent; cursor: pointer;
  display: grid; grid-template-columns: auto 1fr auto; gap: 0 10px; align-items: center;
}
#numbers li.row:hover { background: var(--raised); }
#numbers li.sel, #numbers li.sel:hover { background: var(--accent-soft); }
#numbers li.used .tel, #numbers li.used .sub { opacity: .5; }
#numbers li.used .tel { text-decoration: line-through; }
#numbers li.expired { opacity: .55; }
#numbers .ck { display: grid; place-items: center; width: 28px; height: 28px; margin: -4px; }
#numbers input[type=checkbox] { width: 18px; height: 18px; margin: 0; cursor: pointer; accent-color: var(--accent); }
#numbers .tel { font-family: var(--mono); font-size: 16px; font-weight: 600; display: flex; align-items: center; gap: 4px; min-width: 0; white-space: nowrap; }
#numbers .tel svg { width: 14px; height: 14px; color: var(--warn); fill: currentColor; }
#numbers .sub { grid-column: 2 / 3; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#numbers .acts { grid-row: 1 / 3; grid-column: 3; display: flex; gap: 6px; align-items: center; }
/* 号码右侧的验证码：点一下就复制 */
.codebtn {
  flex-direction: column; gap: 0; padding: 3px 10px; min-width: 78px; line-height: 1.25;
  border-color: var(--accent); background: var(--accent-soft); color: var(--accent);
}
.codebtn b { font-family: var(--mono); font-size: 17px; letter-spacing: 1px; }
.codebtn small { font-size: 11px; opacity: .85; font-weight: 400; }
.codebtn.fresh { border-color: var(--warn); background: var(--warn-soft); color: var(--warn); }
.sortbar #usage { margin-left: auto; font-size: 13px; color: var(--muted); font-family: var(--mono); white-space: nowrap; }
.sortbar select { flex: 0 1 auto; font-size: 13px; padding: 6px 8px; }
#sortDir svg { transition: transform .15s; }
#sortDir.desc svg { transform: rotate(180deg); }
.otag { display: inline-flex; align-items: center; gap: 4px; margin-right: 6px; max-width: 9em; vertical-align: bottom; }
.otag .odot { width: 8px; height: 8px; }
#numbers .sub .warn, .meta .warn { color: var(--warn); font-weight: 600; }
.soonbar {
  border: none; border-bottom: 1px solid var(--line); border-radius: 0; justify-content: flex-start;
  background: var(--warn-soft); color: var(--warn); font-size: 13px; padding: 7px 12px; white-space: normal; text-align: left;
}
.soonbar:hover, .soonbar:active { background: var(--warn-soft); border-color: var(--line); text-decoration: underline; }
.empty { padding: 28px 16px; color: var(--muted); text-align: center; font-size: 14px; }
#listFoot { padding: 6px 12px; padding-bottom: max(6px, env(safe-area-inset-bottom)); font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); }

#detail { min-height: 0; overflow-y: auto; padding: 20px; padding-bottom: max(20px, env(safe-area-inset-bottom)); }
#detail .back { display: none; margin-bottom: 12px; }
.dtel { font-family: var(--mono); font-size: 36px; font-weight: 700; line-height: 1.2; letter-spacing: .02em; margin: 0; display: flex; flex-wrap: wrap; column-gap: .4em; font-variant-numeric: tabular-nums; }
.dtel span { white-space: nowrap; }
.dtel .cc { color: var(--muted); font-weight: 600; }
.meta { color: var(--muted); font-size: 13px; margin: 4px 0 12px; }
.meta .odot { display: inline-block; margin-right: 6px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 14px; }
.card h2 { margin: 0 0 10px; font-size: 14px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card h2 .sp { flex: 1; }
.card h2 small { font-weight: 400; color: var(--muted); font-size: 12px; }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form label { display: grid; gap: 3px; font-size: 12px; color: var(--muted); }
.form label.wide { grid-column: 1 / -1; }
.form input, .form textarea { width: 100%; font-size: 14px; color: var(--text); }
.swatches { display: flex; gap: 8px; align-items: center; padding: 4px 0; flex-wrap: wrap; }
.swatches button { width: 28px; height: 28px; padding: 0; border-radius: 50%; border: 2px solid var(--line); color: var(--muted); }
.swatches button.on { border-color: var(--text); box-shadow: 0 0 0 2px var(--panel) inset; }
.statusline { font-size: 12px; color: var(--muted); display: flex; gap: 8px; align-items: center; font-weight: 400; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1.6s infinite; }
.dot.off { background: var(--muted); animation: none; }
@keyframes pulse { 50% { opacity: .3; } }
.msg { border-top: 1px solid var(--line); padding: 12px 0 10px; display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; }
.msg:first-child { border-top: none; padding-top: 2px; }
.msg .code {
  font-family: var(--mono); font-size: 26px; font-weight: 700; letter-spacing: 2px; color: var(--accent);
  background: none; border: none; padding: 0; justify-self: start;
}
.msg .body { grid-column: 1 / -1; white-space: pre-wrap; word-break: break-word; }
.msg .when { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
.notice { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 12px; font-size: 14px; margin-bottom: 10px; }

dialog {
  border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--text);
  padding: 18px; width: min(560px, calc(100vw - 24px)); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog h2 { margin: 0 0 6px; font-size: 17px; }
dialog p { margin: 0 0 10px; color: var(--muted); font-size: 13px; }
dialog textarea { min-height: 150px; font-family: var(--mono); font-size: 13px; }
dialog .err { color: var(--danger); font-size: 13px; min-height: 1.5em; margin: 6px 0; }
dialog .foot { display: flex; justify-content: flex-end; gap: 8px; }

#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); max-width: 90vw; z-index: 20;
  background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 99px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#toast.show { opacity: 1; }
@media (prefers-reduced-motion: reduce) {
  .dot { animation: none; }
  * { transition: none !important; }
}

/* 手机：单栏，列表和详情二选一 */
@media (max-width: 800px) {
  main { grid-template-columns: 1fr; }
  #listPane { border-right: none; }
  #detail { padding: 14px; }
  #detail .back { display: inline-flex; }
  main.viewing #listPane { display: none; }
  main:not(.viewing) #detail { display: none; }
  header { padding-left: 12px; padding-right: 12px; }
  header #who { display: none; }
  .form { grid-template-columns: 1fr; }
  .dtel { font-size: 30px; }
  /* 输入框不小于 16px，否则 iOS 聚焦时会自动放大页面 */
  input, select, textarea, .form input, .form textarea, #menu select, dialog textarea { font-size: 16px; }
}
/* 触屏：按钮和可点区域放大到好按的尺寸 */
@media (pointer: coarse) {
  button, a.btn { min-height: 44px; }
  button.sm { min-height: 40px; padding: 6px 12px; }
  button.icon { min-width: 44px; }
  .chips button { min-height: 36px; padding: 5px 13px; }
  #numbers li.row { padding-top: 10px; padding-bottom: 10px; }
  #numbers .ck { width: 40px; height: 40px; margin: -6px -6px -6px -8px; }
  #numbers input[type=checkbox] { width: 22px; height: 22px; }
  #numbers li.group { padding-top: 10px; padding-bottom: 10px; }
  .swatches button { width: 36px; height: 36px; }
  .codebtn { min-width: 84px; }
}

/* ---- 公开版追加 ---- */
header .status { margin-left: auto; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.welcome { max-width: 560px; margin: 0 auto; padding: 28px 18px; }
.welcome h2 { margin: 0 0 8px; font-size: 20px; }
.welcome p, .welcome li { color: var(--muted); font-size: 14px; }
.welcome ul { padding-left: 20px; margin: 8px 0 16px; }
.welcome .cta { display: flex; gap: 8px; flex-wrap: wrap; }
dialog label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
dialog input { font-size: 14px; color: var(--text); }
.privacy { font-size: 12px; color: var(--muted); padding: 8px 12px; border-top: 1px solid var(--line); }
@media (max-width: 800px) { dialog input { font-size: 16px; } header .status { display: none; } }
