:root {
  color-scheme: light;
  --bg: #f8fafc;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #d8e0ea;
  --panel: rgba(255, 255, 255, 0.94);
  --panel-strong: #ffffff;
  --primary: #008b78;
  --primary-dark: #006f61;
  --brand-blue: #1594e8;
  --brand-orange: #ff7a00;
  --danger: #dc2626;
  --danger-dark: #b91c1c;
  --button: #eef2f7;
  --shadow: 0 -18px 45px rgba(15, 23, 42, 0.16);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

button,
select {
  font: inherit;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-shell {
  position: fixed;
  inset: 0;
  min-height: 100dvh;
  background: var(--bg);
}

.app-shell::before {
  position: absolute;
  inset: 0 0 auto;
  z-index: 1;
  height: 104px;
  pointer-events: none;
  content: "";
  background: linear-gradient(90deg, rgba(219, 245, 239, 0.88), rgba(255, 255, 255, 0.92), rgba(221, 237, 255, 0.9));
}

.map {
  position: absolute;
  inset: 0;
  z-index: 0;
}
.header-tools {
    display: flex;
    align-items: center;
    gap: 12px;
}

.select-wrap {
    position: relative;
    display: inline-block;
}

.select-wrap select {
    min-width: 220px;
    height: 46px;
    padding: 0 42px 0 44px;
    border: 1px solid #c7d8e8;
    border-radius: 12px;
    background: #ffffff;
    color: #202a3a;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 8px 18px rgba(15, 76, 129, 0.06);
}

.select-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    width: 16px;
    height: 16px;
    transform: translateY(-50%);
    color: #202a3a;
    pointer-events: none;
    z-index: 2;
}

.select-icon svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
    display: block;
}

.select-wrap select:hover,
.select-wrap select:focus {
    border-color: rgba(15, 139, 141, 0.48);
    outline: none;
}
.top-bar {
  position: absolute;
  top: calc(12px + var(--safe-top));
  left: 12px;
  right: 12px;
  z-index: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 64px;
  padding: 10px 12px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(202, 220, 237, 0.9);
  border-radius: 8px;
  box-shadow: 0 12px 34px rgba(20, 78, 120, 0.14);
  backdrop-filter: blur(16px);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-logo {
  width: 42px;
  height: 42px;
  padding: 4px;
  object-fit: contain;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 8px 22px rgba(21, 148, 232, 0.16);
}

.brand,
.top-bar h1 {
  margin: 0;
  line-height: 1.1;
}

.brand {
  color: var(--ink);
  font-size: 20px;
  font-weight: 850;
}

.brand::after {
  display: block;
  width: 42px;
  height: 2px;
  margin-top: 6px;
  content: "";
  background: linear-gradient(90deg, var(--primary), var(--brand-blue), var(--brand-orange));
  border-radius: 99px;
}

.top-bar h1 {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 86px;
  min-height: 36px;
  padding: 8px 12px;
  color: #fff;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 800;
}

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

.install-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  color: var(--primary);
  background: #fff;
  border: 1px solid rgba(202, 220, 237, 0.95);
  border-radius: 999px;
  box-shadow: 0 8px 20px rgba(21, 148, 232, 0.12);
  font-size: 24px;
  font-weight: 650;
  line-height: 1;
  cursor: pointer;
}

.status-idle {
  background: #475569;
}

.status-tracking {
  background: var(--primary);
}

.status-stopped {
  background: #9333ea;
}

.layer-toggle,
.hard-refresh-btn {
  position: absolute;
  right: 12px;
  z-index: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 48px;
  height: 48px;
  padding: 0;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(202, 220, 237, 0.95);
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(20, 78, 120, 0.14);
  font-weight: 800;
  cursor: pointer;
}

.hard-refresh-btn {
  top: calc(88px + var(--safe-top));
  color: var(--primary);
  font-size: 25px;
  line-height: 1;
}

.layer-toggle {
  top: calc(144px + var(--safe-top));
}

.map-icon {
  position: relative;
  display: inline-block;
  width: 26px;
  height: 26px;
}

