* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #ffffff;
  --bg-elevated: #ffffff;
  --bg-sidebar: #f7f8f9;
  --bg-soft: #f1f3f5;
  --border: #e6e8eb;
  --border-strong: #d4d7db;
  --text: #1f2329;
  --text-dim: #6b7280;
  --text-muted: #9ca3af;
  --accent: #00BF6F;
  --accent-hover: #00A560;
  --accent-soft: #e6f8f0;
  --bubble-self-bg: #00BF6F;
  --bubble-self-text: #ffffff;
  --bubble-other-bg: #f1f3f5;
  --bubble-other-text: #1f2329;
  --system: #9ca3af;
  --danger: #ef4444;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.12);

  /* Default avatar silhouette — head + torso, KakaoTalk-style. The body is a
     tall ellipse intentionally drawn past the viewBox bottom; the circular
     border-radius of each avatar container clips it into a clean shoulder
     curve, so the silhouette fills the lower half all the way to the rim
     (no empty white between body and circle edge). */
  --avatar-silhouette: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64' fill='%239ca3af'><circle cx='32' cy='23' r='11'/><ellipse cx='32' cy='64' rx='24' ry='28'/></svg>");
}

html, body {
  height: 100%;
  font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.screen { height: 100vh; display: flex; }
.hidden { display: none !important; }

/* ---------- Login ---------- */
#login-screen {
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #f7f8f9 0%, #ffffff 100%);
}
.login-card {
  background: #ffffff;
  padding: 40px;
  border-radius: 14px;
  border: 1px solid var(--border);
  width: 380px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}
.login-card h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}
.login-card .subtitle {
  color: var(--text-dim);
  margin: 6px 0 28px;
  font-size: 13px;
}
#g-signin {
  display: flex;
  justify-content: center;
  margin-bottom: 14px;
  min-height: 44px;
}
.login-error {
  color: var(--danger);
  font-size: 12px;
  margin-bottom: 10px;
}
.hint {
  color: var(--text-dim);
  font-size: 12px;
  margin-top: 12px;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 260px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.sidebar-header {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border);
  background: #ffffff;
}
.brand {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 12px;
  letter-spacing: 0.04em;
}
.me-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--bg-soft);
  flex-shrink: 0;
  border: 1px solid var(--border);
  display: block;
}
/* No-picture state for the header (me) avatar: show the same silhouette as
   other placeholders. We don't hide the img anymore — the background shows
   through when src is empty, the real picture covers it when set. */
.avatar.placeholder {
  background: #ffffff var(--avatar-silhouette) no-repeat center;
  background-size: 100%;
}
.avatar-clickable {
  position: relative;
  width: 32px; height: 32px;
  cursor: pointer;
  flex-shrink: 0;
}
.avatar-edit-icon {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 16px; height: 16px;
  background: var(--accent);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  border: 2px solid white;
  opacity: 0;
  transition: opacity 0.15s;
}
.avatar-clickable:hover .avatar-edit-icon { opacity: 1; }
.avatar-clickable:hover .avatar { filter: brightness(0.9); }
.me-info { display: flex; flex-direction: column; min-width: 0; }
.me-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 170px;
  cursor: pointer;
}
.me-name:hover { color: var(--accent); }
.logout-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 11px;
  text-align: left;
  cursor: pointer;
  padding: 0;
  margin-top: 2px;
}
.logout-btn:hover { color: var(--accent); }

.sidebar-section {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
}
.sidebar-section:last-child {
  border-bottom: none;
  flex: 1;
  overflow-y: auto;
}
.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  font-weight: 600;
}
.add-room-btn {
  width: 22px; height: 22px;
  border: none;
  background: var(--bg-soft);
  color: var(--text-dim);
  font-size: 16px;
  line-height: 1;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
}
.add-room-btn:hover {
  background: var(--accent);
  color: white;
}

