/* elpi — Faith Companion UI */
:root {
  --bg: #ffffff;
  --bg-elevated: #ffffff;
  --bg-soft: #f0f4f8;
  --panel: #f7f7f8;
  --text: #242424;
  --text-muted: #85858d;
  --accent: #252525;
  --accent-fg: #ffffff;
  --user: #f1f1f1;
  --line: #e8e8eb;
  --border: #dedee2;
  --quote-bg: #f8f9fb;
  --quote-border: #c5cdd8;
  --danger: #b42318;
  --header-h: 62px;
  --footer-h: 88px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --content-max: 820px;
  --font: "Noto Sans KR", "Noto Sans Hebrew", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}
body {
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }

.app {
  height: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 960px;
  margin: 0 auto;
  position: relative;
}

/* Header */
header {
  height: var(--header-h);
  flex: none;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  background: var(--bg);
  z-index: 10;
}
.brand {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: .04em;
}
.brand small {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
  margin-left: 8px;
  letter-spacing: 0;
}
.reset {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 9px;
  padding: 8px 12px;
  color: #666;
  font-size: 12px;
  cursor: pointer;
}

/* Main scroll */
main#scrollArea {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 28px 20px calc(var(--footer-h) + 12px);
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

/* Welcome */
.welcome {
  max-width: 650px;
  margin: 8vh auto 0;
  text-align: center;
}
.mark {
  width: 48px;
  height: 48px;
  margin: 0 auto 22px;
  border: 1px solid #ddd;
  border-radius: 16px;
  display: grid;
  place-items: center;
  font-size: 20px;
  font-weight: 600;
  background: var(--bg-soft);
}
.welcome h1 {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.8px;
  margin: 0 0 12px;
  line-height: 1.35;
}
.welcome p {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.7;
  margin: 0;
}
.suggestions {
  display: flex;
  gap: 9px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 28px;
}
.suggestions button {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 10px 14px;
  font-size: 12px;
  color: #555;
  cursor: pointer;
  transition: background .15s;
}
.suggestions button:hover { background: #f5f5f5; }

/* Messages */
.messages {
  max-width: var(--content-max);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 22px;
  width: 100%;
}
.msg {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  width: 100%;
}
.msg.user { justify-content: flex-end; }
.msg .avatar {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  border: 1px solid var(--line);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #444;
  background: var(--bg-soft);
  margin-top: 2px;
}
.msg.user .avatar { display: none; }
.content { min-width: 0; flex: 1; }
.msg.user .content {
  flex: 0 1 auto;
  max-width: min(640px, 92%);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}
.name {
  font-size: 11px;
  color: var(--text-muted);
  margin: 0 0 6px 1px;
}
.msg.user .name { text-align: right; margin-right: 2px; }
.bubble {
  font-size: 15px;
  line-height: 1.85;
  overflow-wrap: break-word;
  word-break: normal;
  unicode-bidi: plaintext;
}
.bubble.md { unicode-bidi: plaintext; width: 100%; }
.user .bubble {
  background: var(--user);
  padding: 12px 16px;
  border-radius: 18px 18px 4px 18px;
  white-space: pre-wrap;
}
.assistant .bubble { padding: 2px 0; width: 100%; }
.typing { color: var(--text-muted); font-size: 13px; }

/* Markdown */
.bubble.md p { margin: 0 0 0.75em; line-height: 1.85; }
.bubble.md p:last-child { margin-bottom: 0; }
.bubble.md h1, .bubble.md h2, .bubble.md h3, .bubble.md h4 {
  margin: 1.1em 0 0.45em;
  font-weight: 650;
  line-height: 1.35;
  letter-spacing: -0.02em;
}
.bubble.md h1 { font-size: 1.25em; }
.bubble.md h2 { font-size: 1.15em; }
.bubble.md h3 { font-size: 1.05em; }
.bubble.md h1:first-child, .bubble.md h2:first-child, .bubble.md h3:first-child { margin-top: 0; }
.bubble.md strong { font-weight: 650; }
.bubble.md em { font-style: italic; }
.bubble.md ul, .bubble.md ol { margin: 0.4em 0 0.8em; padding-left: 1.35em; }
.bubble.md li { margin: 0.25em 0; }
.bubble.md li > p { margin: 0; }
.bubble.md blockquote {
  margin: 0.7em 0;
  padding: 0.55em 0.9em;
  border-left: 3px solid var(--quote-border);
  background: var(--quote-bg);
  border-radius: 0 8px 8px 0;
  color: #333;
}
.bubble.md blockquote p { margin: 0.3em 0; }
.bubble.md code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.9em;
  background: #f0f1f3;
  padding: 0.12em 0.35em;
  border-radius: 4px;
}
.bubble.md pre {
  margin: 0.7em 0;
  padding: 0.75em 1em;
  background: #f4f5f7;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 0.88em;
  line-height: 1.55;
}
.bubble.md pre code { background: none; padding: 0; font-size: inherit; }
.bubble.md a { color: #2563eb; text-decoration: underline; text-underline-offset: 2px; }
.bubble.md hr { border: 0; border-top: 1px solid var(--line); margin: 1em 0; }

.error {
  color: var(--danger);
  font-size: 12px;
  margin: 10px auto;
  max-width: var(--content-max);
}

/* ===== Composer (ft_fixed style) ===== */
.footer-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  padding: 8px 16px calc(10px + var(--safe-b));
  background: linear-gradient(transparent, #fff 28%);
  pointer-events: none;
}
.footer-inner {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  box-sizing: border-box;
  pointer-events: auto;
  position: relative;
}
.input-group {
  width: 100%;
  min-height: 56px;
  height: 56px;
  margin: 0;
  position: relative;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: center; /* 한 줄일 때 세로 가운데 */
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 28px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
  padding: 0 14px;
  overflow: visible;
  flex-shrink: 0;
}
.composer-icon {
  position: absolute;
  z-index: 3;
  top: 50%;
  transform: translateY(-50%);
  bottom: auto;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  border-radius: 50%;
  cursor: pointer;
}
.composer-icon svg { width: 20px; height: 20px; }
.composer-icon:active { background: var(--bg-soft); }
#more-btn { left: 4px; }
#send-btn {
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  bottom: auto;
  background: var(--accent);
  color: var(--accent-fg);
  border-radius: 50%;
}
#send-btn:disabled { opacity: 0.35; cursor: default; }

