/* ============================================================
   称重溯源云平台 · 控制台样式（深色工业风）
   ============================================================ */
:root {
  --bg: #0b0f14;
  --bg-2: #11161d;
  --panel: #151b23;
  --panel-2: #1a212a;
  --line: #232b36;
  --line-soft: #1b222c;
  --text: #e6edf3;
  --text-2: #9aa7b4;
  --text-3: #6b7885;
  --brand: #3b82f6;
  --brand-2: #1d4ed8;
  --ok: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(1200px 600px at 15% -10%, #16202c 0%, var(--bg) 55%) fixed, var(--bg);
  color: var(--text);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: .2px; }
input, select, textarea, button { font-family: inherit; font-size: 14px; }

/* ---------------- 登录页 ---------------- */
.login-body { display: grid; place-items: center; min-height: 100%; padding: 24px; }
.login-wrap { width: 100%; max-width: 420px; }
.login-card {
  background: linear-gradient(180deg, rgba(28,36,46,.92), rgba(18,24,31,.96));
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 30px 26px 22px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}
.brand { display: flex; gap: 14px; align-items: center; margin-bottom: 26px; }
.brand-mark {
  width: 44px; height: 44px; border-radius: 12px;
  display: grid; place-items: center;
  font-size: 20px; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  box-shadow: 0 6px 18px rgba(59,130,246,.35);
}
.brand-text h1 { font-size: 18px; }
.brand-text p { margin: 3px 0 0; color: var(--text-2); font-size: 12px; }
.field { display: block; margin-bottom: 16px; }
.field > span { display: block; margin-bottom: 7px; color: var(--text-2); font-size: 12.5px; }
.field input, .field select, textarea, .input {
  width: 100%; padding: 11px 13px; color: var(--text);
  background: #0e141b; border: 1px solid var(--line); border-radius: 10px;
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, textarea:focus, .input:focus {
  border-color: #2f6ed8; box-shadow: 0 0 0 3px rgba(59,130,246,.16);
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); cursor: pointer;
  transition: transform .06s, background .15s, border-color .15s, opacity .15s;
  white-space: nowrap;
}
.btn:hover { background: #202936; border-color: #2d3948; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: linear-gradient(135deg, #3b82f6, #2563eb); border-color: #2563eb; font-weight: 600; }
.btn-primary:hover { background: linear-gradient(135deg, #4f8ef8, #2f6ed8); }
.btn-danger { border-color: #7f2d2d; color: #ffb4b4; background: #2a1618; }
.btn-danger:hover { background: #351a1d; }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; padding: 12px; margin-top: 6px; }
.login-error {
  margin: -4px 0 14px; padding: 9px 12px; border-radius: 9px;
  background: rgba(239,68,68,.12); border: 1px solid rgba(239,68,68,.35);
  color: #ffb4b4; font-size: 13px;
}
.shake { animation: shake .32s; }
@keyframes shake {
  0%,100% { transform: translateX(0); } 25% { transform: translateX(-5px); }
  50% { transform: translateX(5px); } 75% { transform: translateX(-3px); }
}
.login-foot {
  margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--line-soft);
  display: flex; gap: 8px; justify-content: center;
  color: var(--text-3); font-size: 12px;
}
.dot-sep { opacity: .5; }

/* ---------------- 主控制台 ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px;
  padding: 12px 18px; border-bottom: 1px solid var(--line);
  background: rgba(11,15,20,.86); backdrop-filter: blur(10px);
}
.topbar .brand { margin: 0; gap: 11px; }
.topbar .brand-mark { width: 34px; height: 34px; border-radius: 10px; font-size: 16px; }
.topbar .brand-text h1 { font-size: 15px; }
.topbar .brand-text p { font-size: 11px; margin-top: 1px; }
.spacer { flex: 1; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 999px; font-size: 12px;
  border: 1px solid var(--line); background: var(--panel);
  color: var(--text-2); white-space: nowrap;
}
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); }
.pill.ok .dot { background: var(--ok); box-shadow: 0 0 0 3px rgba(34,197,94,.16); }
.pill.bad .dot { background: var(--bad); box-shadow: 0 0 0 3px rgba(239,68,68,.16); }
.pill.warn .dot { background: var(--warn); }

.layout {
  display: grid; grid-template-columns: 300px minmax(0,1fr); gap: 14px;
  padding: 14px 18px 26px; align-items: start;
  max-width: 1600px; margin: 0 auto;
}
.panel {
  background: linear-gradient(180deg, rgba(26,33,42,.92), rgba(21,27,35,.96));
  border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; border-bottom: 1px solid var(--line-soft);
  font-size: 13px; font-weight: 600;
}
.panel-head .sub { color: var(--text-3); font-weight: 400; font-size: 12px; }
.panel-body { padding: 12px 14px; }

/* 设备列表 */
.device-list { max-height: calc(100vh - 190px); overflow: auto; padding: 8px; display: grid; gap: 8px; }
.device-item {
  padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line-soft);
  background: #121821; cursor: pointer; transition: border-color .15s, background .15s, transform .06s;
}
.device-item:hover { border-color: #2d3948; background: #161d27; }
.device-item:active { transform: scale(.995); }
.device-item.active { border-color: #2f6ed8; background: #16202c; box-shadow: 0 0 0 1px rgba(59,130,246,.25) inset; }
.device-item .row1 { display: flex; align-items: center; gap: 8px; }
.device-item .name { font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; }
.device-item .meta { margin-top: 5px; color: var(--text-3); font-size: 11.5px; display: flex; gap: 10px; flex-wrap: wrap; }
.device-item .weight { margin-top: 6px; font-size: 17px; font-weight: 700; color: #cfe3ff; letter-spacing: .4px; }
.device-item .weight small { font-size: 11px; color: var(--text-3); font-weight: 400; }
.badge { font-size: 10.5px; padding: 2px 7px; border-radius: 999px; border: 1px solid var(--line); color: var(--text-2); }
.badge.on { color: #8ff0b2; border-color: rgba(34,197,94,.4); background: rgba(34,197,94,.1); }
.badge.off { color: #ffb4b4; border-color: rgba(239,68,68,.35); background: rgba(239,68,68,.08); }

/* 画面预览 */
.screen-box {
  position: relative; background: #070a0e; border-radius: 10px; overflow: hidden;
  min-height: 260px; display: grid; place-items: center;
}
.screen-box img { display: block; width: 100%; height: auto; max-height: 62vh; object-fit: contain; }
.screen-empty { padding: 42px 18px; text-align: center; color: var(--text-3); font-size: 13px; line-height: 1.8; }
.screen-tools { position: absolute; right: 8px; top: 8px; display: flex; gap: 6px; }
.screen-tools .btn { padding: 5px 9px; font-size: 11.5px; background: rgba(11,15,20,.82); }
.screen-stats {
  position: absolute; left: 8px; bottom: 8px; display: flex; gap: 6px; flex-wrap: wrap;
  font-size: 11px; color: #cfe3ff; background: rgba(11,15,20,.75);
  padding: 4px 8px; border-radius: 8px;
}

/* 实时数据 */
.kv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px,1fr)); gap: 10px; }
.kv {
  padding: 9px 11px; border-radius: 10px; background: #10161e; border: 1px solid var(--line-soft);
}
.kv .k { color: var(--text-3); font-size: 11px; }
.kv .v { margin-top: 3px; font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kv .v.big { font-size: 20px; letter-spacing: .5px; color: #d7e9ff; }
.kv.on .v { color: #8ff0b2; }
.kv.off .v { color: var(--text-3); }

/* 指令面板 */
.cmd-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.cmd-grid .btn { flex: 0 0 auto; }
.cmd-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px,1fr)); gap: 10px; margin-top: 12px; }
.cmd-form label { display: block; }
.cmd-form span { display: block; color: var(--text-3); font-size: 11.5px; margin-bottom: 5px; }
textarea { min-height: 74px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12.5px; }

/* 事件流 */
.events { max-height: 340px; overflow: auto; display: grid; gap: 6px; }
.ev {
  display: grid; grid-template-columns: 62px 1fr; gap: 8px; align-items: start;
  padding: 7px 9px; border-radius: 9px; background: #10161e; border: 1px solid var(--line-soft);
  font-size: 12px;
}
.ev .t { color: var(--text-3); font-variant-numeric: tabular-nums; }
.ev .b { color: var(--text-2); word-break: break-all; font-family: ui-monospace, Consolas, monospace; font-size: 11.5px; }
.ev .tag { display: inline-block; margin-right: 6px; padding: 0 6px; border-radius: 6px; font-size: 10.5px; font-family: inherit; }
.tag.in { color: #9ad7ff; background: rgba(59,130,246,.14); }
.tag.out { color: #ffd58a; background: rgba(245,158,11,.14); }
.tag.sys { color: #d0b6ff; background: rgba(168,85,247,.14); }

/* 记录卡片 */
.records { display: grid; gap: 8px; max-height: 300px; overflow: auto; }
.rec {
  padding: 10px 12px; border-radius: 10px; background: #10161e; border: 1px solid var(--line-soft);
}
.rec .code { font-size: 15px; font-weight: 700; letter-spacing: 1px; color: #cfe3ff; font-family: ui-monospace, Consolas, monospace; }
.rec .line { margin-top: 5px; color: var(--text-3); font-size: 11.5px; display: flex; gap: 12px; flex-wrap: wrap; }

.empty { padding: 22px 12px; text-align: center; color: var(--text-3); font-size: 12.5px; }

/* 提示条 */
#toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 16px);
  max-width: min(560px, 92vw); padding: 11px 16px; border-radius: 10px;
  background: rgba(17,23,31,.96); border: 1px solid var(--line); color: var(--text);
  box-shadow: var(--shadow); font-size: 13px; opacity: 0; pointer-events: none;
  transition: opacity .18s, transform .18s; z-index: 50;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.ok { border-color: rgba(34,197,94,.45); }
#toast.bad { border-color: rgba(239,68,68,.5); }

/* 危险确认弹窗 */
.mask {
  position: fixed; inset: 0; background: rgba(3,6,10,.72); backdrop-filter: blur(3px);
  display: grid; place-items: center; z-index: 60; padding: 20px;
}
.mask[hidden] { display: none; }
.dialog {
  width: min(420px, 94vw); background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 18px; box-shadow: var(--shadow);
}
.dialog h3 { font-size: 15px; margin-bottom: 8px; }
.dialog p { color: var(--text-2); font-size: 13px; margin: 0 0 14px; }
.dialog .cmd-preview {
  background: #0d1319; border: 1px solid var(--line-soft); border-radius: 9px;
  padding: 9px 11px; color: #ffd58a; font-family: ui-monospace, Consolas, monospace;
  font-size: 12px; word-break: break-all; margin-bottom: 16px;
}
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; }

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; padding: 12px; }
  .device-list { max-height: 260px; }
  .topbar { flex-wrap: wrap; }
}
