/* ========================================
   公開型GIS スタイル : ベース（変数・アクセシビリティ・ヘッダー・レイアウト・サイドバー・文字サイズ・各パネル）
   （読み込み順が適用順です。index.html / survey/index.html の
     link 順を入れ替えると見た目が変わります）
   ======================================== */
/* ========================================
   公開型GIS - メインスタイル
   ======================================== */

:root {
  --primary: #1a56db;
  --primary-dark: #1e429f;
  --primary-light: #e8f0fe;
  --secondary: #057a55;
  --danger: #c81e1e;
  --warning: #b45309;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-700: #374151;
  --gray-900: #111827;
  --sidebar-width: 320px;
  --header-height: 52px;
  /* 管理者プレビューの帯（js/gis-preview.js）の高さ。帯は position:fixed で
     ヘッダーの直下に出るため、これを足さないとサイドバーや地図に重なる。
     実際の高さ（文字サイズ・言語・画面幅で折り返すと変わる）は gis-preview.js が入れる */
  --preview-banner-height: 0px;
  --content-top: calc(var(--header-height) + var(--preview-banner-height));
  --toolbar-height: 44px;
  --font: 'Hiragino Kaku Gothic ProN', 'Meiryo', 'Yu Gothic', sans-serif;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.15);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* ========================================
   アクセシビリティ基本
   ======================================== */

/* スクリーンリーダー専用（視覚的に非表示） */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* スキップリンク */
.skip-link {
  position: absolute;
  top: -100%;
  left: 8px;
  z-index: 99999;
  background: var(--primary);
  color: #fff;
  padding: 8px 16px;
  border-radius: 0 0 var(--radius) var(--radius);
  font-size: var(--fs-body);
  font-weight: 600;
  text-decoration: none;
  transition: top 0.15s;
}
.skip-link:focus {
  top: 0;
}

/* フォーカスリング（キーボード操作時のみ表示） */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
/* マウス操作時はアウトライン非表示 */
:focus:not(:focus-visible) {
  outline: none;
}

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: var(--fs-body);
  color: var(--gray-900);
  overflow: hidden;
}

/* ========================================
   Header
   ======================================== */
#header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-height);
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  z-index: 1000;
  box-shadow: var(--shadow);
}

#header-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: var(--fs-subhead);
  white-space: nowrap;
  /* ヘッダーは高さ固定の1行。幅が足りないときは、まずこの見出しから詰めて
     操作系（言語切替・文字サイズ切替）を画面内に残す。
     min-width:0 がないと flex 既定の min-width:auto で縮まず、あふれた分が
     そのまま画面外に出る（#header は overflow:visible なのでスクロールもしない）。 */
  min-width: 0;
  flex-shrink: 100;
}

#header-title #app-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

#header-title #app-logo { flex-shrink: 0; }

#header-title .subtitle {
  font-weight: 400;
  font-size: var(--fs-caption);
  opacity: 0.8;
  display: none;
}

@media (min-width: 600px) {
  #header-title .subtitle { display: inline; }
}

#header-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.header-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  text-decoration: none;   /* <a> をボタンとして使う場合の下線を消す */
  padding: 6px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: var(--fs-caption);
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  transition: background 0.15s;
  font-family: var(--font);
  flex-shrink: 0;
}
.header-btn:hover { background: rgba(255,255,255,0.25); }
.header-btn .label { display: none; }
@media (min-width: 640px) { .header-btn .label { display: inline; } }

/* ========================================
   Layout
   ======================================== */
#app {
  position: fixed;
  top: var(--content-top);
  left: 0; right: 0; bottom: 0;
  display: flex;
}

/* ========================================
   Sidebar
   ======================================== */
#sidebar {
  width: var(--sidebar-width);
  background: #fff;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--gray-200);
  z-index: 500;
  transition: transform 0.25s ease;
  position: relative;
  flex-shrink: 0;
}

