/* ===== 路段圖 – 垂直卡片式佈局 ===== */

/* 捲動視窗限縮在 top-group 與 bottom-area 之間 */
#tab2.tab-pane.active {
    position: fixed;
    top: 100px;
    /* top-group 底部約 92px，留 8px 間隔 */
    bottom: 120px;
    /* bottom-area 高度約 116px，留 4px 間隔 */
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow-y: auto;
    overflow-x: hidden;
}

#map-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px 0 24px;
    width: 100%;
    max-width: 600px;
    min-width: 440px;
}

/* ---------- 國道選擇器 ---------- */
.sec-road-selector {
    position: sticky;
    top: 0;
    z-index: 10;
    background: #eef7fc;
    width: 100%;
    text-align: center;
    padding: 8px 0 6px;
    margin-bottom: 8px;
}

.sec-road-select {
    border: none;
    outline: none;
    background: transparent;
    font-size: 20px;
    font-weight: 700;
    color: #333;
    cursor: pointer;
    padding: 4px 8px;
    appearance: auto;
}

.sec-road-select:focus {
    outline: none;
}

/* ---------- 卡片列表容器 ---------- */
.sec-card-list {
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ---------- 節點卡片 ---------- */
.sec-card {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 160px;
    padding: 6px 18px;
    background: #fff;
    border: 2px solid #ddd;
    border-radius: 14px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, .08);
    cursor: pointer;
    position: relative;
    z-index: 0;
    transition: border-color .2s, box-shadow .2s;
}

.sec-card-center {
    align-self: center;
}

.sec-card-left {
    align-self: flex-start;
    margin-left: 8px;
}

.sec-card-right {
    align-self: flex-end;
    margin-right: 8px;
}

.sec-card:hover {
    border-color: #90caf9;
}

.sec-card.active {
    border-color: #1e88e5;
    border-width: 2.5px;
    box-shadow: 0 0 0 4px rgba(30, 136, 229, .15);
}

.sec-card-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.sec-card-name {
    font-size: 15px;
    font-weight: 600;
    color: #333;
    line-height: 1.3;
}

.sec-card-km {
    font-size: 16px;
    color: #333;
    font-weight: 700;
    margin-top: 2px;
}

.sec-card-wx {
    font-size: 22px;
    color: #bbb;
    position: absolute;
    right: 4px;
}

.sec-card-road-icon {
    position: absolute;
    left: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ---------- 連線區域（兩節點之間） ---------- */
.sec-link {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 2px 0;
    min-height: 72px;
}

/* 左右圖示欄 */
.sec-link-icons {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-width: 24px;
    font-size: 15px;
}

/* CCTV 攝影機按鈕 */
.sec-cctv-btn {
    display: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background-color: transparent;
    background-image: url(../image/icons/CCTV_select.png);
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
    transition: opacity .2s;
}

.sec-cctv-btn:hover {
    opacity: .75;
}

#map-container.layer-cctv .sec-cctv-btn.has-data {
    display: block;
}

/* CMS 看板按鈕 */
.sec-cms-btn {
    display: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background-color: transparent;
    background-image: url(../image/icons/cms_select.png);
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
    transition: opacity .2s;
}

.sec-cms-btn:hover {
    opacity: .75;
}

#map-container.layer-cms .sec-cms-btn.has-data {
    display: block;
}

/* 事件類按鈕共用基底（jam / construction / ntf / detour） */
.sec-jam-btn,
.sec-construction-btn,
.sec-ntf-btn,
.sec-detour-btn {
    display: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background-color: transparent;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
    transition: opacity .2s;
}

.sec-jam-btn:hover,
.sec-construction-btn:hover,
.sec-ntf-btn:hover,
.sec-detour-btn:hover {
    opacity: .75;
}

.sec-jam-btn {
    background-image: url(../image/icons/jam_select.png);
}

.sec-construction-btn {
    background-image: url(../image/icons/construction_select.png);
}

.sec-ntf-btn {
    background-image: url(../image/icons/ntf_select.png);
}

.sec-detour-btn {
    background-image: url(../image/icons/detour_select.png);
}

#map-container.layer-jam .sec-jam-btn.has-data {
    display: block;
}

#map-container.layer-construction .sec-construction-btn.has-data {
    display: block;
}

#map-container.layer-ntf .sec-ntf-btn.has-data {
    display: block;
}

#map-container.layer-detour .sec-detour-btn.has-data {
    display: block;
}

/* 路肩開放 / 預告事件 / 服務區 按鈕 */
.sec-shdr-btn,
.sec-prev-btn,
.sec-sa-btn {
    display: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background-color: transparent;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
    transition: opacity .2s;
}

.sec-shdr-btn:hover,
.sec-prev-btn:hover,
.sec-sa-btn:hover {
    opacity: .75;
}

.sec-shdr-btn {
    background-image: url(../image/icons/shoulder_select.png);
}

.sec-prev-btn {
    background-image: url(../image/icons/preview_select.png);
}

