:root {
  --brand: #1E88E5;
  --brand-strong: #0C65BD;
  --on-brand: #fff;
  --bg: #eef3f8;
  --card: #fff;
  --ink: #16202b;
  --ink-2: #4a5866;
  --ink-3: #6f7d8b;
  --line: #e1e7ee;
  --hover: #f1f5fa;
  --sel: #e3f0fc;
  --route: #1E88E5;
  --route-casing: #0C4F92;
  --route-alt: #9aa9b8;
  --a: #1f9d55;
  --b: #e0413a;
  --stop: #e08a00;
  --shadow: 0 2px 6px rgba(15, 30, 50, .12), 0 8px 24px rgba(15, 30, 50, .10);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand: #64AFED; --brand-strong: #8cc4f2; --on-brand: #0b1a29;
    --bg: #0f151c; --card: #1a232d; --ink: #e8eef4; --ink-2: #b3c0cc; --ink-3: #8a98a6;
    --line: #2a3643; --hover: #222d39; --sel: #1d3347;
    --route: #4aa3f0; --route-casing: #0d3e6c; --route-alt: #5d6b79;
    --shadow: 0 2px 6px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --brand: #64AFED; --brand-strong: #8cc4f2; --on-brand: #0b1a29;
  --bg: #0f151c; --card: #1a232d; --ink: #e8eef4; --ink-2: #b3c0cc; --ink-3: #8a98a6;
  --line: #2a3643; --hover: #222d39; --sel: #1d3347;
  --route: #4aa3f0; --route-casing: #0d3e6c; --route-alt: #5d6b79;
  --shadow: 0 2px 6px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  overflow: hidden;
}
#map { position: fixed; inset: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Khung trái (desktop) / trên cùng (điện thoại) */
.panel {
  position: absolute; z-index: 2;
  top: 12px; left: 12px;
  width: 380px;
  max-height: calc(100% - 24px);
  display: flex; flex-direction: column;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel > section { display: flex; flex-direction: column; min-height: 0; overflow-y: auto; }

.searchbar { display: flex; align-items: center; gap: 4px; padding: 6px 6px 6px 12px; }
.searchbar-logo { border-radius: 8px; flex: none; }
.combo { flex: 1; min-width: 0; }
input[type="search"] {
  width: 100%; min-width: 0;
  border: 0; outline: 0; background: transparent;
  color: var(--ink); font: inherit; font-size: 16px;
  padding: 10px 8px;
}
input[type="search"]::-webkit-search-cancel-button { display: none; }
input::placeholder { color: var(--ink-3); }

.icon-btn {
  flex: none; display: inline-grid; place-items: center;
  width: 40px; height: 40px; border: 0; border-radius: 10px;
  background: transparent; color: var(--ink-2); cursor: pointer;
}
.icon-btn:hover { background: var(--hover); }
.icon-btn--brand { color: var(--brand); }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

.suggest { list-style: none; margin: 0; padding: 4px 0; border-top: 1px solid var(--line); }
.suggest li {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 9px 14px; cursor: pointer;
}
.suggest li[aria-selected="true"], .suggest li:hover { background: var(--hover); }
.suggest .ico { flex: none; color: var(--ink-3); margin-top: 1px; }
.suggest .ico--me { color: var(--brand); }
.suggest .t { min-width: 0; }
.suggest .n { font-weight: 600; }
.suggest .a { color: var(--ink-3); font-size: 13px; }
/* Địa chỉ trước sáp nhập 1/7/2025, dưới địa chỉ mới. */
.suggest .o { color: var(--ink-3); font-size: 12px; font-style: italic; opacity: .85; }
.suggest .empty { color: var(--ink-3); cursor: default; }
.suggest .empty:hover { background: none; }

.card { border-top: 1px solid var(--line); padding: 14px 16px 16px; }
.place-name { font-size: 19px; margin: 0 0 4px; line-height: 1.3; }
.place-addr { margin: 0 0 6px; color: var(--ink-2); }
.place-old { margin: -2px 0 6px; color: var(--ink-3); font-size: 13px; font-style: italic; }
.place-coords { margin: 0 0 12px; }
.link-btn { border: 0; background: none; padding: 0; color: var(--ink-3); font-size: 13px; cursor: pointer; font-variant-numeric: tabular-nums; }
.link-btn:hover { color: var(--brand); text-decoration: underline; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 999px; padding: 8px 16px; cursor: pointer; font-weight: 600;
}
.btn:hover { background: var(--hover); }
.btn--primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn--primary:hover { background: var(--brand-strong); border-color: var(--brand-strong); }
.btn--quiet { border-color: transparent; color: var(--ink-2); font-weight: 500; }
.btn:disabled { opacity: .6; cursor: default; }

/* Báo sai bản đồ */
.report {
  border: 0; border-radius: var(--radius); padding: 18px 18px 16px; width: min(420px, calc(100vw - 32px));
  background: var(--card); color: var(--ink); box-shadow: var(--shadow);
}
.report::backdrop { background: rgba(10, 20, 30, .35); }
.report-title { font-size: 18px; margin: 0 0 4px; }
.report-where { margin: 0 0 12px; color: var(--ink-3); font-size: 13px; overflow-wrap: anywhere; }
.report-kinds { border: 0; margin: 0 0 10px; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; }
.report-kinds label { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.report-kinds input { accent-color: var(--brand); margin: 0; }
.report textarea {
  width: 100%; box-sizing: border-box; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px;
  background: var(--card); color: var(--ink); font: inherit; font-size: 15px; resize: vertical;
}
.report textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; }
.report-note { margin: 8px 0 12px; color: var(--ink-3); font-size: 12px; }
.report-actions { justify-content: flex-end; }
@media (max-width: 380px) { .report-kinds { grid-template-columns: 1fr; } }

/* Chỉ đường */
.dir-head { display: flex; align-items: center; gap: 6px; padding: 8px 10px 4px 6px; }
.modes { display: flex; gap: 6px; }
.mode {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink-2);
  border-radius: 999px; padding: 6px 12px; cursor: pointer; font-weight: 600; font-size: 14px;
}
.mode[aria-checked="true"] { background: var(--sel); border-color: var(--brand); color: var(--brand); }

