:root {
  color-scheme: dark;
  --bg: #0b1219;
  --bg-soft: #0e1720;
  --panel: #131e29;
  --line: #24323f;
  --ink: #e9f0f6;
  --muted: #8ea2b3;
  --alarm: #e5484d;
  --fault: #f0a020;
  --feedback: #3b9eff;
  --recovery: #2fbf71;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", sans-serif;
  font-size: 16px;
}

body { overflow: hidden; }

.hidden { display: none !important; }

.app {
  height: 100%;
  max-width: 620px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 10px;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.brand-mark {
  flex: none;
  width: 44px;
  height: 44px;
  display: inline-grid;
  place-items: center;
  border-radius: 12px;
  background: linear-gradient(140deg, #ff5c61, #b3171c);
  color: #fff;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 1px;
  box-shadow: 0 6px 18px rgba(229, 72, 77, 0.35);
}

.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-size: 19px; letter-spacing: 0.5px; }
.brand-text span { color: var(--muted); font-size: 12px; margin-top: 2px; }

.top-actions { display: flex; gap: 8px; }

.icon-btn {
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--ink);
  font-size: 20px;
  line-height: 1;
}

.icon-btn:active { background: #1c2b39; }

.conn-line {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 16px 10px;
  color: var(--muted);
  font-size: 13px;
  min-width: 0;
}

.dot {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #5c7183;
  box-shadow: 0 0 0 4px rgba(92, 113, 131, 0.16);
}

.dot.is-online { background: var(--recovery); box-shadow: 0 0 0 4px rgba(47, 191, 113, 0.18); }
.dot.is-error { background: var(--alarm); box-shadow: 0 0 0 4px rgba(229, 72, 77, 0.18); }
.dot.is-wait { background: var(--fault); box-shadow: 0 0 0 4px rgba(240, 160, 32, 0.18); }

.conn-topic {
  margin-left: auto;
  max-width: 46%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  color: #6f8292;
}

.summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 0 14px;
}

.sum-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  color: var(--ink);
  text-align: left;
}

