/* S200 小车调试工具 — 深色主题，移动端优先（手机/平板） */
:root {
  --bg: #0d1117;
  --card: #161b22;
  --border: #30363d;
  --border2: #21262d;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --accent: #3b82f6;
  --green: #3fb950;
  --yellow: #d29922;
  --red: #f85149;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

/* ============ 顶部栏 ============ */
.topbar {
  z-index: 30; flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px;
  background: var(--card); border-bottom: 1px solid var(--border);
}
.title { font-size: 21px; font-weight: 800; letter-spacing: 1px; flex: 1; min-width: 0; }
.user-name { font-size: 13px; font-weight: 700; color: var(--text-dim); white-space: nowrap; line-height: 40px; }
.top-icons { display: flex; gap: 8px; align-items: center; }
.icon-btn {
  background: none; border: none; color: var(--text);
  font-size: 22px; padding: 6px 8px; cursor: pointer;
  min-width: 40px; min-height: 40px; border-radius: 8px;
}
.icon-btn:active { background: var(--border2); }

/* ============ 抽屉菜单 ============ */
.drawer-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  z-index: 40; opacity: 0; pointer-events: none; transition: opacity .2s;
}
.drawer-mask.show { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; left: 0; bottom: 0; width: 78%; max-width: 320px;
  background: var(--card); z-index: 50; transform: translateX(-100%);
  transition: transform .2s; padding: 16px 12px; overflow-y: auto;
  border-right: 1px solid var(--border);
}
.drawer.show { transform: translateX(0); }
.drawer-title { color: var(--text-dim); font-size: 14px; padding: 8px 12px 12px; }
.drawer-item {
  display: flex; align-items: center; gap: 12px;
  width: 100%; background: none; border: none; color: var(--text);
  font-size: 17px; padding: 14px 12px; cursor: pointer; border-radius: 8px;
  text-align: left; min-height: 48px;
}
.drawer-item span { font-size: 20px; width: 28px; text-align: center; }
.drawer-item:active, .drawer-item.active { background: var(--border2); }
.drawer-item.active { color: var(--accent); font-weight: 700; }

/* ============ 主内容 ============ */
.main { padding: 12px; flex: 1; overflow-y: auto; min-height: 0; }
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px; margin-bottom: 12px;
}
.card-title { font-size: 14px; color: var(--text-dim); margin-bottom: 10px; font-weight: 600; }

/* 运行模式条 */
.mode-strip {
  display: flex; align-items: center; gap: 10px;
  padding: 0 4px 12px;
}
.mode-label { color: var(--text-dim); font-size: 14px; }
.mode-value { font-size: 19px; font-weight: 800; color: var(--accent); }

/* 网格 */
.grid5 { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.grid2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 8px; }
.metric {
  background: var(--bg); border: 1px solid var(--border2);
  border-radius: 8px; padding: 10px 6px; text-align: center;
  min-height: 56px; display: flex; flex-direction: column; justify-content: center;
}
.metric-v { font-size: 17px; font-weight: 700; color: var(--accent); word-break: break-all; }
.metric-k { font-size: 12px; color: var(--text-dim); margin-top: 4px; }

/* 服务监控 */
.svc-groups { display: flex; flex-direction: column; gap: 10px; }
.svc-group-title { font-size: 13px; color: var(--text-dim); margin-bottom: 6px; font-weight: 600; }
.svc-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.svc-item {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; padding: 8px 10px;
  background: var(--bg); border: 1px solid var(--border2); border-radius: 6px;
  word-break: break-all;
}
.dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.dot-on { background: var(--green); }
.dot-off { background: var(--red); }
.dot-unknown { background: #555; }

/* 俯视图占位 */
.carview {
  height: 180px; background: var(--bg); border: 1px solid var(--border2);
  border-radius: 8px; margin-bottom: 10px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-dim); font-size: 14px;
}

