:root {
  /* Dimensions & Spatial Shapes */
  --radius-xs: 8px;
  --radius-sm: 12px;
  --radius-md: 18px;
  --radius-lg: 24px;
  --radius-xl: 32px;
  --radius-pill: 9999px;

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ── DARK THEME (Restrained Professional Slate) ── */
:root[data-theme="dark"], :root {
  --bg-app: #101216;
  --bg-main: #15181D;
  --bg-panel: #1B1F26;
  --bg-panel-hover: #20252D;
  --bg-glass: #171A20;
  --bg-glass-card: #20252D;

  --border-light: #303640;
  --border-focus: rgba(255, 255, 255, 0.3);
  --border-outline: #252B34;
  --border-glass: #303640;
  --border-glass-highlight: #3A414C;

  --text-main: #E5E7EB;
  --text-muted: #9CA3AF;
  --text-dark: #6B7280;

  --accent-primary: #344054;
  --accent-primary-hover: #475467;
  --accent-primary-alpha: rgba(255, 255, 255, 0.05);
  --accent-gradient: #344054;
  --accent-gradient-hover: #475467;

  --success: #34D399;
  --danger: #EF4444;
  --warning: #F59E0B;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
  --shadow-glass-glow: none;

  --msg-self-bg: #2A313C;
  --msg-self-text: #E5E7EB;
  --msg-other-bg: #1B1F26;
  --msg-other-text: #E5E7EB;
  --msg-other-border: #303640;

  --sidebar-overlay-bg: rgba(21, 24, 29, 0.8);
  --icon-color: #9CA3AF;
}

/* ── LIGHT SPATIAL THEME (Frosted Platinum Crystal Glass) ── */
:root[data-theme="light"] {
  --bg-app: #eaeff4;
  --bg-main: rgba(255, 255, 255, 0.78);
  --bg-panel: rgba(0, 0, 0, 0.04);
  --bg-panel-hover: rgba(0, 0, 0, 0.07);
  --bg-glass: rgba(255, 255, 255, 0.78);
  --bg-glass-card: rgba(255, 255, 255, 0.88);

  --border-light: rgba(0, 0, 0, 0.08);
  --border-focus: rgba(15, 23, 42, 0.4);
  --border-outline: rgba(0, 0, 0, 0.04);
  --border-glass: rgba(255, 255, 255, 0.6);
  --border-glass-highlight: rgba(255, 255, 255, 0.95);

  --text-main: #0f172a;
  --text-muted: #475569;
  --text-dark: #64748b;

  --accent-primary: #0f172a;
  --accent-primary-hover: #1e293b;
  --accent-primary-alpha: rgba(15, 23, 42, 0.1);
  --accent-gradient: #0f172a;
  --accent-gradient-hover: #1e293b;

  --success: #059669;
  --danger: #dc2626;
  --warning: #d97706;

  --shadow-sm: 0 4px 12px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 16px 32px -8px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 24px 50px rgba(15, 23, 42, 0.1);
  --shadow-glass-glow: inset 0 1px 0 0 rgba(255, 255, 255, 0.95);

  --msg-self-bg: #0f172a;
  --msg-self-text: #ffffff;
  --msg-other-bg: rgba(255, 255, 255, 0.92);
  --msg-other-text: #0f172a;
  --msg-other-border: rgba(0, 0, 0, 0.08);

  --sidebar-overlay-bg: rgba(15, 23, 42, 0.45);
  --icon-color: #475569;
}

/* ── Base Reset & Spatial Atmosphere ── */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-main);
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
  position: relative;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Atmospheric Ambient Spatial Lighting - Disabled for professional look */
body::before {
  display: none;
}

.background-orbs,
.bg-grid {
  display: none;
}

/* ── Real Glassmorphism Utility ── */
.glass-panel {
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-glass);
  box-shadow: var(--shadow-glass-glow), var(--shadow-lg);
}

