/* === Premium Custom Styles for JR Matsuyama Station Map (Official Edition) === */
:root {
    --primary-blue: #0f4c81; /* Classic Trustworthy Blue */
    --primary-light: #2563eb;
    --navy-blue: #1e293b;
    --emerald-green: #10b981;
    --slate-bg: rgba(255, 255, 255, 0.45);
    --blur-val: 12px;
    --font-family: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

body, html, .leaflet-container {
    font-family: var(--font-family) !important;
}

/* --- Map Title --- */
#map-title {
    position: absolute;
    top: 20px;
    left: 60px; /* Offset to avoid Leaflet zoom controls */
    z-index: 1000;
    background: #ffffff; /* ソリッドな白背景に変更 */
    border: 1px solid rgba(0, 0, 0, 0.15);
    border-radius: 8px;
    padding: 14px 28px;
    font-size: 15pt;
    font-weight: 700;
    color: var(--navy-blue);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.08);
    letter-spacing: 0.5px;
    pointer-events: none;
    border-left: 6px solid var(--primary-blue);
    animation: fadeInDown 0.6s ease;
}

@keyframes fadeInDown {
    0% { opacity: 0; transform: translateY(-10px); }
    100% { opacity: 1; transform: translateY(0); }
}

@media (max-width: 600px) {
    #map-title {
        top: 10px;
        left: 50%;
        transform: translateX(-50%);
        width: auto;
        max-width: 80%;
        text-align: center;
        font-size: 12pt;
        padding: 10px 14px;
        border-radius: 8px;
        border-left: none;
        border-top: 4px solid var(--primary-blue);
        white-space: nowrap;
    }
    .leaflet-top.leaflet-left {
        top: 60px !important;
    }
}

/* --- Modern Layout & Buttons --- */
#filter-buttons {
    position: absolute;
    bottom: 30px;
    left: 15px;
    z-index: 1000;
    max-height: calc(100vh - 60px);
    max-height: calc(100dvh - 60px);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    background: var(--slate-bg);
    backdrop-filter: blur(var(--blur-val)) saturate(150%);
    -webkit-backdrop-filter: blur(var(--blur-val)) saturate(150%);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 10px 35px rgba(0, 0, 0, 0.1);
    font-family: var(--font-family);
    min-width: 200px;
    animation: fadeInUp 0.5s ease;
}

#filter-title {
    font-size: 11pt;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--navy-blue);
    text-align: center;
    letter-spacing: 0.5px;
    border-bottom: 1px solid rgba(0,0,0,0.06);
    padding-bottom: 8px;
}

.modern-btn {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 12px 20px;
    margin-bottom: 12px;
    cursor: pointer;
    font-size: 11pt;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.modern-btn:active {
    transform: scale(0.96);
}

.btn-action {
    background: var(--primary-blue);
    color: white;
    box-shadow: 0 4px 12px rgba(15, 76, 129, 0.25);
}

.btn-action:hover {
    background: #0b3860;
    box-shadow: 0 6px 16px rgba(15, 76, 129, 0.35);
    transform: translateY(-2px);
}

/* Toggle Buttons */
.btn-toggle {
    background: var(--primary-light);
    color: white;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
}

.btn-toggle:hover {
    background: #1d4ed8;
    transform: translateY(-2px);
}

/* Off State for Toggles */
.btn-toggle.off {
    background: #f1f5f9 !important;
    color: #64748b !important;
    box-shadow: none !important;
    border: 1px solid #cbd5e1;
    transform: none;
}
.btn-toggle.off .btn-check {
    display: none;
}

/* Check icon inside toggle buttons */
.btn-check {
    font-weight: 700;
    margin-right: 2px;
}

/* --- iOS Style Label Toggle Switch --- */
#label-toggle-container {
    margin-top: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: rgba(0,0,0,0.02);
    padding: 8px;
    border-radius: 8px;
}

