/**
 * CHARTORY - Election Dashboard
 * style.css (Ver 18.0 - MMD & Ranking Filters Enhanced)
 * 中選挙区対応、ランキングフィルター、履歴モーダルなど全機能をカバーする完全版CSS
 */

 :root {
    --header-height: 60px;
    --footer-height: 30px;
    --panel-width: 440px;
    --bg-color: #f4f7f6;
    --panel-bg: #ffffff;
    --text-color: #333;
    --primary-color: #2c3e50;
    --accent-color: #3498db;
    --border-color: #e0e0e0;
    
    /* リッチなステータスカラー */
    --gold-start: #f1c40f;
    --gold-end: #b7950b;
    --silver-start: #bdc3c7;
    --silver-end: #7f8c8d;
    --bronze-start: #d35400;
    --bronze-end: #a04000;
    --lost-bg: #ecf0f1;
    --lost-text: #95a5a6;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    font-family: "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    overflow: hidden;
}

body {
    display: flex;
    flex-direction: column;
}

/* =========================================
   Header
   ========================================= */
.app-header {
    height: var(--header-height);
    background-color: #fff;
    border-bottom: 1px solid #ddd;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    z-index: 1000;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 30px;
}

.logo {
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--primary-color);
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
}

.view-tabs {
    display: flex;
    background: #f0f0f0;
    border-radius: 8px;
    padding: 4px;
}

.view-tab {
    border: none;
    background: transparent;
    padding: 6px 16px;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    color: #666;
    cursor: pointer;
    transition: all 0.2s ease;
}

.view-tab:hover {
    color: #333;
    background: rgba(255,255,255,0.5);
}

.view-tab.active {
    background: #fff;
    color: var(--primary-color);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.controls select {
    padding: 6px 12px;
    font-size: 0.9rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: #fff;
    margin-left: 10px;
    cursor: pointer;
}

/* =========================================
   Main Layout
   ========================================= */
.main-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    display: flex;
    width: 100%;
    height: calc(100% - var(--header-height) - var(--footer-height));
}

/* 小選挙区ビュー固有 */
#view-smd {
    flex-direction: row;
}

#map-container {
    flex: 1;
    background-color: #aaddff; /* Sea color */
    position: relative;
    overflow: hidden;
}

.info-panel {
    width: var(--panel-width);
    background: var(--panel-bg);
    border-left: 1px solid var(--border-color);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    box-shadow: -2px 0 5px rgba(0,0,0,0.03);
    z-index: 10;
}

/* 比例代表ビュー固有 */
#view-prop {
    display: block; /* FlexではなくBlockでスクロールさせる */
    overflow-y: auto;
    background-color: var(--bg-color);
    padding: 20px;
}

.prop-dashboard {
    max-width: 1200px;
    margin: 0 auto;
    padding-bottom: 40px;
}

/* =========================================
   Panel Components (SMD/MMD)
   ========================================= */
.panel-header {
    padding: 20px 20px 15px;
    border-bottom: 1px solid #eee;
    background: #fff;
    position: sticky;
    top: 0;
    z-index: 20;
}

.panel-header h2 {
    margin: 0;
    font-size: 1.5rem;
    color: var(--primary-color);
}

.subtitle {
    font-size: 0.85rem;
    color: #777;
    margin-top: 4px;
    display: block;
}

.panel-content {
    padding: 20px;
}

.back-btn {
    background: transparent;
    border: 1px solid #ccc;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.8rem;
    cursor: pointer;
    color: #555;
    margin-bottom: 10px;
    display: inline-flex;
    align-items: center;
}
.back-btn:hover { background: #f0f0f0; }

.district-nav {
    display: flex;
    gap: 5px;
}
.nav-arrow-btn {
    background: #fff;
    border: 1px solid #ccc;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.8rem;
    cursor: pointer;
    color: #555;
    transition: all 0.2s;
}
.nav-arrow-btn:hover { background: #f5f5f5; color: #333; border-color: #999; }

/* 候補者カード */
.candidate-card {
    position: relative;
    margin-bottom: 12px;
    padding: 15px 12px;
    background: #fff;
    border: 1px solid #eee;
    border-radius: 10px;
    overflow: hidden;
    transition: transform 0.1s;
}
.candidate-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.05);
}

