* { margin: 0; padding: 0; box-sizing: border-box }
:root {
  --bg: #f5f5f5;
  --sidebar-bg: #fafafa;
  --header-bg: #fff;
  --primary: #fee500;
  --primary-dark: #f0d800;
  --sent-msg: #fee500;
  --received-msg: #fff;
  --text: #1a1a1a;
  --text-secondary: #666;
  --text-muted: #999;
  --border: #e8e8e8;
  --hover: #f0f0f0;
  --danger: #ff4444;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 18px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans KR", sans-serif;
}
html, body { height: 100%; font-family: var(--font); background: var(--bg); color: var(--text) }
#app { height: 100%; display: flex; flex-direction: column }

/* ===== Login Screen ===== */
.screen { height: 100%; display: flex; align-items: center; justify-content: center }
.screen.hidden { display: none }
.login-card {
  background: #fff;
  border-radius: 20px;
  padding: 48px 40px 36px;
  width: 380px;
  max-width: 90vw;
  box-shadow: 0 4px 24px rgba(0,0,0,.08);
  text-align: center;
}
.logo-icon { font-size: 48px; margin-bottom: 8px }
.login-card h1 { font-size: 24px; font-weight: 700; margin-bottom: 4px }
.login-subtitle { font-size: 14px; color: var(--text-muted); margin-bottom: 28px }

/* ===== Guest Auth ===== */
.guest-btn {
  width: 100%;
  padding: 14px;
  background: #fff;
  color: var(--text);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background .2s, border-color .2s;
  font-family: var(--font);
  margin-top: 8px;
}
.guest-btn:hover { background: #f8f8f8; border-color: #ccc }
.guest-btn:disabled { opacity: .5; cursor: not-allowed }
.guest-status {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 8px;
  min-height: 20px;
}
.guest-badge {
  display: inline-block;
  font-size: 10px;
  background: #eee;
  color: var(--text-muted);
  padding: 1px 8px;
  border-radius: 8px;
  margin-top: 2px;
  font-weight: 600;
}
.guest-info {
  padding: 12px 18px;
  background: #fffae6;
  border-bottom: 1px solid #f0e68c;
}
.guest-info.hidden { display: none }
.guest-info-text {
  font-size: 12px;
  color: #8b7a00;
  line-height: 1.4;
}

/* ===== Password Fallback ===== */
#password-fallback {
  margin-top: 8px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}
#password-fallback.hidden { display: none }
.password-divider {
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 20px;
}
.password-divider span { background: #fff; padding: 0 10px }
.input-group {
  text-align: left;
  margin-bottom: 16px;
}
.input-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.input-group input {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  outline: none;
  transition: border-color .2s;
  font-family: var(--font);
}
.input-group input:focus { border-color: var(--primary) }
#login-btn {
  width: 100%;
  padding: 13px;
  background: var(--primary);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 8px;
  transition: background .2s;
}
#login-btn:hover { background: var(--primary-dark) }
#login-btn:disabled { opacity: .5; cursor: not-allowed }
.error-msg { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 20px }

/* ===== Main Layout ===== */
#chat-screen { flex-direction: row; height: 100% }

/* ===== Sidebar ===== */
#sidebar {
  width: 340px;
  min-width: 340px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100%;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--header-bg);
}
.sidebar-header h2 { font-size: 18px; font-weight: 700 }
.icon-btn {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 6px;
  transition: background .2s;
  color: var(--text-secondary);
}
.icon-btn:hover { background: var(--hover); color: var(--text) }
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--header-bg);
}
.my-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}
.my-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.my-name { font-size: 14px; font-weight: 600 }
.my-id { font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis }
.room-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
}
.room-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  cursor: pointer;
  transition: background .15s;
  border-bottom: 1px solid #f3f3f3;
}
.room-item:hover { background: var(--hover) }
.room-item.active { background: #e8e8e8 }
.room-item-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #ddd;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
  overflow: hidden;
}
.room-item-avatar img { width: 100%; height: 100%; object-fit: cover }
.room-item-info { flex: 1; min-width: 0 }
.room-item-name { font-size: 14px; font-weight: 600; margin-bottom: 2px }
.room-item-preview { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis }
.room-item-time { font-size: 11px; color: var(--text-muted); flex-shrink: 0; margin-left: auto; align-self: flex-start }
.room-item-unread {
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
  margin-left: auto;
  flex-shrink: 0;
  align-self: center;
}

