:root {
  --bg: #0a0c10;
  --panel: #141820;
  --panel-border: #2a3140;
  --text: #e8edf4;
  --muted: #8b95a8;
  --accent: #c9a227;
  --accent-dim: #8a7018;
  --primary: #3d8f6a;
  --primary-hover: #4caa7e;
  --locate: #6ec8ff;
  --danger-line: #b85c4a;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
  --radius: 14px;
  --font: "IBM Plex Sans", system-ui, sans-serif;
  --serif: "IBM Plex Serif", Georgia, serif;
}

* {
  box-sizing: border-box;
}

html,
body,
#app {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
}

#app {
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.15rem;
  background:
    linear-gradient(180deg, rgba(18, 22, 30, 0.97), rgba(10, 12, 16, 0.94)),
    radial-gradient(circle at 8% 0%, rgba(110, 200, 255, 0.1), transparent 42%),
    radial-gradient(circle at 90% 0%, rgba(201, 162, 39, 0.08), transparent 40%);
  border-bottom: 1px solid var(--panel-border);
  z-index: 500;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-mark {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(201, 162, 39, 0.2);
}

.brand h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.45rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  line-height: 1.1;
}

.brand p {
  margin: 0.1rem 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-right: 0.25rem;
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}

.toggle:has(input:checked) {
  border-color: var(--accent);
  color: var(--accent);
}

.toggle input {
  accent-color: var(--accent);
  margin: 0;
}

.bus-marker {
  background: transparent;
  border: none;
}

.bus-icon {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transform: rotate(var(--bearing, 0deg));
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.35));
  transition: transform 0.15s ease;
}

.bus-icon:hover {
  transform: rotate(var(--bearing, 0deg)) scale(1.2);
}

.bus-icon svg {
  display: block;
}

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.55rem 1rem;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease,
    transform 0.15s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--primary);
  color: #f4fff8;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--panel-border);
}

.btn-ghost:hover,
.btn-ghost[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.map-shell {
  position: relative;
  min-height: 0;
}

.map-controls {
  position: absolute;
  top: 1rem;
  right: 1rem;
  z-index: 460;
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 3px;
  border-radius: 14px;
  background: rgba(14, 17, 24, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
}

.map-ctrl {
  appearance: none;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 11px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, transform 0.12s ease;
}

.map-ctrl:hover {
  background: rgba(110, 200, 255, 0.12);
  color: var(--locate);
}

.map-ctrl:active {
  transform: scale(0.96);
  background: rgba(110, 200, 255, 0.18);
}

.map-ctrl + .map-ctrl {
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 0 0 11px 11px;
}

.map-ctrl:first-child {
  border-radius: 11px 11px 0 0;
}

.map-controls .map-ctrl:only-child,
.map-controls .map-ctrl:first-child:last-child {
  border-radius: 11px;
  border-top: none;
}

#map {
  width: 100%;
  height: 100%;
  background: #1a1d24;
}

.leaflet-container {
  font: inherit;
  background: #1a1d24;
}

.metro-marker {
  background: transparent;
  border: none;
}

.metro-label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  cursor: pointer;
}

.metro-label:hover .metro-name,
.metro-label:focus-visible .metro-name {
  background: rgba(28, 34, 44, 0.98);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.metro-label:hover .metro-dot,
.metro-label:focus-visible .metro-dot {
  background: var(--locate);
  border-color: #fff;
}

.metro-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #d7dee8;
  border: 1.5px solid #0a0c10;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.2);
}

.metro-name {
  font-family: var(--font);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: #e8edf4;
  background: rgba(16, 20, 28, 0.82);
  padding: 1px 5px 1px 4px;
  border-radius: 3px;
  line-height: 1.2;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.hint {
  position: absolute;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%);
  z-index: 450;
  max-width: min(92vw, 420px);
  padding: 0.7rem 1rem;
  background: rgba(24, 32, 28, 0.94);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  color: var(--text);
  font-size: 0.88rem;
  text-align: center;
  box-shadow: var(--shadow);
  pointer-events: none;
}

.toast {
  position: fixed;
  top: 4.75rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  max-width: min(92vw, 440px);
  padding: 0.75rem 1rem;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  font-size: 0.9rem;
}

.panel {
  width: min(92vw, 420px);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 0;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}

.panel::backdrop {
  background: rgba(6, 10, 8, 0.55);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1rem 0.35rem;
}

.panel-head h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.25rem;
  font-weight: 500;
}

