/* ========================================
   公開型GIS スタイル : 地図まわり（地図コンテナ・ストリートビュー・ツールバー・情報バー・中心マーク・背景地図）
   （読み込み順が適用順です。index.html / survey/index.html の
     link 順を入れ替えると見た目が変わります）
   ======================================== */
/* ========================================
   Map Container
   ======================================== */
#map-wrapper {
  flex: 1;
  position: relative;
  display: flex;
  overflow: hidden;
}

#map, #map2 {
  flex: 1;
  height: 100%;
}

/* 地図の地色。Leaflet の既定はグレー(#ddd)で、透過部分のある背景地図
   （白地図や自治体独自のタイルなど）を選ぶと下地が灰色に見えてしまう。
   紙の地図に合わせて白にする。索引図・分割画面・印刷にも同じ地色を使う。 */
.leaflet-container {
  background: #fff;
}

/* Leaflet のデフォルト grab カーソルを上書き — JS inline style で管理するため CSS 側は無効化のみ */
.leaflet-grab,
.leaflet-dragging .leaflet-grab {
  cursor: inherit;
}
/* 作図モード: 頂点マーカーを計測と同サイズの小さな丸に統一 */
#map .leaflet-div-icon,
#map .leaflet-editing-icon {
  width: 8px !important;
  height: 8px !important;
  margin-left: -4px !important;
  margin-top: -4px !important;
  border-radius: 50% !important;
  background: #fff !important;
  border: 2px solid #c53030 !important;
  box-sizing: border-box !important;
}
/* タッチ用の大きなアイコンも縮小 */
#map .leaflet-touch-icon {
  width: 12px !important;
  height: 12px !important;
  margin-left: -6px !important;
  margin-top: -6px !important;
  border-radius: 50% !important;
  background: #fff !important;
  border: 2px solid #c53030 !important;
  box-sizing: border-box !important;
}

/* 作図モード: Leaflet.Draw の .leaflet-mouse-marker カーソルを黒い十字に固定 */
.leaflet-mouse-marker {
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24'%3E%3Cline x1='12' y1='1' x2='12' y2='23' stroke='%23000' stroke-width='1.5'/%3E%3Cline x1='1' y1='12' x2='23' y2='12' stroke='%23000' stroke-width='1.5'/%3E%3Ccircle cx='12' cy='12' r='2' fill='none' stroke='%23000' stroke-width='1.5'/%3E%3C/svg%3E") 12 12, crosshair !important;
}
/* ローディング中は砂時計（inline style より優先するため !important） */
body.map-loading #map .leaflet-container,
body.map-loading #map {
  cursor: wait !important;
}

#map2 { display: none; }
#map2.active { display: flex; }

#map-divider {
  width: 4px;
  background: var(--primary);
  cursor: col-resize;
  display: none;
  flex-shrink: 0;
  position: relative;
}
#map-divider.active { display: block; }
#map-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 12px;
  height: 40px;
  background: var(--primary);
  border-radius: 2px;
  opacity: 0.7;
}

/* ========================================
   Street View（公開GIS専用）
   2画面表示と同じ場所を使うため、開くのはどちらか一方だけ。
   ======================================== */
#streetview-pane {
  display: none;
  flex: 1;
  height: 100%;
  position: relative;
  border-left: 4px solid var(--primary);
  background: #2d3748;   /* パノラマ読み込み前の下地 */
}
#streetview-pane.active { display: block; }
#streetview-canvas { width: 100%; height: 100%; }

/* 案内文・エラー文はパノラマの上に重ねる */
.sv-msg {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
  margin: 0;
  max-width: 86%;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: var(--fs-body);
  line-height: 1.8;
  text-align: center;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
}
.sv-msg-warn  { border-left: 4px solid #dd6b20; }
.sv-msg-error { border-left: 4px solid #c53030; }

/* 補足（押した場所から離れているときの断り書き）。風景を隠さないよう下端に置く */
#streetview-note {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  margin: 0;
  padding: 7px 12px;
  font-size: var(--fs-caption);
  line-height: 1.6;
  text-align: center;
  color: #fff;
  background: rgba(0, 0, 0, 0.62);
}

#streetview-close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 3;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  color: #333;
  font-size: var(--icon-md);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}
#streetview-close:hover { background: #fff; }

/* 地図上の目印：立っている場所の丸と、見ている向きの扇形 */
.sv-marker-icon .sv-cone {
  position: absolute;
  top: 0;
  left: 0;
  width: 40px;
  height: 40px;
  background: radial-gradient(circle at 50% 50%, rgba(49, 130, 206, 0.55) 0%, rgba(49, 130, 206, 0) 72%);
  clip-path: polygon(50% 50%, 18% 0%, 82% 0%);   /* 0deg で北（上）を向く扇形 */
  transform: rotate(var(--sv-heading, 0deg));
  transform-origin: 50% 50%;
}
.sv-marker-icon .sv-dot {
  position: absolute;
  top: 15px;
  left: 15px;
  width: 10px;
  height: 10px;
  box-sizing: border-box;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 3px rgba(0, 0, 0, 0.5);
}

