:root {
  color-scheme: dark;
  --panel: rgba(21, 29, 52, 0.91);
  --panel-2: rgba(28, 38, 67, 0.78);
  --line: rgba(209, 221, 255, 0.18);
  --text: #f6f7f9;
  --muted: #b4bfd2;
  --accent: #2d86ff;
  --warning: #ffd33d;
  --danger: #ff6b6b;
  --zello: #1e72ff;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html,
body,
.app-shell,
.map-wrap,
#map {
  height: 100%;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #080b0f;
  color: var(--text);
}

button,
input {
  font: inherit;
}

.app-shell {
  display: block;
  min-height: 100vh;
  position: relative;
  overflow: hidden;
}

.map-wrap {
  position: relative;
  min-width: 0;
}

#map {
  width: 100%;
  background: #111820;
}

.top-bar {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 388px;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  pointer-events: none;
}

.top-bar > div {
  pointer-events: auto;
}

.top-bar h1,
.top-bar p,
.panel h2,
.panel p {
  margin: 0;
}

.top-bar h1 {
  font-size: 15px;
  line-height: 1.15;
  letter-spacing: 0;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.75);
}

.top-bar p {
  margin-top: 3px;
  color: rgba(255, 255, 255, 0.82);
  font-size: 13px;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.75);
}

.controls {
  display: flex;
  gap: 8px;
}

.controls button,
.filter,
.history-button,
.follow-button,
.copy-coords,
.overlay-actions button {
  border: 1px solid var(--line);
  color: var(--text);
  background: rgba(16, 21, 27, 0.82);
  border-radius: 6px;
  cursor: pointer;
}

.controls button {
  min-width: 66px;
  min-height: 34px;
  padding: 0 10px;
  box-shadow: var(--shadow);
  font-size: 12px;
}

.controls button:hover,
.filter:hover,
.history-button:hover,
.follow-button:hover,
.copy-coords:hover,
.overlay-actions button:hover {
  border-color: rgba(68, 215, 182, 0.7);
}

.controls button.active {
  color: #06120f;
  border-color: transparent;
  background: var(--accent);
  font-weight: 800;
}

.panel {
  position: absolute;
  top: 14px;
  right: 14px;
  bottom: 22px;
  z-index: 520;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(410px, calc(100vw - 28px));
  min-width: 0;
  height: auto;
  min-height: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(28, 38, 67, 0.94), rgba(17, 25, 45, 0.92));
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
  overflow: hidden;
  transition: transform 180ms ease, opacity 180ms ease;
}

.panel-toggle {
  position: absolute;
  top: 50%;
  right: calc(min(410px, calc(100vw - 28px)) + 15px);
  z-index: 540;
  width: 34px;
  height: 74px;
  border: 1px solid var(--line);
  border-right: 0;
  border-radius: 8px 0 0 8px;
  color: #eaf2ff;
  background: rgba(21, 29, 52, 0.92);
  box-shadow: var(--shadow);
  cursor: pointer;
  font-size: 30px;
  line-height: 1;
  transform: translateY(-50%);
  transition: right 180ms ease, background 180ms ease;
}

.panel-toggle:hover {
  background: rgba(45, 134, 255, 0.9);
}

.panel-collapsed .panel {
  transform: translateX(calc(100% + 18px));
  opacity: 0;
  pointer-events: none;
}

.panel-collapsed .panel-toggle {
  right: 0;
  border-right: 1px solid var(--line);
  border-radius: 8px 0 0 8px;
}

.panel-collapsed .top-bar {
  right: 62px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.panel h2 {
  font-size: 14px;
  line-height: 1.2;
  letter-spacing: 0;
}

.panel p,
.search span {
  color: var(--muted);
  font-size: 12px;
}

#countBadge {
  display: inline-grid;
  place-items: center;
  min-width: 38px;
  height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  color: #dfeaff;
  border: 1px solid rgba(119, 157, 255, 0.42);
  background: rgba(58, 83, 139, 0.5);
  font-weight: 800;
  font-size: 12px;
}

.search {
  display: grid;
  gap: 7px;
}

.search input {
  width: 100%;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  color: var(--text);
  background: rgba(9, 15, 29, 0.45);
  outline: none;
}

.search input:focus {
  border-color: var(--accent);
}

.filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
}

.filter {
  height: 30px;
  padding: 0 6px;
  color: var(--muted);
}

.filter.active {
  color: #eaf2ff;
  border-color: transparent;
  background: var(--zello);
  font-weight: 800;
}

.overlay-panel {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: rgba(9, 15, 29, 0.34);
}

.overlay-heading h3 {
  margin: 0;
  font-size: 14px;
  line-height: 1.2;
  letter-spacing: 0;
}

.overlay-heading p {
  margin-top: 3px;
}

.file-picker {
  display: grid;
  gap: 7px;
}

.file-picker span {
  color: var(--muted);
  font-size: 12px;
}

.file-picker input {
  width: 100%;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
}

.file-picker input::file-selector-button {
  height: 32px;
  margin-right: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: var(--panel);
  cursor: pointer;
}

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