/* ---------- Rooms list ---------- */
.rooms-list { list-style: none; }
.room-item {
  padding: 7px 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  margin-bottom: 2px;
  transition: background 0.1s;
}
.room-item:hover {
  background: rgba(0,191,111,0.08);
}
.room-item.active {
  background: var(--accent);
  color: white;
  font-weight: 500;
}
.room-item.sortable-ghost {
  opacity: 0.4;
  background: var(--accent-soft);
}
.room-item.sortable-chosen {
  cursor: grabbing;
}
.room-prefix {
  color: var(--text-muted);
  font-weight: 600;
}
.room-item.active .room-prefix {
  color: white;
}
.room-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.room-mute {
  width: 13px;
  height: 13px;
  color: var(--text-muted);
  flex-shrink: 0;
  display: inline-block;
}
.room-item.active .room-mute {
  color: rgba(255, 255, 255, 0.85);
}
.unread-badge {
  background: #ef4444;
  color: white;
  font-size: 10px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  padding: 0 6px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: auto;
  box-shadow: 0 1px 2px rgba(239,68,68,0.3);
}
.room-item.active .unread-badge {
  background: white;
  color: var(--accent);
  box-shadow: none;
}

/* ---------- Users list ---------- */
.users-list { list-style: none; }
.user-item {
  padding: 8px 6px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.1s;
}
.user-item:hover { background: rgba(0,191,111,0.08); }
.user-item.is-offline .user-name { color: var(--text-dim); }
.user-item.active { background: var(--accent); }
.user-item.active .user-name,
.user-item.active .user-status { color: white; }
.user-item.active .status-dot { border-color: var(--accent); }
.user-item.active .unread-badge { background: white; color: var(--accent); box-shadow: none; }

.user-avatar-wrap {
  position: relative;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}
.avatar-sm {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  display: block;
}
.avatar-sm.placeholder {
  background: #ffffff var(--avatar-silhouette) no-repeat center;
  background-size: 100%;
}
.status-dot {
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 2px solid var(--bg-sidebar);
}
.status-dot.is-online { background: var(--accent); }
.status-dot.is-offline { background: var(--text-muted); }

.user-info { flex: 1; min-width: 0; }
.user-name {
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-status {
  font-size: 11px;
  margin-top: 1px;
}
.user-status.is-online { color: var(--accent); }
.user-status.is-offline { color: var(--text-muted); }

/* ---------- Main chat ---------- */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
}
.chat-header {
  position: relative;
  padding: 14px 22px;
  border-bottom: 1px solid var(--border);
  background: #ffffff;
  display: flex;
  align-items: center;
  gap: 16px;
}
.chat-header .room-title {
  flex-shrink: 1;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-header .room-actions { margin-left: auto; flex-shrink: 0; }

.back-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
  margin-left: -8px;
}
.back-btn:hover { background: var(--bg-soft); }

/* In-flow search box: grows to fill the space between the room title (left)
   and the action buttons (right), capped at 360px. Used to be absolute-centered
   with a fixed 360px width, which overflowed and covered neighboring controls
   when the chat header got narrow. */
.search-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
  max-width: 360px;
  z-index: 5;
}
.search-input {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-soft);
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.search-input:focus {
  background: white;
  border-color: var(--accent);
}
.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  max-height: 420px;
  overflow-y: auto;
  z-index: 150;
}
.search-empty {
  padding: 16px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}
.search-result-item {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--accent-soft); }
.search-result-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 4px;
}
.search-result-room {
  background: var(--bg-soft);
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
  color: var(--accent-hover);
}
.search-result-author { font-weight: 500; color: var(--text); }
.search-result-time { margin-left: auto; }
.search-result-snippet {
  font-size: 13px;
  color: var(--text);
  line-height: 1.4;
  word-break: break-word;
}
.search-result-snippet mark {
  background: rgba(0,191,111,0.25);
  color: var(--accent-hover);
  padding: 0 2px;
  border-radius: 2px;
}
.room-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.room-action-btn {
  padding: 6px 12px;
  font-size: 12px;
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-dim);
  border-radius: 6px;
  cursor: pointer;
}
.room-action-btn:hover {
  border-color: var(--danger);
  color: var(--danger);
}

