:root {
  color-scheme: dark;
  --bg: #07111f;
  --bg-soft: #0b1628;
  --panel: rgba(10, 18, 33, 0.92);
  --panel-strong: rgba(12, 22, 40, 0.98);
  --panel-border: rgba(148, 163, 184, 0.16);
  --panel-border-strong: rgba(148, 163, 184, 0.24);
  --text: #eef5ff;
  --muted: #93a4bf;
  --muted-2: #6f8098;
  --accent: #63d2ff;
  --accent-2: #7cfe9a;
  --warn: #ffcc66;
  --danger: #ff6b82;
  --good: #42d392;
  --shadow: 0 24px 72px rgba(0, 0, 0, 0.48);
  --radius-lg: 24px;
  --radius-md: 18px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(99, 210, 255, 0.12), transparent 36%),
    radial-gradient(circle at 80% 12%, rgba(66, 211, 146, 0.10), transparent 30%),
    radial-gradient(circle at 50% 80%, rgba(255, 204, 102, 0.09), transparent 34%),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  touch-action: manipulation;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.topbar {
  position: relative;
  z-index: 700;
  padding: max(8px, env(safe-area-inset-top)) 10px 8px;
  background: linear-gradient(180deg, rgba(6, 12, 22, 0.94), rgba(6, 12, 22, 0.78));
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
}

.topbar-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.brand-kicker {
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted-2);
}

.brand-title {
  font-size: 15px;
  font-weight: 720;
  line-height: 1.2;
}

.topbar-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 6px;
}

.topbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.top-action {
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.16);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
}

.top-action.is-muted {
  opacity: 0.78;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border-radius: 999px;
  font-size: 11px;
  letter-spacing: 0.03em;
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(148, 163, 184, 0.14);
  white-space: nowrap;
}

.badge-warm {
  background: rgba(255, 204, 102, 0.14);
  border-color: rgba(255, 204, 102, 0.22);
  color: #ffe8b0;
  text-transform: uppercase;
}

.diagnostics {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.control-drawer {
  display: grid;
  gap: 10px;
  margin-top: 10px;
  overflow: hidden;
  max-height: 480px;
  opacity: 1;
  transition: max-height 0.24s ease, opacity 0.24s ease, margin-top 0.24s ease;
}

.app-shell.is-controls-hidden .control-drawer {
  max-height: 0;
  opacity: 0;
  margin-top: 0;
}

.diag-card {
  min-width: 0;
  padding: 10px 9px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(148, 163, 184, 0.12);
}

.diag-label {
  font-size: 10px;
  color: var(--muted-2);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 4px;
}

.diag-value {
  font-size: 15px;
  font-weight: 700;
}

.layer-switches {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.layer-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 11px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.14);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  user-select: none;
  transition: transform 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}

.layer-switch:active,
.action-button:active,
.target-chip:active {
  transform: scale(0.98);
}

.layer-switch.is-active {
  background: rgba(99, 210, 255, 0.12);
  border-color: rgba(99, 210, 255, 0.3);
}

.layer-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.04);
}

.map-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
}

.map {
  position: absolute;
  inset: 0;
  background: #f4f8fb;
}

.leaflet-container {
  font: inherit;
  background: #f4f8fb;
  outline: none;
}

.leaflet-control-attribution {
  font-size: 10px;
  background: rgba(8, 15, 28, 0.75) !important;
  color: rgba(238, 245, 255, 0.72) !important;
  border: 1px solid rgba(148, 163, 184, 0.12);
  border-radius: 12px;
}

.leaflet-control-attribution a {
  color: #8bd0ff !important;
}

.map-overlay {
  position: absolute;
  z-index: 650;
  pointer-events: none;
  max-width: 50vw;
  padding: 10px 12px;
  border-radius: 18px;
  background: rgba(6, 12, 22, 0.72);
  border: 1px solid rgba(148, 163, 184, 0.12);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.28);
}

.map-overlay-left {
  top: 12px;
  left: 12px;
}

.map-overlay-right {
  top: 12px;
  right: 12px;
  text-align: right;
}

.overlay-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted-2);
  margin-bottom: 4px;
}

.overlay-value {
  font-size: 12px;
  font-weight: 650;
  color: var(--text);
}

.bottom-sheet {
  position: relative;
  z-index: 700;
  padding: 8px 12px max(14px, env(safe-area-inset-bottom)) 12px;
  background: linear-gradient(180deg, rgba(6, 12, 22, 0.12), rgba(6, 12, 22, 0.88) 24%, rgba(6, 12, 22, 0.98));
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid rgba(148, 163, 184, 0.14);
  box-shadow: 0 -16px 50px rgba(0, 0, 0, 0.28);
  max-height: 46vh;
  overflow: auto;
  transition: max-height 0.24s ease, transform 0.24s ease;
}

.bottom-sheet.is-collapsed {
  max-height: 88px;
  overflow: hidden;
}

.sheet-handle {
  width: 54px;
  height: 5px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.28);
  margin: 0 auto 10px;
}

.sheet-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.sheet-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.sheet-kicker {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted-2);
  margin-bottom: 6px;
}

.sheet-title {
  font-size: 20px;
  line-height: 1.1;
  margin: 0;
  font-weight: 760;
}

