/* ===== CSS変数 ===== */
:root {
  --primary: #3B8686;
  --primary-light: #E8F4F4;
  --primary-dark: #2C6464;
  --bg: #F7FAFA;
  --card-bg: #FFFFFF;
  --text: #333333;
  --text-muted: #888888;
  --label: #444444;
  --success: #4CAF50;
  --error: #E53935;
  --warning: #FF9800;
  --progress-done: #4CAF50;
  --progress-current: #3B8686;
  --progress-pending: #D0D0D0;
  --btn-primary: #3B8686;
  --btn-primary-hover: #2C6464;
  --btn-secondary: #E0E0E0;
  --btn-secondary-hover: #CCCCCC;
  --btn-submit: #4CAF50;
  --btn-submit-hover: #388E3C;
  --border: #D8E0E0;
  --border-focus: #3B8686;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --font-main: 'Noto Sans JP', 'Hiragino Sans', 'Meiryo', sans-serif;
}

/* ===== リセット ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-main);
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ===== ヘッダー ===== */
#app-header {
  background: var(--primary);
  color: #fff;
  text-align: center;
  padding: 16px 16px 12px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}
#app-header h1 {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.05em;
}
.header-subtitle {
  font-size: 0.85rem;
  opacity: 0.9;
  margin-top: 2px;
}

/* ===== プログレスバー ===== */
#progress-bar {
  background: #fff;
  padding: 12px 8px;
  display: none;
  justify-content: center;
  align-items: center;
  gap: 0;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 62px;
  z-index: 99;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
#progress-bar.visible {
  display: flex;
}

.progress-step {
  display: flex;
  align-items: center;
  cursor: pointer;
  white-space: nowrap;
}
.progress-step .step-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: #fff;
  background: var(--progress-pending);
  transition: background 0.3s, transform 0.2s;
  flex-shrink: 0;
}
.progress-step.done .step-dot { background: var(--progress-done); }
.progress-step.current .step-dot {
  background: var(--progress-current);
  transform: scale(1.15);
  box-shadow: 0 0 0 3px rgba(59,134,134,0.25);
}
.progress-step .step-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-left: 4px;
  display: none;
}
.progress-step.current .step-label {
  display: inline;
  color: var(--primary);
  font-weight: 700;
}
.progress-line {
  width: 20px;
  height: 2px;
  background: var(--progress-pending);
  flex-shrink: 0;
}
.progress-line.done { background: var(--progress-done); }

/* ===== メインコンテンツ ===== */
#main-content {
  flex: 1;
  padding-bottom: 80px;
}

.screen { display: none; }
.screen.active { display: block; }

/* ===== ウェルカム画面 ===== */
.welcome-card {
  max-width: 520px;
  margin: 40px auto;
  padding: 32px 24px;
  background: var(--card-bg);
  border-radius: 12px;
  box-shadow: var(--shadow);
  text-align: center;
}
.welcome-card h2 {
  font-size: 1.4rem;
  color: var(--primary-dark);
  margin-bottom: 16px;
}
.welcome-card p {
  margin-bottom: 12px;
  font-size: 0.95rem;
}
.welcome-note {
  color: var(--text-muted);
  font-size: 0.85rem !important;
  margin-top: 8px;
}
.welcome-resume {
  background: var(--primary-light);
  border-radius: 8px;
  padding: 16px;
  margin: 20px 0;
}
.welcome-resume p {
  font-weight: 700;
  color: var(--primary-dark);
  margin-bottom: 12px;
}
.welcome-resume .btn { margin: 4px 6px; }
.welcome-resume .resume-divider {
  border: none;
  border-top: 1px solid #ccc;
  margin: 12px 0 8px;
}
.btn-danger {
  background: #CC3333;
  color: #fff;
  border: none;
}
.btn-danger:hover {
  background: #AA2222;
}
.btn-small {
  padding: 6px 14px;
  font-size: 0.8rem;
}

/* ===== フォームコンテナ ===== */
.form-container {
  max-width: 640px;
  margin: 0 auto;
  padding: 20px 16px;
}

