@charset "UTF-8";
/* ============================================================
   RWD 覆寫樣式（必須為最後一支載入的 CSS）
   斷點：max-width:768px 進入行動版，與 js/utils/breakpoint.js 一致。
   原則：桌面樣式只增不改，行動版差異一律包在此檔的 media query 內。
   詳見 docs/rwd-spec.md
   ============================================================ */

/* 展開／收合 chevron：桌面隱藏，僅行動版顯示 */
.filter-card-toggle {
    display: none;
}

/* 地圖圖例 FAB 鈕：桌面隱藏（圖例常駐），僅行動版顯示 */
.map-legend-fab {
    display: none;
}

:root {
    /* 安全區（瀏海 / home bar），不支援時退回 0 */
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);

    /* 行動版主功能鈕尺寸（觸控目標 ≥44px） */
    --nav-trigger-size: 44px;

    /* 行動版頂部品牌列高度，用來把主功能鈕垂直置中。
       = .filter-brand-header 上下 padding (10px + 8px) + .filter-brand-logo 高度 (40px)。
       logo 為 width:100% + max-height:40px，在行動版寬度下必定被 max-height 夾住，
       故盒高恆為 40px。若改動這三個值，此處要同步更新。 */
    --brand-bar-height: 58px;

    /* 查詢藥丸與品牌列之間的間距 */
    --filter-pill-gap: 12px;

    /* Bottom sheet 三段高度（Phase 2/3 使用，先在此定義單一來源）。
       full 同時是面板元素的實際高度；bottomSheet.js 的 stageMetrics 以
       peek/half 對 full 的比例回推，故改 full 不會連動改變 peek/half 的實際高度。 */
    --sheet-peek: 18vh;
    --sheet-half: 56vh;
    --sheet-full: 80vh;
}

