/* =========================================
   1. 全域設定 & 容器
   ========================================= */
*, *::before, *::after {
    box-sizing: border-box;
}

body, html {
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
    font-family: "Microsoft JhengHei", Arial, sans-serif;
    overflow: hidden;
    background-color: #f0f0f0;
}

.container {
    width: 100%;
    height: 100%;
    position: relative;
}

/* =========================================
   2. 地圖系統 (背景層)
   ========================================= */
.map-wrapper {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    background: #fff;
    z-index: 0;
}

#map {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    aspect-ratio: 2018 / 863.57;
}

@media (max-aspect-ratio: 2018/863.57) {
    #map { height: 100vh; width: auto; }
}
@media (min-aspect-ratio: 2018/863.57) {
    #map { width: 100vw; height: auto; }
}

/* =========================================
   3. 左側選單容器 (Sidebar)
   ========================================= */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    width: 280px;
    z-index: 100;
    background-color: #f8f9fa;
    border-right: 1px solid #ddd;
    box-shadow: 2px 0 8px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    overflow: visible !important; 
}

.sidebar .header {
    padding: 15px 20px;
    background: #333;
    color: #fff;
    flex-shrink: 0;
}
.sidebar h2 { 
    margin: 0; 
    font-size: 1.2rem;
    /* 讓標題看起來可以點擊 */
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}
.sidebar h2:hover {
    color: #bbb;
}
.sidebar p { 
    margin: 5px 0 0; 
    font-size: 0.8rem; 
    opacity: 0.8; 
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

#sidebar-content {
    flex-grow: 1;
    overflow: visible;
    padding: 0; 
}

/* =========================================
   4. 飛出式選單系統 (Flyout Menu)
   ========================================= */
.menu-group {
    position: relative; 
    border-bottom: 1px solid #e0e0e0;
    background: #fff;
}

.group-title {
    padding: 15px 20px;
    cursor: default;
    font-weight: bold;
    color: #333;
    transition: background 0.2s, color 0.2s;
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.group-title:hover {
    background-color: #f1f1f1;
}

.menu-group:hover .group-title {
    background-color: #333;
    color: #fff;
    cursor: pointer;
}

.menu-group:hover .group-title::after {
    content: "▶";
    font-size: 12px;
    margin-left: 10px;
}

.flyout-content {
    display: none;
    position: absolute;
    left: 100%; 
    top: 0;
    width: 260px;
    max-height: 100vh;
    overflow-y: auto;
    background: #fff;
    border-left: 1px solid #ddd;
    border-radius: 0 4px 4px 0;
    box-shadow: 4px 0 10px rgba(0,0,0,0.15);
    z-index: 101;
}

@keyframes flyOut {
    from { opacity: 0; transform: translateX(-15px); }
    to { opacity: 1; transform: translateX(0); }
}

.menu-group:hover .flyout-content {
    display: block;
    animation: flyOut 0.2s ease-out forwards;
}

/* =========================================
   5. 特徵選項按鈕 (Radio Buttons)
   ========================================= */
.feature-item {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    border-bottom: 1px solid #f5f5f5;
    background: #fff;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.feature-item:hover { background-color: #f8f9fa; }

.feature-item.active {
    background-color: #e3f2fd;
    border-left: 4px solid #2196f3;
    padding-left: 11px;
}

.feature-item input { margin-right: 12px; cursor: pointer; }
.feature-item span { font-size: 14px; color: #444; }

/* =========================================
   6. SimpleMaps Tooltip (地圖上的小預覽)
   ========================================= */
.tt_name { font-weight: bold; font-size: 16px; margin-bottom: 8px; display: block; color: #000; }

.popup-gallery { 
    max-width: 320px; 
    max-height: 350px; 
    overflow-y: auto; 
    padding-right: 5px;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.popup-img-box { margin-top: 8px; border: 1px solid #eee; padding: 4px; background: #fff; border-radius: 4px; }
.popup-text-content { font-size: 14px; line-height: 1.5; color: #444; background: #f9f9f9; padding: 8px; border-radius: 4px; border: 1px solid #eee; }

/* Tooltip 專用：預覽模式 */
.popup-gallery.preview-mode {
    display: flex; 
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.popup-img-box.small {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    border: none;
    background: transparent;
}

.popup-img-box.small img {
    /* [修改] 寬度設為 100%，以填滿容器寬度 (最寬顯示) */
    width: 100%;
    /* [修改] 高度自動，保持比例 */
    height: auto; 
    /* [修改] 設定最大高度限制 (250px) */
    max-height: 250px;
    /* [修改] 使用 contain 確保圖片在上述限制內完整顯示並置中 */
    object-fit: contain;
    margin: 0 auto;
    display: block;
}

/* =========================================
   7. 彈出視窗 (Modal)
   ========================================= */
.custom-modal-overlay {
    display: none;
    position: fixed; 
    top: 0; left: 0; 
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.6); 
    z-index: 9999; 
    justify-content: center; 
    align-items: center;
    backdrop-filter: blur(2px);
}

.custom-modal-content {
    background: white; 
    width: 90%; 
    height: 90vh; 
    max-width: 1400px; 
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.3);
    display: flex; 
    flex-direction: column;
    overflow: hidden;
    animation: modalFadeIn 0.2s ease-out;
}

@keyframes modalFadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.custom-modal-header {
    padding: 15px 20px;
    border-bottom: 1px solid #eee;
    display: flex; justify-content: space-between; align-items: center;
    background: #f8f9fa;
    flex-shrink: 0;
}
.custom-modal-header h3 { margin: 0; font-size: 18px; color: #333; }
.custom-modal-close {
    font-size: 24px; cursor: pointer; color: #666; line-height: 1;
    transition: color 0.2s;
}
.custom-modal-close:hover { color: #d32f2f; }

.custom-modal-body {
    padding: 20px;
    overflow-y: auto;
    overflow-x: hidden;
    flex-grow: 1; 
    background-color: #fdfdfd;
}

.popup-gallery.full-mode {
    max-width: none;
    max-height: none;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 15px; 
    padding-bottom: 20px;
}

.popup-img-box.large {
    width: 100%; 
    margin-top: 0;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    transition: transform 0.2s;
}

.popup-img-box.large:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}

.popup-img-box.large img {
    width: 100%;
    height: auto;
    object-fit: cover;
    border-radius: 4px;
}