:root {
  color-scheme: light;
  --header: #0b2b1f;
  --bg: #edf4f0;
  --panel: #f8fbf8;
  --card: #ffffff;
  --line: #d8e4dc;
  --text: #142820;
  --muted: #61776b;
  --accent: #2f8a7b;
  --accent-2: #c2720b;
  --danger: #b42318;
  --sidebar: 438px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 8px;
  min-height: 38px;
  padding: 9px 16px;
  color: #fff;
  background: var(--accent);
  font-weight: 800;
  cursor: pointer;
}

button.ghost {
  color: var(--text);
  background: #eaf3ef;
  border: 1px solid var(--line);
}

button.secondary {
  background: var(--accent-2);
}

button:disabled {
  cursor: not-allowed;
  opacity: .55;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  color: var(--text);
  background: #fff;
  outline: none;
}

label {
  display: grid;
  gap: 6px;
  min-width: 0;
}

label > span,
summary {
  color: #53695f;
  font-size: 13px;
  font-weight: 800;
}

.app-shell {
  height: 100vh;
  min-height: 0;
  display: grid;
  grid-template-rows: 60px minmax(0, 1fr);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 60px;
  padding: 0 18px;
  color: #fff;
  background: var(--header);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 20px;
  font-weight: 900;
}

.version-badge {
  border: 1px solid rgba(255, 255, 255, .24);
  border-radius: 999px;
  padding: 3px 8px;
  color: #d7eadf;
  background: rgba(255, 255, 255, .08);
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6edc83, #ead55e);
  box-shadow: 0 0 16px rgba(110, 220, 131, .38);
}

.runtime {
  color: #d7eadf;
  font-size: 13px;
  white-space: nowrap;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--sidebar);
}

.map-area {
  position: relative;
  min-width: 0;
  min-height: 0;
  background: #edf5f1;
}

.map-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(91, 128, 111, .13) 1px, transparent 1px),
    linear-gradient(90deg, rgba(91, 128, 111, .13) 1px, transparent 1px);
  background-size: 46px 46px;
}

.map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: transparent;
}

.leaflet-container {
  width: 100%;
  height: 100%;
  font: inherit;
  background: transparent;
}

.leaflet-control-attribution {
  font-size: 10px;
}

.map-legend,
.map-tools,
.map-toast {
  position: absolute;
  z-index: 500;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .94);
  box-shadow: 0 8px 22px rgba(20, 40, 32, .08);
}

.map-legend {
  top: 16px;
  left: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: linear-gradient(135deg, #e65d5d, #27ae60);
}

.map-tools {
  top: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
}

.map-tools button {
  min-height: 30px;
  padding: 4px 10px;
  color: var(--text);
  background: #edf4f0;
}

.map-tools span {
  min-width: 50px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.map-toast {
  right: 16px;
  bottom: 16px;
  max-width: min(720px, calc(100% - 32px));
  padding: 10px 14px;
  color: #fff;
  background: rgba(11, 43, 31, .88);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar {
  min-height: 0;
  border-left: 1px solid var(--line);
  background: var(--panel);
  display: grid;
  grid-template-rows: auto auto auto auto 1fr;
  overflow: hidden;
}

.panel {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 12px;
}

.control-panel {
  background: #f3f8f5;
}

.selector-panel {
  background: #fff;
}

.inline-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
}

.actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.primary-actions {
  grid-template-columns: 1fr;
}

.status {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  color: var(--muted);
  background: #fff;
  font-size: 13px;
  line-height: 1.5;
}

.status.error {
  color: var(--danger);
  border-color: #f0b4ac;
  background: #fff7f6;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.segment-option {
  min-width: 0;
}

.segment-option input {
  display: none;
}

.segment-option span {
  min-height: 38px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: #f6faf7;
  font-weight: 900;
  cursor: pointer;
}

.segment-option input:checked + span {
  color: #fff;
  background: var(--accent);
}

.segment-option + .segment-option span {
  border-left: 1px solid var(--line);
}

.monitor-toggle {
  min-height: 44px;
}

.monitor-toggle.is-running {
  background: var(--accent-2);
}

.monitor-toggle.is-connecting {
  color: #fff;
  background: #7a9d90;
  cursor: wait;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: #f8fbf8;
}

.metrics div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  background: #fff;
}

.metrics span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.metrics strong {
  display: block;
  margin-top: 4px;
  font-size: 24px;
  line-height: 1;
}

.event-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.event-card div {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.event-card strong {
  overflow: hidden;
  font-size: 17px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.event-card span {
  color: var(--muted);
  font-size: 13px;
}

#visibleBadge {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 4px 10px;
  color: #08723f;
  background: #e5f4eb;
  font-weight: 900;
}

.people-panel {
  min-height: 0;
  overflow: auto;
  background: #fff;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  border-bottom: 1px solid #edf2ef;
  padding: 9px 8px;
  text-align: left;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: #60746a;
  background: #f8fbf8;
  font-size: 12px;
}

td:first-child {
  max-width: 128px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.empty {
  color: var(--muted);
}

.person {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.person-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.clickable {
  cursor: pointer;
}

.clickable:hover {
  background: #f6faf7;
}

.control-marker {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--control-color);
  border: 3px solid rgba(255, 255, 255, .95);
  box-shadow: 0 1px 5px rgba(0, 0, 0, .28);
  font-size: 12px;
  font-weight: 900;
  line-height: 1;
}

.control-marker.start,
.control-marker.finish {
  font-size: 13px;
}

.gps-marker {
  position: relative;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, .96);
  background: var(--marker-color);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .18), 0 0 14px var(--marker-color);
}

.gps-marker::after {
  content: "";
  position: absolute;
  inset: -8px;
  border: 2px solid var(--marker-color);
  border-radius: 50%;
  animation: pulse 1.4s ease-out infinite;
}

@keyframes pulse {
  0% {
    transform: scale(.55);
    opacity: .72;
  }
  100% {
    transform: scale(1.9);
    opacity: 0;
  }
}

@media (max-width: 1180px) {
  :root {
    --sidebar: 390px;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 880px) {
  html,
  body {
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100vh;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: 68vh auto;
  }

  .sidebar {
    border-left: 0;
    border-top: 1px solid var(--line);
    min-height: 60vh;
  }

  .map-toast {
    left: 16px;
  }
}
