:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #fafbfc;
  --text: #16181d;
  --text-2: #6b7280;
  --line: #e6e8ec;
  --brand: #07c160;
  --brand-deep: #06a851;
  --danger: #e5484d;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
  --radius: 14px;
  --topbar-h: calc(58px + env(safe-area-inset-top));
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101215;
    --panel: #17191d;
    --panel-2: #1d2025;
    --text: #eceef2;
    --text-2: #9aa1ad;
    --line: #272b31;
    --brand: #2fd07a;
    --brand-deep: #24b166;
    --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 10px 30px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  overscroll-behavior-y: contain;
}

body { padding-bottom: env(safe-area-inset-bottom); }

button { font-family: inherit; font-size: 14px; cursor: pointer; border: none; background: none; color: inherit; }
input, select { font-family: inherit; font-size: 14px; }

/* ------------------------------------------------------------ 顶栏 */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo {
  width: 34px; height: 34px; border-radius: 10px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--brand), var(--brand-deep));
  font-size: 17px;
}
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-size: 15px; letter-spacing: .2px; }
.brand-text .sub { font-size: 11.5px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dot.online { background: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 22%, transparent); }
.dot.offline { background: #c3c7ce; }
.dot.warn { background: #f5a524; }

.tools { display: flex; gap: 6px; flex: none; }
.tool {
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center;
  font-size: 15px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  filter: grayscale(1) opacity(.55);
  transition: transform .12s ease, filter .12s ease;
}
.tool.on { filter: none; border-color: color-mix(in srgb, var(--brand) 40%, var(--line)); background: color-mix(in srgb, var(--brand) 10%, var(--panel)); }
.tool:active { transform: scale(.92); }

/* ------------------------------------------------------------ 统计 */
.statline {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--line);
  border-bottom: 1px solid var(--line);
}
.stat {
  background: var(--panel);
  padding: 9px 6px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.stat b { font-size: 17px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11px; color: var(--text-2); }

/* ------------------------------------------------------------ 设备条 */
.devices {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 14px;
  scrollbar-width: none;
}
.devices::-webkit-scrollbar { display: none; }

.devchip {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px 7px 9px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 13px;
  white-space: nowrap;
  box-shadow: var(--shadow);
  transition: border-color .15s ease, transform .12s ease;
}
.devchip:active { transform: scale(.97); }
.devchip.active { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 10%, var(--panel)); }
.devchip .avatar {
  width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 700; color: #fff;
}
.devchip .meta { display: flex; flex-direction: column; line-height: 1.15; }
.devchip .meta i { font-style: normal; font-size: 10.5px; color: var(--text-2); }
.devchip .cnt {
  font-size: 10px; padding: 1px 5px; border-radius: 999px;
  background: var(--panel-2); color: var(--text-2);
}

/* ------------------------------------------------------------ 过滤 */
.filterbar {
  position: sticky;
  top: var(--topbar-h);
  z-index: 10;
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px 14px 10px;
  background: var(--bg);
}
.filterbar input[type="search"] {
  flex: 1; min-width: 0;
  height: 36px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  outline: none;
}
.filterbar input[type="search"]:focus { border-color: var(--brand); }
.filterbar select {
  height: 36px;
  max-width: 42vw;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  padding: 0 8px;
  outline: none;
}
.ghost {
  height: 36px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text-2);
  white-space: nowrap;
}
.ghost:active { background: var(--panel-2); }

/* ------------------------------------------------------------ 消息流 */
.feed {
  padding: 0 14px 90px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.empty {
  text-align: center;
  color: var(--text-2);
  padding: 54px 20px;
}
.empty-ico { font-size: 44px; opacity: .8; }
.empty p { margin: 8px 0 0; }
.empty .hint { font-size: 12.5px; max-width: 300px; margin: 10px auto 0; line-height: 1.6; opacity: .85; }

.msg {
  position: relative;
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: 10px;
  padding: 11px 12px 11px 10px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  animation: pop .28s cubic-bezier(.2, .9, .3, 1.2);
  overflow: hidden;
}
.msg::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--accent, var(--brand));
}
@keyframes pop {
  from { opacity: 0; transform: translateY(-8px) scale(.98); }
  to { opacity: 1; transform: none; }
}
.msg.flash { animation: pop .28s cubic-bezier(.2, .9, .3, 1.2), flash 1.2s ease-out; }
@keyframes flash {
  0% { background: color-mix(in srgb, var(--brand) 22%, var(--panel)); }
  100% { background: var(--panel); }
}