/* ツールバーは #map-wrapper を基準に右端へ置いているため、そのままだと
   ストリートビュー側にかぶる。地図（左半分）の右端に寄せ直す。 */
body.sv-open #toolbar { right: calc(50% + 10px); }
/* 2画面表示ではツールバーを動かさない。左画面側へ寄せると検索バー（幅は
   画面中央付近まで）に重なってしまうため、どちらの地図かは各画面のラベル
   （.basemap-label）で示す方式にしている。 */

/* スマホは左右に割ると両方とも狭すぎるので、上下に分ける */
@media (max-width: 640px) {
  body.sv-open #map-wrapper { flex-direction: column; }
  body.sv-open #streetview-pane {
    border-left: none;
    border-top: 4px solid var(--primary);
  }
  /* 上下に分かれるので、ツールバーは右端のままでよい（上半分＝地図の上に乗る） */
  body.sv-open #toolbar { right: 10px; }
}

/* ========================================
   Toolbar (floating on map)
   ======================================== */
/* ツールバーは端末を問わず常に縦並び。
   「その他」を開くと2段目が左隣に縦に並ぶので、地図の上端をふさがない。 */
#toolbar {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  flex-direction: row-reverse;
  align-items: flex-start;
  gap: 4px;
  z-index: 1200;
  background: #fff;
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  padding: 4px;
  max-width: calc(100vw - 24px);
  max-height: calc(100% - 20px);   /* 画面が低いときははみ出さずスクロールする */
  overflow-y: auto;
}

.toolbar-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  justify-content: center;
}
#toolbar-more {
  border-right: 1px solid var(--gray-200);
  padding-right: 4px;
}
#toolbar-more[hidden] { display: none; }

.tool-btn {
  min-width: 62px;
  border: 1px solid var(--gray-200);
  background: none;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 7px 8px 5px;
  color: var(--gray-700);
  font-size: var(--icon-lg);
  transition: all 0.15s;
  position: relative;
}
.tool-btn .tool-label {
  font-size: var(--fs-caption);
  line-height: 1;
  font-family: var(--font);
  white-space: nowrap;
}
.tool-btn i { color: var(--primary); }
.tool-btn:hover { background: var(--gray-100); }
.tool-btn.active { background: var(--primary-light); color: var(--primary); border-color: var(--primary); }
.tool-btn-more i { color: var(--gray-500); }
/* 2段目に使用中の機能があるとき「その他」ボタンに印を付ける */
.tool-btn-more.has-active::after {
  content: '';
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
}

/* ========================================
   Map Info Bar
   ======================================== */
#map-info-bar {
  position: absolute;
  bottom: 28px;
  left: 10px;
  background: rgba(255,255,255,0.9);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 4px 10px;
  font-size: var(--fs-caption);
  color: var(--gray-700);
  z-index: 1200;
  cursor: pointer;
  user-select: none;
}
#map-info-bar:hover { background: #fff; }
#coord-display { display: inline; }

/* ========================================
   Center Mark
   ======================================== */
#center-mark, #center-mark-2 {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1200;
  pointer-events: none;
  display: none;
}
#center-mark.visible, #center-mark-2.visible { display: block; }
#center-mark svg, #center-mark-2 svg {
  width: 32px;
  height: 32px;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.4));
}

/* ========================================
   Basemap Switcher (floating)
   ======================================== */
#basemap-switcher {
  position: absolute;
  bottom: 28px;
  /* ツールバーの左隣に開く。以前の right:10px だとサムネイル化で
     パネルが縦に伸びた分、小さい画面でツールバーのボタンに重なってしまう。
     ツールバーの幅は文字サイズで変わるので、js/gis-toolbar.js が実測して
     渡す --toolbar-w を使う（10px は #toolbar 自身の right）。 */
  right: calc(var(--toolbar-w, 86px) + 10px);
  z-index: 1200;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  display: none;
}
/* .basemap-picker の display:grid より id 側の指定が強いため、ここで grid にする */
#basemap-switcher.visible { display: grid; }

/* 背景地図ピッカー（描画は js/gis-common.js の gisBuildBasemapPicker）。
   ラジオボタンの一覧では地図の見た目が分からないため、いま見ている場所の
   タイル画像をサムネイルにして 2 列に並べる。背景地図が多い自治体でも
   画面からはみ出さないよう、あふれた分はスクロールさせる。 */
