/* ═══════════════════════════════════════════════════════════════════════════
   BubbleChat — "Soft Berry" design system
   Calm surfaces, one strawberry accent, pastel highlights, generous radii.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Tokens ─────────────────────────────────────────────────────────────── */
:root,
[data-theme="dark"] {
  --bg: #150f21;
  --bg-sidebar: #1b1429;
  --surface: #241a37;
  --surface-2: #2d2242;
  --surface-3: #3a2d54;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.15);

  --text: #f6effd;
  --text-2: #cbbfe0;
  --text-3: #9a8db4;

  --accent: #ff7aa2;
  --accent-strong: #f0628f;
  --accent-soft: rgba(255, 122, 162, 0.16);
  --accent-ring: rgba(255, 122, 162, 0.28);
  --grad: linear-gradient(135deg, #f0628f 0%, #f78a72 100%);

  --bubble-other: #2d2242;
  --bubble-other-text: #f6effd;
  --bubble-other-border: rgba(255, 255, 255, 0.06);
  --bubble-own: #7b2f58;
  --bubble-own-text: #fff0f6;
  --bubble-own-border: rgba(255, 122, 162, 0.25);

  --green: #5fd3a8;
  --red: #ff6b81;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.5);

  --page-bg:
    radial-gradient(900px 520px at 8% -10%, rgba(255, 122, 162, 0.16), transparent 60%),
    radial-gradient(800px 520px at 100% 0%, rgba(155, 135, 245, 0.16), transparent 60%),
    var(--bg);
}

[data-theme="light"] {
  --bg: #fff8fb;
  --bg-sidebar: #ffffff;
  --surface: #ffffff;
  --surface-2: #fdf0f5;
  --surface-3: #fbe3ed;
  --border: rgba(90, 40, 70, 0.1);
  --border-strong: rgba(90, 40, 70, 0.18);

  --text: #3a2140;
  --text-2: #66506f;
  --text-3: #766080;

  --accent: #e8588a;
  --accent-strong: #d63f75;
  --accent-soft: rgba(232, 88, 138, 0.11);
  --accent-ring: rgba(232, 88, 138, 0.24);
  --grad: linear-gradient(135deg, #e8588a 0%, #f2766f 100%);

  --bubble-other: #ffffff;
  --bubble-other-text: #3a2140;
  --bubble-other-border: rgba(90, 40, 70, 0.1);
  --bubble-own: #ffdce9;
  --bubble-own-text: #4a1d38;
  --bubble-own-border: rgba(232, 88, 138, 0.22);

  --green: #1fae7d;
  --red: #d63354;
  --shadow-sm: 0 1px 3px rgba(120, 50, 90, 0.08);
  --shadow-md: 0 8px 24px rgba(120, 50, 90, 0.12);
  --shadow-lg: 0 20px 60px rgba(120, 50, 90, 0.18);

  --page-bg:
    radial-gradient(900px 520px at 0% -10%, #ffe1ed, transparent 60%),
    radial-gradient(800px 520px at 100% 0%, #ece6ff, transparent 60%),
    radial-gradient(700px 420px at 50% 115%, #fff0d9, transparent 60%),
    var(--bg);
}

:root {
  --r-sm: 12px;
  --r-md: 16px;
  --r-lg: 22px;
  --r-xl: 32px;
  --r-full: 9999px;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-display: 'Outfit', 'Inter', sans-serif;
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --sidebar-w: 288px;
}

/* ── Base ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { color-scheme: light dark; }
[data-theme="light"] { color-scheme: light; }
[data-theme="dark"] { color-scheme: dark; }

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--page-bg);
  background-attachment: fixed;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
input, button, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
.hidden { display: none !important; }
::selection { background: var(--accent); color: #fff; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input:focus-visible, textarea:focus-visible, select:focus-visible { outline: none; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: var(--r-full); border: 2px solid transparent; background-clip: content-box; }

#sparkle-canvas { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 0; opacity: 0.4; }

/* ═══════════════════════════════════════════════════════════════════════════
   Login
   ═══════════════════════════════════════════════════════════════════════════ */
.login-screen {
  position: relative; z-index: 1;
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; min-height: 100dvh; padding: 20px; overflow-y: auto;
}
.login-card {
  position: relative; width: 100%; max-width: 440px; margin: auto;
  padding: 36px 32px 26px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: cardIn 0.7s var(--spring) both;
}
@keyframes cardIn { from { opacity: 0; transform: translateY(24px) scale(0.96); } to { opacity: 1; transform: none; } }

.login-bubbles { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.bubble { position: absolute; border-radius: 50%; opacity: 0.16; animation: float 11s ease-in-out infinite; }
.b1 { width: 110px; height: 110px; background: #ff7aa2; top: -36px; right: -28px; }
.b2 { width: 70px; height: 70px; background: #9b87f5; bottom: 70px; left: -26px; animation-delay: 2s; }
.b3 { width: 34px; height: 34px; background: #5fd3a8; top: 38%; right: 7%; animation-delay: 4s; }
.b4 { width: 84px; height: 84px; background: #ffb86b; bottom: -30px; right: 22%; animation-delay: 6s; }
.b5 { width: 22px; height: 22px; background: #6bc4ff; top: 16%; left: 10%; animation-delay: 3s; }
.b6 { width: 42px; height: 42px; background: #ffd66b; top: 58%; left: 4%; animation-delay: 5s; }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-14px); } }

.login-header { position: relative; text-align: center; margin-bottom: 22px; }
.logo-wrap { position: relative; display: inline-flex; margin-bottom: 10px; }
.logo-icon {
  width: 68px; height: 68px; display: grid; place-items: center; font-size: 32px;
  background: var(--grad); border-radius: 22px; box-shadow: 0 10px 28px var(--accent-ring);
  transform: rotate(-6deg); animation: wiggle 4s ease-in-out infinite;
}
@keyframes wiggle { 0%, 100% { transform: rotate(-6deg); } 50% { transform: rotate(4deg) translateY(-3px); } }
.logo-ring { display: none; }
.login-header h1 {
  margin: 0; font: 800 2rem/1.1 var(--font-display); letter-spacing: -0.02em;
  background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.tagline { margin: 6px 0 0; color: var(--text-2); font-size: 0.9rem; }

.login-form { position: relative; }
.input-wrapper {
  display: flex; align-items: center; gap: 10px; height: 50px; padding: 0 16px; margin-bottom: 10px;
  background: var(--surface-2); border: 1.5px solid var(--border); border-radius: var(--r-md);
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.input-wrapper:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-ring); background: var(--surface); }
.input-icon { font-size: 1.05rem; }
.input-wrapper input { flex: 1; min-width: 0; height: 100%; background: transparent; border: 0; font-size: 0.95rem; }
.input-wrapper input::placeholder { color: var(--text-3); }

.auth-error {
  margin: 0 0 10px; padding: 9px 12px; border-radius: var(--r-sm); text-align: center;
  font-size: 0.82rem; font-weight: 500; color: var(--red); background: color-mix(in srgb, var(--red) 12%, transparent);
}

.join-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; height: 50px;
  border-radius: var(--r-md); background: var(--grad); color: #fff;
  font: 700 1rem var(--font-display); box-shadow: 0 8px 20px var(--accent-ring);
  transition: transform 0.2s var(--spring), box-shadow 0.2s, filter 0.2s;
}
.join-btn:not(:disabled):hover { transform: translateY(-2px); box-shadow: 0 12px 26px var(--accent-ring); }
.join-btn:not(:disabled):active { transform: scale(0.98); }
.join-btn:disabled { background: var(--surface-3); color: var(--text-3); box-shadow: none; cursor: not-allowed; }

.login-features { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 20px; }
.feature-pill { padding: 5px 12px; border-radius: var(--r-full); font-size: 0.75rem; font-weight: 500; color: var(--text-2); background: var(--surface-2); border: 1px solid var(--border); }
.login-footer { display: flex; justify-content: center; gap: 18px; margin-top: 16px; font-size: 0.75rem; color: var(--text-3); }

/* Avatar picker (login + profile) */
.avatar-picker-wrap { text-align: center; margin-bottom: 14px; }
.avatar-preview {
  width: 80px; height: 80px; margin: 0 auto 8px; display: grid; place-items: center; font-size: 42px;
  border-radius: 50%; background: var(--accent-soft); border: 3px solid var(--surface);
  box-shadow: 0 0 0 2px var(--accent), var(--shadow-md);
}
.avatar-preview.pop { animation: pop 0.4s var(--spring); }
@keyframes pop { 0% { transform: scale(0.6) rotate(-12deg); opacity: 0.4; } 100% { transform: none; opacity: 1; } }
.avatar-label { margin: 0 0 10px; font: 600 0.82rem var(--font-display); color: var(--text-2); }
.avatar-grid {
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; max-height: 148px; overflow-y: auto; padding: 8px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md);
}
.avatar-option {
  aspect-ratio: 1; display: grid; place-items: center; font-size: 22px; border-radius: 50%;
  border: 2px solid transparent; transition: transform 0.2s var(--spring), background 0.15s;
}
.avatar-option:hover { transform: scale(1.2); background: var(--surface-3); }
.avatar-option.selected { border-color: var(--accent); background: var(--accent-soft); transform: scale(1.1); }

/* ═══════════════════════════════════════════════════════════════════════════
   App shell
   ═══════════════════════════════════════════════════════════════════════════ */
.chat-screen { position: relative; z-index: 1; display: flex; height: 100vh; height: 100dvh; }

/* ── Sidebar ────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; display: flex; flex-direction: column;
  background: var(--bg-sidebar); border-right: 1px solid var(--border); z-index: 30;
}
.sidebar-header { display: flex; align-items: center; gap: 12px; padding: 20px 20px 14px; }
.sidebar-logo {
  width: 42px; height: 42px; display: grid; place-items: center; font-size: 21px; flex-shrink: 0;
  background: var(--grad); border-radius: 14px; box-shadow: 0 6px 16px var(--accent-ring); transform: rotate(-5deg);
}
.sidebar-header h2 { margin: 0; font: 800 1.15rem/1.2 var(--font-display); letter-spacing: -0.01em; }
.sidebar-tagline { font-size: 0.72rem; color: var(--text-3); }

.sidebar-section { padding: 6px 12px 10px; }
.sidebar-section:last-of-type { flex: 1; min-height: 0; overflow-y: auto; }
.sidebar-section h3 {
  margin: 6px 0 6px; padding: 0 8px; font: 700 0.68rem var(--font-body); letter-spacing: 0.09em;
  text-transform: uppercase; color: var(--text-3);
}
.room-list, .online-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }

.room-item {
  --rc: var(--accent);
  display: flex; align-items: center; gap: 12px; padding: 7px 10px; border-radius: 14px; cursor: pointer;
  color: var(--text-2); transition: background 0.15s, color 0.15s, transform 0.15s;
}
.room-emoji {
  width: 34px; height: 34px; display: grid; place-items: center; flex-shrink: 0; font-size: 17px; border-radius: 11px;
  background: var(--accent-soft); background: color-mix(in srgb, var(--rc) 20%, transparent);
}
.room-name { flex: 1; min-width: 0; font-size: 0.9rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-count {
  min-width: 22px; height: 22px; padding: 0 7px; display: grid; place-items: center;
  font-size: 0.7rem; font-weight: 700; color: var(--text-3); background: var(--surface-2); border-radius: var(--r-full);
}
.room-item:hover { background: var(--surface-2); color: var(--text); }
.room-item.active { background: var(--accent-soft); background: color-mix(in srgb, var(--rc) 15%, transparent); color: var(--text); }
.room-item.active .room-name { font-weight: 700; }
.room-item.active .room-count { background: color-mix(in srgb, var(--rc) 30%, transparent); color: var(--text); }

.online-user {
  display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-radius: 12px; font-size: 0.875rem; font-weight: 500;
  animation: slideIn 0.3s var(--ease) both;
}
@keyframes slideIn { from { opacity: 0; transform: translateX(-8px); } to { opacity: 1; transform: none; } }
.online-user:hover { background: var(--surface-2); }
.online-avatar { position: relative; width: 30px; height: 30px; display: grid; place-items: center; font-size: 16px; background: var(--surface-2); border-radius: 50%; flex-shrink: 0; }
.online-avatar::after {
  content: ''; position: absolute; right: -1px; bottom: -1px; width: 10px; height: 10px; border-radius: 50%;
  background: var(--green); border: 2px solid var(--bg-sidebar);
}
.online-room-tag { margin-left: auto; font-size: 0.8rem; opacity: 0.8; }

.sidebar-footer { padding: 12px; border-top: 1px solid var(--border); }
.user-card {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; text-align: left;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md);
  transition: background 0.15s, border-color 0.15s;
}
.user-card:hover { background: var(--surface-3); border-color: var(--border-strong); }
.user-card-avatar { width: 38px; height: 38px; display: grid; place-items: center; font-size: 20px; border-radius: 50%; background: var(--accent-soft); flex-shrink: 0; }
.user-card-info { display: flex; flex-direction: column; min-width: 0; }
.user-card-name { font-size: 0.9rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-card-status { font-size: 0.72rem; color: var(--green); font-weight: 600; }
.user-card-edit { margin-left: auto; font-size: 0.8rem; opacity: 0; transition: opacity 0.15s; }
.user-card:hover .user-card-edit { opacity: 0.8; }

.sidebar-overlay { display: none; }

/* ── Main column ────────────────────────────────────────────────────────── */
.chat-main { position: relative; flex: 1; min-width: 0; display: flex; flex-direction: column; }

.chat-header {
  display: flex; align-items: center; gap: 12px; height: 66px; padding: 0 20px; flex-shrink: 0;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border); z-index: 10;
}
.sidebar-toggle { display: none; width: 40px; height: 40px; place-items: center; border-radius: 12px; color: var(--text-2); }
.sidebar-toggle:hover { background: var(--surface-2); }
.header-room-info { display: flex; align-items: center; gap: 12px; min-width: 0; }
.header-room-emoji { width: 42px; height: 42px; display: grid; place-items: center; font-size: 21px; border-radius: 14px; background: var(--accent-soft); flex-shrink: 0; }
.header-room-info h2 { margin: 0; font: 700 1.08rem/1.2 var(--font-display); }
.header-room-desc { display: block; font-size: 0.78rem; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-actions { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.header-member-count {
  display: flex; align-items: center; gap: 6px; margin-right: 6px; padding: 5px 12px; border-radius: var(--r-full);
  font-size: 0.75rem; font-weight: 600; color: var(--text-2); background: var(--surface-2); border: 1px solid var(--border);
}
.member-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 25%, transparent); }
.header-btn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; color: var(--text-2); transition: background 0.15s, color 0.15s, transform 0.2s var(--spring); }
.header-btn:hover { background: var(--surface-2); color: var(--accent-strong); transform: scale(1.08); }
.header-btn svg { width: 19px; height: 19px; }

/* icon state swaps (pure CSS) */
[data-theme="dark"] .i-moon, [data-theme="light"] .i-sun { display: none; }
.header-btn:not(.muted) .i-bell-off, .header-btn.muted .i-bell { display: none; }

/* ── Search panel ───────────────────────────────────────────────────────── */
.search-panel { background: var(--surface); border-bottom: 1px solid var(--border); box-shadow: var(--shadow-md); z-index: 9; }
.search-bar { display: flex; align-items: center; gap: 10px; padding: 12px 20px; }
.search-bar input[type="search"] {
  flex: 1; min-width: 0; height: 40px; padding: 0 16px; border-radius: var(--r-full);
  background: var(--surface-2); border: 1.5px solid var(--border);
}
.search-bar input[type="search"]:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-ring); }
.search-bar input::placeholder { color: var(--text-3); }
.search-scope { display: flex; align-items: center; gap: 6px; font-size: 0.78rem; color: var(--text-2); white-space: nowrap; cursor: pointer; }
.search-scope input { accent-color: var(--accent); }
.search-results { max-height: 40vh; overflow-y: auto; padding: 0 14px 12px; }
.search-empty { margin: 12px 0; text-align: center; font-size: 0.86rem; color: var(--text-3); }
.search-result { display: flex; align-items: flex-start; gap: 10px; width: 100%; padding: 9px 10px; border-radius: 14px; text-align: left; transition: background 0.15s; }
.search-result:hover { background: var(--surface-2); }
.sr-avatar { font-size: 1.4rem; line-height: 1.2; }
.sr-main { display: flex; flex-direction: column; min-width: 0; }
.sr-meta { font-size: 0.74rem; color: var(--text-3); }
.sr-meta strong { color: var(--text); }
.sr-text { font-size: 0.88rem; overflow-wrap: anywhere; }
.sr-text mark { padding: 0 3px; border-radius: 4px; background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }

/* ── Message list ───────────────────────────────────────────────────────── */
.messages-container { flex: 1; overflow-y: auto; padding: 22px 28px 12px; scroll-behavior: smooth; }
.load-older { text-align: center; padding: 8px; font-size: 0.78rem; color: var(--text-3); }

.messages-welcome {
  display: grid; grid-template-columns: auto 1fr; column-gap: 14px; align-items: center;
  max-width: 460px; margin: 0 auto 10px; padding: 14px 18px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-sm);
}
.welcome-emoji { grid-row: span 2; font-size: 34px; line-height: 1; }
.messages-welcome h3 { margin: 0; font: 700 1rem var(--font-display); }
.messages-welcome h3 span { color: var(--accent-strong); }
.messages-welcome p { margin: 0; font-size: 0.82rem; color: var(--text-3); }

.messages { display: flex; flex-direction: column; }

.day-sep { display: flex; align-items: center; gap: 12px; margin: 18px 0 6px; }
.day-sep::before, .day-sep::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.day-sep span { padding: 3px 12px; border-radius: var(--r-full); font-size: 0.7rem; font-weight: 600; letter-spacing: 0.03em; color: var(--text-3); background: var(--surface); border: 1px solid var(--border); }

/* ── Messages ───────────────────────────────────────────────────────────── */
.message {
  --uc: var(--accent);
  position: relative; display: flex; align-items: flex-start; gap: 10px;
  width: fit-content; max-width: min(82%, 680px); margin-top: 14px;
  animation: msgIn 0.25s var(--ease) both;
}
@keyframes msgIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.message.grouped { margin-top: 3px; animation: none; }
.message.own { flex-direction: row-reverse; margin-left: auto; }

.msg-avatar {
  width: 36px; height: 36px; flex-shrink: 0; display: grid; place-items: center; font-size: 19px; border-radius: 50%;
  background: var(--accent-soft); background: color-mix(in srgb, var(--uc) 24%, var(--surface));
  border: 2px solid var(--surface); box-shadow: var(--shadow-sm);
}
.message.grouped .msg-avatar { visibility: hidden; height: 0; }
.message.own .msg-avatar { display: none; }

.msg-body { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; }
.message.own .msg-body { align-items: flex-end; }

.msg-header { display: flex; align-items: baseline; gap: 8px; margin: 0 4px 3px; }
.msg-username { font-size: 0.82rem; font-weight: 700; }
.msg-time { font-size: 0.68rem; color: var(--text-3); }
.msg-edited { font-size: 0.68rem; color: var(--text-3); font-style: italic; }
.msg-edited:empty { display: none; }
.message.own .msg-username { display: none; }
.message.grouped .msg-header { display: none; }

.msg-content {
  margin: 0; padding: 9px 14px; border-radius: 18px; max-width: 100%;
  background: var(--bubble-other); color: var(--bubble-other-text); border: 1px solid var(--bubble-other-border);
  box-shadow: var(--shadow-sm); font-size: 0.94rem; line-height: 1.5; overflow-wrap: anywhere; white-space: pre-wrap;
}
.message:not(.own):not(.grouped) .msg-content { border-top-left-radius: 6px; }
.message.own .msg-content { background: var(--bubble-own); color: var(--bubble-own-text); border-color: var(--bubble-own-border); }
.message.own:not(.grouped) .msg-content { border-top-right-radius: 6px; }
.msg-content a { color: var(--accent-strong); text-decoration: underline; text-underline-offset: 2px; }
.message.own .msg-content a { color: inherit; }

.msg-reply-ref {
  max-width: 100%; margin-bottom: 4px; padding: 5px 10px; font-size: 0.76rem; color: var(--text-2);
  background: var(--accent-soft); border-left: 3px solid var(--accent); border-radius: 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.msg-image {
  display: block; max-width: min(320px, 100%); max-height: 340px; border-radius: 18px; cursor: zoom-in;
  border: 1px solid var(--bubble-other-border); box-shadow: var(--shadow-md); transition: transform 0.2s var(--spring);
}
.msg-image:hover { transform: scale(1.02); }
.message:not(.own):not(.grouped) .msg-image { border-top-left-radius: 6px; }
.message.own:not(.grouped) .msg-image { border-top-right-radius: 6px; }

.msg-reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.reaction-badge {
  display: inline-flex; align-items: center; gap: 4px; height: 26px; padding: 0 9px; font-size: 0.8rem;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-full);
  transition: transform 0.15s var(--spring), background 0.15s;
}
.reaction-badge:hover { transform: scale(1.08); }
.reaction-badge.own { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-strong); }
.reaction-count { font-weight: 700; font-size: 0.74rem; }

.msg-actions {
  position: absolute; top: -16px; right: 0; display: flex; gap: 1px; padding: 2px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 12px; box-shadow: var(--shadow-md);
  opacity: 0; pointer-events: none; transform: translateY(4px); transition: opacity 0.15s, transform 0.15s; z-index: 5;
}
.message.own .msg-actions { right: auto; left: 0; }
.message:hover .msg-actions, .message:focus-within .msg-actions { opacity: 1; pointer-events: auto; transform: none; }
.msg-action-btn { width: 30px; height: 28px; display: grid; place-items: center; font-size: 0.9rem; border-radius: 9px; transition: background 0.15s, transform 0.15s var(--spring); }
.msg-action-btn:hover { background: var(--surface-2); transform: scale(1.15); }
@media (hover: none) { .msg-actions { opacity: 1; pointer-events: auto; transform: none; position: static; margin-top: 2px; box-shadow: none; background: transparent; border: 0; } }

.message.system { margin: 10px auto; max-width: 90%; animation: none; }
.message.system .msg-body { align-items: center; }
.message.system .msg-content { padding: 3px 12px; font-size: 0.74rem; color: var(--text-3); background: transparent; border: 0; box-shadow: none; text-align: center; }

.message.deleted .msg-content, .msg-deleted-text { font-style: italic; color: var(--text-3) !important; background: transparent !important; border: 1px dashed var(--border-strong) !important; box-shadow: none; }

.msg-edit { display: flex; align-items: center; gap: 6px; }
.msg-edit input { min-width: 180px; height: 36px; padding: 0 14px; background: var(--surface); border: 1.5px solid var(--accent); border-radius: var(--r-full); }
.msg-edit button { width: 32px; height: 32px; border-radius: 50%; background: var(--surface-2); }
.msg-edit-save { background: var(--grad) !important; color: #fff; }

.message.flash .msg-content, .message.flash .msg-image { animation: flash 2.2s ease; }
@keyframes flash { 0%, 55% { box-shadow: 0 0 0 4px var(--accent-ring); } 100% { box-shadow: var(--shadow-sm); } }

/* ── Typing ─────────────────────────────────────────────────────────────── */
.typing-indicator { display: flex; align-items: center; gap: 8px; margin: 12px 0 2px; }
.typing-avatar { width: 28px; height: 28px; display: grid; place-items: center; font-size: 15px; border-radius: 50%; background: var(--surface-2); }
.typing-bubble { padding: 9px 13px; background: var(--bubble-other); border: 1px solid var(--bubble-other-border); border-radius: 16px 16px 16px 6px; }
.typing-dots { display: flex; gap: 4px; }
.typing-dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--text-3); animation: bounce 1.2s infinite ease-in-out; }
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.5; } 30% { transform: translateY(-4px); opacity: 1; } }
.typing-text { font-size: 0.76rem; color: var(--text-3); }

/* ── Composer ───────────────────────────────────────────────────────────── */
.reply-preview {
  display: flex; align-items: center; gap: 10px; margin: 0 24px 6px; padding: 8px 12px;
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: var(--r-md);
}
.reply-preview-content { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: 0.8rem; }
.reply-preview-label { color: var(--text-2); }
.reply-preview-text { color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-cancel { width: 26px; height: 26px; border-radius: 50%; color: var(--text-3); }
.reply-cancel:hover { background: var(--surface-2); color: var(--text); }

.chat-footer { padding: 8px 24px 18px; flex-shrink: 0; }
.message-input-wrapper {
  display: flex; align-items: center; gap: 2px; padding: 6px 6px 6px 10px;
  background: var(--surface); border: 1.5px solid var(--border-strong); border-radius: var(--r-full); box-shadow: var(--shadow-md);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.message-input-wrapper:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-ring), var(--shadow-md); }
.message-input-wrapper > input[type="text"] { flex: 1; min-width: 0; height: 40px; padding: 0 10px; background: transparent; border: 0; }
.message-input-wrapper > input::placeholder { color: var(--text-3); }
.input-emoji-btn { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; color: var(--text-3); transition: background 0.15s, color 0.15s; }
.input-emoji-btn:hover { background: var(--surface-2); color: var(--accent-strong); }
.input-emoji-btn svg { width: 21px; height: 21px; }
.send-btn {
  width: 42px; height: 42px; display: grid; place-items: center; border-radius: 50%; flex-shrink: 0;
  background: var(--grad); color: #fff; box-shadow: 0 6px 14px var(--accent-ring); transition: transform 0.2s var(--spring), opacity 0.15s;
}
.send-btn:not(:disabled):hover { transform: scale(1.1) rotate(8deg); }
.send-btn:not(:disabled):active { transform: scale(0.94); }
.send-btn:disabled { background: var(--surface-3); color: var(--text-3); box-shadow: none; cursor: default; }
.send-btn svg { margin-left: -2px; }

/* ── Pickers ────────────────────────────────────────────────────────────── */
.emoji-picker {
  position: absolute; left: 24px; bottom: 84px; width: 344px; max-width: calc(100% - 48px); z-index: 20;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-lg); box-shadow: var(--shadow-lg); overflow: hidden;
  animation: pop 0.25s var(--spring);
}
.emoji-tabs { display: flex; gap: 2px; padding: 8px; overflow-x: auto; border-bottom: 1px solid var(--border); }
.emoji-tab { flex-shrink: 0; width: 34px; height: 34px; display: grid; place-items: center; font-size: 17px; border-radius: 10px; opacity: 0.6; transition: all 0.15s; }
.emoji-tab:hover { opacity: 1; background: var(--surface-2); }
.emoji-tab.active { opacity: 1; background: var(--accent-soft); }
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; max-height: 210px; overflow-y: auto; padding: 8px; }
.emoji-grid button { aspect-ratio: 1; display: grid; place-items: center; font-size: 21px; border-radius: 10px; transition: transform 0.15s var(--spring), background 0.15s; }
.emoji-grid button:hover { background: var(--surface-2); transform: scale(1.2); }

