:root {
    --primary-color: #2E86AB;
    --accent-color: #E63946;
    --bg-color: #F4F7F6;
    --card-bg: #FFFFFF;
    --text-main: #333333;
    --text-sub: #666666;
    --border-color: #EEEEEE;
    --radius-md: 8px;
    --radius-lg: 12px;
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-float: 0 8px 16px rgba(0,0,0,0.15);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: var(--bg-color);
    color: var(--text-main);
}

/* Header */
header {
    background: var(--primary-color);
    color: #fff;
    padding: 12px 24px;
    height: auto;
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-md);
    z-index: 1100;
    flex-wrap: wrap;
    gap: 15px;
}

.header-title {
    display: flex;
    align-items: baseline;
    gap: 12px;
}

header h1 {
    font-size: 1.3rem;
    font-weight: 700;
    white-space: nowrap;
    letter-spacing: 0.02em;
}

.subtitle {
    font-size: 0.9rem;
    opacity: 0.85;
    white-space: nowrap;
    font-weight: 400;
}

.header-info {
    font-size: 0.8rem;
    text-align: right;
    display: flex;
    flex-direction: column;
    justify-content: center;
    opacity: 0.9;
}

.header-info p {
    margin-bottom: 2px;
}

/* Mobile Header */
@media (max-width: 768px) {
    header {
        flex-direction: column;
        align-items: flex-start;
        padding: 12px 16px;
        gap: 10px;
    }
    .header-info {
        text-align: left;
        width: 100%;
        border-top: 1px solid rgba(255,255,255,0.15);
        padding-top: 8px;
    }
    .search-container {
        top: 100px !important;
        left: 10px !important;
        right: 10px !important;
        width: auto !important;
        flex-wrap: wrap;
        padding: 10px !important;
    }
    .search-container input {
        width: 100% !important; /* Mobile: full width */
    }
}

#map {
    width: 100%;
    flex: 1;
    z-index: 1;
}

/* Floating Search Container */
.search-container {
    position: absolute;
    top: 72px; /* 少し上に詰める */
    left: 50px; /* ズームボタン(約34px + マージン)を避けるために右へ */
    z-index: 1000;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(8px);
    padding: 8px 12px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-float);
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1px solid rgba(0,0,0,0.05);
    transition: box-shadow 0.3s ease;
}

.search-container:hover {
    box-shadow: 0 10px 20px rgba(0,0,0,0.18);
}

.search-container input {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: var(--radius-md);
    width: 240px;
    font-size: 14px;
    background: #f9f9f9;
    transition: all 0.2s;
    outline: none;
}

.search-container input:focus {
    background: #fff;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(46, 134, 171, 0.15);
}

.search-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 0 16px;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    height: 36px;
    transition: background 0.2s, transform 0.1s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.search-btn:hover {
    background: #236a8a;
    transform: translateY(-1px);
}

.search-btn:active {
    transform: translateY(1px);
}

.search-divider {
    width: 1px;
    height: 24px;
    background: #e0e0e0;
    margin: 0 4px;
}

/* Map Toggles (Checkbox Chips) */
.map-toggles {
    display: flex;
    align-items: center;
    gap: 8px;
}

.toggle-item {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-main);
    background: transparent;
    padding: 6px 10px;
    border-radius: 20px;
    transition: background 0.2s;
    user-select: none;
}

.toggle-item:hover {
    background: rgba(0,0,0,0.03);
}

.toggle-item input[type="checkbox"] {
    accent-color: var(--primary-color);
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.line-swatch {
    display: inline-block;
    width: 24px;
    height: 4px;
    background-color: var(--primary-color);
    border-radius: 2px;
}

.station-swatch {
    display: inline-block;
    width: 10px;
    height: 10px;
    background-color: var(--accent-color);
    border-radius: 50%;
    border: 1px solid white;
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

/* Suggestion List */
.suggestions-container {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    width: 100%;
    background: white;
    border-radius: var(--radius-md);
    max-height: 320px;
    overflow-y: auto;
    box-shadow: var(--shadow-float);
    display: none;
    border: 1px solid rgba(0,0,0,0.05);
    z-index: 1001;
}

.suggestion-item {
    padding: 10px 14px;
    cursor: pointer;
    font-size: 14px;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.15s;
}

.suggestion-item:last-child {
    border-bottom: none;
}

.suggestion-item:hover {
    background-color: #f0f7fa; /* Thin blue tint */
}

.suggestion-type {
    font-size: 10px;
    color: #666;
    background: #eee;
    padding: 3px 8px;
    border-radius: 12px;
    font-weight: 600;
    text-transform: uppercase;
}

/* Loading Overlay */
.loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(4px);
    padding: 40px 60px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-float);
    z-index: 2000;
    text-align: center;
    border: 1px solid #eee;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #e0e0e0;
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 15px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Leaflet Popup Customization (Modern Card) */
.leaflet-popup {
    margin-bottom: 0 !important;
}

.leaflet-popup-tip-container {
    display: none;
}

.leaflet-popup-content-wrapper {
    padding: 0;
    overflow: hidden;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-float);
    background: var(--card-bg);
    border: 1px solid rgba(0,0,0,0.05);
}