.sum-card span { font-size: 13px; color: var(--muted); }
.sum-card strong { font-size: 30px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.sum-card small { font-size: 11px; color: #6f8292; }

.sum-card.is-alarm strong { color: #ff8589; }
.sum-card.is-fault strong { color: #ffc15e; }
.sum-card.is-feedback strong { color: #7cc0ff; }
.sum-card.is-active { border-color: #3d566c; background: #182636; }

.summary-note {
  margin: 8px 18px 8px;
  color: var(--muted);
  font-size: 12px;
}

.list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 2px 14px 10px;
}

.empty {
  margin: 48px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.8;
}

.event {
  margin-bottom: 10px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-left: 5px solid #5c7183;
  border-radius: 14px;
  background: var(--panel);
}

.event.sev-alarm { border-left-color: var(--alarm); background: linear-gradient(105deg, rgba(229, 72, 77, 0.16), var(--panel) 58%); }
.event.sev-fault { border-left-color: var(--fault); background: linear-gradient(105deg, rgba(240, 160, 32, 0.1), var(--panel) 58%); }
.event.sev-feedback { border-left-color: var(--feedback); background: linear-gradient(105deg, rgba(59, 158, 255, 0.1), var(--panel) 58%); }
.event.sev-recovery { border-left-color: var(--recovery); background: linear-gradient(105deg, rgba(47, 191, 113, 0.1), var(--panel) 58%); }

.event-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

.tag {
  padding: 3px 11px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
  background: #22303c;
  color: var(--ink);
}

.sev-alarm .tag { background: rgba(229, 72, 77, 0.2); color: #ff9a9e; }
.sev-fault .tag { background: rgba(240, 160, 32, 0.18); color: #ffc15e; }
.sev-feedback .tag { background: rgba(59, 158, 255, 0.18); color: #8ac8ff; }
.sev-recovery .tag { background: rgba(47, 191, 113, 0.18); color: #6fe3a3; }

.event-time { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }

.event-addr {
  margin: 7px 0 5px;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.5px;
  font-variant-numeric: tabular-nums;
}

.event-addr b { color: #fff; }

.event-meta {
  display: flex;
  gap: 12px;
  color: #6f8292;
  font-size: 12px;
  overflow: hidden;
  white-space: nowrap;
}

.event-loc { margin-bottom: 4px; color: #b9c9d6; font-size: 14px; line-height: 1.45; }

.more {
  margin: 4px auto 10px;
  padding: 10px 26px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font-size: 14px;
}

.tabbar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-top: 1px solid var(--line);
  background: var(--bg-soft);
  padding-bottom: var(--safe-bottom);
}

.tab {
  padding: 13px 4px 15px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  position: relative;
}

.tab.is-active { color: #fff; }
.tab.is-active::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 6px;
  width: 22px;
  height: 3px;
  border-radius: 3px;
  transform: translateX(-50%);
  background: var(--alarm);
}

/* 全屏火警警报 */
.alarm-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px 22px calc(24px + var(--safe-bottom));
  text-align: center;
  color: #fff;
  background: radial-gradient(circle at 50% 32%, #8d1218 0%, #3a0509 58%, #1a0204 100%);
}

.alarm-glow {
  position: absolute;
  inset: -20% -20% auto;
  height: 70%;
  background: radial-gradient(circle, rgba(255, 70, 76, 0.5), transparent 62%);
  animation: alarmGlow 1.4s ease-in-out infinite;
  pointer-events: none;
}

.alarm-kicker {
  margin: 0;
  letter-spacing: 6px;
  font-size: 13px;
  color: #ffb3b5;
  z-index: 1;
}

.alarm-overlay h1 {
  margin: 4px 0 2px;
  font-size: 66px;
  letter-spacing: 14px;
  text-indent: 14px;
  text-shadow: 0 0 28px rgba(255, 90, 95, 0.75);
  animation: alarmPulse 1.15s ease-in-out infinite;
  z-index: 1;
}

.alarm-addr { font-size: 28px; font-weight: 700; z-index: 1; }
.alarm-addr b { font-size: 34px; }
.alarm-loc {
  max-width: 92%;
  font-size: 19px;
  font-weight: 600;
  line-height: 1.45;
  color: #ffe3e4;
  z-index: 1;
}
.alarm-time { font-size: 20px; color: #ffd6d7; font-variant-numeric: tabular-nums; z-index: 1; }
.alarm-topic { max-width: 90%; font-size: 12px; color: rgba(255, 255, 255, 0.6); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; z-index: 1; }
.alarm-extra { margin-top: 6px; padding: 6px 14px; border-radius: 999px; background: rgba(255, 255, 255, 0.16); font-size: 14px; z-index: 1; }

.alarm-hint { margin-top: 14px; font-size: 13px; color: rgba(255, 255, 255, 0.72); text-align: center; z-index: 1; }
.alarm-actions { display: flex; gap: 10px; width: 100%; max-width: 360px; margin-top: 18px; z-index: 1; }
.alarm-mute, .alarm-close {
  flex: 1;
  height: 56px;
  border: 1px solid rgba(255, 255, 255, 0.42);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 17px;
  font-weight: 700;
}
.alarm-mute:disabled { opacity: 0.55; }
.alarm-close { background: rgba(255, 255, 255, 0.2); }
.alarm-close:active { background: rgba(255, 255, 255, 0.28); }

@keyframes alarmPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.06); opacity: 0.86; }
}

@keyframes alarmGlow {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

/* 底部设置面板 */
.sheet-mask {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: flex-end;
  background: rgba(2, 6, 10, 0.62);
}

.sheet-card {
  width: 100%;
  max-width: 620px;
  margin: 0 auto;
  padding: 16px 18px calc(18px + var(--safe-bottom));
  border-radius: 20px 20px 0 0;
  background: var(--panel);
  border-top: 1px solid var(--line);
}

.sheet-card header { display: flex; align-items: center; justify-content: space-between; }
.sheet-card h3 { margin: 0; font-size: 18px; }

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 2px;
  border-bottom: 1px solid var(--line);
  font-size: 15px;
}

.setting-row.column { flex-direction: column; align-items: stretch; gap: 10px; }
.setting-row input[type="checkbox"] { width: 26px; height: 26px; accent-color: var(--alarm); }
.setting-row b { color: #7cc0ff; font-weight: 600; }

.setting-row input[type="range"] { width: 100%; accent-color: var(--alarm); height: 30px; }

.btn {
  display: block;
  width: 100%;
  height: 50px;
  margin-top: 16px;
  border: 0;
  border-radius: 13px;
  background: var(--alarm);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
}

.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--muted); }

.meta { margin-top: 18px; color: var(--muted); font-size: 12px; line-height: 1.9; word-break: break-all; }
.meta p { margin: 0; }
.meta span { color: #b9c9d6; }

/* 访问码 */
.login {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}

.login-card {
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.login-card .brand-mark { width: 64px; height: 64px; font-size: 24px; border-radius: 18px; }
.login-card h2 { margin: 18px 0 6px; font-size: 22px; }
.login-card p { margin: 0 0 18px; color: var(--muted); font-size: 14px; line-height: 1.6; }

.login-card input {
  width: 100%;
  height: 52px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--panel);
  color: var(--ink);
  font-size: 18px;
  text-align: center;
  letter-spacing: 2px;
  outline: none;
}

.login-card input:focus { border-color: #4a6a84; }
.login-error { min-height: 18px; margin: 12px 0 0 !important; color: #ff8b8f !important; font-size: 13px !important; }

.login-pass { position: relative; margin-top: 10px; }
.login-pass input { padding-right: 52px !important; }
#login-eye {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  background: transparent;
  color: var(--muted);
}
#login-eye svg { width: 20px; height: 20px; }

.login-card > input { margin-top: 10px; }

/* 后台管理（用 id 选择器，避免与用户角色徽标 .badge.admin 冲突） */
#admin {
  position: fixed;
  inset: 0;
  z-index: 85;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  padding-top: var(--safe-top);
}

.admin-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.admin-head h2 { margin: 0; font-size: 20px; }
.admin-head p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.admin-tabs { display: grid; grid-template-columns: repeat(3, 1fr); border-bottom: 1px solid var(--line); }

.atab {
  padding: 13px 4px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

.atab.is-active { color: #fff; border-bottom-color: var(--alarm); }

.admin-body { flex: 1; overflow-y: auto; padding: 16px 16px calc(20px + var(--safe-bottom)); }

.admin-toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.admin-toolbar h3 { margin: 0; font-size: 16px; }

.btn.small { width: auto; height: 40px; margin: 0; padding: 0 16px; font-size: 14px; border-radius: 10px; }

.user-form {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}

.user-form input, .user-form select, .password-form input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0f1922;
  color: var(--ink);
  font-size: 15px;
}

.form-row { display: flex; gap: 8px; }
.users-list { display: flex; flex-direction: column; gap: 10px; }

.user-row { padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.user-row header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.user-row strong { font-size: 16px; }
.user-row small { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }

.user-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.user-actions button {
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f1922;
  color: var(--ink);
  font-size: 13px;
}

.badge { padding: 2px 8px; border-radius: 999px; font-size: 11px; background: #22303c; color: var(--muted); }
.badge.admin { background: rgba(229, 72, 77, 0.18); color: #ff9a9e; }
.badge.viewer { background: rgba(59, 158, 255, 0.16); color: #8ac8ff; }
.badge.disabled { background: #2a2f35; color: #8b949c; }

.password-form { display: flex; flex-direction: column; gap: 12px; max-width: 420px; }
.field { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 13px; }

.mini-actions { display: flex; gap: 10px; margin-top: 14px; }
.mini-actions .btn { margin: 0; }

.pass-field { position: relative; display: block; width: 100%; }
.pass-field input { padding-right: 46px !important; }
.pass-eye {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 0;
  background: transparent;
  color: var(--muted);
}
.pass-eye svg { width: 19px; height: 19px; }

#mini { z-index: 95; }

#mini-input {
  width: 100%;
  height: 48px;
  margin-top: 12px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #0f1922;
  color: var(--ink);
  font-size: 16px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(78px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 120;
  max-width: 88vw;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(20, 32, 44, 0.95);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (min-width: 700px) {
  body { background: #060b10; }
  .app { box-shadow: 0 0 60px rgba(0, 0, 0, 0.6); }
}
