/* ============================================================
   모바일 에이전트 채팅방 — 스타일
   아이폰(iOS Safari) 기준 다크 모던 채팅 UI
   ============================================================ */

:root {
  --bg: #0b0e14;
  --bg-soft: #121722;
  --panel: #161c28;
  --panel-2: #1c2432;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #eef2f8;
  --text-dim: #97a3b6;
  --text-faint: #6b7688;
  --accent: #7c5cff;
  --accent-2: #22d3ee;
  --good: #34d399;
  --bad: #f87171;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --topbar-h: 58px;
  --composer-h: 76px;
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard",
               "Malgun Gothic", "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body {
  background:
    radial-gradient(1100px 520px at 12% -12%, rgba(124, 92, 255, 0.20), transparent 62%),
    radial-gradient(900px 460px at 96% 4%, rgba(34, 211, 238, 0.13), transparent 60%),
    var(--bg);
  min-height: 100vh;
  min-height: 100dvh;
}

.screen { min-height: 100vh; min-height: 100dvh; }
[hidden] { display: none !important; }

button { font-family: inherit; font-size: inherit; color: inherit; cursor: pointer; }
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88em;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 5px;
  padding: 1px 5px;
  word-break: break-all;
}

/* ============================================================
   1. 입장 화면
   ============================================================ */
#join-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(28px + var(--safe-top)) 20px calc(28px + var(--safe-bottom));
}

.join-wrap { width: 100%; max-width: 460px; }

.brand { text-align: center; margin-bottom: 26px; }

.brand-mark {
  width: 68px; height: 68px; margin: 0 auto 16px;
  display: grid; place-items: center;
  font-size: 34px;
  border-radius: 22px;
  background: linear-gradient(145deg, rgba(124, 92, 255, 0.32), rgba(34, 211, 238, 0.18));
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 16px 40px rgba(124, 92, 255, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.brand h1 {
  margin: 0 0 10px;
  font-size: 27px;
  line-height: 1.28;
  letter-spacing: -0.02em;
  font-weight: 800;
  background: linear-gradient(100deg, #ffffff 12%, #c9bfff 56%, #86eaff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-sub {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--text-dim);
}

.card {
  background: linear-gradient(180deg, rgba(28, 36, 50, 0.92), rgba(18, 23, 34, 0.92));
  border: 1px solid var(--line-strong);
  border-radius: 22px;
  padding: 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}

.field { display: block; margin-bottom: 14px; }
.field-label {
  display: block;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-dim);
  margin-bottom: 7px;
  letter-spacing: 0.02em;
}

#join-key {
  width: 100%;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--line-strong);
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.06em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
#join-key::placeholder { color: var(--text-faint); letter-spacing: 0.04em; }
#join-key:focus {
  border-color: rgba(124, 92, 255, 0.85);
  box-shadow: 0 0 0 3px rgba(124, 92, 255, 0.22);
}

.join-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }

.btn {
  border: none;
  border-radius: 13px;
  padding: 13px 14px;
  font-size: 15px;
  font-weight: 700;
  transition: transform .08s ease, filter .15s ease, opacity .15s;
  white-space: nowrap;
}
.btn:active { transform: scale(0.975); }
.btn:disabled { opacity: 0.55; }

.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, #7c5cff, #5b8cff 55%, #22d3ee);
  box-shadow: 0 10px 24px rgba(92, 110, 255, 0.36);
}
.btn-ghost {
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--line-strong);
}

.join-hint {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px dashed var(--line);
  font-size: 12.5px;
  line-height: 1.65;
  color: var(--text-faint);
}
.join-hint p { margin: 0 0 6px; }
.join-hint p:last-child { margin-bottom: 0; }
.join-hint strong { color: var(--text-dim); }

.join-foot {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin-top: 20px;
  font-size: 12px;
  color: var(--text-faint);
}
.dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-faint);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.05);
}
.dot.ok { background: var(--good); box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.18); }
.dot.bad { background: var(--bad); box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.18); }

