* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif; color: #1a1a1a; }
[hidden] { display: none !important; }
.err { color: #c0392b; min-height: 1.2em; }
button { cursor: pointer; }

/* 로그인 */
#login-view { max-width: 340px; margin: 14vh auto; padding: 0 16px; display: flex; flex-direction: column; gap: 10px; }
#login-view h1 { text-align: center; color: #0070C0; }
#login-form { display: flex; flex-direction: column; gap: 8px; }
#login-view input, #login-view button { padding: 12px; font-size: 16px; border: 1px solid #ccc; border-radius: 8px; }
#login-view button { background: #0070C0; color: #fff; border: none; }
.hint { font-size: 13px; color: #555; background: #f2f8ff; padding: 10px; border-radius: 8px; }

/* 앱 레이아웃 */
#app-view { display: grid; grid-template-columns: 300px 1fr; height: 100dvh; }
#room-list-panel { border-right: 1px solid #e2e2e2; display: flex; flex-direction: column; min-width: 0; }
#room-list-panel header { display: flex; align-items: center; gap: 6px; padding: 12px; border-bottom: 1px solid #eee; }
#room-list-panel header .spacer { flex: 1; }
#room-list-panel header button { font-size: 18px; background: none; border: none; }
#me-name { color: #0070C0; }
#room-list { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1; }
#room-list li { padding: 12px; border-bottom: 1px solid #f0f0f0; cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
#room-list li:hover { background: #f7fbff; }
#room-list li.empty, #room-list li.err { color: #888; cursor: default; }
.rtitle small { color: #999; }
.unread.badge { background: #e74c3c; color: #fff; border-radius: 11px; padding: 1px 7px; font-size: 12px; min-width: 20px; text-align: center; }

/* 채팅 */
#chat-panel { display: flex; flex-direction: column; min-width: 0; }
#chat-header { padding: 12px; border-bottom: 1px solid #e2e2e2; display: flex; align-items: center; gap: 8px; }
#chat-header #btn-back { display: none; background: none; border: none; font-size: 18px; }
#messages { flex: 1; overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 6px; background: #f5f6f8; }
.msg { max-width: 72%; padding: 8px 11px; border-radius: 12px; background: #fff; white-space: pre-wrap; word-break: break-word; box-shadow: 0 1px 1px rgba(0,0,0,.06); }
.msg.mine { align-self: flex-end; background: #d6ecff; }
.msg .meta { font-size: 11px; color: #888; margin-top: 3px; display: flex; align-items: center; gap: 6px; }
.msg .rcount { color: #e67e22; font-weight: 600; }
.msg .recall { font-size: 11px; border: none; background: none; color: #c0392b; padding: 0; }
.msg .del { color: #aaa; }
.att-img { max-width: 220px; border-radius: 8px; display: block; margin-top: 4px; }
.att-file { display: inline-block; margin-top: 4px; color: #0070C0; text-decoration: none; }

#send-form { display: flex; gap: 6px; padding: 8px; border-top: 1px solid #e2e2e2; align-items: flex-end; }
#send-form #btn-file { border: none; background: none; font-size: 20px; }
#msg-input { flex: 1; resize: none; font-size: 16px; padding: 9px; border: 1px solid #ccc; border-radius: 8px; max-height: 120px; }
#send-form button[type=submit] { padding: 9px 16px; background: #0070C0; color: #fff; border: none; border-radius: 8px; }

/* 새 대화 선택 모달 */
#picker { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 50; }
.picker-box { background: #fff; border-radius: 12px; padding: 18px; width: min(380px, 92vw); max-height: 80vh; display: flex; flex-direction: column; }
.picker-box h3 { margin: 0 0 10px; }
#picker-list { list-style: none; margin: 0 0 10px; padding: 0; overflow: auto; flex: 1; }
#picker-list li { padding: 8px 4px; border-bottom: 1px solid #f0f0f0; }
#picker-list label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
#picker-gname { padding: 9px; font-size: 15px; border: 1px solid #ccc; border-radius: 8px; margin-bottom: 10px; }
.picker-actions { display: flex; justify-content: flex-end; gap: 8px; }
.picker-actions button { padding: 9px 16px; border-radius: 8px; border: 1px solid #ccc; background: #fff; }
#picker-ok { background: #0070C0; color: #fff; border: none; }

/* 모바일: 한 화면씩 */
@media (max-width: 768px) {
  #app-view { grid-template-columns: 1fr; }
  #app-view.chat-open #room-list-panel { display: none; }
  #app-view:not(.chat-open) #chat-panel { display: none; }
  #chat-header #btn-back { display: inline; }
  .msg { max-width: 85%; }
}
