*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0f172a;
  color: #e2e8f0;
}

#map {
  position: fixed;
  inset: 0;
  z-index: 0;
}

.leaflet-floorplan-overlay svg {
  display: block;
  width: 100%;
  height: 100%;
}

.leaflet-floorplan-overlay img {
  display: block;
  width: 100%;
  height: 100%;
}

.hud {
  position: fixed;
  z-index: 500;
  backdrop-filter: blur(12px);
  background: rgba(15, 23, 42, 0.82);
  border: 1px solid rgba(148, 163, 184, 0.18);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.hud--top {
  top: max(0.75rem, env(safe-area-inset-top));
  left: max(0.75rem, env(safe-area-inset-left));
  right: max(0.75rem, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem;
  border-radius: 1rem;
}

.hud--mode {
  top: calc(max(0.75rem, env(safe-area-inset-top)) + 4.6rem);
  left: max(0.75rem, env(safe-area-inset-left));
  padding: 0.35rem;
  border-radius: 0.85rem;
}

.hud--indoor {
  top: calc(max(0.75rem, env(safe-area-inset-top)) + 7.4rem);
  left: max(0.75rem, env(safe-area-inset-left));
  right: max(0.75rem, env(safe-area-inset-right));
  padding: 0.85rem 1rem;
  border-radius: 1rem;
}

.indoor-panel__head {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.65rem;
}

.indoor-panel__title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
}

.indoor-panel__close {
  appearance: none;
  border: 0;
  background: transparent;
  color: #94a3b8;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.15rem 0.4rem;
}

.stats-panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.stats-panel__title {
  display: none;
  flex: 1;
  font-size: 0.82rem;
  font-weight: 600;
}

.stats-panel__close {
  appearance: none;
  border: 0;
  background: transparent;
  color: #94a3b8;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.1rem 0.35rem;
  flex-shrink: 0;
}

.stats-panel__close:hover {
  color: #e2e8f0;
}

.hud--panel:not(.hud--panel-collapsed) .stats-panel__head {
  margin-bottom: 0.65rem;
}

.stats-panel__toggle {
  display: none;
  flex: 1;
  min-width: 0;
  appearance: none;
  border: 0;
  background: transparent;
  color: #e2e8f0;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0;
  cursor: pointer;
  text-align: left;
}

.stats-panel__toggle-icon {
  float: right;
  color: #94a3b8;
  transition: transform 0.2s ease;
}

.hud--panel:not(.hud--panel-collapsed) .stats-panel__toggle-icon {
  transform: rotate(180deg);
}

.fab {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 0.55rem 0.95rem;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  z-index: 600;
}

.fab--filters {
  position: fixed;
  left: max(0.75rem, env(safe-area-inset-left));
  bottom: calc(max(0.75rem, env(safe-area-inset-bottom)) + 3.25rem);
  background: #2563eb;
  color: #fff;
}

.fab--stats {
  position: fixed;
  right: max(0.75rem, env(safe-area-inset-right));
  bottom: max(0.75rem, env(safe-area-inset-bottom));
  background: rgba(15, 23, 42, 0.92);
  color: #e2e8f0;
  border: 1px solid rgba(148, 163, 184, 0.25);
}

body.stats-panel-hidden #map {
  bottom: max(0.75rem, env(safe-area-inset-bottom));
}

body.stats-panel-hidden .fab--filters {
  bottom: max(0.75rem, env(safe-area-inset-bottom));
}

.fab[hidden] {
  display: none !important;
}

body.indoor-sheet-open::after {
  content: "";
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 840;
  pointer-events: none;
}

.hud--panel {
  left: max(0.75rem, env(safe-area-inset-left));
  right: max(0.75rem, env(safe-area-inset-right));
  bottom: max(0.75rem, env(safe-area-inset-bottom));
  padding: 1rem;
  border-radius: 1rem;
}

.mode-tabs {
  display: flex;
  gap: 0.35rem;
}

.mode-tab {
  appearance: none;
  border: 0;
  border-radius: 0.55rem;
  padding: 0.45rem 0.85rem;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  color: #94a3b8;
  background: transparent;
  cursor: pointer;
}