.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #cbd5e1;
    transition: .3s;
    border-radius: 24px;
}
.slider:before {
    position: absolute;
    content: "";
    height: 18px; width: 18px;
    left: 3px; bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
input:checked + .slider {
    background-color: var(--emerald-green);
}
input:checked + .slider:before {
    transform: translateX(20px);
}
#label-toggle-label {
    color: var(--navy-blue);
    font-size: 10pt;
    font-weight: 600;
    cursor: pointer;
}

/* --- Modern Legend --- */
#map-legend {
    position: absolute;
    bottom: 30px;
    right: 15px;
    z-index: 1000;
    max-height: calc(100vh - 60px);
    max-height: calc(100dvh - 60px);
    overflow-y: auto;
    background: var(--slate-bg);
    backdrop-filter: blur(var(--blur-val)) saturate(150%);
    -webkit-backdrop-filter: blur(var(--blur-val)) saturate(150%);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 12px;
    padding: 16px 24px;
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.1);
    font-family: var(--font-family);
    color: var(--navy-blue);
    pointer-events: auto;
    animation: fadeInUp 0.5s ease;
}

.legend-section {
    margin-bottom: 20px;
}
.legend-section:last-child { margin-bottom: 0; }

.legend-title {
    font-size: 10.5pt;
    font-weight: 700;
    color: #475569;
    text-align: left;
    margin-bottom: 12px;
    padding-bottom: 6px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.legend-item {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
    transition: transform 0.2s ease;
}
.legend-item:last-child {
    margin-bottom: 0; /* 凡例一番下の不要な隙間を詰める */
}
.legend-item:hover { transform: translateX(3px); }

.legend-text {
    font-size: 11pt;
    font-weight: 500;
    color: #334155;
}

.color-box {
    width: 20px;
    height: 12px;
    margin-right: 14px;
    min-width: 20px;
    border-radius: 3px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.icon-circle {
    width: 28px;
    height: 28px;
    min-width: 28px;
    border-radius: 50%;
    /* Official Gradients for Roles */
    background: linear-gradient(135deg, #64748b 0%, #334155 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12pt;
    font-weight: 700;
    margin-right: 14px;
    margin-left: 0;
    border: 1.5px solid white;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    line-height: 1;
}

/* --- Mobile Specific Overrides --- */
#mobile-legend-btn { display: none; }
.mobile-scroll-indicator { display: none; } /* PC環境では表示しない（余白を作らない） */

@media (max-width: 650px) {
    #mobile-legend-btn {
        display: flex; align-items: center; justify-content: center;
        position: absolute; top: 75px; right: 10px; z-index: 1000;
        background: var(--slate-bg); backdrop-filter: blur(14px);
        border: 1px solid rgba(0, 0, 0, 0.1); border-radius: 99px;
        padding: 10px 18px; font-size: 11pt; font-weight: 700; color: var(--navy-blue);
        box-shadow: 0 4px 10px rgba(0,0,0,0.15); cursor: pointer; pointer-events: auto;
    }

    #map-legend {
        display: none; top: 125px; right: 10px; bottom: auto;
        padding: 14px 18px; border-radius: 12px; width: 240px;
        max-height: calc(100vh - 360px);
        max-height: calc(100dvh - 360px);
        overflow-y: auto;
    }
    #map-legend.show-mobile { display: block; animation: fadeIn 0.2s ease-out forwards; }

    #filter-buttons {
        bottom: 15px; left: 10px; right: 10px; width: auto; min-width: 0; padding: 12px;
        flex-direction: row; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 6px;
    }
    #filter-title { display: none; }
    #filter-buttons > * { margin-bottom: 0 !important; }
    #dev-step-btn { width: 100%; padding: 12px; }
    #ehime-btn, #matsuyama-btn { flex: 1; padding: 12px; font-size: 11pt; }
    #label-toggle-container { width: 100%; justify-content: center; gap: 10px; margin-top: 6px; }

    /* Custom Mobile Scrollbar for Legend */
    #map-legend::-webkit-scrollbar { width: 6px; }
    #map-legend::-webkit-scrollbar-track { background: rgba(0,0,0,0.06); border-radius: 8px; margin: 4px; }
    #map-legend::-webkit-scrollbar-thumb { background: rgba(37,99,235,0.4); border-radius: 8px; }

    /* Scroll Indicator */
    .mobile-scroll-indicator {
        display: flex; justify-content: center; align-items: center;
        position: sticky; bottom: -14px; left: 0; right: 0;
        margin-left: -18px; margin-right: -18px; padding: 12px 0 20px 0;
        margin-bottom: -32px; /* 無駄な余白を相殺して凡例下部の不細工なスペースを消去 */
        background: linear-gradient(to bottom, rgba(255,255,255,0) 0%, rgba(255,255,255,0.9) 40%, rgba(255,255,255,1) 100%);
        pointer-events: none; transition: opacity 0.3s ease; z-index: 10;
        border-bottom-left-radius: 12px; border-bottom-right-radius: 12px;
    }
    .mobile-scroll-indicator span {
        background: var(--primary-light); color: white;
        font-size: 9pt; font-weight: 700; padding: 6px 14px;
        border-radius: 16px; box-shadow: 0 4px 12px rgba(0,0,0,0.15);
        animation: bounce 2s infinite;
    }
}