.reaction-picker {
  position: fixed; z-index: 150; display: flex; gap: 2px; padding: 5px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-full); box-shadow: var(--shadow-lg);
  animation: pop 0.22s var(--spring);
}
.reaction-picker button { width: 36px; height: 36px; display: grid; place-items: center; font-size: 20px; border-radius: 50%; transition: transform 0.15s var(--spring), background 0.15s; }
.reaction-picker button:hover { background: var(--surface-2); transform: scale(1.25); }

/* ── Modal, toast, lightbox ─────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; padding: 16px;
  background: rgba(20, 8, 30, 0.5); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.modal-card {
  width: 100%; max-width: 410px; max-height: 92vh; overflow-y: auto; padding: 24px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-xl); box-shadow: var(--shadow-lg);
  animation: pop 0.3s var(--spring);
}
.modal-card h3 { margin: 0 0 14px; text-align: center; font: 700 1.2rem var(--font-display); }
.modal-label { display: block; margin: 14px 0 5px; font: 600 0.78rem var(--font-display); color: var(--text-2); }
.modal-card textarea, .modal-card select {
  width: 100%; padding: 10px 14px; resize: none; background: var(--surface-2); border: 1.5px solid var(--border); border-radius: var(--r-md);
}
.modal-card textarea:focus, .modal-card select:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-ring); }
.modal-actions { display: flex; align-items: center; gap: 8px; margin-top: 18px; }
.modal-actions .spacer { flex: 1; }
.btn-soft, .btn-primary { padding: 10px 18px; border-radius: var(--r-full); font: 600 0.85rem var(--font-display); transition: transform 0.2s var(--spring), background 0.15s; }
.btn-soft { background: var(--surface-2); color: var(--text-2); }
.btn-soft:hover { background: var(--surface-3); }
.btn-soft.danger { color: var(--red); }
.btn-primary { background: var(--grad); color: #fff; box-shadow: 0 6px 14px var(--accent-ring); }
.btn-primary:hover { transform: scale(1.05); }

.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); z-index: 300; max-width: 90vw;
  padding: 11px 20px; border-radius: var(--r-full); font-size: 0.86rem; font-weight: 500;
  background: var(--text); color: var(--bg); box-shadow: var(--shadow-lg); animation: toastIn 0.3s var(--spring);
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }

.lightbox { position: fixed; inset: 0; z-index: 250; display: grid; place-items: center; padding: 20px; background: rgba(15, 6, 24, 0.88); cursor: zoom-out; }
.lightbox img { max-width: 95vw; max-height: 92vh; border-radius: 18px; box-shadow: var(--shadow-lg); }

/* ═══════════════════════════════════════════════════════════════════════════
   Responsive
   ═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 860px) {
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 100; box-shadow: var(--shadow-lg);
    transform: translateX(-102%); transition: transform 0.3s var(--ease);
  }
  .sidebar.open { transform: none; }
  .sidebar.open + .sidebar-overlay { display: block; position: fixed; inset: 0; z-index: 90; background: rgba(20, 8, 30, 0.45); }
  .sidebar-toggle { display: grid; }
  .chat-header { padding: 0 12px; gap: 8px; }
  .header-member-count { display: none; }
  .messages-container { padding: 16px 14px 8px; }
  .message { max-width: 92%; }
  .chat-footer { padding: 6px 12px 12px; }
  .reply-preview { margin: 0 12px 6px; }
  .emoji-picker { left: 12px; bottom: 74px; }
  .search-bar { padding: 10px 12px; flex-wrap: wrap; }
  .search-scope { order: 3; }
}
@media (max-width: 480px) {
  .login-card { padding: 28px 20px 22px; }
  .avatar-grid { grid-template-columns: repeat(6, 1fr); }
  .header-room-desc { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}

/* ── Notifications ──────────────────────────────────────────────────────── */
.notify-banner {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 20px;
  background: var(--accent-soft); border-bottom: 1px solid var(--border); font-size: 0.86rem; z-index: 8;
}
.notify-banner-icon { font-size: 1.2rem; }
.notify-banner-text { flex: 1 1 220px; color: var(--text); }
.notify-banner .btn-primary, .notify-banner .btn-soft { padding: 7px 14px; font-size: 0.8rem; }
.notify-banner .btn-soft { background: var(--surface); }
.notify-box { display: flex; flex-direction: column; gap: 8px; padding: 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md); }
.notify-status { margin: 0; font-size: 0.8rem; color: var(--text-2); line-height: 1.45; }
.notify-box .btn-soft { background: var(--surface); border: 1px solid var(--border-strong); }
.notify-box .btn-soft:disabled { opacity: 0.55; cursor: not-allowed; }
.notify-box select:disabled { opacity: 0.55; }
@media (max-width: 860px) { .notify-banner { padding: 10px 12px; } }
