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

:root {
  --green:  #2d7a4f;
  --green2: #3a9e68;
  --blue:   #1a6fa8;
  --red:    #c0392b;
  --orange: #e67e22;
  --gray:   #f4f5f7;
  --text:   #2c3e50;
  --border: #dde1e7;
  --shadow: 0 2px 8px rgba(0,0,0,.12);
  /* ノッチ Safe Area */
  --safe-top:    env(safe-area-inset-top,    0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left,   0px);
  --safe-right:  env(safe-area-inset-right,  0px);
}

html { height: 100%; }

body {
  font-family: 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  color: var(--text);
  background: var(--gray);
  /* スクロールバウンス防止 */
  overscroll-behavior: none;
}

/* ── ヘッダー（Safe Area 対応） ── */
.header {
  background: var(--green);
  color: #fff;
  padding: 12px 16px;
  padding-top: max(12px, var(--safe-top));
  padding-left:  max(16px, var(--safe-left));
  padding-right: max(16px, var(--safe-right));
}
.header-inner { max-width: 1200px; margin: 0 auto; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.site-title { font-size: 1.4rem; font-weight: 700; line-height: 1.2; }
.site-desc   { font-size: .85rem; opacity: .85; }

/* ── タブナビ ── */
.tab-nav {
  background: #fff;
  border-bottom: 2px solid var(--border);
  display: flex;
  overflow-x: auto;
  /* スクロールバーを隠す */
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding-left:  var(--safe-left);
  padding-right: var(--safe-right);
}
.tab-nav::-webkit-scrollbar { display: none; }

.tab {
  flex: none;
  padding: 0 16px;
  min-height: 44px;      /* タップ最小サイズ */
  border: none;
  background: none;
  cursor: pointer;
  font-size: 1rem;       /* 16px — iOS ズーム防止 */
  color: #666;
  white-space: nowrap;
  border-bottom: 3px solid transparent;
  transition: color .15s, border-color .15s;
  touch-action: manipulation;
  display: flex;
  align-items: center;
}
.tab.active, .tab:hover { color: var(--green); border-bottom-color: var(--green); }

/* ── タブコンテンツ共通 ── */
.tab-content { display: none; }
.tab-content.active { display: block; }
.hidden { display: none !important; }

/* ── 地図 ── */
.map-controls {
  background: #fff;
  padding: 10px 16px;
  padding-left:  max(16px, var(--safe-left));
  padding-right: max(16px, var(--safe-right));
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  border-bottom: 1px solid var(--border);
}
.map-controls select {
  padding: 0 12px;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;     /* iOS ズーム防止 */
  background: #fff;
  touch-action: manipulation;
  /* iOS デフォルトスタイルをリセット */
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23666' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

.type-filters { display: flex; gap: 6px; flex-wrap: wrap; }
.type-filters label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 1rem;
  cursor: pointer;
  min-height: 44px;
  padding: 0 8px;
  border-radius: 8px;
  touch-action: manipulation;
}
.type-filters label:active { background: var(--gray); }
.type-filters input[type=checkbox] {
  width: 18px;
  height: 18px;
  accent-color: var(--green);
  flex-shrink: 0;
}

.filter-badges { display: flex; gap: 6px; flex-wrap: wrap; }
.badge {
  padding: 4px 10px;
  min-height: 28px;
  border-radius: 20px;
  font-size: .82rem;
  font-weight: 600;
  display: flex;
  align-items: center;
}
.badge-danshu     { background: #d4edda; color: #155724; }
.badge-hospital   { background: #cce5ff; color: #004085; }
.badge-consultation { background: #fff3cd; color: #856404; }
.badge-venue      { background: #ede0f7; color: #5b2d8e; }

/* dvh でブラウザ Chrome を除いた正確な高さ */
#map {
  height: calc(100dvh - 180px);
  min-height: 360px;
  z-index: 1;
  touch-action: pan-x pan-y; /* ピンチズーム許可 */
}

/* マップ情報パネル（Safe Area 対応） */
.map-info {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: #fff;
  border-top: 3px solid var(--green);
  padding: 16px;
  padding-left:  max(16px, var(--safe-left));
  padding-right: max(16px, var(--safe-right));
  padding-bottom: max(16px, var(--safe-bottom));
  max-height: 55vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  box-shadow: 0 -4px 12px rgba(0,0,0,.15);
}
.close-info {
  position: absolute;
  top: 8px;
  right: max(8px, var(--safe-right));
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: #888;
  /* 44px タップ領域 */
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
}
.map-info h3 { font-size: 1.1rem; margin-bottom: 6px; padding-right: 40px; }
.map-info .info-type { font-size: .8rem; font-weight: 600; padding: 2px 8px; border-radius: 12px; display: inline-block; margin-bottom: 8px; }
.map-info p { font-size: .9rem; line-height: 1.6; color: #555; }
.map-info a { color: var(--blue); }
.info-actions { margin-top: 12px; display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  padding: 0 16px;
  min-height: 44px;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  touch-action: manipulation;
}
.btn-primary { background: var(--green); color: #fff; }
.btn-secondary { background: var(--border); color: var(--text); }
.btn:active { opacity: .8; }

/* ── 一覧 ── */
.list-controls {
  background: #fff;
  padding: 12px 16px;
  padding-left:  max(16px, var(--safe-left));
  padding-right: max(16px, var(--safe-right));
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.list-controls input,
.list-controls select {
  padding: 0 12px;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;  /* iOS ズーム防止 */
  flex: 1;
  min-width: 140px;
  background: #fff;
  touch-action: manipulation;
  -webkit-appearance: none;
  appearance: none;
}
.list-controls select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23666' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}
.list-count {
  padding: 8px 16px;
  padding-left: max(16px, var(--safe-left));
  font-size: .85rem;
  color: #888;
  background: #fff;
}
.list-container {
  padding: 12px 16px;
  padding-left:  max(12px, var(--safe-left));
  padding-right: max(12px, var(--safe-right));
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
}

.list-card {
  background: #fff;
  border-radius: 10px;
  padding: 14px;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--border);
}
/* hover は pointer デバイスのみ（タッチデバイスでの意図しないスタイル防止） */
@media (hover: hover) {
  .list-card:hover { transform: translateY(-2px); transition: transform .15s; }
}
.list-card.danshu     { border-left-color: var(--green); }
.list-card.hospital   { border-left-color: var(--blue); }
.list-card.consultation { border-left-color: var(--orange); }

.card-type { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 4px; }
.card-type.danshu     { color: var(--green); }
.card-type.hospital   { color: var(--blue); }
.card-type.consultation { color: var(--orange); }

.card-name { font-size: 1rem; font-weight: 700; margin-bottom: 6px; }
.card-meta { font-size: .9rem; color: #666; line-height: 1.7; }
.card-meta span { display: block; }
.card-meta a { color: var(--blue); text-decoration: none; }
.card-tags { margin-top: 8px; display: flex; gap: 4px; flex-wrap: wrap; }
.card-tag { background: var(--gray); padding: 3px 10px; border-radius: 10px; font-size: .8rem; color: #555; }

/* ── 例会 ── */
.meetings-header { padding: 20px 16px 10px; }
.meetings-header h2 { font-size: 1.2rem; }
.meetings-header p  { font-size: .9rem; color: #888; margin-top: 4px; line-height: 1.5; }
.meetings-filter {
  background: #fff;
  padding: 10px 16px;
  padding-left:  max(16px, var(--safe-left));
  padding-right: max(16px, var(--safe-right));
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.meetings-filter select {
  padding: 0 12px;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
  flex: 1;
  min-width: 160px;
  background: #fff;
  touch-action: manipulation;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23666' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}
#meetingsContainer {
  padding: 16px;
  padding-left:  max(16px, var(--safe-left));
  padding-right: max(16px, var(--safe-right));
}

.meeting-org { margin-bottom: 24px; }
.meeting-org-name { font-size: 1rem; font-weight: 700; color: var(--green); border-bottom: 2px solid var(--green2); padding-bottom: 6px; margin-bottom: 10px; }
.meeting-org-pref { font-size: .8rem; color: #888; font-weight: 400; margin-left: 8px; }
.meeting-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; }

.meeting-card {
  background: #fff; border-radius: 8px; padding: 12px; box-shadow: 0 1px 4px rgba(0,0,0,.1);
  border-top: 3px solid var(--green2);
}
.meeting-card.online { border-top-color: var(--blue); }
.meeting-name { font-weight: 600; font-size: 1rem; margin-bottom: 4px; }
.meeting-venue { font-size: .9rem; color: #555; }
.meeting-venue::before { content: "📍 "; }
.meeting-time { font-size: .9rem; color: var(--green); font-weight: 600; margin-top: 4px; }
.meeting-time::before { content: "🗓 "; }
.meeting-note { font-size: .82rem; color: #999; margin-top: 4px; }

/* ── AUDIT ── */
.audit-container {
  max-width: 760px;
  margin: 0 auto;
  padding: 20px 16px;
  padding-left:  max(16px, var(--safe-left));
  padding-right: max(16px, var(--safe-right));
}
.audit-container h2 { font-size: 1.3rem; margin-bottom: 8px; }
.audit-intro { font-size: 1rem; color: #555; margin-bottom: 20px; line-height: 1.7; }

.audit-q { background: #fff; border-radius: 10px; padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.audit-q-text { font-weight: 600; margin-bottom: 10px; font-size: 1rem; line-height: 1.6; }
.audit-q-num  { color: var(--green); margin-right: 6px; }
.audit-options { display: flex; flex-direction: column; gap: 4px; }
.audit-option {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  min-height: 44px;       /* タップ最小サイズ */
  padding: 0 8px;
  border-radius: 8px;
  touch-action: manipulation;
}
.audit-option:active { background: var(--gray); }
.audit-option input {
  accent-color: var(--green);
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}
.audit-option span  { font-size: 1rem; line-height: 1.4; }

.audit-submit {
  margin-top: 20px;
  background: var(--green);
  color: #fff;
  padding: 0 28px;
  min-height: 52px;       /* 大きめのCTAボタン */
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
  touch-action: manipulation;
}
.audit-submit:active { background: var(--green2); }

.audit-result { background: #fff; border-radius: 10px; padding: 20px; margin-top: 16px; box-shadow: var(--shadow); }
.audit-score { font-size: 2.5rem; font-weight: 700; text-align: center; }
.audit-level { font-size: 1.1rem; font-weight: 700; text-align: center; margin: 8px 0; padding: 8px; border-radius: 8px; }
.level-0 { background: #d4edda; color: #155724; }
.level-1 { background: #fff3cd; color: #856404; }
.level-2 { background: #ffe0b2; color: #7b3f00; }
.level-3 { background: #fcd9d7; color: var(--red); }
.audit-advice { font-size: 1rem; line-height: 1.7; color: #444; margin-top: 10px; }
.audit-retry {
  margin-top: 14px;
  background: var(--border);
  color: var(--text);
  padding: 0 20px;
  min-height: 44px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
  width: 100%;
  touch-action: manipulation;
}

/* ── SBIRTSとは ── */
.about-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 24px 16px;
  padding-left:  max(16px, var(--safe-left));
  padding-right: max(16px, var(--safe-right));
  padding-bottom: max(24px, var(--safe-bottom));
}
.about-container h2 { font-size: 1.4rem; margin-bottom: 20px; }
.about-steps { display: flex; flex-direction: column; gap: 16px; margin-bottom: 32px; }
.about-step { background: #fff; border-radius: 10px; padding: 18px; box-shadow: var(--shadow); display: flex; gap: 16px; align-items: flex-start; }
.step-letter { background: var(--green); color: #fff; font-size: 1.3rem; font-weight: 700; width: 48px; height: 48px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.step-content h3 { font-size: 1rem; margin-bottom: 6px; }
.step-content p  { font-size: .9rem; color: #555; line-height: 1.6; }
.about-resources { background: #fff; border-radius: 10px; padding: 18px; box-shadow: var(--shadow); }
.about-resources h3 { margin-bottom: 12px; font-size: 1rem; }
.about-resources ul { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.about-resources li {
  font-size: .9rem;
  padding: 10px 12px;
  border-left: 3px solid var(--green);
  min-height: 44px;
  display: flex;
  align-items: center;
}
.about-resources a { color: var(--blue); font-weight: 600; }

/* ── Leaflet popup カスタム ── */
.leaflet-popup-content { min-width: 200px; font-size: .88rem; }
.popup-name { font-weight: 700; font-size: .95rem; margin-bottom: 4px; }
.popup-type { font-size: .75rem; padding: 1px 6px; border-radius: 8px; display: inline-block; margin-bottom: 6px; }
.popup-danshu { background: #d4edda; color: #155724; }
.popup-hospital { background: #cce5ff; color: #004085; }
.popup-consultation { background: #fff3cd; color: #856404; }
.popup-venue { background: #ede0f7; color: #5b2d8e; }

.venue-meetings { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.venue-meeting-row { background: #f9f4fd; border-left: 3px solid #8e44ad; padding: 6px 10px; border-radius: 0 6px 6px 0; }
.venue-meeting-name { font-weight: 700; font-size: .9rem; display: block; }
.venue-meeting-time { font-size: .82rem; color: #8e44ad; display: block; }
.venue-meeting-org  { font-size: .78rem; color: #888; display: block; }
.popup-body p { margin: 2px 0; color: #444; }

/* ── スマホ専用調整 ── */
@media (max-width: 600px) {
  .site-title { font-size: 1.1rem; }
  .site-desc { display: none; }

  /* タブは等幅で全幅に広げる */
  .tab-nav { display: grid; grid-template-columns: repeat(5, 1fr); }
  .tab { font-size: .72rem; padding: 0 4px; text-align: center; justify-content: center; }

  /* 地図コントロールを縦積みに */
  .map-controls { flex-direction: column; align-items: stretch; }
  .map-controls select { width: 100%; }
  .type-filters { justify-content: space-between; }
  .filter-badges { display: none; }

  /* 地図高さ: タブ高さ等を考慮 */
  #map { height: calc(100dvh - 160px); min-height: 300px; }

  /* 一覧: シングルカラム */
  .list-container { grid-template-columns: 1fr; padding: 8px 12px; }
  .list-controls { gap: 8px; }
  .list-controls input,
  .list-controls select { min-width: 0; }

  /* 例会グリッドをシングルカラムに */
  .meeting-grid { grid-template-columns: 1fr; }
  .meetings-filter { flex-direction: column; }
  .meetings-filter select { width: 100%; }

  /* AUDIT */
  .audit-q-text { font-size: 1rem; }
}

/* 横向きスマホ（landscape） */
@media (max-width: 900px) and (orientation: landscape) {
  #map { height: calc(100dvh - 120px); }
  .map-info { max-height: 70vh; }
}
