/* 変数定義 */
:root {
  --main-color: #FF5722;
  --main-color-hover: #E64A19;
  --main-color-active: #BF360C;
  --main-color-light: #FFCCBC;
  --border-color: #ccc;
  --header-bg: #f2f2f2;
}

/* 全体構成 */
body,
html {
  margin: 0;
  height: 100%;
  font-family: Arial, sans-serif;
  color: #333;
}

/* 地図領域 */
#map {
  width: 100%;
  height: 100%;
}

/* テーブル */
table {
  width: 100%;
  border-collapse: collapse;
}

table th,
table td {
  padding: 8px;
  border: 1px solid #ddd;
  text-align: left;
}

table th {
  background-color: var(--header-bg);
  font-weight: bold;
}

table td {
  background-color: #fff;
}

/* ポップアップ */
.popup-content {
  box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.2);
}

/* レイヤーコントロール */
#layerControl {
  position: absolute;
  top: 10px;
  left: 10px !important;
  right: auto !important;
  width: 350px;
  max-height: calc(100vh - 40px);
  padding: 10px;
  background-color: #fff;
  font-size: 12px;
  border-radius: 5px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
  z-index: 1000;
  display: flex !important;
  flex-direction: column;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#layerControl.collapsed {
  width: 44px;
  height: 44px;
  padding: 0;
  overflow: hidden;
}

#layerControl select,
#layerControl input[type="text"],
#layerControl button,
#opacitySlider {
  width: 100%;
  margin-bottom: 8px;
  padding: 6px;
  font-size: 12px;
  border: 1px solid var(--border-color);
  border-radius: 3px;
  box-sizing: border-box;
}

#opacitySlider {
  margin-top: 5px;
}

#layerControl fieldset label {
  display: inline-block;
  margin-right: 1px;
  white-space: nowrap;
}

/* ステップ説明 */
.step-description {
  font-size: 12px;
  color: #666;
  margin: 0 0 6px 0;
  padding: 0;
}

/* コントロールボタン */
#layerControlButton,
#helpButton {
  display: none !important;
}

#layerControlButton {
  position: absolute;
  top: 10px;
  left: 10px;
  width: 40px;
  height: 40px;
  background-color: var(--main-color);
  color: white;
  font-size: 16px;
  font-weight: bold;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 1000;
}

#helpButton {
  position: absolute;
  top: 60px;
  left: 10px;
  width: 40px;
  height: 40px;
  background-color: var(--main-color);
  color: white;
  font-size: 14px;
  font-weight: bold;
  text-align: center;
  line-height: 40px;
  border-radius: 5px;
  cursor: pointer;
  z-index: 1000;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

/* 中心マーカー (使用していないため無効化) */
/*
.center-marker {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 30px;
  height: 35px;
  background-image: url('https://docs.mapbox.com/mapbox-gl-js/assets/custom_marker.png');
  background-size: contain;
  background-repeat: no-repeat;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 10;
}
*/

/* モーダル */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  z-index: 1000;
}

.modal-content {
  position: relative;
  top: 50%;
  left: 50%;
  width: 90%;
  height: 90%;
  transform: translate(-50%, -50%);
  background: #fff;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.close-button {
  position: absolute;
  top: 10px;
  right: 20px;
  font-size: 30px;
  color: #333;
  cursor: pointer;
}

#helpFrame {
  width: 100%;
  height: 100%;
  border: none;
}

/* 地図帰属情報 */
.attribution {
  position: absolute;
  bottom: 5px;
  right: 10px;
  padding: 3px 10px;
  font-size: 11px;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 4px;
  pointer-events: none;
  z-index: 1000;
}

/* パネルヘッダー */
.panel-header {
  background: var(--main-color);
  margin: -10px -10px 10px -10px;
  padding: 10px 15px;
  border-radius: 5px 5px 0 0;
  color: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  position: relative;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  height: 44px;
  box-sizing: border-box;
  flex-shrink: 0;
}

#layerControl.collapsed .panel-header {
  margin: 0;
  border-radius: 5px;
  width: 44px;
  height: 44px;
  padding: 0;
  justify-content: center;
}

.panel-title {
  margin: 0;
  font-size: 16px;
  font-weight: bold;
  color: white;
  transition: opacity 0.3s ease-out;
}

#layerControl.collapsed .panel-title {
  display: none;
}

