/* ===== DESIGN TOKENS ===== */
:root {
  --line-green:   #2563eb;
  --green:        #2563eb;
  --green-dark:   #1d4ed8;
  --green-light:  #eff6ff;
  --red:          #ef4444;
  --error-color:  #ef4444;
  --bg:           #f4f7fb;
  --card:         #ffffff;
  --text:         #0f172a;
  --text-sub:     #64748b;
  --sub:          #64748b;
  --border:       #cbd5e1;
  --border-color: #cbd5e1;
  --radius:       16px;
  --shadow:       0 4px 6px -1px rgba(0,0,0,0.06), 0 2px 4px -1px rgba(0,0,0,0.04);
}

*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html { font-size: 16px; }

body {
  margin: 0; padding: 0;
  font-family: 'Noto Sans JP', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}

/* ===== APP LAYOUT ===== */
.app-container {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ===== STICKY HEADER ===== */
.app-header {
  background: linear-gradient(135deg, var(--green-dark), var(--green));
  padding: 13px 16px 10px;
  position: sticky; top: 0; z-index: 100;
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}
.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 9px;
}
.app-header h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: #ffffff;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}
.lang-select {
  font-size: 13px; font-weight: 500;
  color: var(--text);
  background: rgba(255, 255, 255, 0.95);
  border: 1.5px solid transparent;
  border-radius: 8px;
  padding: 4px 8px;
  cursor: pointer;
  font-family: inherit;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23666'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  padding-right: 20px;
}
.lang-select:focus {
  border-color: var(--green);
}
.step-counter {
  font-size: 13px; font-weight: 700;
  color: var(--green-dark);
  background: #ffffff;
  padding: 3px 10px; border-radius: 20px;
  white-space: nowrap;
}
.progress-bar-container {
  width: 100%; height: 6px;
  background: #e0e0e0; border-radius: 3px; overflow: hidden;
}
.progress-bar {
  height: 100%; background: var(--green);
  transition: width 0.4s cubic-bezier(.4,0,.2,1);
}

/* ===== MAIN ===== */
.form-container { flex: 1; padding: 16px 14px 0; }

/* ===== STEP ANIMATION ===== */
.form-step { display: none; }
.form-step.active {
  display: block;
  animation: slideIn 0.28s ease;
}
@keyframes slideIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ===== SECTION TITLE ===== */
.step-title {
  font-size: 18px; font-weight: 700;
  color: var(--green-dark);
  border-left: 4px solid var(--green);
  padding-left: 12px;
  margin: 0 0 14px;
  line-height: 1.4;
}

/* ===== CARD ===== */
.input-group {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 16px;
  margin-bottom: 16px;
  border: 1px solid rgba(0,0,0,0.04);
  transition: transform 0.2s, box-shadow 0.2s;
}
.input-group:focus-within {
  transform: translateY(-2px);
  box-shadow: 0 8px 12px rgba(0,0,0,0.06);
}

/* ===== QUESTION LABEL ===== */
.input-group > label,
.q-label {
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 5px;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.5;
  margin-bottom: 13px;
  word-break: auto-phrase;
  overflow-wrap: break-word;
  line-break: strict;
}

/* ===== REQUIRED BADGE ===== */
.required {
  background: var(--red); color: #fff;
  font-size: 12px; font-weight: 700;
  padding: 2px 7px; border-radius: 4px;
  white-space: nowrap; flex-shrink: 0;
  margin-top: 3px; align-self: flex-start;
}

/* ===== TOOLTIP BUTTON ===== */
.tip-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; flex-shrink: 0;
  background: #eaeaea; color: #555;
  border: none; border-radius: 50%;
  font-size: 12px; font-weight: 700;
  cursor: pointer; margin-top: 2px;
  transition: background .2s;
}
.tip-btn:hover { background: #ccc; }
.tooltip-text {
  display: none;
  background: #333; color: #fff;
  font-size: 13px; font-weight: 400;
  padding: 8px 12px; border-radius: 8px;
  margin: 0 0 12px; line-height: 1.5;
}
.tooltip-text.show { display: block; }

/* ===== OPTION GROUPS ===== */
.radio-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.radio-group.vertical {
  flex-direction: column;
  gap: 8px;
}
.checkbox-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

/* ===== OPTION LABELS (radio + checkbox) ===== */
.radio-label,
.checkbox-label {
  position: relative;
  cursor: pointer;
  flex: 1;
  min-width: 80px;
  display: flex;
}
.radio-group.vertical .radio-label { flex: none; }

.radio-label input,
.checkbox-label input {
  position: absolute; opacity: 0; width: 0; height: 0;
}

.radio-label span,
.checkbox-label span {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 52px;
  padding: 10px 8px;
  background: #f6f8f7;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 15px; font-weight: 500;
  text-align: center;
  line-height: 1.4;
  word-break: keep-all;
  transition: all 0.18s;
}
.radio-group.vertical .radio-label span {
  justify-content: flex-start;
  padding: 13px 16px;
  min-height: 56px;
}

.radio-label input:checked + span,
.checkbox-label input:checked + span {
  background: var(--green-light);
  border-color: var(--green);
  color: var(--green-dark);
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.15);
  transform: translateY(-1px);
}