.sec-sa-btn {
    background-image: url(../image/icons/service_select.png);
}

#map-container.layer-shdr .sec-shdr-btn.has-data {
    display: block;
}

#map-container.layer-prev .sec-prev-btn.has-data {
    display: block;
}

#map-container.layer-sa .sec-sa-btn.has-data {
    display: block;
}

/* 雙車道容器 */
.sec-link-lanes {
    display: flex;
    gap: 5px;
}

/* ---------- 橫向節點列（同 X 值的多節點） ---------- */
.sec-row-group {
    position: relative;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 70px;
}

.sec-row-group .sec-card {
    align-self: center;
    margin: 0;
    min-width: 75px;
    padding: 4px 8px;
}

.sec-row-group .sec-card-center {
    flex: 0 0 160px;
    width: 160px;
    z-index: 1;
    /* 保持在排版流中並使其在整個容器置中 */
}

/* 將左右節點及橫向連線設定為絕對定位，避免干擾 center 彈性對齊 */
.sec-row-group .sec-card-left,
.sec-row-group .sec-card-right,
.sec-row-group .sec-hlink {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
}

.sec-row-group .sec-card-left {
    right: calc(50% + 80px + 64px);
}

.sec-card-left+.sec-hlink {
    right: calc(50% + 80px);
}

.sec-row-group .sec-card-right {
    left: calc(50% + 80px + 64px);
}

.sec-card-center+.sec-hlink {
    left: calc(50% + 80px);
}

.sec-row-group .sec-card-wx {
    font-size: 18px;
    right: 4px;
}

/* 橫向連線（同 X 節點間） */
.sec-hlink {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    width: 64px;
    padding: 0 2px;
    flex-shrink: 0;
}

.sec-hlink-lanes {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

/* 橫向車道色帶 */
.sec-lane.sec-lane-h {
    flex-direction: row;
    min-height: unset;
    height: 26px;
    min-width: 60px;
    width: auto;
    padding: 0 5px;
}

/* 單一車道色帶 */
.sec-lane {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 40px;
    min-height: 90px;
    border-radius: 5px;
    padding: 6px 0;
    gap: 2px;
}

.sec-lane-arrow {
    font-size: 13px;
    font-weight: bold;
    color: #505050;
    text-shadow: 0 1px 1px rgba(0, 0, 0, .2);
    line-height: 1;
}

.sec-lane-speed {
    font-size: 16px;
    font-weight: bold;
    color: #505050;
    text-shadow: 0 1px 1px rgba(0, 0, 0, .2);
    line-height: 1;
}

/* ---------- RWD ---------- */
@media screen and (max-width: 768px) {
    /* 處理手機版寬度超過邊界問題，允許橫向捲動 */
    #tab2.tab-pane.active {
        overflow-x: auto;
        bottom: 80px;
    }

    #map-container {
        /* 保留最低寬度避免內容擠壓，左右各佔 100(卡) + 40(線) + 60(中心點半寬) = 200px */
        min-width: 400px;
    }

    /* 將中心卡片與基底卡片寬度縮至 120px (原 160px) */
    .sec-card,
    .sec-row-group .sec-card,
    .sec-row-group .sec-card-center {
        width: 100px !important;
        /*flex: 0 0 70px !important;*/
        /*flex-direction: column;  讓內容上下排列 
        justify-content: center;*/
        /*padding: 12px 6px 6px 4px;*/
        height: auto;
    }

    .sec-row-group .sec-card-center {
        flex: 0 0 124px;
    }
    /* 將左右卡片寬度與高度縮至最小 */
    .sec-row-group .sec-card-left,
    .sec-row-group .sec-card-right {
        width: auto !important;
        height: auto !important;
        min-width: 0 !important;
        padding: 4px !important;
    }

    /* 圖片、文字變上中下排列，重設原先的絕對定位 */
    /*.sec-card .sec-card-road-icon,
    .sec-card .sec-card-wx {
        position: relative !important;
        left: auto !important;
        right: auto !important;
        margin: 4px 0;
    }*/

    .sec-row-group .sec-card .sec-card-road-icon {
        position:initial;
    }
    /* 縮短橫向連線距離，因中心寬度變 120px (半寬 60px) 故重新計算定位 */
    .sec-row-group .sec-card-left {
        right: calc(75% + 42px + 40px) !important;
        display: flow
    }

    .sec-card-left + .sec-hlink {
        right: calc(72% + 40px) !important;
        width: 40px !important;
    }

    .sec-row-group .sec-card-right {
        left: calc(75% + 42px + 40px) !important;
        display: flow
    }

    .sec-card-center + .sec-hlink {
        left: calc(72% + 40px) !important;
        width: 40px !important;
    }

    .sec-hlink {
        width: 40px !important;
    }

    .sec-lane.sec-lane-h {
        min-width: 36px;
        padding: 0 2px;
    }

    .sec-row-group .sec-card-wx {
        display: none;
    }

    .sec-row-group {
        min-height: auto;
    }

}