/* 家族用CSS（スマホ最適化） */
body { font-size: 16px; }
#app { min-height: 100vh; }

/* ===== 全画面ラッパー ===== */
.family-screen {
  min-height: 100vh;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  display: flex;
  flex-direction: column;
}

/* ===== メッセージ画面（一覧・詳細共通） ===== */
/* fixed ヘッダーが画面上部に固定され、コンテンツがその下から始まる */
.messages-screen {
  background: var(--gray-50);
  min-height: 100vh;
  display: block;  /* flex解除: position:fixedはビューポート基準なのでflex不要 */
  position: relative;
}

/* ===== カード（ログイン・登録用） ===== */
.family-card {
  background: #fff;
  border-radius: 20px;
  padding: 32px 24px;
  width: 100%;
  max-width: 440px;
  margin: 20px auto;
  box-shadow: var(--shadow-lg);
  flex-shrink: 0;
}

/* ===== ロゴ・タイトル ===== */
.family-logo { text-align: center; font-size: 48px; margin-bottom: 4px; }
.family-title { text-align: center; font-size: 22px; font-weight: 700; color: var(--primary); margin-bottom: 4px; }
.family-subtitle { text-align: center; font-size: 14px; color: var(--gray-400); margin-bottom: 20px; }

/* ===== ヘッダー（メッセージ画面） ===== */
/* position: fixed でビューポート最上部に常時固定 */
/* ※ flexの親要素に関係なく、ビューポート基準で固定される */
.family-header {
  background: var(--primary);
  color: #fff;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
/* fixedヘッダーの高さ分コンテンツを押し下げ */
.messages-screen .messages-container { padding-top: 72px; }
.family-header h1 { font-size: 18px; font-weight: 700; }
.family-header .subtitle { font-size: 12px; opacity: .8; }
.family-header-left { display: flex; align-items: center; gap: 10px; }
.header-logo { font-size: 24px; }
.header-title { font-size: 16px; font-weight: 700; }
.header-sub { font-size: 12px; opacity: .8; }
.header-logout { background: rgba(255,255,255,.2); color: #fff; padding: 6px 14px; border-radius: 8px; font-size: 14px; border: none; }

/* ===== ログイン画面（旧互換） ===== */
.family-login { min-height: 100vh; background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%); display: flex; align-items: center; justify-content: center; padding: 24px; }
.family-login-card { background: #fff; border-radius: 20px; padding: 36px 28px; width: 100%; max-width: 400px; box-shadow: var(--shadow-lg); }
.family-login-logo { text-align: center; margin-bottom: 28px; }
.family-login-logo .logo-icon { font-size: 48px; margin-bottom: 8px; }
.family-login-logo h1 { font-size: 22px; font-weight: 700; color: var(--primary); }
.family-login-logo p { font-size: 14px; color: var(--gray-400); margin-top: 4px; }

/* ===== ステップバー ===== */
.step-bar {
  display: flex;
  align-items: center;
  margin: 16px 0 24px;
}
.step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.step-num {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700;
  background: var(--gray-200); color: var(--gray-400);
  transition: all .2s;
}
.step-label {
  font-size: 11px; color: var(--gray-400); white-space: nowrap;
}
.step.active .step-num { background: var(--primary); color: #fff; }
.step.active .step-label { color: var(--primary); font-weight: 600; }
.step.done .step-num { background: var(--success); color: #fff; }
.step.done .step-label { color: var(--success); }
.step-line {
  flex: 1; height: 2px; background: var(--gray-200); margin: 0 4px;
  margin-bottom: 18px; /* step-labelの高さ分を補正 */
}
.step-line.done { background: var(--success); }

/* 旧 .steps（互換） */
.steps { display: flex; gap: 0; margin-bottom: 24px; }

/* ===== 登録カード ===== */
.register-card { /* family-cardと共通 */ }
.register-title { font-size: 18px; font-weight: 700; margin-bottom: 8px; }
.reg-memo { font-size: 13px; color: var(--gray-400); background: var(--gray-100); border-radius: 8px; padding: 8px 12px; margin-bottom: 16px; }

/* ===== フォーム拡張 ===== */
.form-label { display: block; font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.form-hint { font-size: 13px; color: var(--gray-400); margin-bottom: 6px; line-height: 1.5; }
.form-input { width: 100%; padding: 14px 16px; border: 2px solid var(--gray-200); border-radius: 10px; font-size: 16px; font-family: inherit; transition: border-color .2s; background: #fff; }
.form-input:focus { outline: none; border-color: var(--primary); }
.form-input-lg { font-size: 18px; padding: 16px 18px; }
.form-select { width: 100%; padding: 14px 16px; border: 2px solid var(--gray-200); border-radius: 10px; font-size: 16px; font-family: inherit; background: #fff; }
.form-select:focus { outline: none; border-color: var(--primary); }
.required { color: var(--danger); font-size: 12px; margin-left: 4px; }

/* ===== OTP入力 ===== */
.otp-input-wrap { margin: 16px 0; }
.otp-input { width: 100%; font-size: 32px; letter-spacing: 12px; text-align: center; font-weight: 700; padding: 16px; border: 2px solid var(--gray-200); border-radius: 10px; font-family: 'Courier New', monospace; }
.otp-input:focus { outline: none; border-color: var(--primary); }
.otp-desc { font-size: 15px; color: var(--gray-600); margin-bottom: 16px; line-height: 1.6; }

/* ===== デモOTPボックス ===== */
.demo-otp-box {
  background: #fef3c7;
  border: 2px solid #fbbf24;
  border-radius: 12px;
  padding: 14px 18px;
  margin-bottom: 16px;
  text-align: center;
}
.demo-otp-label { font-size: 12px; color: #92400e; font-weight: 600; margin-bottom: 4px; }
.demo-otp-code { font-size: 36px; font-weight: 700; color: var(--primary); letter-spacing: 8px; font-family: 'Courier New', monospace; }
/* 旧クラス互換 */
.demo-otp-box .otp-code { font-size: 32px; font-weight: 700; color: var(--primary); letter-spacing: 6px; }
.demo-otp-box p { font-size: 12px; color: var(--gray-600); margin-bottom: 4px; }

/* ===== 登録完了画面 ===== */
.done-icon { font-size: 64px; text-align: center; margin: 16px 0 8px; }
.done-title { font-size: 22px; font-weight: 700; color: var(--primary); text-align: center; margin-bottom: 12px; }
.done-msg { font-size: 16px; color: var(--gray-800); text-align: center; margin-bottom: 16px; line-height: 1.6; }
.done-info { background: var(--gray-50); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.done-info-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--gray-200); font-size: 14px; }
.done-info-row:last-child { border-bottom: none; }
.done-info-label { color: var(--gray-400); font-size: 13px; }
.done-sub { font-size: 13px; color: var(--gray-400); text-align: center; margin-bottom: 20px; }

/* ===== エラー画面 ===== */
.error-card { text-align: center; }
.error-icon { font-size: 48px; margin: 12px 0; }
.error-msg { font-size: 16px; color: var(--danger); font-weight: 600; margin: 8px 0; line-height: 1.5; }
.error-sub { font-size: 14px; color: var(--gray-400); margin-bottom: 20px; }

/* ===== ボタン拡張 ===== */
.btn-lg { padding: 16px 24px; font-size: 17px; }
.btn-block { width: 100%; }
.btn-ghost { background: none; color: var(--primary); font-size: 14px; padding: 8px 16px; border-radius: 8px; }
.btn-ghost:hover { background: var(--primary-light); }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }

/* ===== クイックログイン ===== */
.quick-login-section { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--gray-200); }
.quick-login-label { font-size: 13px; color: var(--gray-400); text-align: center; margin-bottom: 10px; }
.quick-login-btns { display: flex; flex-direction: column; gap: 8px; }

/* ===== メッセージコンテナ ===== */
.messages-container { padding: 16px; max-width: 640px; margin: 0 auto; width: 100%; }
.messages-title-bar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.messages-title { font-size: 20px; font-weight: 700; color: var(--gray-800); }

/* ===== メッセージカード ===== */
.msg-card { background: #fff; border-radius: 16px; padding: 18px; box-shadow: var(--shadow); cursor: pointer; transition: transform .15s, box-shadow .15s; border-left: 4px solid transparent; margin-bottom: 12px; }
.msg-card:active { transform: scale(.98); }
.msg-card.unread { border-left-color: var(--primary); background: #fafffe; }
.msg-card.broadcast { /* badge-broadcastで色は区別 */ }
.msg-card-header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.msg-type-badge { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.msg-badge { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.msg-badge.broadcast { background: #dbeafe; color: #1e40af; }
.msg-badge.individual { background: #fce7f3; color: #9d174d; }
.msg-date { font-size: 12px; color: var(--gray-400); white-space: nowrap; margin-left: auto; }
.msg-preview { font-size: 15px; color: var(--gray-800); line-height: 1.5; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; margin-bottom: 8px; }
.msg-footer { display: flex; align-items: center; gap: 12px; }
.msg-sender { font-size: 13px; color: var(--gray-400); }
.msg-attach { font-size: 13px; color: var(--gray-400); }
.unread-dot { width: 8px; height: 8px; background: var(--accent); border-radius: 50%; flex-shrink: 0; }

/* ===== メッセージ詳細 ===== */
.msg-detail { padding: 20px; max-width: 600px; margin: 0 auto; }
/* .back-btn は下部「前のページに戻るボタン」セクションで定義（重複排除） */
.msg-detail-card { background: #fff; border-radius: 16px; padding: 24px; box-shadow: var(--shadow); }
.msg-detail-type { margin-bottom: 12px; }
.msg-detail-meta { display: flex; flex-wrap: wrap; gap: 8px; font-size: 13px; color: var(--gray-400); margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--gray-100); }
.msg-sender-label, .msg-date-label { display: flex; align-items: center; gap: 4px; }
.msg-detail-body { font-size: 17px; line-height: 1.8; white-space: pre-wrap; margin: 16px 0; color: var(--gray-800); }
.msg-attachments { margin-top: 16px; }
.attach-label { font-size: 14px; color: var(--gray-400); margin-bottom: 8px; }

/* ===== 添付画像グリッド ===== */
.attach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; margin-top: 8px; }
.attach-img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; cursor: pointer; transition: opacity .2s; }
.attach-img:active { opacity: .8; }
.attachment-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; margin-top: 16px; }
.attachment-img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; cursor: pointer; transition: opacity .2s; }
.attachment-img:active { opacity: .8; }

/* ===== 未読バッジ ===== */
.unread-badge { background: var(--accent); color: #fff; border-radius: 999px; padding: 3px 10px; font-size: 13px; font-weight: 700; }

/* ===== 空メッセージ状態 ===== */
.empty-messages { text-align: center; padding: 60px 20px; color: var(--gray-400); }
.empty-messages p { font-size: 15px; margin-bottom: 6px; }
.text-muted { color: var(--gray-400); font-size: 14px; }

/* ===== 登録フォーム（旧互換） ===== */
.register-wrap { min-height: 100vh; background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%); padding: 24px; display: flex; align-items: flex-start; justify-content: center; }
.register-logo { text-align: center; margin-bottom: 24px; }
.register-logo h1 { font-size: 20px; font-weight: 700; color: var(--primary); margin-bottom: 4px; }
.register-logo p { font-size: 14px; color: var(--gray-400); }

/* ===== 登録完了（旧互換） ===== */
.complete-wrap { text-align: center; padding: 40px 20px; }
.complete-icon { font-size: 64px; margin-bottom: 16px; }
.complete-wrap h2 { font-size: 22px; font-weight: 700; color: var(--primary); margin-bottom: 8px; }
.complete-wrap p { font-size: 15px; color: var(--gray-600); }

/* ===== 前のページに戻るボタン ===== */
.back-btn,
.family-header .back-btn {
  display: inline-flex;
  align-items: center;
  background: #ffffff;
  color: #2E7D6F;        /* 緑テキスト — family-headerのcolor:#fff継承を上書き */
  border: none;
  border-radius: 8px;
  padding: 8px 18px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
  -webkit-tap-highlight-color: transparent;
  opacity: 1;
  visibility: visible;
}
.back-btn:hover,
.back-btn:active,
.back-btn:focus,
.family-header .back-btn:hover,
.family-header .back-btn:active {
  background: #e8f5f2;
  color: #2E7D6F;
}
.back-btn i { display: none; }

/* ===== 注意喚起バナー（常時表示） ===== */
.care-notice-banner {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  background: #FFF3E0;
  border-left: 4px solid #E65100;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}
.care-notice-icon {
  font-size: 22px;
  line-height: 1.4;
  flex-shrink: 0;
}
.care-notice-text {
  font-size: 13px;
  line-height: 1.7;
  color: #4E342E;
}
.care-notice-text strong {
  display: block;
  font-size: 15px;
  margin-bottom: 6px;
  color: #BF360C;
}

/* ===== PWAインストールバナー ===== */
.pwa-install-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #E8F5F2;
  border: 1px solid #2E7D6F;
  border-radius: 10px;
  padding: 12px 14px;
  margin: 0 0 12px 0;
  box-shadow: 0 2px 8px rgba(46,125,111,0.12);
  animation: slideDown 0.3s ease;
}
.pwa-ios-banner {
  background: #EFF7FF;
  border-color: #1565C0;
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.pwa-banner-icon {
  font-size: 26px;
  flex-shrink: 0;
}
.pwa-banner-text {
  flex: 1;
  font-size: 13px;
  line-height: 1.5;
  color: #333;
}
.pwa-banner-text strong {
  display: block;
  font-size: 14px;
  color: #2E7D6F;
  margin-bottom: 2px;
}
.pwa-ios-banner .pwa-banner-text strong {
  color: #1565C0;
}
.pwa-banner-btn {
  flex-shrink: 0;
  background: #2E7D6F;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.pwa-banner-btn:hover {
  background: #245f54;
}
.pwa-banner-close {
  flex-shrink: 0;
  background: none;
  border: none;
  font-size: 20px;
  color: #888;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
.pwa-banner-close:hover {
  color: #333;
}

/* ===== v13: 再ログイン案内・ログアウト（目立たない位置） ===== */
.relogin-guide { background: var(--gray-50, #f8f9fa); border-radius: 12px; padding: 16px; text-align: left; font-size: 14px; line-height: 1.7; color: #374151; }
.relogin-guide-title { font-weight: 700; margin-bottom: 8px; }
.relogin-guide-list { padding-left: 20px; margin-bottom: 8px; }
.relogin-guide-list li { margin-bottom: 10px; }
.family-logout-area { text-align: center; margin: 48px 0 24px; }
.family-logout-link { background: none; border: none; color: #9ca3af; font-size: 12px; text-decoration: underline; padding: 8px 12px; cursor: pointer; }
.family-actions-spacer { height: 0; }
