/* ==========================================================================
   乡音广播 · 公共样式
   --------------------------------------------------------------------------
   设计约束（都是被"村委会那台旧电脑 + 60 岁的村干部"逼出来的）：
     1. 字要大。默认 18px，正文最小 16px，关键数字 40px 起。
     2. 按钮要大。最小高度 56px（手指点得中），主按钮 72px。
     3. 颜色要高对比。村里电脑经常放在窗边，屏幕反光，浅灰字等于看不见。
     4. 只用系统自带字体。不能引 CDN 字体（村委会可能没外网），
        中文字体走 PingFang / 微软雅黑 / 思源黑体 的系统回退链。
     5. 不用 CSS 变量以外的新特性，老 Chrome 也要能看。

   ⚠ 本文件必须存为「UTF-8 无 BOM」。
   ========================================================================== */

:root {
  --bg: #eef2f7;
  --card: #ffffff;
  --line: #d3dbe6;
  --text: #16202e;
  --muted: #5b6b80;
  --primary: #1a6fe0;
  --primary-dark: #1358b8;
  --ok: #16a34a;
  --warn: #e08b00;
  --danger: #d92d20;
  --shadow: 0 2px 10px rgba(20, 35, 60, .10);
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", "微软雅黑", "Source Han Sans SC",
               "Noto Sans CJK SC", "Hiragino Sans GB", "Heiti SC", sans-serif;
  font-size: 18px;
  line-height: 1.6;
  /* 手机上禁止双击缩放导致的误触延迟；但不禁用页面缩放（无障碍） */
  -webkit-text-size-adjust: 100%;
}

a { color: var(--primary); }

.wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding: 16px 16px 48px;
}
.wrap.narrow { max-width: 720px; }

