:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --line: #e3e6ea;
  --line-strong: #cdd2d9;
  --text: #1c1e21;
  --text-2: #5c626b;
  --text-3: #8b9199;
  --accent: #2563eb;
  --accent-soft: #e8f0fe;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --ok: #15803d;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

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

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

/* ---------- header ---------- */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.head-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-top: 14px;
  padding-bottom: 14px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  background: var(--accent);
  color: #fff;
  border-radius: 9px;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: .5px;
  flex: none;
}
.brand h1 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: .2px; }
.brand-sub { margin: 0; font-size: 12px; color: var(--text-3); }
.head-meta { display: flex; align-items: center; gap: 10px; }

.pill {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text-2);
  white-space: nowrap;
}
.pill-strong { background: var(--accent-soft); border-color: #c6dafc; color: #1749b1; font-weight: 500; }

/* ---------- buttons ---------- */
.btn, .btn-ghost, .btn-primary {
  font: inherit;
  font-size: 13px;
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
  transition: background .12s, border-color .12s;
}
.btn:hover, .btn-ghost:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #1d4fd8; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- stats ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin: 20px 0;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat-num { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat-lbl { font-size: 12px; color: var(--text-3); }

.notice {
  background: var(--warn-soft);
  border: 1px solid #fcd9a0;
  color: #7c4a03;
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 18px;
}

/* ---------- loading / error ---------- */
.loading { text-align: center; padding: 60px 0; color: var(--text-2); }
.spinner {
  width: 26px; height: 26px;
  margin: 0 auto 14px;
  border: 2.5px solid var(--line-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error {
  background: var(--surface);
  border: 1px solid #f3c4c4;
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
}
.error h2 { margin: 0 0 8px; font-size: 15px; color: var(--danger); }
.error p { margin: 0 0 16px; color: var(--text-2); font-size: 13px; word-break: break-all; }
.err-actions { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.err-actions details { font-size: 13px; color: var(--text-2); }
.err-actions input {
  font: inherit; font-size: 13px;
  width: min(480px, 80vw);
  padding: 6px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  margin: 8px 6px 0 0;
}

/* ---------- toolbar ---------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
#search {
  flex: 1 1 300px;
  font: inherit;
  padding: 8px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}
#search:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.sorts { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); }
#sort {
  font: inherit; font-size: 13px;
  padding: 6px 8px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}
.switch { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); cursor: pointer; }

.region-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.region-head h2 { margin: 0; font-size: 15px; font-weight: 600; }
.hint { font-size: 12px; color: var(--text-3); }
.region-head .btn-ghost { margin-left: auto; }

/* ---------- region grid ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(216px, 1fr));
  gap: 10px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 11px;
  transition: border-color .12s, background .12s, box-shadow .12s;
  text-align: left;
  font: inherit;
  color: inherit;
  width: 100%;
}
.card:hover { border-color: var(--line-strong); box-shadow: 0 1px 4px rgba(20,25,35,.06); }
.card.on {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.flag {
  width: 30px; height: 21px;
  border-radius: 3px;
  object-fit: cover;
  flex: none;
  background: var(--surface-2);
  border: 1px solid var(--line);
  display: block;
}
.flag-fb {
  width: 30px; height: 21px;
  border-radius: 3px;
  flex: none;
  display: grid; place-items: center;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 10px;
  color: var(--text-3);
  font-family: var(--mono);
}
.card-body { min-width: 0; flex: 1; }
.card-code { font-family: var(--mono); font-size: 12px; color: var(--text-3); letter-spacing: .5px; }
.card-name { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-city { font-size: 12px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-count {
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  font-weight: 600;
  color: var(--accent);
  flex: none;
}
.card.on .card-count { color: #1749b1; }
.card-badge {
  display: inline-block;
  font-size: 10px;
  padding: 0 5px;
  border-radius: 4px;
  background: var(--warn-soft);
  color: var(--warn);
  margin-left: 5px;
  vertical-align: 1px;
}
.empty { text-align: center; color: var(--text-3); padding: 30px 0; font-size: 13px; }

/* ---------- panel ---------- */
.panel {
  margin: 24px 0 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
}
.panel-head { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.panel-head h2 { margin: 0; font-size: 15px; font-weight: 600; }

.live-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 14px;
  margin-bottom: 18px;
  background: var(--accent-soft);
  border: 1px solid #d4e2fb;
  border-radius: var(--radius);
}
.live-note { font-size: 12.5px; color: var(--text-2); font-family: var(--mono); }

.api-url-box {
  margin: 18px 0 4px;
  padding: 14px;
  background: var(--surface-2);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
}
.api-url-wrap { display: flex; gap: 8px; margin-top: 8px; }
.api-url-wrap input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  font-family: var(--mono);
  font-size: 12.5px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-1);
}
.api-url-wrap input::placeholder { color: var(--text-3); }
.api-url-wrap button { white-space: nowrap; }

.panel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 18px;
}
.field-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.field-head label { font-size: 13px; font-weight: 500; }
.note { font-size: 12px; color: var(--text-3); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font: inherit; font-size: 13px;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  transition: all .12s;
}
.chip:hover { border-color: var(--text-3); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip:disabled { opacity: .4; cursor: not-allowed; }
.chip-n { font-size: 12px; opacity: .65; margin-left: 2px; font-variant-numeric: tabular-nums; }
.chip-legacy .tag {
  font-size: 10px;
  padding: 0 4px;
  border-radius: 3px;
  background: var(--surface-2);
  color: var(--text-3);
  margin-left: 3px;
}
.chip-legacy.active .tag { background: rgba(255,255,255,.22); color: #fff; }

#qtyRange { width: 100%; margin-top: 10px; }

.out-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.out-meta { font-size: 13px; color: var(--text-2); }
.out-actions { display: flex; gap: 8px; }
.out {
  margin: 12px 0 0;
  padding: 14px;
  background: #fbfcfd;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  max-height: 340px;
  overflow: auto;
  white-space: pre;
  color: #30363d;
}
.out::-webkit-scrollbar { width: 9px; height: 9px; }
.out::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 5px; }

/* ---------- footer ---------- */
.site-footer {
  margin-top: 40px;
  padding: 24px 0 40px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--text-2);
}
.site-footer p { margin: 0 0 6px; }
.site-footer .dim { color: var(--text-3); }

@media (max-width: 640px) {
  .brand-sub { display: none; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .out-head { align-items: flex-start; }
}
