:root {
  --bg: #ffffff;
  --bg-2: #f2f3f5;
  --text: #16181c;
  --muted: #6b7079;
  --line: #e4e6ea;
  --accent: #3b6cf6;
  --mine: #3b6cf6;
  --mine-text: #ffffff;
  --theirs: #eef0f3;
  --theirs-text: #16181c;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111214;
    --bg-2: #1b1d21;
    --text: #eceef1;
    --muted: #8b909a;
    --line: #2a2d33;
    --accent: #5b86ff;
    --mine: #4a76f5;
    --theirs: #24272d;
    --theirs-text: #eceef1;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
input, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }

.view {
  height: 100dvh;
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
}
.view[hidden] { display: none; }

/* 로그인 */
#view-login { justify-content: center; padding: 24px 16px; }
.login-box { text-align: center; }
.logo { font-size: 56px; }
.login-box h1 { margin: 8px 0 4px; font-size: 26px; }
#login-form { display: flex; flex-direction: column; gap: 10px; margin-top: 24px; }
#login-form input {
  padding: 14px 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg-2); font-size: 17px; outline: none;
}
#login-form input:focus { border-color: var(--accent); }
.primary {
  padding: 14px; border-radius: 12px; background: var(--accent); color: #fff;
  font-size: 17px; font-weight: 600;
}

/* 상단바 */
.bar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border-bottom: 1px solid var(--line);
}
.bar h2 { margin: 0; font-size: 18px; flex: 1; }
.bar .title { flex: 1; min-width: 0; text-align: center; }
.bar .title h2 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar .title small { font-size: 12px; }
.icon { width: 40px; height: 40px; border-radius: 10px; font-size: 22px; }
.icon:hover { background: var(--bg-2); }
#btn-back { font-size: 32px; line-height: 1; }

/* 방 목록 */
.room-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.room-list li {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; cursor: pointer;
}
.room-list li:hover { background: var(--bg-2); }
.avatar {
  flex: none; width: 46px; height: 46px; border-radius: 16px;
  display: grid; place-items: center; font-weight: 700; color: #fff; font-size: 18px;
}
.room-info { flex: 1; min-width: 0; }
.room-top { display: flex; justify-content: space-between; gap: 8px; }
.room-top b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-top time { font-size: 12px; color: var(--muted); flex: none; }
.room-last { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.online-dot { color: #2fb36d; font-size: 12px; }
.me-bar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); font-size: 14px;
}
.link { color: var(--accent); }

/* 메시지 */
.messages { flex: 1; overflow-y: auto; padding: 12px 12px 4px; display: flex; flex-direction: column; gap: 2px; }
.day { align-self: center; font-size: 12px; color: var(--muted); background: var(--bg-2); padding: 4px 10px; border-radius: 10px; margin: 12px 0 8px; }
.msg { display: flex; flex-direction: column; max-width: 78%; }
.msg.theirs { align-self: flex-start; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg .who { font-size: 12px; color: var(--muted); margin: 8px 0 3px 4px; }
.row { display: flex; align-items: flex-end; gap: 6px; }
.msg.mine .row { flex-direction: row-reverse; }
.bubble {
  padding: 9px 13px; border-radius: 18px; line-height: 1.4;
  white-space: pre-wrap; word-break: break-word; font-size: 15.5px;
}
.msg.theirs .bubble { background: var(--theirs); color: var(--theirs-text); border-bottom-left-radius: 6px; }
.msg.mine .bubble { background: var(--mine); color: var(--mine-text); border-bottom-right-radius: 6px; }
.msg time { font-size: 11px; color: var(--muted); flex: none; margin-bottom: 2px; }
.msg.pending .bubble { opacity: .55; }
.msg .content { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.msg.mine .content { align-items: flex-end; }
.media { display: block; border-radius: 14px; overflow: hidden; max-width: min(260px, 100%); background: var(--bg-2); }
.media img { display: block; width: 100%; max-height: 320px; object-fit: cover; }
video.media { width: 260px; max-height: 360px; }
.msg audio { width: 240px; max-width: 100%; }
.file-card {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 14px;
  background: var(--theirs); color: var(--theirs-text); text-decoration: none; max-width: 260px;
}
.file-icon { font-size: 22px; flex: none; }
.file-meta { display: flex; flex-direction: column; min-width: 0; }
.file-meta b { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-meta small { font-size: 12px; color: var(--muted); }

.typing { font-size: 12px; min-height: 18px; padding: 0 16px; }

/* 입력창 */
.composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}
.composer textarea {
  flex: 1; resize: none; max-height: 120px;
  padding: 10px 14px; border-radius: 20px; border: 1px solid var(--line);
  background: var(--bg-2); outline: none; font-size: 16px; line-height: 1.35;
}
.attach { flex: none; width: 42px; height: 42px; border-radius: 50%; font-size: 20px; }
.attach:hover { background: var(--bg-2); }
.send {
  flex: none; width: 42px; height: 42px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 18px;
}
.send:disabled { opacity: .4; }

.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  max-width: calc(100% - 32px);
}
