:root {
  --bg: #F5F5F3;
  --surface: #FFFFFF;
  --surface-2: #FAFAF8;
  --border: rgba(0, 0, 0, 0.09);
  --border-strong: rgba(0, 0, 0, 0.16);
  --text: #1F1F1E;
  --muted: #6B6B68;
  --faint: #9A9A96;
  --accent: #185FA5;
  --accent-soft: #E6F1FB;
  --success: #0F6E56;
  --success-soft: #E1F5EE;
  --danger: #A32D2D;
  --danger-soft: #FCEBEB;
  --warn: #854F0B;
  --warn-soft: #FAEEDA;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.06);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

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

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

.hidden { display: none !important; }

/* ---------- 登录页 ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
}
.login-card h1 { font-size: 18px; font-weight: 500; margin: 0 0 4px; }
.login-card .sub { color: var(--muted); font-size: 12px; margin-bottom: 22px; }

/* ---------- 主框架 ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 210px;
  flex: 0 0 210px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 8px; padding: 0 8px 18px; }
.brand .logo {
  width: 26px; height: 26px; border-radius: 7px; background: var(--accent);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 500;
}
.brand .name { font-size: 14px; font-weight: 500; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: block;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: #0C447C; font-weight: 500; }

.side-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--border); }
.side-foot .me { padding: 0 8px 10px; }
.side-foot .me .n { font-size: 13px; font-weight: 500; }
.side-foot .me .r { font-size: 11px; color: var(--muted); }

.main { flex: 1; min-width: 0; padding: 22px 26px 60px; }
.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.topbar h1 { font-size: 17px; font-weight: 500; margin: 0; }
.topbar .desc { font-size: 12px; color: var(--muted); margin-top: 2px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- 卡片与表格 ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.card + .card { margin-top: 16px; }
.card-head {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.card-head h2 { font-size: 13px; font-weight: 500; margin: 0; }
.card-body { padding: 16px; }

.grid-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 22px; font-weight: 500; margin-top: 4px; letter-spacing: -0.5px; }
.stat .x { font-size: 11px; color: var(--faint); margin-top: 2px; }

/* 表格横向滚动容器。
   .card 上有 overflow:hidden（为了圆角），手机端列一多，表格会被直接裁掉，
   用户既看不到右边的列、也划不动。包一层 overflow-x:auto 的容器后，
   表格超出宽度时可以左右滑动查看。 */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-wrap table { min-width: 640px; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; font-weight: 500; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
td { font-size: 13px; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
.mono { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; font-size: 12px; }
.nowrap { white-space: nowrap; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.ellipsis { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.center { text-align: center; }
.right { text-align: right; }

.empty { padding: 44px 16px; text-align: center; color: var(--muted); }
.empty .t { font-size: 13px; margin-bottom: 4px; }
.empty .s { font-size: 12px; color: var(--faint); }

/* ---------- 标签与按钮 ---------- */
.tag {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  line-height: 18px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.tag-blue { background: var(--accent-soft); color: #0C447C; }
.tag-green { background: var(--success-soft); color: var(--success); }
.tag-red { background: var(--danger-soft); color: var(--danger); }
.tag-amber { background: var(--warn-soft); color: var(--warn); }
.tag-gray { background: #F1EFE8; color: #5F5E5A; }

button, .btn {
  font: inherit;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease;
}
button:hover, .btn:hover { background: var(--surface-2); }
button:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #0C447C; }
.btn-danger { color: var(--danger); border-color: rgba(163, 45, 45, .3); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: 3px 9px; font-size: 12px; border-radius: 6px; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-link {
  border: none; background: none; padding: 2px 4px; color: var(--accent);
  cursor: pointer; font-size: 12px;
}
.btn-link:hover { text-decoration: underline; background: none; }
.btn-link.danger { color: var(--danger); }
.row-actions { display: flex; gap: 2px; flex-wrap: wrap; }

/* 注意：必须排除复选框/单选框。
   它们如果被套上 width:100% + padding，放进下面那种"一格一个省"的小格子里
   会把格子整个撑满，把文字挤到格外去（被相邻格子的背景盖住，只剩第一个字）。
   凡是新增 checkbox，都不要再单独去覆盖 width。 */
input:not([type="checkbox"]):not([type="radio"]), select, textarea {
  font: inherit;
  font-size: 13px;
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(24, 95, 165, .12);
}
textarea { resize: vertical; min-height: 62px; }

.searchbar { display: flex; gap: 8px; align-items: center; }
.searchbar input { width: 200px; }

/* ---------- 表单 ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field-full { grid-column: 1 / -1; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.field .hint { font-size: 11px; color: var(--faint); margin-top: 4px; }
.field .err { font-size: 11px; color: var(--danger); margin-top: 4px; }

/* ---------- 弹窗 ---------- */
.mask {
  position: fixed; inset: 0; background: rgba(20, 20, 19, .38);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50;
}
.modal {
  background: var(--surface);
  border-radius: 12px;
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .18);
}
.modal.wide { max-width: 780px; }
.modal-head {
  padding: 15px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-head h3 { font-size: 14px; font-weight: 500; margin: 0; }
.modal-body { padding: 18px; overflow: auto; }
.modal-foot {
  padding: 13px 18px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px;
}
.close-x {
  border: none; background: none; font-size: 18px; line-height: 1; color: var(--muted);
  cursor: pointer; padding: 0 4px;
}

/* ---------- 二维码面板 ---------- */
.qr-panel { display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap; }
.qr-box {
  width: 180px; height: 180px; border: 1px solid var(--border); border-radius: 10px;
  display: flex; align-items: center; justify-content: center; background: #fff; padding: 8px;
}
.qr-box img { width: 100%; height: 100%; display: block; }
.qr-meta { flex: 1; min-width: 220px; }
.kv { display: grid; grid-template-columns: 76px 1fr; gap: 6px 10px; font-size: 12px; }
.kv .k { color: var(--muted); }
.kv .v { word-break: break-all; }

/* ---------- 表单里的图片行（图片型目标） ---------- */
.pm-img-row { display: flex; gap: 8px; align-items: center; }
.pm-img-row button { flex: 0 0 auto; }
.pm-prev { margin-top: 8px; }
.pm-prev img {
  max-width: 100%; max-height: 180px; border-radius: 8px;
  border: 1px solid var(--border); display: block;
}

/* ---------- 地域限制的多选网格 ---------- */
.geo-block { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--border); }
/* 88px 是"黑龙江""内蒙古"这类三字省名放得下的最小宽度 */
.geo-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 6px;
}
.geo-item {
  display: flex; align-items: center; gap: 6px; cursor: pointer;
  min-width: 0;
  padding: 7px 9px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 12px; background: var(--surface-2); user-select: none;
}
.geo-item:hover { border-color: var(--border-strong); }
/* 复选框保持原生尺寸。width/height 必须显式写死，不能靠继承 */
.geo-item input[type="checkbox"] {
  flex: 0 0 auto; width: 14px; height: 14px; margin: 0; padding: 0;
  accent-color: var(--accent); cursor: pointer;
}
/* 万一省名还是超出了格子，宁可省略号，也不要溢出到隔壁格子下面 */
.geo-item span {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0;
}
.geo-item input:checked + span { font-weight: 500; color: #0C447C; }

/* ---------- 地域限制：当前网络自检 ---------- */
.geo-probe {
  margin: 12px 0 10px; padding: 9px 11px; border-radius: 8px;
  font-size: 12px; line-height: 1.65; word-break: break-all;
  background: var(--surface-2); border: 1px solid var(--border);
}
.geo-probe.warn { background: var(--warn-soft); border-color: #EBD9B4; color: var(--warn); }
.geo-probe .good { color: #0F6E3F; font-weight: 500; }
.geo-probe .bad { color: var(--danger); font-weight: 500; }

/* ---------- 目标池里的小缩略图 ---------- */
.tg-thumb img {
  max-width: 96px; max-height: 60px; border-radius: 6px;
  border: 1px solid var(--border); display: block;
}

/* ---------- 二维码工具页 ---------- */
.tools-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.tools-grid .card { margin: 0; }
.drop-zone {
  border: 1px dashed var(--border-strong); border-radius: 10px;
  padding: 26px 16px; text-align: center; cursor: pointer;
  background: var(--surface-2); transition: border-color .15s, background .15s;
}
.drop-zone:hover, .drop-zone.over { border-color: var(--accent); background: var(--accent-soft); }
.drop-zone .t { font-size: 13px; font-weight: 500; }
.drop-zone .s { font-size: 12px; color: var(--muted); margin-top: 4px; }
#qr-decode-out textarea { width: 100%; font-family: var(--mono, monospace); font-size: 12px; }
#qr-out .qr-box img { width: 100%; height: 100%; display: block; }

@media (max-width: 820px) {
  .tools-grid { grid-template-columns: 1fr; }
}

/* ---------- 趋势图 ---------- */
.trend { display: flex; align-items: flex-end; gap: 10px; height: 132px; padding-top: 8px; }
.trend .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.trend .bar {
  width: 100%; max-width: 42px; background: var(--accent); border-radius: 4px 4px 0 0;
  min-height: 3px; transition: height .3s ease;
}
.trend .bar.zero { background: #D9D9D5; }
.trend .lbl { font-size: 11px; color: var(--muted); }
.trend .num { font-size: 11px; color: var(--faint); }

.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 1fr 52px; gap: 10px; align-items: center; font-size: 12px; }
.bar-track { background: var(--surface-2); border-radius: 999px; height: 8px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--success); border-radius: 999px; }

/* ---------- 分页 / Toast ---------- */
.pager { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--border); }
.pager .info { font-size: 12px; color: var(--muted); margin-right: auto; }

#toast-root { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 80; }
.toast {
  background: #2C2C2A; color: #fff; padding: 9px 14px; border-radius: 8px;
  font-size: 13px; box-shadow: var(--shadow); max-width: 340px;
}
.toast.err { background: var(--danger); }
.toast.ok { background: var(--success); }

/* ---------- 终端式提示 ---------- */
.note {
  padding: 10px 12px; border-radius: 8px; font-size: 12px; line-height: 1.7;
  background: var(--warn-soft); color: var(--warn);
}
.note.info { background: var(--accent-soft); color: #0C447C; }
.note.warn { background: var(--danger-soft, #FCEBEB); color: var(--danger, #A32D2D); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

@media (max-width: 820px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%; flex: none; height: auto; position: static;
    flex-direction: row; align-items: center; gap: 12px; padding: 10px 14px;
    overflow-x: auto;
  }
  .brand { padding: 0 4px 0 0; flex: 0 0 auto; }
  .brand .name { white-space: nowrap; }
  .nav { flex-direction: row; gap: 6px; }
  .nav a { white-space: nowrap; padding: 6px 10px; }
  .side-foot { margin: 0 0 0 auto; padding: 0; border: none; display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
  .side-foot .me { display: none; }
  .main { padding: 14px 12px 50px; }
  .form-grid { grid-template-columns: 1fr; }

  /* 操作列不换行，否则窄屏上「二维码/目标池/编辑/删除」会竖成一条 */
  .row-actions { flex-wrap: nowrap; }

  /* 手机端：搜索框独占一行，否则会被挤成一条缝 */
  .actions { width: 100%; }
  .actions > input { flex: 1 1 100%; width: 100% !important; }

  /* 弹窗贴着屏幕边缘，留出更多可视面积 */
  .mask { padding: 8px; }
  .modal { max-height: 94vh; }
  .modal-body { padding: 14px; }
  .modal-foot { padding: 12px 14px; }

  /* 单元格内边距收窄，让一屏能多看到一列 */
  th, td { padding: 8px 10px; }
  .ellipsis { max-width: 170px; }
}
