:root {
  --brand: #009E96;
  /* ヘッダー色 */
  --mode-btn: #263E8B;
  /* 選択モード&DLボタン色 */
}

/* ===== ベース ===== */
html,
body {
  height: 100%;
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans JP", sans-serif;
}

/* ===== レイアウト：ヘッダー + 本体（サイド + 地図） ===== */
#root {
  display: grid;
  grid-template-rows: 48px 1fr;
  /* ヘッダーは常に48px固定 */
  height: 100vh;
}

/* ---- ヘッダー ---- */
#header {
  height: 48px;
  /* 元の高さに固定 */
  min-height: 48px;
  padding: 0 12px;
  /* 上下は0にして実高さが増えないように */
  display: flex;
  align-items: center;
  /* 縦中央 */
  justify-content: flex-end;
  /* 右端にメニューボタン */
  background: var(--brand);
  color: #fff;
  position: relative;
  z-index: 20000 !important;
}

/* タイトル＋ロゴは“48pxの中で”常に中央に */
#titleWrap {
  position: absolute;
  left: 50%;
  top: 0;
  height: 48px;
  /* ヘッダーと同じ高さ */
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  /* 縦中央 */
  gap: 10px;
  white-space: nowrap;
  z-index: 20005 !important;
}

#title {
  font-weight: 700;
  letter-spacing: .5px;
}

#logo {
  height: 28px;
  width: auto;
  display: block;
}

/* ハンバーガーメニュー（角丸→角張りへ） */
#menuBtn {
  appearance: none;
  border: 0;
  background: transparent;
  color: #fff;
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 0;
  /* フラット */
  display: grid;
  place-items: center;
}

#menuBtn:hover {
  background: rgba(255, 255, 255, .12);
}

.hamburger,
.hamburger::before,
.hamburger::after {
  content: "";
  display: block;
  width: 18px;
  height: 2px;
  background: #fff;
  border-radius: 1px;
  position: relative;
}

.hamburger::before {
  position: absolute;
  transform: translateY(-6px);
}

.hamburger::after {
  position: absolute;
  transform: translateY(6px);
}

/* ドロップダウンメニュー */
#menu {
  position: absolute;
  right: 0;
  top: 48px;
  /* ヘッダーの下端に揃える */
  background: #fff;
  color: #333;
  border: 1px solid #ddd;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .12);
  min-width: 180px;
  display: none;
  z-index: 20010 !important;
}

#menu.open {
  display: block;
}

#menu a {
  display: block;
  padding: 10px 14px;
  text-decoration: none;
  color: #111;
  font-size: 14px;
}

#menu a+a {
  border-top: 1px solid #ddd;
}

/* ---- 本体（左メニュー + 地図） ---- */
#app {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: 100%;
}

/* 左メニュー */
aside {
  display: flex;
  flex-direction: column;
  padding: 14px 12px 12px;
  border-right: 1px solid #ddd;
  background: #ECF3F3;
  min-height: 0;
  /* 子要素のスクロールが効くように */
  height: 100%;
  /* 行いっぱい */
}

/* インラインheightが残っていても無効化（はみ出し防止） */
#selectedPanel {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  /* ← これが重要（内側のflex子が縮める） */
  height: auto !important;
}

aside section>div:first-child {
  font-weight: 800;
  color: #0f172a;
}

/* サマリー行 */
.summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
  margin-bottom: 6px;
  flex: 0 0 auto;
  flex-wrap: nowrap;
  white-space: nowrap;
}

#selectedSummary {
  font-size: 12px;
  color: #444;
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 選択リスト領域（DLボタンに重ならないよう余白） */
#addrArea {
  flex: 1 1 auto;
  /* ← 残り高さを使用（可変） */
  display: flex;
  flex-direction: column;
  min-height: 120px;
  margin-top: 6px;
  margin-bottom: 8px;
  /* DLボタンと重ならない */
  min-height: 0;
  /* 内側スクロール許可 */
}