/* ── Toast Notification Styling ── */
.toast-container {
  position: fixed;
  top: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
  width: max-content;
  max-width: 90vw;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.65rem 1.25rem;
  border-radius: var(--radius-pill);
  background: var(--bg-glass-card);
  backdrop-filter: blur(30px);
  -webkit-backdrop-filter: blur(30px);
  border: 1px solid var(--border-glass-highlight);
  box-shadow: var(--shadow-md);
  color: var(--text-main);
  font-size: 0.85rem;
  font-weight: 500;
  animation: toastSlideDown 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.toast-icon {
  display: flex;
  align-items: center;
  color: var(--text-main);
}

@keyframes toastSlideDown {
  from {
    opacity: 0;
    transform: translateY(-12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ── Theme Toggle Button (Spatial Glass Pill) ── */
.theme-toggle {
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  cursor: pointer;
  color: var(--icon-color);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.45rem 0.75rem;
  border-radius: var(--radius-pill);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.theme-toggle:hover {
  background: var(--bg-panel-hover);
  color: var(--text-main);
  border-color: var(--border-glass-highlight);
}

[data-theme="dark"] .moon-icon { display: none; }
[data-theme="light"] .sun-icon { display: none; }

/* Display Helpers */
.d-none { display: none !important; }

.d-lg-none { display: block; }
@media (min-width: 1024px) {
  .d-lg-none { display: none !important; }
}

/* ── Routing Screens ── */
.screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.screen.active {
  display: flex;
  opacity: 1;
}

/* ── JOIN SCREEN (Spatial Glass Window Modal) ── */
#join-screen {
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 10;
}

.join-card {
  width: 100%;
  max-width: 440px;
  padding: 2.5rem;
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  box-shadow: var(--shadow-lg), var(--shadow-glass-glow);
  animation: spatialWindowEnter 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes spatialWindowEnter {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.join-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.25rem;
}

.join-logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 6px;
}

.logo-text {
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text-main);
}

.logo-text .accent {
  color: var(--text-muted);
}

.invite-notice {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-panel);
  border: 1px solid var(--border-glass-highlight);
  color: var(--text-main);
  padding: 0.65rem 0.95rem;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
}

.join-subtitle {
  color: var(--text-muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

/* Forms & Inputs */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.form-group label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-icon {
  position: absolute;
  left: 1rem;
  color: var(--icon-color);
  pointer-events: none;
}

.input-wrapper input {
  width: 100%;
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-pill);
  padding: 0.85rem 1.1rem 0.85rem 2.8rem;
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 15px;
  outline: none;
  transition: all 0.2s ease;
}

.visibility-btn {
  position: absolute;
  right: 0.85rem;
  background: none;
  border: none;
  color: var(--icon-color);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.35rem;
  border-radius: var(--radius-pill);
}

.visibility-btn:hover {
  color: var(--text-main);
}

.input-wrapper input:focus {
  border-color: var(--border-glass-highlight);
  background: var(--bg-panel-hover);
  box-shadow: 0 0 0 3px var(--accent-primary-alpha);
}

.field-hint {
  font-size: 0.75rem;
  color: var(--text-dark);
  padding-left: 0.5rem;
}

/* Spatial Action Button */
.primary-btn {
  background: var(--accent-gradient);
  color: var(--msg-self-text);
  border: 1px solid var(--border-glass-highlight);
  border-radius: var(--radius-pill);
  padding: 0.95rem;
  font-family: var(--font-display);
  font-size: 0.98rem;
  font-weight: 700;
  letter-spacing: 0.3px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  margin-top: 0.5rem;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: var(--shadow-sm);
}

.primary-btn:hover {
  background: var(--accent-gradient-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md), var(--shadow-glass-glow);
}

.primary-btn:active {
  transform: translateY(1px);
}

.primary-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.status-container {
  min-height: 22px;
  text-align: center;
  font-size: 0.85rem;
}

.error-msg {
  color: var(--danger);
  font-weight: 500;
}

.wake-status {
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

/* ── CHAT SCREEN LAYOUT (Separated Spatial Multi-Window Layout) ── */
#chat-screen {
  display: none;
  width: 100vw;
  height: 100dvh;
  padding: 20px 24px;
  gap: 20px;
  overflow: hidden;
  z-index: 10;
  position: relative;
}

#chat-screen.active {
  display: flex;
}

/* Mobile/Tablet Sidebar Overlay */
.sidebar-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100dvh;
  background: var(--sidebar-overlay-bg);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.sidebar-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

/* Distinct Floating Sidebar Glass Window */
.sidebar {
  width: 300px;
  height: 100%;
  border-radius: var(--radius-lg);
  background: var(--bg-glass);
  backdrop-filter: blur(40px) saturate(190%);
  -webkit-backdrop-filter: blur(40px) saturate(190%);
  border: 1px solid var(--border-glass);
  box-shadow: var(--shadow-lg), var(--shadow-glass-glow);
  display: flex;
  flex-direction: column;
  z-index: 100;
  flex-shrink: 0;
  overflow: hidden;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.sidebar-header {
  padding: 1.25rem 1.4rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-light);
  height: 68px;
  flex-shrink: 0;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.sidebar-logo .logo-icon {
  width: 32px;
  height: 32px;
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 5px;
}

.sidebar-logo .logo-text {
  font-size: 1.35rem;
  font-weight: 800;
}

.close-sidebar-btn {
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  color: var(--icon-color);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.4rem;
  border-radius: var(--radius-pill);
}

.close-sidebar-btn:hover {
  color: var(--text-main);
  background: var(--bg-panel-hover);
}

.sidebar-content {
  flex: 1;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  overflow-y: auto;
}

.info-card {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.info-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.room-code-box {
  background: var(--bg-panel);
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.info-value {
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
}

.room-action-buttons {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.inline-btn {
  background: transparent;
  border: none;
  color: var(--icon-color);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.35rem;
  border-radius: var(--radius-pill);
  transition: all 0.2s ease;
}

.inline-btn:hover {
  color: var(--text-main);
  background: var(--bg-panel-hover);
}

.share-link-btn {
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius-pill);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  transition: all 0.2s ease;
}

.share-link-btn:hover {
  background: var(--bg-panel-hover);
  border-color: var(--border-glass-highlight);
}

/* User Profile Row */
.user-profile {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--bg-panel);
  padding: 0.75rem 0.95rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
}

.profile-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.profile-name {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.profile-status {
  font-size: 0.72rem;
  color: var(--success);
  font-weight: 500;
}

.avatar-placeholder,
.avatar-sm {
  background: var(--bg-panel-hover);
  color: var(--text-main);
  border: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-family: var(--font-sans);
  flex-shrink: 0;
}

.avatar-placeholder {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-pill);
  font-size: 1.05rem;
}

.avatar-sm {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-pill);
  font-size: 0.85rem;
}

/* Active Members Row */
.members-card {
  flex: 1;
  min-height: 0; /* Important for flex child scrolling */
  display: flex;
  flex-direction: column;
}

.users-badge-sm {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--success);
  font-size: 0.75rem;
  font-weight: 700;
}

.pulse-dot {
  width: 7px;
  height: 7px;
  background-color: var(--success);
  border-radius: 50%;
}

.members-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1;
  overflow-y: auto;
  padding-right: 0.25rem; /* Space for custom scrollbar */
}

.member-chip {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--bg-panel);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  font-size: 0.82rem;
  color: var(--text-main);
  transition: background 0.2s;
}