.street-icon {
  background:
    linear-gradient(90deg, transparent 0 40%, #fff 40% 60%, transparent 60%),
    linear-gradient(145deg, #2dd4bf, #1594e8);
  border: 2px solid #0f766e;
  border-radius: 8px;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.45);
}

.street-icon::before,
.street-icon::after {
  position: absolute;
  content: "";
  background: rgba(255, 255, 255, 0.86);
  border-radius: 99px;
}

.street-icon::before {
  left: 4px;
  right: 4px;
  top: 7px;
  height: 2px;
  transform: rotate(-22deg);
}

.street-icon::after {
  left: 5px;
  right: 5px;
  bottom: 6px;
  height: 2px;
  transform: rotate(18deg);
}

.satellite-icon {
  border-radius: 50%;
  background:
    radial-gradient(circle at 68% 32%, #fff8c7 0 13%, transparent 14%),
    radial-gradient(circle at 45% 58%, #0f766e 0 17%, transparent 18%),
    linear-gradient(145deg, #0f172a, #1594e8);
  border: 2px solid #1594e8;
  box-shadow: inset -4px -4px 0 rgba(255, 255, 255, 0.18);
}

.satellite-icon::before {
  position: absolute;
  left: 4px;
  right: 4px;
  top: 12px;
  height: 3px;
  content: "";
  background: #ffb703;
  border-radius: 99px;
  transform: rotate(-28deg);
}

.satellite-icon::after {
  position: absolute;
  right: -4px;
  top: 2px;
  width: 8px;
  height: 8px;
  content: "";
  background: var(--brand-orange);
  border-radius: 2px;
}

.control-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 710;
  padding: 7px 14px calc(14px + var(--safe-bottom));
  background: var(--panel);
  border-top: 1px solid rgba(216, 224, 234, 0.9);
  border-radius: 22px 22px 0 0;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  transition: transform 720ms cubic-bezier(0.22, 1, 0.36, 1), background-color 240ms ease;
  will-change: transform;
}

.control-panel.is-collapsed {
  transform: translateY(calc(100% - 52px - var(--safe-bottom)));
}

.panel-toggle {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  width: 100%;
  min-height: 45px;
  margin: 0 0 8px;
  padding: 4px 10px 8px;
  color: var(--muted);
  background: transparent;
  border: 0;
  font-size: 13px;
  font-weight: 850;
  cursor: pointer;
  touch-action: manipulation;
}

.panel-compact-stats {
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
}

.panel-grip {
  width: 46px;
  height: 5px;
  background: #c7d2df;
  border-radius: 999px;
}

.control-panel.is-collapsed .panel-grip {
  background: var(--primary);
}

.panel-content {
  transition: opacity 420ms ease;
}

.control-panel.is-collapsed .panel-content {
  opacity: 0.08;
  pointer-events: none;
}

.notice {
  display: none;
  margin-bottom: 10px;
  padding: 10px 12px;
  color: #854d0e;
  background: #fef3c7;
  border: 1px solid #fde68a;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 650;
}

.notice.is-visible {
  display: block;
}

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

.stat {
  min-width: 0;
  min-height: 58px;
  padding: 9px 8px;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.stat span,
.coordinate-row span,
.geometry-row label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.stat strong {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  font-size: 15px;
  font-weight: 850;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.coordinate-row,
.geometry-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 46px;
  margin-top: 10px;
  padding: 8px 10px;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.coordinate-row strong {
  min-width: 0;
  overflow: hidden;
  font-size: 14px;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.geometry-row select {
  min-height: 38px;
  padding: 6px 34px 6px 10px;
  color: var(--ink);
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-weight: 800;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  padding: 12px 10px;
  border: 0;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 850;
  cursor: pointer;
  touch-action: manipulation;
}

.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--brand-blue));
}

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

.btn-danger {
  color: #fff;
  background: var(--danger);
}

.btn-danger:active {
  background: var(--danger-dark);
}

.btn-secondary {
  color: var(--ink);
  background: linear-gradient(180deg, #ffffff, var(--button));
  border: 1px solid var(--line);
}

.btn:disabled {
  color: #94a3b8;
  background: #e2e8f0;
  border-color: #e2e8f0;
  cursor: not-allowed;
}

.toast {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: calc(340px + var(--safe-bottom));
  z-index: 900;
  display: none;
  padding: 12px 14px;
  color: #fff;
  background: rgba(0, 137, 120, 0.96);
  border: 1px solid rgba(187, 247, 208, 0.72);
  border-radius: 8px;
  box-shadow: 0 18px 40px rgba(0, 95, 82, 0.28);
  font-size: 14px;
  font-weight: 750;
  text-align: center;
}

body.panel-collapsed .toast {
  bottom: calc(72px + var(--safe-bottom));
}

.toast.is-visible {
  display: block;
}

.leaflet-control-attribution {
  margin-bottom: 322px !important;
}

body.panel-collapsed .leaflet-control-attribution {
  margin-bottom: 52px !important;
}

.track-marker {
  position: relative;
  display: block;
  width: 20px;
  height: 20px;
  margin-left: -10px;
  margin-top: -10px;
  background: #ffca2c;
  border: 3px solid #e11d48;
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.95), 0 0 0 6px rgba(225, 29, 72, 0.24), 0 5px 14px rgba(15, 23, 42, 0.38);
}

.track-marker::after {
  position: absolute;
  inset: 4px;
  content: "";
  background: #fff7ad;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(225, 29, 72, 0.18);
}

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

.point-popup .leaflet-popup-content {
  width: 260px !important;
  margin: 12px;
}

.popup-card strong {
  display: block;
  margin-bottom: 8px;
  color: var(--ink);
  font-size: 15px;
}

.popup-card table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.popup-card th,
.popup-card td {
  padding: 6px 0;
  border-top: 1px solid #e2e8f0;
  vertical-align: top;
}

.popup-card th {
  width: 82px;
  color: var(--muted);
  font-weight: 800;
  text-align: left;
}

.popup-card td {
  color: var(--ink);
  font-weight: 700;
  overflow-wrap: anywhere;
}

@media (min-width: 720px) {
  .top-bar {
    left: 20px;
    right: auto;
    width: 390px;
  }

  .hard-refresh-btn {
    top: calc(22px + var(--safe-top));
    right: 20px;
  }

  .layer-toggle {
    top: calc(78px + var(--safe-top));
    right: 20px;
  }

  .control-panel {
    left: 50%;
    right: auto;
    bottom: 18px;
    width: min(520px, calc(100vw - 40px));
    border: 1px solid rgba(216, 224, 234, 0.95);
    border-radius: 18px;
    transform: translateX(-50%);
  }

  .control-panel.is-collapsed {
    transform: translateX(-50%) translateY(calc(100% - 52px));
  }

  .toast {
    left: 50%;
    right: auto;
    bottom: 380px;
    width: min(460px, calc(100vw - 40px));
    transform: translateX(-50%);
  }

  body.panel-collapsed .toast {
    bottom: 92px;
  }

  .leaflet-control-attribution {
    margin-bottom: 0 !important;
  }
}

@media (max-width: 380px) {
  .top-bar h1 {
    font-size: 12px;
  }

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

  .toast {
    bottom: calc(430px + var(--safe-bottom));
  }
}