/* --- Landscape Mobile (横向きスマホ用レイアウト) --- */
@media (max-width: 950px) and (max-height: 500px) and (orientation: landscape) {
    #mobile-legend-btn {
        display: flex; align-items: center; justify-content: center;
        position: absolute; top: 15px; right: 15px; z-index: 1000;
        background: var(--slate-bg); backdrop-filter: blur(14px);
        border: 1px solid rgba(0, 0, 0, 0.1); border-radius: 99px;
        padding: 8px 16px; font-size: 10.5pt; font-weight: 700; color: var(--navy-blue);
        box-shadow: 0 4px 10px rgba(0,0,0,0.15); cursor: pointer; pointer-events: auto;
    }

    #map-legend {
        display: none; top: 65px; right: 15px; bottom: 70px;
        padding: 12px 14px; border-radius: 12px; width: 220px;
        max-height: none; overflow-y: auto;
    }
    #map-legend.show-mobile { display: block; animation: fadeIn 0.2s ease-out forwards; }

    #filter-buttons {
        bottom: 10px; left: 15px; right: 15px; width: auto; min-width: 0; padding: 6px 12px;
        flex-direction: row; flex-wrap: nowrap; justify-content: space-between; align-items: center; gap: 8px;
    }
    #filter-title { display: none; }
    #filter-buttons > * { margin-bottom: 0 !important; }
    #dev-step-btn { width: auto; flex: 1.5; padding: 8px; font-size: 10pt; white-space: nowrap; }
    #ehime-btn, #matsuyama-btn { flex: 1; padding: 8px; font-size: 10pt; white-space: nowrap; }
    #label-toggle-container { width: auto; justify-content: center; gap: 6px; margin-top: 0; background: none; padding: 0; }
    #label-toggle-label { font-size: 9pt; white-space: nowrap; }
    
    .mobile-scroll-indicator { display: none; }
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-4px); }
    60% { transform: translateY(-2px); }
}

/* --- Flowchart Backdrop (dim overlay behind modal) --- */
#flowchart-backdrop {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    animation: fadeIn 0.25s ease;
}
@keyframes fadeIn {
    0% { opacity: 0; }
    100% { opacity: 1; }
}

/* --- Flowchart / Timeline Overlay --- */
#flowchart-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1001;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(var(--blur-val));
    -webkit-backdrop-filter: blur(var(--blur-val));
    border: 1px solid rgba(0,0,0,0.08);
    border-radius: 16px;
    padding: 0;
    width: 600px;
    max-width: 90%;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 25px 50px rgba(0,0,0,0.2);
}

#flowchart-header {
    position: sticky;
    top: 0;
    z-index: 1002;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 20px 40px;
    border-bottom: 1px solid rgba(0,0,0,0.08);
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
    display: flex;
    justify-content: center;
    align-items: center;
}