.basemap-picker {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  padding: 10px;
  max-height: min(72vh, 460px);
  overflow-y: auto;
}
.basemap-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  /* サムネイルより少し広くして、地図の名前が極端に折り返さないようにする */
  width: 96px;
  padding: 0;
  border: none;
  background: none;
  font-family: var(--font);
  color: var(--gray-700);
  cursor: pointer;
}
/* サムネイル枠。寸法は gis-common.js の GIS_BASEMAP_THUMB_W / _H と必ず揃える */
.basemap-card-thumb {
  position: relative;
  width: 78px;
  height: 58px;
  flex-shrink: 0;
  overflow: hidden;
  border-radius: 6px;
  border: 2px solid var(--gray-200);
  background: var(--gray-100);
}
/* タイル画像が無いとき（Google 系・読み込み失敗）に見える絵。
   描画は js/gis-common.js の gisBasemapArt。タイル画像が乗ればそれで隠れる */
.basemap-card-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
/* 管理画面の設定がONのときだけ差し込む本物の Google 地図。
   Google の帰属表示（「地図データ 利用規約」）が 78×58 では収まらないので、
   2倍の大きさで描いて半分に縮小する。px ではなく 200% にしているのは、
   枠線の 2px 分だけはみ出して帰属表示の下端が切れるのを避けるため
   （% は枠線の内側を基準に解決される）。 */
.basemap-card-gmap {
  position: absolute;
  top: 0;
  left: 0;
  width: 200%;
  height: 200%;
  transform: scale(0.5);
  transform-origin: top left;
}
/* タイル画像。中心をサムネイルの中央に寄せるため left / top を JS で付ける */
.basemap-card-thumb img {
  position: absolute;
  width: 256px;
  height: 256px;
  max-width: none;
}
.basemap-card-check {
  position: absolute;
  top: 2px;
  right: 2px;
  font-size: var(--icon-md);
  color: var(--primary);
  background: #fff;
  border-radius: 50%;
  line-height: 1;
  display: none;
}
.basemap-card-name {
  font-size: var(--fs-caption);
  line-height: 1.25;
  text-align: center;
  word-break: break-word;
}
.basemap-card:hover  .basemap-card-thumb { border-color: var(--gray-400); }
.basemap-card:focus-visible .basemap-card-thumb { outline: 2px solid var(--primary); outline-offset: 1px; }
.basemap-card.active .basemap-card-thumb { border-color: var(--primary); }
.basemap-card.active .basemap-card-check { display: block; }
.basemap-card.active .basemap-card-name  { color: var(--primary); font-weight: 600; }

/* 2画面表示のときだけ、各画面の下中央に「どちらの地図か」を出す。
   ツールバーの「地図の種類」が変えるのは左の地図なので、
   2画面では画面ごとのラベルを主な入口にする（描画は js/gis-toolbar.js）。 */
.basemap-label {
  position: absolute;
  /* 検索バー（高さ40px・上から8px）の真下。画面下端は座標表示・縮尺・
     出典表記・全体図・拡大縮小ボタンで埋まっており置き場所がない */
  top: 56px;
  z-index: 1200;
  display: none;              /* 2画面表示のときだけ出す */
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  font-family: var(--font);
  font-size: var(--fs-caption);
  color: var(--gray-700);
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--gray-300);
  border-radius: 4px;
  box-shadow: var(--shadow);
  cursor: pointer;
}
/* 幅の上限。左は仕切りを越えないように、右は右上のツールバーに
   届かないように抑える。ツールバーの幅は文字サイズで変わるため実測値を使う。
   入りきらない地図名は省略表示になるが、ピッカーには全文が出る。 */
#basemap-label-1 { left: 10px;               max-width: calc(50% - 24px); }
#basemap-label-2 { left: calc(50% + 12px);   max-width: calc(50% - var(--toolbar-w, 86px) - 32px); }
/* スマホでは幅が足りないのでサムネイルを省き、地図名の表示に幅を回す */
@media (max-width: 640px) {
  .basemap-label-thumb { display: none; }
}
body.split-active .basemap-label { display: inline-flex; }
.basemap-label:hover { background: #fff; border-color: var(--primary); }
.basemap-label:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
/* 「左の地図」「右の地図」の見出し。色を付けて画面との対応を分かりやすくする */
.basemap-label-side {
  flex-shrink: 0;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}
.basemap-label-thumb {
  width: 22px;
  height: 16px;
  object-fit: cover;
  border-radius: 2px;
  flex-shrink: 0;
}
.basemap-label-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 右画面用のピッカー。2画面表示のときだけ使う。
   ここの値は初期位置で、実際にはラベルの真下へ js/gis-toolbar.js が合わせる
   （文字サイズや言語でラベルの大きさが変わるため実測している）。 */
#basemap-switcher-2 {
  position: absolute;
  top: 88px;
  left: calc(50% + 12px);
  /* Leaflet の地図ペイン（z-index 200〜700）より前に出す。
     指定を忘れると地図タイルの下に隠れて開いていないように見える */
  z-index: 1200;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  display: none;
}
#basemap-switcher-2.visible { display: grid; }