/* ===== Chat Area ===== */
#chat-area { flex: 1; display: flex; flex-direction: column; height: 100%; background: #f9f9f9 }
.room-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  gap: 12px;
}
.placeholder-icon { font-size: 72px; opacity: .5 }
.room-placeholder p { font-size: 16px }

#room-view { flex: 1; display: flex; flex-direction: column; height: 100% }
#room-view.hidden { display: none }

.room-header {
  padding: 14px 20px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.room-header-info { display: flex; align-items: center; gap: 12px }
.room-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: #ddd; display: flex;
  align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0;
  overflow: hidden;
}
.room-avatar img { width: 100%; height: 100%; object-fit: cover }
.room-header h3 { font-size: 16px; font-weight: 600 }
.room-meta { font-size: 12px; color: var(--text-muted) }

/* ===== Message List ===== */
.message-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.message-date-divider {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  padding: 12px 0 8px;
}
.message-group { display: flex; flex-direction: column; max-width: 75%; margin-bottom: 2px }
.message-group.sent { align-self: flex-end; align-items: flex-end }
.message-group.received { align-self: flex-start; align-items: flex-start }
.message-sender {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 600;
  margin-bottom: 2px;
  padding: 0 4px;
}
.message-bubble-wrap { display: flex; align-items: flex-end; gap: 6px; width: 100% }
.message-group.received .message-bubble-wrap { flex-direction: row }
.message-group.sent .message-bubble-wrap { flex-direction: row-reverse }
.message-avatar-col {
  width: 26px;
  flex-shrink: 0;
  align-self: flex-end;
}
.message-avatar-col .profile-avatar {
  width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; background: #ddd; overflow: hidden;
}
.message-avatar-col .profile-avatar img { width: 100%; height: 100%; object-fit: cover }
.message-bubble {
  padding: 8px 13px;
  border-radius: var(--radius-lg);
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}
.message-group.sent .message-bubble {
  background: var(--sent-msg);
  border-bottom-right-radius: 4px;
}
.message-group.received .message-bubble {
  background: var(--received-msg);
  border: 1px solid #eee;
  border-bottom-left-radius: 4px;
}
.message-info {
  display: flex;
  gap: 4px;
  font-size: 10px;
  color: var(--text-muted);
  padding: 0 4px;
  margin-top: 2px;
  align-items: center;
  flex-shrink: 0;
}
.message-group.sent .message-info { justify-content: flex-end }
.message-read-status { font-size: 10px }

/* ===== Typing Indicator ===== */
.typing-indicator {
  padding: 6px 20px;
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
}
.typing-indicator.hidden { display: none }

/* ===== Message Form ===== */
.message-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 16px;
  background: var(--header-bg);
  border-top: 1px solid var(--border);
}
.message-form textarea {
  flex: 1;
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 10px 14px;
  font-size: 14px;
  outline: none;
  resize: none;
  max-height: 120px;
  font-family: var(--font);
  line-height: 1.4;
  transition: border-color .2s;
}
.message-form textarea:focus { border-color: var(--primary) }
.send-btn {
  padding: 10px 20px;
  background: var(--primary);
  border: none;
  border-radius: var(--radius-lg);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background .2s, opacity .2s;
  font-family: var(--font);
}
.send-btn:hover { background: var(--primary-dark) }
.send-btn:disabled { opacity: .4; cursor: not-allowed }

/* ===== Emoji / Image ===== */
.message-bubble img.emoji { width: 22px; height: 22px; vertical-align: middle }
.message-bubble img.msg-image {
  max-width: 280px;
  max-height: 300px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: block;
  margin: 2px 0;
}

/* ===== Scrollbar ===== */
.room-list::-webkit-scrollbar, .message-list::-webkit-scrollbar { width: 6px }
.room-list::-webkit-scrollbar-thumb, .message-list::-webkit-scrollbar-thumb {
  background: #ccc; border-radius: 3px;
}

/* ===== Modal ===== */
.modal {
  position: fixed; z-index: 100; left: 0; top: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,.85);
  display: flex; align-items: center; justify-content: center;
}
.modal.hidden { display: none }
.modal-content { max-width: 90vw; max-height: 90vh; border-radius: 8px }
.modal-close {
  position: absolute; top: 20px; right: 30px;
  color: #fff; font-size: 36px; font-weight: 700;
  cursor: pointer;
}

/* ===== Mobile ===== */
@media (max-width: 720px) {
  #sidebar { width: 100%; min-width: 100% }
  #sidebar.hide { display: none }
  #sidebar.show-mobile { display: flex }
  .message-group { max-width: 90% }
}