/* 直驱遥控盘（按用户参考图：五个圆形立体按钮，上绿/下橙/左黄/右蓝/中红“停”，白箭头） */
.joyview {
  background: var(--bg); border: 1px solid var(--border2);
  border-radius: 8px; margin-bottom: 10px;
  display: flex; align-items: center; justify-content: center;
  padding: 18px 0;
}
.joystick {
  display: grid; grid-template-columns: repeat(3, 72px); grid-template-rows: repeat(3, 72px);
  gap: 10px;
}
.joy-btn {
  border: none; border-radius: 50%;
  width: 72px; height: 72px;
  cursor: pointer; color: #fff;
  font-size: 26px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 10px rgba(0,0,0,.35), inset 0 -3px 0 rgba(0,0,0,.25), inset 0 2px 0 rgba(255,255,255,.35);
}
.joy-btn:active {
  box-shadow: 0 1px 4px rgba(0,0,0,.35), inset 0 -1px 0 rgba(0,0,0,.25);
  transform: translateY(2px);
}
.joy-btn.up    { background: #22c55e; }
.joy-btn.down  { background: #f97316; }
.joy-btn.left  { background: #eab308; }
.joy-btn.right { background: #3b82f6; }
.joy-btn.stop  { background: #ef4444; font-size: 24px; }

/* 跟随画面（跟随启动才传输，未跟随显示提示文字） */
.camview {
  height: 240px; background: var(--bg); border: 1px solid var(--border2);
  border-radius: 8px; margin-bottom: 10px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-dim); font-size: 14px;
  overflow: hidden;
}
.camview img { width: 100%; height: 100%; object-fit: contain; }

/* 按钮 */
.btn {
  background: var(--border2); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; padding: 12px;
  font-size: 15px; font-weight: 600; cursor: pointer;
  min-height: 48px; flex: 1;
}
.btn:active { opacity: .8; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-full { width: 100%; margin-top: 10px; }
.btn-row { display: flex; gap: 10px; margin-top: 10px; }
.btn-row .btn { flex: 1; }

/* 参数折叠 */
.param-group { margin-bottom: 8px; }
.param-toggle {
  width: 100%; background: var(--bg); border: 1px solid var(--border2);
  color: var(--text); font-size: 14px; font-weight: 600;
  padding: 12px; border-radius: 8px; cursor: pointer; text-align: left;
  min-height: 44px;
}
.param-body { padding: 8px 4px 4px; }
.param-row {
  display: flex; align-items: center; gap: 10px; margin-bottom: 8px;
}
.param-row label { font-size: 13px; color: var(--text-dim); min-width: 108px; flex-shrink: 0; }
.param-row input, .param-row select {
  flex: 1; background: var(--bg); border: 1px solid var(--border);
  color: var(--text); border-radius: 6px; padding: 10px; font-size: 15px; min-width: 0;
  min-height: 42px;
}

/* 资产列表 */
.asset-list { display: flex; flex-direction: column; }
.asset-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 2px; border-bottom: 1px solid var(--border2);
  font-size: 14px; gap: 10px;
}
.asset-item:last-child { border-bottom: none; }
.asset-item span:first-child { word-break: break-all; }
.badge { font-size: 12px; padding: 3px 10px; border-radius: 10px; white-space: nowrap; flex-shrink: 0; }
.badge-on { background: rgba(63,185,80,.15); color: var(--green); }
.badge-off { background: rgba(248,81,73,.15); color: var(--red); }

/* 车队状态 */
.fleet-status { display: flex; gap: 16px; margin: 12px 0; }
.fleet-dot { font-size: 15px; font-weight: 700; }
.fleet-dot.on { color: var(--green); }
.fleet-dot.off { color: var(--red); }

/* ============ 底部 ============ */
.bottombar {
  z-index: 20; flex-shrink: 0;
  background: var(--card); border-top: 1px solid var(--border);
  padding: 10px 12px;
}
.chat-row { display: flex; gap: 8px; }
.chat-row input {
  flex: 1; background: var(--bg); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; padding: 12px; font-size: 15px; min-width: 0;
  min-height: 46px;
}
.btn-send {
  background: var(--accent); border: none; border-radius: 8px;
  color: #fff; font-size: 15px; font-weight: 600;
  padding: 0 18px; cursor: pointer; min-height: 46px;
}
.tool-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.tool-spacer { flex: 1; }
.voice-btn {
  flex: 0 1 auto; background: var(--bg); border: 1px solid var(--green);
  color: var(--green); border-radius: 8px; padding: 10px 16px;
  font-size: 15px; font-weight: 700; cursor: pointer; min-height: 44px;
}
.voice-btn.on { background: var(--green); color: #000; }

/* 音量/MIC 弹窗 */
.audio-panel {
  position: fixed; right: 14px; bottom: 155px; z-index: 45;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px; width: 240px;
  box-shadow: 0 6px 20px rgba(0,0,0,.5);
}
.audio-label { font-size: 13px; font-weight: 600; margin: 6px 0; color: var(--text); }
.audio-panel input[type=range] { width: 100%; height: 6px; }

/* ============ 状态条（底部留白） ============ */
.statusbar {
  height: 30px; z-index: 25; flex-shrink: 0;
  background: var(--card); border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px; padding: 0 14px;
  font-size: 12px; color: var(--text-dim);
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }

/* ============ 平板适配（≥768px 加宽网格） ============ */
@media (min-width: 768px) {
  .grid4 { grid-template-columns: repeat(4, 1fr); }
  .carview { height: 240px; }
  .param-row label { min-width: 140px; }
}

/* ============ PC 适配（≥1024px 网格加列，居中限宽不填满屏） ============ */
@media (min-width: 1024px) {
  .svc-grid { grid-template-columns: repeat(4, 1fr); }  /* 服务监控 4 列（基础链路 4 个横排） */
  .grid4 { grid-template-columns: repeat(6, 1fr); }     /* 障碍物 6 项横排一行 */
  .grid2 { grid-template-columns: repeat(4, 1fr); }     /* 整车状态 4 项横排一行 */
}

/* ============ 地图选择弹窗（2026-09-05 对齐 QT-App 弹窗选图） ============ */
.modal-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  z-index: 60; display: flex; align-items: center; justify-content: center;
}
.modal {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; width: 90%; max-width: 420px;
  max-height: 80vh; display: flex; flex-direction: column; padding: 16px;
}
.modal-title { font-size: 17px; font-weight: 700; margin-bottom: 6px; }
.modal-sub { font-size: 13px; color: var(--text-dim); margin-bottom: 10px; word-break: break-all; }
.map-list { flex: 1; overflow-y: auto; min-height: 0; border: 1px solid var(--border2); border-radius: 8px; }
.map-item {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 12px 14px; border-bottom: 1px solid var(--border2); cursor: pointer;
  font-size: 14px; word-break: break-all;
}
.map-item:last-child { border-bottom: none; }
.map-item.sel { background: rgba(59,130,246,.15); }
.map-empty { padding: 20px; text-align: center; color: var(--text-dim); font-size: 14px; }
.modal-actions { display: flex; gap: 10px; margin-top: 12px; }
.modal-actions .btn { flex: 1; }

/* ============ 轻量提示条 ============ */
.toast {
  position: fixed; top: 64px; left: 50%; transform: translateX(-50%);
  background: var(--card); border: 1px solid var(--border); color: var(--text);
  padding: 10px 18px; border-radius: 8px; font-size: 14px; z-index: 100;
  opacity: 0; pointer-events: none; transition: opacity .2s;
  max-width: 90%; box-shadow: 0 6px 20px rgba(0,0,0,.5); word-break: break-all;
}
.toast.show { opacity: 1; }

/* ============ 聊天框消息区（2026-09-05） ============ */
.chat-log {
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chat-msg {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.chat-user { justify-content: flex-end; }     /* 操作员：靠右 */
.chat-bot  { justify-content: flex-start; }   /* 机器人：靠左 */
.chat-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  background: var(--border);
  border: 1px solid var(--border2);
}
.chat-bubble {
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 14px;
  max-width: 70%;
  word-break: break-word;
  line-height: 1.4;
}
.chat-user .chat-bubble { background: var(--accent); color: #fff; }
.chat-bot  .chat-bubble { background: var(--border2); color: var(--text); }
