/* ==========================================================================
   控客设备控制台 · KONKE RELAY CONTROL
   视觉方向：工业配电柜 / 机房控制台 —— 深色金属面板、琥珀色通电指示灯、
   等宽字体遥测数字、真实的物理拨档开关质感。
   ========================================================================== */

:root {
  /* 面板与底色 */
  --bg-0: #07090b;
  --bg-1: #0b0f13;
  --panel-0: #141b21;
  --panel-1: #10161b;
  --panel-2: #0d1216;
  --line: #232d36;
  --line-soft: #1a2229;

  /* 文字 */
  --text: #e8eef3;
  --text-dim: #93a3b0;
  --text-faint: #61707c;

  /* 指示与强调 */
  --amber: #ffb302;
  --amber-deep: #b87400;
  --amber-glow: rgba(255, 179, 2, 0.32);
  --cyan: #45d6d0;
  --cyan-deep: #1d7f7c;
  --red: #ff4d4d;
  --red-glow: rgba(255, 77, 77, 0.3);
  --green: #4ede8a;

  /* 字体：全部使用系统自带字体，不依赖任何外网资源 */
  --font-display: "Bahnschrift", "DIN Alternate", "Franklin Gothic Medium", "HarmonyOS Sans SC", "Microsoft YaHei UI", "PingFang SC", sans-serif;
  --font-body: "HarmonyOS Sans SC", "PingFang SC", "Microsoft YaHei UI", "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC", sans-serif;
  --font-mono: "Cascadia Mono", "Consolas", "SFMono-Regular", "DejaVu Sans Mono", ui-monospace, monospace;

  --radius: 12px;
  --shadow-card: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 10px 24px -14px rgba(0, 0, 0, 0.9);
  --ring: 0 0 0 2px rgba(255, 179, 2, 0.35);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg-0);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; letter-spacing: -0.2px; }