.panel-description {
  font-size: 13px;
  color: #555;
  margin: 0 0 15px 0;
  padding: 0;
  line-height: 1.5;
}

.detail-link {
  color: var(--main-color);
  text-decoration: none;
  font-weight: normal;
  display: inline;
}

.detail-link:hover {
  text-decoration: underline;
}

.powered-by {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  font-size: 11px;
  color: #666;
  margin: 10px 0 0 0;
}

.logo-link {
  display: flex;
  align-items: center;
  transition: opacity 0.2s;
}

.logo-link:hover {
  opacity: 0.8;
}

.mq-logo {
  height: 16px;
  width: auto;
}

.powered-text {
  white-space: nowrap;
}

.mapquest-link {
  color: var(--main-color);
  text-decoration: none;
  font-weight: bold;
}

.mapquest-link:hover {
  text-decoration: underline;
}

.panel-toggle {
  font-size: 18px;
  color: white;
  cursor: pointer;
  user-select: none;
  transition: transform 0.3s;
  font-weight: bold;
}

#layerControl.collapsed .panel-toggle {
  font-size: 22px;
}

.panel-content {
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1;
  min-height: 0;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  opacity: 1;
  visibility: visible;
  transform: scale(1);
  transform-origin: top left;
}

#layerControl.collapsed .panel-content {
  opacity: 0;
  visibility: hidden;
  position: absolute;
  transform: scale(0);
}

/* 距離表示 */
.distance-display {
  background: #FBE9E7;
  border: 1px solid var(--main-color-light);
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 500;
  color: var(--main-color-active);
  text-align: center;
}

.distance-display::before {
  content: '📏 合計距離: ';
}

/* マップ上のセグメント距離ポップアップ */
.comment-popup .maplibregl-popup-content {
  padding: 4px 8px;
  font-size: 12px;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--main-color);
  border-radius: 4px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  position: relative;
}

/* デフォルトの tip を非表示 */
.comment-popup .maplibregl-popup-tip {
  display: none !important;
}

/* カスタム三角形（白背景＋青枠） */
.comment-popup.maplibregl-popup-anchor-bottom .maplibregl-popup-content::after {
  content: '';
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 8px solid var(--main-color);
}

.comment-popup.maplibregl-popup-anchor-bottom .maplibregl-popup-content::before {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 6px solid rgba(255, 255, 255, 0.95);
  z-index: 1;
}

/* セグメント距離表示 */
.distance-label {
  font-weight: bold;
  color: var(--main-color);
  white-space: nowrap;
}

/* 単位セレクタ */
.unit-selectors {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #eee;
}

.unit-selector-row {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.unit-label {
  font-size: 12px;
  color: #666;
}

.unit-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.unit-selectors .unit-selector {
  padding: 4px 6px;
  font-size: 12px;
  border: 1px solid var(--border-color);
  border-radius: 3px;
}

/* モードセレクタ */
.mode-selector {
  display: flex;
  gap: 12px;
  margin-bottom: 6px;
}

.mode-option {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

.mode-option input[type="radio"] {
  margin: 0;
  cursor: pointer;
}

.mode-label {
  font-size: 13px;
  color: #333;
}

/* 面積表示 */
.area-display {
  background: #E3F2FD;
  border: 1px solid #90CAF9;
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 500;
  color: #1565C0;
  text-align: center;
}

.area-display::before {
  content: '\25A0 ';
}

/* 外周表示 */
.perimeter-display {
  background: #E8F5E9;
  border: 1px solid #A5D6A7;
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 500;
  color: #2E7D32;
  text-align: center;
}

.perimeter-display::before {
  content: '\25CB ';
}

/* 計測管理セクション */
.measurement-manager {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
  align-items: center;
}

/* 計測セレクタ（ドロップダウン） */
.measurement-selector {
  flex: 1;
  padding: 6px 8px;
  font-size: 12px;
  border: 1px solid var(--border-color);
  border-radius: 3px;
  box-sizing: border-box;
}

/* アイコンボタン（削除ボタン） */
.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 28px;
  width: 28px;
  min-width: 28px;
  max-width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--border-color);
  border-radius: 3px;
  background: #f5f5f5;
  cursor: pointer;
  color: #666;
  transition: background-color 0.2s, color 0.2s;
}