.mode-tab.is-active {
  color: #fff;
  background: #2563eb;
}

.indoor-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}

.field--wide {
  grid-column: 1 / -1;
}

.field__label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #94a3b8;
}

.field__input {
  width: 100%;
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 0.55rem;
  padding: 0.5rem 0.65rem;
  font: inherit;
  font-size: 0.82rem;
  color: #e2e8f0;
  background: rgba(30, 41, 59, 0.85);
}

.panel-row--indoor {
  margin-top: 0.65rem;
}

.hint {
  margin: 0.65rem 0 0;
  font-size: 0.75rem;
  line-height: 1.45;
  color: #94a3b8;
}

.btn.is-active {
  background: rgba(37, 99, 235, 0.25);
  color: #bfdbfe;
}

.floor-prompt {
  position: fixed;
  left: max(0.75rem, env(safe-area-inset-left));
  right: max(0.75rem, env(safe-area-inset-right));
  bottom: calc(max(0.75rem, env(safe-area-inset-bottom)) + 11.5rem);
  z-index: 700;
  padding: 1rem;
  border-radius: 1rem;
  background: rgba(30, 58, 138, 0.95);
  border: 1px solid rgba(147, 197, 253, 0.35);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.floor-prompt__title {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 700;
}

.floor-prompt__text {
  margin: 0.45rem 0 0.85rem;
  font-size: 0.82rem;
  color: #dbeafe;
}

.floor-prompt__actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.hud__brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.hud__dot {
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 999px;
  background: #64748b;
  flex-shrink: 0;
  box-shadow: 0 0 0 4px rgba(100, 116, 139, 0.2);
}

.hud__dot.is-live {
  background: #22c55e;
  box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.25);
  animation: pulse 1.4s ease-in-out infinite;
}

.hud__dot.is-error {
  background: #ef4444;
  box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.25);
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.15);
  }
}

.hud__title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.hud__subtitle {
  margin: 0.15rem 0 0;
  font-size: 0.78rem;
  color: #94a3b8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud__actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.btn {
  appearance: none;
  border: 0;
  border-radius: 0.65rem;
  padding: 0.55rem 0.9rem;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease, background 0.12s ease;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

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

.btn--primary {
  background: #2563eb;
  color: #fff;
}

.btn--primary:hover:not(:disabled) {
  background: #1d4ed8;
}

.btn--ghost {
  background: rgba(148, 163, 184, 0.12);
  color: #e2e8f0;
}

.btn--ghost:hover:not(:disabled) {
  background: rgba(148, 163, 184, 0.2);
}

.btn--small {
  padding: 0.45rem 0.7rem;
  font-size: 0.78rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.65rem;
}

.stat {
  min-width: 0;
  padding: 0.55rem 0.65rem;
  border-radius: 0.65rem;
  background: rgba(30, 41, 59, 0.75);
}

.stat__label {
  display: block;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #94a3b8;
  margin-bottom: 0.2rem;
}

.stat__value {
  display: block;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat--precise .stat__value {
  font-size: 0.76rem;
  letter-spacing: -0.01em;
  overflow: visible;
  text-overflow: clip;
}

.panel-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.85rem;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.82rem;
  color: #cbd5e1;
  cursor: pointer;
  user-select: none;
}

.toggle input {
  accent-color: #2563eb;
}

.meta {
  margin: 0.75rem 0 0;
  font-size: 0.75rem;
  color: #94a3b8;
}

.error-banner {
  position: fixed;
  top: 5.5rem;
  left: max(0.75rem, env(safe-area-inset-left));
  right: max(0.75rem, env(safe-area-inset-right));
  z-index: 600;
  padding: 0.85rem 1rem;
  border-radius: 0.85rem;
  background: rgba(127, 29, 29, 0.92);
  border: 1px solid rgba(248, 113, 113, 0.35);
  color: #fecaca;
  font-size: 0.875rem;
}

.user-marker {
  position: relative;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: #2563eb;
  border: 3px solid #fff;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.45), 0 4px 12px rgba(0, 0, 0, 0.35);
}

.user-marker__cone {
  position: absolute;
  top: -14px;
  left: 50%;
  width: 0;
  height: 0;
  margin-left: -7px;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-bottom: 14px solid rgba(37, 99, 235, 0.55);
  transform-origin: 50% 100%;
}

.user-marker__pulse {
  position: absolute;
  inset: -10px;
  border-radius: 999px;
  border: 2px solid rgba(37, 99, 235, 0.45);
  animation: marker-pulse 1.8s ease-out infinite;
}

@keyframes marker-pulse {
  0% {
    transform: scale(0.5);
    opacity: 0.9;
  }
  100% {
    transform: scale(1.8);
    opacity: 0;
  }
}

.reference-marker {
  position: relative;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  border: 3px solid #ef4444;
  background: rgba(239, 68, 68, 0.15);
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.35);
}

