/* multiple_point_map — スマホ縦画面ファースト(設計書 §4) */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic UI", Meiryo, sans-serif;
  font-size: 16px;
  color: #202124;
  background: #fff;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

/* ---------- 地図(画面の残り全部) ---------- */

#map-container {
  position: relative;
  flex: 1;
  min-height: 0;
  /* 地図内部の z-index(選択マーカー強調の最大1000)を閉じ込める stacking context を作り、
     シート・ダイアログ等(z-index 30〜)より下に保つ */
  z-index: 0;
}

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

/* ---------- 移動手段セグメント(U8・§4.6) ---------- */

/* 地図右上に重ねる小型セグメント。左上はズームコントロールが使うため右上に配置(§4.1) */
#travel-mode {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top));
  right: 10px;
  z-index: 1100; /* 地図コントロール・選択マーカー(z-index 1000)より上 */
  display: flex;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}

.tm-btn {
  min-height: 40px; /* タップ領域 40px 以上(§4.1) */
  padding: 0 10px;
  border: none;
  background: #fff;
  font-size: 13px;
  font-weight: bold;
  color: #5f6368;
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation; /* iOS Safari の連続タップでダブルタップズームを防ぐ(U8) */
}

.tm-btn + .tm-btn {
  border-left: 1px solid #f1f3f4;
}

.tm-btn.active {
  background: #1a73e8;
  color: #fff;
}

.tm-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

/* U12: 徒歩・自転車の無効表示(グレーアウト)。native disabled は使わず(タップで
   ベータ案内を出すため §12.4)、クラスで見た目だけ無効化する。active(車)には付かない */
.tm-btn--disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* U12: ベータ案内の常設キャプション(#travel-mode 直下・控えめ表示 §12.4)。
   right 揃えで travel-mode の直下に小さく置く。pointer-events: none で地図操作を妨げない */
#travel-mode-note {
  position: absolute;
  top: calc(54px + env(safe-area-inset-top));
  right: 10px;
  z-index: 1100;
  max-width: 190px;
  padding: 2px 7px;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 6px;
  font-size: 11px;
  line-height: 1.35;
  color: #5f6368;
  text-align: right;
  pointer-events: none;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

/* ---------- 言語切り替え(U9・§4.7) ---------- */

/* #travel-mode(top 10px + 高さ40px)+ ベータ案内キャプション(U12)の直下・右端に縦積み。
   U12 でベータ案内(最大2〜3行)を挟むぶん下げる。attribution(右下)とは重ならない */
#lang-control {
  position: absolute;
  top: calc(108px + env(safe-area-inset-top));
  right: 10px;
  z-index: 1100; /* 地図コントロール・選択マーカー(z-index 1000)より上 */
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

#lang-btn {
  width: 40px;
  height: 40px; /* タップ領域 40px 以上(§4.1) */
  border: none;
  border-radius: 8px;
  background: #fff;
  font-size: 20px;
  line-height: 1;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  touch-action: manipulation;
}

#lang-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

#lang-menu {
  margin-top: 6px;
  min-width: 132px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}

.lang-item {
  position: relative;
  display: block;
  width: 100%;
  min-height: 40px;
  padding: 0 14px 0 32px; /* 左は ✓ マークの分を常に確保(選択切替でズレない) */
  border: none;
  background: #fff;
  font-size: 14px;
  color: #202124;
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
}

.lang-item + .lang-item {
  border-top: 1px solid #f1f3f4;
}

.lang-item:disabled {
  opacity: 0.4;
  cursor: default;
}

.lang-item.active {
  color: #1a73e8;
  font-weight: bold;
}

.lang-item.active::before {
  content: "✓";
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
}

/* ---------- CSS 製ピンマーカー(§2.2・§11.1)。番号・S/G・選択強調はクラスで表現 ---------- */

/* MapLibre Marker のラッパ要素(maplibregl-marker クラスは MapLibre が付与)。
   仮マーカーは JS 側で pointer-events: none を指定する(U10-③) */
.mpm-marker {
  cursor: pointer;
}

.mpm-pin {
  position: relative;
  width: 34px;
  height: 46px;
}

/* ティアドロップ形のピン本体(角丸正方形を45度回転) */
.mpm-pin::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 2px;
  width: 30px;
  height: 30px;
  margin-left: -15px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  background: #1a73e8;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.mpm-pin-label {
  position: absolute;
  left: 0;
  top: 9px;
  width: 34px;
  text-align: center;
  color: #fff;
  font-size: 13px;
  font-weight: bold;
  line-height: 1;
  pointer-events: none;
}