/* ============================================================
   2. 채팅방 — 상단 바
   ============================================================ */
#room-screen {
  display: flex;
  flex-direction: column;
  height: 100vh;      /* 구형 iOS 폴백 */
  height: 100dvh;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(8px + var(--safe-top)) 12px 8px;
  min-height: calc(var(--topbar-h) + var(--safe-top));
  background: rgba(11, 14, 20, 0.82);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  border-bottom: 1px solid var(--line);
  z-index: 20;
  flex: 0 0 auto;
}

.icon-btn {
  width: 38px; height: 38px;
  flex: 0 0 auto;
  display: grid; place-items: center;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  font-size: 17px;
  color: var(--text-dim);
}
.icon-btn:active { background: rgba(255, 255, 255, 0.12); }
.icon-btn.spinning { animation: spin .7s linear infinite; color: var(--accent-2); }
@keyframes spin { to { transform: rotate(360deg); } }

.topinfo { flex: 1 1 auto; min-width: 0; }
.topinfo h2 {
  margin: 0;
  font-size: 15.5px;
  font-weight: 800;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.key-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
  padding: 1px 7px;
  border-radius: 7px;
  border: none;
  background: rgba(124, 92, 255, 0.16);
  color: #c9bfff;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  letter-spacing: 0.04em;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 초대 · API 바 */
.invite-bar {
  display: flex;
  gap: 8px;
  padding: 9px 12px;
  flex: 0 0 auto;
  border-bottom: 1px solid var(--line);
  background: rgba(18, 23, 34, 0.6);
}
.btn-invite {
  flex: 1 1 auto;
  padding: 10px 12px;
  font-size: 13.5px;
  border-radius: 11px;
  color: #d9d2ff;
  background: linear-gradient(135deg, rgba(124, 92, 255, 0.28), rgba(34, 211, 238, 0.16));
  border: 1px solid rgba(124, 92, 255, 0.45);
}
.btn-mini {
  flex: 0 0 auto;
  padding: 10px 13px;
  font-size: 13px;
  border-radius: 11px;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
}

/* ============================================================
   3. 메시지 목록
   ============================================================ */
.messages {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 12px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.day-divider {
  align-self: center;
  margin: 6px 0 2px;
  padding: 4px 13px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-faint);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.msg {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  animation: pop .18s ease-out;
}
@keyframes pop {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: none; }
}

.avatar {
  flex: 0 0 auto;
  width: 34px; height: 34px;
  border-radius: 11px;
  display: grid; place-items: center;
  font-size: 14px;
  font-weight: 800;
  color: #0b0e14;
  letter-spacing: -0.02em;
  user-select: none;
}

.msg-body { min-width: 0; flex: 1 1 auto; }

.msg-head {
  display: flex;
  align-items: baseline;
  gap: 7px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}
.msg-sender {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: -0.01em;
}
.msg-time {
  font-size: 10.5px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.bubble {
  position: relative;
  padding: 10px 13px;
  border-radius: 4px 14px 14px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 14.5px;
  line-height: 1.55;
  word-break: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.msg.mine .bubble {
  background: linear-gradient(135deg, rgba(124, 92, 255, 0.26), rgba(92, 140, 255, 0.16));
  border-color: rgba(124, 92, 255, 0.38);
  border-radius: 14px 4px 14px 14px;
}

.bubble .mention {
  color: #8ee7ff;
  font-weight: 700;
  background: rgba(34, 211, 238, 0.12);
  border-radius: 5px;
  padding: 0 3px;
}

.quote {
  display: block;
  margin: 0 0 7px;
  padding: 6px 9px;
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  background: rgba(255, 255, 255, 0.05);
  font-size: 12.5px;
  color: var(--text-dim);
  white-space: pre-wrap;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.quote b { color: var(--text); font-weight: 700; }

.msg-tools {
  display: flex;
  gap: 6px;
  margin-top: 5px;
}
.reply-btn {
  border: none;
  background: none;
  padding: 1px 2px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-faint);
}
.reply-btn:active { color: var(--accent-2); }

.empty {
  margin: auto;
  text-align: center;
  color: var(--text-faint);
  font-size: 13.5px;
  line-height: 1.75;
  padding: 24px 8px;
}
.empty .big { font-size: 34px; display: block; margin-bottom: 10px; }

.jump-latest {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--composer-h) + 18px + var(--safe-bottom));
  padding: 8px 15px;
  border-radius: 999px;
  border: 1px solid rgba(124, 92, 255, 0.55);
  background: rgba(28, 36, 50, 0.96);
  color: #d9d2ff;
  font-size: 12.5px;
  font-weight: 700;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.45);
  z-index: 15;
}

