:root {
  --blue: #0a4f9e;
  --blue-600: #083f7e;
  --blue-50: #eaf2fc;
  --amber: #f5a524;
  --amber-700: #a86a00;
  --green: #128a4a;
  --red: #c4372c;
  --ink: #16202b;
  --ink-2: #4a5866;
  --line: #dde3ea;
  --bg: #f5f7fa;
  --card: #ffffff;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 32, 48, .06), 0 4px 16px rgba(16, 32, 48, .06);
  --topbar: 52px;
  --panel-w: 400px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
body { display: flex; flex-direction: column; }
button { font: inherit; }
a { color: var(--blue); }

.topbar {
  height: var(--topbar); flex: none;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; background: var(--blue); color: #fff;
}
.brand { display: flex; align-items: center; gap: 8px; color: #fff; text-decoration: none; font-weight: 700; font-size: 17px; }
.brand img { border-radius: 7px; box-shadow: 0 0 0 1px rgba(255,255,255,.35); }
.topnav { display: flex; gap: 14px; }
.topnav a { color: #fff; text-decoration: none; font-size: 14px; opacity: .92; white-space: nowrap; }
.topnav a:hover { opacity: 1; text-decoration: underline; }

.app { flex: 1; min-height: 0; display: flex; }
#map { flex: 1; min-width: 0; background: #e8eef3; }

.panel {
  width: var(--panel-w); flex: none; overflow-y: auto;
  background: var(--bg); border-left: 1px solid var(--line);
  padding: 16px 16px 32px;
}
.panel-title { font-size: 18px; margin: 0 0 4px; }
.hint { margin: 0 0 14px; color: var(--ink-2); font-size: 14px; line-height: 1.45; }

.block { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; margin-bottom: 12px; }
.block-title { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-2); margin: 0 0 10px; font-weight: 600; }

/* Loại xe */
.vehicles { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.veh {
  border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 8px 2px 6px;
  cursor: pointer; text-align: center; color: var(--ink); line-height: 1.15;
}
.veh b { display: block; font-size: 15px; }
.veh small { display: block; font-size: 10.5px; color: var(--ink-2); margin-top: 3px; }
.veh[aria-checked="true"] { border-color: var(--blue); background: var(--blue-50); box-shadow: inset 0 0 0 1px var(--blue); }
.veh-desc { font-size: 12.5px; color: var(--ink-2); margin: 8px 0 0; }

/* Chặng */
.legs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.leg { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: #fff; }
.leg.open-leg { border-color: #f3d39b; background: #fffaf0; }
.leg-head { display: flex; justify-content: space-between; align-items: center; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.icon-btn { border: 0; background: none; font-size: 20px; line-height: 1; color: var(--ink-2); cursor: pointer; padding: 0 4px; border-radius: 6px; }
.icon-btn:hover { background: var(--bg); color: var(--red); }
.leg-fields { display: flex; flex-direction: column; gap: 6px; }
.field { display: flex; align-items: center; gap: 8px; }
.field-tag { flex: none; width: 34px; font-size: 11.5px; font-weight: 700; text-align: center; border-radius: 6px; padding: 3px 0; color: #fff; }
.field-tag.in { background: var(--green); }
.field-tag.out { background: var(--red); }
.leg-fee { margin-top: 6px; font-size: 14px; display: flex; justify-content: space-between; gap: 8px; }
.leg-fee .amt { font-weight: 700; white-space: nowrap; }
.leg-fee.err { color: var(--red); font-size: 13px; }
.open-name { font-weight: 600; font-size: 14.5px; }

/* Ô tìm kiếm có gợi ý */
.combo { position: relative; flex: 1; min-width: 0; }
.combo input {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font: inherit; font-size: 14.5px;
  background: #fff; color: var(--ink);
}
.combo input:focus { outline: 2px solid var(--blue); outline-offset: -1px; border-color: transparent; }
.combo.active input { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(10, 79, 158, .15); }
.combo ul {
  position: absolute; z-index: 1000; left: 0; right: 0; top: calc(100% + 4px); max-height: 260px; overflow-y: auto;
  margin: 0; padding: 4px; list-style: none; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
}
.combo li { padding: 7px 8px; border-radius: 6px; cursor: pointer; font-size: 14px; line-height: 1.3; }
.combo li small { display: block; color: var(--ink-2); font-size: 12px; }
.combo li[aria-selected="true"], .combo li:hover { background: var(--blue-50); }
.combo li.empty { color: var(--ink-2); cursor: default; }

.row-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
/* Cách đi: Đi cao tốc / Hỗn hợp / Tránh cao tốc */
.mode { display: grid; grid-template-columns: repeat(3, 1fr); margin-top: 12px; border: 1px solid #bcd0e8; border-radius: 10px; overflow: hidden; }
.mode label { position: relative; cursor: pointer; }
.mode label + label { border-left: 1px solid #bcd0e8; }
.mode input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.mode span { display: block; padding: 8px 4px; text-align: center; font-size: 13.5px; font-weight: 600; color: var(--blue); background: #fff; }
.mode input:checked + span { background: var(--blue); color: #fff; }
.mode input:focus-visible + span { outline: 2px solid var(--blue); outline-offset: -4px; }
.mode-note { font-size: 12.5px; color: var(--ink-2); margin: 6px 0 0; }
.btn {
  border: 1px solid var(--blue); background: var(--blue); color: #fff; border-radius: 9px; padding: 8px 14px;
  cursor: pointer; font-weight: 600; font-size: 14px;
}
.btn:hover { background: var(--blue-600); }
.btn.ghost { background: #fff; color: var(--blue); border-color: #bcd0e8; }
.btn.ghost:hover { background: var(--blue-50); }
.check { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 14px; cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--blue); }

/* Tổng */
.total {
  background: linear-gradient(135deg, var(--blue) 0%, #0d63c2 100%); color: #fff; border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.total-label { font-size: 13px; opacity: .9; }
.total-amount { font-size: 32px; font-weight: 800; letter-spacing: -.01em; margin: 2px 0; font-variant-numeric: tabular-nums; }
.total-note { font-size: 13px; opacity: .9; }
.total-actions { display: flex; gap: 8px; margin-top: 10px; }
.total .btn { background: #fff; color: var(--blue); border-color: #fff; }
.total .btn.ghost { background: transparent; color: #fff; border-color: rgba(255,255,255,.6); }
.total .btn.ghost:hover { background: rgba(255,255,255,.12); }

.breakdown { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.breakdown li { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.breakdown li:last-child { border-bottom: 0; }
.breakdown .free { color: var(--green); }
.breakdown .amt { white-space: nowrap; font-variant-numeric: tabular-nums; }

.disclaimer { font-size: 12.5px; color: var(--ink-2); line-height: 1.5; }
.approx-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; border: 2px dashed var(--ink-2); vertical-align: -1px; }

.ad-slot:empty { display: none; }
.ad-slot { margin: 0 0 12px; min-height: 100px; }
.ad-slot.debug { border: 2px dashed #c8d2dc; border-radius: var(--radius); display: grid; place-items: center; color: var(--ink-2); font-size: 13px; }

/* Bản đồ */
.leaflet-tooltip.st-tip { font-size: 13px; padding: 4px 8px; border-radius: 6px; }
.leaflet-tooltip.st-tip small { color: var(--ink-2); }
.leaflet-tooltip.st-tip .st-note { display: inline-block; max-width: 260px; white-space: normal; margin-top: 2px; }
.map-legend { background: #fff; padding: 8px 10px; border-radius: 10px; box-shadow: var(--shadow); font-size: 12.5px; line-height: 1.7; }
.map-legend i { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff;
  padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 2000; box-shadow: var(--shadow);
}

/* Nhãn Hoàng Sa, Trường Sa */
.island-label { text-align: center; color: #0a3d78; line-height: 1.25; text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 3px #fff; white-space: nowrap; }
.island-label b { display: block; font-size: 13px; }
.island-label span { font-size: 12px; font-weight: 600; }
.sea-label { text-align: center; color: #3a6a9e; font-style: italic; font-size: 13px; letter-spacing: .08em; text-shadow: 0 0 3px #fff, 0 0 3px #fff; white-space: nowrap; }

/* Nút vị trí hiện tại */
.locate-ctl a { display: grid !important; place-items: center; color: #333; }
.locate-ctl a:hover { color: var(--blue); }
.locate-ctl.busy a { color: #1a73e8; animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.near-pop { font-size: 13.5px; line-height: 1.5; }
.near-pop .btn { margin-top: 8px; padding: 6px 12px; font-size: 13px; }

/* Chế độ rà soát toạ độ (?review=1) */
.review { border: 2px solid #d6249f; }
body.reviewing .total { display: none; }
.rv-help { font-size: 13px; color: var(--ink-2); margin: 0 0 8px; line-height: 1.45; }
.rv-search { width: 100%; margin: 8px 0; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; font: inherit; font-size: 14px; }
.rv-list { list-style: none; margin: 0; padding: 0; max-height: 300px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; }
.rv-list li { padding: 7px 10px; border-bottom: 1px solid var(--line); cursor: pointer; font-size: 13.5px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.rv-list li:hover { background: var(--bg); }
.rv-list li.cur { background: #fbeaf6; }
.rv-list li small { display: block; color: var(--ink-2); font-size: 12px; }
.rv-list .btn { padding: 4px 10px; font-size: 12.5px; flex: none; }
.rv-ok { color: var(--green); font-size: 12px; font-weight: 600; }
.rv-json { width: 100%; height: 140px; margin-top: 8px; font: 12px ui-monospace, monospace; }
.rv-pin span { display: block; width: 26px; height: 26px; border-radius: 50% 50% 50% 0; background: #d6249f; transform: rotate(-45deg); border: 3px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.35); }

/* Điện thoại: bản đồ trên, bảng dưới */
@media (max-width: 820px) {
  .app { flex-direction: column; overflow-y: auto; }
  #map { flex: none; height: 46vh; min-height: 280px; }
  .panel { width: 100%; border-left: 0; overflow: visible; padding-bottom: 120px; }
  /* Khung tổng phí gọn: số tiền bên trái, nút bên phải */
  .total {
    position: sticky; bottom: 8px; z-index: 500;
    display: grid; grid-template-columns: 1fr auto; align-items: center; column-gap: 10px;
    padding: 9px 12px; border-radius: 12px;
  }
  .total-label { font-size: 12px; }
  .total-amount { font-size: 22px; line-height: 1.2; margin: 0; }
  .total-note { font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .total-actions { grid-column: 2; grid-row: 1 / span 3; flex-direction: column; gap: 6px; margin: 0; }
  .total .btn { padding: 5px 12px; font-size: 13px; border-radius: 8px; }
  .vehicles small { display: none; }
  .topnav a { font-size: 13px; }
}

/* Nút chọn kiểu bản đồ */
.style-ctl { background: #fff; }
.style-ctl .style-btn { display: grid; place-items: center; width: 34px; height: 34px; border: 0; background: #fff; color: #333; cursor: pointer; border-radius: 4px; }
.style-ctl .style-btn:hover { color: var(--blue); }
.style-ctl .style-list { padding: 6px 10px 8px; border-top: 1px solid #ddd; font-size: 13.5px; }
.style-ctl .style-list label { display: flex; align-items: center; gap: 6px; padding: 3px 0; white-space: nowrap; cursor: pointer; }
/* Nhãn quần đảo, Biển Đông trên nền tối */
[data-map-style="dark"] .island-label, [data-map-style="fiord"] .island-label { color: #e3eeff; text-shadow: 0 0 3px #000, 0 0 3px #000, 0 0 3px #000; }
[data-map-style="dark"] .sea-label, [data-map-style="fiord"] .sea-label { color: #a9c4e8; text-shadow: 0 0 3px #000, 0 0 3px #000; }

/* Bảng chọn khi nhiều điểm chồng nhau */
.pick-pop b { display: block; margin-bottom: 6px; }
.pick-btn { display: flex; gap: 8px; align-items: flex-start; width: 100%; text-align: left; background: none; border: 1px solid #d5dbe3; border-radius: 6px; padding: 6px 8px; margin-top: 4px; cursor: pointer; font: inherit; }
.pick-btn:hover, .pick-btn:focus-visible { background: #eef3fa; border-color: #0a4f9e; }
.pick-btn i { flex: none; width: 10px; height: 10px; border-radius: 50%; margin-top: 4px; background: #0a4f9e; }
.pick-btn i.open { background: #f5a524; }
.pick-btn small { display: block; color: #5a6675; }

/* Nút × xoá điểm đã chọn trong ô nhập */
.combo.has-value input { padding-right: 34px; }
.combo-clear {
  position: absolute; top: 50%; right: 4px; transform: translateY(-50%); width: 28px; height: 28px;
  border: 0; border-radius: 50%; background: transparent; color: var(--ink-2); font-size: 20px; line-height: 1; cursor: pointer;
}
.combo-clear:hover, .combo-clear:focus-visible { background: var(--blue-50); color: var(--ink); }

/* ---------- Trang tính phí theo lộ trình (/lo-trinh/) ---------- */
[hidden] { display: none !important; }
.topnav a[aria-current="page"] { opacity: 1; font-weight: 700; text-decoration: underline; text-underline-offset: 4px; }
.stops { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.stop { display: flex; align-items: center; gap: 8px; }
.stop-tag {
  flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  color: #fff; font-size: 13px; font-weight: 700;
}
.s-start { background: var(--green); }
.s-end { background: var(--red); }
.s-via { background: #6b7a8a; }
.stop .icon-btn { flex: none; }
.stop { transition: transform .15s; position: relative; }
.stop.dragging { transition: none; z-index: 2; box-shadow: 0 6px 18px rgba(16, 42, 67, .18); background: #fff; border-radius: 10px; }
.drag-handle {
  flex: none; width: 22px; height: 34px; margin-right: -4px; border: 0; background: none; padding: 0; border-radius: 6px;
  color: var(--ink-2); font-size: 14px; letter-spacing: -3px; cursor: grab; touch-action: none;
}
.drag-handle:hover, .drag-handle:focus-visible { background: var(--bg); color: var(--ink); }
.stop.dragging .drag-handle { cursor: grabbing; }
.combo li.my-loc { color: var(--blue); font-weight: 600; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.stop-pin span {
  display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.35); color: #fff; font: 700 13px system-ui, sans-serif;
}
.stop-pin.s-start span { background: var(--green); }
.stop-pin.s-end span { background: var(--red); }
.stop-pin.s-via span { background: #6b7a8a; }
.stop-pin b { transform: rotate(45deg); }
.leaflet-marker-icon.stop-pin { background: none; border: 0; }
.pick-btn i.s-start, .pick-btn i.s-via, .pick-btn i.s-end { border-radius: 50%; }
.pick-btn i.s-start { background: var(--green); }
.pick-btn i.s-end { background: var(--red); }
.pick-btn i.s-via { background: #6b7a8a; }
.pick-btn:disabled { opacity: .45; cursor: not-allowed; }
.route-msg { background: #fdecea; color: #8a1f17; border-radius: 10px; padding: 10px 12px; font-size: 14px; margin: 0 0 12px; line-height: 1.45; }
.route-warn { background: #fff6e5; color: #6b4a00; border-radius: 8px; padding: 8px 10px; font-size: 13px; line-height: 1.45; margin: 10px 0 0; }
.tolls li small { display: block; color: var(--ink-2); font-size: 12px; margin-top: 2px; }
.edit-link { display: inline-block; margin-top: 10px; text-decoration: none; font-size: 13px; }
.total.loading .total-amount { opacity: .45; }

/* Menu trên màn hình hẹp: chữ không xuống dòng, ẩn tên site (giữ biểu tượng) */
@media (max-width: 560px) {
  .topbar { padding: 0 10px; gap: 8px; }
  .topnav { gap: 10px; }
}
@media (max-width: 440px) {
  .brand-name { display: none; }
}

/* Lộ trình: trạm BOT trên đường, chọn đường khác tránh trạm */
.tolls li.bot .bot-link { display: inline-block; margin-top: 4px; padding: 0; border: 0; background: none; color: var(--blue); font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.pick-pop .bot-fee { margin: 0 0 6px; font-size: 13px; }
.pick-pop .bot-fee b { display: inline; margin: 0; }
.avoid-bar { position: absolute; z-index: 1000; left: 50%; top: 12px; transform: translateX(-50%); display: flex; gap: 10px; align-items: center; max-width: calc(100% - 100px); padding: 8px 10px 8px 14px; background: #fff8e8; border: 1px solid #f5a524; border-radius: 10px; box-shadow: 0 2px 10px rgba(0,0,0,.15); font-size: 13.5px; }
.avoid-bar[hidden] { display: none; }
.avoid-bar .btn { padding: 4px 10px; font-size: 13px; flex: none; }
#map.picking { cursor: crosshair; }