.member-chip:hover {
  background: var(--bg-panel-hover);
}

.member-chip .member-name {
  font-weight: 600;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.member-chip .member-you {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-weight: 700;
  background: var(--bg-panel-hover);
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-pill);
}

.security-badge {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem;
  background: var(--bg-panel);
  border-radius: var(--radius-sm);
  color: var(--success);
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid var(--border-light);
}

.sidebar-footer {
  padding: 1.1rem 1.4rem;
  border-top: 1px solid var(--border-light);
}

.secondary-btn {
  width: 100%;
  padding: 0.75rem;
  border-radius: var(--radius-pill);
  background: transparent;
  border: 1px solid var(--border-light);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: all 0.2s ease;
}

.secondary-btn:hover {
  background: var(--bg-panel-hover);
}

.danger-btn:hover {
  background: rgba(248, 113, 113, 0.12);
  color: var(--danger);
  border-color: rgba(248, 113, 113, 0.3);
}

/* Distinct Floating Main Chat Glass Window */
.chat-main {
  flex: 1;
  height: 100%;
  border-radius: var(--radius-lg);
  background: var(--bg-glass);
  backdrop-filter: blur(40px) saturate(190%);
  -webkit-backdrop-filter: blur(40px) saturate(190%);
  border: 1px solid var(--border-glass);
  box-shadow: var(--shadow-lg), var(--shadow-glass-glow);
  display: flex;
  flex-direction: column;
  position: relative;
  min-width: 0;
  overflow: hidden;
}

