/* =================================================================
 * JR全線制覇マップ — style.css (Leaflet 版・モバイルファースト)
 * スコープは #app-map-jr で限定
 * ================================================================= */

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

#app-map-jr {
    display: flex;
    flex-direction: column;
    background: var(--bs-body-bg);
    min-height: 100dvh;
}

.jr-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;
}

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

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

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

/* 地方ナビ (横スクロール) */
.jr-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;
}

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

.jr-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;
}

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

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

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

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

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

[data-bs-theme="dark"] .leaflet-tile-pane {
    filter: brightness(1.55) contrast(0.92);
}

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

/* 凡例 */
.jr-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);
}

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

.jr-legend-line { width: 26px; display: inline-block; }

.jr-legend-line.is-none {
    height: 3px;
    background-image: linear-gradient(to right, #94a3b8 60%, transparent 0%);
    background-size: 6px 3px;
    background-repeat: repeat-x;
    opacity: 0.7;
}

.jr-legend-line.is-visited {
    height: 7px;
    border-radius: 3px;
    background: var(--bs-primary);
    box-shadow: 0 0 0 1px rgba(124, 90, 195, 0.4);
}

/* 都道府県ホバーバッジ (地図左下) */
.jr-pref-badge {
    position: absolute;
    left: 10px;
    bottom: 24px;
    z-index: 600;
    background: rgba(var(--bs-body-bg-rgb), 0.92);
    border: 1px solid var(--bs-border-color);
    border-radius: 8px;
    padding: 0.3rem 0.7rem;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--bs-body-color);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
    backdrop-filter: blur(4px);
    pointer-events: none;
}

.jr-pref-badge[hidden] { display: none; }

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

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

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

/* 検索ボックス */
.jr-search-wrap {
    position: relative;
    flex-shrink: 0;
}

.jr-search-wrap .fa-magnifying-glass {
    position: absolute;
    left: 0.7rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--bs-secondary-color);
    font-size: 0.8rem;
    pointer-events: none;
}

#line-search {
    padding-left: 2rem;
    padding-right: 2rem;
}

#line-search-clear {
    position: absolute;
    right: 0.4rem;
    top: 50%;
    transform: translateY(-50%);
    border: 0;
    background: transparent;
    color: var(--bs-secondary-color);
    cursor: pointer;
    padding: 0.25rem 0.4rem;
    line-height: 1;
}

#line-search-clear:hover { color: var(--bs-body-color); }

.jr-list-block {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.jr-list-title {
    font-size: 0.95rem;
    font-weight: 700;
    margin: 0 0 0.6rem;
    color: var(--bs-body-color);
    flex-shrink: 0;
}

.jr-line-stats {
    flex: 1;
    overflow-y: auto;
    min-height: 60px;
    padding-right: 0.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* 地方グループ */
.jr-region-group {
    border: 1px solid var(--bs-border-color);
    border-radius: 8px;
    overflow: hidden;
    flex-shrink: 0;   /* flex 圧縮でグループがつぶれるのを防ぐ */
}

.jr-region-header {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.7rem;
    background: var(--bs-body-tertiary-bg);
    border: 0;
    color: var(--bs-body-color);
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    text-align: left;
}

.jr-region-header:hover { background: var(--bs-secondary-bg); }

.jr-region-caret {
    font-size: 0.7rem;
    transition: transform 0.2s;
    color: var(--bs-secondary-color);
}

.jr-region-group.is-collapsed .jr-region-caret {
    transform: rotate(-90deg);
}

.jr-region-label { flex: 1; }

.jr-region-count {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--bs-secondary-color);
    font-variant-numeric: tabular-nums;
}

.jr-region-body {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    padding: 0.5rem;
}

.jr-region-group.is-collapsed .jr-region-body { display: none; }

/* 路線行 */
.jr-line-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.55rem;
    border: 1px solid var(--bs-border-color);
    border-radius: 8px;
    background: var(--bs-body-bg);
    cursor: pointer;
    transition: background-color 0.15s, border-color 0.15s;
}

.jr-line-row:hover {
    background: var(--bs-primary-bg-subtle);
    border-color: var(--bs-primary);
}

