/* 2026 國旅補助旅宿地圖 — 版面與主題 */

:root {
  --bg: #f5f6f4;
  --panel: #ffffff;
  --ink: #1a1c1a;
  --ink-2: #5d635e;
  --line: #dfe3de;
  --brand: #1f6f5c;
  --brand-ink: #ffffff;
  --brand-soft: #e6f1ed;
  --accent: #c2571f;
  --accent-soft: #fbeee4;
  --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 8px 24px rgba(20, 30, 25, .06);
  --radius: 12px;
  --topbar-h: 60px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14171a;
    --panel: #1c2024;
    --ink: #e8ecea;
    --ink-2: #9aa5a0;
    --line: #2c3238;
    --brand: #4bbf9e;
    --brand-ink: #10231d;
    --brand-soft: #1d332d;
    --accent: #e08a4e;
    --accent-soft: #33261c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
  }
}

:root[data-theme="dark"] {
  --bg: #14171a;
  --panel: #1c2024;
  --ink: #e8ecea;
  --ink-2: #9aa5a0;
  --line: #2c3238;
  --brand: #4bbf9e;
  --brand-ink: #10231d;
  --brand-soft: #1d332d;
  --accent: #e08a4e;
  --accent-soft: #33261c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* 手機瀏覽器的網址列會伸縮，100vh 會被切掉一截，支援 dvh 就改用 dvh */
@supports (height: 100dvh) {
  html, body { height: 100dvh; }
}

body { display: flex; flex-direction: column; overflow: hidden; }

a { color: var(--brand); }

.skip {
  position: absolute; left: -999px; top: 0; z-index: 100;
  background: var(--brand); color: var(--brand-ink); padding: 8px 14px;
}
.skip:focus { left: 8px; top: 8px; }

/* ---------------------------------------------------------------- 標頭 */

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  height: var(--topbar-h); flex: 0 0 auto;
  padding: 0 max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left));
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { font-size: 26px; }
.topbar h1 { font-size: 17px; margin: 0; letter-spacing: .01em; }
.sub { margin: 0; font-size: 12px; color: var(--ink-2); white-space: nowrap;
       overflow: hidden; text-overflow: ellipsis; }
.topActions { display: flex; gap: 6px; flex: 0 0 auto; }

button { font: inherit; cursor: pointer; }

.ghost {
  background: transparent; color: var(--ink); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 12px;
}
.ghost:hover { border-color: var(--brand); color: var(--brand); }
.ghost.small { padding: 3px 10px; font-size: 13px; }

/* ---------------------------------------------------------------- 說明區 */

.guide {
  flex: 0 0 auto; background: var(--panel); border-bottom: 1px solid var(--line);
  padding: 14px; max-height: 45vh; overflow: auto;
}
.guideGrid { display: grid; gap: 18px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.guide h2 { font-size: 14px; margin: 0 0 6px; color: var(--brand); }
.guide ul, .guide ol { margin: 0; padding-left: 18px; }
.guide li { margin: 2px 0; }
.note { font-size: 12.5px; color: var(--ink-2); margin: 6px 0 0; }
.mini { border-collapse: collapse; font-size: 13px; width: 100%; max-width: 380px; }
.mini th, .mini td { border: 1px solid var(--line); padding: 3px 8px; text-align: center; }
.mini th { background: var(--brand-soft); }
.dl {
  display: inline-block; margin: 4px 6px 0 0; padding: 6px 12px; border-radius: 999px;
  background: var(--brand); color: var(--brand-ink); text-decoration: none; font-size: 13px;
}

/* ---------------------------------------------------------------- 版面 */

.layout { flex: 1 1 auto; display: flex; min-height: 0; }

.panel {
  width: 400px; flex: 0 0 auto; display: flex; flex-direction: column;
  background: var(--panel); border-right: 1px solid var(--line); min-height: 0;
}

.mapWrap { flex: 1 1 auto; position: relative; min-width: 0; }
#map { position: absolute; inset: 0; background: var(--bg); }

.mapHud {
  position: absolute; left: 50%; transform: translateX(-50%); top: 10px; z-index: 500;
  background: var(--panel); color: var(--ink); border: 1px solid var(--line);
  border-radius: 999px; padding: 5px 14px; font-size: 13px; box-shadow: var(--shadow);
}

/* ---------------------------------------------------------------- 篩選列 */

.filterbar {
  flex: 0 0 auto; background: var(--panel); border-bottom: 1px solid var(--line);
  padding: 8px 14px 10px;
}
.barRow {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 6px;
}
.barRow:first-child { margin-top: 0; }
.barMore { border-top: 1px dashed var(--line); margin-top: 8px; padding-top: 6px; }
.spacer { flex: 1 1 auto; }

#q {
  flex: 1 1 260px; max-width: 380px; font: inherit; padding: 8px 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
}
#q:focus { outline: 2px solid var(--brand); outline-offset: 1px; }

