/* 文京区「あなたの名所ものがたり」地図 - スタイル
   左サイドバー（絞り込み＋全件一覧）＋地図の2ペイン構成は
   https://metatourism.jp/yamaguchi_hs2025/ の構成を踏襲している。 */

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Hiragino Sans", Meiryo, sans-serif;
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100vh;
    height: 100dvh;
    width: 100%;
}

/* --- サイドバー --- */
#sidebar {
    width: 340px;
    flex-shrink: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: white;
    box-shadow: 2px 0 10px rgba(0,0,0,0.08);
    z-index: 500;
}

.controls {
    flex-shrink: 0;
    max-height: 55vh;
    overflow-y: auto;
    padding: 16px 16px 10px;
    border-bottom: 1px solid #eee;
}

#site-title {
    margin: 0 0 14px;
    font-size: 16px;
    font-weight: bold;
    color: #222;
    line-height: 1.35;
}

.filter-section { margin-bottom: 12px; }
.filter-section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 0 0 6px;
    font-size: 13px;
    font-weight: bold;
    color: #444;
    cursor: pointer;
    user-select: none;
}
.section-arrow {
    font-size: 11px;
    color: #999;
    transition: transform 0.2s;
}
.filter-section.collapsed .section-arrow { transform: rotate(-90deg); }
.filter-section.collapsed .filter-actions,
.filter-section.collapsed .filter-chip-list { display: none; }

.filter-actions { display: flex; gap: 10px; margin-bottom: 6px; }
.filter-all-btn {
    background: none;
    border: none;
    color: #1a73e8;
    font-size: 12px;
    cursor: pointer;
    padding: 0;
}
.filter-all-btn:hover { text-decoration: underline; }

.filter-chip-list {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}
.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    padding: 4px 9px;
    border-radius: 12px;
    border: 1px solid #ddd;
    background: #f7f7f7;
    color: #555;
    cursor: pointer;
    user-select: none;
    white-space: normal;
    max-width: 100%;
    box-sizing: border-box;
    word-break: break-word;
}
.filter-chip input { display: none; }
.filter-chip.active {
    background: #333;
    border-color: #333;
    color: white;
}
.filter-chip .chip-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.result-count {
    margin: 10px 0 0;
    padding-top: 8px;
    border-top: 1px dashed #e0e0e0;
    font-size: 12px;
    color: #666;
}
.result-count #count { font-weight: bold; color: #222; }

/* --- 全件一覧（データリスト） --- */
#data-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 6px 10px 20px;
}

