:root {
  --primary: #2980b9;
  --page-bg: #eef1f5;
  --card-bg: #ffffff;
  --text: #333333;
  --text-muted: #666666;
  --green: #27ae60;
  --red: #e74c3c;
  --purple: #8e44ad;
  --pink: #fd79a8;
  --grey: #95a5a6;
  --line: #2980b9;
  --radius: 6px;
  --radius-lg: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", sans-serif;
  background: var(--page-bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: 52px;
}

body.embedded {
  padding-bottom: 8px;
}

body.embedded .standalone-only {
  display: none !important;
}

/* 与小程序 navigationBar 一致（仅浏览器独立打开时显示） */
.wx-nav {
  background: var(--primary);
  color: #fff;
  text-align: center;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.wx-nav h1 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

/* 与主页/列表相同工具栏 */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: var(--card-bg);
  font-size: 13px;
  color: var(--text-muted);
  border-bottom: 1px solid #e8ecef;
}

.toolbar-right {
  display: flex;
  gap: 12px;
}

.link-btn {
  border: none;
  background: transparent;
  color: var(--primary);
  font-size: 13px;
  padding: 0;
  cursor: pointer;
}

.link-btn:active { opacity: 0.7; }

.auth-panel {
  margin: 8px;
  padding: 10px;
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.auth-label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.auth-bar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.auth-bar input {
  flex: 1 1 160px;
  min-width: 0;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 7px 10px;
  font-size: 13px;
}

.auth-bar button {
  border: none;
  border-radius: 4px;
  background: var(--primary);
  color: #fff;
  padding: 7px 12px;
  font-size: 13px;
  cursor: pointer;
}

.btn-muted {
  background: #ddd !important;
  color: #444 !important;
}

/* 与列表页图例一致 */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 14px;
  background: var(--card-bg);
  margin-bottom: 6px;
  font-size: 12px;
}

.chip {
  padding: 2px 10px;
  border-radius: var(--radius);
  color: #fff;
  font-size: 11px;
  font-weight: 500;
}

.chip.driving { background: var(--green); }
.chip.stopped { background: var(--red); }
.chip.unloading { background: var(--purple); }
.chip.transferring { background: var(--pink); }
.chip.unknown { background: var(--grey); }

/* 白底卡片 + 蓝色标题（与列表分组一致） */
.panel {
  margin: 6px 6px 0;
  background: var(--card-bg);
  overflow: hidden;
}

.panel-title {
  background: var(--primary);
  color: #fff;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
}

.panel-body {
  padding: 10px 12px;
}

.vehicle-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 40px;
  align-items: flex-start;
}

.pipeline-list {
  padding: 6px 0 16px;
}

