:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --border: #e2e6ef;
  --text: #1f2430;
  --muted: #6b7280;
  --brand: #2f6fed;
  --brand-dark: #1f55c4;
  --ok: #12894a;
  --warn: #b7791f;
  --err: #c53030;
  --net: #2b6cb0;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(20, 30, 60, 0.08), 0 6px 20px rgba(20, 30, 60, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Source Han Sans SC", sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

/* ---------- 登录页 ---------- */

#login-view {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #eef3ff 0%, #f7f9fc 60%, #eef7f2 100%);
  z-index: 100;
}

.login-card {
  width: min(380px, 92vw);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 28px 26px;
}

.login-card h1 { margin: 0 0 4px; font-size: 20px; }
.login-card p.sub { margin: 0 0 20px; color: var(--muted); font-size: 13px; }
.login-card .field { margin-bottom: 14px; }
.login-error { color: var(--err); font-size: 13px; min-height: 18px; margin-top: 8px; }

/* 登录 / 注册 切换 */
.auth-switch { display: flex; align-items: center; justify-content: center; gap: 5px; margin-top: 12px; }
.auth-link { color: var(--brand); font-size: 13px; text-decoration: none; cursor: pointer; }
.auth-link:hover { color: var(--brand-dark); text-decoration: underline; }
.switch-line { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text); cursor: pointer; }
.switch-line input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; }

/* ---------- 钱包 / 计费 ---------- */

