*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body, #app {
  width: 100%; height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #1a2e1a;
}

#map {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
}

/* ── Top bar ─────────────────────────────── */
#top-bar {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 52px;
  background: rgba(46,125,50,.95);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 10px;
  z-index: 200;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}

#app-title {
  flex: 1;
  font-size: 17px; font-weight: 700;
  color: #fff; letter-spacing: .5px;
}

.icon-btn {
  background: none; border: none; color: #fff;
  cursor: pointer; padding: 6px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:active { background: rgba(255,255,255,.15); }

#connection-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: #4caf50; transition: background .3s;
}
#connection-dot.offline { background: #f44336; }

/* ── GPS bar ─────────────────────────────── */
#gps-bar {
  position: absolute;
  top: 52px; left: 0; right: 0;
  background: rgba(21,101,192,.92);
  backdrop-filter: blur(6px);
  color: #fff;
  display: flex; align-items: center; gap: 14px;
  padding: 7px 14px;
  font-size: 13px; font-weight: 600;
  z-index: 199;
}
#gps-bar.hidden { display: none; }

.follow-btn {
  margin-left: auto;
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.3);
  border-radius: 6px; color: #fff;
  font-size: 16px; padding: 2px 8px; cursor: pointer;
}
.follow-btn.active { background: rgba(255,255,255,.35); }

/* ── Bottom toolbar ─────────────────────── */
#bottom-toolbar {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 68px;
  background: rgba(255,255,255,.97);
  backdrop-filter: blur(10px);
  display: flex; align-items: stretch;
  box-shadow: 0 -2px 12px rgba(0,0,0,.15);
  z-index: 200;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.tool-btn {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 3px;
  background: none; border: none; cursor: pointer;
  padding: 8px 4px; color: #555;
  font-size: 11px; font-weight: 600;
  transition: background .15s, color .15s;
  -webkit-tap-highlight-color: transparent;
  text-decoration: none;
}
.tool-btn:active { background: #f0f4f0; }
.tool-btn.active { color: #2e7d32; }
.tool-btn.active svg { fill: #2e7d32; }

/* ── Drawer ──────────────────────────────── */
.drawer {
  position: absolute;
  top: 0; left: 0; bottom: 0;
  width: min(320px, 85vw);
  background: #fff; z-index: 300;
  box-shadow: 4px 0 20px rgba(0,0,0,.2);
  display: flex; flex-direction: column;
  transform: translateX(-100%);
  transition: transform .25s ease;
}
.drawer.open { transform: translateX(0); }

.drawer-header {
  display: flex; align-items: center;
  padding: 16px; background: #2e7d32; color: #fff; gap: 10px;
}
.drawer-header h3 { flex: 1; font-size: 16px; margin: 0; }

#drawer-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,.4);
  z-index: 299;
  opacity: 0; pointer-events: none;
  transition: opacity .25s;
}
#drawer-overlay.visible { opacity: 1; pointer-events: auto; }

#route-list {
  flex: 1; overflow-y: auto; padding: 12px;
}

.route-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px;
  margin-bottom: 8px; border: 1px solid #e8ede8;
  cursor: pointer; transition: background .15s;
}
.route-item:active { background: #f1f8f1; }
.route-color-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.route-name { flex: 1; font-size: 14px; font-weight: 600; color: #333; }
.route-meta { font-size: 11px; color: #888; }
.route-del {
  background: none; border: none; color: #bbb;
  cursor: pointer; font-size: 18px; padding: 4px;
  line-height: 1;
}
.route-del:active { color: #f44336; }
.route-fit {
  background: none; border: none; color: #888;
  cursor: pointer; font-size: 13px; padding: 4px;
}

/* ── Bottom sheet (distance) ─────────────── */
.bottom-sheet {
  position: absolute;
  left: 0; right: 0; bottom: 68px;
  background: #fff;
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -4px 20px rgba(0,0,0,.15);
  z-index: 150;
  transform: translateY(100%);
  transition: transform .3s ease;
  max-height: 45vh; overflow-y: auto;
}
.bottom-sheet.open { transform: translateY(0); }

.sheet-handle {
  width: 36px; height: 4px;
  background: #ddd; border-radius: 2px;
  margin: 10px auto 6px;
}

#dist-content { padding: 4px 16px 16px; }

.dist-table {
  width: 100%; border-collapse: collapse;
  font-size: 13px; margin-top: 8px;
}
.dist-table th {
  background: #f5f7fa; padding: 6px 8px;
  text-align: left; color: #555; font-weight: 600;
  border-bottom: 2px solid #e0e0e0;
}
.dist-table td { padding: 5px 8px; border-bottom: 1px solid #f0f0f0; color: #333; }
.dist-total td { background: #f5f7fa; font-weight: 700; border-top: 2px solid #e0e0e0; }

.dist-actions { display: flex; gap: 8px; margin-top: 10px; }
.dist-btn {
  padding: 6px 14px; border: none; border-radius: 20px;
  font-size: 12px; font-weight: 600; cursor: pointer;
}
.dist-btn-undo { background: #f5f5f5; color: #333; }
.dist-btn-reset { background: #ffebee; color: #c62828; }

/* ── Offline progress ────────────────────── */
#offline-progress {
  position: absolute;
  bottom: 80px; left: 16px; right: 16px;
  background: #fff; border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,.2);
  padding: 16px; z-index: 400;
}
#offline-progress.hidden { display: none; }

.progress-inner { display: flex; flex-direction: column; gap: 10px; }
#offline-progress-text { font-size: 13px; color: #333; font-weight: 600; }
.progress-track { height: 6px; background: #e0e0e0; border-radius: 3px; overflow: hidden; }
#offline-progress-bar { height: 100%; background: #2e7d32; border-radius: 3px; width: 0%; transition: width .2s; }
.cancel-btn {
  align-self: flex-end; background: none;
  border: 1px solid #ccc; border-radius: 20px;
  padding: 4px 14px; font-size: 12px; cursor: pointer;
}

/* ── Hint ────────────────────────────────── */
.hint-box {
  text-align: center; color: #888;
  font-size: 13px; padding: 16px; line-height: 1.6;
}

/* ── MapLibre overrides ──────────────────── */
.maplibregl-ctrl-bottom-right,
.maplibregl-ctrl-bottom-left { bottom: 72px !important; }
.maplibregl-ctrl-attrib { font-size: 10px !important; }
