/* ==========================================================================
   台北捷運工程 CCTV 即時地圖巡檢系統專屬樣式 (map.css - Cyber Dark Theme)
   整合臺灣通用電子地圖 (NLSC)、Leaflet MarkerCluster 與深色彈窗
   ========================================================================== */

/* 全域與版面設定 */
.map-page-body {
    overflow: hidden;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: #0b0f19;
}

.map-app-layout {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
    background: #0b0f19;
}

.map-top-bar {
    flex-shrink: 0;
    z-index: 1000;
    background: #0f172a;
    border-bottom: 1px solid #1e293b;
}

.map-brand h2 {
    font-size: 1.15rem;
    color: #f8fafc;
    margin: 0;
    font-weight: 700;
}

.map-brand span {
    font-size: 0.65rem;
    color: #38bdf8;
    font-family: 'Chakra Petch', sans-serif;
    letter-spacing: 1px;
}

/* 主內容區 (左側清單 + 右側地圖) */
.map-main-container {
    display: flex;
    flex: 1;
    height: calc(100vh - 54px);
    position: relative;
    overflow: hidden;
}

/* 左側邊欄 (深色) */
.map-sidebar-panel {
    width: 360px;
    background: #111827;
    border-right: 1px solid #1e293b;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 500;
    box-shadow: 2px 0 16px rgba(0, 0, 0, 0.5);
}

.map-search-block {
    padding: 14px 16px;
    border-bottom: 1px solid #1e293b;
    background: #0f172a;
}

.btn-search-addr {
    width: 100%;
    margin-top: 8px;
    padding: 8px 12px;
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
}

.map-results-block {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    padding: 12px 16px;
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.results-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: #f8fafc;
}

.results-badge {
    background: #1e293b;
    color: #38bdf8;
    border: 1px solid #334155;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 700;
}

/* 搜尋目標提示卡 */
.target-location-card {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid #ef4444;
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 12px;
    animation: fadeIn 0.3s ease;
}

.target-card-header {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 700;
    color: #fca5a5;
    font-size: 0.9rem;
}

.target-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-close-target {
    background: none;
    border: none;
    color: #fca5a5;
    cursor: pointer;
    font-size: 0.9rem;
    padding: 2px 6px;
    border-radius: 4px;
}

.btn-close-target:hover {
    background: rgba(239, 68, 68, 0.3);
}

.target-sub {
    font-size: 0.75rem;
    color: #fecaca;
    margin-top: 4px;
}

/* 攝影機卡片清單滾動區 */
.map-cam-list-scroll {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-right: 4px;
}

/* 地圖側欄攝影機卡片 */
.map-cam-card {
    background: #0f172a;
    border: 1px solid #1e293b;
    border-radius: 8px;
    padding: 10px 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.map-cam-card:hover {
    border-color: #38bdf8;
    background: #1e293b;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.map-cam-card-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.map-cam-proj-tag {
    font-size: 0.75rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    background: #0284c7;
    color: #ffffff;
}

.map-cam-dist-tag {
    font-size: 0.75rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    background: rgba(16, 185, 129, 0.2);
    color: #34d399;
    border: 1px solid #059669;
}

.map-cam-card-title {
    font-size: 0.88rem;
    font-weight: 700;
    color: #f8fafc;
    line-height: 1.3;
}

.map-cam-card-sub {
    font-size: 0.78rem;
    color: #94a3b8;
    display: flex;
    justify-content: space-between;
}

/* 地圖畫布 */
.map-viewport {
    flex: 1;
    position: relative;
    height: 100%;
}

.leaflet-map-canvas {
    width: 100%;
    height: 100%;
}

/* ==========================================================================
   Leaflet 彈窗與 Marker 自訂樣式
   ========================================================================== */
.leaflet-popup-content-wrapper {
    background: #0f172a !important;
    color: #f8fafc !important;
    border-radius: 10px !important;
    padding: 0 !important;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.7) !important;
    border: 1px solid #334155 !important;
}