/* ---------- Announcement banner ---------- */
.announcement-banner {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 22px;
  background: var(--accent-soft);
  border-bottom: 1px solid var(--border);
  border-left: 3px solid var(--accent);
}
.announcement-icon {
  font-size: 18px;
  line-height: 1.2;
}
.announcement-content { flex: 1; min-width: 0; }
.announcement-author {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent-hover);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 2px;
}
.announcement-text {
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
  word-break: break-word;
}
.announcement-clear {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
  padding: 2px 6px;
  border-radius: 4px;
}
.announcement-clear:hover { background: rgba(0,0,0,0.05); color: var(--text); }

/* ---------- Messages ---------- */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.msg {
  max-width: 70%;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.msg.self { align-self: flex-end; flex-direction: row-reverse; }
.msg.other { align-self: flex-start; }
.msg-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.msg.self .msg-body { align-items: flex-end; }
.msg-avatar {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
}
.msg-avatar img {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
  display: block;
}
.msg-avatar-placeholder {
  display: block;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #ffffff var(--avatar-silhouette) no-repeat center;
  background-size: 100%;
  border: 1px solid var(--border);
}
.msg.followup .msg-body { margin-top: 1px; }
.msg.followup .msg-bubble,
.msg.followup .msg-file,
.msg.followup .msg-image { margin-top: -2px; }
.msg-meta {
  font-size: 11px;
  color: var(--text-dim);
  display: flex;
  gap: 8px;
}
.msg-meta .name {
  font-weight: 600;
  color: var(--text);
}
.msg-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  background: var(--bubble-other-bg);
  color: var(--bubble-other-text);
  word-wrap: break-word;
  white-space: pre-wrap;
  line-height: 1.5;
  border: 1px solid var(--border);
}
.msg.self .msg-bubble {
  background: var(--bubble-self-bg);
  color: var(--bubble-self-text);
  border-color: var(--bubble-self-bg);
}

.msg-image {
  max-width: 320px;
  max-height: 320px;
  border-radius: 12px;
  cursor: pointer;
  display: block;
  border: 1px solid var(--border);
}

.msg-file {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bubble-other-bg);
  border-radius: 12px;
  border: 1px solid var(--border);
  text-decoration: none;
  color: var(--text);
  min-width: 240px;
  transition: filter 0.15s, background 0.15s;
}
.msg.self .msg-file {
  background: var(--bubble-self-bg);
  color: var(--bubble-self-text);
  border-color: var(--bubble-self-bg);
}
.msg-file:hover { filter: brightness(0.97); }
.msg.self .msg-file:hover { filter: brightness(1.05); }
.msg-file .icon {
  width: 36px; height: 36px;
  background: rgba(0,0,0,0.05);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.msg.self .msg-file .icon {
  background: rgba(255,255,255,0.2);
}
.msg-file .info { display: flex; flex-direction: column; min-width: 0; }
.msg-file .name {
  font-weight: 600;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 220px;
}
.msg-file .size {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
}
.msg.self .msg-file .size { color: rgba(255,255,255,0.85); }

.msg-system {
  align-self: center;
  color: var(--system);
  font-size: 12px;
  padding: 4px 10px;
}

/* KakaoTalk-style side column next to each message bubble — holds the unread
   count (self only) stacked above the timestamp. align-self: flex-end pins it
   to the bottom edge of the bubble so the time visually "sits" against it. */
.msg-side {
  display: flex;
  flex-direction: column;
  gap: 1px;
  align-self: flex-end;
  flex-shrink: 0;
  margin: 0 4px 2px;
  font-size: 11px;
  line-height: 1.2;
  white-space: nowrap;
}
.msg.self .msg-side { align-items: flex-end; }
.msg.other .msg-side { align-items: flex-start; }
.msg-side .msg-time {
  color: var(--text-dim);
}
.msg-unread-count {
  color: #f59e0b;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.date-separator {
  align-self: stretch;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 500;
  margin: 8px 0 4px;
}
.date-separator::before,
.date-separator::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}
.date-separator span {
  padding: 4px 12px;
  background: var(--bg-soft);
  border-radius: 999px;
  border: 1px solid var(--border);
}