#sidebar.collapsed {
  transform: translateX(calc(-1 * var(--sidebar-width)));
  position: absolute;
  top: 0; bottom: 0;
}

#sidebar-toggle {
  position: absolute;
  right: -32px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 52px;
  background: #fff;
  border: 1px solid var(--gray-200);
  border-left: none;
  border-radius: 0 var(--radius) var(--radius) 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-500);
  box-shadow: 2px 0 4px rgba(0,0,0,0.08);
  z-index: 501;
}
#sidebar-toggle:hover { background: var(--gray-50); }

#sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--gray-200);
  flex-shrink: 0;
}

.sidebar-tab {
  flex: 1;
  min-width: 0;
  padding: 10px 2px;
  border: none;
  background: none;
  cursor: pointer;
  /* タブ名が折り返さないよう文字を詰める（文字サイズ切替時は body.fs-* で上書き） */
  font-size: var(--fs-caption);
  white-space: nowrap;
  letter-spacing: -0.02em;
  color: var(--gray-500);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
  font-family: var(--font);
  position: relative;
}
.sidebar-tab:hover { background: var(--gray-50); color: var(--primary); }
.sidebar-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  background: var(--primary-light);
}
/* 言語切替 */
#lang-switch {
  margin-left: 6px;
  padding: 5px 6px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-family: var(--font);
  font-size: var(--fs-caption);
  min-height: 32px;
  cursor: pointer;
  /* 幅は option の最長文字列（やさしい日本語）で決まり、標準でも118pxを占める。
     ヘッダーで唯一縮めてよい要素なので、足りない分はここで吸収させる。 */
  min-width: 0;
  flex-shrink: 1;
}
#lang-switch option { color: var(--gray-900); background: #fff; }

/* ========================================
   文字サイズ切替（標準 / 大 / 特大）
   ======================================== */
#font-size-switch {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: 6px;
  padding: 2px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  /* アクセシビリティ機能なので、幅が足りなくてもここは縮めない・追い出さない。 */
  flex-shrink: 0;
}
#font-size-switch .fs-label {
  font-size: var(--fs-caption);
  color: rgba(255, 255, 255, 0.85);
  padding: 0 4px;
}
.fs-btn {
  border: none;
  background: none;
  color: #fff;
  font-family: var(--font);
  font-size: var(--fs-caption);
  padding: 5px 7px;
  min-height: 28px;
  border-radius: 4px;
  cursor: pointer;
}
.fs-btn:hover { background: rgba(255, 255, 255, 0.2); }
.fs-btn.active { background: #fff; color: var(--primary); font-weight: 700; }

/* 拡大は css/type-scale.css の --fs-mult が段ごとに行う。
   かつてここには基準値を手計算した固定値（18.9px など）が並んでいたが、
   段がすべて変数になったので削除した。文字サイズを変えたいときは
   type-scale.css の6段だけを見ればよい。

   残しているのは、拡大したときにしか要らないレイアウト側の調整。 */

/* 文字を大きくすると1行に収まらないため、タブ名は折り返しを許可する */
body.fs-large .sidebar-tab, body.fs-xlarge .sidebar-tab { white-space: normal; }

@media (max-width: 640px) {
  #font-size-switch .fs-label { display: none; }
  /* 幅を詰めるのは padding だけにする。ここだけ 10px にしていたが、
     文字サイズ切替ボタン自身が読みにくくては本末転倒なので段に戻した。 */
  .fs-btn { padding: 5px 5px; }

  #header { padding: 0 8px; gap: 6px; }
  /* 文字サイズを「大」「特大」にすると操作系の幅も広がる（ナビ全体で
     315→369→408px）。狭い画面では見出しの文字を省いてロゴ／アイコンだけ残し、
     操作系を画面内に収める。タイトルはタブ名とスタート画面にも出る。 */
  #header-title #app-title { display: none; }
  /* ロゴは #header-title の幅に合わせて縮める。flex-shrink:0 のままだと
     見出し側が縮んでもロゴだけ元の幅で残り、操作系に重なってしまう。
     ロゴを設定している市町村でだけ起きるので base では気付けない
     （大桑村・幅375pxで標準28px / 大84px / 特大90px 重なっていた）。
     overflow:hidden は最後の砦。どんな幅でもロゴが枠外へ出ないようにする。 */
  #header-title { overflow: hidden; }
  #header-title #app-logo {
    max-width: 96px;
    min-width: 0;
    flex-shrink: 1;
    object-fit: contain;
  }
  /* 文字を大きくすると操作系だけで幅を使い切る。縮んだロゴが数pxだけ
     残ると見た目のゴミになるので、この組み合わせでは消す。
     display ではなく max-width で消しているのは、img 側に
     style="display:none" が直書きされていて（表示は js/app.js が切り替える）
     インラインスタイルには CSS が勝てないため。
     ロゴは案内ページとスタート画面にも出る。 */
  body.fs-large  #header-title #app-logo,
  body.fs-xlarge #header-title #app-logo { max-width: 0; }
  /* option なりに広がるのを止める。閉じている間は選択中の言語名が省略され
     うるが、開いたときの一覧には全文が出る。 */
  #lang-switch { max-width: 6em; }
}

