/* =================================================================
 * 都道府県制覇 旅行記録マップ — style.css (Leaflet 版・モバイルファースト)
 * ================================================================= */

/* ---------- レイアウト ---------- */

.app-pref-main {
    display: flex;
    flex-direction: column;
    background: var(--bs-body-bg);
    min-height: 100dvh;
}

/* ヘッダー */
.pf-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.6rem 1rem;
    border-bottom: 1px solid var(--bs-border-color);
    background: var(--bs-body-bg);
    flex-shrink: 0;
}

.pf-header-title {
    display: flex;
    align-items: center;
    min-width: 0;
    flex: 1;
}

.pf-header-actions {
    flex-shrink: 0;
}

.pf-counter {
    display: inline-flex;
    align-items: baseline;
    gap: 0.15rem;
    white-space: nowrap;
}

.pf-counter strong {
    font-size: 1.15rem;
    color: var(--bs-primary);
    font-weight: 800;
}

/* 地域ナビ */
.pf-region-nav {
    display: flex;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--bs-border-color);
    background: var(--bs-body-tertiary-bg);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    flex-shrink: 0;
}

.pf-region-nav::-webkit-scrollbar {
    height: 4px;
}

.pf-region-nav::-webkit-scrollbar-thumb {
    background: var(--bs-border-color);
    border-radius: 2px;
}

.pf-region-btn {
    flex-shrink: 0;
    padding: 0.35rem 0.9rem;
    border: 1px solid var(--bs-border-color);
    background: var(--bs-body-bg);
    color: var(--bs-body-color);
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.15s, color 0.15s, border-color 0.15s;
    white-space: nowrap;
}

.pf-region-btn:hover {
    background: var(--bs-primary-bg-subtle);
    border-color: var(--bs-primary);
    color: var(--bs-primary);
}

.pf-region-btn.is-active {
    background: var(--bs-primary);
    color: #fff;
    border-color: var(--bs-primary);
}

/* メインコンテンツ */
.pf-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.pf-map-wrap {
    position: relative;
    flex-shrink: 0;
    width: 100%;
    background: #e0f2fe;
}

[data-bs-theme="dark"] .pf-map-wrap {
    background: #1a2433;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}

/* CartoDB dark_all は暗すぎるため、タイルだけ明るく持ち上げる（map-airport と同じ） */
[data-bs-theme="dark"] .leaflet-tile-pane {
    filter: brightness(1.55) contrast(0.92);
}

#map {
    width: 100%;
    height: 100%;
}

/* 凡例 */
.pf-legend {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 600;
    background: rgba(var(--bs-body-bg-rgb), 0.92);
    border: 1px solid var(--bs-border-color);
    border-radius: 8px;
    padding: 0.35rem 0.65rem;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
    font-size: 0.78rem;
    display: flex;
    gap: 0.75rem;
    backdrop-filter: blur(4px);
}

.pf-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    color: var(--bs-body-color);
}

.pf-legend-swatch {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    display: inline-block;
    border: 1px solid #94a3b8;
}

.pf-legend-swatch.is-none {
    background: rgba(255, 255, 255, 0.7);
}

.pf-legend-swatch.is-visited {
    background: var(--bs-primary);
    border-color: var(--bs-primary);
}

[data-bs-theme="dark"] .pf-legend-swatch.is-none {
    background: rgba(71, 85, 105, 0.5);
    border-color: #94a3b8;
}

/* 都道府県ラベル（permanent tooltip） */
.pf-label.leaflet-tooltip {
    background: transparent !important;
    border: 0 !important;
    box-shadow: none !important;
    padding: 0 !important;
    color: #1f2937 !important;
    font-family: "Yu Gothic", "Hiragino Sans", "Noto Sans JP", sans-serif;
    font-weight: 700;
    font-size: 11px;
    text-shadow:
        -1px -1px 0 rgba(255, 255, 255, 0.85),
         1px -1px 0 rgba(255, 255, 255, 0.85),
        -1px  1px 0 rgba(255, 255, 255, 0.85),
         1px  1px 0 rgba(255, 255, 255, 0.85);
    pointer-events: none;
    transition: opacity 0.2s;
}

.pf-label.leaflet-tooltip::before {
    display: none !important;
}

[data-bs-theme="dark"] .pf-label.leaflet-tooltip {
    color: #f1f5f9 !important;
    text-shadow:
        -1px -1px 0 rgba(0, 0, 0, 0.85),
         1px -1px 0 rgba(0, 0, 0, 0.85),
        -1px  1px 0 rgba(0, 0, 0, 0.85),
         1px  1px 0 rgba(0, 0, 0, 0.85);
}