/* ---------- Composer ---------- */
.composer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  background: #ffffff;
}
.composer input[type="text"] {
  flex: 1;
  padding: 11px 14px;
  background: var(--bg-soft);
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.composer input[type="text"]:focus {
  background: #ffffff;
  border-color: var(--accent);
}
.composer button[type="submit"] {
  padding: 11px 20px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.composer button[type="submit"]:hover { background: var(--accent-hover); }

.file-btn,
.emoticon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px; height: 42px;
  background: var(--bg-soft);
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--text-dim);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  flex-shrink: 0;
}
.file-btn:hover,
.emoticon-btn:hover {
  color: var(--accent);
  background: var(--accent-soft);
}

/* ---------- Emoticon picker & message ---------- */
.emoticon-picker {
  position: fixed;
  z-index: 250;
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0;
  box-shadow: var(--shadow-md);
  width: 320px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.emoticon-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 12px;
  min-height: 140px;
  align-content: start;
  overflow-y: auto;
  max-height: 200px;
}
.emoticon-item {
  background: var(--bg-soft);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 6px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.emoticon-item:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}
.emoticon-item img {
  width: 56px;
  height: 56px;
  object-fit: contain;
  display: block;
}
.emoticon-empty {
  padding: 24px;
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
}

/* Character tabs at bottom */
.emoticon-tabs {
  display: flex;
  gap: 2px;
  padding: 6px;
  border-top: 1px solid var(--border);
  background: var(--bg-soft);
  overflow-x: auto;
}
.emoticon-tab {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 4px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s;
}
.emoticon-tab img {
  width: 32px;
  height: 32px;
  object-fit: contain;
  display: block;
}
.emoticon-tab:hover { background: white; }
.emoticon-tab.active {
  background: white;
  border-color: var(--accent);
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.msg-emoticon {
  width: 130px;
  height: 130px;
  object-fit: contain;
  background: transparent;
}

.upload-status {
  padding: 8px 22px;
  font-size: 12px;
  color: var(--text-dim);
  background: #ffffff;
  border-top: 1px solid var(--border);
}
.upload-status.error { color: var(--danger); }

/* ---------- File preview (confirm before send) ---------- */
.file-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 22px;
  background: var(--accent-soft);
  border-top: 1px solid var(--border);
  border-left: 3px solid var(--accent);
}
.file-preview-icon { font-size: 22px; }
.file-preview-info { flex: 1; min-width: 0; }
.file-preview-name {
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 320px;
}
.file-preview-size { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.file-preview-confirm {
  font-size: 13px;
  color: var(--accent-hover);
  font-weight: 500;
  margin-right: 8px;
}
.file-preview-btn { padding: 8px 16px; font-size: 13px; }

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
}
.modal-content {
  position: relative;
  background: #ffffff;
  border-radius: 12px;
  padding: 24px;
  width: 360px;
  box-shadow: var(--shadow-lg);
}
.modal-content h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text);
}
.modal-content input {
  width: 100%;
  padding: 11px 14px;
  background: var(--bg-soft);
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  margin-bottom: 16px;
}
.modal-content input:focus {
  background: white;
  border-color: var(--accent);
}
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.btn-primary {
  padding: 9px 18px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary {
  padding: 9px 18px;
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
}
.btn-secondary:hover { background: var(--bg-soft); }

/* ---------- Context menu ---------- */
.context-menu {
  position: fixed;
  z-index: 200;
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  min-width: 96px;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
}
.ctx-item {
  display: block;
  width: 100%;
  padding: 5px 14px;
  background: none;
  border: none;
  text-align: left;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  border-radius: 4px;
  line-height: 1.4;
}
.ctx-item:hover { background: var(--accent-soft); color: var(--accent); }

/* ---------- Reaction picker popover ---------- */
.reaction-picker {
  position: fixed;
  z-index: 250;
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px;
  box-shadow: var(--shadow-md);
  min-width: 220px;
}
.reaction-quick {
  display: flex;
  gap: 4px;
  justify-content: space-between;
}
.reaction-quick button {
  background: none;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
}
.reaction-quick button:hover { background: var(--accent-soft); border-color: var(--accent); }
.emoji-picker-element {
  --background: white;
  --border-color: var(--border);
  --indicator-color: var(--accent);
  --input-border-color: var(--border);
  --num-columns: 8;
  width: 320px;
  height: 360px;
  margin-top: 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

/* ---------- Reply preview in composer ---------- */
.reply-preview {
  display: flex;
  align-items: stretch;
  gap: 10px;
  padding: 10px 22px 10px 18px;
  background: var(--accent-soft);
  border-top: 1px solid var(--border);
}
.reply-preview-bar {
  width: 3px;
  background: var(--accent);
  border-radius: 2px;
  flex-shrink: 0;
}
.reply-preview-content {
  flex: 1;
  min-width: 0;
  padding: 2px 0;
}
.reply-preview-author {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent-hover);
  margin-bottom: 2px;
}
.reply-preview-text {
  font-size: 12px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reply-preview-cancel {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 14px;
  padding: 4px 8px;
  border-radius: 4px;
}
.reply-preview-cancel:hover { background: rgba(0,0,0,0.05); color: var(--text); }

/* ---------- Reply quote in messages ---------- */
.msg-reply-quote {
  display: flex;
  gap: 8px;
  padding: 6px 10px;
  background: rgba(0,0,0,0.04);
  border-radius: 8px;
  margin-bottom: 4px;
  max-width: 100%;
}
.msg.self .msg-reply-quote { background: rgba(255,255,255,0.18); }
.msg-reply-quote .reply-bar {
  width: 3px;
  background: var(--accent);
  border-radius: 2px;
  flex-shrink: 0;
}
.msg.self .msg-reply-quote .reply-bar { background: rgba(255,255,255,0.7); }
.msg-reply-quote .reply-content { min-width: 0; }
.msg-reply-quote .reply-author {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent-hover);
  margin-bottom: 1px;
}
.msg.self .msg-reply-quote .reply-author { color: rgba(255,255,255,0.95); }
.msg-reply-quote .reply-text {
  font-size: 12px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 280px;
}
.msg.self .msg-reply-quote .reply-text { color: rgba(255,255,255,0.85); }

/* ---------- Reactions ---------- */
.msg-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}
.reaction-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
  line-height: 1.4;
  color: var(--text);
}
.reaction-pill:hover { background: var(--accent-soft); border-color: var(--accent); }
.reaction-pill.mine {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-hover);
  font-weight: 600;
}
.reaction-emoji { font-size: 13px; }
.reaction-count { font-size: 11px; }

