/*
 * 高齢ユーザー前提の画面方針（§7.4）:
 * 大きな文字・高コントラスト・画面数の最小化・業務用語のままのラベル。
 */

:root {
  --ink: #2b2b2b;        /* 墨 */
  --paper: #faf7f0;      /* 生成り */
  --card: #ffffff;
  --accent: #6b4a2b;     /* 焦茶 */
  --accent-dark: #503418;
  --line: #d9d2c3;
  --notice-bg: #e8f3e4;
  --notice-ink: #2e5c2e;
  --alert-bg: #fbe9e7;
  --alert-ink: #a13d2d;
  --muted: #6f6a5e;
  --draft: #b08830;
}

* { box-sizing: border-box; }

/* hidden 属性はアプリ全体の表示切替の唯一の手段（Stimulus の各コントローラが使う）。
   display を明示したコンポーネント（.btn 等）でも常に効かせる */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP", sans-serif;
  font-size: 18px;
  line-height: 1.7;
  color: var(--ink);
  background: var(--paper);
}

.site-header {
  background: var(--accent);
  padding: 0 16px;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 20px;
  max-width: 1080px;
  margin: 0 auto;
  min-height: 56px;
  flex-wrap: wrap;
}

.site-nav a, .site-nav .nav-logout {
  color: #fff;
  text-decoration: none;
  font-size: 17px;
  padding: 6px 4px;
}

.site-nav a:hover { text-decoration: underline; }
.site-nav .brand { font-weight: 700; font-size: 20px; }
.nav-spacer { flex: 1; }
.nav-sub { opacity: 0.85; }

.nav-logout {
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

h1 { font-size: 28px; margin: 16px 0; }
h2 { font-size: 22px; margin: 24px 0 8px; }

a { color: var(--accent-dark); }

.flash {
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 16px;
  font-weight: 600;
}
.flash-notice { background: var(--notice-bg); color: var(--notice-ink); }
.flash-alert { background: var(--alert-bg); color: var(--alert-ink); }

/* テーブル */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  margin: 12px 0;
}

th, td {
  border: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
}

