/* ember remote — iPhone Safari 기준 모바일 우선, 다크 전용 */
:root {
  --bg: #0a0b0f;
  --bg-2: #0e1016;
  --surface: #171b24;
  --surface-2: #1f2431;
  --line: #262c3a;
  --text: #eef1f7;
  --muted: #929cae;
  --user: #c2410c;
  --user-2: #e2571a;
  --accent: #ff7a3d;
  --link: #7cc4ff;
  --ok: #3ddc97;
  --err: #ff6b6b;
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  font-size: 16px;
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Apple SD Gothic Neo",
    "Pretendard", "Malgun Gothic", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  overscroll-behavior-y: none;
  -webkit-text-size-adjust: 100%;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  /* iOS 키보드가 올라올 때 visualViewport 로 보정한 값 */
  height: calc(100dvh - var(--kb, 0px));
  max-width: 720px;
  margin: 0 auto;
  background: linear-gradient(180deg, var(--bg-2), var(--bg) 42%);
  position: relative;
}

/* ── 상단 바 ─────────────────────────────── */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(8px + var(--safe-t)) 14px 8px;
  background: rgba(10, 11, 15, 0.82);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--line);
  z-index: 5;
}

.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }

.brand-name {
  font-weight: 700;
  letter-spacing: 0.02em;
  font-size: 16px;
  background: linear-gradient(92deg, #ffcf9e, var(--accent) 60%, #ff5f2e);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.brand-sub {
  color: var(--muted);
  font-size: 12.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 rgba(0, 0, 0, 0);
  transition: background 0.25s, box-shadow 0.25s;
  flex: 0 0 auto;
}
.dot.ok { background: var(--ok); box-shadow: 0 0 10px rgba(61, 220, 151, 0.45); }
.dot.err { background: var(--err); box-shadow: 0 0 10px rgba(255, 107, 107, 0.4); }

.icon-btn {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, transform 0.1s;
}
.icon-btn:active { background: var(--surface); color: var(--text); transform: scale(0.94); }
.icon-btn.spin svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── 메시지 목록 ─────────────────────────── */
.messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 14px 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  scrollbar-width: thin;
}

.empty {
  margin: auto;
  text-align: center;
  color: var(--muted);
  font-size: 14.5px;
  line-height: 1.7;
  padding: 24px;
}
.empty strong { color: var(--text); font-weight: 600; display: block; margin-bottom: 6px; font-size: 15.5px; }