.chat-header {
  height: 68px;
  padding: 0 1.5rem;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  background: transparent;
}

.header-left,
.header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.menu-toggle {
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  padding: 0.5rem;
  border-radius: var(--radius-pill);
}

.header-room-info {
  display: flex;
  flex-direction: column;
}

.header-label {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.icon-btn {
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  color: var(--icon-color);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5rem 0.8rem;
  border-radius: var(--radius-pill);
  font-size: 0.8rem;
  font-weight: 600;
  transition: all 0.2s ease;
}

.icon-btn:hover {
  background: var(--bg-panel-hover);
  color: var(--text-main);
  border-color: var(--border-glass-highlight);
}

/* ── MESSAGES CANVAS ── */
.messages-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.messages-area {
  flex: 1;
  padding: 1.5rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  scroll-behavior: smooth;
}

/* Custom Global WebKit Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-glass-highlight);
}

.system-msg {
  align-self: center;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin: 0.35rem 0;
  padding: 0.4rem 0.9rem;
  border-radius: var(--radius-pill);
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
}

.system-icon {
  color: var(--text-muted);
  display: flex;
}

.welcome-msg {
  background: var(--bg-panel);
  border-color: var(--border-light);
  color: var(--text-main);
}

/* Spatial Chat Bubbles */
.msg {
  display: flex;
  flex-direction: column;
  max-width: 78%;
  position: relative;
  animation: spatialMsgSlide 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes spatialMsgSlide {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg.self {
  align-self: flex-end;
}

.msg.other {
  align-self: flex-start;
}

.msg-meta {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
  padding: 0 0.3rem;
}

.msg.self .msg-meta {
  justify-content: flex-end;
}

.msg-author {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-main);
}

.msg.self .msg-author {
  display: none;
}

.msg-time {
  font-size: 0.68rem;
  color: var(--text-dark);
}

.msg-bubble-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.msg-bubble {
  padding: 0.85rem 1.15rem;
  font-size: 0.93rem;
  line-height: 1.5;
  word-wrap: break-word;
  white-space: pre-wrap;
  position: relative;
  border-radius: var(--radius-md);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.msg.other .msg-bubble {
  background: var(--msg-other-bg);
  border: 1px solid var(--msg-other-border);
  border-bottom-left-radius: 4px;
  color: var(--msg-other-text);
  box-shadow: var(--shadow-sm);
}

.msg.self .msg-bubble {
  background: var(--msg-self-bg);
  border: 1px solid var(--border-glass-highlight);
  border-bottom-right-radius: 4px;
  color: var(--msg-self-text);
  box-shadow: var(--shadow-sm);
}

/* Hover Quick Actions */
.msg-actions {
  position: absolute;
  top: -12px;
  right: 8px;
  display: none;
  background: var(--bg-glass-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-glass-highlight);
  border-radius: var(--radius-pill);
  padding: 0.15rem 0.35rem;
  box-shadow: var(--shadow-sm);
}

.msg.other .msg-actions {
  left: 8px;
  right: auto;
}

.msg:hover .msg-actions {
  display: flex;
  align-items: center;
}

.msg-action-btn {
  background: transparent;
  border: none;
  color: var(--icon-color);
  cursor: pointer;
  padding: 0.2rem;
  border-radius: var(--radius-pill);
  display: flex;
  align-items: center;
}

.msg-action-btn:hover {
  color: var(--text-main);
}

/* Image Messages */
.msg-image-wrapper {
  padding: 4px;
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  overflow: hidden;
  max-width: 320px;
}

.msg-image {
  width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
  display: block;
  cursor: zoom-in;
}

/* New Messages Indicator */
.new-msg-indicator {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  color: var(--text-main);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-pill);
  font-size: 0.8rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  z-index: 10;
  transition: all 0.2s ease;
}

.new-msg-indicator:hover {
  background: var(--bg-panel-hover);
  border-color: var(--border-focus);
}

.new-msg-indicator.d-none {
  display: none;
}

/* Typing Indicator */
.typing-indicator {
  padding: 0.4rem 1.5rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  min-height: 32px;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.typing-name {
  font-weight: 700;
  color: var(--text-main);
}

.typing-dots {
  display: inline-flex;
  gap: 3px;
}

.typing-dots span {
  width: 4px;
  height: 4px;
  background-color: var(--text-muted);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-4px); opacity: 1; }
}

/* ── COMPOSER (Restrained) ── */
.input-area {
  flex-shrink: 0;
  padding: 0.5rem 1.5rem 1.5rem 1.5rem;
  background: transparent;
}

.input-bar {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  padding: 0.55rem 0.75rem;
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
}

.input-bar:focus-within {
  border-color: var(--border-focus);
  box-shadow: var(--shadow-md);
}

.attach-btn {
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  color: var(--icon-color);
  cursor: pointer;
  padding: 0.45rem;
  border-radius: var(--radius-pill);
  display: flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  width: 40px;
  flex-shrink: 0;
  transition: all 0.2s ease;
}

.attach-btn:hover {
  color: var(--text-main);
  background: var(--bg-panel-hover);
  border-color: var(--border-glass-highlight);
}

textarea#message-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 15px;
  padding: 0.55rem 0.5rem;
  resize: none;
  outline: none;
  max-height: 120px;
  line-height: 1.45;
  height: 40px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

textarea#message-input::-webkit-scrollbar {
  display: none;
}