/* ---------- @ mentions ---------- */
.mention {
  color: var(--accent-hover);
  font-weight: 600;
}
.mention-mine {
  background: var(--accent);
  color: white;
  padding: 1px 6px;
  border-radius: 6px;
  font-weight: 600;
}
.msg.self .mention { color: rgba(255,255,255,0.95); text-decoration: underline; }
.msg.self .mention-mine { background: rgba(255,255,255,0.25); color: white; text-decoration: none; }

.mention-popover {
  position: fixed;
  z-index: 300;
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  box-shadow: var(--shadow-md);
  min-width: 200px;
  max-height: 240px;
  overflow-y: auto;
}
.mention-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 6px 10px;
  background: none;
  border: none;
  text-align: left;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  border-radius: 6px;
}
.mention-item.active,
.mention-item:hover { background: var(--accent-soft); color: var(--accent-hover); }
.mention-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.mention-avatar.placeholder {
  background: #ffffff var(--avatar-silhouette) no-repeat center;
  background-size: 100%;
}
.mention-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Toast notifications (Dooray-style) ---------- */
.toast-stack {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column-reverse;
  gap: 10px;
  z-index: 1000;
  pointer-events: none;
  width: 340px;
  max-width: calc(100vw - 40px);
}
.toast {
  position: relative;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(15,23,42,0.10), 0 2px 4px rgba(15,23,42,0.04);
  padding: 12px 14px 12px 16px;
  display: grid;
  grid-template-columns: 44px 1fr;
  grid-template-rows: auto auto auto;
  column-gap: 12px;
  cursor: pointer;
  pointer-events: auto;
  transform: translateX(120%);
  transition: transform 0.34s cubic-bezier(.2,.8,.2,1), opacity 0.25s, box-shadow 0.2s;
  opacity: 0;
  overflow: hidden;
}
/* Blue Dooray-style accent bar on the left */
.toast::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: #00BF6F;
}
.toast.toast-show { transform: translateX(0); opacity: 1; }
.toast.toast-leave { transform: translateX(20px); opacity: 0; }
.toast:hover { box-shadow: 0 18px 44px rgba(0,0,0,0.22); }
.toast.toast-mention::before { background: #ef4444; }
.toast.toast-mention { background: #fff7f7; }
.toast.toast-mention .toast-sender::before { content: '@ '; color: #ef4444; font-weight: 700; }

.toast-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  grid-row: 1 / span 3;
  grid-column: 1;
}
.toast-content {
  grid-column: 2;
  grid-row: 1 / span 3;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
}
.toast-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}
.toast-sender {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 150px;
  flex-shrink: 0;
}
.toast-room {
  font-size: 11px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  text-align: right;
}
.toast-message {
  font-size: 12.5px;
  color: var(--text);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}
.toast-image-preview {
  margin-top: 6px;
  max-width: 100%;
  max-height: 120px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--border);
  display: block;
}
/* Close button — Dooray pattern: hidden by default, shown on hover */
.toast-close {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(255,255,255,0.9);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}
.toast:hover .toast-close { opacity: 1; }
.toast-close:hover { background: var(--bg-soft); color: var(--text); }