/* ============================================================
   4. 입력창
   ============================================================ */
.composer {
  flex: 0 0 auto;
  padding: 9px 10px calc(9px + var(--safe-bottom));
  background: rgba(11, 14, 20, 0.9);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--line);
  z-index: 18;
}

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 7px;
}

.sender-input {
  flex: 0 0 auto;
  width: 90px;
  padding: 10px 8px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-size: 16px;   /* iOS 자동 확대 방지 (16px 미만이면 화면이 확대됨) */
  font-weight: 700;
  text-align: center;
  outline: none;
  min-height: 40px;
}
.sender-input:focus { border-color: rgba(34, 211, 238, 0.6); }

.message-input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 10px 13px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-family: inherit;
  font-size: 16px;   /* iOS 자동 확대 방지 */
  line-height: 1.45;
  outline: none;
  resize: none;
  max-height: 132px;
  min-height: 40px;
}
.message-input::placeholder { color: var(--text-faint); }
.message-input:focus { border-color: rgba(124, 92, 255, 0.7); }

.send-btn {
  flex: 0 0 auto;
  width: 42px; height: 42px;
  display: grid; place-items: center;
  border: none;
  border-radius: 50%;
  font-size: 19px;
  font-weight: 800;
  color: #0b0e14;
  background: linear-gradient(135deg, #a78bfa, #22d3ee);
  box-shadow: 0 8px 20px rgba(124, 92, 255, 0.35);
}
.send-btn:active { transform: scale(0.94); }
.send-btn:disabled { opacity: 0.5; box-shadow: none; }

.reply-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 7px;
  padding: 6px 10px;
  border-radius: 10px;
  background: rgba(124, 92, 255, 0.13);
  border-left: 3px solid var(--accent);
  font-size: 12.5px;
  color: var(--text-dim);
}
.reply-text {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reply-text b { color: var(--text); }
.reply-cancel {
  border: none; background: none; color: var(--text-faint);
  font-size: 14px; padding: 0 2px;
}

.mention-bar {
  display: flex;
  gap: 6px;
  margin-bottom: 7px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}
.mention-bar::-webkit-scrollbar { display: none; }
.mention-chip {
  flex: 0 0 auto;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.06);
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-dim);
}
.mention-chip:active { background: rgba(124, 92, 255, 0.25); }

/* ============================================================
   5. 토스트
   ============================================================ */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + var(--safe-bottom));
  transform: translateX(-50%) translateY(10px);
  max-width: min(88vw, 420px);
  padding: 11px 16px;
  border-radius: 13px;
  background: rgba(28, 36, 50, 0.98);
  border: 1px solid var(--line-strong);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.45;
  text-align: center;
  color: var(--text);
  opacity: 0;
  transition: opacity .18s ease, transform .18s ease;
  pointer-events: none;
  z-index: 60;
  white-space: pre-wrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.good { border-color: rgba(52, 211, 153, 0.5); }
.toast.bad { border-color: rgba(248, 113, 113, 0.5); }

/* ============================================================
   6. 큰 화면 보정 (PC에서도 확인 가능하게)
   ============================================================ */
@media (min-width: 720px) {
  #room-screen {
    max-width: 720px;
    margin: 0 auto;
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
  }
  .messages { padding: 18px 18px 22px; }
}
