/* =================================================================
 * 道の駅ラリー — style.css (Leaflet 版・モバイルファースト)
 * ================================================================= */

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

/* ヘッダー */
.mn-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;
}

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

.mn-counter {
    display: inline-flex;
    align-items: baseline;
    gap: 0.15rem;
    white-space: nowrap;
}
.mn-counter strong {
    font-size: 1.15rem;
    color: var(--bs-primary);
    font-weight: 800;
}

/* 地域ナビ */
.mn-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;
}
.mn-region-nav::-webkit-scrollbar { height: 4px; }
.mn-region-nav::-webkit-scrollbar-thumb { background: var(--bs-border-color); border-radius: 2px; }

.mn-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;
}
.mn-region-btn:hover {
    background: var(--bs-primary-bg-subtle);
    border-color: var(--bs-primary);
    color: var(--bs-primary);
}
.mn-region-btn.is-active {
    background: var(--bs-primary);
    color: #fff;
    border-color: var(--bs-primary);
}

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

.mn-map-wrap {
    position: relative;
    flex-shrink: 0;
    width: 100%;
    background: #e0f2fe;
}
[data-bs-theme="dark"] .mn-map-wrap {
    background: #1a2433;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}

/* CartoDB dark_all 用ブライトネス補正 */
[data-bs-theme="dark"] .leaflet-tile-pane {
    filter: brightness(1.55) contrast(0.92);
}

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

/* 凡例（グラデーションバー） */
.mn-legend {
    position: absolute;
    bottom: 24px;
    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.4rem 0.6rem;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
    font-size: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
    backdrop-filter: blur(4px);
    pointer-events: none;
}
.mn-legend-row {
    display: flex;
    align-items: center;
    gap: 6px;
}
.mn-legend-grad {
    flex: 1;
    height: 8px;
    border-radius: 4px;
    background: linear-gradient(to right, #ffffff, #0d6efd, #f59e0b);
    border: 1px solid var(--bs-border-color);
    min-width: 80px;
}
.mn-legend-caption {
    color: var(--bs-secondary-color);
    text-align: center;
    margin-top: 1px;
}
[data-bs-theme="dark"] .mn-legend-grad {
    background: linear-gradient(to right, #475569, #3b82f6, #f59e0b);
}

/* 都道府県ラベル */
.mn-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;
    pointer-events: none;
    transition: opacity 0.2s;
    text-align: center;
    line-height: 1.1;
}
.mn-label.leaflet-tooltip::before { display: none !important; }

.mn-label-name {
    display: block;
    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);
}
.mn-label-count {
    display: block;
    font-size: 9px;
    font-weight: 600;
    opacity: 0.85;
    text-shadow:
        -1px -1px 0 rgba(255, 255, 255, 0.75),
         1px -1px 0 rgba(255, 255, 255, 0.75),
        -1px  1px 0 rgba(255, 255, 255, 0.75),
         1px  1px 0 rgba(255, 255, 255, 0.75);
}
[data-bs-theme="dark"] .mn-label.leaflet-tooltip {
    color: #f1f5f9 !important;
}
[data-bs-theme="dark"] .mn-label-name,
[data-bs-theme="dark"] .mn-label-count {
    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);
}

/* サイドバー */
.mn-sidebar {
    background: var(--bs-body-bg);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    flex: 1;
    min-height: 0;
    min-width: 0;
}
.mn-progress-block {
    padding: 0.6rem 0.85rem;
    background: var(--bs-body-tertiary-bg);
    border-radius: 10px;
}
.mn-progress {
    height: 12px;
    border-radius: 6px;
    background: var(--bs-secondary-bg);
}
.mn-instruction {
    margin: 0;
    padding: 0.55rem 0.75rem;
    font-size: 0.78rem;
}

/* 県別ミニ統計 */
.mn-pref-stats {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    /* サイドバー自体に overflow-y:auto があるので、ここではスクロールさせない。
       flex:1 を付けると details の展開時に縮められて中身が潰れるため指定しない。 */
}
.mn-region-stat {
    background: var(--bs-body-tertiary-bg);
    border-radius: 8px;
    flex-shrink: 0;  /* details が flex 子要素として縮められて中身が潰れるのを防ぐ */
}
.mn-region-stat > summary {
    list-style: none;
    cursor: pointer;
    padding: 0.55rem 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: 0.85rem;
    user-select: none;
}
.mn-region-stat > summary::-webkit-details-marker { display: none; }
.mn-region-stat > summary::before {
    content: '\f054'; /* fa-chevron-right */
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    font-size: 0.65rem;
    margin-right: 6px;
    color: var(--bs-secondary-color);
    transition: transform 0.15s;
    display: inline-block;
}
.mn-region-stat[open] > summary::before {
    transform: rotate(90deg);
}
.mn-pref-rows {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 4px;
    padding: 0.25rem 0.55rem 0.55rem;
}
.mn-pref-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    background: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 0.78rem;
    cursor: pointer;
    color: var(--bs-body-color);
    transition: background-color 0.15s, border-color 0.15s;
    text-align: left;
}
.mn-pref-row:hover {
    background: var(--bs-primary-bg-subtle);
    border-color: var(--bs-primary);
}
.mn-pref-row-name {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-right: 4px;
}
.mn-pref-row-num {
    font-variant-numeric: tabular-nums;
    color: var(--bs-secondary-color);
    font-size: 0.72rem;
    white-space: nowrap;
}
.mn-pref-row-sep {
    margin: 0 1px;
    opacity: 0.6;
}

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

