/* ==========================================================================
   GPS 定位追踪系统 —— 管理后台样式（深色主题）
   配色取自需求截图：深蓝底 + 蓝色主色 + 绿色在线标签
   ========================================================================== */

:root {
  --bg:        #0f1a30;
  --bg-nav:    #0b1526;
  --bg-panel:  #16233f;
  --bg-card:   #1b2b4d;
  --bg-hover:  #22355e;
  --border:    #24365e;
  --border-lt: #2e4470;
  --text:      #e6edf8;
  --text-dim:  #8fa4c7;
  --text-mute: #6b81a8;
  --primary:   #2563eb;
  --primary-h: #1d4ed8;
  --green:     #22c55e;
  --red:       #ef4444;
  --amber:     #f59e0b;
  --radius:    8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  overflow: hidden;
}

button, input, select, textarea { font-family: inherit; font-size: inherit; }

[hidden] { display: none !important; }

/* ---------------------------------------------------------------- 顶栏 --- */

.topbar {
  height: 48px;
  min-height: 48px;             /* 任何情况下都不允许被压缩掉 */
  flex: 0 0 48px;               /* 不参与伸缩：不会被下方内容挤没 */
  background: var(--bg-nav);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 24px;
  position: relative;
  z-index: 1500;                /* 永远压在地图与弹层之上 */
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
}
.brand svg { display: block; }

.nav { display: flex; gap: 4px; }

.nav a {
  display: block;
  padding: 7px 16px;
  border-radius: 6px;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 14px;
  transition: background .15s, color .15s;
}
.nav a:hover { background: var(--bg-panel); color: var(--text); }
.nav a.active { background: var(--primary); color: #fff; }

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}
.topbar-right .who { color: var(--text-dim); font-size: 13px; }

.btn {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border-lt);
  border-radius: 6px;
  padding: 6px 14px;
  cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-h); }
.btn-danger { background: transparent; border-color: var(--red); color: var(--red); }
.btn-danger:hover { background: rgba(239,68,68,.15); }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-block { width: 100%; }

/* ---------------------------------------------------------------- 布局 --- */

.app { display: flex; flex-direction: column; height: 100%; }

/*
  内容区必须是 flex 容器，否则里面的 .page 拿不到高度：
  .split 用的是 height:100%，而百分比高度需要父元素有确定高度；
  .content 只有 min-height:0 + flex:1 时，.page 的 height:auto 会让
  .split 退化成「由内容撑高」，地图就会塌成一条。
  这里让 .content 成为 flex 容器、.page 自动填满，高度链就完整了。
*/
.content {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
}

/* 每个功能页都自动填满内容区（实时定位 / 设备管理 / 历史轨迹 / 用户管理 / 数据库） */
.page {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
}

.toolbar {
  flex: 0 0 auto;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 8px 16px;
  min-height: 50px;
  z-index: 20;
}

/* 顶部工具条 + 下方内容 */
.has-toolbar { padding-top: 0; }