/* U6: S(緑)/ G(赤)バッジ */
.mpm-pin-start::before {
  background: #188038;
}

.mpm-pin-goal::before {
  background: #d93025;
}

/* 選択強調(黄色いリング) */
.mpm-pin-selected::before {
  box-shadow: 0 0 0 3px #fbbc04, 0 1px 4px rgba(0, 0, 0, 0.4);
}

/* U10-③: 地図タップ直後の仮マーカー(半透明+破線。登録前のプレビュー表示) */
.mpm-pin--temp {
  opacity: 0.65;
}

.mpm-pin--temp::before {
  background: #5f6368;
  border: 2px dashed #fff;
}

/* ---------- 共通: 入力欄・ボタン ---------- */

input[type="text"] {
  width: 100%;
  height: 48px;
  padding: 0 12px;
  border: 1px solid #dadce0;
  border-radius: 8px;
  font-size: 16px; /* iOS のズーム防止のため 16px 以上 */
  background: #fff;
}

input[type="text"]:focus {
  outline: 2px solid #1a73e8;
  border-color: transparent;
}

.btn {
  display: inline-block;
  width: 100%;
  height: 48px;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
}

.btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.btn-primary {
  background: #1a73e8;
  color: #fff;
}

.btn-secondary {
  background: #f1f3f4;
  color: #202124;
}

.btn-danger-outline {
  background: #fff;
  color: #d93025;
  border: 1px solid #d93025;
}

/* ---------- ポイントリスト(§4.1) ---------- */

#point-panel {
  flex: none;
  max-height: 30vh;
  display: flex;
  flex-direction: column;
  border-top: 1px solid #dadce0;
  background: #fff;
}

#list-toggle {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 10px 16px;
  border: none;
  background: #f8f9fa;
  font-size: 14px;
  font-weight: bold;
  color: #202124;
  cursor: pointer;
}

#list-toggle .caret {
  transition: transform 0.2s;
}

#point-panel.collapsed #list-toggle .caret {
  transform: rotate(180deg);
}

#point-panel.collapsed #point-list,
#point-panel.collapsed .panel-actions {
  display: none;
}

#point-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  list-style: none;
}

#point-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid #f1f3f4;
  font-size: 14px;
  cursor: pointer;
}

#point-list li.selected {
  background: #e8f0fe;
}

#point-list .badge {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #dadce0;
  color: #202124;
  font-size: 12px;
  font-weight: bold;
}

#point-list .badge.ordered {
  background: #1a73e8;
  color: #fff;
}

#point-list .label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.panel-actions {
  flex: none;
  padding: 8px 16px;
  border-top: 1px solid #f1f3f4;
}

.panel-actions .btn {
  height: 40px;
  font-size: 14px;
}

/* ---------- スタート/ゴール指定(U6) ---------- */

/* リスト行頭の S / G バッジ */
#point-list .sg-badge {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  color: #fff;
  font-size: 11px;
  font-weight: bold;
}

#point-list .sg-badge.sg-s {
  background: #188038;
}

#point-list .sg-badge.sg-g {
  background: #d93025;
}

/* 「スタートに設定」「ゴールに設定」ボタン(選択中のみ活性) */
.sg-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.sg-row .btn {
  flex: 1;
  padding: 0 4px;
  font-size: 13px;
}

.btn-sg-start {
  background: #fff;
  color: #188038;
  border: 1px solid #188038;
}

.btn-sg-goal {
  background: #fff;
  color: #d93025;
  border: 1px solid #d93025;
}

/* ---------- ボタンバー(§4.1) ---------- */

#button-bar {
  flex: none;
  display: flex;
  border-top: 1px solid #dadce0;
  background: #fff;
  padding-bottom: env(safe-area-inset-bottom);
}

.bar-btn {
  flex: 1;
  height: 56px;
  border: none;
  background: #fff;
  font-size: 15px;
  font-weight: bold;
  color: #1a73e8;
  cursor: pointer;
}

.bar-btn + .bar-btn {
  border-left: 1px solid #f1f3f4;
}

.bar-btn:active {
  background: #f1f3f4;
}

.bar-btn:disabled {
  opacity: 0.4;
}

.bar-btn-danger {
  color: #d93025;
}