.reference-marker__label {
  position: absolute;
  left: 50%;
  top: -1.4rem;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 0.65rem;
  font-weight: 600;
  color: #fecaca;
  background: rgba(127, 29, 29, 0.9);
  padding: 0.15rem 0.4rem;
  border-radius: 0.35rem;
  pointer-events: none;
}

@media (max-width: 640px) {
  #map {
    top: calc(4.75rem + env(safe-area-inset-top));
    bottom: calc(2.85rem + env(safe-area-inset-bottom));
  }

  .hud--top {
    flex-direction: row;
    align-items: center;
    padding: 0.5rem 0.65rem;
    gap: 0.5rem;
  }

  .hud__brand {
    flex: 1;
    min-width: 0;
  }

  .hud__subtitle {
    display: none;
  }

  .hud__title {
    font-size: 0.88rem;
  }

  .hud__actions {
    width: auto;
    flex-shrink: 0;
  }

  .hud__actions .btn {
    flex: 0 0 auto;
    padding: 0.45rem 0.65rem;
    font-size: 0.78rem;
  }

  .hud--mode {
    top: calc(max(0.75rem, env(safe-area-inset-top)) + 2.65rem);
    left: max(0.75rem, env(safe-area-inset-left));
    padding: 0.2rem;
  }

  .mode-tab {
    padding: 0.35rem 0.65rem;
    font-size: 0.75rem;
  }

  .hud--indoor.indoor-panel--sheet {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: min(72vh, 520px);
    overflow: auto;
    border-radius: 1rem 1rem 0 0;
    transform: translateY(110%);
    transition: transform 0.25s ease;
    z-index: 850;
    display: block;
  }

  .hud--indoor.indoor-panel--sheet.is-open {
    transform: translateY(0);
  }

  .hud--indoor.indoor-panel--sheet[hidden] {
    display: none !important;
  }

  .indoor-panel__head {
    display: flex;
  }

  .hud--panel {
    padding: 0.55rem 0.75rem;
    max-height: none;
  }

  .stats-panel__toggle {
    display: block;
    flex: 1;
    min-width: 0;
  }

  .hud--panel-collapsed .stats-panel__head {
    margin-bottom: 0;
  }

  .hud--panel-collapsed .stats-panel__body {
    display: none;
  }

  .hud--panel:not(.hud--panel-collapsed) {
    max-height: min(42vh, 320px);
    overflow: auto;
  }

  .hud--panel:not(.hud--panel-collapsed) {
    bottom: max(0.75rem, env(safe-area-inset-bottom));
  }

  .hud--panel-collapsed {
    bottom: max(0.75rem, env(safe-area-inset-bottom));
  }

  .floor-prompt {
    bottom: calc(max(0.75rem, env(safe-area-inset-bottom)) + 4rem);
  }

  .indoor-grid {
    grid-template-columns: 1fr;
  }

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

  .panel-row {
    margin-top: 0.55rem;
  }

  .meta {
    margin-top: 0.55rem;
  }
}

@media (min-width: 641px) {
  .indoor-panel__head,
  .fab--filters {
    display: none !important;
  }

  .stats-panel__title {
    display: block;
  }

  .stats-panel__head {
    margin-bottom: 0.65rem;
  }
}
