:root {
  --bg: #f3f7f4;
  --surface: #ffffff;
  --text: #1c2b24;
  --muted: #6d7d74;
  --green: #1f9a58;
  --green-soft: #e8f6ee;
  --line: #e3eee6;
  --shadow: 0 10px 28px rgba(36, 74, 48, .08);
  --radius: 18px;
  --red: #e15b5b;
  --amber: #c78412;
  --font: "Segoe UI", "Microsoft YaHei UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; max-width: 100%; overflow-x: clip; }
body {
  font-family: var(--font);
  font-size: 14px;
  font-weight: 400;
  line-height: 1.5;
  background:
    radial-gradient(circle at 0 0, rgba(190, 230, 205, .45), transparent 28%),
    var(--bg);
  color: var(--text);
}
h1, h2, h3 {
  margin: 0 0 12px;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.4;
}
button, input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  font-weight: 400;
  line-height: 1.5;
  color: inherit;
}
button { cursor: pointer; }
.hidden { display: none !important; }

#login-view {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 20px 16px;
}
.login-card {
  width: min(420px, 100%);
  background: var(--surface);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 28px 22px 20px;
}
.login-head { text-align: center; margin-bottom: 18px; }
.login-logo { display: block; width: 220px; max-width: 78%; height: auto; margin: 0 auto 10px; }
.login-head:not(:has(.login-logo)) h1 { margin-top: 0; }
.login-card h1 { margin: 6px 0 0; }
.login-card label { display: block; margin-bottom: 12px; color: var(--muted); font-size: 12px; }
.login-card input, .field input, .field select, .toolbar input, .search input, .row input, .row select {
  display: block; width: 100%; max-width: 100%; min-width: 0; margin-top: 6px; padding: 12px 14px;
  background: #f7fbf8; border: 1px solid #d7e6dc; border-radius: 12px;
}
.login-card input:focus, .field input:focus, .field select:focus, .toolbar input:focus, .search input:focus, .row input:focus, .row select:focus {
  outline: 2px solid rgba(31, 154, 88, .25); border-color: var(--green);
}
.login-card .btn { width: 100%; min-height: 46px; margin-top: 4px; }
.login-error { min-height: 22px; color: var(--red); margin-top: 8px; }
.login-hint {
  margin-top: 12px; padding: 12px; border-radius: 14px; background: var(--green-soft);
  color: #3d624c; line-height: 1.6;
}