select {
  font: inherit; font-size: 14px; padding: 7px 10px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--bg); color: var(--ink); max-width: 170px;
}
select:disabled { opacity: .5; }

.grp { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.lbl { font-size: 12px; color: var(--ink-2); }
.hint { color: var(--brand); margin-left: 4px; }
.inline { font-size: 12px; color: var(--ink-2); display: flex; align-items: center; gap: 5px; }
.check { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; color: var(--ink); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  border-radius: 999px; padding: 4px 11px; font-size: 13px; white-space: nowrap;
}
.chip:hover { border-color: var(--brand); }
.chip[aria-pressed="true"], .chip.on {
  background: var(--brand); border-color: var(--brand); color: var(--brand-ink);
}
.chip .n { opacity: .7; font-size: 11px; margin-left: 3px; }

/* 房價區間：雙滑桿疊在同一條軌道上，加上可直接輸入的數字欄 */
.priceGrp { gap: 8px; }
.num {
  width: 82px; font: inherit; font-size: 14px; padding: 6px 8px; text-align: right;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink);
}
.num:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.dash { color: var(--ink-2); }

.range { position: relative; width: 230px; height: 24px; flex: 0 0 auto; }
.rtrack, .rfill {
  position: absolute; top: 10px; height: 4px; border-radius: 2px; pointer-events: none;
}
.rtrack { left: 0; right: 0; background: var(--line); }
.rfill { background: var(--brand); }

.range input[type="range"] {
  position: absolute; left: 0; top: 0; width: 100%; height: 24px; margin: 0;
  background: none; pointer-events: none; -webkit-appearance: none; appearance: none;
}
.range input[type="range"]:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.range input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; pointer-events: auto; width: 16px; height: 16px; border-radius: 50%;
  background: var(--panel); border: 3px solid var(--brand); cursor: grab; margin-top: 0;
}
.range input[type="range"]::-moz-range-thumb {
  pointer-events: auto; width: 14px; height: 14px; border-radius: 50%;
  background: var(--panel); border: 3px solid var(--brand); cursor: grab;
}
.range input[type="range"]::-webkit-slider-runnable-track { height: 24px; background: none; }
.range input[type="range"]::-moz-range-track { height: 24px; background: none; }
.nearRow { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); }
.nearRow[hidden] { display: none; }

.resultHead {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
  font-size: 13px; color: var(--ink-2); flex: 0 0 auto;
}
#count strong { color: var(--ink); }

/* ---------------------------------------------------------------- 結果清單 */

.results { flex: 1 1 auto; min-height: 0; overflow: auto; overscroll-behavior: contain; }