.panel-note {
  margin: 0 1rem 0.75rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.field {
  display: grid;
  gap: 0.35rem;
  padding: 0 1rem 0.85rem;
  font-size: 0.88rem;
}

.field span {
  color: var(--muted);
}

.field select,
.field textarea,
.field input[type="file"] {
  width: 100%;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  background: #101612;
  color: var(--text);
  font: inherit;
  padding: 0.65rem 0.75rem;
}

.field textarea {
  resize: vertical;
  min-height: 4.5rem;
}

.coords {
  margin: 0 1rem 0.5rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.panel-foot {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1rem 1rem;
}

.icon-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.15rem 0.4rem;
}

.icon-btn:hover {
  color: var(--text);
}

.detail-body {
  padding: 0 1rem 0.5rem;
  display: grid;
  gap: 0.75rem;
}

.detail-body .meta {
  color: var(--muted);
  font-size: 0.82rem;
}

.detail-body .label {
  font-weight: 600;
  font-size: 1rem;
}

.cluster-list {
  margin: 0;
  padding-left: 1.1rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.leaflet-tooltip.trace-tip {
  background: rgba(24, 28, 34, 0.92);
  border: 1px solid #3a4250;
  color: #d7dde6;
  font-size: 11px;
  padding: 4px 7px;
  border-radius: 6px;
  box-shadow: none;
}

.leaflet-tooltip.trace-tip::before {
  border-top-color: rgba(24, 28, 34, 0.92);
}

.media-frame {
  overflow: hidden;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: #0b100e;
}

.media-frame img,
.media-frame video {
  display: block;
  width: 100%;
  max-height: 240px;
  object-fit: cover;
}

.marker-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid #fff8dc;
  box-shadow: 0 0 0 3px rgba(201, 162, 39, 0.35), 0 2px 8px rgba(0, 0, 0, 0.4);
  background: var(--accent);
}

.event-marker {
  background: transparent !important;
  border: none !important;
}

.obs-marker {
  position: relative;
  width: 40px;
  height: 40px;
  cursor: pointer;
  filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.35));
  transform: scale(var(--obs-scale, 1));
  opacity: var(--obs-opacity, 1);
  transition: transform 0.15s ease, opacity 0.4s ease;
}

.obs-marker:hover {
  transform: scale(calc(var(--obs-scale, 1) * 1.08));
}

.obs-face {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 20px;
  height: 20px;
  transform: translate(-50%, -50%);
  /* Silhouette PNG is black+alpha — force alpha mask so black stays visible */
  background-color: #1a1d24;
  -webkit-mask-image: url('/police-face.png');
  mask-image: url('/police-face.png');
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
  -webkit-mask-source-type: alpha;
  mask-mode: alpha;
  pointer-events: none;
}

.obs-face.is-pending {
  background-color: #8a7018;
  opacity: 1;
}

.obs-face.is-published {
  background-color: #1e4fb8;
  opacity: 1;
  filter: none;
}

.obs-marker.is-pending {
  animation: obs-breathe 3.2s ease-in-out infinite;
}

@keyframes obs-breathe {
  0%,
  100% {
    filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.28));
  }
  50% {
    filter: drop-shadow(0 2px 8px rgba(47, 111, 237, 0.35));
  }
}

.obs-marker.is-published {
  animation: none;
}

.obs-count {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 14px;
  height: 14px;
  padding: 0 3px;
  border-radius: 999px;
  background: #2f6fed;
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  line-height: 14px;
  text-align: center;
  box-shadow: 0 0 0 1.5px #fff;
}

.witness-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0.15rem 0 0.25rem;
}

.witness {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1.5px solid #9a9a94;
  background: transparent;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.witness.is-filled {
  background: #7eb6ff;
  border-color: #7eb6ff;
  box-shadow: 0 0 0 2px rgba(126, 182, 255, 0.18);
}

.witness-label {
  margin-left: 0.15rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.marker-dot.placing {
  background: var(--primary);
  border-color: #dff7ea;
  box-shadow: 0 0 0 3px rgba(61, 143, 106, 0.35);
}

.user-marker {
  background: transparent !important;
  border: none !important;
}

.user-dot {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 12px;
  height: 12px;
  margin: -6px 0 0 -6px;
  border-radius: 50%;
  background: var(--locate);
  border: 2px solid #fff;
  box-shadow: 0 0 0 2px rgba(110, 200, 255, 0.35);
  z-index: 2;
}

.user-pulse {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 24px;
  height: 24px;
  margin: -12px 0 0 -12px;
  border-radius: 50%;
  background: rgba(110, 200, 255, 0.35);
  animation: user-pulse 2s ease-out infinite;
  z-index: 1;
}

@keyframes user-pulse {
  0% {
    transform: scale(0.55);
    opacity: 0.8;
  }
  100% {
    transform: scale(1.6);
    opacity: 0;
  }
}

.btn.is-loading {
  opacity: 0.7;
  pointer-events: none;
}

.leaflet-control-attribution {
  font-size: 10px !important;
  background: rgba(10, 12, 16, 0.78) !important;
  color: #8b95a8 !important;
}

.leaflet-control-attribution a {
  color: var(--locate) !important;
}

@media (max-width: 640px) {
  .brand p {
    display: none;
  }

  .btn {
    padding: 0.5rem 0.85rem;
    font-size: 0.84rem;
  }

  #btn-locate {
    padding: 0.5rem 0.7rem;
  }
}