.overlay-actions button {
  height: 32px;
  min-width: 0;
  padding: 0 6px;
  color: var(--muted);
  font-size: 12px;
}

.waypoint-editor {
  display: grid;
  gap: 9px;
  padding-top: 2px;
}

.waypoint-editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.waypoint-editor h4 {
  margin: 0;
  font-size: 13px;
  line-height: 1.2;
  letter-spacing: 0;
}

#waypointCount {
  display: inline-grid;
  place-items: center;
  min-width: 28px;
  height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  color: var(--muted);
  background: var(--panel);
  font-size: 12px;
  font-weight: 800;
}

.waypoint-list {
  display: grid;
  gap: 9px;
  max-height: 330px;
  overflow: auto;
  padding-right: 2px;
}

.waypoint-card {
  display: grid;
  gap: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: rgba(10, 14, 19, 0.58);
}

.waypoint-card.selected {
  border-color: var(--accent);
}

.waypoint-card label,
.waypoint-card-head,
.waypoint-controls {
  min-width: 0;
}

.waypoint-card label {
  display: grid;
  gap: 5px;
}

.waypoint-card label span {
  color: var(--muted);
  font-size: 11px;
}

.waypoint-card input[type="text"],
.waypoint-card textarea,
.waypoint-card select {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: var(--panel);
  outline: none;
}

.waypoint-card input[type="text"],
.waypoint-card select {
  height: 32px;
  padding: 0 9px;
}

.waypoint-card textarea {
  resize: vertical;
  min-height: 52px;
  padding: 8px 9px;
}

.waypoint-card input:focus,
.waypoint-card textarea:focus,
.waypoint-card select:focus {
  border-color: var(--accent);
}

.waypoint-card-head {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 8px;
  align-items: end;
}

.waypoint-focus {
  width: 34px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: #06120f;
  background: var(--accent);
  cursor: pointer;
  font-weight: 900;
}

.waypoint-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 74px;
  gap: 8px;
  align-items: end;
}

.waypoint-card input[type="color"] {
  width: 74px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px;
  background: var(--panel);
}

.user-list {
  display: grid;
  align-content: start;
  gap: 9px;
  flex-grow: 1;
  flex-shrink: 1;
  flex-basis: 0;
  min-height: 0;
  overflow: auto;
  padding-right: 3px;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.user-card {
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 7px 8px;
  background: transparent;
  cursor: pointer;
}

.user-card:hover {
  border-color: rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.05);
}

.user-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(68, 215, 182, 0.35);
}

.user-card.following {
  border-color: rgba(45, 134, 255, 0.88);
  background: rgba(45, 134, 255, 0.13);
}

.user-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.user-name {
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr);
  align-items: start;
  gap: 8px;
  min-width: 0;
}

.vehicle-title {
  min-width: 0;
}

.vehicle-title strong,
.vehicle-title span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.vehicle-title strong {
  font-size: 15px;
  font-weight: 900;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.55);
}

.vehicle-title span,
.user-meta,
.empty {
  color: var(--muted);
  font-size: 12px;
}

.status-pill {
  display: none;
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 4px 8px;
  color: #06120f;
  background: var(--accent);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.status-pill.standby {
  background: var(--warning);
}

.status-pill.stale {
  background: var(--danger);
}

.user-meta {
  display: none;
  grid-template-columns: 1fr 1fr;
  gap: 5px 10px;
  margin-top: 11px;
}

.vehicle-actions {
  display: none;
}

.user-card.selected .user-meta {
  display: grid;
}

.user-card.selected .vehicle-actions {
  display: block;
}

.history-button {
  width: 100%;
  height: 32px;
  margin-top: 7px;
  color: var(--muted);
}

.follow-button {
  width: 100%;
  height: 32px;
  margin-top: 7px;
  color: #eaf2ff;
  background: rgba(45, 134, 255, 0.28);
}

.user-card.following .follow-button {
  color: #ffffff;
  border-color: rgba(108, 170, 255, 0.9);
  background: var(--zello);
  font-weight: 900;
}

.vehicle-dot {
  display: block;
  width: 9px;
  height: 9px;
  border: 1px solid rgba(255, 255, 255, 0.58);
  border-radius: 999px;
  background: #8fa2c5;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.28);
}

.vehicle-dot.online {
  background: #9dff1f;
}

.vehicle-dot.standby {
  background: #b9c4d7;
}

.vehicle-dot.stale {
  background: #ff3b4f;
}

.copy-coords {
  width: 100%;
  height: 32px;
  margin-top: 7px;
  color: var(--muted);
  background: rgba(11, 17, 31, 0.58);
}

.waypoint-card .copy-coords {
  margin-top: 0;
}

.popup-copy {
  margin-top: 10px;
}

.toast {
  position: absolute;
  left: 16px;
  bottom: 18px;
  z-index: 500;
  max-width: min(520px, calc(100% - 32px));
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(12, 16, 21, 0.9);
  color: var(--text);
  box-shadow: var(--shadow);
  font-size: 13px;
}

.unit-marker {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 2px solid #ffffff;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.38);
}

.unit-marker::after {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #06120f;
}

.unit-marker.standby {
  background: var(--warning);
}

.unit-marker.stale {
  background: var(--danger);
}

.dropped-pin-marker {
  width: 34px;
  height: 34px;
  border: 2px solid #ffffff;
  border-radius: 50% 50% 50% 0;
  background: #ff4f9a;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.42);
  transform: rotate(-45deg);
}

.dropped-pin-marker::after {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 50%;
  background: #071310;
}

.my-location-marker {
  position: relative;
  width: 34px;
  height: 34px;
  border: 3px solid #ffffff;
  border-radius: 999px;
  background: #2d86ff;
  box-shadow: 0 0 0 6px rgba(45, 134, 255, 0.25), 0 4px 18px rgba(0, 0, 0, 0.42);
}

.my-location-marker::after {
  content: "";
  position: absolute;
  inset: 9px;
  border-radius: 999px;
  background: #ffffff;
}

.drop-pin-mode {
  cursor: crosshair;
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  background: rgba(20, 29, 54, 0.96);
  color: var(--text);
  border: 1px solid rgba(209, 221, 255, 0.16);
  box-shadow: var(--shadow);
}

.leaflet-popup-content-wrapper {
  border-radius: 8px;
}

.leaflet-popup-content {
  min-width: 250px;
  margin: 16px;
}

.popup-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  margin-bottom: 10px;
  font-size: 20px;
}