/* セクションタイトル */
.section-header {
  margin-bottom: 24px;
}
.section-title {
  font-size: 1.25rem;
  color: var(--primary-dark);
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-icon {
  font-size: 1.3rem;
}
.section-description {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 6px;
}

/* サブセクション */
.subsection {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}
.subsection-title {
  font-size: 1.05rem;
  color: var(--primary);
  margin-bottom: 16px;
  font-weight: 700;
}

/* ===== フォーム部品 ===== */
.field-group {
  margin-bottom: 24px;
}
.field-label {
  display: block;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--label);
  margin-bottom: 8px;
  line-height: 1.5;
}
.field-label .required {
  color: var(--error);
  font-size: 0.8rem;
  margin-left: 4px;
}

/* --- コンパクトセクション --- */
.compact-section .field-group { margin-bottom: 10px; }

/* --- インラインフィールド（ラベル+入力を同一行） --- */
.field-group.field-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.field-inline .field-label {
  min-width: 180px;
  max-width: 220px;
  margin-bottom: 0;
  flex-shrink: 0;
  font-size: 0.9rem;
  text-align: right;
  white-space: nowrap;
}
.field-inline .field-input {
  flex: 1;
  padding: 8px 10px;
}
.field-inline .options-group {
  flex-direction: row;
  flex-wrap: wrap;
  flex: 1;
}
.field-inline .radio-label,
.field-inline .checkbox-label {
  padding: 6px 12px;
  min-height: 36px;
  border: none;
  font-size: 0.9rem;
}
.field-inline .radio-label:hover,
.field-inline .checkbox-label:hover {
  background: var(--primary-light);
}
.field-inline .date-select-group {
  flex: 1;
}
.field-inline .date-select-group select {
  padding: 8px 6px;
  font-size: 0.9rem;
}
/* インラインのエラーは行の下に折り返し表示 */
.field-group.field-inline {
  flex-wrap: wrap;
}
.field-inline .field-error {
  flex-basis: 100%;
  margin-left: 0;
  padding-left: calc(110px + 8px);
}

/* --- セクション内ヘッダー --- */
.field-header {
  margin: 20px 0 8px;
  padding: 8px 0 6px;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 700;
}

/* --- セレクト（プルダウン） --- */
.field-select {
  padding: 8px 10px;
  font-size: 1rem;
  font-family: var(--font-main);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  width: 100%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23888' fill='none' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}
.field-select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59,134,134,0.15);
}
.field-inline .field-select {
  flex: 1;
  padding: 8px 10px;
}

/* --- 郵便番号入力 --- */
.postal-group {
  display: flex;
  gap: 8px;
  flex: 1;
  align-items: center;
}
.postal-group .field-input {
  width: 130px;
  flex: none;
}
.postal-btn {
  padding: 8px 12px;
  font-size: 0.8rem;
  font-family: var(--font-main);
  font-weight: 700;
  background: var(--primary-light);
  color: var(--primary-dark);
  border: 1.5px solid var(--primary);
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s;
}
.postal-btn:hover { background: #d0eaea; }
.postal-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.postal-status {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* テキスト入力 */
.field-input {
  width: 100%;
  padding: 12px 14px;
  font-size: 1rem;
  font-family: var(--font-main);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
  -webkit-appearance: none;
  appearance: none;
}
.field-input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59,134,134,0.15);
}
.field-input::placeholder { color: #B0B0B0; }
textarea.field-input {
  min-height: 100px;
  resize: vertical;
}

/* ラジオボタン・チェックボックス */
.options-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.radio-label, .checkbox-label {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  font-size: 0.95rem;
  min-height: 48px;
  user-select: none;
}
.radio-label:hover, .checkbox-label:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

/* カスタムラジオ */
.radio-label input[type="radio"],
.checkbox-label input[type="checkbox"] {
  display: none;
}
.radio-custom {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: border-color 0.2s;
}
.radio-custom::after {
  content: '';
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--primary);
  transform: scale(0);
  transition: transform 0.15s;
}
.radio-label input:checked ~ .radio-custom {
  border-color: var(--primary);
}
.radio-label input:checked ~ .radio-custom::after {
  transform: scale(1);
}
.radio-label:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-light);
}

/* カスタムチェックボックス */
.checkbox-custom {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: border-color 0.2s, background 0.2s;
}
.checkbox-custom::after {
  content: '✓';
  font-size: 14px;
  color: #fff;
  opacity: 0;
  transition: opacity 0.15s;
}
.checkbox-label input:checked ~ .checkbox-custom {
  border-color: var(--primary);
  background: var(--primary);
}
.checkbox-label input:checked ~ .checkbox-custom::after {
  opacity: 1;
}
.checkbox-label:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-light);
}

