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

body {
  font-family: 'Segoe UI', 'Hiragino Sans', 'Meiryo', sans-serif;
  font-size: 14px;
  color: #333;
  height: 100dvh;
  overflow: hidden;
}

/* =====================
   ログイン画面
===================== */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100dvh;
  background: #f0f4f8;
}

#login-box {
  background: white;
  border-radius: 12px;
  padding: 36px 32px;
  text-align: center;
  box-shadow: 0 4px 20px rgba(0,0,0,0.1);
  width: 340px;
}

#login-logo {
  width: 100%;
  max-width: 280px;
  height: auto;
  display: block;
  margin: 0 auto 20px;
  /* 薄い白背景のJPEGロゴを白いカードに溶け込ませる（フチを消す） */
  mix-blend-mode: multiply;
}

#login-box h1 {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 24px;
  color: #1a3a5c;
  line-height: 1.4;
}

.login-input {
  width: 100%;
  box-sizing: border-box;
  padding: 11px 12px;
  margin-bottom: 10px;
  border: 1px solid #cfd8e3;
  border-radius: 6px;
  font-size: 16px;       /* iOSで16px未満だと自動ズームするため16pxに統一 */
}
.login-input:focus {
  outline: none;
  border-color: #378ADD;
  box-shadow: 0 0 0 2px rgba(55,138,221,0.15);
}

.login-btn {
  width: 100%;
  padding: 12px;
  background: #378ADD;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 4px;
}
.login-btn:hover { background: #2b6fb3; }

.login-link {
  width: 100%;
  background: none;
  border: none;
  color: #378ADD;
  font-size: 12px;
  cursor: pointer;
  margin-top: 12px;
  padding: 4px;
}
.login-link:hover { text-decoration: underline; }

/* =====================
   プロジェクト選択画面
===================== */
#project-screen {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: #f0f4f8;
}

#project-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: #1a3a5c;
  color: white;
}

#project-header h2 {
  font-size: 18px;
  font-weight: 600;
}

#project-list-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
}

.project-card {
  background: white;
  border-radius: 10px;
  padding: 16px 20px;
  margin-bottom: 10px;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
  border: 2px solid transparent;
  display: flex;
  align-items: center;
  gap: 12px;
}

.project-card:hover { border-color: #378ADD; }

.project-card-icon {
  width: 40px;
  height: 40px;
  background: #E6F1FB;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #1a3a5c;
  font-size: 20px;
  flex-shrink: 0;
}

.project-card-body { flex: 1; }

.project-card-name {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 3px;
}

.project-card-meta {
  font-size: 12px;
  color: #888;
}

.proj-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 6px;
  color: white;
  font-size: 13px;
  cursor: pointer;
}

.proj-btn:hover { background: rgba(255,255,255,0.25); }

.proj-btn-primary {
  width: 100%;
  padding: 12px;
  background: #1a3a5c;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
}

.proj-btn-primary:hover { background: #0c2a4a; }

.proj-btn-sm {
  display: flex;
  align-items: center;
  padding: 5px 8px;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 4px;
  color: white;
  font-size: 16px;
  cursor: pointer;
}

/* =====================
   プロジェクト管理画面
===================== */
#manager-screen {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: #f0f4f8;
}

#manager-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: #1a3a5c;
  color: white;
}

#manager-header h2 {
  font-size: 16px;
  font-weight: 600;
}

#manager-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  max-width: 700px;
  width: 100%;
  margin: 0 auto;
}

.manager-section {
  background: white;
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}

.manager-section-title {
  font-size: 13px;
  font-weight: 600;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid #eee;
}

.layer-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: #f8f9fa;
  border-radius: 6px;
  margin-bottom: 6px;
  border: 1px solid #e0e0e0;
}

.layer-type-badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}

.layer-type-survey { background: #E6F1FB; color: #185FA5; }
.layer-type-reference { background: #F0F0F0; color: #666; }

/* =====================
   ツールバー
===================== */
#toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: #1a3a5c;
  color: white;
  flex-wrap: wrap;
  z-index: 1000;
  position: relative;
}

#app-title {
  font-size: 13px;
  font-weight: 600;
  margin-right: 4px;
  white-space: nowrap;
}

.tool-group {
  display: flex;
  gap: 4px;
}

.tool-right {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.tool-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 4px;
  color: white;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}