textarea#message-input::placeholder {
  color: var(--text-dark);
}

.send-btn {
  background: var(--accent-primary);
  color: #FFFFFF;
  border: 1px solid var(--border-light);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-pill);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.send-btn:hover {
  opacity: 0.92;
  transform: translateY(-1px);
}

/* ── POPUP PANELS (Emoji & GIF) ── */
.popup-panel {
  position: absolute;
  bottom: 115px;
  left: 20px;
  z-index: 50;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: popupSlideUp 0.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes popupSlideUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.popup-panel.d-none {
  display: none !important;
}

#emoji-picker-container {
  width: 320px;
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
}

.emoji-header {
  padding: 10px 12px;
  font-weight: 700;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border-light);
  background: rgba(0, 0, 0, 0.1);
  color: var(--text-main);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.emoji-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
}

.emoji-close:hover {
  color: var(--text-main);
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  padding: 10px;
  max-height: 250px;
  overflow-y: auto;
}

.emoji-item {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  padding: 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform 0.1s, background 0.1s;
  user-select: none;
}

.emoji-item:hover {
  background: var(--bg-panel-hover);
  transform: scale(1.15);
}


.input-footer {
  text-align: center;
  padding-top: 0.45rem;
  font-size: 0.72rem;
  color: var(--text-dark);
}

/* Image Lightbox Overlay */
.img-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  cursor: zoom-out;
}

.img-overlay img {
  max-width: 90%;
  max-height: 90%;
  border-radius: var(--radius-md);
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.5);
}

.img-overlay-controls {
  position: absolute;
  top: 20px;
  right: 30px;
  z-index: 1010;
}

.download-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  color: white;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
}

.download-btn:hover {
  background: rgba(255, 255, 255, 0.25);
  transform: scale(1.1);
}

/* ── VOICE NOTES & RECORDING ── */
#mic-btn.recording {
  color: var(--danger);
  animation: pulse 1.5s infinite;
}

#audio-ui-wrapper {
  flex: 1;
  display: flex;
}

.audio-ui-state {
  display: flex;
  align-items: center;
  flex: 1;
  gap: 12px;
  padding: 0 10px;
}

#recording-ui {
  color: var(--danger);
  font-size: 0.9rem;
  font-weight: 600;
}

#preview-ui {
  color: var(--text-main);
  font-size: 0.9rem;
}

#preview-time {
  margin-left: auto;
}

.preview-player {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  padding: 4px 12px;
  border-radius: 20px;
}

.preview-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-primary);
  border: none;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.preview-btn:hover { background: var(--accent-hover); }

.audio-visualizer {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 14px;
  margin: 0 4px;
  opacity: 0.3;
  transition: opacity 0.2s;
}

.audio-visualizer.playing {
  opacity: 1;
}