.icon-btn:hover {
  background: #e0e0e0;
  color: #e53935;
}

.icon-btn .material-icons {
  font-size: 18px;
}

/* 計測結果コンテナ */
.measurement-result-container {
  margin-top: 6px;
}

/* ========================================
   計測パネルリスト（SMM-007）
   ======================================== */

/* パネルリストコンテナ */
.measurement-panel-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 10px 0;
  max-height: 300px;
  overflow-y: auto;
}

/* 計測パネル */
.measurement-panel {
  display: flex;
  flex-shrink: 0;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
  overflow: hidden;
}

.measurement-panel:hover {
  border-color: #999;
}

/* アクティブパネル */
.measurement-panel.active {
  border-width: 2px;
  border-color: var(--main-color);
  box-shadow: 0 2px 4px rgba(255, 87, 34, 0.2);
}

/* 色インジケータ（パネル左端の縦バー） */
.color-indicator {
  width: 6px;
  flex-shrink: 0;
}

/* パネルボディ */
.panel-body {
  flex: 1;
  padding: 8px 10px;
  min-width: 0;
}

/* パネルヘッダー行（アイコン + タイトル + 編集ボタン） */
.panel-header-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

/* モードアイコン */
.panel-header-row .mode-icon {
  font-size: 18px;
  color: #666;
}

/* パネルタイトル */
.measurement-panel .panel-title {
  font-size: 13px;
  font-weight: bold;
  color: #333;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* パネル計測結果行（結果 + 削除ボタン） */
.panel-result-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* パネル計測結果 */
.panel-result {
  flex: 1;
  font-size: 18px;
  font-weight: bold;
  color: #333;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 外周テキスト（面積計測時） */
.panel-result .perimeter-text {
  font-size: 12px;
  font-weight: normal;
  color: #666;
}

/* パネル内ボタン共通 */
.panel-btn {
  padding: 3px 6px;
  font-size: 11px;
  border: 1px solid var(--border-color);
  border-radius: 3px;
  background: #f5f5f5;
  cursor: pointer;
  transition: background-color 0.2s;
}

.panel-btn:hover:not(:disabled) {
  background: #e0e0e0;
}

.panel-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* パネル内アイコンボタン */
.panel-btn.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 !important;
  padding: 0 !important;
  width: 24px;
  height: 24px;
  border: none !important;
  background: transparent !important;
  color: #888;
}

.panel-btn.icon-btn .material-icons {
  font-size: 16px;
}

.panel-btn.icon-btn:hover:not(:disabled) {
  background: transparent;
  color: #e53935;
}

/* Undo/削除ボタンを右端に配置 */
.panel-btn.icon-btn.undo-btn {
  margin-left: auto !important;
}

/* 新規計測ボタンコンテナ */
.add-measurement-btns {
  display: flex;
  gap: 8px;
}

/* 新規計測ボタン */
.add-measurement-btn {
  flex: 1;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--main-color);
  background: #fff;
  border: 1px dashed var(--main-color);
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.2s, color 0.2s;
}

.add-measurement-btn:hover {
  background: var(--main-color-light);
  color: var(--main-color-active);
}

/* 合計距離ラベル（Popup） */
.total-distance-popup .maplibregl-popup-content {
  background: rgba(255, 255, 255, 0.95);
  padding: 4px 8px;
  border-radius: 4px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

.total-distance-popup .maplibregl-popup-tip {
  border-top-color: rgba(255, 255, 255, 0.95);
}

.total-label-title {
  font-size: 13px;
  font-weight: bold;
  color: #333;
  white-space: nowrap;
  text-align: center;
}

.total-label {
  font-size: 13px;
  font-weight: bold;
  color: #333;
  white-space: nowrap;
}

/* 面積ラベル（HTML マーカー） */
.area-label {
  background: rgba(255, 255, 255, 0.95);
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: bold;
  color: #333;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
  white-space: nowrap;
  text-align: center;
}

.area-label-title {
  font-size: 13px;
  font-weight: bold;
  color: #333;
}

/* セグメント距離ラベル（HTML マーカー） */
.segment-label {
  background: rgba(255, 255, 255, 0.85);
  padding: 1px 4px;
  border-radius: 2px;
  font-size: 10px;
  font-weight: 500;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
  white-space: nowrap;
  pointer-events: none;
}