.msg {
  display: flex;
  flex-direction: column;
  max-width: 88%;
  min-width: 0;
  animation: pop 0.18s ease-out;
}
@keyframes pop {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.bot { align-self: flex-start; align-items: flex-start; }

.bubble {
  max-width: 100%;
  min-width: 0;
  padding: 10px 13px;
  border-radius: var(--radius);
  font-size: 16.5px;
  line-height: 1.58;
  word-break: break-word;
  overflow-wrap: anywhere;
  white-space: normal;
}

.msg.user .bubble {
  background: linear-gradient(180deg, var(--user-2), var(--user));
  color: #fff;
  border-bottom-right-radius: 6px;
  box-shadow: 0 2px 12px rgba(194, 65, 12, 0.22);
  white-space: pre-wrap;
}

.msg.bot .bubble {
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
  color: var(--text);
}

.meta {
  margin: 4px 6px 0;
  font-size: 11.5px;
  color: var(--muted);
  letter-spacing: 0.01em;
}

/* ── 말풍선 안 마크다운 ──────────────────── */
.bubble > :first-child { margin-top: 0; }
.bubble > :last-child { margin-bottom: 0; }

.bubble p { margin: 0.5em 0; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4, .bubble h5, .bubble h6 {
  margin: 0.7em 0 0.35em;
  line-height: 1.35;
  font-weight: 700;
}
.bubble h1 { font-size: 1.25em; }
.bubble h2 { font-size: 1.16em; }
.bubble h3 { font-size: 1.08em; }
.bubble h4, .bubble h5, .bubble h6 { font-size: 1em; }

.bubble strong { font-weight: 700; }
.bubble em { font-style: italic; }
.bubble del { opacity: 0.75; }

.bubble code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.88em;
  background: rgba(255, 255, 255, 0.09);
  border-radius: 6px;
  padding: 0.12em 0.36em;
}
.msg.user .bubble code { background: rgba(0, 0, 0, 0.22); }

.bubble pre {
  margin: 0.6em 0;
  padding: 10px 12px;
  background: #080a0e;
  border: 1px solid var(--line);
  border-radius: 10px;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.bubble pre code {
  background: none;
  padding: 0;
  font-size: 13.5px;
  line-height: 1.5;
  white-space: pre-wrap;   /* 폰에서는 접어서 보여준다(가로 스크롤 최소화) */
  overflow-wrap: anywhere;
}

.bubble ul, .bubble ol { margin: 0.45em 0; padding-left: 1.3em; }
.bubble li { margin: 0.2em 0; }
.bubble li > p { margin: 0.15em 0; }

.bubble a { color: var(--link); text-decoration: underline; text-underline-offset: 2px; }
.msg.user .bubble a { color: #d9ecff; }

.bubble blockquote {
  margin: 0.5em 0;
  padding: 0.1em 0 0.1em 0.75em;
  border-left: 3px solid var(--line);
  color: #cdd5e2;
}
.bubble hr { border: none; border-top: 1px solid var(--line); margin: 0.8em 0; }

/* ── 봇 작업 중 ─────────────────────────── */
.typing {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 18px 8px;
  color: var(--muted);
  font-size: 13.5px;
}
.typing[hidden] { display: none; }
.typing-dots { display: inline-flex; gap: 3px; }
.typing-dots i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.35;
  animation: blink 1.1s infinite ease-in-out;
}
.typing-dots i:nth-child(2) { animation-delay: 0.18s; }
.typing-dots i:nth-child(3) { animation-delay: 0.36s; }
@keyframes blink {
  0%, 80%, 100% { opacity: 0.28; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

/* ── 토스트 ─────────────────────────────── */
.toast {
  position: absolute;
  left: 50%;
  bottom: calc(150px + var(--safe-b));
  transform: translateX(-50%);
  max-width: 88%;
  padding: 9px 14px;
  border-radius: 12px;
  background: rgba(38, 44, 58, 0.96);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 13.5px;
  text-align: center;
  z-index: 20;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}
.toast[hidden] { display: none; }

/* ── 입력 영역 ───────────────────────────── */
.composer {
  flex: 0 0 auto;
  padding: 6px 10px calc(8px + var(--safe-b));
  background: rgba(10, 11, 15, 0.9);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  backdrop-filter: saturate(160%) blur(14px);
  border-top: 1px solid var(--line);
}

.quick {
  display: flex;
  gap: 8px;
  padding: 4px 2px 8px;
  overflow-x: auto;
  scrollbar-width: none;
}
.quick::-webkit-scrollbar { display: none; }

.quick-btn {
  flex: 1 1 0;
  min-width: 68px;
  height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-size: 15.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s, border-color 0.15s;
}
.quick-btn:active {
  transform: scale(0.96);
  background: var(--surface-2);
  border-color: var(--accent);
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.input {
  flex: 1 1 auto;
  min-height: 46px;
  max-height: 132px;
  padding: 12px 15px;
  border-radius: 22px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 16.5px; /* iOS 자동 확대 방지 */
  line-height: 1.4;
  resize: none;
  outline: none;
  overflow-y: auto;
  transition: border-color 0.15s, background 0.15s;
}
.input::placeholder { color: #6b7688; }
.input:focus { border-color: #3a4356; background: var(--surface-2); }

.send-btn {
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(180deg, var(--user-2), var(--user));
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.15s, filter 0.15s;
  box-shadow: 0 4px 14px rgba(194, 65, 12, 0.35);
}
.send-btn:active { transform: scale(0.93); }
.send-btn:disabled { opacity: 0.45; box-shadow: none; }

/* ── 접근성 ─────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

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