.waypoints { position: relative; padding: 4px 52px 8px 14px; }
.wp { display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); }
.wp:last-of-type { border-bottom: 0; }
.wp-dot { flex: none; width: 12px; height: 12px; border-radius: 50%; border: 3px solid; }
.wp-dot--a { border-color: var(--a); }
.wp-dot--b { border-color: var(--b); background: var(--b); }
.swap { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); }
.wp--stop { position: relative; }
.wp-dot--stop {
  width: 18px; height: 18px; margin: 0 -3px; border: 0; background: var(--stop); color: #fff;
  font-size: 11px; font-weight: 700; display: grid; place-items: center;
}
.wp-remove { width: 32px; height: 32px; margin-right: -4px; }
.wp-remove svg { width: 16px; height: 16px; }
.add-stop {
  display: inline-flex; align-items: center; gap: 6px; align-self: flex-start;
  margin: 0 0 8px 8px; padding: 6px 10px; border: 0; border-radius: 8px; background: none;
  color: var(--brand); font-weight: 600; font-size: 14px; cursor: pointer;
}
.add-stop:hover { background: var(--hover); }
.add-stop svg { width: 16px; height: 16px; }

.status { padding: 0 16px; color: var(--ink-3); font-size: 14px; }
.status:not(:empty) { padding: 10px 16px; border-top: 1px solid var(--line); }
.status.error { color: var(--b); }

