:root {
  --accent: #1846c7;
  --accent-soft: rgba(24, 70, 199, .1);
  --text: #1c1d20;
  --secondary: rgba(50, 52, 57, .6);
  --divider: rgba(50, 52, 57, .1);
  --surface: #fff;
  --surface-2: #f3f4f6;
  --map-bg: rgb(230, 233, 235);
  --radius: 24px;
  --shadow: 0 2px 8px rgba(0, 0, 0, .06), 0 8px 24px rgba(0, 0, 0, .08);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --panel-width: 380px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--map-bg); }
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { opacity: .4; cursor: default; }
input { font: inherit; color: inherit; }
svg { display: block; flex-shrink: 0; }
[hidden] { display: none !important; }

#map { position: absolute; inset: 0; }
.maplibregl-canvas:focus { outline: none; }

.floating { position: absolute; z-index: 3; }

/* Building pill */
.pill {
  display: flex; align-items: center; gap: 6px; max-width: calc(100% - 96px);
  padding: 8px 12px 8px 14px; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow);
  font-size: 15px; font-weight: 600; white-space: nowrap;
}
.pill span { overflow: hidden; text-overflow: ellipsis; }
#building-pill { top: calc(12px + var(--safe-top)); left: 12px; }

/* Floor selector */
#levels {
  top: calc(12px + var(--safe-top)); right: 12px; display: flex; flex-direction: column; gap: 2px;
  padding: 4px; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow);
}
#levels:empty { display: none; }
.level-btn {
  position: relative; width: 40px; height: 40px; border-radius: 20px; font-size: 15px; color: var(--secondary);
  transition: background .15s, color .15s;
}
.level-btn:hover { background: var(--surface-2); }
.level-btn.on { background: var(--accent); color: #fff; font-weight: 600; }
.level-btn.on-route::after {
  content: ""; position: absolute; right: 5px; top: 5px; width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--surface);
}
.level-btn.on.on-route::after { background: #fff; border-color: var(--accent); }

#map-controls { right: 12px; bottom: calc(96px + var(--safe-bottom)); display: flex; flex-direction: column; gap: 8px; }
.round-btn {
  display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%;
  background: var(--surface); box-shadow: var(--shadow); color: #333;
}
.round-btn:hover { background: #fafafa; }

/* Panel: bottom sheet on mobile, side card on desktop */
#panel {
  position: absolute; z-index: 4; left: 8px; right: 8px; bottom: calc(8px + var(--safe-bottom));
  max-height: min(72vh, 640px); overflow: auto; overscroll-behavior: contain;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  transition: max-height .2s;
}
#panel.compact { background: transparent; box-shadow: none; overflow: visible; }
#panel.tall { max-height: calc(100% - 72px - var(--safe-top) - var(--safe-bottom)); height: calc(100% - 72px - var(--safe-top) - var(--safe-bottom)); }
#panel:empty { display: none; }

.panel-body { padding: 16px; }
.panel-header { display: flex; align-items: center; gap: 8px; padding: 12px 12px 4px 16px; }
.panel-header h2 { flex: 1; margin: 0; font-size: 20px; line-height: 26px; }
.icon-btn { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; color: var(--secondary); }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* Search */
.search-bar {
  display: flex; align-items: center; gap: 8px; width: 100%; height: 52px; padding: 0 8px 0 16px;
  border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); color: var(--secondary); text-align: left;
}
.compact .search-bar { box-shadow: var(--shadow); }
.search-bar .placeholder { flex: 1; font-size: 16px; }
.search-bar .route-btn { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); }
.search-field {
  display: flex; align-items: center; gap: 4px; margin: 12px 12px 4px; padding: 0 4px; height: 48px;
  border-radius: 16px; background: var(--surface-2);
}
.search-field input { flex: 1; min-width: 0; height: 100%; border: 0; background: none; outline: none; font-size: 16px; }
.search-field input::placeholder { color: var(--secondary); }
.search-field .icon-btn { width: 40px; height: 40px; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 8px 12px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  display: flex; align-items: center; gap: 6px; padding: 6px 12px 6px 6px; border-radius: 18px;
  background: var(--surface-2); font-size: 14px; white-space: nowrap;
}
.chip img { width: 24px; height: 24px; }
.chip.text-only { padding-left: 12px; }
.chip:hover, .chip.on { background: var(--accent-soft); color: var(--accent); }

