/* ===== 主题变量 ===== */
:root {
  --bg: #f4f6fb;
  --bg-soft: #eef1f8;
  --card: #ffffff;
  --border: #e3e8f2;
  --border-strong: #cfd7e8;
  --text: #1b2333;
  --text-soft: #5b6780;
  --text-mute: #8a95aa;
  --primary: #2f6fed;
  --primary-soft: #e8f0ff;
  --primary-hover: #245cd4;
  --danger: #e5484d;
  --ok: #12b76a;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .06);
  --shadow-sm: 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 14px;
  --radius-sm: 10px;
  --mono: "SFMono-Regular", "JetBrains Mono", Consolas, "PingFang SC", monospace;
}

[data-theme="dark"] {
  --bg: #0f1319;
  --bg-soft: #151a22;
  --card: #171d26;
  --border: #242c38;
  --border-strong: #333d4d;
  --text: #e6eaf2;
  --text-soft: #9ba7bb;
  --text-mute: #6d7a90;
  --primary: #5b8dff;
  --primary-soft: #1a2540;
  --primary-hover: #7ba4ff;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, .4);
}

* { box-sizing: border-box; }

/* hidden 属性优先级最高，防止被 display:grid/flex 等作者样式覆盖 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  padding-bottom: 40px;
  transition: background .2s ease, color .2s ease;
}

.wrap {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 20px;
}

/* ===== Header ===== */
.app-header {
  background: linear-gradient(135deg, var(--primary) 0%, #6f4bf0 100%);
  color: #fff;
  padding: 22px 0 26px;
  box-shadow: var(--shadow);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-logo {
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 12px;
  background: rgba(255, 255, 255, .18);
  display: grid;
  place-items: center;
}

.brand-logo svg { width: 24px; height: 24px; }

.brand-text h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: .3px;
}

.brand-text p {
  margin: 2px 0 0;
  font-size: 12.5px;
  opacity: .88;
}

.theme-btn {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, .28);
  background: rgba(255, 255, 255, .14);
  color: #fff;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  display: grid;
  place-items: center;
  transition: background .18s;
}

.theme-btn:hover { background: rgba(255, 255, 255, .26); }

.theme-icon { display: none; }
[data-theme="light"] .theme-icon[data-icon="moon"] { display: block; }
[data-theme="dark"] .theme-icon[data-icon="sun"] { display: block; }

/* ===== Layout ===== */
.app-main {
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin-top: -10px;
  padding-top: 10px;
}

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px 22px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px dashed var(--border);
}

.panel-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.count-badge {
  background: var(--primary-soft);
  color: var(--primary);
  border-radius: 20px;
  padding: 1px 10px;
  font-size: 12px;
  font-weight: 700;
}

.panel-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.link-btn {
  border: none;
  background: transparent;
  color: var(--text-soft);
  font-size: 12.5px;
  padding: 5px 9px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .16s, color .16s;
}

.link-btn:hover { background: var(--bg-soft); color: var(--primary); }
.link-btn.danger:hover { background: rgba(229, 72, 77, .1); color: var(--danger); }
.link-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ===== Field ===== */
.field { margin-bottom: 18px; }
.field:last-child { margin-bottom: 0; }

.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 9px;
  color: var(--text);
}

.field-label .hint {
  font-weight: 400;
  font-size: 12px;
  color: var(--text-mute);
  margin-left: 6px;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

/* ===== 运营商 tabs ===== */
.carrier-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.carrier-tab {
  position: relative;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 13px;
  border-radius: 10px;
  border: 1.5px solid var(--border-strong);
  background: var(--card);
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all .16s ease;
  user-select: none;
}

.carrier-tab .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  opacity: .55;
  flex: none;
}

.carrier-tab .tab-sub {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-mute);
}

.carrier-tab:hover { border-color: var(--c); color: var(--c); }

.carrier-tab.active {
  border-color: var(--c);
  color: var(--c);
  background: color-mix(in srgb, var(--c) 10%, transparent);
}

.carrier-tab.active .dot { opacity: 1; box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 25%, transparent); }
.carrier-tab.active .tab-sub { color: var(--c); opacity: .8; }

.mix-row {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.mix-label { font-size: 12.5px; color: var(--text-mute); }

.seg {
  display: inline-flex;
  background: var(--bg-soft);
  border-radius: 9px;
  padding: 3px;
  gap: 2px;
}

.seg-btn {
  border: none;
  background: transparent;
  color: var(--text-soft);
  font-size: 12.5px;
  padding: 5px 12px;
  border-radius: 7px;
  cursor: pointer;
  transition: all .16s;
}

.seg-btn.active { background: var(--card); color: var(--primary); font-weight: 600; box-shadow: var(--shadow-sm); }

/* ===== Select ===== */
.sel-item { display: block; }

.sel-item > span {
  display: block;
  font-size: 12px;
  color: var(--text-mute);
  margin-bottom: 5px;
}

select, .text-input {
  width: 100%;
  padding: 9px 11px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text);
  font-size: 13.5px;
  font-family: inherit;
  outline: none;
  transition: border-color .16s, box-shadow .16s;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238a95aa' stroke-width='3' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  padding-right: 30px;
}

