/* =================================================================
 * Style for Station Rally (Refactored & Mobile Optimized)
 * ================================================================= */

:root {
    --map-sea-fixed: #e6f4f9;
    --map-stroke-fixed: #94a3b8;
    --c-level-0: #ffffff;
    --c-progress: #3b82f6;
    --c-complete: #eab308;
    --txt-default: #475569;
    --header-height: 60px;
    /* 共通ヘッダーの高さを想定 */
}

[data-bs-theme="dark"] {
    --map-sea-fixed: #e6f4f9;
    --map-stroke-fixed: #4b5563;
    --c-level-0: #ffffff;
    --txt-default: #475569;
}

/* --- Layout & Utilities --- */
.app-layout-container {
    height: calc(100vh - var(--header-height));
    min-height: 600px;
    overflow: hidden;
}

.map-column-bg {
    background-color: var(--map-sea-fixed) !important;
    transition: background-color 0.5s ease;
    position: relative;
    overflow: hidden;
    height: 100%;
    /* PCのデフォルト高さ */
}

.map-header-overlay {
    z-index: 10;
    background: rgba(var(--bs-body-bg-rgb), 0.85);
    backdrop-filter: blur(8px);
    transition: all 0.3s ease;
}

.sidebar-panel {
    z-index: 20;
    background-color: var(--bs-body-bg);
    display: flex;
    flex-direction: column;
}

/* --- SVG & Map Interaction --- */
.svg-container {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1rem;
    /* 少し内側に寄せる */
}

svg {
    width: 100%;
    height: 100%;
    object-fit: contain;
    /* アスペクト比を維持して収める */
    display: block;
    filter: drop-shadow(4px 6px 12px rgba(0, 0, 0, 0.15));
    /* タッチデバイスでの操作性向上 */
    touch-action: manipulation;
}

svg path,
svg rect {
    fill: var(--c-level-0);
    stroke: var(--map-stroke-fixed);
    stroke-width: 1px;
    vector-effect: non-scaling-stroke;
    cursor: pointer;
    transition: fill 0.3s ease;
}

svg path:hover,
svg rect:hover,
svg g[id^="pref-"]:hover> :is(path, rect) {
    opacity: 0.8;
    stroke: #333;
    stroke-width: 2px !important;
    z-index: 10;
}

.fill-level-complete {
    stroke: #eab308 !important;
    stroke-width: 2px !important;
    z-index: 5;
}

[data-bs-theme="dark"] .fill-level-complete {
    stroke: #fff !important;
}

/* --- Labels --- */
.pref-label {
    fill: var(--txt-default);
    font-weight: 700;
    pointer-events: none;
    text-anchor: middle;
    dominant-baseline: central;
    user-select: none;
    font-family: "Helvetica Neue", Arial, sans-serif;
    transition: fill 0.3s ease;
    paint-order: stroke fill;
    stroke: #ffffff;
    stroke-width: 3px;
    stroke-linecap: round;
    stroke-linejoin: round;
    cursor: pointer;
}

.pref-label.vertical {
    -webkit-writing-mode: vertical-rl;
    -ms-writing-mode: tb-rl;
    writing-mode: vertical-rl;
    text-orientation: upright;
    letter-spacing: 0.1em;
    font-family: "Yu Gothic", "YuGothic", "Hiragino Kaku Gothic ProN", sans-serif;
}

.pref-label.label-white {
    fill: #ffffff !important;
    stroke: rgba(0, 0, 0, 0.5) !important;
    stroke-width: 3px;
}

/* --- Legend & UI Components --- */
.legend-box {
    width: 16px;
    height: 16px;
    display: inline-block;
    border-radius: 3px;
    vertical-align: text-bottom;
}

.map-legend .bg-level-0 {
    background-color: var(--c-level-0) !important;
    border: 1px solid #cbd5e1;
}

.map-legend .bg-level-1 {
    background: linear-gradient(135deg, var(--c-level-0) 20%, var(--c-progress) 100%);
    border: 1px solid #cbd5e1;
}