/* 外側ラッパー（選択リストの外枠） */
#addrListWrapper {
  /* サイズ＆はみ出し対策 */
  box-sizing: border-box;
  /* ← これを追加！ */
  width: 100%;
  max-width: 100%;
  min-width: 0;
  /* flex の最小幅問題対策 */
  min-height: 64px !important;
  height: 100px;
  /* 初期高さ（可変） */

  /* スクロール */
  overflow-y: auto !important;
  overflow-x: hidden;

  /* 枠線（inline styleに勝つ） */
  border: 1px solid #e3e8f0 !important;
  border-bottom: none !important;
  /* DLボタン直上の線を消す */
  border-radius: 0 !important;

  /* 背景 */
  background: #fff;

  /* 左右均等の余白 */
  padding: 6px 8px !important;
}


/* 選択リスト（可変・スクロール：内側は枠なし） */
#selectedList {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: 100%;
  /* ラッパー（240px）に合わせる */
  overflow-y: auto;
  /* 中身が増えたら縦スクロール */
  overflow-x: hidden;
  /* 横方向は固定 */
}

/* リスト項目の中で長い名称が来ても横に広がらないように折り返す */
.sel-item {
  min-width: 0;
}

.sel-name {
  font-size: 13px;
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

#selectedList .sel-meta {
  font-size: 9px !important;
  color: #666 !important;
}

.sel-item:hover {
  background: #f0f6ff;
}

.sel-badge {
  width: 18px;
  text-align: center;
}

.sel-meta {
  color: #666;
  font-size: 11px;
}

.danger {
  color: #c5332b !important;
  font-weight: 600;
}

/* DLボタン行（常に下に固定される領域） */
#downloadArea {
  flex: 0 0 auto;
  /* ← 伸縮しない */
  margin-top: 8px;
  border-top: none;
  padding-top: 0;
  background: transparent;
}

/* ===== ボタン（フラット角張りデザインで統一） ===== */
button {
  height: 32px;
  padding: 0 12px;
  border-radius: 0;
  /* ← 角丸なし */
  border: 1px solid #ccd3e0;
  background: #fff;
  cursor: pointer;
  box-shadow: none;
}

button:disabled {
  opacity: .6;
  cursor: not-allowed;
}

/* 小ボタン（全解除） */
#btnClearSelection {
  height: 28px;
  padding: 0 12px;
  font-weight: 600;
  flex: 0 0 auto;
}

/* 大ボタン（ダウンロード） */
#btnDownload {
  width: 100%;
  height: 56px;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: .3px;
  background: var(--mode-btn);
  border: 1px solid var(--mode-btn);
  color: #fff;
  margin-bottom: 8px;
  border-radius: 0;
  /* ← 角丸なし */
}

#btnDownload:hover:enabled {
  filter: brightness(1.03);
}

#btnDownload:disabled {
  opacity: .55;
}

/* ---- モード切替（四角い2分割タブ） ---- */
.mode-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
}

.mode-tabs {
  display: flex;
  border: 1px solid var(--mode-btn);
  border-radius: 0;
  /* ← 角丸なし */
  overflow: hidden;
  background: #fff;
}

.mode-tabs .mode-btn {
  flex: 1;
  height: 36px;
  border: none;
  background: #fff;
  color: var(--mode-btn);
  font-weight: 700;
  border-right: 1px solid var(--mode-btn);
  border-radius: 0;
  /* ← 角丸なし */
}

.mode-tabs .mode-btn:last-child {
  border-right: none;
}

.mode-tabs .mode-btn.active {
  background: var(--mode-btn);
  color: #fff;
}

.mode-note {
  font-size: 11px;
  color: #667085;
}

/* ---- 地図領域 ---- */
#ZMap {
  width: 100%;
  height: 100%;
  position: relative;
}