.msg .ava {
  width: 38px; height: 38px; border-radius: 11px;
  display: grid; place-items: center;
  font-size: 15px; font-weight: 700; color: #fff;
  background: var(--accent, var(--brand));
}
.msg .body { min-width: 0; }
.msg .row1 {
  display: flex; align-items: baseline; gap: 6px;
  min-width: 0;
}
.msg .chat {
  font-weight: 600; font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.msg .sender {
  font-size: 11.5px; color: var(--text-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  flex: none; max-width: 40%;
}
.msg .time {
  margin-left: auto; flex: none;
  font-size: 11px; color: var(--text-2);
  font-variant-numeric: tabular-nums;
}
.msg .text {
  margin-top: 3px;
  font-size: 14px;
  color: var(--text);
  word-break: break-word;
  white-space: pre-wrap;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.msg .from {
  margin-top: 5px;
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10.5px; color: var(--text-2);
  background: var(--panel-2);
  border: 1px solid var(--line);
  padding: 1px 7px;
  border-radius: 999px;
}

/* ------------------------------------------------------------ 未读条 */
.unreadbar {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(18px + env(safe-area-inset-bottom));
  display: flex;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity .2s ease, transform .2s ease;
}
.unreadbar.show { opacity: 1; transform: none; }
.unreadbar button {
  pointer-events: auto;
  padding: 9px 18px;
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  box-shadow: 0 8px 22px color-mix(in srgb, var(--brand) 40%, transparent);
}

/* ------------------------------------------------------------ 抽屉 */
.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(360px, 86vw);
  background: var(--panel);
  border-left: 1px solid var(--line);
  transform: translateX(102%);
  transition: transform .26s cubic-bezier(.3, .8, .3, 1);
  z-index: 41;
  display: flex;
  flex-direction: column;
}
.drawer.open { transform: none; }
.drawer-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--line);
  padding-top: calc(16px + env(safe-area-inset-top));
}
.drawer-body { padding: 14px 16px 30px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--text-2); }
.field input {
  height: 38px; padding: 0 12px;
  border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); outline: none;
}
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); padding: 8px 10px; border-radius: 10px; word-break: break-all; }

.addrlist { display: flex; flex-direction: column; gap: 6px; margin-top: 2px; }
.addr {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px 8px 7px 10px;
}
.addr code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: var(--text);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.addr .tag {
  flex: none;
  font-size: 10px;
  color: var(--text-2);
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 1px 6px;
  border-radius: 999px;
  white-space: nowrap;
}
.addr .copy {
  flex: none;
  font-size: 11.5px;
  padding: 4px 9px;
  border-radius: 7px;
  background: var(--brand);
  color: #fff;
  font-weight: 600;
}
.addr .copy:active { background: var(--brand-deep); }
.muted { font-size: 12px; color: var(--text-2); }
.switch { display: flex; align-items: center; gap: 10px; font-size: 13.5px; padding: 4px 0; }
.switch input { width: 18px; height: 18px; accent-color: var(--brand); }
.tip { font-size: 11.5px; color: var(--text-2); margin: 0; line-height: 1.6; }
.primary {
  height: 40px; border-radius: 10px;
  background: var(--brand); color: #fff; font-weight: 600;
}
.primary:active { background: var(--brand-deep); }
.mask {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, .35);
  opacity: 0; pointer-events: none;
  transition: opacity .22s ease;
  z-index: 40;
}
.mask.show { opacity: 1; pointer-events: auto; }

