/* The PDA console. Dark palette, large type (base 17px, key numbers bold and larger), 44px touch targets, one
   column on a phone. The page scrolls (no fixed panes). */
:root {
  --bg: #0d1117;
  --panel: #121a24;
  --panel-2: #0f151d;
  --line: #223044;
  --line-2: #2f4057;
  --text: #dbe4ee;
  --muted: #8d9aaa;
  --accent: #58a6ff;
  --ok: #3fd49f;
  --warn: #f0b545;
  --weak: #f0b545;
  --bad: #ff6b70;
  --font: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --touch: 44px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 17px/1.5 var(--font); }
body { overflow-x: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.5; }
a { color: var(--accent); }
h2 { font-size: 22px; margin: 0 0 12px; }
h3 { font-size: 19px; margin: 22px 0 8px; }
code { font-family: var(--mono); font-size: 15px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; overflow-wrap: anywhere; }
.muted { color: var(--muted); font-weight: normal; }
.small { font-size: 15px; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.big { font-size: 21px; font-weight: 700; }
.huge { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; }
.lv-good { color: var(--ok); }
.lv-ok { color: #a9d46b; }
.lv-weak { color: var(--weak); }
.lv-bad { color: var(--bad); }

#pda-app { max-width: 1280px; margin: 0 auto; padding: 0 16px 48px; }
#top { display: flex; align-items: center; gap: 16px; min-height: 56px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 20px; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.logo { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.user { margin-left: auto; display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.user .logout { text-decoration: none; min-height: var(--touch); display: inline-flex; align-items: center; padding: 0 6px; }

.btn { min-height: var(--touch); background: #1b2a3d; border: 1px solid var(--line-2); border-radius: 8px; padding: 6px 16px; white-space: nowrap; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn.primary { background: #1d3a5e; border-color: var(--accent); color: #eef6ff; font-weight: 600; }
.btn.danger { border-color: #6b2a2d; color: #ffc2c4; }
.btn.warn { border-color: #6b5420; color: #ffe3a6; background: #2a2210; }
.btn.big { min-height: 52px; padding: 8px 24px; font-size: 19px; }
.btn.small { min-height: 36px; padding: 2px 10px; font-size: 15px; }
.btn.loading { opacity: 0.75; cursor: progress; }
.btn.on { background: #10342a; border-color: var(--ok); color: var(--ok); font-weight: 700; }

.tabs { display: flex; gap: 8px; margin: 14px 0; overflow-x: auto; }
.tab { min-height: var(--touch); flex: 1 0 auto; background: var(--panel); border: 1px solid var(--line-2); border-radius: 8px; padding: 6px 16px; font-size: 18px; color: var(--muted); }
.tab.on { background: #1d3a5e; border-color: var(--accent); color: #fff; font-weight: 700; box-shadow: inset 0 -3px 0 var(--accent); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.card.pad { padding: 18px; }
.card + .card { margin-top: 14px; }
.notice-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 28px 22px; margin: 32px auto; max-width: 640px; text-align: center; }
.notice-card h2 { font-size: 26px; }
.notice-card p { margin: 10px 0; overflow-wrap: anywhere; }
.empty { padding: 32px 16px; text-align: center; }

.err-box { background: #2a1416; border: 1px solid #6b2a2d; border-left: 5px solid var(--bad); color: #ffd3d5; border-radius: 8px; padding: 12px 14px; margin: 12px 0; overflow-wrap: anywhere; }
.ok-box { background: #10261f; border: 1px solid #1f5a46; border-left: 5px solid var(--ok); color: #c5f3e1; border-radius: 8px; padding: 12px 14px; margin: 12px 0; overflow-wrap: anywhere; }
.help-box { background: #111d2b; border: 1px solid var(--line-2); border-left: 5px solid var(--accent); border-radius: 8px; padding: 12px 14px; margin: 12px 0; overflow-wrap: anywhere; }
.help-box p { margin: 6px 0; }
.help-box pre { margin: 8px 0; padding: 10px 12px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; font-family: var(--mono); font-size: 15px; white-space: pre-wrap; overflow-wrap: anywhere; }
.field-err { color: var(--bad); font-size: 16px; min-height: 0; }
.field-err:empty { display: none; }
.field-hint { color: var(--muted); font-size: 15px; }

.spinner { width: 28px; height: 28px; margin: 8px auto; border-radius: 50%; border: 3px solid var(--line-2); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- 设备 ---- */
.bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.stats { display: flex; gap: 22px; align-items: baseline; flex-wrap: wrap; }
.bar-r { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.map-line { font-size: 15px; color: var(--muted); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 380px), 1fr)); gap: 14px; }
.dev { padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; border-left: 5px solid var(--line-2); }
.dev.online { border-left-color: var(--ok); }
.dev.retired { opacity: 0.6; }
.dev header { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.dev .serial b { font-size: 24px; }
.dev footer { display: flex; gap: 10px; flex-wrap: wrap; }
.dev footer .btn { flex: 1; }
.pill { display: inline-block; padding: 2px 12px; border-radius: 999px; font-weight: 700; font-size: 16px; }
.pill.on { background: #10342a; color: var(--ok); border: 1px solid #1f5a46; }
.pill.off { background: #2a1416; color: var(--bad); border: 1px solid #6b2a2d; }
.pill.warn { background: #2a2210; color: var(--warn); border: 1px solid #6b5420; }
.tag { display: inline-block; margin-left: 6px; font-size: 14px; padding: 0 7px; border-radius: 4px; border: 1px solid var(--line-2); color: var(--muted); }
.tag.warn { color: var(--warn); border-color: #6b5420; }
.tag.bad { color: var(--bad); border-color: #6b2a2d; }
.tag.good { color: var(--ok); border-color: #1f5a46; }
.kvs { display: grid; grid-template-columns: 1fr; gap: 4px; }
.kv { display: grid; grid-template-columns: 7.5em 1fr; gap: 10px; align-items: baseline; min-width: 0; }
.kv .k { color: var(--muted); font-size: 16px; }
.kv .v { min-width: 0; overflow-wrap: anywhere; }
.kvs.wide { grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); column-gap: 24px; }
.kvs.wide .kv { grid-template-columns: 9em 1fr; }
.upg { border-top: 1px dashed var(--line-2); padding-top: 8px; display: flex; flex-direction: column; gap: 4px; }
.upg-h { font-weight: 700; color: var(--muted); font-size: 16px; }
.upg .err-box { margin: 4px 0; padding: 8px 10px; }

/* ---- 详情 dialog ---- */
dialog#detail { width: min(1000px, calc(100vw - 24px)); max-height: calc(100vh - 32px); background: var(--bg); color: var(--text); border: 1px solid var(--line-2); border-radius: 14px; padding: 0; }
dialog#detail::backdrop { background: rgba(5, 8, 12, 0.7); }
.dlg-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.dlg-head h2 { margin: 0; font-size: 22px; }
.dlg-body { padding: 14px 16px 22px; }
.sum { display: flex; flex-wrap: wrap; gap: 8px 22px; margin-bottom: 10px; }
.gaps { margin: 4px 0 12px; padding-left: 1.3em; color: var(--weak); }
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 16px; }
.tbl th, .tbl td { padding: 7px 10px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl th { color: var(--muted); font-weight: 600; background: var(--panel-2); position: sticky; top: 0; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl td.wrap { white-space: normal; overflow-wrap: anywhere; min-width: 14em; }
.tbl tr.stale td { color: var(--muted); }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: #16212f; }
.tbl tr.sel td { background: #1d3a5e; }
.tbl tr.expand td { white-space: pre-wrap; font-family: var(--mono); font-size: 14px; background: var(--panel-2); overflow-wrap: anywhere; }
.tbl .linkish { color: var(--accent); cursor: pointer; text-decoration: underline dotted; }
.row-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: 12px 0; }

/* ---- 出回应码 ---- */
.code-form { display: flex; flex-direction: column; gap: 10px; max-width: 640px; }
.lbl { color: var(--muted); font-size: 16px; margin-top: 6px; display: block; }
.inp { min-height: var(--touch); width: 100%; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 8px; padding: 8px 12px; outline: none; min-width: 0; }
.inp:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(88, 166, 255, 0.25); }
.inp.bad { border-color: var(--bad); }
.inp.big { font-size: 19px; }
.huge-inp { font-size: 30px; letter-spacing: 0.15em; font-weight: 700; min-height: 60px; }
.code-row { display: flex; gap: 10px; }
.code-row .inp { flex: 1; }
.code-out { margin-top: 18px; max-width: 640px; }
.code-card { border: 2px solid var(--ok); border-radius: 14px; background: #0f231c; padding: 18px; text-align: center; }
.code-big { font-size: clamp(40px, 14vw, 112px); font-weight: 800; line-height: 1.1; color: #eafff6; letter-spacing: 0.06em; margin: 6px 0; white-space: nowrap; }
.code-card .row-actions { justify-content: center; }

/* ---- 配置 ---- */
.ver { margin-bottom: 8px; }
.field { margin-bottom: 4px; }
.cfg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 4px 18px; }
.ovrs { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 380px), 1fr)); gap: 12px; }
.ovr { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--panel-2); display: flex; flex-direction: column; gap: 4px; }
.ovr-h b { font-size: 19px; }
.row-actions.save-bar { padding-top: 12px; border-top: 1px solid var(--line); }
.versions { margin-top: 14px; color: var(--muted); }
details > summary { cursor: pointer; min-height: var(--touch); display: flex; align-items: center; }
.json-edit { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 6px; }
.json-edit summary { font-weight: 700; font-size: 18px; }
textarea.inp { font-family: var(--mono); font-size: 15px; line-height: 1.45; min-height: 320px; resize: vertical; white-space: pre; overflow-wrap: normal; overflow-x: auto; }

/* ---- 升级 ---- */
.dist { display: flex; flex-wrap: wrap; gap: 8px 18px; margin: 8px 0; }

/* ---- 位置 ---- */
.plots { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr)); gap: 14px; margin: 12px 0; }
.plot { border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); padding: 8px; }
.plot h4 { margin: 0 0 6px; font-size: 17px; }
.plot svg { width: 100%; height: auto; display: block; background: #0b1119; border-radius: 6px; }
.plot svg text { font-family: var(--mono); }

/* ---- AP 观测 ---- */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.filters .f { display: flex; flex-direction: column; min-width: 140px; flex: 1 1 160px; }
.filters .f.wide { flex: 2 1 240px; }

/* ---- 地图 ---- */
.site-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 360px), 1fr)); gap: 14px; margin: 12px 0; }
.site-card { padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; border-left: 5px solid var(--line-2); }
.site-card.ok { border-left-color: var(--ok); }
.site-card.bad { border-left-color: var(--bad); }
.site-card header { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ---- 管理员 ---- */
.adms { display: flex; flex-direction: column; gap: 10px; margin: 12px 0; }
.adm { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: center; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--panel-2); }
.adm-f { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: 10px; }
.adm-m { grid-column: 1; }
.adm .btn { grid-column: 2; grid-row: 1 / span 2; }

#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; z-index: 100; pointer-events: none; width: min(560px, calc(100vw - 32px)); }
.toast { background: #1a2738; border: 1px solid var(--line-2); border-left: 5px solid var(--accent); border-radius: 8px; padding: 10px 16px; font-size: 17px; opacity: 0; transform: translateY(6px); transition: opacity 0.2s, transform 0.2s; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5); max-width: 100%; overflow-wrap: anywhere; }
.toast.in { opacity: 1; transform: none; }
.toast-ok { border-left-color: var(--ok); }
.toast-warn { border-left-color: var(--warn); }
.toast-error { border-left-color: var(--bad); color: #ffd0d2; }

@media (max-width: 640px) {
  #pda-app { padding: 0 12px 40px; }
  #top { gap: 10px; padding: 6px 0; }
  .tabs { gap: 6px; }
  .tab { flex: 0 0 auto; padding: 6px 12px; font-size: 16px; }
  .kv { grid-template-columns: 6.2em 1fr; }
  .kvs.wide .kv { grid-template-columns: 7.5em 1fr; }
  .code-row { flex-direction: column; }
  .card.pad { padding: 14px; }
  .code-card { padding: 14px 8px; }
  .code-big { letter-spacing: 0.02em; }
  .adm-f { grid-template-columns: 1fr; }
  .adm { grid-template-columns: 1fr; }
  .adm .btn { grid-column: 1; grid-row: auto; justify-self: start; }
  dialog#detail { width: 100vw; max-width: 100vw; max-height: 100vh; height: 100vh; border-radius: 0; margin: 0; }
}

/* ---- confirm dialog, device identity, upgrade controls, technical folds ---- */
dialog#ask { width: min(620px, calc(100vw - 24px)); max-height: calc(100vh - 32px); background: var(--panel); color: var(--text); border: 1px solid var(--line-2); border-radius: 14px; padding: 0; }
dialog#ask::backdrop { background: rgba(5, 8, 12, 0.75); }
.ask-body { padding: 18px 20px; }
.ask-body h2 { margin: 0 0 10px; }
.ask-body p { margin: 8px 0; }
.ask-list { margin: 6px 0; padding-left: 20px; font-size: 15px; }
.ask-actions { justify-content: flex-end; margin-top: 16px; }
.dev-id { display: inline-flex; flex-wrap: wrap; align-items: baseline; gap: 2px 6px; }
.dev-id .dev-sub { flex-basis: 100%; }
.up-ctl { display: flex; flex-direction: column; gap: 4px; margin-top: 4px; }
.up-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.up-row select { flex: 1 1 220px; min-width: 0; max-width: 100%; }
.up-state { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin: 12px 0; }
.up-state.paused { border-color: #6b5420; }
.up-global { margin: 12px 0; }
details.tech { margin: 14px 0; border: 1px dashed var(--line-2); border-radius: 8px; padding: 8px 12px; }
details.tech > summary { cursor: pointer; color: var(--muted); min-height: var(--touch); display: flex; align-items: center; }