.jr-line-chip {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    flex-shrink: 0;
}

.jr-line-name {
    flex: 1;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--bs-body-color);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.jr-line-progress-wrap {
    flex: 1;
    height: 6px;
    background: var(--bs-secondary-bg);
    border-radius: 3px;
    overflow: hidden;
    min-width: 44px;
    max-width: 80px;
}

.jr-line-progress-bar {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s ease;
}

.jr-line-count {
    font-size: 0.76rem;
    color: var(--bs-secondary-color);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.jr-line-count strong {
    color: var(--bs-primary);
    font-size: 0.86rem;
}

.jr-line-row.is-complete .jr-line-name::after {
    content: ' 👑';
    font-size: 0.85em;
}

/* 全線塗り/解除ボタン */
.jr-line-fill {
    flex-shrink: 0;
    border: 1px solid var(--bs-border-color);
    background: var(--bs-body-bg);
    color: var(--bs-secondary-color);
    border-radius: 6px;
    padding: 0.2rem 0.45rem;
    font-size: 0.72rem;
    line-height: 1;
    cursor: pointer;
    transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}

.jr-line-fill:hover {
    background: var(--bs-primary-bg-subtle);
    border-color: var(--bs-primary);
    color: var(--bs-primary);
}

.jr-line-fill.is-on {
    background: var(--bs-primary);
    border-color: var(--bs-primary);
    color: #fff;
}

.jr-hint {
    margin: 0;
    padding: 0.6rem 0.85rem;
    font-size: 0.8rem;
    flex-shrink: 0;
}

.jr-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex-shrink: 0;
}

/* 都道府県絞り込みセレクト (ナビ右端) */
.jr-pref-select {
    flex-shrink: 0;
    width: auto;
    margin-left: auto;
    border-radius: 999px;
    font-size: 0.85rem;
    padding-top: 0.3rem;
    padding-bottom: 0.3rem;
}

/* ---------- 駅ポップアップ ---------- */
.jr-sta-popup {
    min-width: 180px;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.jr-sta-popup-title {
    font-weight: 700;
    font-size: 0.95rem;
    padding-bottom: 0.3rem;
    border-bottom: 1px solid var(--bs-border-color);
}

.jr-sta-popup-row {
    display: flex;
    align-items: center;
    gap: 0.45rem;
}

.jr-sta-popup-label {
    flex: 1;
    font-size: 0.85rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.jr-sta-popup-row .btn {
    flex-shrink: 0;
    font-size: 0.72rem;
    padding: 0.15rem 0.5rem;
    white-space: nowrap;
}

.jr-sta-popup-container .leaflet-popup-content {
    margin: 12px 16px;
    min-width: 200px;
}

/* ポップアップのテーマ対応 */
.jr-sta-popup-container .leaflet-popup-content-wrapper {
    background: var(--bs-body-bg);
    color: var(--bs-body-color);
    border: 1px solid var(--bs-border-color);
    border-radius: 10px;
}

.jr-sta-popup-container .leaflet-popup-tip {
    background: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
}

.jr-sta-popup-container .leaflet-popup-close-button {
    color: var(--bs-secondary-color);
}

/* ---------- Leaflet tooltip ---------- */
.jr-tooltip {
    background: rgba(33, 37, 41, 0.94);
    color: #fff;
    border: 0;
    border-radius: 6px;
    padding: 4px 9px;
    font-size: 0.82rem;
    font-weight: 600;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

.jr-tooltip::before {
    border-top-color: rgba(33, 37, 41, 0.94) !important;
}

/* Leaflet attribution / controls */
.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; }

/* ---------- ローディング ---------- */
.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) {
    .jr-header { padding: 0.5rem 0.75rem; }
    .jr-region-nav { padding: 0.45rem 0.75rem; }

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

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

    .jr-line-stats {
        max-height: none;
        overflow: visible;
    }

    .jr-list-block { flex: initial; }
}

@media (min-width: 992px) {
    #app-map-jr {
        height: calc(100vh - 60px);
        min-height: 640px;
        max-height: 100dvh;
    }

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

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

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

/* X (旧 Twitter) シェアボタン: ダークモード分離 */
[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;
}