/* ---------- Sound toggle button in sidebar header ---------- */
.me-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}
.me-action-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  font-size: 14px;
  line-height: 1;
  color: var(--text-dim);
  display: inline-flex;
  align-items: center;
}
.me-action-btn:hover { background: var(--bg-soft); }
.me-action-btn-active {
  background: var(--accent-soft);
  color: var(--accent);
}
.me-action-btn-active:hover { background: var(--accent-soft); }

/* ---------- Drag & drop overlay ---------- */
.drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 191, 111, 0.18);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.drop-overlay-text {
  background: white;
  padding: 24px 36px;
  border-radius: 16px;
  border: 2px dashed var(--accent);
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
  box-shadow: var(--shadow-lg);
}

/* ---------- Scrollbar ---------- */
.messages::-webkit-scrollbar,
.sidebar-section::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-track,
.sidebar-section::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb,
.sidebar-section::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 4px;
}
.messages::-webkit-scrollbar-thumb:hover,
.sidebar-section::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ---------- PWA install banner ---------- */
.install-banner {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 12px 8px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow-md);
  z-index: 800;
}
.install-banner-text {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}
.install-btn-primary {
  background: var(--accent);
  color: white;
  border: none;
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.install-btn-primary:hover { background: var(--accent-hover); }
.install-banner-dismiss {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 14px;
  padding: 4px 6px;
  border-radius: 4px;
}
.install-banner-dismiss:hover { background: var(--bg-soft); color: var(--text); }

/* ---------- Mobile (B: 2단계 네비) ---------- */
/* Slide-style mobile layout only kicks in at phone-sized viewports. The
   Electron desktop window (minWidth 720) never falls into this range, so
   sidebar + chat stay side-by-side no matter how narrow the user drags. */
@media (max-width: 480px) {
  body { font-size: 14px; }
  #chat-screen {
    position: relative;
    overflow: hidden;
  }
  .sidebar {
    width: 100%;
    border-right: none;
    transition: transform 0.25s ease;
  }
  .main {
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg);
    transform: translateX(100%);
    transition: transform 0.25s ease;
  }
  #chat-screen[data-mobile-view="chat"] .sidebar { transform: translateX(-100%); }
  #chat-screen[data-mobile-view="chat"] .main { transform: translateX(0); }

  .back-btn { display: inline-flex; }

  /* Login card scaled */
  .login-card {
    width: calc(100% - 32px);
    max-width: 380px;
    padding: 28px;
  }

  /* Sidebar adjustments on mobile */
  .sidebar-header { padding: 14px 16px; }
  .brand { font-size: 16px; margin-bottom: 10px; }
  .me-name { max-width: none; font-size: 14px; }
  .sidebar-section { padding: 12px 16px 8px; }

  /* Chat header adjustments */
  .chat-header {
    padding: 10px 14px;
    gap: 10px;
  }
  .room-title { font-size: 15px; }
  .room-actions { gap: 4px; display: flex; }
  .room-action-btn { padding: 5px 9px; font-size: 12px; }

  /* Search: back to inline flex on mobile */
  .search-wrap {
    position: relative;
    left: auto;
    top: auto;
    transform: none;
    flex: 1;
    width: auto;
    max-width: 180px;
  }
  .search-input { font-size: 12px; padding: 7px 10px; }
  .search-results { width: 290px; left: auto; right: 0; }

  /* Messages */
  .messages {
    padding: 14px 14px;
  }
  .msg { max-width: 85%; }
  .msg-bubble { padding: 9px 12px; line-height: 1.5; }
  .msg-image { max-width: 240px; max-height: 240px; }
  .msg-emoticon { width: 110px; height: 110px; }
  .msg-file .name { max-width: 160px; }

  /* Composer */
  .composer {
    padding: 10px 12px;
    gap: 6px;
  }
  .composer input[type="text"] {
    padding: 11px 12px;
    font-size: 14px;
  }
  .composer button[type="submit"] { padding: 11px 14px; font-size: 13px; }
  .file-btn, .emoticon-btn { width: 40px; height: 40px; }

  /* Reply preview */
  .reply-preview { padding: 8px 14px 8px 12px; }

  /* File preview */
  .file-preview {
    flex-wrap: wrap;
    padding: 10px 14px;
    gap: 8px;
  }
  .file-preview-name { max-width: 200px; }

  /* Toast: bottom center on mobile */
  .toast-stack {
    bottom: 12px;
    right: 12px;
    left: 12px;
    max-width: none;
  }
  .toast { width: auto; }

  /* Drop overlay text smaller */
  .drop-overlay-text { font-size: 14px; padding: 18px 24px; }

  /* Modals */
  .modal-content { width: calc(100% - 32px); max-width: 360px; }

  /* Emoji / reaction pickers responsive */
  .reaction-picker {
    width: calc(100% - 24px);
    max-width: 320px;
    left: 12px !important;
  }
  .emoji-picker-element {
    width: 100% !important;
    --num-columns: 7;
  }
  .emoticon-picker {
    width: calc(100% - 24px);
    max-width: 320px;
    left: 12px !important;
  }
  .emoticon-grid { grid-template-columns: repeat(4, 1fr); }
  .emoticon-item img { width: 50px; height: 50px; }

  /* Context menu touch-friendly */
  .ctx-item { padding: 8px 14px; font-size: 14px; }

  /* User list / Room list a touch larger */
  .user-item { padding: 10px 6px; }
  .user-name { font-size: 14px; }
  .room-item { padding: 9px 12px; font-size: 14px; }
}