#close-flowchart-btn {
    position: absolute;
    right: 20px;
    cursor: pointer;
    background: #f1f5f9;
    color: #475569;
    border: none;
    border-radius: 8px;
    padding: 8px 16px;
    font-size: 10pt;
    font-weight: 700;
    transition: background 0.2s;
}
#close-flowchart-btn:hover { background: #e2e8f0; color: #0f172a; }

#flowchart-header h3 {
    font-size: 16pt;
    font-weight: 700;
    color: var(--navy-blue);
    margin: 0;
    text-align: center;
}

/* Premium Vertical Stepper */
.timeline {
    position: relative;
    padding: 40px 40px 40px 76px;
}
.timeline::before {
    content: ''; position: absolute; top: 0; bottom: 0; left: 50px; width: 3px; background: #cbd5e1;
}

.tl-item { position: relative; margin-bottom: 24px; }
.tl-item::before {
    content: ''; position: absolute; top: 4px; left: -33px; width: 14px; height: 14px;
    border-radius: 50%; background: var(--primary-blue); border: 2px solid white; box-shadow: 0 0 0 3px rgba(15, 76, 129, 0.2);
}

.tl-date { font-size: 12pt; font-weight: 700; color: var(--primary-blue); margin-bottom: 8px; letter-spacing: 0.5px; }

.tl-content {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 16px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.03);
    display: flex; flex-direction: column; gap: 8px;
}

.flow-item {
    cursor: pointer; font-size: 11pt; font-weight: 500; color: #334155; padding: 10px 14px;
    border-radius: 8px; transition: all 0.25s ease; border-left: 4px solid #e2e8f0; background: #f8fafc;
}
.flow-item:hover {
    background: #eff6ff; color: var(--primary-blue); font-weight: 600;
    transform: translateX(4px); border-left-color: var(--primary-light); box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

/* Map Popup - High contrast for readability */
.leaflet-popup-content-wrapper {
    background: rgba(255, 255, 255, 0.92) !important;
    backdrop-filter: blur(16px) saturate(150%) !important;
    -webkit-backdrop-filter: blur(16px) saturate(150%) !important;
    box-shadow: 0 10px 40px rgba(0,0,0,0.14) !important;
    border-radius: 12px !important;
    border: 1px solid rgba(0,0,0,0.08);
    animation: popupEntrance 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.leaflet-popup-tip { background: rgba(255, 255, 255, 0.92) !important; }
.leaflet-popup-content { font-family: var(--font-family) !important; }
.leaflet-popup-close-button {
    font-size: 24px !important; width: 30px !important; height: 30px !important; line-height: 30px !important;
    padding: 0 !important; color: #475569 !important; transition: color 0.2s;
}
.leaflet-popup-close-button:hover { color: #0f172a !important; }

@keyframes popupEntrance {
    0% { opacity: 0; transform: translateY(15px) scale(0.95); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes fadeInUp {
    0% { opacity: 0; transform: translateY(12px); }
    100% { opacity: 1; transform: translateY(0); }
}

/* --- Label Tooltip Visibility --- */
.css_point_GeoJSON_4 {
    background: var(--slate-bg) !important; border: 1px solid rgba(0, 0, 0, 0.08) !important;
    border-radius: 6px !important; padding: 4px 10px !important; box-shadow: 0 4px 12px rgba(0,0,0,0.08) !important;
    font-family: var(--font-family) !important; font-weight: 600; color: var(--navy-blue);
}
.css_point_GeoJSON_4 div { text-shadow: 0 0 4px rgba(255,255,255,1); }

/* --- Attribution / Credit --- */
.leaflet-control-attribution {
    background: rgba(255, 255, 255, 0.8) !important; backdrop-filter: blur(6px);
    font-size: 9px !important; border-radius: 6px 6px 0 0 !important; font-family: var(--font-family) !important;
}

/* Custom Scrollbar */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