.wallet-cards { display: flex; flex-wrap: wrap; gap: 12px; }
.wcard {
  flex: 1 1 150px;
  min-width: 140px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  background: var(--bg);
}
.wcard .wl { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.wcard .wv { font-size: 20px; font-weight: 700; }
.wcard.primary { border-color: var(--brand); }
.wcard.primary .wv { color: var(--brand); }
.wcard.ok .wv { color: var(--ok); }
.ledger-in { color: var(--ok); font-weight: 600; }
.ledger-out { color: var(--err); font-weight: 600; }
#wallet-badge.ok { color: var(--ok); border-color: var(--ok); }

.panel#panel-agent-apply .rules-box { max-width: 560px; }

/* ---------- 布局 ---------- */

header.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 14px;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

header.topbar .logo { font-weight: 700; font-size: 16px; white-space: nowrap; }
header.topbar .logo small { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 6px; }
header.topbar .spacer { flex: 1; }

nav.tabs {
  display: flex;
  gap: 4px;
  padding: 0 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
nav.tabs button {
  border: 0;
  background: transparent;
  padding: 11px 14px;
  cursor: pointer;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
nav.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

main { padding: 18px; max-width: 1280px; margin: 0 auto; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.panel h2 { margin: 0 0 12px; font-size: 15px; }
.panel h2 .hint { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 8px; }

.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row > * { min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; color: var(--muted); }
.field input, .field select, .field textarea {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  outline: none;
  min-width: 0;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.12); }
.field input[readonly] { background: #f7f8fb; color: var(--muted); }

button.btn {
  padding: 8px 14px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  transition: 0.15s;
}
button.btn:hover { border-color: #c9d2e3; background: #fafbff; }
button.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
button.btn.primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
button.btn.danger { color: var(--err); border-color: #f2c9c9; }
button.btn.danger:hover { background: #fff5f5; }
button.btn.warn { color: var(--warn); border-color: #f0e0bd; }
button.btn.warn:hover { background: #fdf6e8; }
button.btn.sm { padding: 4px 9px; font-size: 12px; border-radius: 6px; }
button.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 18px;
  background: #eef1f7;
  color: var(--muted);
}
.badge.ok { background: #e6f6ec; color: var(--ok); }
.badge.warn { background: #fdf3e2; color: var(--warn); }
.badge.err { background: #fdeaea; color: var(--err); }
.badge.run { background: #e8f0fe; color: var(--brand); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
table th, table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
table th { color: var(--muted); font-weight: 500; font-size: 12px; background: #fafbfd; }
table tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafcff; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- 任务列表: 桌面表格 / 移动端卡片 ---------- */
.task-cards { display: none; }
.task-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 10px;
  background: #fff;
}
.task-card .tc-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.task-card .tc-acc { font-size: 14px; min-width: 0; overflow-wrap: anywhere; }
.task-card .tc-progress { margin-bottom: 4px; }
.task-card .tc-meta { margin-bottom: 4px; }
.task-card .tc-result { overflow-wrap: anywhere; margin-bottom: 8px; }
.task-card .tc-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.progress { height: 6px; background: #eef1f7; border-radius: 999px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--brand); width: 0; transition: width 0.3s; }
.progress.indet > i { width: 35% !important; animation: slide 1.2s infinite ease-in-out; }
@keyframes slide { 0% { margin-left: -35%; } 100% { margin-left: 100%; } }

#map { height: 460px; border-radius: var(--radius); border: 1px solid var(--border); }
.map-wrap { position: relative; }
.map-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  align-items: flex-end;
}

.stat-line { color: var(--muted); font-size: 13px; display: flex; gap: 16px; flex-wrap: wrap; }
.stat-line b { color: var(--text); font-variant-numeric: tabular-nums; }

.logbox {
  background: #0f1420;
  color: #d7dce6;
  border-radius: var(--radius);
  padding: 12px;
  font: 12px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  max-height: 420px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
.logbox .l-debug { color: #8b93a7; }
.logbox .l-info { color: #d7dce6; }
.logbox .l-ok { color: #6ee7a8; }
.logbox .l-warn { color: #f6c66b; }
.logbox .l-error { color: #ff8a8a; }
.logbox .l-net { color: #79b8ff; }

.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(16, 22, 36, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}
.modal {
  background: #fff;
  border-radius: 12px;
  width: min(860px, 96vw);
  max-height: 88vh;
  overflow: auto;
  padding: 20px;
  box-shadow: 0 20px 60px rgba(10, 20, 40, 0.3);
}
.modal h3 { margin: 0 0 12px; font-size: 16px; display: flex; align-items: center; gap: 10px; }
.modal .close { margin-left: auto; cursor: pointer; border: 0; background: transparent; font-size: 20px; color: var(--muted); line-height: 1; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: #1f2430;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 300;
  opacity: 0;
  transition: 0.25s;
  pointer-events: none;
  max-width: 80vw;
}
.toast.show { opacity: 1; }
.toast.err { background: #b3261e; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.empty { color: var(--muted); text-align: center; padding: 26px 0; font-size: 13px; }
.right { text-align: right; }
.mt8 { margin-top: 8px; }
.mt12 { margin-top: 12px; }
.hidden { display: none !important; }

.rules-box {
  background: #f8faff;
  border: 1px solid #e3ebfa;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12.5px;
  color: #3d4a63;
  white-space: pre-wrap;
}

/* ---------- 报价框 (填完公里数 → 告诉你要花多少钱) ---------- */

.cost-box {
  background: #f7faff;
  border: 1px solid #dbe7fd;
  border-left: 3px solid var(--brand);
  border-radius: 8px;
  padding: 11px 13px;
}
.cost-box .cost-main { font-size: 14.5px; color: #26324a; }
.cost-box .cost-main b { font-size: 18px; }
.cost-box .cost-amt { color: var(--brand); }
.cost-box .cost-sub { margin-top: 4px; font-size: 12.5px; color: var(--muted); }
.cost-box .cost-sub b { color: #26324a; }
.cost-box .cost-sub.err { color: var(--err); }
.cost-box.free { border-left-color: var(--muted); background: #fafbfd; }
.cost-box.warn { border-left-color: var(--err); background: #fff8f8; border-color: #f6dddd; }
.cost-box.warn .cost-amt { color: var(--err); }

.checkline { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.checkline input { margin: 0; }

/* ---------- 代理申请 / 联系方式 ---------- */

.qq-block,
.apply-qq { display: flex; flex-direction: column; gap: 6px; }

.qq-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.qq-num {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 1.5px;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Courier New", monospace;
  color: var(--brand);
  background: #eef3ff;
  border: 1px solid #d8e3ff;
  border-radius: 8px;
  padding: 4px 12px;
}

#panel-agent-apply textarea { width: 100%; resize: vertical; }

/* ---------- 邀请链接 ---------- */

.invite-banner {
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13px;
  line-height: 1.5;
  margin-bottom: 12px;
  border: 1px solid #d8e3ff;
  background: #eef3ff;
  color: #25437e;
}
.invite-banner b { color: var(--brand); }
.invite-banner.ok { border-color: #cfe9d8; background: #eefaf3; color: #17603a; }
.invite-banner.ok b { color: var(--ok); }
.invite-banner.warn { border-color: #f4e3c2; background: #fdf7ec; color: #8a5a12; }

.invite-box {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.invite-box input {
  flex: 1;
  min-width: 220px;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Courier New", monospace;
  font-size: 13px;
  background: #f8faff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}

/* ---------- 新手引导(三步跑起来) ---------- */

.guide { display: flex; flex-direction: column; gap: 10px; }
.guide-step { display: flex; gap: 10px; align-items: flex-start; }
.guide-step > b {
  flex: 0 0 22px;
  height: 22px;
  line-height: 22px;
  text-align: center;
  border-radius: 999px;
  background: #eef3ff;
  color: var(--brand);
  font-size: 12px;
  font-weight: 700;
}
.guide-step > div > b { color: var(--text); }

/* ---------- 高级选项折叠 ---------- */

details.adv {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfcfe;
  padding: 8px 12px;
}
details.adv > summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--brand);
  user-select: none;
  list-style: none;
}
details.adv > summary::-webkit-details-marker { display: none; }
details.adv > summary::before { content: '▸ '; }
details.adv[open] > summary { color: var(--muted); margin-bottom: 6px; }
details.adv[open] > summary::before { content: '▾ '; }

/* 账号表格里的「出口线路」下拉: 紧凑, 只显示管理员起的名字 (不显示真实 IP) */
table select.line-sel {
  padding: 5px 8px;
  font-size: 12.5px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: inherit;
  max-width: 170px;
}

/* 账号表格: 单元格不换行挤压, 窄屏靠横向滑动看全 (配合已有的 overflow-x:auto) */
#accounts-body th,
#accounts-body td {
  white-space: nowrap;
}

@media (max-width: 760px) {
  /* ---- 顶栏: logo 独占一行, 状态元素紧凑排第二行 ---- */
  header.topbar {
    gap: 6px 8px;
    padding: 8px 12px;
    padding-top: max(8px, env(safe-area-inset-top));
  }
  header.topbar .logo { flex: 1 1 100%; font-size: 15px; }
  header.topbar .logo small { display: none; }
  header.topbar .spacer { flex: 1 1 auto; }
  header.topbar .badge { font-size: 11px; padding: 1px 7px; }
  header.topbar #apply-agent-btn { order: 9; }

  /* ---- 标签栏: 横向轻扫, 隐藏滚动条 ---- */
  nav.tabs {
    padding: 0 6px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  nav.tabs::-webkit-scrollbar { display: none; }
  nav.tabs button { padding: 10px 12px; font-size: 13.5px; }

  /* ---- 主体: 收窄 + 刘海屏安全区 ---- */
  main {
    padding: 12px max(12px, env(safe-area-inset-right))
             calc(16px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  }

  .panel { padding: 12px; }
  .panel h2 .hint { display: block; margin: 3px 0 0; line-height: 1.45; }

  .grid2, .grid3 { grid-template-columns: 1fr; }

  /* ---- 表单: 每个字段独占一行, 主按钮全宽 ---- */
  .row { gap: 8px; }
  .row > .field { flex: 1 1 100% !important; width: auto !important; }
  /* "指定日期 / 时 / 分" 仍保持一行排开 */
  #field-once > .field, #field-runat > .field { flex: 1 1 0 !important; min-width: 0; }
  #field-once, #field-runat { width: 100%; }
  .row > button.btn.primary { flex: 1 1 100%; }
  .row > button.btn { min-height: 40px; }

  /* 输入字号 >=16px, 避免 iOS Safari 聚焦时自动放大页面 */
  .field input, .field select, .field textarea,
  .invite-box input { font-size: 16px; }
  .field input, .field select, .field textarea { padding: 10px 12px; }

  /* ---- 地图工具栏: 数字框两个一行, 按钮均分铺满 ---- */
  .map-toolbar { gap: 6px; }
  .map-toolbar .field { flex: 1 1 calc(50% - 6px) !important; width: auto !important; }
  .map-toolbar .btn { flex: 1 1 auto; padding: 9px 8px; text-align: center; }
  #map { height: 320px; }

  .btn { min-height: 40px; }
  .btn.sm { min-height: 32px; padding: 6px 10px; }

  /* ---- 表格: 可横向轻扫, 不再被裁切 ---- */
  table {
    display: block;
    overflow-x: auto;
    min-width: 100%;
    -webkit-overflow-scrolling: touch;
  }

  .modal-back { padding: 10px; }
  .modal { padding: 16px 14px; max-height: 92vh; }
  .toast { bottom: calc(24px + env(safe-area-inset-bottom)); }

  /* 折叠标题做成整行可点, 手指更好按 */
  details.adv { padding: 4px 12px; }
  details.adv > summary { min-height: 42px; display: flex; align-items: center; }
  details.adv[open] > summary { min-height: 34px; }

  /* 任务页移动端: 隐藏宽表格, 用卡片列表 */
  #tasks-body .task-table-wrap { display: none; }
  #tasks-body .task-cards { display: block; }
}