.card {
  padding: 11px 12px; border-bottom: 1px solid var(--line); cursor: pointer;
  display: grid; grid-template-columns: 1fr auto; gap: 2px 10px;
}
.card:hover, .card.hot { background: var(--brand-soft); }
.card h3 { margin: 0; font-size: 15px; grid-column: 1; }
.card p { margin: 0; }                     /* 段落預設的上下 margin 會把卡片撐高 */
.card .meta { grid-column: 1; font-size: 12.5px; color: var(--ink-2); }
.card .plan {
  grid-column: 1 / -1; font-size: 13px; color: var(--ink-2); margin: 4px 0 0;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card .side { grid-column: 2; grid-row: 1 / span 2; text-align: right; }
.price { font-weight: 700; color: var(--accent); font-size: 15px; white-space: nowrap; }
.price small { font-weight: 400; color: var(--ink-2); }
.dist { font-size: 12px; color: var(--ink-2); }
.star { color: #d98324; font-weight: 700; }
.rv { color: var(--ink-2); font-size: 11.5px; margin-left: 2px; }
.rack { display: block; font-size: 12px; color: var(--ink-2); font-weight: 400; white-space: nowrap; }
.rack.strike { text-decoration: line-through; opacity: .75; }
.psrc {
  display: inline-block; font-size: 10.5px; line-height: 1.5; padding: 0 6px;
  border-radius: 999px; margin-left: 4px; vertical-align: middle;
  background: var(--brand-soft); color: var(--brand); font-weight: 400;
}
.psrc.src-manual { background: var(--accent-soft); color: var(--accent); }
.psrc.src-plan { background: var(--accent-soft); color: var(--accent); }
.psrc.src-ota { background: var(--line); color: var(--ink-2); }
.ota { color: var(--ink-2); font-weight: 700; font-size: 15px; white-space: nowrap; }
.ota small { font-weight: 400; }
.muted { color: var(--ink-2); font-size: 12.5px; }
.tags { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.tag {
  font-size: 11.5px; padding: 1px 8px; border-radius: 999px;
  background: var(--brand-soft); color: var(--brand); border: 1px solid transparent;
}
.tag.alt { background: var(--accent-soft); color: var(--accent); }
.tag.warn { background: transparent; border-color: var(--line); color: var(--ink-2); }
.fav { border: 0; background: none; font-size: 17px; line-height: 1; padding: 0 0 0 6px; }

.empty { padding: 40px 20px; text-align: center; color: var(--ink-2); }

/* ---------------------------------------------------------------- 詳情 */

.sheet {
  position: fixed; inset: 0; z-index: 1200; background: rgba(10, 15, 12, .45);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.sheet[hidden] { display: none; }
.sheetInner {
  background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow);
  max-width: 560px; width: 100%; max-height: 84vh; overflow: auto; padding: 20px; position: relative;
}
.sheetClose {
  position: absolute; right: 10px; top: 10px; border: 0; background: transparent;
  color: var(--ink-2); font-size: 18px;
}
.sheetInner h2 { margin: 0 6px 2px 0; font-size: 19px; }
.sheetInner .kv { display: grid; grid-template-columns: 76px 1fr; gap: 4px 10px; font-size: 14px; margin: 12px 0; }
.sheetInner .kv dt { color: var(--ink-2); }
.sheetInner .kv dd { margin: 0; word-break: break-word; }
.planBox {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; margin: 8px 0; white-space: pre-wrap; font-size: 14px;
}
.planBox h4 { margin: 0 0 4px; font-size: 13px; color: var(--brand); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.actions a, .actions button {
  text-decoration: none; font-size: 14px; padding: 8px 14px; border-radius: 999px;
  background: var(--brand); color: var(--brand-ink); border: 0;
}
.actions .sec { background: var(--bg); color: var(--ink); border: 1px solid var(--line); }
.actions .shareBtn { background: var(--accent); color: #fff; }

/* ---------------------------------------------------------------- 地圖標記 */

.pin-approx { opacity: .55; filter: grayscale(.4); }
.leaflet-popup-content { margin: 10px 12px; font-size: 14px; }
.leaflet-popup-content b { font-size: 15px; }
.leaflet-container { font: inherit; }

/* ---------------------------------------------------------------- 頁尾 */

.foot {
  flex: 0 0 auto; padding: 8px 14px; font-size: 11.5px; color: var(--ink-2);
  background: var(--panel); border-top: 1px solid var(--line);
}
.foot p { margin: 1px 0; }

/* Ko-fi：低調的文字連結，不用浮動視窗（見 README 的說明） */
.kofi { color: var(--ink-2); text-decoration: none; border-bottom: 1px dotted var(--line); }
.kofi:hover { color: var(--accent); border-bottom-color: var(--accent); }

.mobileTabs { display: none; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------ 平板／窄桌機 */

@media (min-width: 760px) and (max-width: 1180px) {
  .panel { width: 336px; }
  .topbar h1 { font-size: 16px; }
  #q { flex-basis: 200px; }
}

/* ---------------------------------------------------------------- 手機 */

@media (max-width: 759px) {
  .layout { position: relative; }
  .panel { width: 100%; border-right: 0; }
  .mapWrap { position: absolute; inset: 0; }
  body.view-list .mapWrap { display: none; }
  body.view-map .panel { display: none; }
  .filterbar { padding: 8px 10px; }
  /* 手機畫面小：只留「搜尋 + 縣市鄉鎮 + 我附近」，其餘跟著「更多條件」一起收合，
     結果清單才有足夠高度 */
  .barRow.secondary, .barRow.places { display: none; }
  body.filters-open .barRow.secondary,
  body.filters-open .barRow.places { display: flex; }
  #q { flex: 1 1 100%; }
  /* 還沒選縣市時鄉鎮選單是停用的，手機上直接收起來，省一整排 */
  #town:disabled { display: none; }
  /* 展開後別把結果清單擠光，篩選區自己捲 */
  body.filters-open .filterbar { max-height: 56vh; overflow: auto; }
  #q { max-width: none; }
  select { flex: 1 1 40%; max-width: none; }
  .range { width: 100%; }
  .num { width: 72px; }

  .filterbar { padding-left: max(10px, env(safe-area-inset-left));
               padding-right: max(10px, env(safe-area-inset-right)); }
  .card { padding-left: max(12px, env(safe-area-inset-left));
          padding-right: max(12px, env(safe-area-inset-right)); }
  /* 手機上價格／距離／收藏改成橫排，只佔第一列，卡片就不會被撐高 */
  .card .side { grid-row: 1; display: flex; align-items: center; gap: 8px; }
  .card .meta { grid-column: 1 / -1; }
  .card .dist { font-size: 12px; }

  .mobileTabs {
    display: flex; flex: 0 0 auto; background: var(--panel); border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);          /* 避開 iPhone 的home 指示條 */
  }
  .mobileTabs button {
    flex: 1 1 0; border: 0; background: transparent; color: var(--ink-2);
    padding: 12px 0; font-size: 14px; min-height: 46px;
  }
  .mobileTabs button.active { color: var(--brand); font-weight: 700; box-shadow: inset 0 -2px 0 var(--brand); }
  /* 分頁列最右邊的小咖啡：固定寬度，不跟兩個分頁搶空間 */
  .kofiTab {
    flex: 0 0 auto; width: 46px; display: flex; align-items: center; justify-content: center;
    font-size: 17px; text-decoration: none; opacity: .5;
    border-left: 1px solid var(--line);
  }
  .kofiTab:active { opacity: 1; }

  .topbar { --topbar-h: 54px; }
  .topbar h1 { font-size: 15px; }
  .logo { font-size: 22px; }
  .foot { display: none; }

  /* 詳情改成從底部升起的 bottom sheet，符合手機操作習慣 */
  .sheet { align-items: flex-end; padding: 0; }
  .sheetInner {
    max-height: 88vh; max-height: 88dvh; border-radius: 16px 16px 0 0;
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
    animation: sheetUp .18s ease-out;
  }
  .sheetInner::before {
    content: ""; display: block; width: 38px; height: 4px; border-radius: 2px;
    background: var(--line); margin: -6px auto 12px;
  }
  .sheetClose { right: 8px; top: 8px; font-size: 22px; padding: 6px 10px; }
  .sheetInner .kv { grid-template-columns: 68px 1fr; }
}

@keyframes sheetUp { from { transform: translateY(14px); opacity: .6 } to { transform: none; opacity: 1 } }

/* 很窄的手機（iPhone SE 等）：標頭按鈕只留圖示 */
@media (max-width: 400px) {
  .topbar h1 { font-size: 14px; }
  /* 小螢幕把卡片壓扁一點，一屏才看得到兩筆以上 */
  .card { padding: 10px 12px; }
  .card .plan { font-size: 12.5px; margin-top: 2px; }
  .card .tags { max-height: 24px; overflow: hidden; margin-top: 4px; }
  .sub { font-size: 11px; }
  #btnGuide::after { content: "說明"; }
  #btnDownload::after { content: "下載"; }
  #btnGuide, #btnDownload { font-size: 0; }
  #btnGuide::after, #btnDownload::after { font-size: 13px; }
  .num { width: 64px; }
}

/* 最窄的機型（≤360px）：「我附近」只留圖示 */
@media (max-width: 360px) {
  #btnLocate .txt { display: none; }
}

/* 手機橫放：高度很矮，把不必要的高度全部縮掉 */
@media (max-width: 900px) and (max-height: 480px) {
  .panel { width: 100%; }
  .topbar { --topbar-h: 46px; }
  .guide { max-height: 60vh; }
  body.filters-open .filterbar { max-height: 70vh; }
  .mobileTabs button { padding: 7px 0; min-height: 38px; }
}

/* 觸控裝置：把可點擊的東西放大到手指按得到（約 44px） */
@media (pointer: coarse) {
  .chip { padding: 9px 14px; font-size: 14px; }
  .ghost { padding: 9px 14px; }
  .ghost.small { padding: 7px 12px; }
  select, .num { padding: 10px 10px; font-size: 16px; }   /* 16px 以下 iOS 會自動放大畫面 */
  #q { padding: 11px 16px; font-size: 16px; }
  .fav { padding: 6px 0 6px 10px; font-size: 20px; }
  .card { padding: 14px 12px; }
  .range { height: 34px; }
  .rtrack, .rfill { top: 15px; }
  .range input[type="range"] { height: 34px; }
  .range input[type="range"]::-webkit-slider-thumb { width: 22px; height: 22px; }
  .range input[type="range"]::-moz-range-thumb { width: 20px; height: 20px; }
  .actions a, .actions button { padding: 11px 16px; }
}

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