:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --ink: #1a2233;
  --ink-2: #5a6779;
  --ink-3: #8b97a8;
  --line: #e4e9f2;
  --brand: #2f6bff;
  --brand-dark: #1b4fd8;
  --ok: #0f9d58;
  --warn: #d98300;
  --err: #d93a3a;
  --side: #131a2a;
  --side-2: #1c2436;
  --radius: 12px;
  --mono: "Cascadia Code", "JetBrains Mono", Consolas, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.6 -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app { display: flex; min-height: 100vh; }

/* ---------- 侧边栏 ---------- */
.sidebar {
  width: 232px;
  flex: 0 0 232px;
  background: var(--side);
  color: #cfd8e8;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; gap: 10px; align-items: center; padding: 0 6px 20px; }
.logo {
  width: 36px; height: 36px; flex: 0 0 36px;
  border-radius: 9px;
  background: linear-gradient(135deg, #2f6bff, #6f9bff);
  color: #fff; font-weight: 700; font-size: 12px;
  display: grid; place-items: center;
  letter-spacing: .5px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.3; }
.brand-text strong { color: #fff; font-size: 14px; }
.brand-text span { color: #77839a; font-size: 11px; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav button {
  all: unset;
  display: flex; align-items: center; gap: 9px;
  padding: 9px 10px;
  border-radius: 8px;
  color: #b9c3d6;
  font-size: 13.5px;
  cursor: pointer;
  transition: background .14s, color .14s;
  white-space: nowrap;
}
.nav button .ico { width: 16px; text-align: center; color: #6f7d95; font-size: 12px; }
.nav button:hover { background: var(--side-2); color: #fff; }
.nav button.active { background: var(--brand); color: #fff; }
.nav button.active .ico { color: #fff; }

.nav-link {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 10px; border-radius: 8px;
  color: #b9c3d6; font-size: 13.5px; text-decoration: none;
  transition: background .14s, color .14s; white-space: nowrap;
}
.nav-link .ico { width: 16px; text-align: center; color: #6f7d95; font-size: 12px; }
.nav-link .ext { margin-left: auto; font-size: 10px; color: #6f7d95; }
.nav-link:hover { background: var(--side-2); color: #fff; }
.nav-link:hover .ext { color: #fff; }

.side-foot { border-top: 1px solid #26304a; padding-top: 12px; margin-top: 10px; }
.conn { font-size: 12px; padding: 5px 9px; border-radius: 6px; background: #23304a; color: #9fb0c9; }
.conn.ok { background: rgba(15,157,88,.18); color: #6fe0a5; }
.conn.warn { background: rgba(217,131,0,.18); color: #ffc46b; }
.conn.err { background: rgba(217,58,58,.2); color: #ff9b9b; }
.tiny { font-size: 11px; color: #66738c; margin-top: 8px; word-break: break-all; line-height: 1.5; }

.user-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; }
.user-chip {
  font-size: 11.5px; color: #cfd8e8;
  background: #23304a; padding: 3px 9px; border-radius: 999px;
  max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.link-btn {
  all: unset;
  font-size: 11.5px; color: #7f8da6; cursor: pointer;
  padding: 3px 4px; border-radius: 5px;
}
.link-btn:hover { color: #ff9b9b; }
.link-btn.logout { display: block; margin-top: 6px; font-size: 11px; color: #6b7890; }
.link-btn.logout:hover { color: #ff9b9b; }
.link-btn.danger { color: #e05b5b; }
.link-btn[disabled] { opacity: .5; cursor: default; }

.role-tag {
  font-size: 10.5px; padding: 2px 7px; border-radius: 999px;
  background: #2a3752; color: #9fb0c9; white-space: nowrap;
}
.role-tag.admin { background: rgba(47,107,255,.22); color: #9dc0ff; }
.pill {
  font-size: 10px; padding: 1px 6px; border-radius: 999px;
  background: #eef2fb; color: #3a5fa8; vertical-align: middle;
}

/* ---------- 数据看板 ---------- */
.dash { display: flex; flex-direction: column; gap: 16px; }
.stat.accent b { font-size: 24px; color: var(--brand-dark); }
.stat em { font-size: 11px; color: var(--ink-3); font-style: normal; }

.chart-grid { display: grid; grid-template-columns: 1.15fr 1fr; gap: 16px; }
@media (max-width: 1080px) { .chart-grid { grid-template-columns: 1fr; } }

.chart { width: 100%; height: auto; display: block; }
.bar-rect { fill: #4b80f5; }
.bar-rect:hover { fill: #2f6bff; }
.bar-val { font-size: 11px; fill: #5a6779; font-family: var(--mono); }
.bar-label { font-size: 10.5px; fill: #8b97a8; }
.line-path { fill: none; stroke: #2f6bff; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.line-dot { fill: #fff; stroke: #2f6bff; stroke-width: 2.5; }

.rank { display: flex; flex-direction: column; gap: 9px; }
.rank-row { display: grid; grid-template-columns: 130px 1fr 72px; align-items: center; gap: 12px; }
.rank-name { font-size: 12.5px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-bar { height: 9px; background: #eef1f7; border-radius: 999px; overflow: hidden; }
.rank-bar i { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, #6f9bff, #2f6bff); }
.rank-val { font-size: 12.5px; font-family: var(--mono); text-align: right; color: var(--ink); }

.addr-form {
  display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap;
  margin-top: 16px; padding-top: 16px; border-top: 1px dashed var(--line);
}
.addr-form .field { flex: 1 1 200px; }
.addr-form button { margin-bottom: 1px; }

.op-cell { display: flex; gap: 4px; flex-wrap: wrap; }
.op-cell .link-btn { color: #3a5fa8; }
.op-cell .link-btn:hover { text-decoration: underline; }
.op-cell .link-btn.danger { color: #d93a3a; }
.ok-text { color: var(--ok); font-size: 12.5px; }
.user-mgmt { display: flex; flex-direction: column; gap: 16px; }

/* ---------- 实时播报 ---------- */
.cast { display: flex; flex-direction: column; gap: 16px; }

.cast-controls { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.switch { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--ink-2); cursor: pointer; user-select: none; }
.switch input {
  appearance: none;
  width: 34px; height: 19px; border-radius: 999px;
  background: #dfe5f0; position: relative; cursor: pointer;
  transition: background .18s; flex: none;
}
.switch input::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 15px; height: 15px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(20,30,50,.25);
  transition: transform .18s;
}
.switch input:checked { background: var(--brand); }
.switch input:checked::after { transform: translateX(15px); }

.feed {
  display: flex; flex-direction: column; gap: 1px;
  max-height: 460px; overflow-y: auto;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--line);
}
.feed-item {
  display: grid;
  grid-template-columns: 76px 84px minmax(80px, 1fr) minmax(140px, 1.4fr) 96px;
  align-items: center; gap: 10px;
  padding: 9px 12px;
  background: #fff;
  font-size: 12.5px;
  transition: background .5s;
}
.feed-item.fresh { background: #eaf1ff; }
.feed-time { font-family: var(--mono); font-size: 11.5px; color: var(--ink-3); }
.feed-tag {
  font-size: 10.5px; padding: 2px 7px; border-radius: 5px;
  text-align: center; white-space: nowrap;
}
.feed-tag.times { background: rgba(47,107,255,.1); color: var(--brand); }
.feed-tag.smart { background: rgba(15,157,88,.1); color: var(--ok); }
.feed-label { color: var(--ink); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed-detail { color: var(--ink-2); }
.feed-tx { font-family: var(--mono); font-size: 11px; color: var(--ink-3); text-align: right; }
.feed .empty { padding: 28px 12px; text-align: center; background: #fff; margin: 0; }

.cast-notify {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-top: 14px; padding-top: 14px;
  border-top: 1px dashed var(--line);
}
.cast-notify-label { font-size: 12.5px; color: var(--ink-3); }
.chips { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.chip {
  font-size: 11.5px; padding: 2px 8px; border-radius: 999px;
  background: #eef2f8; color: var(--ink-2);
}
.chip.ok { background: rgba(15,157,88,.1); color: var(--ok); }
.chip.muted { background: transparent; color: var(--ink-3); padding-left: 0; }
button.small { padding: 5px 12px; font-size: 11.5px; }

/* 推送通道与分组 */
table.mini { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.mini th {
  text-align: left; font-weight: 500; color: var(--ink-3); font-size: 11.5px;
  padding: 7px 10px; border-bottom: 1px solid var(--line); background: #fafbfe;
}
table.mini td { padding: 9px 10px; border-bottom: 1px solid #f0f3f9; vertical-align: middle; }
table.mini tr:last-child td { border-bottom: 0; }
.ta-r { text-align: right; }
.row-acts { white-space: nowrap; }
.row-acts .link {
  background: none; border: 0; padding: 0 6px; font-size: 12px;
  color: var(--brand); cursor: pointer;
}
.row-acts .link.danger { color: #d93a3a; }
.row-acts .link:disabled { opacity: .5; cursor: default; }
.muted { color: var(--ink-3); }

.cast-add {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--line);
}
.cast-add select, .cast-add input {
  padding: 7px 10px; font-size: 12.5px; border: 1px solid var(--line);
  border-radius: 7px; background: #fff; color: var(--ink); outline: none; font-family: inherit;
}
.cast-add input.grow { flex: 1; min-width: 220px; }
.cast-add select:focus, .cast-add input:focus { border-color: var(--brand); }

.routes { margin-top: 16px; }
.routes-title { font-size: 12px; color: var(--ink-3); margin: 0 0 8px; }
.route-row {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 9px 0; border-bottom: 1px solid #f2f5fa;
}
.route-row:last-child { border-bottom: 0; }
.route-who { display: flex; flex-direction: column; gap: 2px; min-width: 170px; }
.route-who b { font-size: 12.5px; font-weight: 500; }
.route-who .mono { font-family: var(--mono); font-size: 10.5px; color: var(--ink-3); }
.chip.pick {
  background: #f2f5fa; color: var(--ink-2); border: 1px solid transparent;
  cursor: pointer; font-family: inherit;
}
.chip.pick:hover { border-color: #c9d6ee; }
.chip.pick.on { background: rgba(47,107,255,.1); color: var(--brand); border-color: rgba(47,107,255,.35); }

@media (max-width: 860px) {
  .feed-item { grid-template-columns: 68px 1fr; grid-auto-rows: auto; }
  .feed-detail, .feed-tx { grid-column: 1 / -1; }
}

/* ---------- 登录页 ---------- */
.login-body {
  min-height: 100vh;
  margin: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 15% -10%, #24334f 0%, transparent 60%),
    radial-gradient(900px 500px at 100% 100%, #1d2b45 0%, transparent 55%),
    #0f1624;
}
.login-card {
  width: 100%; max-width: 372px;
  background: #fff;
  border-radius: 16px;
  padding: 30px 30px 24px;
  box-shadow: 0 24px 60px rgba(4, 10, 22, .5);
}
.login-brand { display: flex; gap: 10px; align-items: center; margin-bottom: 22px; }
.login-brand .brand-text strong { color: var(--ink); font-size: 14px; }
.login-brand .brand-text span { color: var(--ink-3); font-size: 11px; }
.login-card h1 { margin: 0; font-size: 21px; font-weight: 650; letter-spacing: -.3px; }
.login-sub { margin: 5px 0 22px; color: var(--ink-3); font-size: 12.5px; }
.login-card .field { margin-bottom: 14px; }
.login-card input { padding: 10px 12px; font-size: 13.5px; }
.login-btn { width: 100%; margin-top: 6px; padding: 10px; font-size: 13.5px; }
.login-card .err-box { margin-bottom: 14px; }
.login-foot { margin: 18px 0 0; text-align: center; color: #a7b2c2; font-size: 11px; line-height: 1.6; }

/* ---------- 主区 ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  padding: 24px 28px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky; top: 0; z-index: 5;
}
.titles h1 { margin: 0; font-size: 19px; font-weight: 650; letter-spacing: -.2px; }
.titles p { margin: 3px 0 0; color: var(--ink-3); font-size: 12.5px; }

.view { padding: 22px 28px 60px; display: flex; flex-direction: column; gap: 16px; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: 0 1px 2px rgba(20,30,50,.03);
}
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 14px; }
.card-head h3 { margin: 0; font-size: 14.5px; font-weight: 600; }
.card-head .desc { margin: 4px 0 0; color: var(--ink-3); font-size: 12.5px; max-width: 620px; }
.ep {
  font-family: var(--mono); font-size: 11.5px;
  background: #eef2fb; color: #3a5fa8;
  padding: 4px 8px; border-radius: 6px; white-space: nowrap;
}

/* ---------- 表单 ---------- */
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px 14px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field .lbl { font-size: 12.5px; color: var(--ink-2); font-weight: 500; }
.field .req { color: var(--err); margin-left: 3px; }
.field small { color: var(--ink-3); font-size: 11.5px; }

input[type=text], input[type=number], select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  transition: border-color .14s, box-shadow .14s;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(47,107,255,.12);
  background: #fff;
}
input::placeholder { color: #b3bdcc; }

.row-actions { display: flex; gap: 10px; margin-top: 16px; align-items: center; }

button {
  font: inherit; font-size: 13px; font-weight: 500;
  padding: 8px 16px; border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background .14s, border-color .14s, opacity .14s;
}
button.primary { background: var(--brand); color: #fff; }
button.primary:hover { background: var(--brand-dark); }
button.primary:disabled { opacity: .6; cursor: default; }
button.ghost { background: #fff; border-color: var(--line); color: var(--ink-2); }
button.ghost:hover { border-color: #c6d2e6; color: var(--ink); }
button.ghost:disabled { opacity: .55; cursor: default; }

.note {
  margin: 12px 0 0; padding: 8px 11px;
  background: #f7f9fd; border-left: 3px solid #c9d6ee;
  color: var(--ink-2); font-size: 12px; border-radius: 0 6px 6px 0;
}

/* ---------- 结果区 ---------- */
.result { margin-top: 16px; border-top: 1px dashed var(--line); padding-top: 14px; }
.res-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.res-head .spacer { flex: 1; }
.res-head .msg { font-size: 12.5px; color: var(--ink-2); }
.badge { font-size: 11.5px; font-weight: 600; padding: 3px 8px; border-radius: 5px; letter-spacing: .2px; }
.badge.ok { background: rgba(15,157,88,.12); color: var(--ok); }
.badge.err { background: rgba(217,58,58,.12); color: var(--err); }
.badge.neutral { background: #eef1f7; color: var(--ink-2); }

.kv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.kv { background: #fff; padding: 9px 12px; display: flex; flex-direction: column; gap: 2px; }
.kv span { font-size: 11.5px; color: var(--ink-3); font-family: var(--mono); }
.kv b { font-size: 13.5px; font-weight: 600; word-break: break-all; }

.sub { margin-top: 14px; }
.sub h4 { margin: 0 0 6px; font-size: 12.5px; color: var(--ink-2); font-weight: 600; }

pre.json {
  margin: 0;
  background: #0f1626;
  color: #c8d6ef;
  padding: 13px 15px;
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.65;
  overflow: auto;
  max-height: 340px;
}

details.raw { margin-top: 12px; }
details.raw summary {
  cursor: pointer; font-size: 12px; color: var(--ink-3);
  user-select: none; outline: none;
}
details.raw summary:hover { color: var(--brand); }
details.raw pre.json { margin-top: 8px; }

.loading { color: var(--ink-3); font-size: 12.5px; padding: 10px 0; }
.err-box { background: rgba(217,58,58,.07); color: var(--err); padding: 10px 12px; border-radius: 8px; font-size: 12.5px; }
.empty { color: var(--ink-3); font-size: 12.5px; margin: 6px 0; }

/* ---------- 表格 ---------- */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.tbl th, .tbl td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl th { background: #f7f9fd; color: var(--ink-2); font-weight: 600; font-size: 11.5px; letter-spacing: .3px; }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl tbody tr:hover { background: #fafcff; }
.tbl code { font-family: var(--mono); font-size: 12px; color: #2b4b8a; }
.tbl .muted { color: var(--ink-3); }

.tag { font-family: var(--mono); font-size: 10.5px; font-weight: 700; padding: 2px 6px; border-radius: 4px; }
.tag.get { background: rgba(15,157,88,.12); color: var(--ok); }
.tag.post { background: rgba(47,107,255,.12); color: var(--brand); }

/* ---------- 统计条 ---------- */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex; flex-direction: column; gap: 4px;
}
.stat span { font-size: 11.5px; color: var(--ink-3); }
.stat b { font-size: 21px; font-weight: 650; letter-spacing: -.4px; font-variant-numeric: tabular-nums; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px;
  transform: translate(-50%, 16px);
  background: #1a2233; color: #fff;
  padding: 10px 18px; border-radius: 9px;
  font-size: 13px; box-shadow: 0 8px 24px rgba(10,20,40,.22);
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
  max-width: 80vw; z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: #b32d2d; }

@media (max-width: 860px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; flex: none; height: auto; position: static; flex-direction: row; align-items: center; gap: 12px; overflow-x: auto; padding: 12px; }
  .brand { padding: 0; flex: none; }
  .brand-text { display: none; }
  .nav { flex-direction: row; flex: none; }
  .side-foot { display: none; }
  .view, .topbar { padding-left: 16px; padding-right: 16px; }
}
/* ---------- 地址列表（笔数用户） ---------- */
.ab-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ab-mode { font-size: 12px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); }
.ab-ops { display: flex; gap: 10px; flex-wrap: wrap; }
.ab-ops .link-btn { color: #3a5fa8; }
.ab-ops .link-btn:hover { text-decoration: underline; }
.ab-ops .link-btn.danger { color: #d93a3a; }
.pill.ok { background: rgba(15,157,88,.12); color: #0f9d58; }.pill.warn { background: rgba(214,158,46,.16); color: #8a6100; }
.pill.bad { background: rgba(217,72,72,.14); color: #b3261e; }
.addrbook #abBody .tbl { min-width: 1150px; }
.addrbook .ab-mode { min-width: 112px; }
.addrbook #abBody .tbl th, .addrbook #abBody .tbl td { white-space: nowrap; }

/* ---------- 备注就地编辑 ---------- */
.ab-label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; border-radius: 6px; padding: 2px 6px; margin: -2px -6px; transition: background .15s; }
.ab-label:hover { background: #eef3fb; }
.ab-pencil { font-size: 11px; color: #9aa7bd; opacity: 0; transition: opacity .15s; }
.ab-label:hover .ab-pencil { opacity: 1; }
.ab-label.editing { background: #fff; padding: 4px 6px; box-shadow: 0 0 0 1px var(--line) inset; }
.ab-label-input { width: 220px; font-size: 13px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 6px; outline: none; }
.ab-label-input:focus { border-color: #3a5fa8; box-shadow: 0 0 0 3px rgba(58,95,168,.12); }
.ab-save { font-size: 12px; padding: 4px 10px; border: 0; border-radius: 6px; background: #3a5fa8; color: #fff; cursor: pointer; white-space: nowrap; }
.ab-save:hover { background: #2f4f8f; }
.ab-save:disabled { opacity: .6; cursor: default; }

/* ---------- 地址复制按钮 ---------- */
.ab-addr-line { display: inline-flex; align-items: center; gap: 6px; }
.ab-copy { font-size: 11px; padding: 1px 7px; border: 1px solid var(--line); border-radius: 5px; background: #fff; color: #3a5fa8; cursor: pointer; line-height: 1.7; transition: background .15s, border-color .15s; }
.ab-copy:hover { background: #eef3fb; border-color: #b9cbe6; }
.ab-copy:active { transform: translateY(1px); }