/* ---------- オーバーレイ共通 ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
}

#sheet-overlay {
  z-index: 30;
}

#confirm-overlay {
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

/* U12: ORS キーダイアログ(#orskey-*)のスタイルは削除(完全キー不要化 §12.7) */

/* ---------- 住所入力シート(§5) ---------- */

#sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  background: #fff;
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.2);
  transform: translateY(100%);
  transition: transform 0.25s ease;
  padding-bottom: env(safe-area-inset-bottom);
}

#sheet.open {
  transform: translateY(0);
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  font-weight: bold;
  border-bottom: 1px solid #f1f3f4;
}

#sheet-close {
  border: none;
  background: none;
  font-size: 24px;
  line-height: 1;
  width: 40px;
  height: 40px;
  margin: -8px -8px -8px 0;
  color: #5f6368;
  cursor: pointer;
}

.sheet-body {
  padding: 12px 16px 20px;
}

.section-label {
  font-size: 13px;
  color: #5f6368;
  margin: 10px 0 8px;
  text-align: center;
}

#btn-register {
  margin-top: 10px;
}

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

.zip-row input {
  flex: 1;
  min-width: 0;
}

.zip-row .btn {
  flex: none;
  width: auto;
  padding: 0 14px;
  font-size: 14px;
}

.hint {
  font-size: 12px;
  color: #5f6368;
  margin-top: 8px;
  line-height: 1.6;
}

/* ---------- 施設・住所検索(U7・ボタン起動型) ---------- */

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

.search-row input {
  flex: 1;
  min-width: 0;
}

.search-row .btn {
  flex: none;
  width: auto;
  padding: 0 18px;
  font-size: 14px;
}

/* 検索候補リスト(最大5件。タップで即登録 §5.1) */
#search-results {
  list-style: none;
  margin-top: 8px;
  border: 1px solid #dadce0;
  border-radius: 8px;
  max-height: 180px;
  overflow-y: auto;
}

#search-results .search-item {
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.5;
  cursor: pointer;
}

#search-results .search-item + .search-item {
  border-top: 1px solid #f1f3f4;
}

#search-results .search-item:active {
  background: #e8f0fe;
}

#search-results .search-empty {
  padding: 10px 12px;
  font-size: 13px;
  color: #5f6368;
}

/* ---------- 確認ダイアログ(§4.4・§6) ---------- */

#confirm-dialog {
  width: 100%;
  max-width: 360px;
  background: #fff;
  border-radius: 12px;
  padding: 20px 16px 16px;
}

#confirm-message {
  font-size: 15px;
  line-height: 1.7;
  margin-bottom: 20px;
  white-space: pre-line;
  word-break: break-all;
}

.confirm-actions {
  display: flex;
  gap: 10px;
}

.confirm-actions .btn {
  flex: 1;
}

/* ---------- トースト(§7) ---------- */

#toast {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  max-width: calc(100% - 32px);
  padding: 12px 18px;
  border-radius: 8px;
  color: #fff;
  font-size: 14px;
  line-height: 1.5;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  animation: toast-in 0.2s ease;
}

#toast.error {
  background: #d93025;
}

#toast.success {
  background: #188038;
}

/* U12: 情報系(ベータ案内など)。エラー(赤)ではない中立色 */
#toast.info {
  background: #5f6368;
}

/* U13: アクションボタン付きトースト(地図タップ即登録の「取り消す」)。
   メッセージとボタンを横並びにする。ボタンはタップしやすく・目立ちすぎない半透明 */
#toast.action {
  display: flex;
  align-items: center;
  gap: 12px;
}

#toast .toast-msg {
  flex: 1 1 auto;
  min-width: 0;
}

#toast .toast-action {
  flex: none;
  min-height: 32px;
  padding: 6px 14px;
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

#toast .toast-action:active {
  background: rgba(255, 255, 255, 0.34);
}

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, -8px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------- 通信中スピナー ---------- */

#busy-spinner {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 70;
  width: 36px;
  height: 36px;
  margin: -18px 0 0 -18px;
  border: 4px solid rgba(26, 115, 232, 0.25);
  border-top-color: #1a73e8;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* PC など横幅が広い場合もレイアウトはそのまま(縦持ち前提のシンプル構成) */
@media (min-width: 600px) {
  #sheet,
  #confirm-dialog {
    max-width: 480px;
  }
  #sheet {
    left: 50%;
    right: auto;
    width: 480px;
    transform: translate(-50%, 100%);
  }
  #sheet.open {
    transform: translate(-50%, 0);
  }
}