/* サイドバー */
.pf-sidebar {
    background: var(--bs-body-bg);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    flex: 1;
    min-height: 0;
    min-width: 0;
}

.pf-list-block,
.pf-progress-block,
.pf-region-stats {
    min-width: 0;
}

.pf-progress-block {
    padding: 0.6rem 0.85rem;
    background: var(--bs-body-tertiary-bg);
    border-radius: 10px;
}

.pf-progress {
    height: 12px;
    border-radius: 6px;
    background: var(--bs-secondary-bg);
}

/* 地域別ミニ統計 */
.pf-region-stats {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    padding-top: 0.25rem;
    border-top: 1px solid var(--bs-border-color);
    padding-top: 0.75rem;
}

.pf-region-stat-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: 0.82rem;
    margin-bottom: 2px;
}

.pf-region-stat-bar {
    height: 6px;
    border-radius: 3px;
    background: var(--bs-secondary-bg);
}

/* 訪問済み・未訪問リスト */
.pf-list-block {
    padding: 0.6rem 0.85rem;
    background: var(--bs-body-tertiary-bg);
    border-radius: 10px;
}

.pf-list-block.muted {
    opacity: 0.75;
}

.pf-list-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-weight: 600;
    margin-bottom: 0.25rem;
    font-size: 0.9rem;
}

.pf-list-head strong {
    color: var(--bs-primary);
    font-size: 1.1rem;
}

.pf-list-block.muted .pf-list-head strong {
    color: var(--bs-secondary-color);
}

.pf-list-text {
    font-size: 0.78rem;
    line-height: 1.5;
    color: var(--bs-secondary-color);
    /* 日本語の長い列挙が折り返されず横にはみ出すのを防ぐ */
    overflow-wrap: anywhere;
    word-break: normal;
}

.pf-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: auto;
    padding-top: 0.5rem;
}

/* ---------- Leaflet 帰属・コントロール（ダークモード） ---------- */

.leaflet-control-attribution {
    font-size: 0.65rem !important;
    background: rgba(255, 255, 255, 0.75) !important;
}

[data-bs-theme="dark"] .leaflet-control-attribution {
    background: rgba(15, 23, 42, 0.75) !important;
    color: #cbd5e1 !important;
}

[data-bs-theme="dark"] .leaflet-control-attribution a {
    color: #9d83d9 !important;
}

[data-bs-theme="dark"] .leaflet-bar a {
    background-color: #1e293b;
    color: #e2e8f0;
    border-bottom-color: #334155;
}

[data-bs-theme="dark"] .leaflet-bar a:hover {
    background-color: #334155;
}

/* ---------- 使い方モーダル ---------- */

.step-icon {
    width: 36px;
    height: 36px;
    font-weight: 700;
}

/* ---------- ローディング ---------- */

.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.88);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.loading-overlay[hidden] {
    display: none;
}

/* ---------- レスポンシブ ---------- */

/* スマホ：地図とサイドバーを縦並び */
@media (max-width: 991.98px) {
    .pf-header {
        padding: 0.5rem 0.75rem;
    }

    .pf-region-nav {
        padding: 0.45rem 0.75rem;
    }

    .pf-map-wrap {
        height: 55dvh;
        min-height: 340px;
    }

    .pf-sidebar {
        padding: 0.85rem 0.85rem 1.5rem;
        border-top: 1px solid var(--bs-border-color);
    }

    .pf-label.leaflet-tooltip {
        font-size: 10px;
    }
}

/* PC：地図とサイドバーを横並び */
@media (min-width: 992px) {
    .app-pref-main {
        height: calc(100vh - 60px);
        min-height: 640px;
        max-height: 100dvh;
    }

    .pf-content {
        flex-direction: row;
    }

    .pf-map-wrap {
        flex: 7;
        height: auto;
        min-width: 0;
    }

    .pf-sidebar {
        flex: 3;
        max-width: 480px;
        min-width: 300px;
        flex-shrink: 0;
        border-left: 1px solid var(--bs-border-color);
        overflow-y: auto;
    }

    .pf-label.leaflet-tooltip {
        font-size: 12px;
    }
}

/* X (旧 Twitter) シェアボタン: ダークモードで body bg と同化しないよう、純黒+ボーダーで分離 */
[data-bs-theme="dark"] #btn-share-x {
    background-color: #000000;
    border: 1px solid #495057;
    color: #ffffff;
}
[data-bs-theme="dark"] #btn-share-x:hover {
    background-color: #1a1a1a;
    border-color: #6c757d;
    color: #ffffff;
}
