*, *::before, *::after { box-sizing: border-box; }
:root {
  --bg: #f3f6f9;
  --surface: #ffffff;
  --border: #d9e2ec;
  --text: #102a43;
  --muted: #52606d;
  --primary: #0f766e;
  --primary-hover: #115e59;
  --danger: #b91c1c;
  --warn-bg: #fffbeb;
  --warn-bd: #f59e0b;
  --warn-tx: #92400e;
  --info-bg: #eff6ff;
  --info-bd: #3b82f6;
  --info-tx: #1e40af;
  --danger-bg: #fef2f2;
  --danger-bd: #ef4444;
  --danger-tx: #991b1b;
  --ok-bg: #ecfdf5;
  --ok-tx: #065f46;
  --radius: 10px;
}
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  overflow-x: hidden;
}
.hidden { display: none !important; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.small { font-size: 12px; }
.muted { color: var(--muted); }
.center { text-align: center; }

.topbar {
  background: #0f172a;
  color: #f8fafc;
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid #1e293b;
}
.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 10px 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #14b8a6;
  box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.25);
  flex-shrink: 0;
}
.brand-title { margin: 0; font-size: 16px; font-weight: 600; line-height: 1.25; }
.user-bar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.user-chip { font-size: 12px; color: #e2e8f0; }

.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 12px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.auth-card { max-width: 400px; margin: 28px auto; }
.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.card-head h2, .card-head h3 { margin: 0; font-size: 15px; font-weight: 600; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-demo { background: #fef3c7; color: #92400e; margin-top: 2px; }
.badge-ok { background: var(--ok-bg); color: var(--ok-tx); }
.badge-warn { background: var(--warn-bg); color: var(--warn-tx); }
.badge-danger { background: var(--danger-bg); color: var(--danger-tx); }
.badge-info { background: var(--info-bg); color: var(--info-tx); }
.badge-muted { background: #e2e8f0; color: #334155; }

.alert {
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid transparent;
  margin: 8px 0;
  font-size: 13px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.alert-warn { background: var(--warn-bg); border-color: var(--warn-bd); color: var(--warn-tx); }
.alert-danger { background: var(--danger-bg); border-color: var(--danger-bd); color: var(--danger-tx); }
.alert-info { background: var(--info-bg); border-color: var(--info-bd); color: var(--info-tx); }
.alert-ok { background: var(--ok-bg); border-color: #10b981; color: var(--ok-tx); }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field span { font-size: 12px; color: var(--muted); font-weight: 500; }
.field input, .field select, .date-controls input {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
  color: var(--text);
}
.field input:disabled, .field select:disabled { background: #f1f5f9; color: #64748b; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-sm { min-height: 32px; padding: 0 10px; font-size: 12px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warn { background: #d97706; color: #fff; }
.btn-outline { background: #fff; color: var(--text); border-color: #cbd5e1; }
.btn-ghost { background: transparent; color: #cbd5e1; border-color: #334155; }
.action-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

.selector-group { margin-bottom: 10px; }
.selector-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; font-weight: 500; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 38px;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.chip.empty-chip { border-style: dashed; color: #64748b; }
.chip-cnt {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.08);
}
.chip.active .chip-cnt { background: rgba(255, 255, 255, 0.22); }

.summary-box {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-top: 8px;
}
.summary-line { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; }
.device-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.dev-tag {
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 6px;
  background: #e2e8f0;
  color: #1e293b;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}
.kpi-box {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}
.kpi-label { font-size: 12px; color: var(--muted); }
.kpi-val { font-size: 18px; font-weight: 700; margin: 2px 0; }
.kpi-sub { font-size: 12px; color: var(--muted); word-break: break-all; }

.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 580px;
  font-size: 13px;
}
.data-table th, .data-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #e2e8f0;
  text-align: left;
  white-space: nowrap;
}
.data-table th { background: #f8fafc; color: var(--muted); font-weight: 600; }
.data-table tr:last-child td { border-bottom: none; }
.val-unknown { color: #b45309; font-weight: 600; }
.val-zero { color: #0f766e; font-weight: 600; }

.toggle-inline { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.date-controls { display: flex; align-items: center; gap: 6px; }
.date-controls input { width: auto; min-height: 32px; padding: 4px 8px; font-size: 13px; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}
.modal-card {
  width: 100%;
  max-width: 380px;
  background: #fff;
  border-radius: var(--radius);
  padding: 16px;
}
