:root {
	--primary: #005CAF; 
	--white: #ffffff;
	--text-main: #333333; 
	--text-light: #666666;
	--bg-panel: #ffffff;
	--border-color: #005CAF;
	--border-light: #dddddd; 
	--bg-light: #f7f9fa; 
	--active-bg: #e6f0fa;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Noto Sans JP', sans-serif; color: var(--text-main); }
body, html { width: 100%; height: 100%; overflow: hidden; background-color: var(--primary); }

/* --- 背景・地図ステート制御 --- */
#home-bg {
	position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 1;
	background-color: var(--primary);
	background-image: radial-gradient(rgba(255,255,255,0.1) 2px, transparent 2px);
	background-size: 30px 30px;
}
body.state-home #map { opacity: 0; pointer-events: none; }
body.state-map #home-bg { display: none; }
body.state-map #map { opacity: 1; pointer-events: auto; position: absolute; top: 0; left: 0; width: 100vw; height: 100vh; z-index: 1; transition: opacity 0.5s; }

/* --- コントロールパネルのベース --- */
#control-panel {
	position: absolute; z-index: 1000; background-color: var(--bg-panel);
	display: flex; flex-direction: column; transition: transform 0.3s ease-in-out, height 0.3s ease-in-out, opacity 0.3s ease-in-out;
}

/* スマホ：初期状態（画面中央配置） */
body.state-home #control-panel {
	top: 50%; left: 50%; transform: translate(-50%, -50%);
	width: 90%; max-width: 480px; height: 85vh;
	border: 3px solid var(--border-color); border-radius: 8px;
	box-shadow: 0 15px 35px rgba(0,0,0,0.4);
}
body.state-home #control-panel.collapsed { transform: translate(-50%, -40%) scale(0.9); opacity: 0; visibility: hidden; pointer-events: none; }

/* スマホ：検索後マップ状態（下部固定シート） */
body.state-map #control-panel {
	bottom: 0; left: 0; width: 100vw; height: 50vh; /* 半分表示 */
	border: 3px solid var(--border-color); border-bottom: none; border-left: none; border-right: none;
	box-shadow: 0 -5px 25px rgba(0,0,0,0.2);
	transform: none;
}
body.state-map #control-panel.collapsed { transform: translateY(105%); opacity: 0; visibility: hidden; pointer-events: none; }

/* --- スマホ時の全画面表示クラス --- */
body.state-map #control-panel.expanded { height: 90vh !important; }

/* --- パネル再表示ボタン（一元管理） --- */
#panel-toggle-show {
	position: absolute; display: none; z-index: 1001; bottom: 20px; left: 50%; transform: translateX(-50%);
	border-radius: 999px; box-shadow: 0 4px 15px rgba(0,0,0,0.3); padding: 12px 24px;
}
body.panel-closed #panel-toggle-show { display: block !important; }

/* --- ヘッダー＆タブ --- */
#panel-header-bar {
	display: flex; justify-content: space-between; align-items: center;
	border-bottom: 1px solid var(--border-light); background-color: var(--bg-light);
	padding: 0 12px; flex-shrink: 0;
}
.app-title { font-family: 'Black Ops One', system-ui; color: var(--primary); font-size: 24px; padding: 12px 0; letter-spacing: 1px; margin: 0 auto; }
.header-actions { display: flex; gap: 8px; align-items: center; }
.icon-btn { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--text-main); padding: 5px; }
.mobile-only { display: none; }

.tabs { display: flex; border-bottom: 2px solid var(--border-color); background: var(--white); flex-shrink: 0; }
.tab-btn { flex: 1; background: var(--white); color: var(--primary); border: none; border-right: 1px solid var(--border-light); padding: 12px 0; font-weight: bold; cursor: pointer; font-size: 13px; }
.tab-btn:last-child { border-right: none; }
.tab-btn.active { background: var(--primary); color: var(--white); }

/* --- 多言語ボタン（最前面固定） --- */
.lang-btn { position: absolute; top: 15px; right: 15px; z-index: 9999; padding: 6px 12px; font-weight: bold; border-radius: 4px; box-shadow: 0 2px 6px rgba(0,0,0,0.3); }

/* --- スクロール構造の正常化 --- */
.tab-content { display: none; padding: 12px; overflow-y: auto; flex: 1; min-height: 0; -webkit-overflow-scrolling: touch; }
.tab-content.active { display: flex; flex-direction: column; }

.results-list, .saved-list { 
	margin-top: 10px; display: flex; flex-direction: column; gap: 8px; flex-shrink: 0;
}

