/* こもれび整体院 AIフロントデスク — mobile-first, no external assets. */

:root {
  --bg: #f5f3ec;
  --surface: #ffffff;
  --ink: #26302a;
  --muted: #6a756d;
  --line: #e2e0d6;
  --brand: #3f7a57;
  --brand-ink: #ffffff;
  --brand-soft: #e6f0e8;
  --sun: #f3c969;
  --banner-bg: #fff6dc;
  --banner-ink: #5e4a12;
  --warn-bg: #fdecea;
  --warn-ink: #8a2c22;
  --tag-handoff-bg: #e8eefb;
  --tag-handoff-ink: #2c4a8a;
  --tag-medical-bg: #fbeee4;
  --tag-medical-ink: #8a4a1c;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(38, 48, 42, 0.06), 0 2px 8px rgba(38, 48, 42, 0.05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171b18;
    --surface: #222823;
    --ink: #e7ece7;
    --muted: #9aa69d;
    --line: #333b35;
    --brand: #5c9e76;
    --brand-soft: #27352c;
    --banner-bg: #3a3218;
    --banner-ink: #f1dfa6;
    --warn-bg: #44221e;
    --warn-ink: #f4b8ae;
    --tag-handoff-bg: #22304d;
    --tag-handoff-ink: #b8c9f2;
    --tag-medical-bg: #45301f;
    --tag-medical-ink: #f2c9a6;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Yu Gothic", Meiryo,
    "Noto Sans JP", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.7;
  -webkit-text-size-adjust: 100%;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 760px;
  margin: 0 auto;
  background: var(--bg);
}

/* Header: a solid bar above the chat. The chat scrolls in its own area below it, never underneath. */
.header {
  position: relative;
  z-index: 1;
  flex: none;
  padding: 12px 16px 12px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 2px 8px rgba(38, 48, 42, 0.06);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { flex: none; border-radius: 10px; }
.title { margin: 0; font-size: 1.15rem; line-height: 1.3; font-weight: 700; letter-spacing: 0.02em; }
.title-sub { color: var(--brand); white-space: nowrap; }
.subtitle { margin: 2px 0 0; color: var(--muted); font-size: 0.8rem; line-height: 1.4; }

/* Banner: full disclaimer until the first question, then one compact line. */
.banner {
  margin: 10px 0 0;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--banner-bg);
  color: var(--banner-ink);
  font-size: 0.82rem;
  line-height: 1.6;
}
.banner p { margin: 0; }
.banner-link { color: inherit; font-weight: 600; font-size: 0.78rem; text-underline-offset: 2px; white-space: nowrap; }
.banner-short { display: none; }
.banner.compact {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
  padding: 5px 12px;
  font-size: 0.74rem;
  line-height: 1.5;
}
.banner.compact .banner-full { display: none; }
.banner.compact .banner-short {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.banner.compact .banner-link { font-size: 0.72rem; }
.about-short { display: none; }
/* Phones: the compact line must keep the whole disclaimer visible, so the link gets shorter. */
@media (max-width: 480px) {
  .banner.compact { gap: 6px; padding: 5px 10px; font-size: 0.7rem; }
  .banner.compact .about-long { display: none; }
  .banner.compact .about-short { display: inline; }
}

/* Chat */
.chat {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.msg { display: flex; flex-direction: column; max-width: 88%; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.bot { align-self: flex-start; align-items: flex-start; }

.bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-shadow: var(--shadow);
}
.msg.user .bubble { background: var(--brand); color: var(--brand-ink); border-bottom-right-radius: 6px; }
.msg.bot .bubble { background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 6px; }

.meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; font-size: 0.75rem; }
.source {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 600;
}
.source::before { content: "📄"; font-size: 0.7rem; }
.tag { padding: 2px 10px; border-radius: 999px; font-weight: 600; }
.tag.handoff { background: var(--tag-handoff-bg); color: var(--tag-handoff-ink); }
.tag.refuse_redirect { background: var(--tag-medical-bg); color: var(--tag-medical-ink); }

.notice {
  align-self: center;
  max-width: 92%;
  padding: 8px 14px;
  border-radius: 12px;
  background: var(--warn-bg);
  color: var(--warn-ink);
  font-size: 0.85rem;
  text-align: center;
}

/* Typing indicator */
.typing { display: inline-flex; gap: 5px; padding: 14px 16px; }
.typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted);
  animation: blink 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* Suggestions: above the composer on phones; moved under the welcome message on desktop (app.js). */
.suggestions { flex: none; padding: 0 16px 8px; }
.chat .suggestions { padding: 0; margin-top: -4px; }
.suggestions[hidden] { display: none; }
.suggestions-label { margin: 0 0 6px; font-size: 0.75rem; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  flex: none;
  padding: 7px 13px;
  border: 1px solid var(--brand);
  border-radius: 999px;
  background: var(--surface);
  color: var(--brand);
  font: inherit;
  font-size: 0.85rem;
  line-height: 1.3;
  cursor: pointer;
}
.chip:hover { background: var(--brand-soft); }
.chip:disabled { opacity: 0.5; cursor: default; }

/* Composer */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--bg);
}
.input-wrap { position: relative; flex: 1; }
textarea {
  display: block;
  width: 100%;
  min-height: 46px;
  max-height: 140px;
  padding: 11px 64px 11px 14px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 16px; /* >= 16px keeps iOS from zooming in */
  line-height: 1.5;
  resize: none;
}
textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; }
.counter {
  position: absolute;
  right: 14px;
  bottom: 12px;
  font-size: 0.72rem;
  color: var(--muted);
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}
.counter.over { color: var(--warn-ink); font-weight: 700; }
.send {
  flex: none;
  width: 46px;
  height: 46px;
  border: 0;
  border-radius: 50%;
  background: var(--brand);
  color: var(--brand-ink);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.send:disabled { opacity: 0.4; cursor: default; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); border: 0;
}

@media (min-width: 720px) {
  .app { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
  .title { font-size: 1.3rem; }
  .msg { max-width: 76%; }
}

@media (prefers-reduced-motion: reduce) {
  .chat { scroll-behavior: auto; }
  .typing span { animation: none; opacity: 0.6; }
}