.audio-visualizer .bar {
  width: 3px;
  height: 4px;
  background: var(--accent-primary);
  border-radius: 2px;
  transition: height 0.1s ease;
}

.audio-visualizer.playing .bar {
  animation: eq-bounce 0.8s infinite alternate ease-in-out;
}

.audio-visualizer.playing .bar:nth-child(1) { animation-duration: 0.7s; }
.audio-visualizer.playing .bar:nth-child(2) { animation-delay: -0.2s; animation-duration: 0.9s; }
.audio-visualizer.playing .bar:nth-child(3) { animation-delay: -0.4s; animation-duration: 0.6s; }
.audio-visualizer.playing .bar:nth-child(4) { animation-delay: -0.6s; animation-duration: 0.8s; }

@keyframes eq-bounce {
  0% { height: 4px; }
  100% { height: 14px; }
}

#record-timer {
  flex: 1;
  font-variant-numeric: tabular-nums;
  text-align: right;
  margin-right: 5px;
}

.record-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.record-action-btn {
  border: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  color: white;
}

.record-action-btn.cancel {
  background: rgba(255, 60, 60, 0.2);
  color: var(--danger);
}
.record-action-btn.cancel:hover {
  background: var(--danger);
  color: white;
}

.record-action-btn.stop {
  background: rgba(255, 200, 0, 0.2);
  color: #ffaa00;
}
.record-action-btn.stop:hover {
  background: #ffaa00;
  color: white;
}

.record-action-btn.send {
  background: var(--accent-primary);
  color: white;
}
.record-action-btn.send:hover {
  background: var(--accent-hover);
  transform: scale(1.05);
}

.record-dot {
  width: 10px;
  height: 10px;
  background-color: var(--danger);
  border-radius: 50%;
  animation: pulse 1.5s infinite;
}

/* ── CUSTOM AUDIO PLAYER ── */
.custom-audio-player {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 280px;
  background: rgba(255, 255, 255, 0.05);
  padding: 8px 12px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.play-pause-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-primary);
  border: none;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s;
}

.play-pause-btn:hover {
  background: var(--accent-hover);
}

.audio-track {
  flex: 1;
  height: 6px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.audio-progress {
  height: 100%;
  background: var(--accent-primary);
  width: 0%;
  pointer-events: none;
}

.audio-time {
  font-size: 0.75rem;
  color: rgba(255,255,255,0.7);
  font-variant-numeric: tabular-nums;
  min-width: 65px;
  text-align: right;
}

/* ── GHOST LOADING BUBBLE ── */
.msg.ghost {
  opacity: 1;
  align-self: flex-end;
}
.msg.ghost .msg-bubble-wrapper {
  justify-content: flex-end;
}
.msg.ghost .msg-bubble {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 500;
  font-size: 0.82rem;
  line-height: 1.2;
  color: var(--text-muted);
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-radius: 20px !important;
  padding: 6px 14px;
  box-shadow: var(--shadow-sm);
  width: fit-content;
  white-space: nowrap;
}
.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--border-light);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── RESPONSIVE SPATIAL DESKTOP BREAKPOINTS ── */
@media (min-width: 1025px) {
  #chat-screen {
    padding: 20px 24px;
    gap: 20px;
  }
  .sidebar {
    transform: none !important;
    position: relative !important;
  }
  .menu-toggle {
    display: none;
  }
}

@media (max-width: 1024px) and (min-width: 768px) {
  #chat-screen {
    padding: 12px;
    gap: 0;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100dvh;
    border-radius: 0;
    transform: translateX(-100%);
    z-index: 100;
  }

  .sidebar.open {
    transform: translateX(0);
  }
}

@media (max-width: 767px) {
  #chat-screen {
    padding: 0;
    gap: 0;
  }

  .chat-main {
    border-radius: 0;
    border: none;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 285px;
    height: 100dvh;
    border-radius: 0;
    transform: translateX(-100%);
    z-index: 100;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .join-card {
    padding: 1.75rem 1.25rem;
    border-radius: var(--radius-md);
  }

  .messages-area {
    padding: 1rem 0.85rem 80px 0.85rem;
  }

  .msg {
    max-width: 88%;
  }

  .input-area {
    padding: 0 10px 10px 10px;
  }

  .input-footer {
    display: none;
  }
}