/* ---- 顶栏 ---- */
.top {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
  position: sticky;
  top: 0;
  z-index: 20;
}
.top .wrap { padding-bottom: 10px; padding-top: 10px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
/* 顶栏里的每一项都要允许收缩：
   flex 子项默认 min-width:auto，遇到"服务正常 · 版本 1.0.0 · 已运行 0:12 · 在线设备 0"
   这种长状态串就完全不肯变窄，直接把整页撑出横向滚动条（390px 手机上实测到过）。 */
.top .wrap > * { min-width: 0; }
.brand { font-size: 22px; font-weight: 700; letter-spacing: 1px; }
.brand small { font-size: 15px; font-weight: 400; color: var(--muted); margin-left: 8px; letter-spacing: 0; }
.spacer { flex: 1 1 auto; }

@media (max-width: 700px) {
  /* 手机上顶栏状态文字允许换行，别硬撑一行 */
  .top .nowrap { white-space: normal; }
  .brand { font-size: 20px; }
  .brand small { display: block; margin-left: 0; }
}

h1 { font-size: 30px; margin: 18px 0 6px; }
h2 { font-size: 24px; margin: 22px 0 10px; }
h3 { font-size: 20px; margin: 16px 0 8px; }
p.lead { font-size: 19px; color: var(--muted); margin: 4px 0 18px; }

/* ---- 卡片 ---- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin: 14px 0;
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }

.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

@media (max-width: 780px) {
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: minmax(0, 1fr); }
}

/* ---- 按钮 ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 56px;
  padding: 0 22px;
  font-size: 20px;
  font-family: inherit;
  font-weight: 600;
  color: #fff;
  background: var(--primary);
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  text-decoration: none;
  /* 手机上点按钮不要出现灰色高亮块 */
  -webkit-tap-highlight-color: transparent;
  transition: filter .15s, transform .05s;
  user-select: none;
  -webkit-user-select: none;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn.disabled { background: #9aa7b8; cursor: not-allowed; filter: none; }
.btn.ghost { background: #fff; color: var(--primary); border: 2px solid var(--primary); }
.btn.gray { background: #64748b; }
.btn.ok { background: var(--ok); }
.btn.warn { background: var(--warn); }
.btn.danger { background: var(--danger); }
.btn.sm { min-height: 44px; font-size: 17px; padding: 0 14px; border-radius: 10px; }
.btn.block { width: 100%; }

/* 大入口按钮（落地页 / 接收端启动） */
.btn-huge {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  min-height: 140px;
  padding: 18px;
  font-size: 30px;
  font-weight: 700;
  border-radius: 18px;
  color: #fff;
  background: var(--primary);
  border: 0;
  cursor: pointer;
  text-decoration: none;
  box-shadow: var(--shadow);
  -webkit-tap-highlight-color: transparent;
}
.btn-huge small { font-size: 16px; font-weight: 400; opacity: .92; }
.btn-huge .ico { font-size: 40px; line-height: 1; }
.btn-huge.green { background: var(--ok); }
.btn-huge.slate { background: #3f4c60; }
.btn-huge:active { transform: translateY(1px); }

/* 呼吸动画：接收端"等你点一下"时用，让人一眼看到 */
@keyframes xy-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(26, 111, 224, .55); }
  70%  { box-shadow: 0 0 0 22px rgba(26, 111, 224, 0); }
  100% { box-shadow: 0 0 0 0 rgba(26, 111, 224, 0); }
}
.pulse { animation: xy-pulse 1.8s infinite; }

/* ---- 表单 ---- */
label.field { display: block; margin: 10px 0; }
label.field > span { display: block; font-size: 16px; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=number], textarea, select {
  width: 100%;
  min-height: 52px;
  padding: 10px 12px;
  font-size: 19px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 10px;
  outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--primary); }
textarea { min-height: 110px; resize: vertical; line-height: 1.5; }
input[readonly] { background: #f1f5f9; color: var(--muted); }

input[type=range] {
  width: 100%;
  /* 44px 是手指点得中的下限（苹果/谷歌的人机指南都这么写）。
     滑块做矮了，村干部在手机上要么调不动，要么一碰就到底。 */
  height: 44px;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
}
input[type=range]::-webkit-slider-runnable-track { height: 12px; background: #cfd8e5; border-radius: 8px; }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 34px; height: 34px; margin-top: -11px;
  border-radius: 50%; background: var(--primary); border: 3px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.3); cursor: pointer;
}
input[type=range]::-moz-range-track { height: 12px; background: #cfd8e5; border-radius: 8px; }
input[type=range]::-moz-range-thumb { width: 30px; height: 30px; border-radius: 50%; background: var(--primary); border: 3px solid #fff; }

/* ---- 状态点 / 标签 ---- */
.dot {
  display: inline-block; width: 14px; height: 14px; border-radius: 50%;
  background: #9aa7b8; vertical-align: -1px; margin-right: 8px;
}
.dot.ok { background: var(--ok); box-shadow: 0 0 0 4px rgba(22,163,74,.18); }
.dot.bad { background: var(--danger); box-shadow: 0 0 0 4px rgba(217,45,32,.18); }
.dot.wait { background: var(--warn); box-shadow: 0 0 0 4px rgba(224,139,0,.18); }

.tag {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: 15px; background: #e6edf7; color: #2b4a75; margin: 2px 4px 2px 0;
}
.tag.ok { background: #dff5e6; color: #12693a; }
.tag.bad { background: #fde3e0; color: #9a1c12; }
.tag.warn { background: #fdf0d8; color: #8a5a00; }

/* ---- 数据格子 ---- */
.stat {
  background: #f7f9fc;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
}
.stat .k { font-size: 16px; color: var(--muted); }
.stat .v { font-size: 32px; font-weight: 700; line-height: 1.25; font-variant-numeric: tabular-nums; }
.stat .v.sm { font-size: 22px; }
.stat .v.green { color: var(--ok); }
.stat .v.red { color: var(--danger); }

/* ---- 进度/电平条 ---- */
.bar { height: 18px; background: #dde5ef; border-radius: 9px; overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; background: var(--ok); transition: width .12s linear; }
.bar.warn > i { background: var(--warn); }
.bar.thin { height: 12px; }

/* ---- 表格 ---- */
.table { width: 100%; border-collapse: collapse; font-size: 17px; }
.table th, .table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); }
.table th { color: var(--muted); font-weight: 600; font-size: 16px; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover { background: #f4f8ff; }
.table tr.sel { background: #e8f1ff; }
.scroll-x { overflow-x: auto; }

/* ---- 日志 ---- */
.log {
  font-family: Consolas, "Courier New", monospace;
  font-size: 15px;
  line-height: 1.7;
  background: #0f172a;
  color: #cbd5e1;
  border-radius: 10px;
  padding: 10px 12px;
  max-height: 260px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-all;
}
.log .t { color: #64748b; }

/* ---- 提示条 ---- */
.notice {
  border-radius: 12px;
  padding: 12px 14px;
  margin: 10px 0;
  font-size: 17px;
  border: 1px solid;
  background: #eaf3ff; border-color: #b9d5ff; color: #113a72;
}
.notice.warn { background: #fff7e6; border-color: #ffd591; color: #7a4c00; }
.notice.bad { background: #fdeceb; border-color: #ffbdb6; color: #8d1a10; }
.notice.ok { background: #e9f9ef; border-color: #a9e3c0; color: #10633a; }
.notice b { font-size: 18px; }

/* ---- 浮动提示 ---- */
#xy-toast {
  position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%);
  z-index: 999; display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none; width: min(92vw, 620px);
}
#xy-toast .toast {
  background: rgba(16, 26, 40, .94); color: #fff;
  padding: 12px 20px; border-radius: 12px; font-size: 18px;
  box-shadow: 0 6px 24px rgba(0,0,0,.28); max-width: 100%;
}
#xy-toast .toast.bad { background: rgba(160, 24, 16, .96); }
#xy-toast .toast.ok { background: rgba(15, 110, 60, .96); }

/* ---- 弹窗 ---- */
.mask {
  position: fixed; inset: 0; background: rgba(10, 18, 30, .55);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px;
}
.mask[hidden] { display: none; }
.mask .card { max-width: 520px; width: 100%; margin: 0; max-height: 90vh; overflow: auto; }

/* ---- PTT（按住说话）---- */
.ptt {
  width: 100%;
  min-height: 190px;
  border-radius: 24px;
  border: 0;
  font-size: 34px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(180deg, #2b82f0, #1a5fc4);
  box-shadow: 0 8px 22px rgba(26, 95, 196, .35);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;           /* 关键：手指按住时不要触发页面滚动/缩放 */
  user-select: none;
  -webkit-user-select: none;
}
.ptt small { display: block; font-size: 17px; font-weight: 400; opacity: .9; margin-top: 8px; }
.ptt.on { background: linear-gradient(180deg, #ff5a4d, #cc2418); box-shadow: 0 8px 22px rgba(204, 36, 24, .4); }
.ptt.disabled { background: #9aa7b8; box-shadow: none; }

/* ---- 小圆按钮选区 ---- */
.chips { display: flex; gap: 10px; flex-wrap: wrap; }
.chip {
  min-height: 48px; padding: 0 18px; border-radius: 999px;
  border: 2px solid var(--line); background: #fff; color: var(--text);
  font-size: 18px; font-family: inherit; cursor: pointer;
}
.chip.on { border-color: var(--primary); background: #e8f1ff; color: #113a72; font-weight: 700; }
.chip.on.danger { border-color: var(--danger); background: #fdeceb; color: #8d1a10; }

/* ---- 预设通知按钮 ---- */
.preset {
  display: block; width: 100%; text-align: left;
  padding: 12px 14px; margin: 8px 0;
  font-size: 17px; font-family: inherit; line-height: 1.5;
  background: #f7f9fc; color: var(--text);
  border: 1px solid var(--line); border-radius: 12px; cursor: pointer;
}
.preset:hover { background: #eef4ff; border-color: #b9d5ff; }

/* ---- 大数字（广播码）---- */
.code-big {
  font-family: Consolas, Menlo, monospace;
  font-size: 56px; font-weight: 800; letter-spacing: 10px;
  text-align: center; color: var(--primary);
  padding: 10px 0 4px;
  word-break: break-all;
}
@media (max-width: 520px) { .code-big { font-size: 40px; letter-spacing: 6px; } }

.kv { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px dashed var(--line); font-size: 17px; }
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--muted); }
.kv .v { font-weight: 600; word-break: break-all; text-align: right; }

.muted { color: var(--muted); }
.center { text-align: center; }
.mono { font-family: Consolas, Menlo, monospace; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 14px; }
.mb { margin-bottom: 14px; }
.flex { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.hide { display: none !important; }

/* 接收端"挂机大屏"用的深色变体：晚上不刺眼，白天也看得清 */
body.dark { background: #0b1220; color: #e8eef7; }
body.dark .card { background: #131c2e; border-color: #253149; }
body.dark .stat { background: #0f1829; border-color: #253149; }
body.dark .stat .k, body.dark .muted, body.dark p.lead { color: #93a4bd; }
body.dark .top { background: #131c2e; border-color: #253149; }
body.dark input, body.dark textarea, body.dark select { background: #0f1829; color: #e8eef7; border-color: #2c3a55; }
body.dark .bar { background: #253149; }
body.dark .kv { border-color: #253149; }
body.dark .notice { background: #16233a; border-color: #2c4270; color: #bcd4f5; }
body.dark .tag { background: #1d2a42; color: #a9c3e8; }

/* ============================================================================
   配置防误触锁（与安卓端对齐）
   ============================================================================
   为什么 H5 也需要这个：大喇叭那台电脑就摆在村委会，鼠标随手一划就可能
   改掉广播码；改完没人知道，全村广播就哑了，而界面上看起来只是"没连上"。

   与安卓的差异：安卓是触屏，长按天然防误触；电脑用鼠标，
   "按住不放 3 秒"同样成立（按住时显示环形进度），
   所以两端用同一套交互，学习成本一致。
   ============================================================================ */
.cfg-lock {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; margin: 0 0 12px;
  background: #eceff3; border: 2px solid var(--line);
  border-radius: 12px; cursor: pointer;
  font-size: 18px; font-weight: 700; color: #475569;
  user-select: none; -webkit-user-select: none;
  touch-action: manipulation;   /* 防止长按被浏览器当成文字选择/拖动 */
  position: relative; overflow: hidden;
  transition: background .15s, color .15s, border-color .15s;
}
.cfg-lock:focus { outline: 3px solid var(--primary); outline-offset: 2px; }
/* 按住时的环形进度：只用一个 CSS 变量驱动，避免 JS 频繁改样式 */
.cfg-lock::after {
  content: ''; position: absolute; left: 0; bottom: 0; height: 5px;
  width: var(--hold, 0%); background: var(--warn);
  transition: width .1s linear;
}
.cfg-lock.holding { background: #fff7e6; border-color: var(--warn); color: #8a5a00; }
.cfg-lock.unlocked {
  background: #fff4e5; border-color: #f0a30a; color: #8a5a00;
}
.cfg-lock.unlocked::after { width: 0; }

/* 锁定时把配置区整体变淡并禁用点击，和安卓的 enabled=false + 灰度一致 */
.cfg-locked { opacity: .5; pointer-events: none; filter: grayscale(.35); }
/* 但"只读摘要"在锁定时要清楚显示（否则锁住就看不到连的哪儿了） */
.cfg-summary {
  font-size: 17px; line-height: 1.65; color: var(--text);
  background: #f5f7fa; border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; margin: 0 0 12px;
  word-break: break-all;
}
.cfg-summary b { color: #0f172a; }
body.dark .cfg-lock { background: #1a2438; border-color: #2c3a55; color: #a9b8ce; }
body.dark .cfg-lock.holding, body.dark .cfg-lock.unlocked { background: #3a2f14; border-color: #b9820a; color: #f5c76a; }
body.dark .cfg-summary { background: #0f1829; border-color: #253149; color: #cfdcee; }
body.dark .cfg-summary b { color: #fff; }

/* ============================================================================
   超大状态字（与安卓的 30sp 粗体对齐）
   隔着半米也要能看清"现在通没通"
   ============================================================================ */
.status-huge {
  font-size: clamp(30px, 6vw, 44px); font-weight: 800; line-height: 1.3;
  text-align: center; letter-spacing: 1px;
  margin: 4px 0 6px;
}
.status-sub {
  font-size: clamp(18px, 3.2vw, 22px); font-weight: 700;
  text-align: center; margin: 0 0 6px;
}
.status-huge.ok, .status-sub.ok { color: var(--ok); }
.status-huge.bad, .status-sub.bad { color: var(--danger); }
.status-huge.wait, .status-sub.wait { color: var(--warn); }

/* 角色选择：加大加粗（对齐安卓 24sp 粗体 + 56dp 行高） */
.role-row { display: flex; gap: 12px; flex-wrap: wrap; margin: 0 0 12px; }
.role-btn {
  flex: 1 1 200px; min-height: 62px;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  font-size: 24px; font-weight: 800;
  border: 3px solid var(--line); border-radius: 14px;
  background: #fff; color: var(--muted); cursor: pointer;
  user-select: none; -webkit-user-select: none;
}
.role-btn[aria-pressed="true"] {
  border-color: var(--primary); background: #eaf2ff; color: var(--primary-dark);
}
.role-btn:focus { outline: 3px solid var(--primary); outline-offset: 2px; }

/* 开关式说话按钮（对着安卓的 toggle 说话按钮） */
.talk-toggle {
  width: 100%; min-height: 150px; margin: 0 0 10px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; border: 0; border-radius: 16px; cursor: pointer;
  font-size: 30px; font-weight: 800; color: #fff;
  background: linear-gradient(180deg, #2b7ce8, #1560c4);
  box-shadow: 0 6px 18px rgba(21, 96, 196, .28);
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
.talk-toggle small { font-size: 17px; font-weight: 500; opacity: .95; }
.talk-toggle.on {
  background: linear-gradient(180deg, #ff5a4d, #cc2418);
  box-shadow: 0 8px 22px rgba(204, 36, 24, .4);
}
.talk-toggle.preparing {
  background: linear-gradient(180deg, #f5b301, #d99400);
  box-shadow: 0 6px 18px rgba(217, 148, 0, .3);
}
.talk-toggle:disabled { background: #9aa7b8; box-shadow: none; cursor: not-allowed; }

/* 快捷通知：高频按钮做大（对齐安卓）
   —— 村里真正天天用的就是那几句，按钮必须好点 */
.quick-btn {
  width: 100%; min-height: 64px; margin: 0 0 10px;
  font-size: 19px; font-weight: 700; line-height: 1.35;
  border: 0; border-radius: 12px; cursor: pointer;
  background: #e8edf5; color: #16202e; padding: 10px 14px; text-align: center;
}
.quick-btn:hover { background: #dbe4f0; }
.quick-btn:active { transform: translateY(1px); }
.quick-btn:disabled { opacity: .55; cursor: not-allowed; }
body.dark .quick-btn { background: #1d2a42; color: #e8eef7; }
body.dark .quick-btn:hover { background: #24334f; }
body.dark .role-btn { background: #131c2e; border-color: #2c3a55; }
body.dark .role-btn[aria-pressed="true"] { background: #12325c; color: #9ec5ff; border-color: #3b7fd4; }

/* 说话计时条：让"还要多久自动停"看得见 */
.talk-timer {
  font-size: 17px; font-weight: 700; text-align: center;
  color: var(--muted); margin: 0 0 10px;
}
.talk-timer.warn { color: var(--danger); }