/* ------------------------------------------------------------ toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(78px + env(safe-area-inset-bottom));
  transform: translate(-50%, 14px);
  background: rgba(20, 22, 26, .92);
  color: #fff;
  font-size: 13px;
  padding: 9px 16px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 50;
  max-width: 84vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 780px) {
  .feed { max-width: 760px; margin: 0 auto; }
  .filterbar, .devices, .statline { max-width: 760px; margin: 0 auto; }
  .topbar > * { max-width: 760px; }
}

/* -------------------------------------------------- 后台推送卡片 / iOS 提示 */
.pushcard {
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: var(--radius);
  padding: 12px 12px 10px;
  margin: 12px 0;
}
.pushcard-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 14px;
}
.pill {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--line);
  color: var(--text-2);
  white-space: nowrap;
}
.pill.on { background: rgba(7, 193, 96, .16); color: var(--brand-deep); }
.pill.warn { background: rgba(245, 158, 11, .18); color: #b45309; }
.pill.off { background: rgba(229, 72, 77, .14); color: var(--danger); }
.pushcard .primary, .pushcard .ghost { width: 100%; margin-top: 6px; }
.pushcard .mono { margin-top: 8px; }

.iosbar {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin: 10px 12px 0;
  padding: 11px 12px;
  border-radius: var(--radius);
  border: 1px solid rgba(245, 158, 11, .45);
  background: rgba(245, 158, 11, .12);
  color: var(--text);
  font-size: 12.5px;
  line-height: 1.5;
}
.iosbar strong { display: block; font-size: 13px; margin-bottom: 2px; }
.iosbar p { margin: 0; color: var(--text-2); }
.iosbar button { flex: 0 0 auto; align-self: center; }

/* ------------------------------------------------ 电量徽标 / 低电提醒 */
.batterybar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 8px 12px 0;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid rgba(229, 72, 77, .42);
  background: rgba(229, 72, 77, .09);
  font-size: 12.5px;
  color: var(--text);
}
.batterybar b { color: var(--danger); }
.batterybar .batalert {
  border: 1px solid rgba(229, 72, 77, .35);
  background: var(--panel-2);
  color: var(--danger);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}
.bat {
  font-size: 11px;
  color: var(--text-2);
  margin-left: 6px;
  white-space: nowrap;
}
.bat.low { color: var(--danger); font-weight: 700; }
.bat.stale { opacity: .55; }
.devchip.lowdev { border-color: rgba(229, 72, 77, .5); }
.devchip.outdated { border-color: rgba(47, 111, 237, .55); }
.devchip .upd { font-size: 10.5px; color: #2f6fed; font-weight: 700; white-space: nowrap; }
#updateState > div { padding: 2px 0; }
.msg.alert {
  border-color: rgba(245, 158, 11, .5);
  background: rgba(245, 158, 11, .08);
}
.msg.alert .text { color: #92400e; font-weight: 600; }

/* ------------------------------------------------ 媒体消息（含语音）标记 */
.mediatag {
  margin-left: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  color: #075e44;
  background: rgba(7, 193, 96, .12);
  border: 1px solid rgba(7, 193, 96, .28);
  white-space: nowrap;
}
.mediahint {
  margin-top: 6px;
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.6;
  color: #92400e;
  background: rgba(245, 158, 11, .10);
  border: 1px solid rgba(245, 158, 11, .22);
}

/* ------------------------------------------------ 远程屏幕协助 */
.rcbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 8px 12px 0;
  padding: 9px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 12.5px;
}
.rcbar > b { font-size: 12px; font-weight: 700; color: var(--text-2); margin-right: 2px; }
.rcbtn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text-2);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.rcbtn:hover { color: var(--text); }
.rcbtn.ready { color: var(--brand-deep); border-color: rgba(7, 193, 96, .45); background: rgba(7, 193, 96, .10); }
.rcbtn.live { color: #fff; background: var(--brand); border-color: var(--brand); }

.rcwrap {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: rgba(9, 12, 16, .62);
  backdrop-filter: blur(2px);
}
.rcwrap[hidden] { display: none; }
.rccard {
  width: 100%;
  max-width: 560px;
  max-height: calc(100vh - 24px);
  overflow: auto;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, .3);
}
.rchead { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.rchead-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.rchead-left strong {
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rcnotice {
  margin-bottom: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 12px;
  line-height: 1.55;
  color: #92400e;
  background: rgba(245, 158, 11, .12);
  border: 1px solid rgba(245, 158, 11, .3);
}
.rcnotice[hidden] { display: none; }

.rcstage {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  border-radius: 12px;
  background: #0b0d10;
  min-height: 200px;
}
.rcframe {
  position: relative;
  aspect-ratio: 9 / 19.5;
  max-height: 64vh;
  max-width: 100%;
  border-radius: 8px;
  overflow: hidden;
  background: #000;
}
.rcframe img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
  touch-action: none;
  user-select: none;
  -webkit-user-drag: none;
}
.rcplaceholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  text-align: center;
  font-size: 12.5px;
  color: #8b93a1;
}
.rcplaceholder[hidden] { display: none; }

.rctoolbar { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.rctoolbar .ghost { flex: 1 1 auto; }
.rctoolbar select {
  flex: 1 1 130px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 10px;
  padding: 6px 8px;
}
.rccard .tip { margin: 8px 0 0; }
