:root {
  --bg: #eef2ef;
  --panel: #ffffff;
  --ink: #14261f;
  --muted: #5a6d64;
  --line: #d5ddd7;
  --line-strong: #b8c5bc;
  --leaf: #2a684c;
  --leaf-deep: #163d2d;
  --leaf-soft: #e8f2ec;
  --warn: #c47a12;
  --warn-bg: #fff6e8;
  --danger: #c0352b;
  --danger-bg: #fdeceb;
  --ok: #1b7a4a;
  --ok-bg: #e7f6ee;
  --info: #2b6cb0;
  --shadow: 0 8px 24px rgba(16, 42, 31, 0.07);
  --radius: 12px;
  --sidebar: 232px;
  --sans: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --serif: "Songti SC", "STSong", "Noto Serif SC", serif;
  --topbar-h: 64px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.5;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--leaf); outline-offset: 2px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 34px;
  padding: 0.4rem 0.85rem;
  border: 1px solid transparent;
  border-radius: 8px;
  background: #fff;
  white-space:nowrap;
  transition: 0.12s ease;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--leaf-deep); color: #f3f7f4; }
.btn-primary:hover:not(:disabled) { background: var(--leaf); }
.btn-ghost { border-color: var(--line); background: #fff; }
.btn-ghost:hover:not(:disabled) { background: var(--leaf-soft); }
.btn-danger { background: var(--danger-bg); color: var(--danger); border-color: #f0c4c0; }
.btn-danger:hover:not(:disabled) { background: #fadad7; }
.btn-text { border: 0; background: transparent; color: var(--leaf); padding-inline: 0.4rem; min-height: 28px; }
.btn-text.danger { color: var(--danger); }
.btn-sm { min-height: 28px; padding: 0.2rem 0.55rem; font-size: 12px; }
.btn-block { width: 100%; }

.field {
  display: grid;
  gap: 0.3rem;
}
.field > span { color: var(--muted); font-size: 12px; }
.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 36px;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.field textarea { min-height: 84px; resize: vertical; }
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

/* Login */
.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  position: relative;
  background:
    radial-gradient(ellipse at 15% 0%, rgba(42,104,76,.16), transparent 42%),
    linear-gradient(165deg, #e7eee8, #f5f3ee 50%, #e4ebe5);
}
.login-card {
  width: min(440px, 100%);
  padding: 2rem 1.7rem 1.4rem;
  background: rgba(255,255,255,.95);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.login-brand { margin: 0; color: var(--leaf); letter-spacing: .16em; font-size: 12px; }
.login-card h1 {
  margin: .45rem 0 .3rem;
  font-family: var(--serif);
  font-size: 1.8rem;
  color: var(--leaf-deep);
}
.login-lead { margin: 0 0 0.65rem; color: var(--muted); }
.login-entry {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  justify-content: center;
  margin: 0 0 1.1rem;
  font-size: 0.86rem;
  color: var(--muted);
}
.login-entry a { color: var(--leaf); text-decoration: none; }
.login-entry a:hover { text-decoration: underline; }

.simple-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.75rem;
}
.simple-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-end;
  gap: 0.3rem;
  min-height: 96px;
  padding: 0.9rem 1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  text-align: left;
  cursor: pointer;
}
.simple-card:hover { border-color: var(--leaf); background: var(--leaf-soft); }
.simple-card b { font-size: 15px; }
.simple-card span { color: var(--muted); font-size: 12px; }
.login-card label { display: grid; gap: .3rem; margin-bottom: .85rem; }
.login-card label span { font-size: 12px; color: var(--muted); }
.login-card input {
  width: 100%;
  padding: .7rem .8rem;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.form-error { margin: 0 0 .7rem; color: var(--danger); font-size: 13px; }
.demo-accounts { margin-top: 1rem; color: var(--muted); font-size: 12px; }
.demo-accounts ul { margin: .5rem 0 0; padding-left: 1.1rem; }
.demo-accounts li + li { margin-top: .2rem; }

/* Shell */
.app-body {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar) 1fr;
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #143628, #1a4634 55%, #123024);
  color: #e7efe9;
  padding: .9rem .7rem;
  z-index: 40;
}
.sidebar-brand {
  padding: .45rem .55rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.1);
  margin-bottom: .65rem;
}
.sidebar-brand strong {
  display: block;
  font-family: var(--serif);
  font-size: 1.05rem;
}
.sidebar-brand span {
  display: block;
  margin-top: .2rem;
  font-size: 11px;
  opacity: .7;
}
.side-nav { display: grid; gap: .2rem; flex: 1; overflow: auto; }
.nav-group {
  margin: .55rem .45rem .2rem;
  font-size: 11px;
  letter-spacing: .08em;
  opacity: .45;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: .5rem;
  width: 100%;
  padding: .62rem .7rem;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  text-align: left;
}
.nav-item:hover { background: rgba(255,255,255,.08); }
.nav-item.is-active { background: rgba(255,255,255,.15); }
.nav-item .ico { width: 1.2rem; text-align: center; opacity: .9; font-size: 12px; }
.sidebar-user {
  margin-top: auto;
  padding: .75rem .55rem .25rem;
  border-top: 1px solid rgba(255,255,255,.1);
  font-size: 12px;
}
.sidebar-user b { display: block; margin-bottom: .15rem; font-size: 13px; }
.sidebar-user span { opacity: .7; }

.app-main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .75rem 1.1rem;
  background: rgba(255,255,255,.9);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 30;
  backdrop-filter: blur(10px);
}
.menu-btn {
  display: none;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.topbar-title { flex: 1; min-width: 0; }
.topbar-title h1 {
  margin: 0;
  font-size: 1.1rem;
  font-family: var(--serif);
  color: var(--leaf-deep);
}
.topbar-title p { margin: .1rem 0 0; color: var(--muted); font-size: 12px; }
.topbar-actions { display: flex; align-items: center; gap: .5rem; }
.role-pill {
  padding: .25rem .65rem;
  border-radius: 999px;
  background: var(--leaf-soft);
  color: var(--leaf-deep);
  font-size: 12px;
}
.content { padding: 1rem 1.1rem 2rem; }

/* Enterprise blocks */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0,1fr));
  gap: .75rem;
  margin-bottom: .9rem;
}
.kpi {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .85rem .9rem;
  box-shadow: var(--shadow);
}
.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .value {
  margin-top: .25rem;
  font-family: var(--serif);
  font-size: 1.45rem;
  color: var(--leaf-deep);
  letter-spacing: -.02em;
}
.kpi .sub { margin-top: .2rem; font-size: 11px; color: var(--muted); }
.kpi.warn .value { color: var(--warn); }
.kpi.danger .value { color: var(--danger); }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: .9rem;
  overflow: hidden;
}
.panel-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: .8rem 1rem;
  border-bottom: 1px solid var(--line);
}
.panel-hd h2 {
  margin: 0;
  font-size: 15px;
  font-family: var(--serif);
  color: var(--leaf-deep);
}
.panel-bd { padding: .9rem 1rem 1rem; }
.panel-bd.flush { padding: 0; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  align-items: center;
  margin-bottom: .75rem;
}
.toolbar .spacer { flex: 1; }
.search-box,
.filter-select {
  min-height: 34px;
  padding: .35rem .65rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  min-width: 160px;
}
.search-box { min-width: 220px; }