.routes { list-style: none; margin: 0; padding: 0; }
.routes li { border-top: 1px solid var(--line); padding: 12px 16px; cursor: pointer; display: flex; gap: 12px; align-items: baseline; }
.routes li:hover { background: var(--hover); }
.routes li[aria-current="true"] { background: var(--sel); box-shadow: inset 3px 0 0 var(--brand); }
.routes .dur { font-size: 18px; font-weight: 700; min-width: 86px; }
.routes li[aria-current="true"] .dur { color: var(--brand); }
.routes .dist { color: var(--ink-2); font-weight: 600; }
.routes li.route-note { cursor: default; padding: 8px 16px; font-size: 12px; color: var(--ink-3); }
.routes li.route-note:hover { background: none; }
.routes .via { color: var(--ink-3); font-size: 13px; }

.steps-head { display: flex; align-items: center; border-top: 1px solid var(--line); padding-right: 12px; }
.steps-toggle {
  flex: 1; text-align: left; border: 0; background: none;
  padding: 10px 16px; font-weight: 700; cursor: pointer; color: var(--ink-2);
}
.nav-start { padding: 6px 14px; font-size: 14px; }
.steps-toggle::after { content: "▾"; margin-left: 6px; }
.steps-toggle[aria-expanded="false"]::after { content: "▸"; }
.steps { list-style: none; margin: 0; padding: 0 0 8px; }
.steps li { display: flex; gap: 12px; padding: 8px 16px; cursor: pointer; align-items: flex-start; }
.steps li:hover { background: var(--hover); }
.steps .arr { flex: none; width: 24px; text-align: center; font-size: 17px; color: var(--brand); line-height: 1.3; }
.steps .txt { flex: 1; }
.steps .sd { color: var(--ink-3); font-size: 13px; white-space: nowrap; }

