:root {
  --bg: #eef3f7;
  --surface: #ffffffcc;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #0b57d0;
  --success: #128a44;
  --danger: #c62828;
  --shadow: 0 10px 30px rgba(26, 44, 73, 0.14);
  --radius: 16px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 12% 8%, #f5f9ff 0%, var(--bg) 45%, #dbe7f3 100%);
}

#app {
  height: 100dvh;
  width: 100%;
  position: relative;
  overflow: hidden;
}

#map {
  height: 100%;
  width: 100%;
  z-index: 1;
}

.glass {
  background: var(--surface);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid #ffffff8f;
  box-shadow: var(--shadow);
  border-radius: var(--radius);
}

.search-wrap {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  z-index: 10;
  padding: 10px;
}

#search-form {
  display: flex;
  gap: 8px;
}

.menu-btn {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: #fff;
  color: #1e3a8a;
  font-size: 20px;
  line-height: 1;
}

#search-input {
  flex: 1;
  border: 1px solid #d8dde6;
  background: #fff;
  border-radius: 999px;
  padding: 10px 14px;
  font-size: 16px;
  outline: none;
}

#search-input:focus {
  border-color: #8eb7ff;
  box-shadow: 0 0 0 3px #cfe0ff;
}

.btn {
  border: none;
  border-radius: 999px;
  font-weight: 600;
  cursor: pointer;
}

.btn.primary {
  background: var(--primary);
  color: #fff;
  padding: 0 14px;
}

.search-results {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  max-height: 220px;
  overflow: auto;
  border-radius: 12px;
  background: #fff;
}

.search-results:empty {
  display: none;
}

.search-results li {
  padding: 10px 12px;
  border-bottom: 1px solid #eef2f7;
  cursor: pointer;
}

.search-results li:last-child {
  border-bottom: none;
}

.search-results li:hover {
  background: #f8fbff;
}

.layer-panel {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: 12px;
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 30;
  width: min(360px, calc(100% - 40px));
  padding: 10px;
  overflow: auto;
  transform: translateX(calc(-100% - 20px));
  opacity: 0;
  pointer-events: none;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

body.layer-menu-open .layer-panel {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}

.layer-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.layer-drawer-head strong {
  font-size: 14px;
}

.layer-backdrop {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: rgba(15, 23, 42, 0.26);
  border: none;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

body.layer-menu-open .layer-backdrop {
  opacity: 1;
  pointer-events: auto;
}

.basemap-panel {
  border: 1px solid #dbe4ee;
  background: #f8fbff;
  border-radius: 12px;
  padding: 8px;
  margin-bottom: 10px;
}

.chip-group {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 6px;
}

.chip {
  border: 1px solid #d7e1ee;
  background: #ffffff;
  color: #4b5563;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 4px;
}

.chip.active {
  background: #0b57d0;
  color: #fff;
  border-color: #0b57d0;
}

.layer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.layer-head strong {
  font-size: 13px;
}

.village-head {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px dashed #d8e1ee;
}

.btn.mini {
  border-radius: 10px;
  padding: 6px 9px;
  font-size: 12px;
  background: #eff6ff;
  color: #1e40af;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 2px;
  font-size: 13px;
}

.toggle-row.compact {
  font-size: 12px;
  padding: 2px 2px 4px;
}

.toggle-row input {
  width: 16px;
  height: 16px;
}

.sub-row {
  color: #344054;
  padding-left: 20px;
}

.hidden-control {
  display: none;
}

.map-actions {
  position: absolute;
  right: 12px;
  bottom: calc(210px + env(safe-area-inset-bottom));
  z-index: 9;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

body.trip-minimized .map-actions {
  bottom: calc(86px + env(safe-area-inset-bottom));
}

.fab {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  background: #fff;
  color: #2c3c54;
  box-shadow: var(--shadow);
  font-size: 20px;
}

#follow-btn.active {
  background: #0b57d0;
  color: #fff;
}

#navigate-btn.active {
  background: var(--success);
  color: #fff;
}

#clear-btn {
  color: var(--danger);
}

.trip-panel {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 9;
  max-height: 40dvh;
  overflow: auto;
  padding: 12px;
  transition: transform 0.22s ease, opacity 0.2s ease;
}