/* 「その他」テキスト入力 */
.other-input-wrapper {
  margin-top: 8px;
  display: none;
}
.other-input-wrapper.visible {
  display: block;
}
.other-input-wrapper .field-input {
  margin-top: 4px;
}

/* チェックボックス詳細入力（checkbox_detail） */
.detail-input-wrapper {
  margin: 2px 0 6px 28px;
  display: none;
}
.detail-input-wrapper.visible {
  display: block;
}
.detail-input-wrapper .field-input {
  font-size: 0.9em;
}

/* 日付セレクト */
.date-select-group {
  display: flex;
  gap: 8px;
  align-items: center;
}
.date-select-group select {
  padding: 12px 8px;
  font-size: 1rem;
  font-family: var(--font-main);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}
.date-select-group select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59,134,134,0.15);
}
.date-select-group .date-year { flex: 2; }
.date-select-group .date-month { flex: 1; }
.date-select-group .date-day { flex: 1; }
.date-select-group .date-sep {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* 家族構成: 行形式 動的追加UI */
.family-members-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
}
.family-row {
  display: flex;
  gap: 6px;
  align-items: center;
}
.family-rel-sel {
  width: auto;
  min-width: 90px;
  max-width: 110px;
  padding: 7px 24px 7px 8px;
  font-size: 0.85rem;
  flex-shrink: 0;
}
.family-gender-sel {
  width: auto;
  min-width: 68px;
  max-width: 80px;
  padding: 7px 22px 7px 6px;
  font-size: 0.85rem;
  flex-shrink: 0;
}
.family-name-input {
  flex: 1;
  min-width: 60px;
  padding: 7px 8px;
  font-size: 0.9rem;
}
.family-remark-input {
  flex: 2;
  min-width: 80px;
  padding: 7px 8px;
  font-size: 0.9rem;
}
.family-row-remove {
  background: none;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px 6px;
  border-radius: 4px;
  line-height: 1;
  flex-shrink: 0;
}
.family-row-remove:hover {
  background: #fee;
  color: #c00;
}
.family-row-wrapper {
  display: flex;
  flex-direction: column;
}
.family-spouse-sub {
  margin-left: 24px;
  margin-top: 2px;
  margin-bottom: 4px;
}
.family-spouse-sub .family-marriage-age {
  padding: 6px 8px;
  font-size: 0.85rem;
  max-width: 300px;
  border: 1.5px dashed var(--border);
  border-radius: 6px;
}
.family-spouse-sub .family-marriage-age:focus {
  border-style: solid;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59,134,134,0.15);
}
.family-contact-sub {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: 24px;
  margin-top: 2px;
  margin-bottom: 4px;
}
.family-contact-sub .family-contact-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}
.family-contact-sub .family-phone-input,
.family-contact-sub .family-address-input {
  flex: 1;
  padding: 6px 8px;
  font-size: 0.85rem;
  border: 1.5px dashed var(--border);
  border-radius: 6px;
}
.family-contact-sub .family-address-input {
  flex: 2;
}
.family-contact-sub .family-phone-input:focus,
.family-contact-sub .family-address-input:focus {
  border-style: solid;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59,134,134,0.15);
}
.family-add-btn {
  align-self: flex-start;
  padding: 6px 14px;
  font-size: 0.85rem;
}
/* ページ2: 案内バナー */
.page2-banner {
  background: var(--primary-light);
  border-left: 4px solid var(--primary);
  padding: 12px 16px;
  margin-bottom: 20px;
  border-radius: 0 8px 8px 0;
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--primary-dark);
}

/* ページ2: セクション区切り */
.page2-section {
  margin-bottom: 32px;
  padding-bottom: 16px;
  border-bottom: 2px solid var(--border);
}
.page2-section:last-child {
  border-bottom: none;
}

/* ヒントテキスト */
.field-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  flex-basis: 100%;
  padding-left: calc(110px + 8px);
  margin-top: -2px;
}
@media (min-width: 768px) {
  .field-hint { padding-left: calc(140px + 8px); }
}

