:root {
  --mist: #E3E7DF;
  --paper: #F0F2EB;
  --indigo: #1E2B55;
  --indigo-soft: #4A5578;
  --marigold: #E2A02B;
  --teak: #7A5233;
  --moss: #46654A;
  --line: #C9CFC3;
  --warn: #9C2F2F;
  --radius: 6px;
  --panel-w: 420px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--mist);
  color: var(--indigo);
  font-family: 'IBM Plex Sans Thai', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
}
h1, h2, h3 { font-family: 'Noto Serif Thai', serif; margin: 0; line-height: 1.3; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--marigold); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* layout: map top on mobile, panel left on desktop */
.shell { display: grid; grid-template-rows: 38dvh 1fr; height: 100dvh; }
.map-wrap { order: 1; position: relative; min-height: 0; }
.panel { order: 2; min-height: 0; overflow-y: auto; background: var(--paper); border-top: 3px solid var(--indigo); display: flex; flex-direction: column; }
#map { position: absolute; inset: 0; background: #d5dbd0; }
.map-fallback { position: absolute; inset: auto 16px 16px 16px; margin: 0; padding: 12px 14px; background: var(--paper); border-left: 4px solid var(--warn); z-index: 500; }

@media (min-width: 900px) {
  .shell { grid-template-columns: var(--panel-w) 1fr; grid-template-rows: 1fr; }
  .panel { order: 1; border-top: 0; border-right: 3px solid var(--indigo); }
  .map-wrap { order: 2; }
}

/* masthead */
.masthead { position: sticky; top: 0; z-index: 5; background: var(--paper); padding: 14px 16px 0; border-bottom: 1px solid var(--line); }
.brand { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 2px 10px; }
.brand-side { margin-left: auto; }
.brand .greeting { flex-basis: 100%; }
.lang-select { padding: 4px 6px; font-size: 13px; }
.masthead h1 { font-size: 22px; }
.greeting { margin: 0; color: var(--indigo-soft); font-size: 13px; }
.tabs { display: flex; gap: 4px; margin-top: 10px; }
.tabs button { background: none; border: 0; border-bottom: 3px solid transparent; padding: 8px 12px; font-weight: 500; color: var(--indigo-soft); }
.tabs button[aria-selected="true"] { color: var(--indigo); border-bottom-color: var(--marigold); }
.count { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 4px; background: var(--indigo); color: var(--paper); border-radius: 10px; font-size: 12px; text-align: center; }

.view { padding: 14px 16px 8px; flex: 1; }