.pipeline-card {
  margin: 8px 6px 0;
  background: var(--card-bg);
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.pipeline-header {
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  line-height: 1.45;
  padding: 10px 14px;
  font-weight: 600;
}

.pipeline-body {
  display: grid;
  grid-template-columns: 32px 1fr;
  grid-template-rows: auto auto;
  gap: 4px 6px;
  align-items: stretch;
  min-height: 96px;
  padding: 8px 6px 10px;
  background: var(--card-bg);
}

.avg-times {
  grid-column: 1;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  font-size: 10px;
  color: var(--text-muted);
  text-align: center;
  padding-top: 6px;
}

.route-track {
  grid-column: 2;
  grid-row: 1;
  position: relative;
  min-height: 96px;
  padding: 0 4px 0 0;
}

.site-column {
  grid-column: 1 / -1;
  grid-row: 2;
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 6px;
  align-items: start;
  padding-top: 2px;
  border-top: 1px dashed rgba(41, 128, 185, 0.25);
  margin-top: 2px;
  padding-bottom: 2px;
}

.site-icon {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  margin-top: 2px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%232980b9'%3E%3Cpath d='M3 21V8l9-5 9 5v13h-6v-7H9v7H3z'/%3E%3C/svg%3E") center/22px no-repeat;
}

/* 工地围栏车辆：2 行 × 3 列 */
.site-stack {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: minmax(42px, auto);
  gap: 4px;
  width: 100%;
  max-height: calc(42px * 2 + 4px);
  overflow-y: auto;
}

.pipeline-body:not(:has(.site-column)) {
  grid-template-rows: auto;
}

.pipeline-body:not(:has(.site-column)) .route-track {
  grid-column: 2;
}

.site-stack .vehicle-box.at-site {
  width: 100%;
  min-width: 0;
  padding: 3px 2px;
  box-sizing: border-box;
}

.site-stack .vehicle-box.at-site .label {
  font-size: 11px;
  line-height: 1.1;
}

.site-stack .vehicle-box.at-site .sub {
  font-size: 8px;
  line-height: 1.2;
  opacity: 0.95;
}

.avg-times .val {
  font-weight: 700;
  font-size: 12px;
  line-height: 1.1;
  color: var(--primary);
}

.plant-marker {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 26px;
  height: 26px;
  z-index: 4;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%232980b9'%3E%3Cpath d='M12 3L2 12h3v8h6v-5h2v5h6v-8h3L12 3z'/%3E%3C/svg%3E") center/20px no-repeat;
}

.route-line {
  position: absolute;
  left: 22px;
  right: 6px;
  top: 50%;
  height: 3px;
  background: var(--line);
  transform: translateY(-50%);
  border-radius: 2px;
  z-index: 1;
  opacity: 0.85;
}

.route-lane {
  position: absolute;
  left: 14px;
  right: 4px;
  height: 36px;
  z-index: 2;
}

.route-lane-top { top: 8px; }
.route-lane-bottom { bottom: 8px; }

.vehicle-box.lane-top,
.vehicle-box.lane-bottom {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  transition: left 0.9s ease;
}

.vehicle-box.static {
  position: static;
  transform: none;
}

.panel.returning .vehicle-row {
  gap: 8px;
}

.vehicle-box.returning-chip {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  padding: 4px 6px;
}

.vehicle-box.returning-chip .sub.dist {
  font-size: 10px;
  font-weight: 600;
  opacity: 1;
}

.vehicle-box.at-site .sub {
  font-size: 9px;
  line-height: 1.25;
}

.site-column .site-stack .vehicle-box.at-site .sub {
  font-size: 8px;
}

.vehicle-box .label {
  font-weight: 700;
  font-size: 12px;
}

.vehicle-box .sub {
  font-size: 9px;
  opacity: 0.95;
  margin-top: 1px;
}

.vehicle-box.driving { background: var(--green); }
.vehicle-box.stopped { background: var(--red); }
.vehicle-box.unloading { background: var(--purple); }
.vehicle-box.transferring { background: var(--pink); }
.vehicle-box.unknown { background: var(--grey); }

.vehicle-box {
  min-width: 36px;
  text-align: center;
  border-radius: var(--radius);
  color: #fff;
  font-size: 11px;
  line-height: 1.15;
  padding: 3px 4px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
  z-index: 3;
}

.inline-chip {
  display: inline-block;
  flex-shrink: 0;
}

.empty-hint {
  color: var(--text-muted);
  font-size: 12px;
  padding: 4px;
}

.empty-card {
  margin: 12px;
  padding: 24px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.6;
  background: var(--card-bg);
  border-radius: var(--radius-lg);
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: #fff;
  border-top: 1px solid #e0e0e0;
  height: 52px;
  z-index: 20;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 10px;
  color: #666;
  line-height: 1.1;
}

.nav-icon {
  display: block;
  width: 22px;
  height: 22px;
  background-position: center;
  background-repeat: no-repeat;
  background-size: 20px 20px;
  opacity: 0.55;
}

.nav-item.active {
  color: var(--primary);
  font-weight: 600;
}

.nav-item.active .nav-icon { opacity: 1; }

.nav-icon-home {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23666'%3E%3Cpath d='M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8h5z'/%3E%3C/svg%3E");
}
.nav-item.active .nav-icon-home {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%232980b9'%3E%3Cpath d='M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8h5z'/%3E%3C/svg%3E");
}
.nav-icon-dispatch {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23666'%3E%3Cpath d='M18 18.5a1.5 1.5 0 100-3 1.5 1.5 0 000 3zM6 18.5a1.5 1.5 0 100-3 1.5 1.5 0 000 3zM20 8h-3V6H6v2H3l2 6h11l2-6z'/%3E%3C/svg%3E");
}
.nav-item.active .nav-icon-dispatch {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%232980b9'%3E%3Cpath d='M18 18.5a1.5 1.5 0 100-3 1.5 1.5 0 000 3zM6 18.5a1.5 1.5 0 100-3 1.5 1.5 0 000 3zM20 8h-3V6H6v2H3l2 6h11l2-6z'/%3E%3C/svg%3E");
}
.nav-icon-list {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23666'%3E%3Cpath d='M3 5h18v2H3V5zm0 6h18v2H3v-2zm0 6h18v2H3v-2z'/%3E%3C/svg%3E");
}
.nav-item.active .nav-icon-list {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%232980b9'%3E%3Cpath d='M3 5h18v2H3V5zm0 6h18v2H3v-2zm0 6h18v2H3v-2z'/%3E%3C/svg%3E");
}
.nav-icon-monitor {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23666'%3E%3Cpath d='M21 3H3c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h7v2H8v2h8v-2h-2v-2h7c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 14H3V5h18v12z'/%3E%3C/svg%3E");
}
.nav-item.active .nav-icon-monitor {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%232980b9'%3E%3Cpath d='M21 3H3c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h7v2H8v2h8v-2h-2v-2h7c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 14H3V5h18v12z'/%3E%3C/svg%3E");
}

.error-toast {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 58px;
  background: #c0392b;
  color: #fff;
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  z-index: 30;
}

body.embedded .error-toast { bottom: 12px; }

.loading-mask {
  position: fixed;
  inset: 0;
  background: rgba(238, 241, 245, 0.75);
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: center;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(41, 128, 185, 0.25);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.hidden { display: none !important; }

.demo-banner {
  background: #e67e22;
  color: #fff;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 8px;
  letter-spacing: 0.5px;
}

body.demo-mode.embedded .demo-banner {
  font-size: 11px;
  padding: 4px 6px;
}

@media (min-width: 768px) {
  body {
    max-width: 480px;
    margin: 0 auto;
    box-shadow: 0 0 24px rgba(0, 0, 0, 0.08);
  }
  .bottom-nav {
    max-width: 480px;
    left: 50%;
    transform: translateX(-50%);
  }
}