.mn-source {
    padding: 0.7rem 0.85rem;
    background: var(--bs-body-tertiary-bg);
    border-radius: 8px;
    line-height: 1.55;
    font-size: 0.75rem;
    color: var(--bs-secondary-color);
}
.mn-source-head {
    color: var(--bs-body-color);
    font-size: 0.82rem;
    margin-bottom: 0.3rem;
}
.mn-source-text {
    margin: 0;
    line-height: 1.5;
}
.mn-source-buttons {
    display: flex;
    gap: 6px;
    margin: 0.3rem 0;
}
.mn-source-buttons .btn {
    font-size: 0.78rem;
    padding: 2px 9px;
}
.mn-source a {
    text-decoration: none;
}
.mn-source a:hover {
    text-decoration: underline;
}

/* マーカー（個別駅） */
.mn-station-marker {
    background: transparent !important;
    border: 0 !important;
    cursor: pointer;
}
.mn-station-marker .mn-station-dot {
    display: block;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.9);
    border: 2px solid #64748b;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
    transition: transform 0.15s, background-color 0.2s, border-color 0.2s;
}
.mn-station-marker.is-visited .mn-station-dot {
    background: var(--bs-primary);
    border-color: #ffffff;
}
.mn-station-marker:hover .mn-station-dot {
    transform: scale(1.4);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}
[data-bs-theme="dark"] .mn-station-marker .mn-station-dot {
    background: rgba(30, 41, 59, 0.9);
    border-color: #cbd5e1;
}
[data-bs-theme="dark"] .mn-station-marker.is-visited .mn-station-dot {
    background: var(--bs-primary);
    border-color: #0f172a;
}

/* マーカーのツールチップ */
.mn-marker-tooltip {
    background: rgba(33, 37, 41, 0.94);
    color: #fff;
    border: 0;
    border-radius: 6px;
    padding: 4px 9px;
    font-size: 0.78rem;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}
.mn-marker-tooltip::before {
    border-top-color: rgba(33, 37, 41, 0.94) !important;
}
.mn-marker-tooltip .mn-mt-pref {
    opacity: 0.7;
    font-size: 0.7rem;
}

/* クラスタ（leaflet.markercluster default を上書き） */
.mn-cluster {
    background: transparent !important;
    border: 0 !important;
}
.mn-cluster > div {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.4);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
    border: 2px solid rgba(255, 255, 255, 0.7);
    line-height: 1;
}
.mn-cluster > div span {
    font-size: 0.95rem;
}
.mn-cluster > div small {
    font-size: 0.65rem;
    opacity: 0.85;
    margin-top: 1px;
}
.mn-cluster-low > div    { background: rgba(100, 116, 139, 0.85); }   /* slate-500 */
.mn-cluster-mid > div    { background: rgba(59, 130, 246, 0.85); }    /* blue-500 */
.mn-cluster-high > div   { background: rgba(13, 110, 253, 0.92); }    /* primary 濃 */
.mn-cluster-full > div   { background: rgba(245, 158, 11, 0.95); }    /* amber-500 達成 */

/* 表示モード切替（choropleth / mixed / markers） */
.mn-map-wrap.mode-mixed .leaflet-interactive[fill] { fill-opacity: 0.35 !important; }
.mn-map-wrap.mode-markers .leaflet-interactive[fill] { fill-opacity: 0.08 !important; }
.mn-map-wrap.mode-markers .mn-label { opacity: 0 !important; }
.mn-map-wrap.mode-mixed .mn-label-count { opacity: 0.4; }

/* オープンデータカード（ページ下部） */
.mn-opendata-card {
    background: var(--bs-body-tertiary-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: 12px;
    padding: 1.25rem 1.5rem;
}
.mn-opendata-card h2 { color: var(--bs-body-color); }
.mn-opendata-format {
    background: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: 8px;
    padding: 0.85rem 1rem;
    height: 100%;
}
.mn-opendata-format code {
    color: var(--bs-secondary-color);
    word-break: break-all;
    font-size: 0.72rem;
}

/* モーダル内駅一覧 */
.mn-station-list {
    max-height: 60vh;
    overflow-y: auto;
}
.mn-station-item {
    cursor: pointer;
    padding: 0.6rem 1rem;
}
.mn-station-item input[type="checkbox"] {
    cursor: pointer;
    flex-shrink: 0;
}

/* 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;
}

/* ローディング */
.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) {
    .mn-header { padding: 0.5rem 0.75rem; }
    .mn-region-nav { padding: 0.45rem 0.75rem; }
    .mn-map-wrap { height: 55dvh; min-height: 340px; }
    .mn-sidebar { padding: 0.85rem 0.85rem 1.5rem; border-top: 1px solid var(--bs-border-color); }
    .mn-pref-stats { overflow: visible; max-height: none; flex: initial; }
    .mn-label-name { font-size: 10px; }
    .mn-label-count { font-size: 8px; }
    .mn-pref-rows { grid-template-columns: repeat(3, 1fr); }
    .mn-station-list { max-height: 55vh; }
}

@media (min-width: 992px) {
    .app-mn-main {
        height: calc(100vh - 60px);
        min-height: 640px;
        max-height: 100dvh;
    }
    .mn-content { flex-direction: row; }
    .mn-map-wrap { flex: 7; height: auto; min-width: 0; }
    .mn-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) シェアボタン: ダークモードで 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;
}