/* 实时定位 / 历史轨迹：左侧设备列表 + 右侧地图 */
.split { display: flex; flex: 1 1 auto; height: 100%; min-height: 0; min-width: 0; }
.side {
  width: 250px;
  flex: 0 0 250px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.side-head {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex: 0 0 auto;
}
.side-body { flex: 1 1 auto; overflow-y: auto; padding: 10px; }
.main-pane { flex: 1 1 auto; min-width: 0; position: relative; }
.map { position: absolute; inset: 0; background: #0a1322; }

/* ------------------------------------------------------------ 设备卡片 --- */

.dev-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.dev-card:hover { background: var(--bg-hover); }
.dev-card.active { border-color: var(--primary); background: var(--bg-hover); }

.dev-card .dc-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.dev-card .dc-name {
  font-size: 15px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dev-card .dc-line {
  color: var(--text-dim);
  font-size: 12.5px;
  line-height: 1.7;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dev-card .dc-line b { color: var(--text); font-weight: 500; }

.tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  border: 1px solid transparent;
  white-space: nowrap;
  flex: 0 0 auto;
}
.tag-on   { background: rgba(34,197,94,.16);  color: var(--green); border-color: rgba(34,197,94,.4); }
.tag-off  { background: rgba(107,129,168,.16); color: var(--text-mute); border-color: rgba(107,129,168,.35); }
.tag-warn { background: rgba(245,158,11,.16); color: var(--amber); border-color: rgba(245,158,11,.4); }

/* -------------------------------------------------------------- 数据表 --- */

.table-wrap {
  height: 100%;
  overflow: auto;
  padding: 0;
}
table.grid {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
table.grid th {
  position: sticky;
  top: 0;
  background: var(--bg-panel);
  color: var(--text-dim);
  font-weight: 500;
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  z-index: 2;
}
table.grid td {
  padding: 11px 14px;
  border-bottom: 1px solid rgba(36,54,94,.6);
  white-space: nowrap;
}
table.grid tbody tr:hover { background: rgba(34,53,94,.45); }
table.grid td.mono { font-family: Consolas, "Courier New", monospace; letter-spacing: .3px; }
table.grid td.dim { color: var(--text-dim); }
table.grid .cell-actions { display: flex; gap: 10px; }
.link {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  padding: 0;
  font-size: 13.5px;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.link:hover { color: #60a5fa; }
.link.danger { color: var(--red); }
.link.danger:hover { color: #f87171; }

/* 表头与工具区 */
.page-head {
  display: flex;
  align-items: center;
  padding: 14px 20px;
  flex: 0 0 auto;
}
.page-head h1 { margin: 0; font-size: 19px; }
.page-head .spacer { margin-left: auto; }

.page-col { display: flex; flex-direction: column; flex: 1 1 auto; height: 100%; min-height: 0; }
.page-col .table-wrap { flex: 1 1 auto; min-height: 0; }

/* ------------------------------------------------------------ 表单控件 --- */

.fld { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.fld > span { color: var(--text-dim); font-size: 13px; }
input[type=text], input[type=password], input[type=number], input[type=date],
input[type=datetime-local], select, textarea {
  background: var(--bg-card);
  border: 1px solid var(--border-lt);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 10px;
  outline: none;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
input::placeholder { color: var(--text-mute); }
select { cursor: pointer; }
input[type=date] { width: 150px; }
input[type=datetime-local] { width: 200px; }
textarea { width: 100%; resize: vertical; min-height: 70px; }

.hint { color: var(--text-mute); font-size: 12.5px; }

/* 地图图层切换（右上角） */
.map-layers {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 500;
  display: flex;
  gap: 6px;
  background: rgba(11,21,38,.9);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px;
}
.map-layers button {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 5px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}
.map-layers button:hover { color: var(--text); }
.map-layers button.active { background: var(--primary); color: #fff; }

/* 地图左下状态条（自动刷新时间）—— 避开右下角的 Leaflet 版权文字 */
.map-status {
  position: absolute;
  bottom: 10px;
  left: 56px;
  z-index: 500;
  background: rgba(11,21,38,.88);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  color: var(--text-dim);
  font-size: 12.5px;
  display: flex;
  gap: 14px;
}
.map-status b { color: var(--text); font-weight: 600; }

/* 地图左上角小统计（在线 / 总计 / 更新） */
.map-stats {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 500;
  display: flex;
  gap: 18px;
  background: rgba(11,21,38,.88);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 16px;
  font-size: 13px;
  color: var(--text-dim);
  max-width: calc(100% - 280px);
  overflow: hidden;
  white-space: nowrap;
}
.map-stats b { color: var(--text); font-weight: 600; }
.map-stats .on { color: var(--green); }

/* Leaflet 自带控件：缩放控件放在左下角，避免与左上角统计、右上角图层按钮重叠 */
.leaflet-control-zoom { margin: 0 0 10px 10px !important; }
.leaflet-bottom.leaflet-left { bottom: 0; }

/* 窄屏（笔记本 / 分屏）时收紧顶部工具条与地图角标，避免互相挤压 */
@media (max-width: 1400px) {
  .map-stats { gap: 12px; padding: 6px 12px; max-width: calc(100% - 260px); }
  .side { width: 220px; flex-basis: 220px; }
  .track-side { width: 260px; flex-basis: 260px; }
}

@media (max-width: 1100px) {
  .map-stats { max-width: calc(100% - 200px); font-size: 12px; }
  .side { width: 200px; flex-basis: 200px; }
  .track-side { width: 230px; flex-basis: 230px; }
  .map-layers button { padding: 5px 8px; font-size: 12px; }
}

/* -------------------------------------------------------------- 弹窗 --- */

.mask {
  position: fixed;
  inset: 0;
  background: rgba(4,10,20,.65);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal {
  background: var(--bg-panel);
  border: 1px solid var(--border-lt);
  border-radius: 10px;
  width: 460px;
  max-width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 60px rgba(0,0,0,.55);
}
.modal-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-x {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
}
.modal-x:hover { color: var(--text); }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-foot {
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
.form-row { margin-bottom: 14px; }
.form-row > label {
  display: block;
  color: var(--text-dim);
  font-size: 13px;
  margin-bottom: 6px;
}
.form-row input, .form-row select { width: 100%; }
.form-row .tip { color: var(--text-mute); font-size: 12px; margin-top: 5px; }

/* -------------------------------------------------------------- 提示条 --- */

.toasts {
  position: fixed;
  top: 60px;
  right: 18px;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--bg-card);
  border: 1px solid var(--border-lt);
  border-left: 3px solid var(--primary);
  border-radius: 6px;
  padding: 10px 16px;
  font-size: 13.5px;
  box-shadow: 0 10px 30px rgba(0,0,0,.45);
  animation: toastIn .18s ease-out;
  max-width: 380px;
}
.toast.ok   { border-left-color: var(--green); }
.toast.err  { border-left-color: var(--red); }
.toast.warn { border-left-color: var(--amber); }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* ---------------------------------------------------------- 登录页 --- */

.login-wrap {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(1200px 600px at 50% 0%, #1a2b4d 0%, var(--bg) 60%);
}
.login-card {
  width: 380px;
  max-width: calc(100vw - 40px);
  background: var(--bg-panel);
  border: 1px solid var(--border-lt);
  border-radius: 12px;
  padding: 32px 28px 26px;
  box-shadow: 0 24px 70px rgba(0,0,0,.5);
}
.login-card .logo { display: flex; justify-content: center; margin-bottom: 12px; }
.login-card h1 {
  margin: 0 0 6px;
  font-size: 19px;
  text-align: center;
  color: #fff;
}
.login-card .sub {
  margin: 0 0 24px;
  text-align: center;
  color: var(--text-mute);
  font-size: 13px;
}
.login-card .form-row input { padding: 9px 12px; }
.login-msg {
  margin-top: 12px;
  min-height: 18px;
  text-align: center;
  font-size: 13px;
  color: var(--red);
}

/* --------------------------------------------------- 历史轨迹 回放条 --- */

.track-side { width: 300px; flex: 0 0 300px; }
.readout {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 12px;
  font-size: 13px;
  line-height: 1.9;
}
.readout .kv { display: flex; justify-content: space-between; gap: 10px; }
.readout .kv span { color: var(--text-dim); }
.readout .kv b { font-weight: 600; }

input[type=range] {
  width: 100%;
  margin: 12px 0 6px;
  accent-color: var(--primary);
  cursor: pointer;
}
input[type=range]:disabled { cursor: not-allowed; opacity: .45; }

.pt-list { margin-top: 10px; }
.pt-item {
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 12.5px;
  color: var(--text-dim);
  cursor: pointer;
  border-left: 2px solid transparent;
  line-height: 1.6;
}
.pt-item:hover { background: var(--bg-card); }
.pt-item.active { background: var(--bg-card); border-left-color: var(--primary); color: var(--text); }
.pt-item .t { color: var(--text); }

/* 空状态 */
.empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-mute);
  font-size: 13px;
}

/* ------------------------------------------------- 数据库管理页 --- */

/*
  仅超级用户可见的元素（导航里的「数据库」标签、数据库页里的高危按钮）。

  这里**不能**用 `display: none !important`：
  !important 的样式表规则会压过 JS 写的内联 style.display，
  结果就是无论怎么切换角色，这个标签都永远显示不出来（本项目踩过这个坑）。
  正确做法是给 <body> 加/去 is-super 类，由下面两条规则控制显隐。
*/
.super-only { display: none; }
body.is-super .super-only { display: block; }
/* 导航里的标签用 flex 布局更贴合顶栏 */
body.is-super .nav a.super-only { display: block; }

.db-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 0 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card-box {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  flex: 0 0 auto;
}

.card-head {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.card-body { padding: 14px; }

.table-scroll.mid { max-height: 300px; overflow: auto; }

.danger-box { border-color: rgba(239,68,68,.45); }
.danger-box .card-head { background: rgba(239,68,68,.10); }

.pin-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding-bottom: 14px;
  border-bottom: 1px dashed var(--border-lt);
  margin-bottom: 14px;
}
.pin-label { color: var(--text-dim); font-size: 13px; }
input.pin-input {
  width: 260px;
  font-family: Consolas, "Courier New", monospace;
  letter-spacing: 2px;
  text-transform: uppercase;
}
.pin-display {
  font-family: Consolas, "Courier New", monospace;
  letter-spacing: 3px;
  font-size: 16px;
  font-weight: 700;
  color: var(--amber);
  background: rgba(245,158,11,.12);
  border: 1px solid rgba(245,158,11,.4);
  border-radius: 6px;
  padding: 4px 12px;
  user-select: all;
}

.danger-actions { display: flex; flex-direction: column; gap: 12px; }
.danger-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
}
.danger-text { display: flex; flex-direction: column; gap: 4px; min-width: 260px; }
.danger-text b { color: var(--red); }
.danger-text span { color: var(--text-dim); font-size: 12.5px; line-height: 1.6; }

/* 危险操作确认弹窗里的提示 */
.modal .danger-note {
  background: rgba(239,68,68,.10);
  border: 1px solid rgba(239,68,68,.4);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 13px;
  line-height: 1.7;
  margin-bottom: 14px;
}

/* -------------------------------------------------------- 滚动条 --- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2b4070; border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #3a5590; }

/* Leaflet 深色适配 */
.leaflet-container { background: #0a1322; font-family: inherit; }
.leaflet-control-attribution {
  background: rgba(11,21,38,.8) !important;
  color: var(--text-mute) !important;
}
.leaflet-control-attribution a { color: var(--text-dim) !important; }
.leaflet-bar a {
  background: #1b2b4d !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}
.leaflet-bar a:hover { background: #22355e !important; }

/* 自定义定位气泡 */
.dev-marker {
  width: 26px; height: 26px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center;
}
.dev-marker.online  { background: var(--primary); }
.dev-marker.offline { background: #64748b; }
.dev-marker i {
  transform: rotate(45deg);
  width: 7px; height: 7px;
  background: #fff;
  border-radius: 50%;
}