.tool-btn:hover { background: rgba(255,255,255,0.25); }
.tool-btn.active { background: #378ADD; border-color: #378ADD; }

/* スナップON時は緑で明示（選択の青と区別） */
#btn-snap.active { background: #1D9E75; border-color: #1D9E75; }
/* スナップのON/OFFラベルはモバイルでも表示する */
#snap-label { display: inline; }

.tool-dropdown {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  background: white;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  min-width: 130px;
  z-index: 2000;
  margin-top: 4px;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  font-size: 13px;
  color: #333;
  cursor: pointer;
}

.dropdown-item:hover { background: #f0f4f8; }
.dropdown-item:first-child { border-radius: 6px 6px 0 0; }
.dropdown-item:last-child { border-radius: 0 0 6px 6px; }

/* =====================
   メインエリア
===================== */
#main-screen {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

#main-area {
  flex: 1;
  display: flex;
  position: relative;
  overflow: hidden;
}

/* =====================
   地図
===================== */
#map {
  flex: 1;
  height: 100%;
  z-index: 1;
  position: relative;
}

#map-controls {
  position: absolute;
  bottom: 78px;
  left: 10px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.map-ctrl-btn {
  width: 36px;
  height: 36px;
  background: white;
  border: 1px solid #ccc;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 18px;
  color: #333;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

.map-ctrl-btn:hover { background: #f0f4f8; }

/* =====================
   サイドバー
===================== */
#sidebar {
  width: 280px;
  background: white;
  border-left: 1px solid #e0e0e0;
  display: flex;
  flex-direction: row;
  z-index: 100;
}

/* ハンドルを除くサイドバー本体 */
#sidebar-inner {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

/* PCのドラッグハンドル（左端の縦バー） */
#sidebar-drag-handle {
  width: 8px;
  min-height: 100%;
  background: #f0f4f8;
  border-right: 2px solid #dde3ea;
  cursor: ew-resize;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  order: -1;
}
#sidebar-drag-handle:hover {
  background: #dde8f5;
  border-right-color: #378ADD;
}
#sidebar-drag-handle > div {
  display: none;
}

#sidebar-tabs {
  display: flex;
  border-bottom: 1px solid #e0e0e0;
}

.stab {
  flex: 1;
  padding: 8px 4px;
  text-align: center;
  font-size: 12px;
  cursor: pointer;
  color: #888;
  border-bottom: 2px solid transparent;
}

.stab.active {
  color: #1a3a5c;
  border-bottom-color: #1a3a5c;
  font-weight: 600;
}

#sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
}

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

/* =====================
   地物カード
===================== */
.feature-card {
  background: #f8f9fa;
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 6px;
  cursor: pointer;
  border: 1px solid transparent;
}

