:root {
  --bg: #f3f6f4;
  --panel: #ffffff;
  --ink: #1c2320;
  --muted: #75807a;
  --line: #e5ebe7;
  --brand: #1f6b4f;
  --brand-strong: #17543e;
  --brand-soft: #e8f2ed;
  --warn: #b85a1e;
  --warn-soft: #fdf0e7;
  --danger: #b93a2c;
  --danger-soft: #fdecea;
  --sidebar: #0f2a22;
  --sidebar-ink: #cfe4da;
  --shadow: 0 10px 30px rgba(15, 42, 34, 0.08);
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.55;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); font-size: 13px; margin: 8px 0 0; }
code { font-family: Consolas, Menlo, monospace; font-size: 12px; background: #f2f5f3; padding: 2px 6px; border-radius: 6px; word-break: break-all; }

button { font: inherit; cursor: pointer; }
input, select { font: inherit; }

/* ---------------------------------------------------------------- login */
.login-screen {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(1200px 600px at 20% 10%, #2f8a63 0%, #1f6b4f 45%, #0f2a22 100%);
}

.login-card {
  width: min(400px, 100%);
  padding: 36px 32px 28px;
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
}

.login-logo {
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 26px;
  font-weight: 700;
}

.login-card h1 { margin: 18px 0 4px; font-size: 24px; }
.login-card .muted { margin: 0 0 22px; }

.field { margin-bottom: 14px; }
.field span, .field label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 13px; }
.field input, .filters select {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfcfb;
  color: var(--ink);
  outline: none;
}
.field input:focus, .filters select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(31, 107, 79, 0.14); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 38px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font-weight: 500;
  white-space: nowrap;
}
.btn:hover { background: #f5f8f6; }
.btn.primary { border-color: var(--brand); background: var(--brand); color: #fff; width: 100%; height: 42px; }
.btn.primary:hover { background: var(--brand-strong); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.55; cursor: default; }
.link-btn { border: 0; background: none; color: var(--brand); padding: 0; font-size: 13px; }
.link-btn:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- app shell */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 216px;
  flex: none;
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  background: var(--sidebar);
  color: var(--sidebar-ink);
}

.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px 22px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, 0.1); color: #fff; font-weight: 700; font-size: 20px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.3; }
.brand-text strong { color: #fff; font-size: 15px; }
.brand-text span { font-size: 12px; color: rgba(207, 228, 218, 0.72); }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  border: 0; text-align: left; padding: 10px 12px; border-radius: 10px;
  background: transparent; color: var(--sidebar-ink); font-size: 14px;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.07); }