@media (max-width: 768px) {
    /* ----------------------------------------------------------
       Phase 1：filter-card → 頂部全寬搜尋／篩選列
       ---------------------------------------------------------- */
    /* 品牌列（頂部導覽列）改為獨立固定於畫面頂端，脫離 .filter-card 流。
       這樣查詢列才能與它分離、往下浮成一顆藥丸。
       position:fixed 的包含區塊是視窗，不受 .filter-card 的 overflow 影響；
       .filter-card 未使用 transform/filter，不會意外變成包含區塊。 */
    .filter-brand-header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        /* 上內距含安全區，讓背景一路鋪滿瀏海區；
           內容帶（padding 10/8 + logo 40 = --brand-bar-height）維持原高度，
           主功能鈕的垂直置中算式才不用改。 */
        padding: calc(var(--safe-top) + 10px) 14px 8px;
        box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
    }

    /* 查詢列：與品牌列隔開一段距離的浮動藥丸 */
    .filter-card {
        top: calc(var(--safe-top) + var(--brand-bar-height) + var(--filter-pill-gap));
        left: 12px;
        right: 12px;
        width: auto;
        max-width: none;
        max-height: calc(
            100dvh - var(--safe-top) - var(--brand-bar-height) - var(--filter-pill-gap) - 16px
        );
        /* 收合時為長條藥丸；展開時放寬成圓角卡片（見下方 :not(.is-collapsed)） */
        border-radius: 999px;
        /* 藥丸圓角需露出品牌列（fixed 子元素）；收合動畫已由各區塊自行 overflow:hidden */
        overflow: visible;
        box-shadow: 0 6px 20px rgba(15, 23, 42, 0.18);
        /* 圓角一律「瞬間切換」，不取中間值。
           999px 會依盒子尺寸被 CSS 等比縮放，盒子一變高，上方兩角就往內彎成大弧線，
           而標題文字位置不動（.filter-card 為 overflow:visible），看起來就溢出白底。
           收合方向：等高度縮完（0.24s）才變回藥丸，過程中維持 20px 直角感。 */
        transition: border-radius 0s linear 0.24s;
    }

    /* 展開：立刻攤成圓角卡片，盒子開始變高時圓角已就定位 */
    .filter-card:not(.is-collapsed) {
        border-radius: 20px;
        transition: border-radius 0s;
    }

    /* 標題列當作展開／收合的點擊區 */
    .filter-card-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
        cursor: pointer;
        user-select: none;
        /* 藥丸的左右弧線會吃掉邊緣，內距加大讓文字與 chevron 不貼著曲線 */
        padding: 0.7rem 1.15rem;

    }

    /* 收合（藥丸）時底線會畫在弧線內側，很突兀；展開後才需要它分隔內容 */
    .filter-card.is-collapsed .filter-card-header {
        border-bottom-color: transparent;
    }

    .filter-card-header .filter-card-toggle {
        display: inline-flex;
        flex: 0 0 auto;
        font-size: 0.9rem;
        color: #6b7280;
        /* 與內容展開同曲線同節奏，避免箭頭先轉完、內容還在動 */
        transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
    }

    /* 收合／展開過場：用 max-height + opacity 讓內容「滑」進滑出，
       取代 display:none 的瞬間切換。卡片本身高度由子元素撐開，
       因此子元素收合時整張卡片會跟著滑順縮起。
       .has-collapse-anim 由 coastline-filter.js 於首次渲染後才加上，
       避免初次載入（預設收合）時看到一次多餘的收合動畫。 */
    .filter-card.has-collapse-anim .filter-card-body,
    .filter-card.has-collapse-anim .filter-card-footer,
    .filter-card.has-collapse-anim .filter-results {
        /* 展開：單純由上往下長出來，不做額外位移或錯開，
           全部區塊同一節奏，看起來就是一個往下展開的動作。 */
        transition:
            max-height 0.32s cubic-bezier(0.22, 1, 0.36, 1),
            opacity 0.26s ease-out,
            padding-top 0.32s cubic-bezier(0.22, 1, 0.36, 1),
            padding-bottom 0.32s cubic-bezier(0.22, 1, 0.36, 1),
            visibility 0s;
    }

    /* 收合狀態：只露品牌列＋標題列，內容滑上去收起 */
    .filter-card.is-collapsed .filter-card-body,
    .filter-card.is-collapsed .filter-card-footer,
    .filter-card.is-collapsed .filter-results {
        max-height: 0;
        opacity: 0;
        padding-top: 0;
        padding-bottom: 0;
        border-top-width: 0;
        overflow: hidden;
        /* 收合後才隱藏（延遲到動畫結束），內部元素不再被 Tab 聚焦 */
        visibility: hidden;
    }

    /* 收合：較短、起步即加速的曲線。收起本來就該比展開果斷。 */
    .filter-card.has-collapse-anim.is-collapsed .filter-card-body,
    .filter-card.has-collapse-anim.is-collapsed .filter-card-footer,
    .filter-card.has-collapse-anim.is-collapsed .filter-results {
        transition:
            max-height 0.24s cubic-bezier(0.4, 0, 1, 1),
            opacity 0.16s ease-in,
            padding-top 0.24s cubic-bezier(0.4, 0, 1, 1),
            padding-bottom 0.24s cubic-bezier(0.4, 0, 1, 1),
            visibility 0s linear 0.24s;
    }

    .filter-card.is-collapsed .filter-card-toggle {
        transform: rotate(-90deg);
    }

    /* 展開時讓內容可捲動，避免超出視窗；max-height 同時是滑動的終點值。
       關鍵：這個值要「貼近實際內容高度」，否則動畫會提早演完再空等
       （收合時則是前段完全不動）。表單為靜態內容，實測約 310px，
       故以 360px 為上限，僅在矮螢幕才退回視窗算式。
       若日後表單增減欄位，請一併重新校正這個值。 */
    .filter-card:not(.is-collapsed) .filter-card-body {
        max-height: min(360px, calc(100dvh - 220px - var(--safe-top)));
        overflow-y: auto;
    }

    .filter-card:not(.is-collapsed) .filter-card-footer {
        /* 同上，需貼近實際高度：查詢鈕（約 44px）＋上下內距，驗證訊息顯示時再多一行 */
        max-height: 108px;
        overflow: hidden;
    }

    /* 品牌 logo 行動版縮小，省垂直空間（padding 見上方 .filter-brand-header 固定列規則） */
    .filter-brand-logo {
        max-height: 40px;
    }

    /* 結果區行動版可用較高比例（Phase 3 會改由 bottom sheet 承載） */
    .filter-results.is-visible {
        max-height: 50vh;
    }

    /* ----------------------------------------------------------
       Phase 3：左側詳情面板 → 底部 Bottom Sheet
       由 bottomSheet.js 的 attachBottomSheet 收編 #left-sidebar，
       這裡只負責把它從「滿高左側欄」改成「貼底面板」外觀。
       transform 由 JS 以 inline style 驅動（translateY），故不在此設定。
       ---------------------------------------------------------- */
    .sidebar.left {
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: auto !important; /* 蓋過 JS 設定的 inline 430px */
        height: var(--sheet-full);
        max-height: var(--sheet-full);
        /* 必須高於 sheet 遮罩(1599)，否則 full 段遮罩會蓋住面板導致無法操作。
           與 .bottom-sheet 的 z-index:1600 一致。 */
        z-index: 1600;
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -6px 24px rgba(15, 23, 42, 0.18);
        /* 預設藏於畫面下方，open() 後由 JS translateY 帶上來 */
        transform: translateY(100%);
        /* 拖曳跟手：預設無過場，僅 snap/open/close 時（.is-animating）才動畫。
           .is-animating 由 attachBottomSheet 控制。比 .sidebar.left 高一層特異度，
           蓋過 sidebar.css 既有的 transition。 */
        transition: none;
    }

    .sidebar.left.is-animating {
        transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
    }

    /* 行動版以 handle + 遮罩操作，隱藏原「返回查詢」凸出鈕 */
    .sidebar.left .left-toggle-btn {
        display: none !important;
    }

    /* 收編後的把手（由 left-sidebar.js 插入 sidebar 頂端） */
    .sidebar.left .sidebar-sheet-handle {
        flex: 0 0 auto;
    }

    /* 標題／地點／難度／環景鈕移到封面照之前（比照 Google Maps）。
       peek/half 段只露出一小截時，使用者該先看到「這是哪條海岸線」，
       而不是一張還讀不出資訊的照片。
       用 flex order 調整視覺順序，不動 DOM，桌面版維持照片在上。
       注意：改為 flex 後子元素上下 margin 不再合併，間距會略有差異。 */
    .sidebar.left .sidebar-header-inner {
        display: flex;
        flex-direction: column;
    }

    .sidebar.left .header-cover-img {
        order: 1;
        /* 移到最後後，原本的 margin-bottom 會在照片與分頁列之間留空隙，改放上方 */
        margin: 0.5rem 0 0;
    }

    /* 標題區塊（封面圖＋名稱＋位置）也納入拖曳區。
       觸控時內容區是 pan-y，把手又只有約 19px，可抓範圍太小。
       這裡不改 handleEl（把手仍保有 slider 語意與鍵盤操作），
       而是用 touch-action:none 讓手勢不被瀏覽器接手，
       bottomSheet.js 既有的「捲動區在頂端時可從內容拖曳」路徑就會生效。 */
    .sidebar.left .sidebar-header {
        touch-action: none;
    }

    /* full 段例外：此時在標題上滑動多半是想捲內容，交還給瀏覽器；
       收合改用把手或往下拖內容。否則會變成「往上滑沒有任何反應」的死區。 */
    .sheet-at-full .sidebar.left .sidebar-header {
        touch-action: pan-y;
    }

    /* 詳情面板的捲動區：捲到頂／底時不把手勢外傳，
       否則在卡片內下拉會一路傳到文件層，觸發瀏覽器下拉重新整理。
       touch-action 明確標為 pan-y，與 .bottom-sheet-content 一致。 */
    .sidebar.left .sidebar-scroll-area {
        overscroll-behavior: contain;
        touch-action: pan-y;
    }

    /* 內容捲動交給既有 .sidebar-scroll-area；底部留安全區 */
    .sidebar.left .sidebar-footer {
        padding-bottom: calc(1rem + var(--safe-bottom));
    }

    /* ----------------------------------------------------------
       Phase 4：地圖圖例 → 右下 FAB；縮放鈕隱藏（改用雙指縮放）
       FAB 底部位置由 --map-fab-bottom 驅動，sheet 開啟時會抬高。
       ---------------------------------------------------------- */
    .map-legend {
        right: 16px;
        bottom: var(--map-fab-bottom, calc(20px + var(--safe-bottom)));
        min-width: 0;
        background: transparent;
        box-shadow: none;
        overflow: visible;
        flex-direction: column;
        align-items: flex-end;
        gap: 10px;
        transition:
            bottom 0.28s cubic-bezier(0.22, 1, 0.36, 1),
            opacity 0.2s ease;
    }

    /* full 段：FAB 已無意義且會被推到頂端，直接隱藏 */
    .sheet-at-full .map-legend {
        opacity: 0;
        pointer-events: none;
    }

    /* 縮放鈕：行動版改用雙指縮放，隱藏 */
    .map-zoom-controls {
        display: none;
    }

    /* FAB 圓鈕 */
    .map-legend-fab {
        order: 2;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 48px;
        height: 48px;
        border-radius: 50%;
        background: #fff;
        color: #014f5a;
        font-size: 1.45rem;
        box-shadow: 0 4px 16px rgba(15, 23, 42, 0.22);
        cursor: pointer;
    }

    .map-legend.is-open .map-legend-fab {
        background: #014f5a;
        color: #fff;
    }

    /* 圖例面板：收合時隱藏，展開才浮出（白底圓角卡片） */
    .map-legend-content {
        order: 1;
        min-width: 180px;
        background: #fff;
        border-radius: 12px;
        box-shadow: 0 4px 16px rgba(15, 23, 42, 0.18);
    }

    .map-legend:not(.is-open) .map-legend-content {
        display: none;
    }

    /* ----------------------------------------------------------
       Phase 5：收尾打磨
       ---------------------------------------------------------- */

    /* 品牌列右側預留空間，避免 logo 與 site-nav 選單鈕（右上）重疊。
       查詢藥丸已下移到選單鈕下方，不再需要這段預留。 */
    .filter-brand-header {
        padding-right: 60px;
    }

    /* site-nav 抽屜改用動態視窗高度（iOS Safari 網址列） */
    .site-nav-drawer {
        height: 100dvh;
    }

    /* 主功能選單鈕：行動版收成純漢堡圖示鈕，省下頂部橫向空間。
       無障礙：按鈕本身有 aria-label（「開啟主功能」／「關閉主功能」，
       由 siteNav.js 隨開合更新），文字隱藏後仍有可及名稱；
       圖示為 aria-hidden，不會重複播報。尺寸維持 44×44 觸控目標。 */
    .site-nav-menu-trigger-text {
        display: none;
    }

    .site-nav-menu-trigger {
        gap: 0;
        width: var(--nav-trigger-size);
        min-width: var(--nav-trigger-size);
        height: var(--nav-trigger-size);
        min-height: var(--nav-trigger-size);
        padding: 0;
        /* 疊在頂部白色卡片上，陰影多餘 */
        box-shadow: none;
        /* 垂直置中於頂部品牌列（.filter-brand-header），
           該列高度 = 上下 padding + logo 高，見下方 --brand-bar-height。
           水平則對齊品牌列的 14px 內距。 */
        top: calc(var(--safe-top) + (var(--brand-bar-height) - var(--nav-trigger-size)) / 2);
        right: 14px;
    }

    .site-nav-menu-trigger .bi {
        font-size: 1.35rem;
    }

    /* 鍵盤聚焦時要看得見（圖示鈕沒有文字可輔助辨識） */
    .site-nav-menu-trigger:focus-visible {
        outline: 3px solid #014f5a;
        outline-offset: 2px;
    }

    /* 彈窗：外層固定不捲動，只讓 body 捲，確保標題列與底部按鈕永遠看得見。
       原本外層是 max-height:90dvh + overflow-y:auto，而 body 各自帶 vh 上限
       （.filter-alert-body 70vh、.cal-popup-body 60vh）。行動瀏覽器網址列展開時
       vh 指「大視窗」而 dvh 指「目前可見視窗」，vh > dvh，於是
       header + body + footer 會超出外層上限，外層自己捲了起來——
       表現就是：body 捲到底仍看不到底部按鈕，再往下拉按鈕才出現，但標題已被捲走。 */
    .cal-day-popup,
    .filter-alert-popup {
        max-height: 90dvh;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .cal-day-popup .cal-popup-header,
    .cal-day-popup .cal-popup-footer,
    .filter-alert-popup .filter-alert-header,
    .filter-alert-popup .filter-alert-footer {
        flex: 0 0 auto;
    }

    /* 高度改由 flex 分配，移除 vh 上限（那正是溢出的來源）。
       選擇器需含彈窗類別，才蓋得過 .filter-alert-popup--form .filter-alert-body。 */
    .cal-day-popup .cal-popup-body,
    .filter-alert-popup .filter-alert-body {
        flex: 1 1 auto;
        min-height: 0;
        max-height: none;
        overflow-y: auto;
        overscroll-behavior: contain;
    }

    /* 行動版照片檢視改為全螢幕，讓照片吃滿整個畫面 */
    .panorama-modal {
        inset: 0;
        border-radius: 0;
    }

    .panorama-modal-body {
        padding: 0;
    }

    .panorama-drag-container {
        border-radius: 0;
    }

    .panorama-full-img {
        border-radius: 0;
    }

    /* 窄螢幕標題列空間有限：縮放比例文字收起，只留圖示 */
    .photo-zoom-btn [data-zoom-label],
    .photo-zoom-btn [data-header-zoom-label] {
        display: none;
    }

    /* 關閉鈕觸控目標 ≥44px */
    .cal-popup-close-x,
    .panorama-close-btn,
    .filter-alert-close-x {
        min-width: 44px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
}

@media (prefers-reduced-motion: reduce) {
    .filter-card,
    .filter-card:not(.is-collapsed),
    .filter-card-header .filter-card-toggle,
    .filter-card.has-collapse-anim .filter-card-body,
    .filter-card.has-collapse-anim .filter-card-footer,
    .filter-card.has-collapse-anim .filter-results,
    .sidebar.left.is-animating,
    .map-legend {
        transition-duration: 0.01ms;
    }

    /* 延遲一併歸零：visibility 的延遲隱藏、卡片圓角的延後 */
    .filter-card,
    .filter-card.has-collapse-anim.is-collapsed .filter-card-body,
    .filter-card.has-collapse-anim.is-collapsed .filter-card-footer,
    .filter-card.has-collapse-anim.is-collapsed .filter-results {
        transition-delay: 0s;
    }
}

@media (max-width: 480px) {
    .filter-card-header {
        padding: 0.65rem 1rem;
    }

    .filter-card-body {
        padding: 0.85rem;
    }
}