/* 背景：蓝图网格 + 暗角 + 颗粒 */
.blueprint {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(1200px 700px at 12% -10%, rgba(69, 214, 208, 0.07), transparent 60%),
    radial-gradient(900px 600px at 100% 0%, rgba(255, 179, 2, 0.06), transparent 55%),
    linear-gradient(180deg, var(--bg-1), var(--bg-0) 60%);
}
.blueprint::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(120, 155, 175, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(120, 155, 175, 0.055) 1px, transparent 1px),
    linear-gradient(rgba(120, 155, 175, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(120, 155, 175, 0.03) 1px, transparent 1px);
  background-size: 96px 96px, 96px 96px, 16px 16px, 16px 16px;
  -webkit-mask-image: radial-gradient(120% 90% at 50% 0%, #000 35%, transparent 85%);
  mask-image: radial-gradient(120% 90% at 50% 0%, #000 35%, transparent 85%);
}
.blueprint::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.5;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='0.32'/%3E%3C/svg%3E");
  mix-blend-mode: overlay;
}

/* ------------------------------------------------------------------ 顶栏 */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 26px;
  background: linear-gradient(180deg, rgba(17, 23, 29, 0.96), rgba(11, 15, 19, 0.92));
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
.topbar::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--amber-glow), transparent);
}
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand-mark {
  width: 34px; height: 34px;
  flex: 0 0 auto;
  border-radius: 9px;
  background: linear-gradient(160deg, #2a3540, #151c22);
  border: 1px solid #33404b;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07), 0 6px 14px -8px #000;
  position: relative;
}
.brand-mark::before {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 12px; height: 12px;
  border-radius: 3px;
  background: var(--amber);
  box-shadow: 0 0 14px 2px var(--amber-glow), inset 0 0 4px rgba(0, 0, 0, 0.5);
  animation: lamp-breathe 3.6s ease-in-out infinite;
}
.brand-text { min-width: 0; }
.brand h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-sub {
  margin: 1px 0 0;
  font-size: 12px;
  color: var(--text-dim);
  letter-spacing: 0.04em;
}
.brand-sub .sep { color: var(--text-faint); margin: 0 6px; }
.topbar-right { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.clock {
  font-size: 13px;
  color: var(--text-dim);
  padding: 5px 10px;
  border: 1px solid var(--line-soft);
  border-radius: 7px;
  background: var(--panel-2);
}

/* ------------------------------------------------------------------ 按钮 */
.btn {
  font-family: var(--font-display);
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 10px 16px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #1d262e, #151c22);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.14s cubic-bezier(0.2, 1.3, 0.4, 1), box-shadow 0.18s, border-color 0.18s, background 0.18s, color 0.18s;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 6px 14px -12px #000;
  white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); border-color: #35424e; }
.btn:active { transform: translateY(1px) scale(0.995); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn-sm { padding: 7px 12px; font-size: 12px; }
.btn-block { width: 100%; padding: 13px 18px; font-size: 14px; }

.btn-on {
  border-color: rgba(255, 179, 2, 0.5);
  background: linear-gradient(180deg, rgba(255, 179, 2, 0.2), rgba(255, 179, 2, 0.06));
  color: #ffd479;
}
.btn-on:hover { border-color: var(--amber); box-shadow: 0 0 22px -6px var(--amber-glow), inset 0 1px 0 rgba(255, 255, 255, 0.08); }
.btn-off {
  border-color: #37434f;
  background: linear-gradient(180deg, #1b232a, #121820);
  color: #cfdae3;
}
.btn-off:hover { border-color: #4a5763; }
.btn-primary {
  border-color: rgba(69, 214, 208, 0.45);
  background: linear-gradient(180deg, rgba(69, 214, 208, 0.22), rgba(69, 214, 208, 0.07));
  color: #a9f4f1;
}
.btn-primary:hover { border-color: var(--cyan); box-shadow: 0 0 24px -8px rgba(69, 214, 208, 0.5); }
.btn-ghost { background: linear-gradient(180deg, #161d24, #11171d); color: var(--text-dim); }
.btn-ghost:hover { color: var(--text); }
.btn-danger { border-color: rgba(255, 77, 77, 0.45); color: #ffb1b1; background: linear-gradient(180deg, rgba(255, 77, 77, 0.16), rgba(255, 77, 77, 0.05)); }
.icon-btn {
  border: 1px solid var(--line);
  background: #131a20;
  color: var(--text-dim);
  width: 30px; height: 30px;
  border-radius: 8px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, transform 0.15s;
}
.icon-btn:hover { color: var(--text); border-color: #3a4753; transform: rotate(90deg); }

/* ------------------------------------------------------------------ 布局 */
.shell {
  position: relative;
  z-index: 1;
  padding: 22px 26px 60px;
  max-width: 1680px;
  margin: 0 auto;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 22px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--panel-0), var(--panel-1));
  box-shadow: var(--shadow-card);
  margin-bottom: 20px;
}
.tool-group { display: flex; align-items: center; gap: 8px; }
.tool-label {
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-right: 2px;
}
.tabs { display: flex; gap: 4px; margin-left: auto; padding: 3px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line-soft); }
.tab {
  position: relative;
  font-family: var(--font-display);
  font-size: 12.5px;
  letter-spacing: 0.08em;
  padding: 8px 15px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: color 0.16s, background 0.16s;
}
.tab:hover { color: var(--text); }
.tab.is-active {
  color: #ffd479;
  background: linear-gradient(180deg, rgba(255, 179, 2, 0.16), rgba(255, 179, 2, 0.05));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 0 18px -10px var(--amber-glow);
}
.tab-badge {
  display: none;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(69, 214, 208, 0.18);
  color: var(--cyan);
  font-size: 11px;
  font-family: var(--font-mono);
}
.tab-badge.has { display: inline-block; }

.panel { display: none; animation: fade-up 0.35s ease both; }
.panel.is-active { display: block; }
.panel-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line-soft);
}
.panel-head h2 { margin: 0; font-family: var(--font-display); font-size: 17px; letter-spacing: 0.06em; text-transform: uppercase; }
.panel-sub { margin: 4px 0 0; font-size: 12.5px; color: var(--text-dim); }

/* -------------------------------------------------------------- 设备卡片 */
.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 18px;
}
.device-card {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 16px 16px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.025), transparent 40%),
    linear-gradient(180deg, var(--panel-0), var(--panel-2));
  box-shadow: var(--shadow-card);
  overflow: hidden;
  animation: rise 0.5s cubic-bezier(0.2, 0.85, 0.25, 1) both;
  animation-delay: calc(var(--i, 0) * 55ms);
  transition: border-color 0.2s, transform 0.2s, box-shadow 0.25s;
}
/* 四角铆钉 */
.device-card::before,
.device-card::after {
  content: "";
  position: absolute;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #46545f, #1b2228 70%);
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.6);
  opacity: 0.75;
}
.device-card::before { top: 8px; left: 8px; }
.device-card::after { top: 8px; right: 8px; }