/* explore */
.tools { display: grid; gap: 10px; margin-bottom: 12px; }
input[type="search"] { width: 100%; padding: 10px 12px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { padding: 5px 12px; background: none; border: 1px solid var(--line); border-radius: 16px; }
.chips button[aria-pressed="true"] { background: var(--indigo); border-color: var(--indigo); color: var(--paper); }

.places { list-style: none; margin: 0; padding: 0; }
.place { display: flex; align-items: stretch; border-left: 5px solid var(--cat, var(--line)); background: #fff; margin-bottom: 8px; border-radius: 0 var(--radius) var(--radius) 0; }
.place-head { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; padding: 10px 12px; background: none; border: 0; text-align: left; }
.place-head strong { flex: 1; font-weight: 600; }
.add-mini { width: 44px; background: none; border: 0; border-left: 1px solid var(--line); font-size: 20px; color: var(--indigo); }
.add-mini.added { background: var(--marigold); }
.place-meta { font-size: 12px; color: var(--indigo-soft); }
.place-body { padding: 0 12px 12px; display: grid; gap: 8px; }
.place-body p { margin: 0; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin: 0; font-size: 13px; }
.facts dt { color: var(--indigo-soft); }
.facts dd { margin: 0; }
.tips { margin: 0; padding-left: 18px; font-size: 13px; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; }

button.primary, .btns button, .actions button, .auto button {
  padding: 7px 14px; background: var(--paper); border: 1px solid var(--indigo); border-radius: var(--radius);
}
button.primary { background: var(--indigo); color: var(--paper); }
button.danger { border-color: var(--warn); color: var(--warn); }
button.added { background: var(--marigold); border-color: var(--marigold); color: var(--indigo); }

/* plan */
.auto { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 14px; }
.auto summary { padding: 10px 12px; cursor: pointer; font-weight: 600; }
.auto form { padding: 0 12px 12px; display: grid; gap: 10px; }
.auto fieldset { border: 0; padding: 0; margin: 0; }
.auto legend { font-size: 13px; color: var(--indigo-soft); padding: 0; margin-bottom: 4px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.checks label { display: inline-flex; align-items: center; gap: 6px; }
.hint { margin: 0; font-size: 12px; color: var(--indigo-soft); }
.row { display: flex; align-items: center; gap: 8px; }
select { padding: 6px 8px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }

.daybar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 14px; }
.day-tabs { display: flex; flex-wrap: wrap; gap: 4px; }
.day-tabs button { padding: 5px 12px; background: none; border: 1px solid var(--line); border-radius: var(--radius); }
.day-tabs button[aria-selected="true"] { background: var(--indigo); border-color: var(--indigo); color: var(--paper); }

/* timeline: the route thread */
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.stop, .leg { position: relative; padding-left: 44px; }
.stop::before, .leg::before { content: ''; position: absolute; left: 15px; top: 0; bottom: 0; width: 4px; background: var(--marigold); }
.stop:first-child::before { top: 14px; }
.stop:last-child::before { bottom: calc(100% - 14px); }
.stop:only-child::before { display: none; }
.leg { padding-top: 6px; padding-bottom: 6px; font-size: 12px; color: var(--indigo-soft); }
.leg.wait { color: var(--teak); }
.node { position: absolute; left: 4px; top: 0; width: 26px; height: 26px; display: grid; place-items: center; border-radius: 50%; background: var(--indigo); color: var(--paper); font-weight: 600; font-size: 13px; border: 3px solid var(--paper); box-sizing: content-box; margin: -3px; }
.gap { padding: 6px 0 10px; font-size: 12px; color: var(--indigo-soft); }
.gap.wait { color: var(--teak); }
.stop-card { background: #fff; border-left: 5px solid var(--cat, var(--line)); padding: 8px 10px; border-radius: 0 var(--radius) var(--radius) 0; }
.stop-time { font-size: 13px; font-weight: 600; }
.stop-name { font-weight: 600; }
.stop-warn { color: var(--warn); font-size: 12px; margin: 2px 0 0; }
.stop-tools { display: flex; gap: 6px; margin-top: 6px; }
.stop-tools button { min-width: 34px; padding: 2px 8px; background: none; border: 1px solid var(--line); border-radius: var(--radius); }
.stop-tools button:disabled { opacity: .35; cursor: default; }
.day-total { margin: 12px 0 0; font-size: 13px; color: var(--indigo-soft); }
.empty { padding: 20px 14px; background: #fff; border: 1px dashed var(--line); border-radius: var(--radius); }
.empty p { margin: 0 0 4px; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.toast { min-height: 1.4em; margin: 8px 0 0; font-size: 13px; color: var(--moss); }
.foot { padding: 12px 16px 20px; font-size: 12px; color: var(--indigo-soft); }

/* map pins */
.gpin { position: relative; line-height: 0; filter: drop-shadow(0 2px 2px rgba(0,0,0,.4)); }
.gpin svg { display: block; overflow: visible; }
.gpin path { fill: var(--c, var(--indigo)); stroke: rgba(0,0,0,.28); stroke-width: 1; }
.gpin.dim { opacity: .45; }
.gpin.num path { stroke: var(--marigold); stroke-width: 2; }
.gpin.num span { position: absolute; top: 0; left: 0; right: 0; height: 74%; display: grid; place-items: center; color: #fff; font-weight: 600; font-size: 14px; line-height: 1; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }

@media print {
  .map-wrap, .tabs, .masthead, .tools, .auto, .daybar .row, .actions, .stop-tools, .foot { display: none !important; }
  .shell { display: block; height: auto; }
  .panel { overflow: visible; border: 0; }
  #view-explore { display: none !important; }
  #view-plan { display: block !important; }
}

/* shared button look for links + buttons */
.btn { display: inline-block; padding: 8px 14px; background: var(--paper); border: 1px solid var(--indigo); border-radius: var(--radius); color: var(--indigo); text-decoration: none; text-align: center; }
.btn.primary { background: var(--indigo); color: var(--paper); }
.btn.added { background: var(--marigold); border-color: var(--marigold); }
.icon-btn { width: 40px; height: 40px; flex: none; background: none; border: 1px solid var(--line); border-radius: 50%; font-size: 22px; line-height: 1; }

/* bottom drawer */
.drawer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 900;
  max-height: 62dvh; display: flex; flex-direction: column;
  background: var(--paper); border-top: 5px solid var(--cat, var(--indigo));
  border-radius: 14px 14px 0 0; box-shadow: 0 -6px 24px rgba(30, 43, 85, .22);
  transform: translateY(105%); visibility: hidden;
  transition: transform .28s ease-out, visibility 0s linear .28s;
}
.drawer.open { transform: none; visibility: visible; transition: transform .28s ease-out; }
.drawer-grip { width: 44px; height: 4px; margin: 8px auto 0; border-radius: 2px; background: var(--line); flex: none; }
.drawer-inner { overflow-y: auto; padding: 8px 16px 20px; display: grid; gap: 10px; }
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.drawer-head h2 { font-size: 20px; }
.drawer-sub { margin: 2px 0 0; font-size: 13px; color: var(--indigo-soft); }
.drawer-desc { margin: 0; }
.photos { display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x proximity; padding-bottom: 4px; min-height: 120px; }
.photos a { flex: none; scroll-snap-align: start; }
.photos img { display: block; height: 150px; width: auto; max-width: 260px; object-fit: cover; border-radius: var(--radius); background: var(--line); }
.photo-msg { margin: 0; align-self: center; font-size: 13px; color: var(--indigo-soft); }
.credit { margin: -6px 0 0; font-size: 11px; color: var(--indigo-soft); }
.drawer-actions { display: flex; flex-wrap: wrap; gap: 8px; }

@media (min-width: 900px) {
  .drawer { left: var(--panel-w); max-height: 58dvh; }
  .drawer-inner { grid-template-columns: 1fr 1fr; align-items: start; }
  .drawer-head, .photos, .wiki-img, .credit, .drawer-actions { grid-column: 1 / -1; }
}

/* explore: province + sort row, load-more */
.row2 { display: flex; gap: 8px; align-items: center; }
.row2 select { flex: 1; min-width: 0; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; flex: none; }
.seg button { padding: 6px 10px; background: #fff; border: 0; font-size: 13px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--indigo); color: var(--paper); }
.more { display: block; width: 100%; margin: 4px 0 12px; padding: 9px; background: none; border: 1px dashed var(--indigo-soft); border-radius: var(--radius); }
.auto select { max-width: 100%; }

/* Wikipedia image in drawer */
.wiki-img img { display: block; width: 100%; max-height: 220px; object-fit: cover; border-radius: var(--radius); background: var(--line); }

/* quote (เสนอราคาเหมารถ) */
.quote { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); margin-top: 16px; }
.quote summary { padding: 10px 12px; cursor: pointer; font-weight: 600; }
.quote-body { padding: 0 12px 12px; display: grid; gap: 10px; }
.quote select, .quote input[type="date"], .quote input[type="number"], .quote textarea { padding: 6px 8px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
.quote textarea { width: 100%; font-size: 13px; line-height: 1.5; resize: vertical; }
.quote .row label { min-width: 8.5em; }
.q-day h4 { margin: 0 0 2px; font-size: 14px; }
.q-day table { width: 100%; border-collapse: collapse; font-size: 13px; }
.q-day td { padding: 2px 0; }
.q-day td:last-child, .q-total strong { text-align: right; font-variant-numeric: tabular-nums; }
.q-day tr.sum td { border-top: 1px solid var(--line); font-weight: 600; }
.q-total { display: grid; gap: 4px; padding: 8px 10px; background: var(--paper); border-left: 5px solid var(--marigold); border-radius: 0 var(--radius) var(--radius) 0; }
.q-total div { display: flex; justify-content: space-between; gap: 8px; }
.q-total strong { font-size: 16px; }
.q-offer input { width: 9em; text-align: right; }
.q-src ul { margin: 4px 0 0; padding-left: 18px; font-size: 12px; }
.quote .actions { margin-top: 0; }