.brand-mark {
  width: 44px; height: 44px; border-radius: 14px;
  display: grid; place-items: center;
  background: var(--green); color: white; font-size: 14px; font-weight: 600;
}
#app-view, .main, #page, .panel, .dash, .metrics, .cards, .split, .toolbar, .row, .search, .chart {
  min-width: 0;
  max-width: 100%;
}
#app-view { min-height: 100dvh; padding-bottom: calc(86px + env(safe-area-inset-bottom)); }
.mask { position: fixed; inset: 0; background: rgba(24, 46, 32, .38); z-index: 25; }
.nav {
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 30;
  width: min(86vw, 320px);
  background: #fff;
  padding: 16px 12px 24px;
  overflow: auto;
  transform: translateX(-105%);
  transition: transform .22s ease;
  box-shadow: var(--shadow);
}
body.drawer-open .nav { transform: none; }
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 8px 16px; }
.brand strong { display: block; font-size: 14px; font-weight: 600; overflow-wrap: anywhere; }
.brand small { color: var(--muted); font-size: 12px; }
.nav-item {
  width: 100%; text-align: left; background: transparent; border: 0;
  color: #31443a; padding: 8px 10px; margin: 2px 0; border-radius: 12px;
  font-size: 14px; font-weight: 400;
  display: flex; align-items: center; gap: 8px;
}
.nav-item.sub { color: #5d7266; }
.nav-item .nav-text { flex: 1 1 auto; min-width: 0; text-align: left; }
.nav-item.active { background: var(--green-soft); color: #157a44; font-weight: 600; }
.ico {
  width: 22px; height: 22px; flex: 0 0 22px;
  display: grid; place-items: center; border-radius: 7px;
  background: var(--bg, #eef6f1);
}
.ico svg { width: 14px; height: 14px; display: block; }
.nav-label { margin: 16px 12px 4px; color: #8aa093; font-size: 12px; }
.nav-fold-btn {
  width: 100%; text-align: left; background: transparent; border: 0;
  color: #31443a; padding: 8px 10px; margin: 2px 0; border-radius: 12px;
  font-size: 14px; display: flex; align-items: center; gap: 8px;
}
.nav-fold-btn .nav-text { flex: 1 1 auto; min-width: 0; text-align: left; }
.nav-fold-body { display: none; }
.nav-fold.open .nav-fold-body { display: block; }
.nav-fold-body .nav-item { padding-left: 18px; }
.chev {
  width: 7px; height: 7px; flex: 0 0 7px; margin-right: 4px;
  border-right: 1.5px solid #8aa093; border-bottom: 1.5px solid #8aa093;
  transform: rotate(-45deg); transition: transform .16s ease;
}
.nav-fold.open .chev { transform: rotate(45deg); margin-top: -2px; }
.nav-logout { width: 100%; margin-top: 16px; display: flex; align-items: center; justify-content: flex-start; gap: 8px; padding-left: 10px; }
.house-list { display: grid; gap: 10px; margin-top: 14px; }
.house-card { display: grid; gap: 8px; }
.house-card .row input { flex: 1 1 160px; margin-top: 0; }
.badge {
  display: inline-block; min-width: 18px; padding: 0 6px; margin-left: 4px;
  background: var(--red); color: white; border-radius: 999px; font-style: normal; font-size: 12px; font-weight: 600; }
}
.main { min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; flex-wrap: wrap; gap: 10px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, .9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.top-title { min-width: 0; flex: 1; }
#house-name { display: block; font-size: 18px; font-weight: 600; line-height: 1.4; }
.pills, .top-right { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.pills { margin-top: 4px; }
.top-right { justify-content: flex-end; }
#clock, #who { color: var(--muted); font-size: 12px; }
#clock { font-variant-numeric: tabular-nums; }
.icon-btn {
  width: 40px; height: 40px; border: 0; border-radius: 12px; background: var(--green-soft);
  display: grid; gap: 4px; place-content: center; flex: 0 0 auto;
}
.icon-btn span { display: block; width: 16px; height: 2px; background: #1f7a48; border-radius: 2px; }
.pill {
  border-radius: 999px; padding: 3px 8px; font-size: 12px;
  background: #eef3f0; color: #5d7266;
}
.pill.ok { background: #e7f7ee; color: #157a44; }
.pill.warn { background: #fff6e4; color: #9a6410; }
.pill.bad { background: #ffefef; color: #c44747; }
#page { padding: 14px 12px 20px; }

.panel, .metric, .device-card, .chart {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 20px rgba(40, 80, 50, .04);
}
.panel { padding: 14px; }
#page > h2, .panel h2 { margin: 0 0 12px; }
.dash, .cards, .split { display: grid; gap: 12px; }
.dash-meta { margin: 0; color: var(--muted); font-size: 12px; }
.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.metric { padding: 12px 14px; }
.metric .k { color: var(--muted); font-size: 12px; }
.metric .v {
  margin-top: 2px;
  font-size: 20px; line-height: 1.3; font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.metric .u { font-size: 12px; color: var(--muted); margin-left: 2px; font-weight: 400; }
.metric .sub { margin-top: 4px; color: #7d9186; font-size: 12px; }
.metric.bad { background: #fff6f6; border-color: #f3c7c7; }
button.metric {
  width: 100%; text-align: left; font: inherit; color: inherit; cursor: pointer;
}
.metric-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.metric-head .k { min-width: 0; }
.metric-link:hover { border-color: #b7dcc8; }
.metric-link:focus-visible { outline: 2px solid #1f9a58; outline-offset: 2px; }
.status-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.status-grid .metric { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.status-grid .pill { margin-top: 0; }
.circuit-list { display: grid; }
.circuit {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 0; border-top: 1px solid var(--line);
}
.circuit:first-child { border-top: 0; padding-top: 0; }
.circuit-name { font-size: 14px; line-height: 1.4; }
.circuit-spec { font-size: 12px; color: var(--muted); }
.circuit .pill { flex: 0 0 auto; }
.dash > .btn { justify-self: start; }

.btn {
  background: #fff; color: #245c3c; border: 1px solid #cfe3d6;
  border-radius: 12px; padding: 8px 14px; min-height: 40px; white-space: nowrap;
}
.search .btn { flex: 0 0 auto; }
.btn:hover { background: #f4fbf7; }
.btn.primary { background: var(--green); color: white; border-color: var(--green); }
.btn.danger { background: #fff; color: #c44747; border-color: #f0c4c4; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.big { min-height: 44px; min-width: 88px; }
.device-card { display: flex; flex-direction: column; gap: 8px; padding: 14px; }
.device-card h3 { margin: 0; font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.lamp { width: 10px; height: 10px; border-radius: 50%; background: #c9d5ce; display: inline-block; }
.lamp.run { background: #22a35f; box-shadow: 0 0 0 4px rgba(34, 163, 95, .15); }
.lamp.stop { background: #c5cfc8; }
.lamp.fault { background: var(--red); box-shadow: 0 0 0 4px rgba(225, 91, 91, .15); }
.state-lg { font-size: 14px; font-weight: 600; line-height: 1.4; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; margin-bottom: 12px; }
.toolbar label { color: var(--muted); font-size: 12px; display: flex; flex-direction: column; gap: 4px; flex: 1 1 100%; min-width: 0; }
.toolbar input { margin-top: 0; width: 100%; }
.chart { width: 100%; height: 320px; padding: 8px; overflow: hidden; }
.stats span { max-width: 100%; overflow-wrap: anywhere; }
.stats { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.stats span {
  background: white; border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 10px; color: #4d6458; font-size: 12px;
}
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { border-bottom: 1px solid #edf3ef; padding: 10px 8px; text-align: left; font-weight: 400; }
th { color: var(--muted); font-weight: 600; background: #f7fbf8; }
td.wrap { white-space: normal; word-break: break-word; }
.table-wrap { width: 100%; max-width: 100%; overflow-x: auto; }
table { min-width: 0; }
.alarm-list { display: grid; gap: 10px; }
.alarm-item {
  background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px;
}
.alarm-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 14px; }
.alarm-head strong { font-weight: 600; }
.alarm-item p { margin: 8px 0; line-height: 1.5; }
.alarm-item .alarm-meta { color: var(--muted); font-size: 12px; }
.alarm-item .btn { margin-top: 10px; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; flex-wrap: wrap; margin-top: 10px; color: var(--muted); }
.field { margin-bottom: 12px; }
.field span { display: block; color: var(--muted); font-size: 12px; }
.note {
  color: #8a5a10; background: #fff8e8; border-radius: 12px; padding: 10px 12px; line-height: 1.5;
}
.help h3 { margin: 18px 0 6px; font-size: 14px; }
.help p, .help li { color: #31443a; line-height: 1.75; }
.help code { color: #157a44; }
.search { display: flex; gap: 8px; margin-bottom: 10px; }
.search input { flex: 1 1 auto; margin-top: 0; min-width: 0; }
.help, .note, p, li, code { overflow-wrap: anywhere; }
.tag-open { color: #c44747; }
.tag-ack { color: #157a44; }
.loading, .error { padding: 28px 8px; color: var(--muted); }
.error { color: var(--red); }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.grow { flex: 1; }
.muted { color: var(--muted); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: rgba(255, 255, 255, .96);
  border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tabbar button {
  border: 0; background: transparent; color: #7b8d82; font-size: 11px; font-weight: 400;
  padding: 4px 0; border-radius: 12px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; line-height: 1.2;
}
.tabbar .nav-text { display: inline-flex; align-items: center; gap: 2px; }
.tabbar button.active { color: var(--green); font-weight: 600; background: var(--green-soft); }

.modal {
  position: fixed; inset: 0; background: rgba(24, 46, 32, .4);
  display: grid; place-items: end center; z-index: 40; padding: 16px;
}
.modal-card {
  width: min(460px, 100%); background: white; border-radius: 24px;
  padding: 18px; box-shadow: var(--shadow); margin-bottom: 8px;
}
.modal-card.danger { border: 1px solid #f3c7c7; }
.modal-kicker { color: var(--green); font-size: 12px; font-weight: 600; }
.modal-card.danger .modal-kicker { color: var(--red); }
.modal-card h3 { margin: 8px 0; }
.modal-card p { margin: 0 0 8px; line-height: 1.5; }
.modal-meta { color: var(--muted); font-size: 12px; margin-bottom: 14px; }
.modal-actions { display: flex; gap: 8px; }
.modal-actions .btn { flex: 1; }
.toast {
  position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #1c2b24; color: white; border-radius: 999px; padding: 10px 16px;
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; }
.toast.bad { background: #a33d3d; }

@media (min-width: 900px) {
  .alarm-list { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 720px) {
  .cards { grid-template-columns: 1fr 1fr; }
  .chart { height: 420px; }
}
@media (min-width: 960px) {
  #app-view {
    display: grid;
    grid-template-columns: 248px minmax(0, 1fr);
    padding-bottom: 0;
  }
  .nav {
    position: sticky; top: 0; transform: none; width: auto; height: 100dvh;
    box-shadow: none; border-right: 1px solid var(--line);
  }
  .tabbar, #menu-btn, .mask { display: none !important; }
  .metrics { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .circuit-list { grid-template-columns: 1fr 1fr; column-gap: 28px; }
  .circuit:nth-child(2) { border-top: 0; padding-top: 0; }
  .toast { bottom: 24px; }
  .modal { place-items: center; }
}
@media (min-width: 1100px) {
  .cards { grid-template-columns: 1fr 1fr 1fr; }
  .split { grid-template-columns: 340px minmax(0, 1fr); }
  .chart { height: 480px; }
}
@media (min-width: 721px) {
  .toolbar label { flex-basis: 220px; }
}
@media (max-width: 720px) {
  #who, #full { display: none; }
  .toolbar { display: grid; grid-template-columns: 1fr 1fr; }
  .toolbar label { grid-column: 1 / -1; }
  .toolbar .btn { width: 100%; min-width: 0; }
  .row > h2, .row > input, .row > select, .row > .btn:not(.big) { flex: 1 1 100%; width: 100%; }
  .row:has(.btn.big) { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .btn.big { min-width: 0; width: 100%; padding-left: 8px; padding-right: 8px; }
  .table-wrap { overflow: visible; }
  table, tbody, tr, td { display: block; width: auto; min-width: 0; }
  thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  tr {
    background: #f7fbf8;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 8px 12px;
    margin-bottom: 8px;
  }
  td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    border: 0;
    padding: 6px 0;
  }
  td::before {
    content: attr(data-label);
    color: var(--muted);
    flex: 0 0 5.5em;
  }
  td[data-label=""]::before { content: none; }
  td.wrap { display: block; }
  td.wrap::before { display: block; margin-bottom: 2px; }
  td input, td select { flex: 1 1 auto; width: auto; min-width: 0; margin-top: 0; }
}