.vote-bar-bg {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    z-index: 0;
    transition: width 0.5s ease-out;
}

.status-badge {
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: bold;
    color: #fff;
    display: inline-block;
    text-shadow: 0 1px 1px rgba(0,0,0,0.2);
}
.badge-gold { background: linear-gradient(135deg, var(--gold-start), var(--gold-end)); }
.badge-silver { background: linear-gradient(135deg, var(--silver-start), var(--silver-end)); }
.badge-lost { background: #95a5a6; color: #fff; }

.party-chip {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 100px;
    font-size: 0.75rem;
    font-weight: bold;
    color: #333;
    border: 1px solid rgba(0,0,0,0.1);
}

.cand-votes-box .vote-num {
    font-family: 'Roboto', sans-serif;
    letter-spacing: -0.5px;
}

.sekihai-rate {
    font-size: 0.75rem;
    color: #e67e22;
    font-weight: bold;
    background: #fff5e6;
    padding: 1px 6px;
    border-radius: 4px;
}

.duplicate-mark {
    display: inline-block;
    background: #333;
    color: #fff;
    font-size: 0.65rem;
    padding: 1px 4px;
    border-radius: 3px;
    margin-left: 5px;
    vertical-align: middle;
}

/* MMD Specific (中選挙区用) */
.mmd-summary-box {
    background: #f9f9f9;
    padding: 12px 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    border-left: 4px solid #555;
    box-shadow: 0 2px 4px rgba(0,0,0,0.03);
}

.mmd-summary-title {
    font-size: 0.85rem;
    font-weight: bold;
    color: #666;
    margin-bottom: 10px;
    border-bottom: 1px solid #eee;
    padding-bottom: 5px;
    display: block;
}

.mmd-party-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.mmd-party-item {
    display: flex;
    align-items: center;
    background: #fff;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 0.85rem;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    border: 1px solid #eee;
}

.mmd-color-box {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    margin-right: 6px;
}

/* =========================================
   Proportional View
   ========================================= */
.prop-national-summary {
    background: #fff;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 30px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.03);
    border: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
}

.summary-header h2 { margin: 0 0 10px 0; font-size: 1.2rem; color: #555; }
.total-seats-display { font-size: 2.5rem; font-weight: 800; color: var(--primary-color); }

.prop-chart-wrapper {
    flex: 1;
    min-width: 300px;
    height: 180px;
    position: relative;
    margin-left: 20px;
}

.prop-blocks-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr)); /* レスポンシブグリッド */
    gap: 20px;
}

.prop-block-section {
    background: #fff;
    border-radius: 8px;
    border: 1px solid #ddd;
    overflow: hidden;
    box-shadow: 0 2px 5px rgba(0,0,0,0.02);
}

.prop-list-container {
    max-height: 500px;
    overflow-y: auto;
}

/* =========================================
   Ranking View (Enhanced)
   ========================================= */
.ranking-dashboard {
    max-width: 1000px;
    margin: 0 auto;
}

.ranking-header {
    text-align: center;
    margin-bottom: 30px;
}

.ranking-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    justify-content: center;
    align-items: center;
    margin-bottom: 30px;
    background: #fff;
    padding: 15px;
    border-radius: 12px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.03);
    border: 1px solid #eee;
}