.tabs {
  display: flex;
  gap: .25rem;
  flex-wrap: wrap;
  margin-bottom: .75rem;
}
.tab {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: .3rem .7rem;
  font-size: 12px;
  color: var(--muted);
}
.tab.is-active {
  background: var(--leaf-deep);
  border-color: var(--leaf-deep);
  color: #fff;
}

.table-wrap { overflow: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.data th,
table.data td {
  padding: .7rem .85rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}
table.data th {
  position: sticky;
  top: 0;
  background: #f7faf7;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  z-index: 1;
}
table.data td { white-space: nowrap; }
table.data tr:hover td { background: #f7faf8; }
table.data .ops {
  display: flex;
  gap: .15rem;
  justify-content: flex-end;
}
.col-ops { width: 1%; text-align: right; }

.tag {
  display: inline-flex;
  align-items: center;
  padding: .12rem .45rem;
  border-radius: 999px;
  font-size: 11px;
  background: #eef2ef;
  color: var(--muted);
}
.tag.ok { background: var(--ok-bg); color: var(--ok); }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.danger { background: var(--danger-bg); color: var(--danger); }
.tag.info { background: #e8f1fb; color: var(--info); }

.split-2 {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: .9rem;
}
.split-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .9rem;
}

.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain li {
  display: grid;
  grid-template-columns: 8px 1fr auto;
  gap: .65rem;
  align-items: start;
  padding: .7rem 0;
  border-bottom: 1px solid var(--line);
}
.list-plain li:last-child { border-bottom: 0; }
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: .4rem;
  background: var(--warn);
}
.dot.danger { background: var(--danger); }
.dot.ok { background: var(--ok); }
.dot.info { background: var(--info); }

.sensor-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .85rem;
  background: #fbfcfb;
}
.sensor-card h3 {
  margin: 0 0 .65rem;
  font-size: 14px;
  display: flex;
  justify-content: space-between;
  gap: .5rem;
  align-items: center;
}
.meter { margin-bottom: .55rem; }
.meter label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  margin-bottom: .2rem;
  color: var(--muted);
}
.bar {
  height: 7px;
  border-radius: 999px;
  background: #e5ece7;
  overflow: hidden;
}
.bar > i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--leaf-deep), #5f9a78);
}