.text-input { background-image: none; padding-right: 11px; }

select:focus, .text-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

select:disabled { opacity: .5; cursor: not-allowed; }

.region-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 12px;
}

.region-preview {
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-mute);
  display: flex;
  align-items: center;
  gap: 6px;
}

.region-preview b { color: var(--primary); font-weight: 600; }

/* ===== Switch ===== */
.switch-row {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  user-select: none;
}

.switch-row input { position: absolute; opacity: 0; pointer-events: none; }

.switch-track {
  width: 38px;
  height: 22px;
  border-radius: 20px;
  background: var(--border-strong);
  position: relative;
  transition: background .2s;
  flex: none;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .2);
  transition: transform .2s;
}

.switch-row input:checked + .switch-track { background: var(--primary); }
.switch-row input:checked + .switch-track::after { transform: translateX(16px); }
.switch-row input:focus-visible + .switch-track { box-shadow: 0 0 0 3px var(--primary-soft); }
.switch-text { font-size: 13px; color: var(--text-soft); }

/* ===== Stepper ===== */
.count-row {
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
}

.stepper {
  display: inline-flex;
  align-items: center;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--card);
}

.stepper button {
  width: 38px;
  height: 38px;
  border: none;
  background: var(--bg-soft);
  color: var(--text-soft);
  font-size: 16px;
  cursor: pointer;
  transition: background .16s, color .16s;
}

.stepper button:hover { background: var(--primary-soft); color: var(--primary); }

.stepper input {
  width: 92px;
  border: none;
  border-radius: 0;
  background-image: none;
  padding: 0;
  text-align: center;
  font-size: 15px;
  font-weight: 700;
  font-family: var(--mono);
  color: var(--text);
  outline: none;
}

.stepper input::-webkit-outer-spin-button,
.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.stepper input[type=number] { -moz-appearance: textfield; }

.quick-btns { display: flex; gap: 6px; flex-wrap: wrap; }

.quick-btns button {
  border: 1px solid var(--border-strong);
  background: var(--card);
  color: var(--text-soft);
  font-size: 12.5px;
  padding: 6px 11px;
  border-radius: 8px;
  cursor: pointer;
  transition: all .16s;
}

.quick-btns button:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }

/* ===== Checkbox grid ===== */
.check-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-soft);
  cursor: pointer;
  user-select: none;
}

.check input {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
  flex: none;
}

/* ===== Buttons ===== */
.action-row {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 11px 22px;
  border-radius: var(--radius-sm);
  border: 1.5px solid transparent;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all .16s ease;
}

.btn.primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--primary) 30%, transparent);
  flex: 1;
  min-width: 160px;
}

.btn.primary:hover { background: var(--primary-hover); transform: translateY(-1px); }
.btn.primary:active { transform: translateY(0); }

.btn.ghost {
  background: var(--card);
  border-color: var(--border-strong);
  color: var(--text-soft);
}

.btn.ghost:hover { border-color: var(--primary); color: var(--primary); }

/* ===== Stats ===== */
.stat-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.stat-card {
  flex: 1;
  min-width: 118px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 13px;
}

.stat-card .stat-top {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-soft);
}

.stat-card .stat-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }

.stat-card .stat-val {
  font-family: var(--mono);
  font-size: 19px;
  font-weight: 700;
  margin-top: 2px;
}

.stat-card .stat-bar {
  height: 4px;
  border-radius: 4px;
  background: var(--border);
  margin-top: 7px;
  overflow: hidden;
}

.stat-card .stat-bar i { display: block; height: 100%; border-radius: 4px; transition: width .5s ease; }

/* ===== Toolbar ===== */
.result-toolbar {
  display: grid;
  grid-template-columns: 1fr 150px 130px;
  gap: 10px;
  margin-bottom: 14px;
}

.result-toolbar .sel-item > span { display: none; }

/* ===== Result ===== */
.result-box { position: relative; }

.empty-state {
  text-align: center;
  padding: 46px 20px;
  color: var(--text-mute);
}

.empty-state p { margin: 12px 0 4px; font-size: 14px; color: var(--text-soft); font-weight: 600; }
.empty-state span { font-size: 12.5px; }
.empty-state svg { color: var(--border-strong); }

.result-list {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.row {
  display: grid;
  grid-template-columns: 46px 1.4fr 100px 1fr 76px;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  transition: background .14s;
}

.row:last-child { border-bottom: none; }
.row:hover { background: var(--bg-soft); }

.row-head {
  background: var(--bg-soft);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-mute);
  letter-spacing: .4px;
}