.section-title { padding: 12px 16px 4px; font-size: 13px; color: var(--secondary); text-transform: uppercase; letter-spacing: .02em; }
.list { padding: 0 8px 8px; }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 8px; border-radius: 14px; text-align: left;
}
.row:hover, .row.active { background: var(--surface-2); }
.row img, .row .row-icon { width: 36px; height: 36px; }
.row .row-icon { display: grid; place-items: center; border-radius: 50%; background: var(--surface-2); color: var(--secondary); }
.row .texts { flex: 1; min-width: 0; }
.row .title { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .title mark { background: none; color: var(--accent); font-weight: 600; }
.row .subtitle { font-size: 13px; color: var(--secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .check { color: var(--accent); }
.empty { padding: 24px 16px 32px; text-align: center; color: var(--secondary); }
.empty b { display: block; margin-bottom: 4px; color: var(--text); font-size: 17px; }

/* Unit card */
.unit-card { display: flex; gap: 12px; align-items: flex-start; padding: 16px 12px 8px 16px; }
.unit-card img { width: 48px; height: 48px; }
.unit-card .texts { flex: 1; min-width: 0; }
.unit-card h2 { margin: 2px 0 2px; font-size: 22px; line-height: 28px; overflow-wrap: anywhere; }
.unit-card .subtitle { color: var(--secondary); font-size: 15px; }
.actions { display: flex; gap: 8px; padding: 8px 16px 16px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 44px; padding: 0 18px;
  border-radius: 22px; background: var(--surface-2); color: var(--accent); font-weight: 600; font-size: 15px;
}
.btn.primary { flex: 1; background: var(--accent); color: #fff; }
.btn.grow { flex: 1; }
.btn:hover { filter: brightness(.97); }
.btn.square { width: 44px; padding: 0; }

/* Route planner */
.endpoints { position: relative; margin: 4px 12px 8px; padding: 4px 52px 4px 4px; border-radius: 18px; background: var(--surface-2); }
.endpoint { display: flex; align-items: center; gap: 10px; width: 100%; height: 44px; padding: 0 10px; border-radius: 14px; text-align: left; }
.endpoint:hover { background: rgba(0, 0, 0, .03); }
.endpoint + .endpoint { border-top: 1px solid var(--divider); border-radius: 0 0 14px 14px; }
.endpoint .badge {
  display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; flex-shrink: 0;
  background: var(--accent); color: #fff; font-size: 12px; font-weight: 600;
}
.endpoint .value { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 16px; }
.endpoint .value.placeholder { color: var(--secondary); }
.swap-btn { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); width: 36px; height: 36px; border-radius: 50%; background: var(--surface); box-shadow: var(--shadow); display: grid; place-items: center; color: var(--accent); }

.routes { display: flex; flex-direction: column; gap: 8px; padding: 4px 12px 8px; }
.route-card { width: 100%; padding: 12px 14px; border-radius: 18px; border: 2px solid var(--divider); text-align: left; }
.route-card.on { border-color: var(--accent); background: var(--accent-soft); }
.route-card .head { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.route-card .meta { color: var(--secondary); font-weight: 400; white-space: nowrap; }
.parts { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-top: 8px; font-size: 13px; color: var(--secondary); }
.part { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px 2px 2px; border-radius: 12px; background: var(--surface); }
.part img { width: 20px; height: 20px; }
.parts .sep { opacity: .5; }

/* Navigation */
.progress { display: flex; gap: 4px; padding: 14px 16px 0; }
.progress i { flex: 1; height: 4px; border-radius: 2px; background: var(--divider); }
.progress i.done { background: var(--accent); }
.step { display: flex; gap: 14px; align-items: center; padding: 14px 16px 4px; }
.step img { width: 52px; height: 52px; }
.step .kicker { font-size: 13px; color: var(--secondary); }
.step .instruction { font-size: 19px; line-height: 25px; font-weight: 600; }

/* Pick on map hint, toast, loading */
#pick-hint {
  left: 50%; top: calc(64px + var(--safe-top)); transform: translateX(-50%); display: flex; align-items: center; gap: 10px;
  padding: 8px 8px 8px 16px; border-radius: var(--radius); background: var(--text); color: #fff; box-shadow: var(--shadow); white-space: nowrap;
}
#pick-hint button { padding: 6px 12px; border-radius: 16px; background: rgba(255, 255, 255, .15); }
#toast {
  position: absolute; z-index: 10; left: 50%; top: calc(16px + var(--safe-top)); transform: translateX(-50%);
  padding: 10px 16px; border-radius: 16px; background: var(--text); color: #fff; font-size: 14px; box-shadow: var(--shadow);
  animation: toast-in .2s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -8px); } }
#loading {
  position: absolute; z-index: 20; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  background: var(--map-bg); color: var(--secondary); transition: opacity .3s;
}
#loading.hide { opacity: 0; pointer-events: none; }
.spinner { width: 32px; height: 32px; border-radius: 50%; border: 3px solid var(--divider); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.desktop-only { display: none; }

@media (max-width: 899px) {
  body[data-mode="search"] .floating { display: none; }
}

@media (min-width: 900px) {
  #panel, #panel.tall {
    left: 12px; right: auto; top: calc(12px + var(--safe-top)); bottom: auto; width: var(--panel-width);
    height: auto; max-height: calc(100% - 24px - var(--safe-top) - var(--safe-bottom));
  }
  #panel.compact { background: var(--surface); box-shadow: var(--shadow); overflow: auto; }
  #panel.compact .search-bar { box-shadow: none; }
  #building-pill { left: calc(var(--panel-width) + 24px); }
  #map-controls { bottom: 24px; }
  #pick-hint { left: calc(50% + var(--panel-width) / 2); }
  .desktop-only { display: grid; }
}