/* エラー表示 */
.field-error {
  color: var(--error);
  font-size: 0.8rem;
  margin-top: 6px;
  display: none;
}
.field-error.visible { display: block; }
.field-input.error { border-color: var(--error); }

/* ===== 確認画面 ===== */
.preview-section {
  background: var(--card-bg);
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-bottom: 12px;
  overflow: hidden;
}
.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  background: var(--primary-light);
  cursor: pointer;
  user-select: none;
}
.preview-header h3 {
  font-size: 0.95rem;
  color: var(--primary-dark);
}
.preview-header .edit-btn {
  font-size: 0.8rem;
  color: var(--primary);
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--font-main);
  font-weight: 700;
  padding: 4px 8px;
}
.preview-body {
  padding: 12px 16px;
  display: none;
}
.preview-section.open .preview-body { display: block; }
.preview-item {
  padding: 6px 0;
  border-bottom: 1px solid #f0f0f0;
  display: flex;
  gap: 8px;
}
.preview-item:last-child { border-bottom: none; }
.preview-item-label {
  color: var(--text-muted);
  font-size: 0.8rem;
  min-width: 120px;
  flex-shrink: 0;
}
.preview-item-value {
  font-size: 0.9rem;
  word-break: break-all;
}
.preview-item-empty {
  color: var(--text-muted);
  font-style: italic;
}

.confirm-check {
  margin: 24px 0;
  text-align: center;
}
.confirm-check .checkbox-label {
  display: inline-flex;
  border: none;
  padding: 8px 0;
  font-weight: 700;
}

/* ===== 送信完了画面 ===== */
.done-icon {
  font-size: 3rem;
  margin-bottom: 16px;
}
.done-note {
  color: var(--text-muted);
  margin-top: 16px;
}

/* ===== ボタン ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 24px;
  font-size: 1rem;
  font-family: var(--font-main);
  font-weight: 700;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  user-select: none;
  min-height: 48px;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--btn-primary);
  color: #fff;
}
.btn-primary:hover { background: var(--btn-primary-hover); }

.btn-secondary {
  background: var(--btn-secondary);
  color: var(--text);
}
.btn-secondary:hover { background: var(--btn-secondary-hover); }

.btn-submit {
  background: var(--btn-submit);
  color: #fff;
  width: 100%;
  font-size: 1.1rem;
  padding: 16px;
}
.btn-submit:hover:not(:disabled) { background: var(--btn-submit-hover); }
.btn-submit:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-large {
  padding: 16px 40px;
  font-size: 1.1rem;
  margin-top: 16px;
}

.nav-arrow { font-size: 0.8em; }

/* ===== フッターナビ ===== */
#nav-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #fff;
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 100;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.06);
}
.nav-step-label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ===== レスポンシブ ===== */
@media (min-width: 768px) {
  .form-container { padding: 32px 24px; }
  .welcome-card { padding: 48px 40px; }
  #progress-bar { padding: 14px 24px; }
  .progress-step .step-label { display: inline; }
  .field-inline .field-label { min-width: 200px; }
  .field-inline .field-error { padding-left: calc(200px + 8px); }
}

@media (max-width: 500px) {
  .field-inline .field-label {
    min-width: 130px;
    max-width: 160px;
    font-size: 0.8rem;
  }
  .field-inline .field-input { font-size: 0.9rem; }
  .field-inline .field-select { font-size: 0.9rem; }
  .postal-group .field-input { width: 110px; }
  .family-row { flex-wrap: wrap; }
  .family-rel-sel { min-width: 80px; }
  .family-name-input { min-width: 50px; }
  .family-remark-input { min-width: 60px; flex-basis: 100%; }
  .family-contact-sub { flex-wrap: wrap; }
  .family-contact-sub .family-phone-input,
  .family-contact-sub .family-address-input { flex-basis: 100%; }
}

@media (max-width: 400px) {
  .date-select-group { flex-wrap: wrap; }
  .date-select-group .date-sep { display: none; }
  .field-group.field-inline {
    flex-wrap: wrap;
  }
  .field-inline .field-label {
    min-width: 100%;
    text-align: left;
    margin-bottom: 4px;
  }
}

/* ===== ローディング ===== */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text {
  margin-top: 16px;
  color: var(--primary-dark);
  font-weight: 700;
}
