/* AI受診ナビ - モバイルファースト */
:root {
  --c-bg: #f4f7fb;
  --c-surface: #ffffff;
  --c-text: #1f2a37;
  --c-muted: #64748b;
  --c-border: #e2e8f0;
  --c-primary: #1f7a8c;
  --c-primary-dark: #17616f;
  --c-primary-soft: #e3f2f5;
  --c-user: #d9f0e6;
  --c-danger: #d7263d;
  --c-danger-soft: #fdecef;
  --c-warn: #b45309;
  --c-warn-soft: #fef3c7;
  --c-ok: #15803d;
  --c-ok-soft: #dcfce7;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .06);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", Meiryo, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--c-text);
  background: var(--c-bg);
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--c-primary); }
[hidden] { display: none !important; }

/* header */
.app-header {
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  position: sticky; top: 0; z-index: 10;
}
.app-header__inner {
  max-width: 720px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.app-header__title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.app-header__icon { font-size: 26px; }
.app-header__name { font-weight: 700; font-size: 17px; line-height: 1.2; }
.app-header__clinic { font-size: 12px; color: var(--c-muted); }

/* main */
.app-main { flex: 1; width: 100%; max-width: 720px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: 10px;
  padding: 10px 16px; font-size: 15px; font-weight: 600; cursor: pointer;
  text-decoration: none; line-height: 1.3; transition: background .15s, opacity .15s;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn--primary { background: var(--c-primary); color: #fff; }
.btn--primary:not(:disabled):hover { background: var(--c-primary-dark); }
.btn--ghost { background: var(--c-surface); color: var(--c-primary); border-color: var(--c-border); }
.btn--danger { background: var(--c-danger); color: #fff; }
.btn--block { width: 100%; padding: 14px; font-size: 16px; }
.btn--sm { padding: 6px 12px; font-size: 13px; }

/* consent */
.consent { background: var(--c-surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px 20px; }
.consent__title { font-size: 22px; line-height: 1.4; margin: 0 0 12px; }
.consent__lead { margin: 0 0 18px; color: #334155; }
.notice { background: var(--c-warn-soft); border-radius: 10px; padding: 14px 16px; margin-bottom: 18px; }
.notice__title { font-weight: 700; color: var(--c-warn); margin-bottom: 6px; font-size: 14px; }
.notice__list { margin: 0; padding-left: 18px; font-size: 14px; }
.notice__list li + li { margin-top: 6px; }
.consent__check { display: flex; align-items: center; gap: 10px; margin: 0 0 14px; font-weight: 600; cursor: pointer; }
.consent__check input { width: 20px; height: 20px; }
.consent__foot { margin: 16px 0 0; font-size: 12px; color: var(--c-muted); text-align: center; }

/* chat */
.chat { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat__log { flex: 1; display: flex; flex-direction: column; gap: 12px; padding-bottom: 8px; }
.msg { display: flex; gap: 8px; max-width: 92%; }
.msg--assistant { align-self: flex-start; }
.msg--user { align-self: flex-end; flex-direction: row-reverse; }
.msg__avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--c-primary-soft); display: flex; align-items: center; justify-content: center; font-size: 18px; flex: none; }
.msg__bubble {
  background: var(--c-surface); border-radius: var(--radius); padding: 10px 14px;
  box-shadow: var(--shadow); white-space: pre-wrap; word-break: break-word; font-size: 15px;
}
.msg--user .msg__bubble { background: var(--c-user); box-shadow: none; }
.msg--error .msg__bubble { background: var(--c-danger-soft); color: var(--c-danger); }
.msg__time { font-size: 11px; color: var(--c-muted); margin-top: 4px; }

.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: #94a3b8; animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* quick replies */
.chat__quick { display: flex; flex-wrap: wrap; gap: 8px; padding: 6px 0; }
.chat__quick:empty { display: none; }
.quick { background: var(--c-surface); border: 1px solid var(--c-primary); color: var(--c-primary); border-radius: 999px; padding: 7px 14px; font-size: 14px; cursor: pointer; }
.quick:hover { background: var(--c-primary-soft); }

/* input */
.chat__form { position: sticky; bottom: 0; display: flex; gap: 8px; align-items: flex-end; background: var(--c-bg); padding: 8px 0 4px; }
.chat__form textarea {
  flex: 1; resize: none; border: 1px solid var(--c-border); border-radius: 12px; padding: 11px 14px;
  font: inherit; font-size: 16px; max-height: 140px; background: var(--c-surface);
}
.chat__form textarea:focus { outline: 2px solid var(--c-primary); outline-offset: -1px; }
.chat__send { padding: 11px 18px; }
.chat__disclaimer { margin: 4px 0 0; font-size: 11px; color: var(--c-muted); text-align: center; }

/* result card */
.result { background: var(--c-surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-top: 4px; }
.result__head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.result__title { font-weight: 700; font-size: 16px; }
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.badge--emergency { background: var(--c-danger-soft); color: var(--c-danger); }
.badge--today { background: #fee2e2; color: #b91c1c; }
.badge--within_days { background: var(--c-warn-soft); color: var(--c-warn); }
.badge--routine { background: var(--c-primary-soft); color: var(--c-primary-dark); }
.badge--self_care { background: var(--c-ok-soft); color: var(--c-ok); }
.result__summary { font-size: 14px; color: #334155; margin: 0 0 12px; }
.result__section { margin-top: 12px; }
.result__label { font-size: 12px; font-weight: 700; color: var(--c-muted); letter-spacing: .04em; margin-bottom: 6px; }
.cond { border: 1px solid var(--c-border); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; }
.cond__head { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.cond__num { width: 22px; height: 22px; border-radius: 50%; background: var(--c-primary); color: #fff; font-size: 12px; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.cond__lik { margin-left: auto; font-size: 11px; color: var(--c-muted); font-weight: 600; }
.cond__desc { font-size: 13px; color: #334155; margin-top: 4px; }
.result__list { margin: 0; padding-left: 18px; font-size: 14px; }
.result__advice { font-size: 14px; white-space: pre-wrap; }
.result__redflags { background: var(--c-danger-soft); border-radius: 10px; padding: 10px 12px; }
.result__redflags .result__label { color: var(--c-danger); }
.result__actions { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.result__clinic { font-size: 13px; color: var(--c-muted); margin-top: 8px; }
.result__foot { font-size: 12px; color: var(--c-muted); margin-top: 12px; border-top: 1px dashed var(--c-border); padding-top: 8px; }

/* emergency banner */
.emergency-banner { background: var(--c-danger-soft); border: 2px solid var(--c-danger); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; }
.emergency-banner__title { font-weight: 800; color: var(--c-danger); font-size: 17px; }
.emergency-banner__body { margin: 4px 0 10px; font-size: 14px; }
.emergency-banner__actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* footer */
.app-footer { max-width: 720px; margin: 0 auto; padding: 16px; font-size: 12px; color: var(--c-muted); text-align: center; width: 100%; }
.app-footer div + div { margin-top: 2px; }

@media (min-width: 640px) {
  .result__actions { flex-direction: row; }
  .result__actions .btn { flex: 1; }
}

/* quick replies: 複数選択 */
.chat__quick-hint { width: 100%; font-size: 12px; color: var(--c-muted); }
.quick--multi { position: relative; padding-left: 28px; }
.quick--multi::before { content: ""; position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 12px; height: 12px; border: 2px solid var(--c-primary); border-radius: 3px; background: var(--c-surface); }
.quick--on { background: var(--c-primary); color: #fff; }
.quick--on::before { background: #fff; border-color: #fff; box-shadow: inset 0 0 0 3px var(--c-primary); }
.chat__quick-send { width: 100%; margin-top: 4px; }

/* 問診のまとめ (結果カード内) */
.result__chart { border: 1px solid var(--c-border); border-radius: 10px; padding: 8px 12px; }
.result__chart summary { cursor: pointer; font-size: 14px; font-weight: 600; color: var(--c-primary-dark); }
.chart__dl { margin: 8px 0 0; display: grid; grid-template-columns: max-content 1fr; gap: 4px 8px; font-size: 13px; }
.chart__dl dt { font-weight: 700; white-space: nowrap; }
.chart__dl dd { margin: 0; white-space: pre-wrap; }
@media (max-width: 480px) { .chart__dl { grid-template-columns: 1fr; } }

/* 画像添付 */
.chat__attach { padding: 11px 12px; font-size: 18px; line-height: 1; }
.attach-picker { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius); padding: 12px 14px; margin: 6px 0; box-shadow: var(--shadow); }
.attach-picker__title { font-weight: 700; font-size: 14px; margin-bottom: 8px; }
.attach-picker__opts { display: flex; flex-wrap: wrap; gap: 8px; }
.quick--cancel { border-color: var(--c-border); color: var(--c-muted); }
.attach-picker__note { font-size: 12px; color: var(--c-muted); margin-top: 8px; }
.attach-preview { display: flex; align-items: center; gap: 10px; background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius); padding: 8px 10px; margin: 6px 0; }
.attach-preview img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; }
.attach-preview__meta { display: flex; align-items: center; gap: 8px; font-size: 13px; flex: 1; }
.attach-preview__remove { border: none; background: var(--c-danger-soft); color: var(--c-danger); border-radius: 50%; width: 28px; height: 28px; cursor: pointer; flex: none; margin-left: auto; }
.msg__img { display: block; max-width: 220px; max-height: 220px; border-radius: 10px; margin-top: 8px; }

.attach-picker__lead { font-size: 13px; margin-bottom: 8px; }
.chat__attach-hint { font-size: 12px; color: var(--c-muted); margin: 2px 0 0 4px; }