.popup-title::before {
  content: "▤";
  color: #e9f0ff;
  font-size: 17px;
}

.source-tag {
  display: inline-block;
  margin-bottom: 14px;
  padding: 3px 8px;
  border: 1px solid rgba(66, 147, 255, 0.78);
  border-radius: 4px;
  color: #cfe4ff;
  background: rgba(0, 88, 218, 0.42);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0;
}

.popup-grid {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 7px 8px;
  color: #f1f5ff;
  font-size: 16px;
  line-height: 1.15;
}

.popup-grid span {
  color: #f1f5ff;
}

.popup-grid strong {
  color: #ffffff;
  font-weight: 900;
}

.stale-warning {
  margin-top: 13px;
  color: var(--warning);
  font-size: 16px;
  font-weight: 900;
}

.overlay-popup {
  max-width: 260px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  white-space: pre-wrap;
}

.waypoint-popup-grid {
  margin-top: 8px;
}

.waypoint-marker {
  position: relative;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 2px solid #ffffff;
  color: #06120f;
  background: var(--waypoint-color);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.42);
  font-size: 12px;
  font-weight: 900;
  line-height: 1;
}

.waypoint-marker.pin {
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
}

.waypoint-marker.pin span {
  transform: rotate(45deg);
}

.waypoint-marker.pin::after {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #06120f;
}

.waypoint-marker.flag {
  border-radius: 4px;
  clip-path: polygon(12% 8%, 82% 8%, 68% 32%, 86% 55%, 12% 55%);
}

.waypoint-marker.star {
  clip-path: polygon(50% 5%, 61% 36%, 95% 36%, 68% 56%, 79% 91%, 50% 70%, 21% 91%, 32% 56%, 5% 36%, 39% 36%);
}

.waypoint-marker.check,
.waypoint-marker.number {
  border-radius: 8px;
}

@media (max-width: 820px) {
  .app-shell {
    display: block;
  }

  .panel {
    top: auto;
    right: 10px;
    bottom: 12px;
    left: 10px;
    width: auto;
    height: 45vh;
    max-height: 45vh;
    min-height: 0;
    padding: 12px;
  }

  .panel-toggle {
    top: auto;
    right: 18px;
    bottom: calc(45vh + 12px);
    width: 74px;
    height: 34px;
    border-right: 1px solid var(--line);
    border-bottom: 0;
    border-radius: 8px 8px 0 0;
    transform: none;
  }

  .panel-collapsed .panel {
    transform: translateY(calc(100% + 18px));
  }

  .panel-collapsed .panel-toggle {
    right: 18px;
    bottom: 0;
  }

  .top-bar {
    right: 10px;
    align-items: flex-start;
    gap: 10px;
  }

  .controls {
    flex-direction: column;
  }

  .controls button {
    min-width: 68px;
    min-height: 34px;
  }
}

/* Compact field mode: keep map readable while shrinking app text. */
.top-bar h1 {
  font-size: 8px;
}

.top-bar p,
.panel p,
.search span,
.file-picker span,
.waypoint-card label span,
.vehicle-title span,
.user-meta,
.empty,
.overlay-actions button,
.filter,
.controls button,
.history-button,
.follow-button,
.copy-coords,
.file-picker input,
.panel input,
.panel textarea,
.panel select {
  font-size: 6px;
}

.panel h2,
.overlay-heading h3,
.waypoint-editor h4 {
  font-size: 7px;
}

.vehicle-title strong {
  font-size: 8px;
}

#countBadge,
#waypointCount,
.status-pill {
  font-size: 6px;
}

.source-tag {
  font-size: 7px;
}

.popup-title {
  font-size: 10px;
}

.popup-title::before {
  font-size: 9px;
}

.popup-grid,
.overlay-popup,
.stale-warning {
  font-size: 8px;
}
