/* Colours come from Telegram's theme (set on :root by telegram-web-app.js); fallbacks for a plain browser. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f2f3f5);
  --text: var(--tg-theme-text-color, #1c1c1e);
  --hint: var(--tg-theme-hint-color, #8a8a8e);
  --link: var(--tg-theme-link-color, #2481cc);
  --btn: var(--tg-theme-button-color, #e5487f);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #e53935);
  --radius: 14px;
  --gap: 12px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-tg]) {
    --bg: #18181b;
    --bg2: #232327;
    --text: #f2f2f3;
    --hint: #9a9aa0;
  }
}

* { box-sizing: border-box; }
/* .card etc. set display; keep the hidden attribute authoritative */
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "PingFang HK", "Noto Sans HK", "Microsoft JhengHei", sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, input, select, textarea { font: inherit; color: inherit; }

.topbar {
  position: sticky; top: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px; background: var(--bg);
  border-bottom: 1px solid color-mix(in srgb, var(--hint) 25%, transparent);
}
.brand { font-weight: 700; }
.tabs { display: flex; background: var(--bg2); border-radius: 10px; padding: 3px; }
.tab {
  border: 0; background: transparent; padding: 6px 16px; border-radius: 8px; cursor: pointer; color: var(--hint);
}
.tab[aria-selected="true"] { background: var(--bg); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgb(0 0 0 / 0.12); }

.map { height: 42vh; min-height: 220px; background: var(--bg2); }
.map.compact { height: 30vh; }
.panel { padding: 16px; display: flex; flex-direction: column; gap: var(--gap); padding-bottom: calc(24px + env(safe-area-inset-bottom)); }