th { background: #f1ece0; font-weight: 700; white-space: nowrap; }

/* 並び替えできる見出し。見出しのどこを押しても効くよう、余白はリンク側が持つ */
th.sortable { padding: 0; }

th .sort-link {
  display: block;
  padding: 10px 12px;
  color: inherit;
  text-decoration: none;
}

th .sort-link:hover, th .sort-link:focus { background: var(--line); text-decoration: underline; }
th .sort-link.active { color: var(--accent-dark); }
th .sort-mark { font-size: 0.85em; }
th .sort-link.active .sort-mark { color: inherit; }

/* ボタン・フォーム（タップしやすい大きさに） */
.btn, button[type="submit"], input[type="submit"] {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 10px 20px;
  font-size: 18px;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
}

.btn:hover, button[type="submit"]:hover { background: var(--accent-dark); }

.btn-secondary {
  background: var(--card);
  color: var(--accent-dark);
  border: 2px solid var(--accent);
}
.btn-secondary:hover { background: #f1ece0; }

.btn-danger { background: var(--alert-ink); }

.actions { margin: 20px 0; display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }

label {
  display: block;
  font-weight: 700;
  margin: 16px 0 4px;
}

input[type="text"], input[type="email"], input[type="password"], input[type="date"],
input[type="number"], input[type="search"], select, textarea {
  width: 100%;
  max-width: 480px;
  font-size: 18px;
  font-family: inherit;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--card);
}

textarea { max-width: 640px; }

.field-hint { color: var(--muted); font-size: 15px; margin: 2px 0 0; }

.form-errors {
  background: var(--alert-bg);
  color: var(--alert-ink);
  border-radius: 6px;
  padding: 12px 16px;
  margin-bottom: 16px;
}

/* ステータスバッジ */
.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 12px;
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
}
.badge-draft { background: #f7edd3; color: var(--draft); }      /* 未確認 */
.badge-confirmed { background: var(--notice-bg); color: var(--notice-ink); }
.badge-active { background: var(--notice-bg); color: var(--notice-ink); }
.badge-left, .badge-extinct { background: #eee8dc; color: var(--muted); }
.badge-owner { background: #ede4f3; color: #5b3a80; }
.badge-member { background: #e3ecf5; color: #2c5680; }

/* ダッシュボードの統計カード */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin: 20px 0;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px 20px;
}

.stat-card .stat-label { color: var(--muted); font-size: 16px; }
.stat-card .stat-value { font-size: 36px; font-weight: 700; }
.stat-card .stat-note { color: var(--muted); font-size: 14px; }

/* 検索ボックス */
.search-form { display: flex; gap: 8px; margin: 16px 0; flex-wrap: wrap; }
.search-form input[type="search"] { flex: 1; min-width: 240px; max-width: none; }

.empty-state { color: var(--muted); padding: 24px 0; }

/* 世話人の担当地区（チェックボックスの横並び）と表中の紐付けフォーム */
.checkbox-row { display: flex; gap: 16px; flex-wrap: wrap; margin: 8px 0; }
.checkbox-label { display: inline-flex; align-items: center; gap: 6px; font-weight: normal; }
.checkbox-label input[type="checkbox"] { width: auto; margin: 0; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline-form select { max-width: 260px; }

.muted { color: var(--muted); }

/* OCR 確認画面（R-1: 画像と下書きの並置照合） */
.ocr-layout {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(320px, 1fr);
  gap: 24px;
  align-items: start;
}

@media (max-width: 800px) {
  .ocr-layout { grid-template-columns: 1fr; }
}

.ocr-image { position: sticky; top: 12px; }

.entry-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  padding: 4px 20px 20px;
  margin-bottom: 20px;
}

.entry-warnings {
  background: #f7edd3;
  color: var(--draft);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 15px;
}

/* §7.7: 読み取り信頼度が低いフィールドの強調 */
input.low-confidence {
  border: 2px solid var(--draft);
  background: #fdf6e3;
}

.badge-pending, .badge-processing { background: #e3ecf5; color: #2c5680; }
.badge-reviewing { background: #f7edd3; color: var(--draft); }
.badge-failed { background: var(--alert-bg); color: var(--alert-ink); }
.badge-mapping { background: #f7edd3; color: var(--draft); }
.badge-importing { background: #e3ecf5; color: #2c5680; }
.badge-completed { background: var(--notice-bg); color: var(--notice-ink); }

/* インポートのプレビューのサンプル値 */
.sample-value {
  display: inline-block;
  background: #f1ece0;
  border-radius: 4px;
  padding: 1px 8px;
  margin: 2px 4px 2px 0;
  font-size: 14px;
}

.radio-label { font-weight: 400; margin: 4px 0; }

/* U-8 月参り: 当日リストと週間ビュー */
tr.visit-done { opacity: 0.55; }

.week-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  margin: 12px 0;
}

.week-day {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 15px;
}

.week-day-current { border: 2px solid var(--accent); }
.week-day-head { font-weight: 700; }
.week-day-count { color: var(--accent-dark); font-weight: 700; }
.week-day-names { color: var(--muted); font-size: 14px; }

/* U-3 行事出欠: 一括入力フォーム */
.attendance-choices { white-space: nowrap; }
.radio-inline { display: inline-block; font-weight: 400; margin: 0 10px 0 0; cursor: pointer; }
.radio-inline input { margin-right: 2px; }
input.attendance-count { width: 70px; }
input.attendance-note { min-width: 160px; }

/* U-1 年忌: 状態バッジ（予定→案内済→出欠確定→実施→記録済） */
.badge-service-planned { background: #e3ecf5; color: #2c5680; }
.badge-service-notified { background: #f7edd3; color: var(--draft); }
.badge-service-confirmed { background: #ede4f3; color: #5b3a80; }
.badge-service-done { background: var(--notice-bg); color: var(--notice-ink); }
.badge-service-recorded { background: #eee8dc; color: var(--muted); }

/* 一覧行の中に置く小さめの操作ボタン */
.nenki-actions { white-space: nowrap; }
.nenki-actions form { display: inline-block; margin-right: 8px; }
button.btn-inline {
  background: var(--card);
  color: var(--accent-dark);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 15px;
  font-family: inherit;
  cursor: pointer;
}
button.btn-inline:hover { background: #f1ece0; }

/* S-3 区画マップ */
.map-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  margin: 12px 0;
}

.map-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  text-decoration: none;
}

.map-card:hover { border-color: var(--accent); }
.map-card-title { font-weight: 700; font-size: 18px; }
.map-card-thumb { max-width: 100%; max-height: 160px; object-fit: contain; border: 1px solid var(--line); background: #fff; }

.map-toolbar {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 16px 16px;
  margin: 12px 0;
}

.map-hint {
  background: #f7edd3;
  color: var(--draft);
  border-radius: 6px;
  padding: 8px 12px;
  margin: 8px 0 0;
  font-weight: 600;
}

/* 文中に置くリンク風のボタン（区画マップの取り消し・置き直し、まとめて編集の「追加を取り消す」） */
.map-cancel, .map-replace, button.btn-link {
  background: none;
  border: none;
  padding: 0;
  font-family: inherit;
  font-size: inherit;
  color: var(--accent-dark);
  text-decoration: underline;
  cursor: pointer;
}

.map-stage {
  position: relative;
  display: inline-block;
  max-width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  touch-action: manipulation;
}

.map-stage img { display: block; max-width: 100%; height: auto; }
.map-stage-placing { cursor: crosshair; outline: 3px solid var(--draft); }
.map-stage-placing .map-pin { pointer-events: none; } /* 配置中はピンの下にも打てる */

.map-pin {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}

/* ピンの見た目は区画マップ（.map-pin-dot）と家の住所地図（.address-pin =
   Leaflet の divIcon）で共有する。変えるときはここ 1 か所 */
.map-pin-dot,
.address-pin {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
}

.map-pin-label {
  font-size: 13px;
  line-height: 1.3;
  white-space: nowrap;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 4px;
  padding: 0 5px;
  color: var(--ink);
}

.map-pin-selected .map-pin-dot,
.map-pin-highlight .map-pin-dot { background: #c62828; }
.map-pin-highlight .map-pin-dot { animation: map-pin-pulse 1.2s ease-in-out 3; }

@keyframes map-pin-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.6); }
}

/* 家の住所地図（詳細画面）。タイルは地理院（淡色）、ピン（.address-pin）の
   見た目は上の .map-pin-dot と共有 */
.family-map {
  height: 340px;
  max-width: 680px;
  border: 1px solid var(--line);
  background: #f4f2ec;
}

/* 編集モード中はタップでピンを置けることをカーソルでも示す */
.family-map-editing .family-map { cursor: crosshair; }

.map-info {
  background: var(--card);
  border: 2px solid var(--accent);
  border-radius: 8px;
  padding: 12px 16px;
  margin: 12px 0;
}

.map-info-item { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.map-info-links { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
button.map-unpin { background: none; border: none; padding: 0; font-family: inherit; font-size: inherit; color: var(--alert-ink); text-decoration: underline; cursor: pointer; }
button.map-unpin:hover { background: none; }
.map-place-form { display: none; }

/* 認証画面 */
.auth-card {
  max-width: 440px;
  margin: 60px auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px 32px 32px;
}

/* U-10 統一スケジュール（予定表。docs/schedule.md） */
.calendar { table-layout: fixed; }
.calendar th { text-align: center; }
.calendar td.calendar-day {
  vertical-align: top;
  height: 96px;
  padding: 4px 6px;
  font-size: 14px;
}
.calendar-other-month { background: #f4f0e6; opacity: 0.6; }
.calendar-today { outline: 2px solid var(--accent); outline-offset: -2px; }
.calendar-day-head { display: flex; justify-content: space-between; font-weight: 700; }
.calendar-day-head a { text-decoration: none; }
.calendar-add { color: var(--muted); visibility: hidden; }
.calendar-day:hover .calendar-add { visibility: visible; }

.sched-item {
  display: block;
  margin: 2px 0;
  padding: 1px 6px;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.5;
  text-decoration: none;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sched-item:hover { outline: 1px solid var(--accent); }
.sched-more { display: block; font-size: 13px; color: var(--muted); }

/* 種別の色分け（凡例＝フィルタのラベルと共通） */
.sched-kind {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 6px;
  font-size: 14px;
  white-space: nowrap;
}
.sched-kind-nenki { background: #ede4f3; color: #5b3a80; }
.sched-kind-higan { background: #e3ecf5; color: #2c5680; }
.sched-kind-bon { background: #f7edd3; color: #7a5c14; }
.sched-kind-segaki { background: #fbe9e7; color: #a13d2d; }
.sched-kind-funeral { background: #e5e2da; color: #4c463a; }
.sched-kind-meeting { background: #e8f3e4; color: #2e5c2e; }
.sched-kind-tsukimairi { background: #e0efee; color: #1f5f5b; }
.sched-kind-tanagyo { background: #f6e8d8; color: #8a5a1e; }
.sched-kind-other { background: #eee8dc; color: var(--muted); }
.sched-kind-temple_task { background: #e9edda; color: #55611f; }
.sched-kind-personal { background: #eceff1; color: #546e7a; border: 1px dashed #90a4ae; }

.schedule-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  margin: 12px 0;
  font-size: 15px;
}
.schedule-filter-kind { font-weight: 400; cursor: pointer; white-space: nowrap; }
.schedule-filter .btn { font-size: 15px; padding: 4px 14px; }

.schedule-day-heading { margin-bottom: 4px; }
.schedule-day-heading .muted { font-weight: 400; font-size: 15px; margin-left: 8px; }
.schedule-day-today { border-left: 4px solid var(--accent); padding-left: 8px; }

/* 家台帳の「まとめて編集」（家の情報・ご家族・故人記録を 1 つのフォームで保存する）。
   人・記録ごとに .entry-card（OCR 確認画面と共用）で区切り、入力欄は幅に応じて 2〜4 列に並べる */
.edit-section { margin: 28px 0 8px; }

.entry-card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}

.entry-card-title { font-size: 19px; font-weight: 700; margin: 12px 0 0; }
.entry-card .form-errors { margin: 12px 0 0; }

.edit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0 16px;
}

.edit-grid .field-wide { grid-column: 1 / -1; }
.edit-grid label { margin-top: 12px; }
.edit-grid input, .edit-grid select, .edit-grid textarea { max-width: none; }
