/* 変数定義（デザインシステムトークン） */
:root {
    --bg-primary: #0a0f1d;
    --bg-secondary: #111827;
    --bg-card: rgba(17, 24, 39, 0.75);
    --border-color: rgba(255, 255, 255, 0.08);
    --text-main: #f3f4f6;
    --text-muted: #9ca3af;
    
    /* アクセント・ステータスカラー */
    --accent-cyan: #00d2ff;
    --accent-mint: #05ffc7;
    --accent-pink: #ff0055;
    --accent-purple: #8b5cf6;
    --accent-amber: #f59e0b;
    
    /* フォント設定 */
    --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-display: 'Outfit', var(--font-ui);
    
    /* トランジション */
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* 全体基本設定 */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-ui);
    background-color: var(--bg-primary);
    color: var(--text-main);
    overflow: hidden;
    height: 100vh;
}

/* スクロールバーのカスタマイズ */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* アプリケーションレイアウト */
.app-container {
    display: flex;
    width: 100vw;
    height: 100vh;
    position: relative;
}

/* 左側：サイドバー */
.sidebar {
    width: 420px;
    min-width: 420px;
    height: 100%;
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 10;
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.5);
}

.sidebar-header {
    padding: 24px;
    border-bottom: 1px solid var(--border-color);
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 6px;
}

.logo-icon {
    font-size: 24px;
}

.logo h1 {
    font-family: var(--font-display);
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.highlight {
    background: linear-gradient(135deg, var(--accent-cyan), var(--accent-mint));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.scrollable-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 28px;
}

/* KPIカードセクション */
.kpi-section h2, .table-section h2 {
    font-family: var(--font-display);
    font-size: 16px;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.kpi-card {
    background-color: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: var(--transition-smooth);
}

.kpi-card:hover {
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
    background-color: rgba(255, 255, 255, 0.04);
}

.kpi-label {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 6px;
}

.kpi-value {
    font-family: var(--font-display);
    font-size: 20px;
    font-weight: 700;
}

/* 特殊カードスタイル */
.highlight-card {
    grid-column: span 2;
    background: linear-gradient(135deg, rgba(0, 210, 255, 0.1), rgba(5, 255, 199, 0.05));
    border: 1px solid rgba(0, 210, 255, 0.25);
    position: relative;
    overflow: hidden;
}

.highlight-card:hover {
    border-color: rgba(0, 210, 255, 0.5);
    box-shadow: 0 4px 20px rgba(0, 210, 255, 0.15);
}

.highlight-card .kpi-value {
    font-size: 32px;
    color: var(--accent-cyan);
    margin-bottom: 8px;
}

.warning-card {
    border-color: rgba(255, 0, 85, 0.2);
}
.warning-card .kpi-value {
    color: var(--accent-pink);
}

.success-card {
    border-color: rgba(5, 255, 199, 0.2);
}
.success-card .kpi-value {
    color: var(--accent-mint);
}

/* 進捗バー */
.progress-bar-container {
    width: 100%;
    height: 6px;
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-cyan), var(--accent-mint));
    border-radius: 3px;
    transition: width 1s ease-in-out;
}

/* テーブルセクション */
.table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.table-header h2 {
    margin-bottom: 0;
}

