:root {
  color-scheme: dark light;
  --bg: #0f1219;
  --surface: #171c27;
  --border: rgba(255,255,255,0.08);
  --text: #e8eaef;
  --muted: #9aa3b5;
  --accent: #7c6cf9;
  --accent-dim: rgba(124,108,249,0.2);
  --user: #263349;
  --assistant: #1e232e;
  --system: #3d2a1f;
  --radius: 14px;
  --font: "IBM Plex Sans", system-ui, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fb; --surface: #ffffff;
    --border: rgba(15,18,25,0.1); --text: #121722;
    --muted: #5c6578; --accent: #5a48e8;
    --accent-dim: rgba(90,72,232,0.12);
    --user: #dce6ff; --assistant: #eef0f6; --system: #ffe8d9;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

code {
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 0.9em;
  padding: .1em .35em;
  border-radius: 6px;
  background: var(--accent-dim);
}

.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 860px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 2rem;
}

/* ── 헤더 ── */
.header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.title { font-size: 1.35rem; font-weight: 600; letter-spacing: -.02em; margin: 0 0 .35rem; }
.subtitle { margin: 0; color: var(--muted); font-size: .95rem; max-width: 36rem; }

.header-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .65rem; }

.session-pill {
  display: flex; align-items: center; gap: .45rem;
  padding: .35rem .65rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  max-width: min(320px, 100%);
}
.session-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.session-id { font-size: .75rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; background: transparent; padding: 0; }

/* ── 채팅 패널 ── */
.main { flex: 1; min-height: 0; }

.chat-panel {
  display: flex; flex-direction: column;
  height: min(72vh, 640px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 18px 48px rgba(0,0,0,.18);
}

.messages {
  flex: 1; overflow-y: auto;
  padding: 1rem 1rem .75rem;
  display: flex; flex-direction: column; gap: .65rem;
}

.empty { margin: auto; text-align: center; color: var(--muted); font-size: .95rem; padding: 2rem 1rem; }

/* ── 말풍선 ── */
.bubble {
  align-self: flex-start;
  max-width: 92%;
  padding: .55rem .75rem .65rem;
  border-radius: 12px;
  border: 1px solid var(--border);
}
.bubble.user      { align-self: flex-end; background: var(--user); }
.bubble.assistant { background: var(--assistant); }
.bubble.system    { background: var(--system); border-style: dashed; }

.bubble-meta {
  display: block; font-size: .68rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); margin-bottom: .35rem;
}
.bubble-text { margin: 0; white-space: pre-wrap; word-break: break-word; font-family: inherit; font-size: .95rem; }

/* 타이핑 점 */
.bubble.typing .dots { display: flex; gap: .35rem; padding: .35rem 0; }
.bubble.typing .dots span {
  width: .4rem; height: .4rem; border-radius: 50%;
  background: var(--muted); opacity: .45;
  animation: bounce 1s ease-in-out infinite;
}
.bubble.typing .dots span:nth-child(2) { animation-delay: .15s; }
.bubble.typing .dots span:nth-child(3) { animation-delay: .3s; }

@keyframes bounce {
  0%,80%,100% { transform: translateY(0); opacity: .35; }
  40%          { transform: translateY(-4px); opacity: .9; }
}

/* ── 입력창 ── */
.composer { border-top: 1px solid var(--border); padding: .75rem 1rem 1rem; background: var(--surface); }

.input {
  width: 100%; resize: vertical;
  min-height: 3.25rem; max-height: 9rem;
  padding: .65rem .75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg); color: var(--text);
  font-family: inherit; font-size: .95rem;
  margin-bottom: .55rem;
}
.input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.input:disabled { opacity: .65; }

.composer-row { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; }
.hint { font-size: .78rem; color: var(--muted); }

/* ── 버튼 ── */
.btn {
  font-family: inherit; font-size: .88rem; font-weight: 600;
  border-radius: 10px; border: 1px solid transparent;
  padding: .45rem .95rem; cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:disabled { cursor: not-allowed; opacity: .55; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.06); }
.btn.ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn.ghost:hover:not(:disabled) { border-color: var(--muted); }