.card { background: var(--bg2); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.card h2 { margin: 0; font-size: 17px; }
.card p { margin: 0; }
.muted { color: var(--hint); font-size: 14px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }
.big { font-size: 22px; font-weight: 700; }

.field { position: relative; display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 13px; color: var(--hint); }
.input {
  width: 100%; border: 1px solid transparent; border-radius: 10px; padding: 10px 12px;
  background: var(--bg); outline: none;
}
.input:focus { border-color: var(--btn); }

/* Date field drawn as a button; the native input covers it invisibly and opens the picker. */
.date-pick {
  position: relative; display: flex; align-items: center; justify-content: space-between;
  border: 1.5px dashed var(--link); border-radius: 10px; padding: 12px; background: var(--bg);
  color: var(--link); font-weight: 600;
}
.date-pick.set { border-style: solid; border-color: var(--hint); color: var(--text); font-weight: 400; }
.date-pick .chev { color: var(--hint); font-size: 1.3em; line-height: 1; }
.date-pick input {
  position: absolute; inset: 0; width: 100%; height: 100%; min-width: 0;
  opacity: 0; -webkit-appearance: none; appearance: none; border: 0; cursor: pointer;
}
.field.active .input { border-color: var(--btn); }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.dot.pickup { background: #2e7d32; }
.dot.dropoff { background: #e53935; }

.suggestions {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 1100; margin-top: 4px;
  background: var(--bg); border-radius: 10px; box-shadow: 0 6px 24px rgb(0 0 0 / 0.18); overflow: hidden;
  max-height: 260px; overflow-y: auto;
}
.suggestions button {
  display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 10px 12px; cursor: pointer;
}
.suggestions button + button { border-top: 1px solid var(--bg2); }
.suggestions small { display: block; color: var(--hint); }

.segmented { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; gap: 3px; }
.segmented button {
  flex: 1; border: 0; background: transparent; border-radius: 8px; padding: 8px 4px; cursor: pointer; font-size: 14px;
}
.segmented button[aria-pressed="true"] { background: var(--btn); color: var(--btn-text); font-weight: 600; }

.check { display: flex; gap: 10px; align-items: flex-start; font-size: 15px; }
.check input { width: 20px; height: 20px; margin: 1px 0 0; accent-color: var(--btn); flex: none; }

.btn {
  border: 0; border-radius: 12px; padding: 13px 16px; cursor: pointer; font-weight: 600; width: 100%;
  background: var(--btn); color: var(--btn-text);
}
a.btn { display: block; text-align: center; text-decoration: none; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.secondary { background: var(--bg); color: var(--text); }
.btn.danger { background: transparent; color: var(--danger); }
.btn.small { width: auto; padding: 8px 12px; font-size: 14px; }
.link { color: var(--link); background: none; border: 0; padding: 0; cursor: pointer; font-size: 14px; }

.status { display: flex; gap: 10px; align-items: center; }
.pulse { width: 12px; height: 12px; border-radius: 50%; background: var(--btn); animation: pulse 1.4s infinite; flex: none; }
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.35; transform: scale(0.75); } }
@media (prefers-reduced-motion: reduce) { .pulse { animation: none; } }

.doc { display: flex; align-items: center; gap: 10px; }
.doc .grow { flex: 1; }
.doc img { width: 52px; height: 52px; object-fit: cover; border-radius: 8px; background: var(--bg); }
.doc input[type="file"] { display: none; }

.ledger { display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.ledger div { display: flex; justify-content: space-between; gap: 8px; }
.plus { color: #2e7d32; }
.minus { color: var(--danger); }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 2000;
  background: rgb(0 0 0 / 0.82); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; max-width: calc(100% - 32px);
}

.pin { font-size: 30px; line-height: 30px; text-align: center; filter: drop-shadow(0 2px 2px rgb(0 0 0 / 0.35)); }
.leaflet-control-attribution img { height: 14px; vertical-align: middle; }

/* ── Map markers (centered on the point) ── */
.pin-wrap > * { transform: translate(-50%, -50%); }
.pin-start, .pin-end, .pin-stop {
  display: grid; place-items: center; width: 28px; height: 28px; font-size: 13px; font-weight: 700;
  box-shadow: 0 2px 6px rgb(0 0 0 / 0.35); border: 2px solid #fff;
}
.pin-start { background: #f5b301; color: #1c1c1e; border-radius: 50%; }
.pin-end { background: #e53935; color: #fff; border-radius: 6px; }
.pin-stop { background: #fff; color: #1c1c1e; border-radius: 50%; border-color: #f5b301; }
.pin-me {
  width: 16px; height: 16px; border-radius: 50%; background: #1a73e8; border: 3px solid #fff;
  box-shadow: 0 0 0 8px rgb(26 115 232 / 0.2), 0 1px 4px rgb(0 0 0 / 0.4);
}
.dot.start { background: #f5b301; }
.dot.end { background: #e53935; border-radius: 2px; }
.dot.stop { background: #fff; border: 2px solid #f5b301; }

/* ── Route fields ── */
.route-fields { position: relative; display: flex; flex-direction: column; gap: 8px; padding-right: 44px; }
.swap {
  position: absolute; right: 0; top: 50%; transform: translateY(-50%);
  width: 36px; height: 36px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--bg); font-size: 18px;
}
.icon-btn { border: 0; background: var(--bg); border-radius: 10px; padding: 0 10px; cursor: pointer; color: var(--hint); }

/* ── More options ── */
details.more summary { cursor: pointer; list-style: none; display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
details.more summary::-webkit-details-marker { display: none; }
details.more summary::after { content: '▾'; color: var(--hint); }
details.more[open] summary::after { content: '▴'; }
details.more summary .muted { font-weight: 400; flex: 1; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.opt { display: grid; grid-template-columns: 64px 1fr; gap: 8px; align-items: start; padding-top: 12px; }
.opt > label, .opt > span:first-child { font-size: 14px; color: var(--hint); padding-top: 7px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid color-mix(in srgb, var(--hint) 45%, transparent); background: transparent; border-radius: 999px;
  padding: 6px 12px; font-size: 14px; cursor: pointer;
}
.chip[aria-pressed="true"] { border-color: var(--btn); background: color-mix(in srgb, var(--btn) 18%, transparent); color: var(--text); font-weight: 600; }
.hint { font-size: 12px; color: var(--hint); }

/* ── Font size (標準 / 大 / 特大): zoom the panels only; zooming the map would break its touch maths ── */
.font-size { margin-left: 12px; white-space: nowrap; }
.topbar { gap: 8px; }
.topbar .brand { flex: 1; }
[data-fs="lg"] .panel, [data-fs="lg"] .topbar .brand { zoom: 1.15; }
[data-fs="xl"] .panel, [data-fs="xl"] .topbar .brand { zoom: 1.3; }