#message-input {
  display: block;
  white-space: pre-wrap;
  width: 100%;
  min-width: 0;
  height: 24px;
  min-height: 24px;
  max-height: 72px;
  margin: 0;
  padding: 0 52px 0 36px;
  box-sizing: border-box;
  border: 0;
  outline: none;
  resize: none;
  overflow-x: hidden;
  overflow-y: hidden;
  background: transparent;
  box-shadow: none;
  font-family: inherit;
  font-size: 15px;
  line-height: 24px;
  color: var(--text);
}
.input-group:not(.is-multiline) #message-input {
  white-space: nowrap;
  overflow-x: hidden;
  overflow-y: hidden;
}
#message-input:focus {
  border: 0;
  outline: none;
  box-shadow: none;
  background: transparent;
}
#message-input::placeholder { color: #aaa; }

.input-group.is-multiline {
  padding: 12px 14px 48px 14px;
  min-height: 104px;
  height: auto;
  justify-content: flex-start;
}
.input-group.is-multiline #message-input {
  max-height: 72px;
  overflow-y: auto;
  padding-right: 0 !important;
  padding-left: 0 !important;
  white-space: pre-wrap;
}
.input-group.is-multiline .composer-icon {
  top: auto;
  bottom: 10px;
  transform: none;
}
.input-group.is-multiline #send-btn {
  top: auto;
  bottom: 10px;
  transform: none;
}

.composer-status {
  position: absolute;
  left: 48px;
  right: 56px;
  top: 50%;
  transform: translateY(-50%);
  display: none;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 20px;
  pointer-events: none;
}
.composer-status[aria-hidden="false"] { display: flex; }
.composer-status-bars {
  display: inline-flex;
  align-items: flex-end;
  gap: 3px;
  height: 16px;
}
.composer-status-bars span {
  display: block;
  width: 3px;
  height: 40%;
  min-height: 3px;
  background: var(--accent);
  border-radius: 2px;
  transform-origin: bottom center;
  animation: barPulse 0.9s ease-in-out infinite;
}
.composer-status-bars span:nth-child(1) { animation-delay: 0s; }
.composer-status-bars span:nth-child(2) { animation-delay: 0.12s; }
.composer-status-bars span:nth-child(3) { animation-delay: 0.24s; }
.composer-status-bars span:nth-child(4) { animation-delay: 0.36s; }
.composer-status-bars span:nth-child(5) { animation-delay: 0.48s; }
@keyframes barPulse {
  0%, 100% { height: 25%; opacity: 0.55; }
  50% { height: 100%; opacity: 1; }
}

.composer-meta {
  width: 100%;
  height: 14px;
  margin: 6px 0 0;
  padding: 0 4px;
  box-sizing: border-box;
  font-size: 10px;
  line-height: 14px;
  color: var(--text-muted);
  text-align: center;
  user-select: none;
}

/* Mobile */
@media (max-width: 600px) {
  header { padding: 0 16px; height: 56px; }
  main#scrollArea { padding: 24px 16px calc(var(--footer-h) + 8px); }
  .welcome { margin-top: 6vh; }
  .welcome h1 { font-size: 22px; }
  .messages { gap: 18px; }
  .footer-bar {
    padding-left: 12px;
    padding-right: 12px;
    /* 키보드 올라와도 배경이 튀지 않도록 */
    background: #fff;
  }
  .input-group {
    min-height: 52px;
    height: 52px;
    padding: 0 12px;
    border-radius: 26px;
    justify-content: center;
  }
  .input-group.is-multiline {
    min-height: 96px;
    height: auto;
    max-height: 140px;
    padding: 12px 12px 44px 12px;
    border-radius: 20px;
    justify-content: flex-start;
  }
  /* iOS 자동 확대 방지: 입력 폰트 16px 이상 */
  #message-input {
    font-size: 16px !important;
    height: 24px;
    min-height: 24px;
    line-height: 24px;
    padding-left: 28px;
    padding-right: 48px;
  }
  .composer-icon { width: 36px; height: 36px; }
  #more-btn { left: 6px; }
  #send-btn { right: 6px; }
  .composer-meta { font-size: 9px; }
}
@media (max-width: 480px) {
  .msg .avatar { display: none !important; }
  .msg { gap: 0; }
  .content { max-width: 100% !important; }
}