.ranking-controls select {
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: 20px;
    font-size: 0.9rem;
    background: #fff;
    cursor: pointer;
    color: #555;
    outline: none;
}
.ranking-controls select:hover { border-color: #999; }

.ranking-controls label {
    display: flex; 
    align-items: center; 
    font-size: 0.9rem; 
    color: #555;
    cursor: pointer;
    background: #f9f9f9;
    padding: 6px 12px;
    border-radius: 20px;
    border: 1px solid #ccc;
}
.ranking-controls input[type="checkbox"] {
    margin-right: 8px;
}

.rank-btn {
    background: #fff;
    border: 1px solid #ccc;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    color: #555;
    font-weight: 500;
}

.rank-btn:hover {
    background: #f0f0f0;
    color: #333;
    border-color: #bbb;
}

.rank-btn.active {
    background: var(--primary-color);
    color: #fff;
    border-color: var(--primary-color);
    box-shadow: 0 2px 5px rgba(44, 62, 80, 0.3);
}

/* ランキングカード */
.ranking-card {
    background: #fff;
    border-radius: 8px;
    border: 1px solid #eee;
    padding: 15px 20px;
    display: flex;
    align-items: center;
    gap: 20px;
    transition: transform 0.1s;
    position: relative;
}

.ranking-card:hover {
    transform: translateX(5px);
    border-color: #ddd;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

/* 順位バッジ */
.rank-badge {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 1.1rem;
    color: #fff;
    flex-shrink: 0;
}
.rank-1 { background: linear-gradient(135deg, #f1c40f, #f39c12); box-shadow: 0 2px 5px rgba(241, 196, 15, 0.4); border: 2px solid #fff; }
.rank-2 { background: linear-gradient(135deg, #bdc3c7, #95a5a6); box-shadow: 0 2px 5px rgba(189, 195, 199, 0.4); border: 2px solid #fff; }
.rank-3 { background: linear-gradient(135deg, #d35400, #a04000); box-shadow: 0 2px 5px rgba(211, 84, 0, 0.4); border: 2px solid #fff; }
.rank-other { background: #ecf0f1; color: #7f8c8d; font-size: 0.9rem; font-weight: 600; }

.rank-info { flex: 1; }
.rank-name { font-size: 1.2rem; font-weight: bold; color: #2c3e50; margin-right: 10px; }
.rank-party { font-size: 0.85rem; padding: 2px 8px; border-radius: 10px; border: 1px solid #ccc; background: #f9f9f9; }
.rank-meta { font-size: 0.85rem; color: #777; margin-top: 4px; }

.rank-value {
    text-align: right;
    min-width: 100px;
}
.rank-main-val { font-size: 1.4rem; font-weight: 800; color: #2c3e50; display: block; }
.rank-sub-val { font-size: 0.8rem; color: #999; display: block; }

/* =========================================
   Modal (Candidate History)
   ========================================= */
#history-modal {
    animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

/* =========================================
   Footer
   ========================================= */
.app-footer {
    height: var(--footer-height);
    background: #333;
    color: #aaa;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

/* ランキング画面のスクロールを有効化 */
#view-ranking {
    display: block; /* FlexではなくBlockで表示 */
    overflow-y: auto; /* 縦スクロールを許可 */
    height: 100%; /* 親要素の高さを継承 */
}

/* ランキングリストの余白調整 */
.ranking-list-container {
    padding-bottom: 50px;
}


.map-label.visible {
    opacity: 1;
}

/* =========================================
   Ranking Enhanced
   ========================================= */
/* 順位バッジ（金銀銅＋その他） */
.rank-badge-gold { 
    background: linear-gradient(135deg, #f1c40f, #b7950b); 
    border: 2px solid #fff; 
    box-shadow: 0 2px 5px rgba(241, 196, 15, 0.4);
    color: #fff;
}
.rank-badge-silver { 
    background: linear-gradient(135deg, #bdc3c7, #7f8c8d); 
    border: 2px solid #fff; 
    box-shadow: 0 2px 5px rgba(189, 195, 199, 0.4);
    color: #fff;
}
.rank-badge-bronze { 
    background: linear-gradient(135deg, #d35400, #a04000); 
    border: 2px solid #fff; 
    box-shadow: 0 2px 5px rgba(211, 84, 0, 0.4);
    color: #fff;
}
.rank-badge-normal { 
    background: #ecf0f1; 
    color: #7f8c8d; 
    font-weight: 600;
}

/* フィルターエリア */
.ranking-options {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-top: 10px;
    font-size: 0.9rem;
    color: #555;
    background: #f8f8f8;
    padding: 8px 15px;
    border-radius: 8px;
}



/* =========================================
   Map Styling Updates (修正版)
   ========================================= */
   .district-poly {
    stroke: #999; /* 境界線をグレーに */
    stroke-width: 0.5px;
    vector-effect: non-scaling-stroke; /* ズームしても線を太くしない */
    cursor: pointer;
    transition: fill 0.2s;
    pointer-events: auto;
}
.district-poly:hover {
    stroke: #333;
    stroke-width: 1px;
    opacity: 0.8;
}

.map-label {
    font-family: "Helvetica Neue", Arial, sans-serif;
    fill: #666; /* 控えめな色 */
    font-weight: bold;
    text-shadow: 
        -1px -1px 0 rgba(255,255,255,0.8),  
        1px -1px 0 rgba(255,255,255,0.8),
        -1px 1px 0 rgba(255,255,255,0.8),
        1px 1px 0 rgba(255,255,255,0.8); /* 白縁取り */
        pointer-events: none !important; /* 強制的に無効化 */
        user-select: none;  /* ★重要: ラベルをクリックしても透過させる（下の地図をクリック可能に） */
    text-anchor: middle;
    opacity: 0;
    transition: opacity 0.2s;
}
.map-label.visible {
    opacity: 1;
}

/* 政党バッジ（ランキング用） */
.rank-party-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    color: #fff !important; /* 文字色は白強制 */
    font-size: 0.75rem;
    font-weight: bold;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
    border: 1px solid rgba(0,0,0,0.1);
}

/* =========================================
   Header Layout Adjustment
   ========================================= */
.header-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

/* =========================================
   Hamburger Menu (Added)
   ========================================= */
.hamburger-menu {
    position: relative;
    z-index: 9999;
}

#menu-btn-check {
    display: none;
}

.menu-btn {
    display: flex;
    height: 30px;
    width: 30px;
    justify-content: center;
    align-items: center;
    position: relative;
    cursor: pointer;
    z-index: 10001; /* メニュー背景より上に表示 */
}

/* ハンバーガーアイコンの線 */
.menu-btn span,
.menu-btn span:before,
.menu-btn span:after {
    content: '';
    display: block;
    height: 2px;
    width: 24px;
    border-radius: 2px;
    background-color: var(--primary-color);
    position: absolute;
    transition: all 0.2s;
}

.menu-btn span:before { bottom: 8px; }
.menu-btn span:after { top: 8px; }

/* 開いた時のアイコン変化（×印） */
#menu-btn-check:checked ~ .menu-btn span { background-color: rgba(255, 255, 255, 0); }
#menu-btn-check:checked ~ .menu-btn span::before { bottom: 0; transform: rotate(45deg); background-color: #333; }
#menu-btn-check:checked ~ .menu-btn span::after { top: 0; transform: rotate(-45deg); background-color: #333; }

/* メニュー画面（全画面オーバーレイ） */
.menu-content {
    width: 100%;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 100%; /* 初期状態は画面外 */
    z-index: 10000;
    background-color: rgba(255, 255, 255, 0.95);
    transition: all 0.3s ease-in-out;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
}

#menu-btn-check:checked ~ .menu-content {
    left: 0; /* スライドイン */
    opacity: 1;
}

/* メニューリスト */
.nav-list {
    list-style: none;
    padding: 0;
    text-align: center;
}

.nav-list li {
    margin: 20px 0;
}

.nav-list a {
    text-decoration: none;
    color: var(--primary-color);
    font-size: 1.4rem;
    font-weight: 800;
    font-family: 'Helvetica Neue', sans-serif;
    display: block;
    transition: color 0.2s;
}

.nav-list a:hover {
    color: var(--accent-color);
}

.nav-list a span {
    display: block;
    font-size: 0.85rem;
    color: #888;
    font-weight: normal;
    font-family: "Noto Sans JP", sans-serif;
    margin-top: 4px;
}

.nav-divider {
    height: 1px;
    background-color: #ddd;
    margin: 25px auto !important;
    width: 60px;
}

/* =========================================
   Hamburger Menu (Left Side)
   ========================================= */
   .hamburger-menu {
    position: relative;
    z-index: 9999;
    margin-right: 15px; /* ロゴとの間隔を空ける */
}

#menu-btn-check {
    display: none;
}

.menu-btn {
    display: flex;
    height: 30px;
    width: 30px;
    justify-content: center;
    align-items: center;
    position: relative;
    cursor: pointer;
    z-index: 10001;
}

.menu-btn span,
.menu-btn span:before,
.menu-btn span:after {
    content: '';
    display: block;
    height: 2px;
    width: 24px;
    border-radius: 2px;
    background-color: var(--primary-color); /* ロゴの色に合わせる */
    position: absolute;
    transition: all 0.2s;
}

.menu-btn span:before { bottom: 8px; }
.menu-btn span:after { top: 8px; }

/* 開いた時のアイコン変化 */
#menu-btn-check:checked ~ .menu-btn span { background-color: rgba(255, 255, 255, 0); }
#menu-btn-check:checked ~ .menu-btn span::before { bottom: 0; transform: rotate(45deg); background-color: #333; }
#menu-btn-check:checked ~ .menu-btn span::after { top: 0; transform: rotate(-45deg); background-color: #333; }

/* メニュー画面（左からスライドイン） */
.menu-content {
    width: 100%;
    height: 100vh;
    position: fixed;
    top: 0;
    left: -100%; /* ★変更: 左側に隠しておく */
    z-index: 10000;
    background-color: rgba(255, 255, 255, 0.98);
    transition: all 0.3s ease-in-out;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
}

#menu-btn-check:checked ~ .menu-content {
    left: 0; /* スライドイン */
    opacity: 1;
}

/* 以下、リストのスタイルは前回と同じ */
.nav-list {
    list-style: none;
    padding: 0;
    text-align: center;
}

.nav-list li { margin: 20px 0; }

.nav-list a {
    text-decoration: none;
    color: var(--primary-color);
    font-size: 1.4rem;
    font-weight: 800;
    font-family: 'Helvetica Neue', sans-serif;
    display: block;
    transition: color 0.2s;
}
.nav-list a:hover { color: var(--accent-color); }

.nav-list a span {
    display: block;
    font-size: 0.85rem;
    color: #888;
    font-weight: normal;
    font-family: "Noto Sans JP", sans-serif;
    margin-top: 4px;
}

.nav-divider {
    height: 1px;
    background-color: #ddd;
    margin: 25px auto !important;
    width: 60px;
}


@media (max-width: 768px) {
    .main-container { flex-direction: column; }
    #view-smd { flex-direction: column; }
    #map-container { height: 50vh; width: 100%; }
    .info-panel { width: 100%; height: 50vh; border-left: none; border-top: 1px solid #ddd; }
    
    .prop-national-summary { flex-direction: column; text-align: center; }
    .prop-chart-wrapper { width: 100%; margin: 20px 0 0 0; }
    
    .header-left { gap: 10px; }
    .logo span { display: none; }
    .view-tab { padding: 4px 8px; font-size: 0.8rem; }
    
    .ranking-card { flex-direction: column; align-items: flex-start; gap: 10px; }
    .rank-value { text-align: left; width: 100%; border-top: 1px dashed #eee; padding-top: 5px; margin-top: 5px; }
    .rank-badge { position: absolute; top: 10px; right: 10px; }
    
    .ranking-controls { flex-direction: column; align-items: stretch; }
}