.btn-secondary {
    background-color: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.btn-secondary:hover {
    background-color: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

/* 検索・フィルターボックス (2段構成) */
.search-filter-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.filter-row {
    display: flex;
    gap: 8px;
}

.filter-row select {
    flex: 1;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    outline: none;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.filter-row select:focus {
    border-color: var(--accent-cyan);
}

.search-row {
    display: flex;
}

.search-row input {
    flex: 1;
    background-color: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    outline: none;
    transition: var(--transition-smooth);
}

.search-row input:focus {
    border-color: var(--accent-cyan);
    background-color: rgba(255, 255, 255, 0.06);
}

/* テーブルスタイル */
.table-wrapper {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: rgba(0, 0, 0, 0.1);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

th {
    position: sticky;
    top: 0;
    background-color: #172033;
    color: var(--text-muted);
    font-weight: 600;
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-color);
    z-index: 1;
}

td {
    padding: 10px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    color: var(--text-main);
}

tr {
    cursor: pointer;
    transition: var(--transition-smooth);
}

tr:hover {
    background-color: rgba(0, 210, 255, 0.05);
}

tr.selected {
    background-color: rgba(0, 210, 255, 0.12);
    border-left: 3px solid var(--accent-cyan);
}

.num-col {
    text-align: right;
}

.loading-placeholder {
    text-align: center;
    color: var(--text-muted);
    padding: 40px 0;
}

/* フッター */
.sidebar-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    font-size: 10px;
    color: var(--text-muted);
    text-align: center;
}

/* 右側：地図コンテナ */
.map-container {
    flex: 1;
    height: 100%;
    position: relative;
}

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

/* グラスモルフィズムカード共通 */
.card-glass {
    position: absolute;
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 16px;
    z-index: 5;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

/* 凡例 */
.map-legend {
    bottom: 24px;
    right: 24px;
    width: 260px;
}

.map-legend h3, .map-layers-control h3 {
    font-family: var(--font-display);
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 6px;
}

.legend-group {
    margin-bottom: 12px;
}

.legend-group:last-child {
    margin-bottom: 0;
}

.legend-group h4 {
    font-size: 10px;
    color: var(--text-muted);
    margin-bottom: 6px;
    text-transform: uppercase;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    margin-bottom: 4px;
    cursor: pointer;
    user-select: none;
    transition: opacity 0.2s ease;
}

.legend-item:hover {
    opacity: 0.85;
}

.legend-item.disabled {
    opacity: 0.3;
    text-decoration: line-through;
}

.legend-color {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    display: inline-block;
}

/* 凡例カラー */
.pt-covered { background-color: #00d2ff; }
.pt-uncovered { background-color: #ff0055; }
.poly-pub { background-color: rgba(59, 130, 246, 0.4); border: 1.5px solid rgb(59, 130, 246); }
.poly-auto { background-color: rgba(16, 185, 129, 0.4); border: 1.5px solid rgb(16, 185, 129); }
.poly-expanded { background-color: rgba(139, 92, 246, 0.35); border: 1.5px dashed rgb(167, 139, 250); }

/* レイヤコントロール */
.map-layers-control {
    top: 24px;
    right: 24px;
    width: 240px;
}

.control-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 11px;
    margin-bottom: 8px;
    cursor: pointer;
    user-select: none;
}

.control-item:last-child {
    margin-bottom: 0;
}

.control-item input[type="checkbox"] {
    cursor: pointer;
}

/* MapLibreポップアップカスタマイズ */
.maplibregl-popup-content {
    background: #111827 !important;
    border: 1px solid rgba(255, 255, 255, 0.12) !important;
    border-radius: 12px !important;
    color: #f3f4f6 !important;
    font-family: var(--font-ui) !important;
    font-size: 11px !important;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5) !important;
    padding: 12px 16px !important;
}

.maplibregl-popup-anchor-top .maplibregl-popup-tip { border-bottom-color: #111827 !important; }
.maplibregl-popup-anchor-bottom .maplibregl-popup-tip { border-top-color: #111827 !important; }
.maplibregl-popup-anchor-left .maplibregl-popup-tip { border-right-color: #111827 !important; }
.maplibregl-popup-anchor-right .maplibregl-popup-tip { border-left-color: #111827 !important; }

.popup-title {
    font-family: var(--font-display);
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--accent-cyan);
    border-bottom: 1px solid rgba(255,255,255,0.08);
    padding-bottom: 4px;
}

.popup-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
}

.popup-row:last-child {
    margin-bottom: 0;
}

.popup-label {
    color: var(--text-muted);
}

.popup-value {
    font-weight: 500;
    text-align: right;
}

/* メディアクエリ（画面幅狭い場合） */
@media (max-width: 1024px) {
    .sidebar {
        width: 360px;
        min-width: 360px;
    }
    .kpi-grid {
        grid-template-columns: 1fr;
    }
    .highlight-card {
        grid-column: span 1;
    }
}

/* --- 追加のUIスタイル --- */

/* テーマ切り替え用の CSS 定義 */
body.light-theme {
    --bg-primary: #f3f4f6;
    --bg-secondary: #ffffff;
    --bg-card: rgba(255, 255, 255, 0.85);
    --border-color: rgba(0, 0, 0, 0.08);
    --text-main: #1f2937;
    --text-muted: #4b5563;
}

body.light-theme .kpi-card {
    background-color: rgba(0, 0, 0, 0.01);
    border-color: rgba(0, 0, 0, 0.08);
}
body.light-theme .kpi-card:hover {
    background-color: rgba(0, 0, 0, 0.03);
    border-color: rgba(0, 0, 0, 0.15);
}
body.light-theme th {
    background-color: #e5e7eb;
    color: #4b5563;
    border-bottom-color: rgba(0, 0, 0, 0.1);
}
body.light-theme td {
    border-bottom: 1px solid rgba(0, 0, 0, 0.04);
}
body.light-theme tr:hover {
    background-color: rgba(0, 210, 255, 0.05);
}
body.light-theme tr.selected {
    background-color: rgba(0, 210, 255, 0.08);
}
body.light-theme .btn-secondary {
    background-color: rgba(0, 0, 0, 0.04);
    color: var(--text-main);
    border-color: rgba(0, 0, 0, 0.12);
}
body.light-theme .btn-secondary:hover {
    background-color: rgba(0, 0, 0, 0.08);
}
body.light-theme .btn-theme-toggle {
    background: rgba(0, 0, 0, 0.04);
    color: var(--text-main);
    border-color: rgba(0, 0, 0, 0.12);
}
body.light-theme .btn-theme-toggle:hover {
    background: rgba(0, 0, 0, 0.08);
}
body.light-theme .maplibregl-popup-content {
    background: #ffffff !important;
    border-color: rgba(0,0,0,0.1) !important;
    color: #1f2937 !important;
    box-shadow: 0 10px 30px rgba(0,0,0,0.15) !important;
}
body.light-theme .maplibregl-popup-anchor-top .maplibregl-popup-tip { border-bottom-color: #ffffff !important; }
body.light-theme .maplibregl-popup-anchor-bottom .maplibregl-popup-tip { border-top-color: #ffffff !important; }
body.light-theme .maplibregl-popup-anchor-left .maplibregl-popup-tip { border-right-color: #ffffff !important; }
body.light-theme .maplibregl-popup-anchor-right .maplibregl-popup-tip { border-left-color: #ffffff !important; }
body.light-theme select {
    background-color: #ffffff !important;
    color: #1f2937 !important;
}

/* テーマ切り替えボタン */
.btn-theme-toggle {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 14px;
    transition: var(--transition-smooth);
    margin-left: auto;
}
.btn-theme-toggle:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: scale(1.05);
}

/* サマリー市区町村選択エリア */
.summary-header-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    gap: 8px;
}
.summary-header-container h2 {
    margin-bottom: 0 !important;
}
#summary-city-select {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 11px;
    outline: none;
    cursor: pointer;
    transition: var(--transition-smooth);
    max-width: 180px;
}
#summary-city-select:focus {
    border-color: var(--accent-cyan);
}