/* ===== TEXT INPUTS ===== */
input[type="text"],
input[type="tel"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 13px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 16px;
  font-family: inherit;
  line-height: 1.5;
  outline: none;
  transition: border-color .2s;
  -webkit-appearance: none;
  background: #fff;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.15);
}
textarea { resize: vertical; min-height: 88px; field-sizing: content; }

/* weight row */
.weight-row { display: flex; align-items: center; gap: 10px; }
.weight-row input { width: 130px; }
.weight-row span { font-size: 15px; color: var(--sub); }

/* ===== CONDITIONAL EXPAND ===== */
.sub-input {
  margin-top: 13px;
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition: max-height .35s ease, opacity .3s;
}
/* max-height を十分大きくしてドロップダウンが切れないように。
   overflow:visible にして position:absolute のサジェストが親にクリップされないようにする */
.sub-input.open { max-height: 800px; opacity: 1; overflow: visible; }
/* 旧スタイルとの互換性（hidden クラスも動作するように残す） */
.sub-input.hidden { max-height: 0 !important; opacity: 0 !important; overflow: hidden !important; }

/* hidden weight group */
#weight-input-group {
  margin-top: 8px;
  overflow: hidden;
  max-height: 0; opacity: 0;
  transition: max-height .35s ease, opacity .3s;
}
#weight-input-group.open { max-height: 160px; opacity: 1; }

/* hayfever sub */
#hayfever-subgroup {
  margin-top: 12px;
  overflow: hidden;
  max-height: 0; opacity: 0;
  transition: max-height .35s ease, opacity .3s;
}
#hayfever-subgroup.open { max-height: 300px; opacity: 1; }

.sub-section {
  padding: 13px;
  background: #f5faf7;
  border-radius: 10px;
  border-left: 3px solid var(--green);
}
.sub-section-label {
  font-size: 14px; font-weight: 700; color: #444;
  margin-bottom: 10px;
}

/* ===== INFO NOTE ===== */
.info-note {
  background: var(--green-light);
  border: 2px solid var(--green);
  padding: 13px 15px;
  border-radius: 12px;
  font-size: 15px; font-weight: 700;
  color: var(--green-dark);
  line-height: 1.6;
  margin-bottom: 12px;
}

/* ===== GENERIC EXPLANATION ===== */
.generic-note {
  background: #fffbe6;
  border: 1px solid #f0d060;
  padding: 10px 13px;
  border-radius: 10px;
  font-size: 13px; color: #7a6000;
  margin-bottom: 12px; line-height: 1.5;
}

/* ===== HINT TEXT ===== */
.hint {
  font-size: 13px; color: var(--sub);
  margin: -6px 0 10px;
}

/* mt-10ユーティリティ */
.mt-10 { margin-top: 10px; }

/* ===== CONFIRMATION VIEW ===== */
.confirmation-view {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 12px;
}
.conf-section {
  border-bottom: 2px solid var(--bg);
}
.conf-section:last-child { border-bottom: none; }
.conf-section-head {
  background: var(--green-light);
  padding: 9px 16px;
  font-size: 13px; font-weight: 700;
  color: var(--green-dark);
}
.conf-item {
  padding: 11px 16px;
  border-bottom: 1px solid #f0f0f0;
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.conf-item:last-child { border-bottom: none; }
.conf-label {
  font-size: 12px; color: var(--sub);
  flex-shrink: 0;
  width: 110px;
}
.conf-value {
  font-size: 15px; font-weight: 700;
  flex: 1;
  word-break: break-all;
}

/* ===== DATA NOTICE ===== */
.data-notice {
  font-size: 14px; color: var(--sub);
  background: #f6f8f7;
  border-left: 3px solid var(--green);
  padding: 10px 14px;
  border-radius: 10px;
  margin: 14px 0 10px;
  line-height: 1.6;
}

/* ===== AGREEMENT ===== */
.agreement { margin-top: 14px; }
.agree-box {
  display: flex; align-items: center;
  background: #edfff3;
  border: 2px solid var(--green);
  padding: 18px;
  border-radius: var(--radius);
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(6,199,85,.12);
  transition: transform .15s;
}
.agree-box:active { transform: scale(0.98); }
.agree-box input[type="checkbox"] {
  width: 28px; height: 28px; flex-shrink: 0;
  accent-color: var(--green); cursor: pointer; margin-right: 14px;
}
.agree-box span {
  font-size: 15px; font-weight: 700;
  color: var(--green-dark); line-height: 1.5;
}
.agree-box a { color: var(--green-dark); }

/* ===== NAV BUTTONS ===== */
.form-nav {
  padding: 18px 0 36px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#next-btn, #submit-btn {
  width: 100%;
  min-height: 56px;
  background: linear-gradient(135deg, var(--green), var(--green-dark));
  color: #fff;
  border: none; border-radius: 30px;
  font-size: 18px; font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 8px 16px rgba(37, 99, 235, 0.25);
  transition: transform .15s, box-shadow .15s;
  -webkit-appearance: none;
}
#next-btn:active, #submit-btn:active {
  transform: translateY(2px);
  box-shadow: 0 4px 8px rgba(37, 99, 235, 0.2);
}
#prev-btn {
  align-self: flex-start;
  background: none; border: none;
  font-size: 15px; font-weight: 500;
  color: var(--sub); cursor: pointer;
  padding: 6px 4px;
  text-decoration: underline;
  font-family: inherit;
  -webkit-appearance: none;
}