.status-pill {
  flex: 0 0 auto;
  padding: 8px 11px;
  border-radius: 999px;
  background: rgba(99, 210, 255, 0.12);
  color: #b8e9ff;
  border: 1px solid rgba(99, 210, 255, 0.24);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.status-pill-button {
  border: 0;
  cursor: pointer;
  pointer-events: auto;
}

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

.stat-card,
.panel-box {
  padding: 12px 11px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(148, 163, 184, 0.12);
}

.stat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted-2);
  margin-bottom: 5px;
}

.stat-value {
  font-size: 18px;
  font-weight: 760;
}

.sheet-note {
  margin-top: 10px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--muted);
}

.targets-panel,
.problem-list-wrap {
  margin-top: 12px;
}

.panel-label {
  font-size: 11px;
  color: var(--muted-2);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
}

.target-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.target-chip {
  padding: 8px 10px;
  border-radius: 999px;
  background: rgba(99, 210, 255, 0.10);
  border: 1px solid rgba(99, 210, 255, 0.20);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}

.target-chip.is-active {
  background: rgba(66, 211, 146, 0.14);
  border-color: rgba(66, 211, 146, 0.28);
}

.problem-list {
  display: grid;
  gap: 8px;
}

.problem-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px 11px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(148, 163, 184, 0.10);
}

.problem-item-title {
  font-size: 13px;
  font-weight: 650;
}

.problem-item-sub {
  font-size: 12px;
  color: var(--muted);
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 14px;
}

.action-button {
  min-height: 42px;
  border-radius: 14px;
  border: 1px solid rgba(148, 163, 184, 0.14);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-weight: 670;
  font-size: 13px;
  cursor: pointer;
}

.action-button.primary {
  background: linear-gradient(135deg, rgba(66, 211, 146, 0.22), rgba(99, 210, 255, 0.20));
  border-color: rgba(99, 210, 255, 0.24);
}

.action-button.accent {
  background: linear-gradient(135deg, rgba(255, 204, 102, 0.20), rgba(255, 107, 130, 0.20));
  border-color: rgba(255, 204, 102, 0.22);
}

.boot {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 20%, rgba(99, 210, 255, 0.12), transparent 32%),
    radial-gradient(circle at 30% 72%, rgba(66, 211, 146, 0.08), transparent 30%),
    #07111f;
}

.boot.is-hidden {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.boot-card {
  width: min(440px, calc(100vw - 32px));
  padding: 24px 20px;
  border-radius: 28px;
  background: rgba(8, 15, 28, 0.95);
  border: 1px solid rgba(148, 163, 184, 0.16);
  box-shadow: var(--shadow);
}

.boot-kicker {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--muted-2);
  margin-bottom: 8px;
}

.boot-title {
  font-size: 23px;
  font-weight: 780;
  margin-bottom: 8px;
}

.boot-subtitle {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
}

.boot-pulse {
  display: flex;
  gap: 8px;
  margin-top: 18px;
}

.boot-pulse span {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--accent);
  animation: bootPulse 1.2s infinite ease-in-out;
}

.boot-pulse span:nth-child(2) {
  background: var(--warn);
  animation-delay: 0.15s;
}

.boot-pulse span:nth-child(3) {
  background: var(--good);
  animation-delay: 0.3s;
}

@keyframes bootPulse {
  0%, 100% { transform: translateY(0); opacity: 0.45; }
  50% { transform: translateY(-5px); opacity: 1; }
}

.toast-host {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(52vh + 18px);
  z-index: 1300;
  display: grid;
  justify-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 10px 13px;
  border-radius: 999px;
  background: rgba(10, 18, 33, 0.96);
  border: 1px solid rgba(148, 163, 184, 0.18);
  box-shadow: var(--shadow);
  font-size: 12px;
  color: var(--text);
}

.noscript {
  position: fixed;
  inset: auto 12px 12px 12px;
  z-index: 1400;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(24, 8, 10, 0.94);
  color: #ffd7dd;
  border: 1px solid rgba(255, 107, 130, 0.22);
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  background: rgba(10, 18, 33, 0.98);
  color: var(--text);
  border: 1px solid rgba(148, 163, 184, 0.16);
  box-shadow: var(--shadow);
}

.leaflet-popup-content {
  margin: 10px 12px;
}

.leaflet-popup-content strong {
  display: block;
  margin-bottom: 4px;
}

.leaflet-control-zoom {
  border: 1px solid rgba(148, 163, 184, 0.18) !important;
  box-shadow: var(--shadow) !important;
}

.leaflet-control-zoom a {
  background: rgba(10, 18, 33, 0.94) !important;
  color: var(--text) !important;
}

@media (max-width: 480px) {
  .topbar {
    padding-left: 10px;
    padding-right: 10px;
  }

  .topbar-row {
    align-items: center;
  }

  .topbar-actions {
    flex-direction: column;
    align-items: flex-end;
  }

  .sheet-title {
    font-size: 18px;
  }

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

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

  .map-overlay {
    max-width: 60vw;
  }

  .toast-host {
    bottom: calc(50vh + 14px);
  }

  .bottom-sheet.is-collapsed {
    max-height: 82px;
  }
}

.app-shell.is-controls-hidden .topbar {
  border-bottom-color: rgba(148, 163, 184, 0.08);
}

.app-shell.is-sheet-open .bottom-sheet {
  max-height: 46vh;
}