/* ヘッダー「お知らせ」ボタンの重要件数バッジ */
#notices-link { position: relative; }
.header-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  background: var(--danger);
  color: #fff;
  font-size: var(--fs-caption);
  line-height: 1.4;
  border-radius: 8px;
  padding: 0 4px;
  min-width: 15px;
  text-align: center;
}

.sidebar-tab .badge {
  position: absolute;
  top: 5px;
  right: 10px;
  background: var(--danger);
  color: #fff;
  font-size: var(--fs-caption);
  border-radius: 8px;
  padding: 1px 4px;
  min-width: 16px;
  text-align: center;
}

#sidebar-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ========================================
   Layers Panel
   ======================================== */
#panel-layers {
  padding: 0;
}

.layer-category {
  border-bottom: 1px solid var(--gray-200);
}

.layer-category-header {
  padding: 8px 12px;
  background: var(--gray-50);
  font-size: var(--fs-caption);
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.layer-category-header:hover { background: var(--gray-100); }

.layer-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--gray-100);
  cursor: pointer;
  transition: background 0.1s;
}
.layer-item:hover { background: var(--gray-50); }
.layer-item:last-child { border-bottom: none; }

.layer-visibility {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  border: 2px solid var(--gray-300);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
  transition: all 0.15s;
}
.layer-visibility.checked {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.layer-color-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1.5px solid rgba(0,0,0,0.15);
}
.layer-color-line {
  width: 20px;
  height: 4px;
  border-radius: 2px;
  flex-shrink: 0;
}

.layer-name {
  flex: 1;
  min-width: 0;
  font-size: var(--fs-body);
  color: var(--gray-700);
  /* 長いレイヤ名（ハザードマップ等）は省略（…）せず折り返して全文を表示する */
  overflow-wrap: anywhere;
  line-height: 1.4;
}

.layer-count {
  font-size: var(--fs-caption);
  color: var(--gray-400);
  flex-shrink: 0;
}

/* レイヤ行の「⋯」メニュー */
.layer-menu-btn {
  background: none;
  border: none;
  width: 28px;
  height: 28px;
  cursor: pointer;
  color: var(--gray-400);
  font-size: var(--icon-md);
  flex-shrink: 0;
  border-radius: 4px;
  line-height: 1;
}
.layer-menu-btn:hover,
.layer-menu-btn.active { color: var(--primary); background: var(--primary-light); }

.layer-menu {
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-100);
  padding: 4px 0;
}
.layer-menu [role="menuitem"] {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 38px;
  padding: 0 12px 0 40px;
  border: none;
  background: none;
  font-family: var(--font);
  font-size: var(--fs-body);
  color: var(--gray-700);
  cursor: pointer;
  text-align: left;
}
.layer-menu [role="menuitem"]:hover { background: var(--primary-light); color: var(--primary); }
.layer-menu [role="menuitem"] i { width: 14px; text-align: center; color: var(--gray-500); }
.layer-menu [role="menuitem"]:hover i { color: var(--primary); }

