* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* hidden 属性全局生效：防止 .modal/.login-wrap 等 display 规则覆盖默认的 [hidden]{display:none} */
[hidden] {
  display: none !important;
}

:root {
  --bg: #0a0e14;
  --bg-card: #11161f;
  --bg-card-2: #161d28;
  --border: #1f2937;
  --text: #e6edf3;
  --text-secondary: #8b949e;
  --text-dim: #57606a;
  --green: #00e676;
  --blue: #4f8cff;
  --cyan: #38bdf8;
  --orange: #f5a623;
  --red: #ef4444;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  min-height: 100vh;
}

/* 登录 */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 32px;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.login-title {
  font-size: 20px;
  text-align: center;
  margin-bottom: 8px;
}
.input {
  height: 44px;
  background: var(--bg-card-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0 14px;
  font-size: 15px;
  outline: none;
}
.input:focus {
  border-color: var(--green);
}
.login-error {
  color: var(--red);
  font-size: 13px;
  min-height: 18px;
}

/* 按钮 */
.btn {
  height: 44px;
  border-radius: 8px;
  border: none;
  font-size: 15px;
  cursor: pointer;
}
.btn-primary {
  background: var(--green);
  color: #0a0e14;
  font-weight: 600;
}
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: 0 16px;
  height: 36px;
  font-size: 13px;
}

/* 主界面 */
.main {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-title {
  font-size: 18px;
  font-weight: 600;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}
.topbar-user {
  color: var(--text-secondary);
  font-size: 14px;
}

.content {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

/* 概要统计 */
.summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}
.stat {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.stat-k {
  font-size: 13px;
  color: var(--text-secondary);
}
.stat-v {
  font-size: 30px;
  font-weight: 700;
  font-family: 'DIN Alternate', 'Roboto Mono', monospace;
}
.stat-alarm .stat-v {
  color: var(--red);
}

/* 工具栏 */
.toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
}
.search-input {
  flex: 1;
  max-width: 360px;
}
.filter-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
}
.filter-toggle input {
  accent-color: var(--green);
}

/* 地图 */
.map {
  height: 320px;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg-card-2);
  /* 像 Excel 冻结窗口：向下滚动设备列表时，地图固定在顶栏下方保持可见（z-index 低于 topbar 的 10） */
  position: sticky;
  top: 68px;
  z-index: 5;
}
.map-fallback {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 13px;
}

.section-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
}
.section-title {
  font-size: 16px;
  font-weight: 600;
}
.section-sub {
  font-size: 13px;
  color: var(--text-secondary);
}

/* 设备列表（按客户代码分组） */
.devices {
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.customer-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.customer-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.customer-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--cyan);
}
.customer-count {
  font-size: 12px;
  color: var(--text-dim);
}
.customer-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}
.device-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.device-card:hover {
  border-color: var(--blue);
}
.device-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.device-head-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.device-del {
  background: transparent;
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: var(--red);
  border-radius: 6px;
  font-size: 12px;
  padding: 2px 10px;
  cursor: pointer;
}
.device-del:hover {
  background: rgba(239, 68, 68, 0.12);
}
.device-serial {
  font-weight: 600;
  font-size: 15px;
}
.badge-alarm {
  color: var(--red);
  background: rgba(239, 68, 68, 0.12);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
}
/* 定位来源标签：GPS（蓝）/ 基站（橙） */
.loc-src {
  display: inline-block;
  font-style: normal;
  font-size: 10px;
  line-height: 1;
  border-radius: 4px;
  padding: 2px 5px;
  margin-right: 4px;
  vertical-align: 1px;
}
.loc-src-gps { color: #38bdf8; background: rgba(56, 189, 248, 0.14); }
.loc-src-lbs { color: #f5a623; background: rgba(245, 166, 35, 0.14); }
.device-name {
  color: var(--text-secondary);
  font-size: 13px;
}
.device-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.metric {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
  background: var(--bg-card-2);
  border-radius: 8px;
  padding: 10px 4px;
}
.m-k {
  font-size: 11px;
  color: var(--text-dim);
}
.m-v {
  font-size: 15px;
  font-weight: 600;
  font-family: 'DIN Alternate', 'Roboto Mono', monospace;
}
.device-status {
  font-size: 13px;
}
.device-foot {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--text-dim);
}
.device-foot .loc {
  flex: 1;
  min-width: 0;
  line-height: 1.4;
  word-break: break-all;
}
.device-foot .time {
  flex-shrink: 0;
  white-space: nowrap;
}

.empty {
  text-align: center;
  color: var(--text-dim);
  padding: 40px;
}

/* 设备详情弹窗 */
.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 1000; /* 高于 Leaflet 各 pane（tile 200/marker 600/popup 700） */
}
.modal-mask {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}
.modal-panel {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 860px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-title {
  font-size: 16px;
  font-weight: 600;
}
.modal-close {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
}
.report-head,
.report-row {
  display: grid;
  grid-template-columns: 150px 60px 70px 70px 60px 60px 130px;
  gap: 8px;
  align-items: center;
  font-size: 12px;
}
.report-head {
  padding: 10px 20px;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  background: var(--bg-card-2);
}
.report-row {
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}
.report-row:last-child {
  border-bottom: none;
}
.r-time {
  color: var(--text);
}
.r-soc,
.r-v,
.r-c {
  font-family: 'DIN Alternate', 'Roboto Mono', monospace;
}
.r-alarm {
  color: var(--red);
}
.r-loc {
  color: var(--text-dim);
  font-size: 11px;
  white-space: normal;
  word-break: break-all;
  line-height: 1.4;
}
.detail-map {
  height: 260px;
  flex-shrink: 0;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.report-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: auto;
}
.detail-loading {
  padding: 32px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}

/* 固件管理 */
.fw-panel {
  max-width: 720px;
}
.fw-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow-y: auto;
}
.fw-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.fw-row {
  display: flex;
  gap: 12px;
}
.fw-row .input {
  flex: 1;
}
.fw-upload {
  align-items: center;
}
.fw-upload input[type='file'] {
  flex: 1;
  color: var(--text-secondary);
  font-size: 13px;
}
.fw-upload-btn {
  height: 40px;
  padding: 0 20px;
}
.fw-msg {
  font-size: 13px;
  min-height: 18px;
  color: var(--text-secondary);
}
.fw-msg.ok {
  color: var(--green);
}
.fw-msg.err {
  color: var(--red);
}
.fw-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.fw-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-card-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
}
.fw-item-main {
  flex: 1;
  min-width: 0;
}
.fw-item-line {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  flex-wrap: wrap;
}
.fw-tag {
  color: var(--text-dim);
  font-size: 12px;
  margin-left: 6px;
}
.fw-tag-sw {
  margin-left: 0;
}
.fw-sw {
  color: var(--green);
  font-weight: 600;
  font-family: 'DIN Alternate', 'Roboto Mono', monospace;
}
.fw-item-sub {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-dim);
}
.fw-del {
  height: 32px;
  padding: 0 14px;
  font-size: 13px;
  background: transparent;
  color: var(--red);
  border: 1px solid rgba(239, 68, 68, 0.4);
  flex-shrink: 0;
}
.fw-del:hover {
  background: rgba(239, 68, 68, 0.12);
}

/* 移动端 */
@media (max-width: 640px) {
  .summary {
    grid-template-columns: repeat(2, 1fr);
  }
  .customer-cards {
    grid-template-columns: 1fr;
  }
  .content {
    padding: 16px;
  }
  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .search-input {
    max-width: none;
  }
  .modal {
    padding: 12px;
  }
  .map {
    height: 240px;
  }
}