body.trip-minimized .trip-panel {
  transform: translateY(140%);
  opacity: 0;
  pointer-events: none;
}

.trip-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.trip-grabber {
  width: 40px;
  height: 4px;
  border-radius: 999px;
  background: #cfd8e4;
  margin: 0 auto 10px;
}

.trip-head h1 {
  margin: 0;
  font-size: 18px;
}

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

.badge {
  font-size: 12px;
  color: #fff;
  background: var(--primary);
  padding: 5px 10px;
  border-radius: 999px;
}

#trip-toggle-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 10px;
  background: #eff6ff;
  color: #1e40af;
}

#trip-summary {
  margin: 8px 0;
  color: var(--muted);
  font-size: 14px;
}

.turn-list {
  margin: 0;
  padding-left: 20px;
  color: #334155;
  font-size: 14px;
}

.turn-list li {
  margin: 6px 0;
}

.trip-mini {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 9;
  border-radius: 14px;
  border: 1px solid #ffffff8f;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: transform 0.22s ease, opacity 0.2s ease;
}

body:not(.trip-minimized) .trip-mini {
  transform: translateY(140%);
  opacity: 0;
  pointer-events: none;
}

.trip-mini-status {
  font-size: 11px;
  font-weight: 700;
  color: #0b57d0;
  background: #e8f0ff;
  border-radius: 999px;
  padding: 4px 8px;
  white-space: nowrap;
}

.trip-mini-summary {
  flex: 1;
  font-size: 12px;
  color: #334155;
  text-align: left;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.trip-mini-expand {
  color: #1e3a8a;
  font-weight: 700;
}

.leaflet-control-container .leaflet-routing-container {
  display: none;
}

.kecamatan-name-label-anchor {
  background: transparent !important;
  border: none !important;
}

.kecamatan-name-label {
  display: inline-block;
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid rgba(99, 102, 241, 0.32);
  border-radius: 6px;
  color: #312e81;
  font-size: 10px;
  font-weight: 600;
  line-height: 1.1;
  padding: 2px 5px;
  white-space: nowrap;
  transform: translate(-50%, -50%);
  box-shadow: 0 1px 6px rgba(15, 23, 42, 0.12);
}

.kabupaten-name-label-anchor {
  background: transparent !important;
  border: none !important;
}

.kabupaten-name-label {
  display: inline-block;
  background: rgba(255, 255, 255, 0.84);
  border: 1px solid rgba(29, 78, 216, 0.32);
  border-radius: 7px;
  color: #1e3a8a;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.1;
  padding: 3px 7px;
  white-space: nowrap;
  transform: translate(-50%, -50%);
  box-shadow: 0 1px 8px rgba(15, 23, 42, 0.14);
}

.desa-name-label-anchor {
  background: transparent !important;
  border: none !important;
}

.desa-name-label {
  display: inline-block;
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid rgba(15, 118, 110, 0.34);
  border-radius: 6px;
  color: #115e59;
  font-size: 10px;
  font-weight: 600;
  line-height: 1.1;
  padding: 2px 5px;
  white-space: nowrap;
  transform: translate(-50%, -50%);
  box-shadow: 0 1px 6px rgba(15, 23, 42, 0.12);
}

.map-theme-dark .kecamatan-name-label {
  background: rgba(15, 23, 42, 0.75);
  border-color: rgba(129, 140, 248, 0.5);
  color: #e0e7ff;
}

.map-theme-dark .kabupaten-name-label {
  background: rgba(15, 23, 42, 0.8);
  border-color: rgba(96, 165, 250, 0.55);
  color: #dbeafe;
}

.map-theme-dark .desa-name-label {
  background: rgba(15, 23, 42, 0.78);
  border-color: rgba(45, 212, 191, 0.45);
  color: #ccfbf1;
}

@media (orientation: landscape) and (max-height: 560px) {
  .search-wrap {
    right: 48%;
  }

  .trip-panel {
    left: 12px;
    right: 54%;
    max-height: 52dvh;
  }

  .trip-mini {
    left: 12px;
    right: 54%;
  }

  .map-actions {
    right: calc(46% + 12px);
    bottom: max(12px, env(safe-area-inset-bottom));
  }

  body.trip-minimized .map-actions {
    bottom: calc(74px + env(safe-area-inset-bottom));
  }
}