.layer-menu-opacity {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px 40px;
}
.layer-menu-opacity label { font-size: var(--fs-caption); color: var(--gray-700); flex-shrink: 0; }
.layer-menu-opacity input[type=range] { flex: 1; height: 4px; }

/* ========================================
   Legend Panel
   ======================================== */
#panel-legend { padding: 12px; }
.legend-section { margin-bottom: 16px; }
.legend-title { font-size: var(--fs-body); font-weight: 600; color: var(--gray-700); margin-bottom: 8px; }
.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.legend-symbol { width: 20px; flex-shrink: 0; }
.legend-symbol.circle {
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(0,0,0,0.2);
}
.legend-symbol.line { height: 3px; border-radius: 2px; }
.legend-symbol.polygon { height: 14px; border-radius: 2px; border: 1.5px solid rgba(0,0,0,0.2); }
.legend-label { font-size: var(--fs-caption); color: var(--gray-700); }

/* ========================================
   Search Panel
   ======================================== */
#panel-search { padding: 12px; }
.search-group { margin-bottom: 16px; }

/* 検索パネル内の各セクションをカード形式で区別 */
#panel-search .search-group {
  background: var(--gray-50, #f9fafb);
  border: 1px solid var(--gray-200, #e5e7eb);
  border-radius: var(--radius, 8px);
  padding: 10px 12px 12px;
  margin-bottom: 10px;
}
#panel-search .search-group:last-child { margin-bottom: 0; }

.search-group-title {
  font-size: var(--fs-caption);
  font-weight: 700;
  color: var(--primary, #1a56db);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--gray-200, #e5e7eb);
  letter-spacing: 0.02em;
}
.search-input-row {
  display: flex;
  gap: 6px;
}
.search-input-row input {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: var(--fs-body);
  font-family: var(--font);
  transition: border 0.15s;
}
.search-input-row input:focus-visible { outline: none; border-color: var(--primary); }
.search-results { margin-top: 8px; }
.search-result-item {
  padding: 8px 10px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  margin-bottom: 4px;
  cursor: pointer;
  font-size: var(--fs-body);
  transition: background 0.1s;
}
.search-result-item:hover { background: var(--primary-light); border-color: var(--primary); }
.search-result-item .name { font-weight: 500; color: var(--gray-900); }
.search-result-item .address { font-size: var(--fs-caption); color: var(--gray-500); margin-top: 2px; }

.latlng-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 6px;
}
.latlng-row input {
  padding: 8px 10px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: var(--fs-body);
  font-family: var(--font);
}
.latlng-row input:focus-visible { outline: none; border-color: var(--primary); }

/* ========================================
   Notices Panel
   ======================================== */
.notice-item {
  padding: 10px;
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
  margin-bottom: 8px;
  cursor: pointer;
  transition: background 0.1s;
}
.notice-item:hover { background: var(--gray-50); }
/* 「重要」はテキストのバッジ（.notice-important-badge）で示すので、
   枠の色帯は付けない（同じことを二重に言わない） */
.notice-item.important { border-color: var(--danger); }
.notice-item .notice-date { font-size: var(--fs-caption); color: var(--gray-400); margin-bottom: 3px; }
.notice-item .notice-title { font-size: var(--fs-body); font-weight: 600; color: var(--gray-900); }
.notice-item .notice-body { font-size: var(--fs-body); color: var(--gray-500); margin-top: 4px; line-height: 1.5; }
.notice-important-badge {
  display: inline-block;
  font-size: var(--fs-caption);
  background: var(--danger);
  color: #fff;
  padding: 1px 5px;
  border-radius: 3px;
  margin-right: 4px;
  vertical-align: middle;
}