.leaflet-popup-content {
    margin: 0 !important;
    line-height: 1.4 !important;
    width: 380px !important;
    max-width: calc(100vw - 40px) !important;
}

.leaflet-popup-tip {
    background: #0f172a !important;
}

/* 自訂彈窗內部結構 */
.popup-video-box {
    display: flex;
    flex-direction: column;
    background: #0f172a;
}

.popup-header {
    padding: 8px 12px;
    background: #1e293b;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.popup-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: #ffffff;
    display: flex;
    align-items: center;
    gap: 6px;
}

.popup-tag {
    font-size: 0.72rem;
    padding: 1px 5px;
    border-radius: 3px;
    background: #0284c7;
    color: #ffffff;
}

.popup-iframe-wrap {
    position: relative;
    width: 100%;
    height: 0;
    padding-bottom: 56.25%; /* 16:9 */
    background: #000000;
}

.popup-iframe-wrap iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
}

.popup-info-row {
    padding: 6px 12px;
    font-size: 0.78rem;
    color: #94a3b8;
    background: #0f172a;
    display: flex;
    justify-content: space-between;
}

/* 彈窗操作按鈕列 */
.popup-actions-bar {
    padding: 8px 12px;
    background: #1e293b;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
}

.btn-popup-action {
    padding: 4px 8px;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 4px;
    border: 1px solid #334155;
    background: #0f172a;
    color: #e2e8f0;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.btn-popup-action:hover {
    background: #0284c7;
    border-color: #38bdf8;
    color: #ffffff;
}

/* 「田 放入監控格位」下拉選單容器 */
.slot-dropdown-wrapper {
    position: relative;
    display: inline-block;
}

.slot-dropdown-menu {
    position: absolute;
    bottom: 100%;
    left: 0;
    margin-bottom: 6px;
    background: #111827;
    border: 1px solid #334155;
    border-radius: 6px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.6);
    padding: 6px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    z-index: 100;
    width: 140px;
}

.btn-slot-item {
    padding: 4px;
    font-size: 0.72rem;
    font-weight: 700;
    text-align: center;
    background: #1e293b;
    color: #f8fafc;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-slot-item:hover {
    background: #0284c7;
}

/* 自訂 Marker 發光圖示 */
.custom-mrt-marker {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #0284c7;
    color: #ffffff;
    font-size: 14px;
    border: 2px solid #ffffff;
    box-shadow: 0 0 10px rgba(2, 132, 199, 0.8), 0 2px 4px rgba(0, 0, 0, 0.5);
    cursor: pointer;
    transition: transform 0.2s ease;
}

.custom-mrt-marker:hover {
    transform: scale(1.2);
    z-index: 9999 !important;
}

.marker-north { background: #0284c7; box-shadow: 0 0 12px rgba(2, 132, 199, 0.9); }
.marker-south { background: #ec4899; box-shadow: 0 0 12px rgba(236, 72, 153, 0.9); }
.marker-wanda { background: #10b981; box-shadow: 0 0 12px rgba(16, 185, 129, 0.9); }
.marker-xinyi { background: #f59e0b; box-shadow: 0 0 12px rgba(245, 158, 11, 0.9); }
.marker-other { background: #8b5cf6; box-shadow: 0 0 12px rgba(139, 92, 246, 0.9); }

/* 目標搜尋落點針 Marker */
.custom-target-marker {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: #ef4444;
    color: #ffffff;
    font-size: 20px;
    border: 3px solid #ffffff;
    box-shadow: 0 0 20px rgba(239, 68, 68, 1);
    animation: targetPulse 1.5s infinite alternate;
}

@keyframes targetPulse {
    0% { transform: scale(1); }
    100% { transform: scale(1.2); }
}

/* 響應式微調 */
@media (max-width: 768px) {
    .map-sidebar-panel {
        width: 100%;
        height: 35vh;
        border-right: none;
        border-top: 1px solid #1e293b;
    }
    .map-main-container {
        flex-direction: column-reverse;
    }
}