.row-head:hover { background: var(--bg-soft); }

.row-idx { font-family: var(--mono); font-size: 12px; color: var(--text-mute); }

.row-phone {
  font-family: var(--mono);
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: .4px;
  cursor: pointer;
  word-break: break-all;
}

.row-phone:hover { color: var(--primary); }

.row-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 20px;
}

.row-region { font-size: 12.5px; color: var(--text-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.row-ops { display: flex; gap: 6px; justify-content: flex-end; }

.mini-btn {
  border: 1px solid var(--border-strong);
  background: var(--card);
  color: var(--text-soft);
  width: 28px;
  height: 28px;
  border-radius: 7px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: all .14s;
}

.mini-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.mini-btn svg { width: 14px; height: 14px; }

.result-more { text-align: center; margin-top: 14px; }

.no-match { padding: 26px; text-align: center; color: var(--text-mute); font-size: 13px; }

/* ===== History ===== */
.history-list { display: flex; flex-direction: column; gap: 8px; }

.hist-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
}

.hist-info { min-width: 0; }
.hist-info .hist-t { font-size: 13px; font-weight: 600; }
.hist-info .hist-d { font-size: 11.5px; color: var(--text-mute); }
.hist-item .panel-actions { flex: none; }

/* ===== Footer ===== */
.app-footer {
  font-size: 12px;
  color: var(--text-mute);
  text-align: center;
  padding: 6px 10px 0;
  line-height: 1.7;
}

.app-footer strong { color: var(--text-soft); }
.foot-sub { margin-top: 2px; opacity: .8; }

/* ===== Toast ===== */
.toast-wrap {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 999;
  pointer-events: none;
}

.toast {
  background: var(--text);
  color: var(--card);
  padding: 9px 18px;
  border-radius: 22px;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: toastIn .25s ease;
  white-space: nowrap;
}

.toast.ok { background: var(--ok); }
.toast.err { background: var(--danger); }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== Modal ===== */
.modal { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: 20px; }
.modal-mask { position: absolute; inset: 0; background: rgba(12, 18, 30, .45); backdrop-filter: blur(2px); }

.modal-card {
  position: relative;
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  animation: modalIn .2s ease;
  overflow: hidden;
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(10px) scale(.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

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

.modal-head h3 { margin: 0; font-size: 14px; }

.icon-btn {
  border: none;
  background: transparent;
  color: var(--text-mute);
  font-size: 15px;
  cursor: pointer;
  width: 28px;
  height: 28px;
  border-radius: 7px;
}

.icon-btn:hover { background: var(--bg-soft); color: var(--text); }

.modal-body { padding: 16px; }

.kv {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px dashed var(--border);
  font-size: 13px;
}

.kv:last-child { border-bottom: none; }
.kv span { color: var(--text-mute); flex: none; }
.kv b { font-weight: 600; text-align: right; word-break: break-all; }
.kv b.mono { font-family: var(--mono); font-size: 15px; }

/* ===== Responsive ===== */
@media (max-width: 860px) {
  .two-col { grid-template-columns: 1fr; }
  .result-toolbar { grid-template-columns: 1fr 1fr; }
  .result-toolbar .sel-item.sort-wrap { grid-column: span 2; }
  .region-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 640px) {
  body { font-size: 13.5px; }
  .wrap { padding: 0 14px; }
  .app-header { padding: 16px 0 20px; }
  .brand-logo { width: 38px; height: 38px; border-radius: 10px; }
  .brand-text h1 { font-size: 17px; }
  .brand-text p { font-size: 11.5px; }
  .panel { padding: 16px 15px 18px; border-radius: 12px; }
  .check-grid { grid-template-columns: 1fr; }
  .region-grid { grid-template-columns: 1fr; }
  .carrier-tabs { display: grid; grid-template-columns: repeat(2, 1fr); }
  .carrier-tab { justify-content: center; padding: 9px 8px; }
  .carrier-tab .tab-sub { display: none; }
  .result-toolbar { grid-template-columns: 1fr; }
  .result-toolbar .sel-item.sort-wrap { grid-column: auto; }
  .stat-card { min-width: calc(50% - 5px); }

  /* 卡片式结果（移动端） */
  .result-list { border: none; border-radius: 0; }
  .row-head { display: none; }
  .row {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "phone ops"
      "meta meta";
    gap: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    padding: 11px 13px;
    background: var(--card);
  }
  .row-idx, .row-tag, .row-region { display: none; }
  .row-meta-mobile {
    grid-area: meta;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
  }
  .toast-wrap { bottom: 20px; }
  .btn.primary { width: 100%; }
  .action-row { flex-direction: column; }
}

.row-meta-mobile { display: none; }
.row-meta-mobile .row-region { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
