:root {
  --bg: #ffffff;
  --bg-2: #f3f5f8;
  --fg: #1b1f24;
  --fg-2: #5b6470;
  --line: #e1e5eb;
  --accent: #0f6fff;
  --accent-fg: #ffffff;
  --shadow: 0 6px 24px rgba(16, 24, 40, 0.16);
  --radius: 14px;
  color-scheme: light;
}
:root[data-theme='dark'] {
  --bg: #1b1f26;
  --bg-2: #252a33;
  --fg: #eceff3;
  --fg-2: #9aa3af;
  --line: #333a45;
  --accent: #4d94ff;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--fg);
  font: 14px/1.4 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; }
#map { position: absolute; inset: 0; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; color: var(--fg); }

/* panel */
.panel { position: absolute; top: 12px; left: 12px; width: 380px; max-height: calc(100% - 24px);
  display: flex; flex-direction: column; background: var(--bg); border-radius: var(--radius);
  box-shadow: var(--shadow); z-index: 5; overflow: hidden; }
.brand { display: flex; align-items: center; gap: 8px; padding: 10px 12px 4px; font-weight: 700; color: var(--accent); }
.brand span { flex: 1; color: var(--fg); }
.view { padding: 6px 12px 10px; overflow-y: auto; min-height: 0; }
.panel-foot { display: flex; justify-content: space-between; gap: 8px; padding: 6px 12px 8px;
  border-top: 1px solid var(--line); color: var(--fg-2); font-size: 12px; }
.panel-foot a { color: var(--accent); text-decoration: none; }
.panel.collapsed .view, .panel.collapsed .panel-foot { display: none; }

.search-row { display: flex; gap: 6px; }
.search-row input, .stop input { flex: 1; min-width: 0; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--bg-2); outline: none; }
.search-row input:focus, .stop input:focus { border-color: var(--accent); background: var(--bg); }
.icon-btn { border: 0; background: transparent; border-radius: 8px; padding: 6px 8px; color: var(--fg-2); }
.icon-btn:hover { background: var(--bg-2); color: var(--fg); }
#btn-directions { background: var(--accent); color: var(--accent-fg); padding: 8px 10px; }
.link-btn { border: 0; background: none; color: var(--accent); padding: 4px 2px; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding: 8px 0 4px; scrollbar-width: none; }
.chip { flex: 0 0 auto; border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 5px 11px; font-size: 13px; }
.chip:hover, .chip.on { border-color: var(--accent); color: var(--accent); }

.results { list-style: none; margin: 4px 0 0; padding: 0; }
.results li { padding: 8px 6px; border-radius: 8px; cursor: pointer; display: grid; gap: 1px; }
.results li:hover, .results li.active { background: var(--bg-2); }
.results .t { font-weight: 600; }
.results .s { color: var(--fg-2); font-size: 12.5px; }
.results .d { color: var(--fg-2); font-size: 12px; float: right; }

.place { margin-top: 6px; padding: 10px; border-radius: 10px; background: var(--bg-2); }
.place h2 { margin: 0 0 2px; font-size: 17px; }
.place .cat { color: var(--accent); font-size: 12px; text-transform: capitalize; }
.place .addr { color: var(--fg-2); margin: 4px 0 8px; }
.place dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 0 0 8px; font-size: 13px; }
.place dt { color: var(--fg-2); }
.place dd { margin: 0; overflow-wrap: anywhere; }
.place .actions { display: flex; flex-wrap: wrap; gap: 6px; }
.btn { border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 6px 10px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }

/* directions */
.route-head { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.modes { display: flex; gap: 4px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.mode { flex: 0 0 auto; border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 5px 10px; font-size: 12.5px; }
.mode.on { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.stops { display: grid; gap: 6px; }
.stop { display: flex; align-items: center; gap: 6px; }
.stop .dot { width: 12px; height: 12px; border-radius: 50%; flex: 0 0 12px; border: 2px solid var(--accent); }
.stop:first-child .dot { background: #fff; }
.stop:last-child .dot { background: #e0464a; border-color: #e0464a; }
.stop:not(:first-child):not(:last-child) .dot { background: var(--fg-2); border-color: var(--fg-2); }
.route-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin: 6px 0; font-size: 13px; }
.opt { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--fg-2); }
.routes { display: grid; gap: 6px; margin-top: 6px; }
.route-card { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; cursor: pointer; background: var(--bg); text-align: left; }
.route-card.on { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.route-card .big { font-size: 17px; font-weight: 700; }
.route-card .sub { color: var(--fg-2); font-size: 12.5px; }
.steps { margin: 8px 0 0; padding-left: 22px; font-size: 13px; }
.steps li { padding: 5px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.steps li span { color: var(--fg-2); font-size: 12px; display: block; }
.note { color: var(--fg-2); font-size: 13px; padding: 8px 2px; }

/* tools */
.tools { position: absolute; top: 12px; right: 56px; display: flex; gap: 6px; z-index: 4; }
.tool { width: 38px; height: 38px; border: 0; border-radius: 10px; background: var(--bg); box-shadow: var(--shadow); display: grid; place-items: center; color: var(--fg); }
.tool.on { color: var(--accent); }
.popover { position: absolute; top: 58px; right: 56px; width: 240px; padding: 10px; background: var(--bg);
  border-radius: 12px; box-shadow: var(--shadow); z-index: 6; display: grid; gap: 8px; }
.pop-title { font-weight: 700; }
.theme-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.theme { border: 2px solid var(--line); border-radius: 10px; padding: 0; overflow: hidden; background: var(--bg); font-size: 12px; }
.theme i { display: block; height: 42px; }
.theme.on { border-color: var(--accent); }
.popover select { flex: 1; padding: 4px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg-2); }

.measure { position: absolute; bottom: 34px; left: 50%; transform: translateX(-50%); background: var(--bg);
  box-shadow: var(--shadow); border-radius: 999px; padding: 6px 14px; display: flex; gap: 10px; align-items: center; z-index: 6; }
.ctx { position: absolute; z-index: 10; min-width: 200px; background: var(--bg); border-radius: 10px; box-shadow: var(--shadow); padding: 4px; }
.ctx button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 6px; }
.ctx button:hover { background: var(--bg-2); }
.ctx .coords { padding: 6px 10px; color: var(--fg-2); font-size: 12px; border-bottom: 1px solid var(--line); margin-bottom: 2px; }
.toast { position: absolute; bottom: 40px; left: 50%; transform: translateX(-50%); background: #222; color: #fff;
  padding: 8px 14px; border-radius: 8px; z-index: 20; font-size: 13px; }

.wavhub-pin { width: 26px; height: 26px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); border: 3px solid #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,.35); background: var(--accent); }
.wavhub-pin.red { background: #e0464a; }
.wavhub-pin.gray { background: #6b7280; width: 20px; height: 20px; }
.wavhub-pin span { display: block; transform: rotate(45deg); color: #fff; font-weight: 700; font-size: 11px; text-align: center; line-height: 20px; }

.maplibregl-ctrl-attrib { font-size: 11px; }

/* embed mode: just the map */
body.embed .panel, body.embed .tools { display: none; }

/* phones: panel becomes a bottom sheet */
@media (max-width: 640px) {
  .panel { top: auto; bottom: 0; left: 0; right: 0; width: auto; max-height: 62%; border-radius: 16px 16px 0 0; }
  .panel.collapsed { max-height: none; }
  .tools { right: 10px; top: 10px; flex-direction: column; }
  .popover { right: 56px; top: 10px; }
  .maplibregl-ctrl-top-right { top: 140px; }
  .measure { bottom: auto; top: 12px; }
}