/* Xem từng bước: khung trái ẩn, thẻ bước ở đáy, nút ← góc trên-trái. */
body.navigating .panel { display: none; }
.nav-back {
  position: absolute; z-index: 3; top: max(12px, env(safe-area-inset-top)); left: 16px;
  width: 48px; height: 48px; border: 0; border-radius: 50%; display: grid; place-items: center;
  background: var(--card); color: var(--ink); box-shadow: var(--shadow); cursor: pointer;
}
.nav {
  position: absolute; z-index: 3; left: 16px; right: 16px; bottom: max(16px, env(safe-area-inset-bottom));
  display: flex; justify-content: center; pointer-events: none;
}
.nav-card {
  pointer-events: auto; width: min(520px, 100%); min-height: 88px; display: flex; align-items: center; gap: 2px;
  padding: 10px 4px; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  touch-action: pan-y; user-select: none;
}
.nav-card .icon-btn:disabled { opacity: .3; cursor: default; background: none; }
.nav-body { flex: 1; min-width: 0; display: flex; gap: 12px; align-items: flex-start; padding: 0 4px; }
.nav-arr { flex: none; width: 34px; text-align: center; font-size: 28px; line-height: 1.1; color: var(--brand); }
.nav-t { min-width: 0; }
.nav-txt { font-size: 18px; font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
.nav-sub { margin-top: 3px; color: var(--ink-3); font-size: 14px; font-variant-numeric: tabular-nums; }
/* Dẫn đường theo vị trí: nút quay về vị trí nổi ngay trên thẻ; chấm vị trí có mũi chỉ hướng đi. */
.nav { flex-direction: column; align-items: center; gap: 10px; }
.nav-recenter {
  pointer-events: auto; border: 0; border-radius: 999px; padding: 9px 16px; font: inherit; font-weight: 600; font-size: 14px;
  background: var(--brand); color: #fff; box-shadow: var(--shadow); cursor: pointer;
}
.me-dot {
  width: 22px; height: 22px; border-radius: 50%; background: #1a73e8; border: 3px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .35); position: relative;
}
/* Mũi trắng TRONG chấm: mũi xanh chìa ra ngoài thì lẫn vào nét tuyến xanh ngay dưới nó. */
.me-dot i {
  position: absolute; left: 50%; top: 2px; margin-left: -5px; width: 0; height: 0;
  border-left: 5px solid transparent; border-right: 5px solid transparent; border-bottom: 10px solid #fff;
}
/* Đang dẫn đường thì ghim điểm đi (xanh lá) nằm chồng lên chấm vị trí ngay chỗ xuất phát — hai dấu cho cùng một chỗ, dễ
   nhầm (10/10/2026). Ẩn ghim điểm đi; thoát dẫn đường là hiện lại. Ghim điểm đến và điểm dừng giữ nguyên. */
body.live .start-dot { display: none; }
/* Chấm của nút định vị MapLibre chỉ chụp một lần, không chạy theo — ẩn đi kẻo có hai chấm lệch nhau. */
body.live .maplibregl-user-location-dot, body.live .maplibregl-user-location-accuracy-circle { display: none; }
/* Nút la bàn/định vị và thước tỉ lệ nổi lên trên thẻ. */
body.navigating .maplibregl-ctrl-bottom-right,
body.navigating .maplibregl-ctrl-bottom-left { bottom: 116px; }

/* Menu chuột phải / giữ lâu */
.ctx { display: flex; flex-direction: column; min-width: 190px; }
.ctx button { border: 0; background: none; text-align: left; padding: 8px 12px; cursor: pointer; border-radius: 8px; color: var(--ink); }
.ctx button:hover { background: var(--hover); }
.ctx .coord { color: var(--ink-3); font-size: 12px; font-variant-numeric: tabular-nums; }
.maplibregl-popup-content { background: var(--card); color: var(--ink); border-radius: 12px; padding: 6px; box-shadow: var(--shadow); }
.maplibregl-popup-tip { border-top-color: var(--card) !important; border-bottom-color: var(--card) !important; }
.maplibregl-popup-close-button { color: var(--ink-3); font-size: 18px; right: 4px; top: 2px; }

/* Ghim */
.pin { width: 26px; height: 34px; cursor: grab; filter: drop-shadow(0 2px 2px rgba(0,0,0,.3)); }
.pin svg { width: 26px; height: 34px; stroke: #fff; stroke-width: 2; }
/* Điểm đi: vòng tròn rỗng, khác hẳn hình ghim của điểm đến (xem startMarker trong app.js). Không đặt position — như .pin. */
.start-dot {
  box-sizing: border-box; width: 24px; height: 24px; border-radius: 50%; background: #fff; border: 7px solid var(--a);
  box-shadow: 0 0 0 2px #fff, 0 2px 4px rgba(0, 0, 0, .35); cursor: grab;
}
.pin--b svg, .pin--place svg { fill: var(--b); }
/* Không đặt position cho .pin: MapLibre cần position:absolute của .maplibregl-marker (cùng độ ưu tiên, file này
   nạp sau nên sẽ thắng) — ghi relative ở đây từng làm mỗi ghim bị đẩy xuống dưới ghim trước nó. absolute cũng đã
   là khung cho .pin-num. */
.pin--stop svg { fill: var(--stop); }
.pin-num { position: absolute; left: 0; right: 0; top: 5px; text-align: center; color: #fff; font: 700 12px/16px system-ui, sans-serif; pointer-events: none; }

/* Nút sáng/tối nằm trong cột control của MapLibre (app.js) — không định vị tuyệt đối nữa: nút định vị ngay dưới nó
   cao thấp tuỳ trình duyệt, và vị trí cố định từng đè lên nó. */
#theme { display: grid; place-items: center; color: var(--ink-2); cursor: pointer; }
#theme svg { width: 20px; height: 20px; }
#three-d { display: grid; place-items: center; color: var(--ink-2); cursor: pointer; font: 700 12px/1 system-ui, sans-serif; }
#three-d[aria-pressed="true"] { color: var(--brand, #147DFF); }
#info { display: grid; place-items: center; color: var(--ink-2); cursor: pointer; }
#info svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.theme-box { position: relative; }
.info-menu {
  position: absolute; right: calc(100% + 8px); bottom: 0; min-width: 180px; padding: 6px 0;
  background: var(--card); border-radius: 10px; box-shadow: var(--shadow); display: flex; flex-direction: column;
}
.info-menu[hidden] { display: none; }
.info-menu a { padding: 9px 14px; color: var(--ink); text-decoration: none; font-size: 14px; white-space: nowrap; }
.info-menu a:hover, .info-menu a:focus-visible { background: var(--hover); }
.maplibregl-ctrl-group { background: var(--card); box-shadow: var(--shadow) !important; border-radius: 10px; }
.maplibregl-ctrl-group button { width: 40px; height: 40px; }
:root[data-theme="dark"] .maplibregl-ctrl-group button .maplibregl-ctrl-icon,
:root[data-theme="dark"] .maplibregl-ctrl-attrib-button { filter: invert(1); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .maplibregl-ctrl-group button .maplibregl-ctrl-icon,
  :root:not([data-theme="light"]) .maplibregl-ctrl-attrib-button { filter: invert(1); }
}

/* Ghi công: chữ nhỏ, nền trong để không che bản đồ. Điện thoại: MapLibre thu thành nút "©" sau lần kéo đầu (app.js). */
.maplibregl-ctrl-bottom-right .maplibregl-ctrl-attrib { margin: 0 !important; }
.maplibregl-ctrl-attrib {
  background: color-mix(in srgb, var(--card) 55%, transparent) !important; color: var(--ink-3);
  font-size: 10px; line-height: 16px; padding: 0 6px !important; border-radius: 6px 0 0 0;
}
.maplibregl-ctrl-attrib a { color: var(--ink-3); }
/* compact ở mọi cỡ (app.js): mở sẵn lúc vào trang, thu lại khi kéo bản đồ → ẩn hẳn; ghi công còn trong menu ℹ. */
.maplibregl-ctrl-attrib.maplibregl-compact { padding: 0 6px !important; min-height: 0; }
.maplibregl-ctrl-attrib.maplibregl-compact:not(.maplibregl-compact-show) { display: none !important; }
.maplibregl-ctrl-attrib .maplibregl-ctrl-attrib-button { display: none !important; }
.info-attrib { margin: 0; padding: 8px 14px 9px; font-size: 12px; color: var(--ink-3); border-bottom: 1px solid var(--line); white-space: nowrap; }
.info-attrib a { padding: 0 !important; color: var(--ink-2) !important; font-size: 12px !important; display: inline !important; }
.info-attrib a:hover { background: none !important; text-decoration: underline; }
/* Dòng ghi công mở ra phủ ngang đáy bản đồ: ẩn thước tỉ lệ thay vì để hai khung đè nhau. */
@media (max-width: 640px) { .maplibregl-map:has(.maplibregl-compact-show) .maplibregl-ctrl-scale { visibility: hidden; } }
.maplibregl-ctrl-scale { background: color-mix(in srgb, var(--card) 70%, transparent); color: var(--ink); border-color: var(--ink-2); }

.toast {
  position: absolute; z-index: 3; left: 50%; bottom: 32px; transform: translateX(-50%);
  background: var(--ink); color: var(--card); padding: 10px 16px; border-radius: 999px;
  font-size: 14px; box-shadow: var(--shadow); max-width: calc(100% - 32px);
}

/* Màn hình cảm ứng: chụm hai ngón để phóng to, bỏ nút +/- cho cột nút bên phải gọn lại (giữ la bàn). */
@media (pointer: coarse) {
  .maplibregl-ctrl-zoom-in, .maplibregl-ctrl-zoom-out { display: none !important; }
}

/* Điện thoại: khung chiếm bề ngang, cách mép 16px */
@media (max-width: 640px) {
  .panel { top: max(8px, env(safe-area-inset-top)); left: 16px; right: 16px; width: auto; max-height: 46%; }
  .dir-head .mode { padding: 6px 10px; }
}