.map-legend .bg-level-complete {
    background: linear-gradient(135deg, #284c84, #7ab789, #efc34b, #c43e32);
    border: 2px solid #eab308;
}

[data-bs-theme="dark"] .map-legend .bg-level-0 {
    background-color: #ffffff !important;
}

[data-bs-theme="dark"] .map-legend .bg-level-1 {
    background: linear-gradient(to right, #ffffff, #3b82f6);
}

.capture-mode {
    background-color: var(--map-sea-fixed) !important;
    padding: 0 !important;
}

/* --- Accordion Badge --- */
.accordion-badge-pref {
    font-size: 0.7rem;
    min-width: 4.5em;
    text-align: center;
}

/* --- Modal --- */
.station-list-modal-content {
    height: 80vh;
}

[data-bs-theme="dark"] .modal-content,
[data-bs-theme="dark"] .list-group-item {
    background-color: #212529;
    color: #e9ecef;
    border-color: #495057;
}

/* =================================================================
 * Mobile Optimization (Responsive) - FIX for Header Overlap
 * ================================================================= */
@media (max-width: 991.98px) {

    /* --- メインレイアウト --- */
    .app-layout-container {
        height: auto !important;
        min-height: 100dvh;
        display: flex;
        flex-direction: column;
        overflow: visible;
    }

    /* --- 地図カラム (上部) --- */
    .map-column-bg {
        /* 共通ヘッダー(約60px)の分だけ余白を空ける */
        padding-top: 60px !important;

        /* 地図エリアの高さ確保 */
        height: 60vh !important;
        min-height: 400px;
        width: 100%;
        order: 1;
        display: flex;
        flex-direction: column;
        position: relative;
        /* 子要素の基準点 */
    }

    /* --- タイトル＆凡例エリア (見やすく調整) --- */
    .map-header-overlay {
        position: absolute !important;
        /* 地図の上に重ねる */
        top: 70px !important;
        /* ヘッダー(60px) + 余白(10px) */
        left: 10px !important;
        right: 10px !important;
        /* 幅は左右10px空ける */
        width: auto !important;

        /* 白いパネル風にして可読性を確保 */
        background: rgba(255, 255, 255, 0.9) !important;
        backdrop-filter: blur(4px) !important;
        border-radius: 8px;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);

        padding: 0.75rem 1rem !important;
        border-bottom: none !important;
        flex-direction: column;
        align-items: flex-start !important;
        pointer-events: auto;
        z-index: 15;
    }

    .map-header-overlay h1 {
        /* 文字色を濃いグレーに強制して見やすくする */
        color: #333333 !important;
        font-size: 1rem !important;
        margin-bottom: 0.5rem !important;
        line-height: 1.4;
        white-space: normal;
        text-shadow: none !important;
    }

    /* アイコンの色も調整 */
    .map-header-overlay h1 i {
        color: #3b82f6 !important;
        /* プライマリー色 */
    }

    /* 凡例 */
    .map-legend {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: wrap;
        gap: 0.5rem !important;
        padding: 0 !important;
        background: transparent !important;
        box-shadow: none !important;
        margin-bottom: 0;
    }

    /* 凡例の文字色も黒系にする */
    .map-legend .small {
        color: #444 !important;
    }

    /* --- SVG地図エリア --- */
    .svg-container {
        flex-grow: 1;
        padding: 4rem 1rem 1rem 1rem;
        /* パネルと被らないよう上部余白を多めに */
        align-items: center;
    }

    /* --- 情報パネル (下部) --- */
    .sidebar-panel {
        height: auto !important;
        min-height: 45vh;
        order: 2;
        /* 地図に少し被せる */
        margin-top: -1.5rem;
        border-radius: 1.5rem 1.5rem 0 0;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1) !important;
        border-top: 1px solid rgba(255, 255, 255, 0.8);
        padding-bottom: 2rem;
        position: relative;
        z-index: 20;
    }

    [data-bs-theme="dark"] .sidebar-panel {
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }

    /* ダークモード時のヘッダーパネル調整 */
    [data-bs-theme="dark"] .map-header-overlay {
        background: rgba(33, 37, 41, 0.9) !important;
    }

    [data-bs-theme="dark"] .map-header-overlay h1,
    [data-bs-theme="dark"] .map-legend .small {
        color: #e9ecef !important;
    }
}