:root {
  --bg: #f6f5f2;
  --panel: #ffffff;
  --line: #e7e4de;
  --text: #1f1d1a;
  --muted: #8a857c;
  --accent: #2f6f5e;
  --accent-soft: #e3efe9;
  --mine: #2f6f5e;
  --mine-text: #ffffff;
  --theirs: #ffffff;
  --badge: #e0533d;
  --danger: #c2412d;
  --radius: 14px;
  --font: "Pretendard", "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161715; --panel: #1f201e; --line: #2e302c; --text: #ecebe7; --muted: #8f8d86;
    --accent: #5fb59a; --accent-soft: #24332d; --mine: #3b8a73; --theirs: #2a2c29;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 15px/1.5 var(--font); color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; font-weight: 400; }
button { font: inherit; color: inherit; cursor: pointer; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.btn { border: 0; border-radius: 10px; padding: 10px 16px; font-weight: 600; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:disabled { opacity: .5; cursor: default; }
.icon-btn { display: grid; place-items: center; width: 36px; height: 36px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); }
.icon-btn:hover { background: var(--bg); color: var(--text); }

/* 로그인 */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(360px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 32px 28px; display: grid; gap: 12px; text-align: center; }
.login-icon { width: 56px; height: 56px; margin: 0 auto 4px; }
.login-card h1 { margin: 0; font-size: 20px; }
.login-card p { margin: 0 0 8px; }
.login-card input, .open-form input {
  width: 100%; padding: 11px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text); font: inherit; outline: none;
}
.login-card input:focus, .open-form input:focus, .composer textarea:focus { border-color: var(--accent); }
.err { color: var(--danger); min-height: 1.5em; font-size: 13px; }

/* 레이아웃 */
.app { display: grid; grid-template-columns: 340px 1fr; height: 100dvh; }
.side { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 8px 18px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.brand img { width: 26px; height: 26px; }
.head-actions { display: flex; gap: 2px; }
.open-form { padding: 4px 14px 10px; }
.status { margin: 0 14px 10px; padding: 9px 12px; border-radius: 10px; background: #fbeae6; color: var(--danger); font-size: 13px; }
.side-scroll { overflow-y: auto; flex: 1; padding-bottom: 16px; }
.sec-title { font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: .02em; margin: 14px 18px 6px; display: flex; gap: 8px; align-items: baseline; }
.room-list { list-style: none; margin: 0; padding: 0 8px; }
.room { display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 12px; cursor: pointer; position: relative; }
.room:hover { background: var(--bg); }
.room.active { background: var(--accent-soft); }
.avatar { flex: none; width: 42px; height: 42px; border-radius: 14px; display: grid; place-items: center; font-weight: 700; color: #fff; font-size: 16px; }
.room-body { min-width: 0; flex: 1; }
.room-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; gap: 6px; align-items: baseline; }
.room-name .members { color: var(--muted); font-weight: 400; font-size: 12px; }
.room-preview { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { flex: none; background: var(--badge); color: #fff; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px; }
.fav-del { opacity: 0; border: 0; background: transparent; color: var(--muted); width: 28px; height: 28px; border-radius: 8px; }
.room:hover .fav-del { opacity: 1; }
.fav-del:hover { background: var(--line); }
.hint { color: var(--muted); font-size: 12px; margin: 14px 18px 0; }
.empty-li { color: var(--muted); font-size: 13px; padding: 6px 12px; }

/* 대화 */
.chat { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.empty { margin: auto; text-align: center; color: var(--muted); }
.empty svg { width: 48px; height: 48px; stroke-width: 1.4; }
.chat-view { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.chat-head .back { display: none; }
.chat-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-title strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 16px; }
.messages { flex: 1; overflow-y: auto; padding: 16px 20px 8px; display: flex; flex-direction: column; gap: 2px; }
.day { align-self: center; margin: 14px 0 8px; font-size: 12px; color: var(--muted); background: var(--panel); border: 1px solid var(--line); padding: 2px 12px; border-radius: 999px; }
.sys { align-self: center; margin: 6px 0; font-size: 12px; color: var(--muted); text-align: center; max-width: 80%; }
.msg { display: flex; flex-direction: column; align-items: flex-start; max-width: min(72%, 560px); }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg .who { font-size: 12px; color: var(--muted); margin: 10px 0 3px 4px; }
.msg .row { display: flex; align-items: flex-end; gap: 6px; }
.msg.mine .row { flex-direction: row-reverse; }
.bubble { background: var(--theirs); border: 1px solid var(--line); padding: 8px 12px; border-radius: 4px 16px 16px 16px; white-space: pre-wrap; word-break: break-word; }
.msg.mine .bubble { background: var(--mine); color: var(--mine-text); border-color: transparent; border-radius: 16px 4px 16px 16px; }
.msg.cont .bubble { border-radius: 16px; }
.msg .time { font-size: 11px; color: var(--muted); white-space: nowrap; }
.msg.pending .bubble { opacity: .55; }
.bubble a { color: inherit; }
.to-bottom { position: absolute; right: 24px; bottom: 84px; border: 0; background: var(--accent); color: #fff; padding: 6px 14px; border-radius: 999px; font-size: 13px; box-shadow: 0 4px 14px rgb(0 0 0 / .15); }
.composer { display: flex; gap: 8px; align-items: flex-end; padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--panel); }
.composer textarea { flex: 1; resize: none; max-height: 160px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); color: var(--text); font: inherit; outline: none; }
.btn.send { width: 44px; height: 44px; padding: 0; display: grid; place-items: center; border-radius: 12px; }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: .2s; max-width: 90vw; }
.toast.show { opacity: 1; transform: translateX(-50%); }

/* 모바일 */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .app.in-chat .side { display: none; }
  .app:not(.in-chat) .chat { display: none; }
  .chat-head .back { display: grid; }
  .msg { max-width: 82%; }
  .messages { padding: 12px 12px 8px; }
}