.list-item {
    padding: 10px;
    margin-bottom: 4px;
    border-radius: 6px;
    cursor: pointer;
    border: 1px solid transparent;
}
.list-item:hover { background: #f5f7fa; }
.list-item.active {
    background: #eef3ff;
    border-color: #bcd2ff;
}
.list-item h3 {
    margin: 0 0 5px;
    font-size: 14px;
    color: #222;
    line-height: 1.35;
}
.list-item .badges {
    display: flex;
    gap: 5px;
    margin-bottom: 5px;
    flex-wrap: wrap;
}
.list-item .badge {
    font-size: 10px;
    font-weight: bold;
    padding: 2px 8px;
    border-radius: 10px;
    color: white;
    white-space: nowrap;
}
.list-item .badge-year { background: #666; }
.list-item p.snippet {
    margin: 0;
    font-size: 12px;
    color: #666;
    line-height: 1.5;
}
.list-item-empty {
    padding: 20px 10px;
    text-align: center;
    color: #999;
    font-size: 13px;
}

/* --- 地図 --- */
#map { flex: 1; min-width: 0; height: 100%; }

/* Leafletコントロール */
.leaflet-control-layers {
    border: none !important;
    box-shadow: 0 1px 5px rgba(0,0,0,0.4) !important;
    border-radius: 6px !important;
}
.leaflet-control-attribution { font-size: 10px; }

/* ピンアイコン */
.custom-pin { background: transparent; border: none; position: relative; }
.pin-svg { filter: drop-shadow(0px 2px 3px rgba(0,0,0,0.35)); }

/* クラスターピン */
.cluster-pin-icon-wrap { background: transparent; border: none; }
.cluster-pin-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.cluster-pin-outer, .cluster-pin-inner {
    position: absolute;
    left: 50%;
    bottom: 0;
    transform: translateX(-50%);
}
/* 外側のハロー（装飾用）は、近接する別のピンのクリックを奪わないようにする */
.cluster-pin-outer { pointer-events: none; }
.cluster-pin-count-wrap {
    position: absolute;
    top: 28%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
}
.cluster-pin-count {
    color: white;
    font-weight: bold;
    font-size: 13px;
    text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}
.cluster-pin-container.cluster-medium .cluster-pin-count { font-size: 14px; }
.cluster-pin-container.cluster-large .cluster-pin-count { font-size: 15px; }

/* ポップアップ */
.leaflet-popup { max-height: 75vh; }
.leaflet-popup-content-wrapper { max-height: 75vh; overflow: hidden; }
.popup-content {
    font-size: 14px;
    line-height: 1.55;
    max-height: calc(75vh - 60px);
    overflow-y: auto;
}
/* PCでの横幅（従来の340pxの160%） */
.leaflet-popup-content { width: 544px !important; }

.popup-tag-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
    flex-wrap: wrap;
}
.popup-tag {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: bold;
    color: white;
}
.popup-tag-year {
    background: #666;
}

.popup-title { margin: 0 0 6px; font-size: 16px; font-weight: bold; color: #222; }
.popup-meta { margin: 0 0 8px; font-size: 13px; color: #555; }

.popup-gallery {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    margin: 8px 0;
    padding-bottom: 2px;
}
.popup-image {
    flex: 0 0 auto;
    width: auto;
    height: 180px;
    max-width: none;
    display: block;
    margin: 0;
    border-radius: 4px;
    border: 1px solid #ddd;
    cursor: pointer;
    object-fit: contain;
    scroll-snap-align: start;
    background: #f5f5f5;
}
.popup-image:hover { opacity: 0.9; }

.popup-desc { margin: 8px 0; font-size: 13px; color: #333; white-space: pre-wrap; }

.popup-audio { width: 100%; max-width: 300px; margin: 8px 0; display: block; }

.popup-story + .popup-story {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px dashed #ccc;
}

.popup-group-label {
    font-size: 11px;
    color: #888;
    margin: 0 0 8px;
}

/* 画像拡大モーダル */
.modal {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.8);
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
    transition: opacity 0.2s;
}
.modal.hidden { visibility: hidden; opacity: 0; pointer-events: none; }
.image-modal-content {
    background: transparent;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    max-width: 90vw;
    max-height: 90vh;
}
.image-modal-content img {
    max-width: 90vw;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 4px;
    box-shadow: 0 0 30px rgba(0,0,0,0.5);
}
.image-modal-content .close-btn {
    position: absolute;
    top: -36px;
    right: 0;
    color: white;
    font-size: 28px;
    background: rgba(0,0,0,0.5);
    border-radius: 50%;
    width: 30px;
    height: 30px;
    line-height: 30px;
    text-align: center;
    cursor: pointer;
}

/* レスポンシブ：モバイルは地図を上段、サイドバーを下段に */
@media (max-width: 768px) {
    .app-container { flex-direction: column-reverse; }
    #sidebar {
        width: 100%;
        flex: 1;
        min-height: 0;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.08);
    }
    #map {
        flex: 0 0 42vh;
        height: 42vh;
        width: 100%;
    }
    .controls { max-height: 30vh; }
    #site-title { font-size: 14px; }
    .leaflet-popup-content { width: 90vw !important; }
    .popup-image { height: 140px; }

    /* 地図の表示域(42vh)より高いポップアップはautoPanが破綻して
       開いた直後に閉じてしまうため、地図の高さに収まるよう抑える */
    .leaflet-popup { max-height: 34vh; }
    .leaflet-popup-content-wrapper { max-height: 34vh; }
    .popup-content { max-height: calc(34vh - 50px); }
}
