:root {
  --bg: #f3f6f4;
  --card: #ffffff;
  --ink: #17251d;
  --muted: #6b7c72;
  --line: #dfe8e2;
  --green: #1f7a4d;
  --green-2: #2f9e66;
  --green-soft: #e8f5ee;
  --amber: #b97712;
  --amber-soft: #fff6e5;
  --red: #c0392b;
  --red-soft: #fdecea;
  --blue: #2563a6;
  --blue-soft: #eaf2fb;
  --shadow: 0 10px 30px rgba(20, 52, 38, .06);
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; }
.shell { display: grid; grid-template-columns: 238px minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  background: linear-gradient(180deg, #0f3d2e 0%, #14563f 100%);
  color: #eaf5ef;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; gap: 11px; align-items: center; padding: 4px 8px 24px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 12px;
  display: grid; place-items: center;
  background: #d7f3e2; color: #0f3d2e; font-weight: 800; font-size: 20px;
}
.brand strong { display: block; font-size: 16px; letter-spacing: .3px; }
.brand span { display: block; color: #9fc7b5; font-size: 11px; margin-top: 3px; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  color: #c8ded4; padding: 11px 12px; border-radius: 10px;
  font-size: 13.5px; transition: background .15s, color .15s;
}
.nav a span { width: 18px; text-align: center; color: #93c4ad; }
.nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav a.active { background: #d9f2e4; color: #12432f; font-weight: 700; }
.nav a.active span { color: #1f7a4d; }
.side-foot {
  margin-top: auto; display: flex; gap: 10px; align-items: flex-start;
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.09);
  padding: 12px; border-radius: 12px;
}
.env-dot { width: 8px; height: 8px; border-radius: 50%; background: #62d49a; margin-top: 5px; box-shadow: 0 0 0 4px rgba(98,212,154,.12); }
.side-foot b { display: block; font-size: 12px; }
.side-foot small { display: block; color: #9fc7b5; font-size: 10.5px; margin-top: 3px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 74px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px; border-bottom: 1px solid var(--line);
  background: rgba(243,246,244,.92); backdrop-filter: blur(10px);
  position: sticky; top: 0; z-index: 5;
}
.crumb { font-size: 16px; font-weight: 700; }
.top-sub { color: var(--muted); font-size: 11.5px; margin-top: 4px; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.pill { background: var(--green-soft); color: var(--green); font-size: 11px; padding: 6px 10px; border-radius: 999px; }
#ws-state.off { background: #eef2ef; color: var(--muted); }
#ws-state.on { background: var(--green-soft); color: var(--green); }
#mqtt-state.on { background: var(--green-soft); color: var(--green); }
#mqtt-state.connecting { background: var(--amber-soft); color: var(--amber); }
#mqtt-state.off { background: var(--red-soft); color: var(--red); }
#mqtt-state.disabled { background: #eef2ef; color: var(--muted); }
.alarm-pill { background: var(--red-soft); color: var(--red); font-weight: 700; }
.alarm-pill.quiet { background: var(--green-soft); color: var(--green); }
.avatar { width: 34px; height: 34px; border-radius: 10px; background: #d9f2e4; color: #14563f; display: grid; place-items: center; font-weight: 700; }
.view { padding: 24px 28px 40px; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.page-head h1 { font-size: 22px; margin: 0 0 6px; letter-spacing: .2px; }
.page-head p { margin: 0; color: var(--muted); font-size: 12px; }
.page-actions { display: flex; gap: 8px; align-items: center; }

.btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 9px 14px; border-radius: 10px; cursor: pointer; font-size: 12.5px;
  transition: .15s; white-space: nowrap;
}
.btn:hover { border-color: #b9cdc1; background: #fbfdfc; }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:hover { background: #196b43; }
.btn.danger { color: var(--red); border-color: #f1c7c2; background: #fffafa; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 9px; font-size: 11.5px; border-radius: 8px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 16px; }
.kpi {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 17px 18px; box-shadow: var(--shadow);
}
.kpi .label { color: var(--muted); font-size: 11.5px; display: flex; justify-content: space-between; }
.kpi .value { font-size: 28px; font-weight: 800; margin-top: 10px; letter-spacing: .5px; }
.kpi .hint { color: var(--muted); font-size: 11px; margin-top: 6px; }
.kpi.green .value { color: var(--green); }
.kpi.amber .value { color: var(--amber); }
.kpi.blue .value { color: var(--blue); }

.grid-2 { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, .65fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.card-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px 12px; }
.card-head h3 { margin: 0; font-size: 14px; }
.card-head .muted { color: var(--muted); font-size: 11px; }
.card-body { padding: 0 18px 16px; }
.card-body.pad { padding: 16px 18px; }
.divider { height: 1px; background: var(--line); margin: 0 18px; }

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 10px; border-bottom: 1px solid #edf2ee; font-size: 12.5px; white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 11px; background: #fbfdfc; }
tbody tr:hover { background: #f8fbf9; }
td .name { font-weight: 700; }
td .sub { color: var(--muted); font-size: 10.5px; margin-top: 2px; }
.row-link { cursor: pointer; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 4px 8px; border-radius: 999px; font-size: 10.5px; font-weight: 600; }
.badge::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.badge.online, .badge.active, .badge.success { color: var(--green); background: var(--green-soft); }
.badge.offline, .badge.retired, .badge.failed { color: var(--red); background: var(--red-soft); }
.badge.warn, .badge.inventory, .badge.pending, .badge.sent, .badge.timeout { color: var(--amber); background: var(--amber-soft); }
.badge.info { color: var(--blue); background: var(--blue-soft); }

.metric-list { display: grid; gap: 10px; }
.metric { display: flex; justify-content: space-between; align-items: center; padding: 9px 0; border-bottom: 1px dashed #edf2ee; }
.metric:last-child { border-bottom: 0; }
.metric span { color: var(--muted); font-size: 11.5px; }
.metric b { font-size: 13px; }

.device-hero {
  background: linear-gradient(135deg, #15563f, #1f7a4d 58%, #2f9e66);
  color: #fff; border-radius: 18px; padding: 22px 24px; margin-bottom: 16px;
  display: flex; justify-content: space-between; gap: 20px; box-shadow: 0 14px 34px rgba(24, 90, 61, .18);
}
.device-hero h2 { margin: 0 0 6px; font-size: 23px; }
.device-hero p { margin: 0; color: #cde9db; font-size: 12px; }
.hero-meta { display: flex; gap: 22px; flex-wrap: wrap; margin-top: 16px; }
.hero-meta div span { display: block; color: #a9d6c0; font-size: 10px; margin-bottom: 4px; }
.hero-meta div b { font-size: 13px; }
.hero-side { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.hero-side .big { font-size: 30px; font-weight: 800; }

.filter-bar { display: flex; gap: 9px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.input, .select {
  border: 1px solid var(--line); background: #fff; border-radius: 9px;
  padding: 9px 11px; font: inherit; font-size: 12px; color: var(--ink); outline: none;
}
.input:focus, .select:focus { border-color: var(--green-2); box-shadow: 0 0 0 3px rgba(47,158,102,.1); }
.input.wide { min-width: 250px; }
.muted { color: var(--muted); }
.mono { font-family: "Cascadia Code", Consolas, monospace; font-size: 11.5px; }
.right { text-align: right; }
.spacer { flex: 1; }

.valve-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 9px; }
.valve {
  border: 1px solid var(--line); border-radius: 11px; padding: 12px 8px; background: #fbfdfc;
  cursor: pointer; text-align: center; transition: .15s;
}
.valve b { display: block; font-size: 15px; }
.valve span { color: var(--muted); font-size: 10px; }
.valve.on { background: var(--green); border-color: var(--green); color: #fff; }
.valve.on span { color: #d8f0e4; }

.plan-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px dashed #edf2ee; }
.plan-row:last-child { border-bottom: 0; }
.plan-name { width: 36px; height: 36px; border-radius: 10px; background: var(--green-soft); color: var(--green); display: grid; place-items: center; font-weight: 800; }
.plan-main { flex: 1; min-width: 0; }
.plan-main b { font-size: 13px; }
.plan-main small { display: block; color: var(--muted); font-size: 10.5px; margin-top: 3px; }

.empty { padding: 26px 10px; text-align: center; color: var(--muted); font-size: 12px; }
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 16px);
  background: #173d2c; color: #fff; padding: 10px 16px; border-radius: 10px;
  font-size: 12px; opacity: 0; pointer-events: none; transition: .2s; z-index: 50;
  box-shadow: 0 10px 30px rgba(0,0,0,.2);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #8f2c22; }

.modal-mask {
  position: fixed; inset: 0; background: rgba(15, 38, 28, .45); z-index: 40;
  display: grid; place-items: center; padding: 20px;
}
.modal {
  width: min(720px, 96vw); background: #fff; border-radius: 18px; box-shadow: 0 30px 80px rgba(0,0,0,.25);
  overflow: hidden;
}
.modal-head { padding: 18px 20px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 18px 20px; max-height: 70vh; overflow: auto; }
.modal-foot { padding: 14px 20px 18px; display: flex; justify-content: flex-end; gap: 9px; border-top: 1px solid var(--line); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.field label { display: block; color: var(--muted); font-size: 11px; margin-bottom: 6px; }
.field .input, .field .select { width: 100%; }
.field.full { grid-column: 1 / -1; }
.week-row { display: flex; gap: 6px; flex-wrap: wrap; }
.week { border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; font-size: 11px; cursor: pointer; background: #fff; }
.week.on { background: var(--green-soft); border-color: #b9dfca; color: var(--green); font-weight: 700; }
.hint { color: var(--muted); font-size: 10.5px; margin-top: 8px; }
.bytes { font-family: Consolas, monospace; color: var(--green); }

.skeleton { padding: 60px; text-align: center; color: var(--muted); }

.login-mask {
  position: fixed; inset: 0; z-index: 80;
  display: grid; place-items: center;
  background:
    radial-gradient(800px 500px at 15% 10%, rgba(47,158,102,.25), transparent 60%),
    linear-gradient(135deg, #0d3326, #14563f 60%, #1f7a4d);
  padding: 20px;
}
.login-card {
  width: min(420px, 96vw); background: #fff; border-radius: 20px;
  padding: 28px; box-shadow: 0 30px 80px rgba(0,0,0,.3);
}
.login-brand { display: flex; gap: 11px; align-items: center; margin-bottom: 22px; }
.login-brand .brand-mark { background: #d9f2e4; color: #14563f; }
.login-brand b { display: block; font-size: 17px; }
.login-brand small { display: block; color: var(--muted); font-size: 10.5px; margin-top: 4px; }
.login-card h2 { margin: 0 0 6px; font-size: 21px; }
.login-card p { margin: 0 0 18px; color: var(--muted); font-size: 11.5px; line-height: 1.6; }
.login-card .field { margin-bottom: 12px; }
.login-card .field label { display: block; color: var(--muted); font-size: 11px; margin-bottom: 6px; }
.login-card .input { width: 100%; }
.login-error { color: var(--red); font-size: 11.5px; min-height: 18px; margin: 6px 0; }
.login-demo { background: var(--green-soft); border: 1px solid #cfe8d9; border-radius: 10px; padding: 10px 12px; color: #246348; font-size: 10.5px; line-height: 1.7; margin-top: 14px; }
.login-card .btn { width: 100%; padding: 11px; margin-top: 2px; }
@media (max-width: 820px) {
  .top-actions .pill { display: none; }
  .login-card { padding: 22px; }
}
@media (max-width: 1100px) {
  .kpis, .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .nav { flex-direction: row; overflow: auto; }
  .nav a { white-space: nowrap; }
  .side-foot { display: none; }
  .topbar { padding: 0 16px; }
  .view { padding: 16px; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}