.leaflet-popup-content {
    margin: 0 !important;
    min-width: 280px;
    line-height: 1.5;
    color: var(--text-main);
}

/* Close Button */
.leaflet-popup-close-button {
    color: rgba(255,255,255,0.8) !important;
    font: 24px/36px sans-serif !important;
    padding: 0 !important;
    top: 0 !important;
    right: 0 !important;
    width: 36px !important;
    height: 36px !important;
    text-align: center !important;
    text-decoration: none !important;
    transition: all 0.2s;
    z-index: 10;
}

.leaflet-popup-close-button:hover {
    background-color: rgba(255,255,255,0.2) !important;
    color: white !important;
}

/* Popup Header */
.popup-header {
    background: var(--primary-color);
    color: white;
    padding: 12px 40px 12px 16px;
    cursor: move;
    position: relative;
    /* 微妙なグラデーションで立体感 */
    background: linear-gradient(135deg, var(--primary-color), #236a8a);
}

.popup-header h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    color: white !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: 0.03em;
}

/* Popup Body */
.popup-body {
    padding: 16px;
    font-size: 13px;
}

.popup-body p {
    margin: 6px 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.popup-body strong {
    color: var(--text-sub);
    font-weight: 600;
    min-width: 80px; /* ラベル幅を揃える */
}

.popup-body hr {
    border: 0;
    border-top: 1px solid #eee;
    margin: 12px 0;
}

.popup-body a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
    display: inline-block;
    transition: opacity 0.2s;
}

.popup-body a:hover {
    opacity: 0.8;
    text-decoration: underline;
}

/* Leader Line */
.leader-line {
    pointer-events: none;
    fill: none;
    stroke: #000000;
    stroke-width: 2px;
    opacity: 0.6;
    z-index: 600;
    filter: drop-shadow(0 1px 2px rgba(255,255,255,0.8)); /* 視認性向上のための白い影 */
}

/* Advertisement Container */
.ad-container-bottom {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    width: auto;
    max-width: 90%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.ad-placeholder {
    background: #FFFFFF;
    padding: 8px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-float);
    border: 1px solid rgba(0,0,0,0.1);
    text-align: center;
}

.ad-content {
    min-width: 320px;
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
}

@media (max-width: 480px) {
    .ad-content {
        min-width: 280px;
    }
}

/* Bottom Left Info */
.bottom-left-info {
    position: absolute;
    bottom: 5px;
    left: 5px;
    z-index: 1000;
    background: rgba(255, 255, 255, 0.85);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    color: #555;
    pointer-events: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-width: 300px;
    line-height: 1.3;
}

.bottom-left-info a {
    color: var(--primary-color);
    text-decoration: none;
}

.bottom-left-info a:hover {
    text-decoration: underline;
}

/* Help Panel */
.help-panel {
    position: absolute;
    top: 72px; /* Matches search container top */
    right: 20px;
    z-index: 1000;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(8px);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-float);
    width: 260px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid rgba(0,0,0,0.05);
    overflow: hidden;
}

.help-panel.collapsed {
    width: auto;
    height: auto;
    background: var(--primary-color);
    color: white;
    cursor: pointer;
}

.help-header {
    padding: 10px 14px;
    font-size: 14px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    background: rgba(0,0,0,0.02);
    border-bottom: 1px solid rgba(0,0,0,0.05);
}

.help-panel.collapsed .help-header {
    background: transparent;
    border-bottom: none;
    padding: 8px 12px;
}

.help-panel.collapsed .toggle-help-btn {
    display: none;
}

.toggle-help-btn {
    background: none;
    border: none;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    color: var(--text-sub);
    padding: 0;
    line-height: 1;
}

.help-content {
    padding: 12px 14px;
    font-size: 12px;
    color: var(--text-main);
    line-height: 1.6;
    transition: max-height 0.3s ease, opacity 0.3s ease;
    max-height: 200px;
    opacity: 1;
}

.help-panel.collapsed .help-content {
    max-height: 0;
    opacity: 0;
    padding: 0;
}

.help-content ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.help-content li {
    margin-bottom: 6px;
    padding-left: 10px;
    position: relative;
}

.help-content li::before {
    content: "•";
    position: absolute;
    left: 0;
    color: var(--primary-color);
}

.help-content strong {
    color: var(--primary-color);
}