.device-card:hover { transform: translateY(-2px); border-color: #33414d; box-shadow: 0 1px 0 rgba(255, 255, 255, 0.05) inset, 0 18px 34px -20px #000; }
.device-card.is-on { border-color: rgba(255, 179, 2, 0.42); }
.device-card.is-on { box-shadow: 0 1px 0 rgba(255, 255, 255, 0.05) inset, 0 18px 34px -20px #000, 0 0 34px -22px var(--amber-glow); }
.device-card.is-off { border-color: #2b343d; }
.device-card.is-unknown { border-color: #3c4a56; border-style: dashed; }
.device-card.is-offline { border-style: dashed; border-color: #3a2a2e; opacity: 0.82; }
.device-card.is-busy { pointer-events: none; }
.device-card.is-busy::after { box-shadow: none; }

.card-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.chip {
  font-family: var(--font-display);
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #131a20;
  color: var(--text-dim);
}
.chip-group { color: #b9c7d3; }
.chip-type { color: var(--text-faint); }
.chip-online { color: var(--green); border-color: rgba(78, 222, 138, 0.35); background: rgba(78, 222, 138, 0.08); }
.chip-offline { color: #ff9d9d; border-color: rgba(255, 77, 77, 0.35); background: rgba(255, 77, 77, 0.08); }
.card-menu { margin-left: auto; display: flex; gap: 6px; opacity: 0; transition: opacity 0.18s; }
.device-card:hover .card-menu, .device-card:focus-within .card-menu { opacity: 1; }
.card-menu button {
  border: 1px solid var(--line);
  background: #12181e;
  color: var(--text-dim);
  font-size: 11.5px;
  padding: 3px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.card-menu button:hover { color: var(--text); border-color: #3a4753; }
.card-menu button[data-act="del"]:hover { color: #ff9d9d; border-color: rgba(255, 77, 77, 0.5); }

.device-name {
  margin: 0 0 4px;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.02em;
  word-break: break-all;
}
.device-meta {
  margin: 0 0 14px;
  font-size: 11.5px;
  color: var(--text-faint);
  font-family: var(--font-mono);
  display: flex;
  flex-wrap: wrap;
  gap: 2px 8px;
}
.device-note { margin: -8px 0 12px; font-size: 12px; color: var(--text-dim); }

/* 状态灯 + 读数 */
.readout {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #0a0f13;
  border: 1px solid var(--line-soft);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.7);
}
.lamp {
  width: 15px; height: 15px;
  border-radius: 50%;
  flex: 0 0 auto;
  background: #1d2429;
  box-shadow: inset 0 0 0 1px #2b343b;
  position: relative;
}
.lamp.on {
  background: radial-gradient(circle at 35% 30%, #fff2cf, var(--amber) 55%, var(--amber-deep));
  box-shadow: 0 0 12px 2px var(--amber-glow), inset 0 0 3px rgba(0, 0, 0, 0.4);
  animation: lamp-breathe 2.6s ease-in-out infinite;
}
.lamp.off {
  background: radial-gradient(circle at 35% 30%, #3a464f, #1a2126 70%);
  box-shadow: inset 0 0 0 1px #2b343b, inset 0 -2px 4px rgba(0, 0, 0, 0.6);
}
.lamp.unknown {
  background: radial-gradient(circle at 35% 30%, #4b3a3a, #241a1a 70%);
  box-shadow: 0 0 10px 1px var(--red-glow), inset 0 0 0 1px #4a2b2b;
}
.readout-state {
  font-family: var(--font-display);
  font-size: 15px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.readout-state.on { color: #ffd479; text-shadow: 0 0 18px var(--amber-glow); }
.readout-state.off { color: var(--text-dim); }
.readout-state.unknown { color: #ff9d9d; }
.readout-right { margin-left: auto; text-align: right; font-size: 11px; color: var(--text-faint); line-height: 1.4; }
.readout-right b { display: block; font-size: 12.5px; color: var(--text-dim); font-weight: 500; }

/* 物理拨档开关 */
.switch {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  margin-top: 14px;
  padding: 4px;
  border-radius: 12px;
  background: linear-gradient(180deg, #0c1116, #10161b);
  border: 1px solid var(--line);
  box-shadow: inset 0 3px 8px rgba(0, 0, 0, 0.75), 0 1px 0 rgba(255, 255, 255, 0.03);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.switch .opt {
  position: relative;
  z-index: 2;
  text-align: center;
  padding: 13px 0;
  font-family: var(--font-display);
  font-size: 14px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--text-faint);
  transition: color 0.22s;
}
.switch .knob {
  position: absolute;
  z-index: 1;
  top: 4px; bottom: 4px;
  left: 4px;
  width: calc(50% - 4px);
  border-radius: 9px;
  background: linear-gradient(180deg, #29343d, #1a222a);
  border: 1px solid #36434f;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.09), 0 8px 18px -10px #000;
  transition: transform 0.32s cubic-bezier(0.2, 1.25, 0.35, 1), background 0.25s, border-color 0.25s;
}
.switch[data-state="close"] .knob { transform: translateX(100%); }
.switch[data-state="open"] .opt[data-val="open"],
.switch[data-state="close"] .opt[data-val="close"] { color: #fff; }
.switch[data-state="open"] .knob {
  background: linear-gradient(180deg, #ffca4d, #d99000);
  border-color: #ffdc85;
  box-shadow: 0 0 26px -4px var(--amber-glow), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}
.switch[data-state="open"] .opt[data-val="open"] { color: #3a2700; text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35); }
.switch[data-state="close"] .knob { box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 8px 18px -10px #000; }
.switch.is-pending .knob { animation: knob-pulse 0.9s ease-in-out infinite; }
.switch.is-disabled { cursor: not-allowed; opacity: 0.5; }

.card-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: auto;
  padding-top: 12px;
  font-size: 11px;
  color: var(--text-faint);
}
.card-foot .spacer { margin-left: auto; }
.link-btn {
  border: 0;
  background: none;
  color: var(--text-faint);
  font-size: 11.5px;
  cursor: pointer;
  padding: 3px 4px;
  border-bottom: 1px dashed transparent;
  transition: color 0.15s, border-color 0.15s;
}
.link-btn:hover { color: var(--cyan); border-color: var(--cyan); }

/* -------------------------------------------------------------- 定时任务 */
.task-list { display: flex; flex-direction: column; gap: 12px; }
.task-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--panel-0), var(--panel-2));
  box-shadow: var(--shadow-card);
  animation: rise 0.4s cubic-bezier(0.2, 0.85, 0.25, 1) both;
  animation-delay: calc(var(--i, 0) * 40ms);
}
.task-item.is-paused { opacity: 0.62; }
.task-item.is-due { border-color: rgba(69, 214, 208, 0.4); }
.task-main { min-width: 0; flex: 1; }
.task-name { margin: 0; font-size: 15.5px; font-weight: 600; }
.task-meta { margin: 4px 0 0; font-size: 12px; color: var(--text-dim); display: flex; flex-wrap: wrap; gap: 4px 10px; }
.task-meta .mono { color: var(--text-faint); }
.task-tagline { margin: 6px 0 0; font-size: 11.5px; color: var(--text-faint); }
.task-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }

.toggle-mini {
  position: relative;
  width: 46px; height: 26px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #0d1318;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
  flex: 0 0 auto;
}
.toggle-mini span {
  position: absolute;
  top: 2px; left: 2px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: linear-gradient(180deg, #3b4753, #222a31);
  transition: transform 0.26s cubic-bezier(0.2, 1.25, 0.35, 1), background 0.2s;
}
.toggle-mini.is-on { border-color: rgba(69, 214, 208, 0.5); background: rgba(69, 214, 208, 0.14); }
.toggle-mini.is-on span { transform: translateX(20px); background: linear-gradient(180deg, #8ff0ec, #2ba8a3); }

/* ------------------------------------------------------------------ 日志 */
.log-list { display: flex; flex-direction: column; gap: 2px; }
.log-row {
  display: grid;
  grid-template-columns: 150px 78px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 12.5px;
  transition: background 0.15s, border-color 0.15s;
}
.log-row:nth-child(odd) { background: rgba(255, 255, 255, 0.014); }
.log-row:hover { background: rgba(255, 255, 255, 0.03); border-color: var(--line-soft); }
.log-time { color: var(--text-faint); font-family: var(--font-mono); font-size: 11.5px; }
.log-kind {
  font-family: var(--font-display);
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 5px;
  text-align: center;
  border: 1px solid var(--line);
  color: var(--text-dim);
}
.log-kind.k-switch { color: #ffd479; border-color: rgba(255, 179, 2, 0.32); }
.log-kind.k-task { color: var(--cyan); border-color: rgba(69, 214, 208, 0.32); }
.log-kind.k-login { color: #c8b4ff; border-color: rgba(160, 130, 255, 0.32); }
.log-kind.k-discover, .log-kind.k-device { color: #9fd8ff; border-color: rgba(120, 190, 255, 0.3); }
.log-kind.k-error { color: #ff9d9d; border-color: rgba(255, 77, 77, 0.4); }
.log-text { color: var(--text-dim); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-text b { color: var(--text); font-weight: 600; }
.log-bad { color: #ff9d9d; }
.log-lat { color: var(--text-faint); font-family: var(--font-mono); font-size: 11.5px; }

.empty-state { text-align: center; padding: 70px 20px; border: 1px dashed var(--line); border-radius: var(--radius); background: rgba(255, 255, 255, 0.012); }.empty-title { margin: 0 0 6px; font-size: 16px; font-family: var(--font-display); letter-spacing: 0.05em; }
.empty-sub { margin: 0; color: var(--text-dim); font-size: 13px; }

/* ------------------------------------------------------------------ 弹层 */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(4, 6, 8, 0.72);
  backdrop-filter: blur(6px);
  animation: fade 0.18s ease both;
}
.modal[hidden] { display: none; }
.modal-card {
  width: 100%;
  max-width: 620px;
  max-height: 88vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(180deg, #161d24, #0f141a);
  box-shadow: 0 40px 90px -30px #000, inset 0 1px 0 rgba(255, 255, 255, 0.05);
  animation: pop 0.24s cubic-bezier(0.2, 1.2, 0.35, 1) both;
}
.modal-narrow { max-width: 460px; }
.modal-wide { max-width: 860px; }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line-soft);
}
.modal-head h2 { margin: 0; font-family: var(--font-display); font-size: 16px; letter-spacing: 0.08em; text-transform: uppercase; }
.modal-body { padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-foot {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 20px;
  border-top: 1px solid var(--line-soft);
  background: rgba(0, 0, 0, 0.18);
}
.modal-foot .btn-primary, .modal-foot .btn-ghost:last-child { margin-left: auto; }
.modal-foot .btn-primary + .btn-ghost, .modal-foot .btn-ghost + .btn-primary { margin-left: 0; }
.modal-foot > .btn:first-of-type { margin-left: auto; }
.rule { border: 0; border-top: 1px solid var(--line-soft); margin: 4px 0; }

/* 表单 */
.field { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 0; }
.field-label {
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.field-hint { font-size: 11.5px; color: var(--text-faint); }
.field-row { display: flex; gap: 14px; flex-wrap: wrap; }
.field-inline { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-dim); }
input[type="text"], input[type="password"], input[type="number"], input[type="time"], input[type="datetime-local"], input:not([type]), select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: #0b1015;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  transition: border-color 0.16s, box-shadow 0.16s;
}
input:focus, select:focus { outline: none; border-color: var(--cyan-deep); box-shadow: 0 0 0 3px rgba(69, 214, 208, 0.14); }
input::placeholder { color: #4d5b66; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, #6b7b88 50%), linear-gradient(135deg, #6b7b88 50%, transparent 50%); background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
input[type="checkbox"] { accent-color: var(--cyan); width: 15px; height: 15px; }
.form-error { margin: 0; min-height: 16px; font-size: 12.5px; color: #ff9d9d; }
.device-picker { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.device-picker label {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101720;
  font-size: 12.5px;
  color: var(--text-dim);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.device-picker label:hover { border-color: #3a4753; color: var(--text); }
.device-picker label.is-checked { border-color: rgba(69, 214, 208, 0.5); background: rgba(69, 214, 208, 0.1); color: #a9f4f1; }
.day-picker { display: flex; gap: 6px; flex-wrap: wrap; }
.day-picker label {
  display: flex; align-items: center; justify-content: center;
  width: 40px; height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101720;
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}
.day-picker input { display: none; }
.day-picker label.is-checked { border-color: rgba(255, 179, 2, 0.5); background: rgba(255, 179, 2, 0.12); color: #ffd479; }

/* 扫描雷达 */
.scan-stage { position: relative; display: flex; align-items: center; justify-content: center; height: 170px; border: 1px solid var(--line-soft); border-radius: 12px; background: radial-gradient(circle at 50% 50%, rgba(69, 214, 208, 0.08), transparent 70%), #080d11; overflow: hidden; }
.scan-radar {
  position: absolute;
  width: 320px; height: 320px;
  border-radius: 50%;
  background: conic-gradient(from 0deg, rgba(69, 214, 208, 0.42), rgba(69, 214, 208, 0) 26%, transparent 100%);
  animation: sweep 1.8s linear infinite;
  -webkit-mask-image: radial-gradient(circle, #000 62%, transparent 72%);
  mask-image: radial-gradient(circle, #000 62%, transparent 72%);
}
.scan-radar::before, .scan-radar::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px solid rgba(69, 214, 208, 0.22);
}
.scan-radar::before { inset: 22%; }
.scan-radar::after { inset: 44%; }
.scan-text { position: relative; z-index: 2; margin: 0; font-family: var(--font-mono); font-size: 12.5px; color: var(--cyan); letter-spacing: 0.06em; text-shadow: 0 0 16px rgba(69, 214, 208, 0.5); }
.scan-stage.is-done .scan-radar { animation: none; opacity: 0.28; }
.scan-result { display: flex; flex-direction: column; gap: 8px; }
.scan-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0d1319;
  animation: ping-in 0.4s cubic-bezier(0.2, 1.2, 0.35, 1) both;
  animation-delay: calc(var(--i, 0) * 70ms);
}
.scan-row.is-known { border-color: rgba(69, 214, 208, 0.34); }
.scan-row label { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; cursor: pointer; }
.scan-info { min-width: 0; }
.scan-name { font-size: 14px; font-weight: 600; }
.scan-meta { font-size: 11.5px; color: var(--text-faint); font-family: var(--font-mono); }
.scan-badge { font-size: 10.5px; padding: 2px 7px; border-radius: 5px; border: 1px solid var(--line); color: var(--text-dim); font-family: var(--font-display); letter-spacing: 0.08em; text-transform: uppercase; }
.scan-badge.changed { color: #ffd479; border-color: rgba(255, 179, 2, 0.4); }

/* 提示条 */
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 90; display: flex; flex-direction: column; gap: 10px; max-width: min(380px, calc(100vw - 40px)); }
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #171f26, #10161b);
  box-shadow: 0 20px 40px -22px #000;
  font-size: 13px;
  animation: toast-in 0.28s cubic-bezier(0.2, 1.2, 0.35, 1) both;
}
.toast.out { animation: toast-out 0.22s ease forwards; }
.toast::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--cyan); box-shadow: 0 0 12px var(--cyan); flex: 0 0 auto; }
.toast.ok::before { background: var(--green); box-shadow: 0 0 12px var(--green); }
.toast.warn::before { background: var(--amber); box-shadow: 0 0 12px var(--amber); }
.toast.err::before { background: var(--red); box-shadow: 0 0 12px var(--red); }

/* 忙碌遮罩 */
.busy {
  position: fixed; inset: 0; z-index: 80;
  display: flex; align-items: center; justify-content: center; gap: 12px;
  background: rgba(4, 6, 8, 0.45);
  backdrop-filter: blur(2px);
  font-size: 13.5px;
  color: var(--text-dim);
}
.busy[hidden] { display: none; }
.busy-spinner {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 2px solid rgba(69, 214, 208, 0.2);
  border-top-color: var(--cyan);
  animation: spin 0.8s linear infinite;
}

/* ------------------------------------------------------------------ 登录页 */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 24px; }
.login-wrap { position: relative; z-index: 2; width: 100%; max-width: 400px; }
.login-card {
  padding: 26px 24px 20px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(180deg, #161e25, #0d1217);
  box-shadow: 0 50px 90px -40px #000, inset 0 1px 0 rgba(255, 255, 255, 0.05);
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: rise 0.5s cubic-bezier(0.2, 0.85, 0.25, 1) both;
}
.login-card.shake { animation: shake 0.4s cubic-bezier(0.36, 0.07, 0.19, 0.97) both; }
.plate {
  display: inline-flex; align-items: center; gap: 8px;
  align-self: flex-start;
  padding: 5px 10px;
  border-radius: 7px;
  border: 1px solid #2c3843;
  background: linear-gradient(180deg, #202a33, #151c22);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07);
}
.plate-led { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 10px var(--green); animation: lamp-breathe 2.4s ease-in-out infinite; }
.plate-text { font-family: var(--font-display); font-size: 10.5px; letter-spacing: 0.24em; color: var(--text-dim); }
.login-card h1 { margin: 2px 0 0; font-family: var(--font-display); font-size: 22px; letter-spacing: 0.06em; }
.login-sub { margin: -8px 0 4px; color: var(--text-dim); font-size: 13px; }
.login-msg { margin: 0; min-height: 18px; font-size: 12.5px; color: #ff9d9d; }
.login-foot { margin: 2px 0 0; font-size: 11.5px; color: var(--text-faint); text-align: center; }
code { font-family: var(--font-mono); font-size: 0.92em; background: rgba(255, 255, 255, 0.05); padding: 1px 5px; border-radius: 4px; }

/* 顶部提示条（例如仍在使用出厂口令） */
.alert {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  padding: 12px 16px;
  border: 1px solid rgba(255, 179, 2, 0.42);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(255, 179, 2, 0.13), rgba(255, 179, 2, 0.04));
  color: #ffd479;
  font-size: 13px;
}
.alert strong { color: #fff; }
.alert::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 12px var(--amber); flex: 0 0 auto; }
.alert .btn { margin-left: auto; }

/* ------------------------------------------------------------- 动画定义 */
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes fade-up { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(0.97); } to { opacity: 1; transform: none; } }
@keyframes toast-in { from { opacity: 0; transform: translateX(24px) scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateX(24px) scale(0.96); } }
@keyframes ping-in { from { opacity: 0; transform: scale(0.94); } to { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes sweep { to { transform: rotate(360deg); } }
@keyframes lamp-breathe { 0%, 100% { opacity: 1; } 50% { opacity: 0.62; } }
@keyframes knob-pulse { 0%, 100% { filter: brightness(1); } 50% { filter: brightness(1.5); } }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-7px); }
  40%, 60% { transform: translateX(7px); }
}

/* 触摸设备没有 hover，卡片操作按钮常显 */
@media (hover: none) {
  .card-menu { opacity: 1; }
  .device-card:hover { transform: none; }
}

/* --------------------------------------------------------------- 响应式 */
@media (max-width: 900px) {
  .shell { padding: 16px 14px 56px; }
  .topbar { padding: 12px 14px; flex-wrap: wrap; }
  .topbar-right { width: 100%; justify-content: space-between; }
  .clock { display: none; }
  .toolbar { gap: 12px; }
  .tabs { margin-left: 0; width: 100%; }
  .tab { flex: 1; text-align: center; }
  .log-row { grid-template-columns: 96px 64px 1fr; }
  .log-lat { display: none; }
}
@media (max-width: 560px) {
  body { font-size: 14.5px; }
  .brand h1 { font-size: 16px; }
  .device-grid { grid-template-columns: 1fr; gap: 14px; }
  .tool-group { flex: 1 1 auto; }
  .tool-group .btn { flex: 1; text-align: center; }
  .tool-label { display: none; }
  .task-item { flex-direction: column; align-items: stretch; }
  .task-actions { justify-content: space-between; }
  .modal { padding: 10px; }
  .modal-card { max-height: 94vh; }
  .switch .opt { padding: 16px 0; font-size: 15px; }
  .log-row { grid-template-columns: 1fr auto; gap: 6px; }
  .log-kind { display: none; }
  .log-time { grid-column: 1; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}