.cam-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .75rem;
}
.cam-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #0f1f18;
}
.cam-view {
  aspect-ratio: 16/10;
  display: grid;
  place-items: center;
  color: rgba(255,255,255,.75);
  background:
    linear-gradient(135deg, rgba(42,104,76,.4), rgba(10,24,18,.92)),
    repeating-linear-gradient(0deg, transparent, transparent 10px, rgba(255,255,255,.03) 11px);
  font-size: 12px;
}
.cam-view.off { background: #1a1f1c; color: #8a9390; }
.cam-meta { padding: .65rem .75rem; background: #fff; }
.cam-meta strong { display: block; font-size: 13px; }
.cam-meta span { color: var(--muted); font-size: 11px; }

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: .7rem .9rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}
.pager-btns { display: flex; gap: .35rem; }

.empty {
  padding: 2.5rem 1rem;
  text-align: center;
  color: var(--muted);
}
.empty b { display: block; margin-bottom: .35rem; color: var(--ink); }

/* Drawer / Modal */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(12, 28, 22, .42);
  z-index: 80;
  display: grid;
  justify-items: end;
}
.overlay.center { place-items: center; justify-items: center; }
.drawer {
  width: min(440px, 100vw);
  height: 100%;
  background: #fff;
  box-shadow: -12px 0 40px rgba(0,0,0,.12);
  display: flex;
  flex-direction: column;
  animation: slideIn .18s ease;
}
@keyframes slideIn {
  from { transform: translateX(18px); opacity: .6; }
  to { transform: none; opacity: 1; }
}
.drawer-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--line);
}
.drawer-hd h3 { margin: 0; font-size: 16px; font-family: var(--serif); color: var(--leaf-deep); }
.drawer-bd {
  flex: 1;
  overflow: auto;
  padding: 1rem 1.1rem;
  display: grid;
  gap: .75rem;
  align-content: start;
}
.drawer-ft {
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
  padding: .85rem 1.1rem;
  border-top: 1px solid var(--line);
  background: #fafcfa;
}
.modal {
  width: min(420px, calc(100vw - 2rem));
  background: #fff;
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.modal-hd {
  padding: 1rem 1.1rem .2rem;
  font-family: var(--serif);
  font-size: 16px;
  color: var(--leaf-deep);
}
.modal-bd { padding: .5rem 1.1rem 1rem; color: var(--muted); line-height: 1.6; }
.modal-ft {
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
  padding: .75rem 1.1rem 1rem;
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 100;
  max-width: min(360px, calc(100vw - 2rem));
  padding: .7rem .95rem;
  background: var(--leaf-deep);
  color: #fff;
  border-radius: 8px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  transition: .18s ease;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: none; }
.toast.err { background: #8f2b24; }

.detail-grid {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: .45rem .75rem;
  font-size: 13px;
}
.detail-grid dt { color: var(--muted); }
.detail-grid dd { margin: 0; }

.chart-bars {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: .45rem;
  align-items: end;
  height: 120px;
  margin-top: .5rem;
}
.chart-bars .c {
  display: grid;
  gap: .25rem;
  align-content: end;
  height: 100%;
}
.chart-bars .c i {
  display: block;
  border-radius: 4px 4px 0 0;
  background: linear-gradient(180deg, #5f9a78, var(--leaf-deep));
  min-height: 4px;
}
.chart-bars .c span {
  text-align: center;
  font-size: 10px;
  color: var(--muted);
}

.sidebar-mask {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10,24,18,.35);
  z-index: 35;
}

@media (max-width: 1200px) {
  .kpi-row { grid-template-columns: repeat(3, 1fr); }
  .split-2, .split-3, .cam-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 860px) {
  .app-body { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    left: 0; top: 0;
    width: min(86vw, 280px);
    transform: translateX(-105%);
    transition: transform .2s ease;
  }
  .sidebar.is-open { transform: none; }
  .menu-btn { display: inline-grid; place-items: center; }
  .sidebar-mask.is-on { display: block; }
  .kpi-row, .split-2, .split-3, .cam-grid, .field-row { grid-template-columns: 1fr; }
  .role-pill { display: none; }
  .search-box { min-width: 140px; width: 100%; }
}