.nav-item.active { background: #1f6b4f; color: #fff; font-weight: 600; }

.sidebar-foot { margin-top: auto; padding: 16px 6px 0; border-top: 1px solid rgba(255, 255, 255, 0.08); }
.conn { display: flex; align-items: center; gap: 7px; font-size: 12px; color: rgba(207, 228, 218, 0.85); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #c9a227; flex: none; }
.dot.online { background: #4fd18b; }
.dot.offline { background: #c05a4d; }
.dot.idle { background: #8a958f; }
.sidebar-foot .muted { color: rgba(207, 228, 218, 0.55); margin-top: 4px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 0 28px 32px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 20px 0 16px; position: sticky; top: 0; z-index: 20;
  background: linear-gradient(var(--bg) 80%, rgba(243, 246, 244, 0));
}
.topbar h1 { margin: 0; font-size: 22px; }
.topbar p { margin: 2px 0 0; }
.topbar-actions { display: flex; gap: 8px; }

.view { display: none; flex-direction: column; gap: 18px; }
.view.active { display: flex; }

/* ---------------------------------------------------------------- overview */
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
@media (max-width: 900px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.stat {
  padding: 16px 18px; border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow);
}
.stat span { display: block; color: var(--muted); font-size: 12px; }
.stat strong { display: block; margin-top: 6px; font-size: 26px; line-height: 1.2; }
.stat strong.warn { color: var(--warn); }
.stat strong.brand { color: var(--brand); }

.split { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 18px; }
.panel { padding: 20px; border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow); min-width: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.panel-head h2 { margin: 0; font-size: 15px; }
.chip { padding: 2px 10px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); font-size: 12px; }

.list { display: flex; flex-direction: column; }
.list-empty { padding: 26px 0; text-align: center; color: var(--muted); font-size: 13px; }

.row-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--line);
}
.row-item:last-child { border-bottom: 0; }
.row-item .grow { flex: 1; min-width: 0; }
.row-item .title { font-weight: 600; font-size: 14px; }
.row-item .meta { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-item .note { color: #4c5651; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge {
  display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; background: #eef1ef; color: #55605a; flex: none;
}
.badge.checkin { background: var(--brand-soft); color: var(--brand); }
.badge.report { background: var(--warn-soft); color: var(--warn); }
.badge.on { background: var(--brand-soft); color: var(--brand); }
.badge.off { background: #eef1ef; color: var(--muted); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }

.lan-list { display: flex; flex-direction: column; gap: 8px; }
.lan-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 12px; border: 1px dashed var(--line); border-radius: 10px; }
.lan-row code { background: transparent; padding: 0; }

/* ---------------------------------------------------------------- map */
.map-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 18px; align-items: stretch; }
.map-wrap { position: relative; min-width: 0; }
.map {
  min-height: 520px;
  height: calc(100vh - 150px);
  border-radius: var(--radius);
  background: #dfe7e2;
  overflow: hidden;
  z-index: 1;
}
.map-hint {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 500;
  max-width: calc(100% - 40px);
  padding: 8px 14px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 6px 18px rgba(15, 42, 34, 0.12);
  color: #4c5651;
  font-size: 12px;
  line-height: 1.5;
  text-align: center;
}
.map-fallback { display: flex; align-items: center; justify-content: center; height: 100%; padding: 40px; text-align: center; color: var(--muted); }
.map-side { padding: 18px; border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow); display: flex; flex-direction: column; min-height: 0; }
.map-users { overflow: auto; max-height: calc(100vh - 240px); }
.map-user { cursor: pointer; }
.map-user:hover { background: #f7faf8; }
.map-side .muted { margin-top: auto; }
.leaflet-popup-content { margin: 12px 14px; font-size: 13px; line-height: 1.6; }
.leaflet-popup-content b { color: var(--ink); }

/* ---------------------------------------------------------------- tables */
.table-wrap { overflow: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 11px 10px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { color: var(--muted); font-weight: 500; font-size: 12px; white-space: nowrap; }
.table td.actions { white-space: nowrap; }
.table .sub { display: block; color: var(--muted); font-size: 12px; }
.table .btn { height: 30px; padding: 0 10px; font-size: 12px; }
.table .btn + .btn { margin-left: 6px; }
.table .btn.danger { border-color: var(--danger-soft); color: var(--danger); background: var(--danger-soft); }
.table .btn.danger:hover { background: #fbdcd8; }

/* ---------------------------------------------------------------- records */
.filters { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.filters select { width: auto; min-width: 130px; }
.record-list { display: flex; flex-direction: column; gap: 14px; }
.record-card { border: 1px solid var(--line); border-radius: 14px; padding: 16px; background: #fcfdfc; }
.record-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.record-head .name { font-weight: 600; }
.record-head .time { color: var(--muted); font-size: 12px; }
.record-meta { margin: 6px 0 0; color: var(--muted); font-size: 12px; }
.record-note { margin: 10px 0 0; color: #39433e; }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.thumbs a { display: block; width: 96px; height: 96px; border-radius: 10px; overflow: hidden; background: #e9efeb; }
.thumbs img { width: 100%; height: 100%; object-fit: cover; display: block; }
.record-actions { display: flex; gap: 8px; margin-top: 12px; }
.record-actions .btn { height: 30px; font-size: 12px; padding: 0 12px; }
.record-actions .btn.danger { border-color: var(--danger-soft); color: var(--danger); background: var(--danger-soft); }

/* ---------------------------------------------------------------- storage */
.field-row { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.field-row > span { color: var(--muted); flex: none; }
.field-row strong, .field-row code { text-align: left; }
.field-row code { display: block; width: 100%; overflow-x: auto; white-space: nowrap; }
.buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
#tile-url { margin-bottom: 8px; }
.kv { display: flex; flex-direction: column; }
.kv .row-item .grow { min-width: 0; }
.kv code { background: transparent; padding: 0; }

/* ---------------------------------------------------------------- toast */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px);
  max-width: min(520px, calc(100vw - 32px));
  padding: 10px 18px; border-radius: 999px; background: #0f2a22; color: #fff;
  font-size: 13px; box-shadow: 0 12px 30px rgba(0, 0, 0, 0.24);
  opacity: 0; pointer-events: none; transition: opacity 0.18s ease, transform 0.18s ease; z-index: 9999;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 1100px) {
  .split { grid-template-columns: 1fr; }
  .map-layout { grid-template-columns: 1fr; }
  .map { height: 56vh; min-height: 380px; }
  .map-users { max-height: 300px; }
}
@media (max-width: 860px) {
  .app { flex-direction: column; }
  .sidebar { width: auto; flex-direction: row; align-items: center; gap: 14px; padding: 12px 14px; overflow-x: auto; }
  .brand { padding: 0; }
  .brand-text span { display: none; }
  .nav { flex-direction: row; }
  .nav-item { white-space: nowrap; padding: 8px 10px; }
  .sidebar-foot { display: none; }
  .main { padding: 0 16px 24px; }
}

/* ---------------------------------------------------------------- user drawer */
.drawer {
  position: fixed;
  inset: 0;
  z-index: 9000;
}
.drawer-mask {
  position: absolute;
  inset: 0;
  background: rgba(15, 42, 34, 0.42);
}
.drawer-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: min(480px, 100%);
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #fff;
  box-shadow: -24px 0 70px rgba(0, 0, 0, 0.24);
}
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  flex: none;
}
.drawer-head h2 { margin: 0; font-size: 16px; }
.drawer-close {
  border: 0;
  background: transparent;
  font-size: 26px;
  line-height: 1;
  color: var(--muted);
  padding: 0 4px;
}
.drawer-close:hover { color: var(--ink); }
.drawer-body {
  padding: 20px 22px 40px;
  overflow-y: auto;
}
.drawer-profile {
  display: flex;
  align-items: center;
  gap: 14px;
}
.avatar-lg {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 20px;
  font-weight: 700;
  flex: none;
}
.drawer-profile h3 { margin: 0; font-size: 18px; }
.drawer-profile .muted { font-size: 12px; }
.drawer-stats {
  display: flex;
  gap: 18px;
  margin: 16px 0 4px;
  padding: 12px 14px;
  border-radius: 12px;
  background: #f7faf8;
  font-size: 13px;
}
.drawer-stats strong { color: var(--brand); }
.drawer-section {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}
.drawer-section h3 { margin: 0 0 10px; font-size: 14px; }
.drawer-section label {
  display: block;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 12px;
}
.drawer-section input[type='text'],
.drawer-section input[type='password'] {
  display: block;
  width: 100%;
  height: 36px;
  margin-top: 5px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fbfcfb;
  color: var(--ink);
  outline: none;
}
.drawer-section input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(31, 107, 79, 0.13);
}
.drawer-section .btn { margin-top: 6px; }
.drawer-section .btn + .btn { margin-left: 8px; }
.drawer-section .inline-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #5c6661;
}
.mini-records { display: flex; flex-direction: column; }
.mini-record {
  display: flex;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}
.mini-record:last-child { border-bottom: 0; }
.mini-record .grow { flex: 1; min-width: 0; }
.mini-record .meta { color: var(--muted); white-space: nowrap; }
.btn.danger {
  border-color: var(--danger-soft);
  color: var(--danger);
  background: var(--danger-soft);
}
.btn.danger:hover { background: #fbdcd8; }