/* ===== HIDDEN ===== */
.hidden { display: none !important; }

/* ===== FOOTER ===== */
.app-footer {
  text-align: center; padding: 16px;
  color: #aaa; font-size: 12px;
}

/* ===== SUCCESS VIEW ===== */
.success-view {
  text-align: center; padding: 50px 20px;
}
.success-icon {
  font-size: 80px; color: var(--green); margin-bottom: 20px;
}
.success-view h2 {
  font-size: 22px; color: var(--text); margin-bottom: 12px;
}
.success-view p {
  font-size: 16px; color: #555; line-height: 1.7;
}

/* ===== RESPONSIVE (very small screens) ===== */
@media (max-width: 360px) {
  .checkbox-grid { grid-template-columns: 1fr 1fr; }
  .radio-label span, .checkbox-label span { font-size: 14px; }
}


/* Auto-complete specific styles */
.autocomplete-wrapper { position: relative; width: 100%; margin-top: 12px; }
.suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: white;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  max-height: 240px;
  overflow-y: scroll;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  z-index: 9999;
  display: none;
  text-align: left;
}
.suggestion-item { padding: 14px 16px; border-bottom: 1px solid #f0f0f0; cursor: pointer; font-size: 15px; color: var(--text); min-height: 48px; display: flex; align-items: center; }
.suggestion-item:last-child { border-bottom: none; }
.suggestion-item:hover, .suggestion-item:active { background: #e8f7ed; color: var(--green); font-weight: 700; }

.chip-container { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; text-align: left; }
.chip { background: #e8f7ed; color: var(--green-dark); border: 1px solid var(--green); padding: 8px 14px; border-radius: 20px; font-size: 14px; display: inline-flex; align-items: center; font-weight: 600; animation: popIn 0.2s ease-out;}
.chip-close { margin-left: 8px; cursor: pointer; color: var(--green-dark); font-size: 16px; padding: 0 4px;}
.chip-close:hover { color: var(--error-color); }

@keyframes popIn {
    0% { transform: scale(0.8); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

/* ===== ALLERGY CARD (症状B+Cハイブリッド) ===== */
.allergy-card {
  background: #fff;
  border: 1.5px solid var(--green);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 10px;
  width: 100%;
  animation: popIn 0.2s ease-out;
}
.allergy-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.allergy-med-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--green-dark);
  flex: 1;
  line-height: 1.4;
}
.chip-remove {
  background: none;
  border: none;
  color: #aaa;
  font-size: 20px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  flex-shrink: 0;
  -webkit-appearance: none;
}
.chip-remove:hover, .chip-remove:active { color: var(--error-color); }
.symptom-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--sub);
  margin-bottom: 8px;
}
.symptom-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}
.symptom-btn {
  padding: 7px 13px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  background: #f6f8f7;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
  transition: all 0.15s;
  min-height: 36px;
  -webkit-appearance: none;
}
.symptom-btn.active {
  background: var(--green-light);
  border-color: var(--green);
  color: var(--green-dark);
  font-weight: 700;
}
.symptom-btn:active { transform: scale(0.95); }
.symptom-note {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  box-sizing: border-box;
}
.symptom-note:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(6,199,85,.12);
  outline: none;
}
/* ===== REACTION BADGE（症状から自動判定バッジ） ===== */
.allergy-card-title {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
}
.reaction-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  width: fit-content;
}
.badge-allergy {
  background: #fff0f0;
  color: #d72020;
  border: 1px solid #d72020;
}
.badge-side-effect {
  background: #fff8e0;
  color: #8a6000;
  border: 1px solid #c8860a;
}
.badge-both {
  background: #fff4f0;
  color: #b03000;
  border: 1px solid #b03000;
}
.badge-none {
  background: #f0f0f0;
  color: #999;
  border: 1px solid #ccc;
  font-weight: 400;
}

/* ===== FOOD ALLERGY BUTTONS ===== */
.food-allergy-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}
.food-btn {
  padding: 9px 14px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  background: #f6f8f7;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
  transition: all 0.15s;
  min-height: 42px;
  -webkit-appearance: none;
}
.food-btn.active {
  background: var(--green-light);
  border-color: var(--green);
  color: var(--green-dark);
  font-weight: 700;
}
.food-btn:active { transform: scale(0.95); }
/* Sʃ[fBOI[o[C */
.submit-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.6);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 99999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
}
.submit-overlay.active {
    opacity: 1;
    pointer-events: auto;
}
.overlay-spinner {
    width: 50px;
    height: 50px;
    border: 5px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}
.overlay-text {
    color: white;
    font-size: 18px;
    font-weight: bold;
    text-align: center;
    line-height: 1.5;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}
@keyframes spin { 100% { transform: rotate(360deg); } }