.feature-card:hover { border-color: #ccc; }
.feature-card.selected { border-color: #378ADD; background: #e8f1fb; }

.feature-card-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 3px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.feature-card-title { font-size: 12px; font-weight: 600; }
.feature-card-meta { font-size: 11px; color: #888; }

.badge {
  display: inline-block;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  margin-top: 3px;
}

.badge-red    { background: #fde8e8; color: #c0392b; }
.badge-amber  { background: #fef3e2; color: #e67e22; }
.badge-green  { background: #e8f5e9; color: #27ae60; }

/* =====================
   フォーム
===================== */
.form-row { margin-bottom: 10px; }

.form-label {
  font-size: 11px;
  color: #666;
  margin-bottom: 3px;
  display: block;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 12px;
  color: #333;
  background: #FFFFCC;   /* 入力対象の項目は黄色（参照項目は灰色のまま） */
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: #E0B400;
  background: #FFF9A8;   /* 入力中は少し濃い黄色 */
}

.form-textarea { resize: none; }

/* 左下のスケール表示（ものさし＋縮尺値）を控えめに */
.leaflet-control-scale {
  margin-bottom: 4px !important;
  margin-left: 8px !important;
}
.leaflet-control-scale-line {
  font-size: 12px;
  line-height: 1.3;
  padding: 2px 6px;
  background: rgba(255,255,255,0.8);
  border-color: #777 !important;
  color: #222;
}
.scale-ratio {
  font-size: 12px;
  font-weight: 600;
  color: #222;
  background: rgba(255,255,255,0.8);
  padding: 2px 6px;
  border-radius: 3px;
  margin-left: 8px !important;
  margin-bottom: 4px !important;
  pointer-events: none;
}
#draw-actions {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  gap: 8px;
  background: rgba(255,255,255,0.95);
  padding: 8px;
  border-radius: 10px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.25);
}
.draw-act-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}
.draw-act-btn.finish { background: #27ae60; color: #fff; }
.draw-act-btn.undo   { background: #f0f0f0; color: #333; }
.draw-act-btn.cancel { background: #f0f0f0; color: #c0392b; }
.draw-act-btn:active { opacity: 0.8; }

.form-btn {
  width: 100%;
  padding: 7px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  border: 1px solid #ddd;
  background: white;
  margin-bottom: 6px;
}

.form-btn.primary { background: #1a3a5c; color: white; border-color: #1a3a5c; }
.form-btn.success { background: #27ae60; color: white; border-color: #27ae60; }
.form-btn.danger  { background: #c0392b; color: white; border-color: #c0392b; }
.form-btn.warning { background: #e67e22; color: white; border-color: #e67e22; }

/* =====================
   写真エリア
===================== */
.photo-area {
  width: 100%;
  height: 80px;
  background: #f0f4f8;
  border: 1px dashed #ccc;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
  color: #888;
  font-size: 11px;
  margin-bottom: 6px;
}

/* =====================
   進捗
===================== */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 10px;
}

.stat-card {
  background: #f8f9fa;
  border-radius: 6px;
  padding: 8px;
  text-align: center;
}

.stat-num { font-size: 22px; font-weight: 600; }
.stat-label { font-size: 10px; color: #888; margin-top: 2px; }
.stat-未調査 { background: #fff1f1; }
.stat-未調査 .stat-num { color: #d71d1d; }
.stat-未調査 .stat-label { color: #d71d1d; }
.stat-調査中 { background: #f0fdf4; }
.stat-調査中 .stat-num { color: #1a7a3f; }
.stat-調査中 .stat-label { color: #1a7a3f; }
.stat-調査済 { background: #eff6ff; }
.stat-調査済 .stat-num { color: #2563b0; }
.stat-調査済 .stat-label { color: #2563b0; }

.progress-bar {
  height: 6px;
  background: #e0e0e0;
  border-radius: 3px;
  margin: 6px 0 12px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: #27ae60;
  border-radius: 3px;
  transition: width 0.3s;
}

/* =====================
   レイヤーパネル
===================== */
.section-label {
  font-size: 11px;
  font-weight: 600;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.layer-radio, .layer-check {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 5px;
  cursor: pointer;
  font-size: 12px;
}

/* =====================
   スタイル設定
===================== */
.color-rule-item {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  padding: 6px 8px;
  background: #f8f9fa;
  border-radius: 4px;
}

.color-swatch {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  border: 1px solid #ddd;
  cursor: pointer;
  flex-shrink: 0;
}

/* =====================
   ステータスバー
===================== */
#status-bar {
  padding: 4px 12px;
  background: #f0f4f8;
  border-top: 1px solid #ddd;
  font-size: 11px;
  color: #666;
  display: flex;
  gap: 16px;
}

/* =====================
   新規プロジェクトフォーム
===================== */
#new-project-form {
  background: white;
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 10px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}

#new-project-form h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 14px;
  color: #1a3a5c;
}
/* =====================
   スマホ対応（768px以下）
===================== */
@media (max-width: 768px) {

  /* ツールバー */
  #toolbar {
    padding: 4px 8px;
    gap: 4px;
  }
  #app-title { display: none; }
  .tool-btn {
    padding: 6px 8px;
    font-size: 11px;
  }
  .tool-btn span { display: none; } /* ユーザー名テキスト非表示 */

  /* メインエリア：縦積み */
  #main-area {
    flex-direction: column;
    overflow: hidden;
  }

  /* 地図：残り全部。最低20dvh（パネル最大80dvhと足して100dvhに収め、
     パネルを最大まで引いても枠が画面外にはみ出さない＝下端ボタンが隠れない） */
  #map {
    flex: 1;
    min-height: 20dvh;
  }

  /* サイドバー：下部・ドラッグで高さ可変 */
  #sidebar {
    width: 100%;
    height: 45dvh;
    min-height: 80px;
    max-height: 80dvh;
    border-left: none;
    border-top: 2px solid #1a3a5c;
    flex: none;
    display: flex;
    flex-direction: column;
  }

  #sidebar-inner {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
  }

  /* ドラッグハンドル（スマホでは上部バー） */
  #sidebar-drag-handle {
    width: 100%;
    min-height: 20px;
    height: 20px;
    background: #f0f4f8;
    border-bottom: 1px solid #ddd;
    border-right: none;
    cursor: ns-resize;
    order: 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  #sidebar-drag-handle > div {
    display: block;
  }

  #sidebar-content {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  /* 全タブ共通：下端ボタンがスクロール範囲に確実に入るよう下余白を確保 */
  .tab-panel.active {
    padding-bottom: 80px;
  }

  /* ステータスバー非表示 */
  #status-bar {
    display: none;
  }

  /* ドロップダウンメニュー */
  .dropdown-menu {
    font-size: 13px;
  }

  /* フォーム */
  .form-input, .form-select {
    font-size: 16px; /* iOS自動ズーム防止 */
  }

  /* ログイン画面 */
  #login-box {
    width: 90%;
    padding: 32px 20px;
  }

  /* プロジェクト選択 */
  #project-list-container {
    padding: 12px;
  }

  /* 管理画面 */
  #manager-content {
    padding: 12px;
  }

  /* 地図コントロール */
  #map-controls {
    bottom: 70px;
    left: 8px;
  }
  .map-ctrl-btn {
    width: 40px;
    height: 40px;
    font-size: 20px;
  }
}