/* 地図左上の住所検索オーバーレイ（角張り） */
#mapSearch {
  position: absolute;
  left: 12px;
  top: 12px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 0;
  padding: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .12);
  z-index: 10000;
  width: 360px;
  pointer-events: auto;
}

#mapSearch .row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.input-wrap {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  max-width: calc(100% - 78px);
}

#addr {
  width: 100%;
  height: 32px;
  box-sizing: border-box;
  padding: 0 34px 0 10px;
  border: 1px solid #cbd5e1;
}

#addrClear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  border: none;
  background: transparent;
  color: #9aa3b2;
  font-size: 16px;
  line-height: 22px;
  text-align: center;
  border-radius: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

#addrClear:hover {
  background: #f1f5f9;
}

#btnSearch {
  height: 32px;
  flex: 0 0 72px;
}

#addrMsg {
  font-size: 11px;
  color: #a00;
  margin-top: 4px;
}

/* 住所候補リスト：画面拡大でも伸びない（上限固定） */
.addr-list {
  margin-top: 6px;
  border: 1px solid #e5e7eb;
  max-height: 240px !important;
  /* ← 伸ばさないため固定上限 */
  height: auto !important;
  overflow: auto;
  padding: 0;
  list-style: none;
  display: none;
  border-radius: 0;
  background: #fff;
}

.addr-item {
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid #f1f5f9;
}

.addr-item:hover {
  background: #f3f6ff;
}

.addr-sub {
  color: #666;
  font-size: 11px;
}

/* ---- モーダル ---- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(0, 0, 0, .45);
  z-index: 2147483000;
}

.modal-backdrop.open {
  display: grid;
}

.modal {
  position: relative;
  width: min(520px, calc(100% - 32px));
  background: #fff;
  border-radius: 0;
  /* 角張り */
  box-shadow: 0 10px 30px rgba(0, 0, 0, .22);
  padding: 6px 16px 16px;
}

.modal h3 {
  margin: 0 0 14px;
  font-size: 16px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

.modal button {
  height: 32px;
  padding: 0 14px;
  border-radius: 0;
}

.modal-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  border-radius: 0;
  border: 1px solid #e5e7eb;
  background: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: #444;
}

.modal-close:hover {
  background: #f8fafc;
}


/* === ページ外側のスクロールを無効化（中だけスクロール） === */
html,
body {
  overflow: hidden !important;
}

/* 左メニューは外側にスクロールを出さない */
aside {
  overflow: hidden !important;
}

/* 可変エリアがちゃんと縮めるように */
#selectedPanel,
#addrArea {
  min-height: 0 !important;
}

/* リスト本体は枠ナシ＆可変 */
#selectedList {
  height: auto !important;
  flex: 1 1 auto !important;
  overflow-y: auto !important;
  border: none !important;
  min-height: 64px !important;
  /* ここも縮む余地を確保 */
}

/* ダウンロードエリアは常に下。線は完全に消す（インラインに勝つ） */
#downloadArea {
  flex: 0 0 auto !important;
  border-top: none !important;
  /* ← 線を消す */
  padding-top: 0 !important;
  background: transparent !important;
  padding-bottom: 5px !important;
}

.addr-list,
#addrList {
  max-height: 240px !important;
  /* お好みで数値調整可 */
  height: auto !important;
  overflow-y: auto !important;
}

/* 検索入力のネイティブ取消ボタン(青い×)を消す：Chrome/Edge/Safari */
#addr::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}

/* 旧Edge/IE系 */
#addr::-ms-clear {
  display: none;
  width: 0;
  height: 0;
}

/* モード説明 */
.mode-note {
  margin-top: 6px;
  font-size: 12px;
  line-height: 1.4;
  color: #6b7280;
  /* 灰色 */
}

/* ===== プレビューボタン ===== */
#btnPreview {
  height: 28px;
  padding: 0 12px;
  font-weight: 600;
  flex: 0 0 auto;
  background: #263E8B;
  border: 1px solid #263E8B;
  color: #ffffff;
}