/* --- 各種フォームパーツ --- */
.search-box { display: flex; flex-direction: column; gap: 8px; flex-shrink: 0; }
input[type="text"] { width: 100%; padding: 10px; border: 1px solid #ccc; font-size: 14px; outline: none; transition: border 0.2s; border-radius: 4px; }
input[type="text"]:focus { border-color: var(--primary); background: var(--active-bg); }

.flat-btn { background-color: var(--primary); color: var(--white) !important; border: 2px solid var(--primary); padding: 11px; font-size: 13px; font-weight: bold; cursor: pointer; text-align: center; text-decoration: none; display: inline-block; transition: 0.2s; border-radius: 4px; }
.flat-btn:disabled { background-color: #f5f5f0; border-color: #dddddd; color: #aaaaaa !important; cursor: not-allowed; }
.flat-btn:not(:disabled):active { background-color: var(--white); color: var(--primary) !important; }
.flat-btn.outline { background-color: var(--white); color: var(--primary) !important; }
.flat-btn.outline:not(:disabled):active { background-color: var(--primary); color: var(--white) !important; }
.flat-btn.small { padding: 8px; font-size: 12px; }
.full-width { width: 100%; }

.custom-select { 
	padding: 10px 30px 10px 10px; border: 1px solid #ccc; background: var(--white); font-size: 13px; font-weight: bold; color: var(--text-main); outline: none; border-radius: 4px;
	appearance: none; -webkit-appearance: none; cursor: pointer;
	background-image: url('data:image/svg+xml;utf8,<svg fill="%23333" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><path d="M7 10l5 5 5-5z"/><path d="M0 0h24v24H0z" fill="none"/></svg>');
	background-repeat: no-repeat; background-position: right 8px center;
}
.custom-select:disabled { background-color: #f9f9f9; color: #aaa; cursor: not-allowed; }

.divider { border-top: 1px dashed var(--border-light); margin: 8px 0; flex-shrink: 0; }
.category-header { margin-bottom: 4px; flex-shrink: 0; }
.category-title { font-weight: bold; font-size: 13px; color: var(--primary); }
.category-dropdowns { display: flex; flex-direction: column; gap: 8px; flex-shrink: 0; }
.category-action-buttons { display: flex; gap: 6px; width: 100%; }
.category-action-buttons button { flex: 1; }

/* --- リストアイテムスタイル --- */
.result-item, .saved-item { border: 1px solid var(--border-light); border-left: 4px solid var(--primary); padding: 10px; background: var(--white); cursor: pointer; flex-shrink: 0; border-radius: 4px; }
.result-item:hover, .saved-item:hover { background: var(--bg-light); }
.result-item.active, .saved-item.active { background: var(--primary) !important; border-color: var(--primary) !important; }
.result-item.active .item-title, .result-item.active .item-sub, .saved-item.active .item-title, .saved-item.active .item-sub { color: var(--white) !important; }
.item-title { font-weight: bold; color: var(--text-main); font-size: 13px; margin-bottom: 2px; word-break: break-all; }
.item-sub { font-size: 11px; color: var(--text-light); word-break: break-all; }

.panel-footer { padding: 10px; text-align: center; font-size: 11px; border-top: 1px solid var(--border-light); background: var(--bg-light); flex-shrink: 0; }
.panel-footer a { color: var(--primary); text-decoration: none; font-weight: bold; }
.modal-overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(51, 51, 51, 0.8); z-index: 3000; justify-content: center; align-items: center; }
.modal-overlay.show { display: flex; }
.modal-content { background: var(--white); border: 3px solid var(--primary); width: 90%; max-width: 500px; max-height: 80vh; padding: 20px; display: flex; flex-direction: column; }
.modal-content h2 { color: var(--primary); border-bottom: 1px solid var(--border-light); padding-bottom: 8px; margin-bottom: 12px; font-size: 17px; }
.modal-body { overflow-y: auto; font-size: 13px; line-height: 1.6; flex: 1; white-space: pre-wrap; }

/* Leaflet ポップアップ上書き */
.leaflet-popup-content-wrapper { border: 3px solid var(--primary) !important; border-radius: 0 !important; background: var(--white) !important; box-shadow: 0 4px 10px rgba(51, 51, 51, 0.2) !important; }
.leaflet-popup-tip { background: var(--primary) !important; box-shadow: none !important; }
.custom-popup h3 { margin: 0 0 4px 0; color: var(--primary); font-size: 14px; font-weight: bold; border-bottom: 1px solid var(--border-light); padding-bottom: 5px; }
.custom-popup p { margin: 4px 0 8px 0; font-size: 11px; color: var(--text-light); }
.popup-actions { display: flex; gap: 4px; margin-bottom: 6px; }

/* --- PC版レスポンシブ --- */
@media (min-width: 769px) {
	body.state-home #home-bg { display: none; }
	body.state-home #map { opacity: 1 !important; pointer-events: auto !important; position: absolute; top: 0; left: 0; width: 100vw; height: 100vh; z-index: 1;}
	
	body.state-home #control-panel,
	body.state-map #control-panel { 
		top: 20px; left: 20px; bottom: auto; width: 380px; height: calc(100vh - 40px); 
		border: 3px solid var(--border-color) !important; border-radius: 8px !important;
		box-shadow: 0 10px 25px rgba(0,0,0,0.2) !important; transform: none !important; opacity: 1 !important; visibility: visible !important;
	}
	body.state-home #control-panel.collapsed,
	body.state-map #control-panel.collapsed { 
		transform: translateX(-120%) !important; opacity: 0 !important; visibility: hidden !important; pointer-events: none !important;
	}
	
	body.panel-closed #panel-toggle-show { 
		bottom: auto !important; top: 20px !important; left: 20px !important; transform: none !important; 
	}
	.leaflet-control-container .leaflet-left { left: 400px; transition: left 0.3s; }
}

@media (max-width: 768px) {
	body.state-home #panel-header-bar #panel-toggle-hide { display: none !important; }
	.mobile-only { display: inline-block; }
	.leaflet-control-container .leaflet-bottom { bottom: 52vh !important; transition: bottom 0.3s; }
	/* 拡大時のLeafletズームコントロール位置調整 */
	body.state-map #control-panel.expanded ~ .leaflet-control-container .leaflet-bottom { bottom: 92vh !important; }
}