#btnPreview:disabled {
  opacity: .6;
}

#btnPreview:hover:enabled {
  filter: brightness(1.03);
}

/* ===== プレビューモーダル ===== */
.modal-xl {
  width: min(1100px, calc(100vw - 80px));
  max-width: 100%;
}

.viewerWrap {
  position: relative;
  width: 100%;
  height: min(78vh, 820px);
  background: #222;
  border: 1px solid #1f2937;
}

#previewFrame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: #000;
}

.preview-loader {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(20, 20, 20, .65);
  color: #e5e7eb;
  font-size: 13px;
  text-align: center;
  z-index: 2;
}

.preview-loader .spinner {
  width: 44px;
  height: 44px;
  border: 4px solid rgba(255, 255, 255, .25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .9s linear infinite;
  margin-bottom: 12px;
}

/* ▼ サマリー行を2段構成にする */
.summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  /* 右端寄せ */
  gap: 8px;
  margin-top: 8px;
  margin-bottom: 6px;
  flex: 0 0 auto;
  flex-wrap: nowrap;
  /* 折り返さない */
  white-space: nowrap;
  /* 1行維持 */
}

/* ボタンは1段目に並ぶ */
#btnPreview,
#btnClearSelection {
  order: 1;
}

/* 「選択数 / 合計サイズ」は2段目で全幅 */
#selectedSummary {
  flex: 1 1 auto;
  margin-top: 0;
  font-size: 12px;
  color: #444;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#previewModal .modal h3 {
  display: inline-flex;
  margin: 0;
  align-items: center;
}

/* タイトルを囲むラッパーを追加する前提 */
.preview-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  gap: 12px;
}

/* プレビュータイトルは幅を必要最小限に */
#previewTitle {
  flex: 0 0 auto;
}

/* プルダウンは右側で表示 */
.preview-select {
  flex: 0 0 260px;
  margin-left: auto;
}

/* プレビューモーダルの右上 要素間余白調整 */
.preview-title-row {
  padding-right: 40px;
  /* ×ボタンとセレクトが被らないよう余白追加 */
}

/* セレクトと×ボタンの視覚的余白も少し強化 */
.preview-select {
  margin-right: 6px;
}

/* タイトルを大きめにして存在感アップ */
#previewTitle {
  font-size: 18px;
  font-weight: 700;
  line-height: 32px;
  height: 32px;
  display: flex;
  align-items: center;
}

/* セレクトボックスを×と並んだ時に負けないサイズへ */
.preview-select {
  height: 32px;
  font-size: 14px;
  padding: 0 12px;
  border: 1px solid #a0a4ac;
  border-radius: 2px;
  /* ほんの少しだけ丸み */
}

/* ===== プレビューヘッダーを上下中央に揃える ===== */
.preview-title-row {
  position: relative;
  /* ← ×ボタンの基準 */
  display: flex;
  align-items: center;
  /* タイトルとセレクトを縦中央 */
  gap: 16px;
  padding-right: 56px;
  /* ×ボタン分の余白を少し広めに */
  min-height: 40px;
  /* 行に高さを与えて安定させる */
}

/* タイトルは32px行高で中央 */
#previewTitle {
  font-size: 18px;
  font-weight: 700;
  line-height: 32px;
  height: 32px;
  display: flex;
  align-items: center;
}

/* セレクトも32pxで中央 */
.preview-select {
  height: 32px;
  font-size: 14px;
  padding: 0 12px;
  border: 1px solid #a0a4ac;
  border-radius: 2px;
  margin-left: auto;
  /* 右寄せ（タイトルの右端に寄る） */
}

/* ×ボタンをヘッダー行の縦中央に */
#previewModal .modal .modal-close#previewClose {
  position: absolute;
  /* .preview-title-row を基準に */
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  /* 縦中央 */
  width: 30px;
  height: 30px;
  line-height: 30px;
}


@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}