/* ============================================================
   VARIABLES — CSS custom properties
   ============================================================ */
:root {
  --primary: #7C5CFC;
  --primary-dark: #6A4CE4;
  --primary-hover: #6A4CE4;
  --primary-light: #EDE8FF;
  --primary-subtle: rgba(124, 92, 252, 0.12);
  --bg: #FAFAFA;
  --bg-secondary: #F7F7F8;
  --bg-dark: #EDEDF0;
  --text: #1A1A2E;
  --text-secondary: #6E6E80;
  --text-muted: #A0A0B0;
  --text-light: #FFFFFF;
  --border: #E5E5EA;
  --divider: #F0F0F2;
  --online: #34C759;
  --danger: #FF3B30;
  --warning: #FF9F0A;
  --success: #30D158;
  --bubble-out: #7C5CFC;
  --bubble-in: #F0EFF5;
  --bubble-out-text: #FFFFFF;
  --bubble-in-text: #1A1A2E;
  --shadow-xs: 0 1px 2px rgba(124, 92, 252, 0.04);
  --shadow-sm: 0 1px 3px rgba(124, 92, 252, 0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px rgba(124, 92, 252, 0.06), 0 2px 4px rgba(0,0,0,0.03);
  --shadow-lg: 0 10px 25px rgba(124, 92, 252, 0.08), 0 4px 10px rgba(0,0,0,0.04);
  --shadow-xl: 0 20px 50px rgba(124, 92, 252, 0.12), 0 8px 20px rgba(0,0,0,0.06);
  --shadow-float: 0 8px 30px rgba(0,0,0,0.12), 0 2px 8px rgba(124, 92, 252, 0.06);
  --shadow: var(--shadow-sm);
  --radius: 14px;
  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  --radius-full: 9999px;
  --chat-bg: #F0F0F5;
  --msg-font-size: 14.5px;
  --sidebar-bg: #FFFFFF;
  --input-bg: #F2F2F7;
  --modal-bg: #FFFFFF;
  --font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  /* Glass materials — Apple-inspired */
  --glass-bg: rgba(255, 255, 255, 0.72);
  --glass-bg-thick: rgba(255, 255, 255, 0.85);
  --glass-bg-thin: rgba(255, 255, 255, 0.55);
  --glass-border: rgba(255, 255, 255, 0.35);
  --glass-blur: blur(12px) saturate(120%);
  --glass-blur-heavy: blur(16px) saturate(140%);
  --glass-blur-light: blur(8px) saturate(120%);
}

/* ============================================================
   DARK MODE variables
   ============================================================ */
body.dark {
  --bg: #0F0F14;
  --bg-secondary: #1A1A24;
  --bg-dark: #24243A;
  --text: #E8E8F0;
  --text-secondary: #8888A0;
  --text-muted: #555568;
  --text-light: #FFFFFF;
  --border: #2A2A3C;
  --divider: #1F1F30;
  --bubble-out: #7C5CFC;
  --bubble-in: #1E1E30;
  --bubble-out-text: #FFFFFF;
  --bubble-in-text: #E8E8F0;
  --shadow-xs: 0 0 0 1px rgba(255,255,255,0.04);
  --shadow-sm: 0 0 0 1px rgba(255,255,255,0.06), 0 2px 8px rgba(0,0,0,0.3);
  --shadow-md: 0 0 0 1px rgba(255,255,255,0.06), 0 4px 16px rgba(0,0,0,0.4);
  --shadow-lg: 0 0 0 1px rgba(255,255,255,0.08), 0 8px 30px rgba(0,0,0,0.5);
  --shadow-float: 0 0 0 1px rgba(124, 92, 252, 0.15), 0 8px 30px rgba(0,0,0,0.5);
  --shadow: var(--shadow-sm);
  --chat-bg: #12121C;
  --sidebar-bg: #141420;
  --input-bg: #1E1E2E;
  --modal-bg: #1A1A24;
  --online: #30D158;
  --danger: #FF453A;

  /* Glass materials — dark mode overrides */
  --glass-bg: rgba(20, 20, 32, 0.72);
  --glass-bg-thick: rgba(20, 20, 32, 0.85);
  --glass-bg-thin: rgba(20, 20, 32, 0.55);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-blur: blur(12px) saturate(120%);
  --glass-blur-heavy: blur(16px) saturate(140%);
  --glass-blur-light: blur(8px) saturate(120%);
}

/* ============================================================
   REDUCED MOTION — disable all blur/backdrop effects
   Respects OS-level "Reduce Motion" setting. Users with
   vestibular disorders can be affected by heavy GPU effects.
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  :root {
    --glass-blur: none;
    --glass-blur-heavy: none;
    --glass-blur-light: none;
  }
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-family);
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button {
  cursor: pointer;
  font-family: var(--font-family);
}

input, textarea {
  font-family: var(--font-family);
  font-size: inherit;
}

/* ============================================================
   SCROLLBARS
   ============================================================ */
::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}

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

::-webkit-scrollbar-thumb {
  background: var(--primary-subtle);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(124, 92, 252, 0.25);
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--primary-subtle) transparent;
}

/* ============================================================
   ANIMATIONS & TRANSITIONS
   ============================================================ */
@keyframes messageIn {
  from { opacity: 0; transform: translateY(8px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes messageSent {
  0% { opacity: 0; transform: translateY(20px) scale(0.95); }
  60% { transform: translateY(-2px) scale(1.01); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(30px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes slideInLeft {
  from { opacity: 0; transform: translateX(-30px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes badgePulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

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

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

@keyframes typingFade {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

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

@keyframes panelSlideIn {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

@keyframes overlayFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes modalCardIn {
  from { opacity: 0; transform: scale(0.94) translateY(12px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes ctxFadeIn {
  from { opacity: 0; transform: scale(0.95); }
  to   { opacity: 1; transform: scale(1); }
}

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

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

/* ============================================================
   AUTH SCREEN
   ============================================================ */
#auth-screen {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #1a0533 0%, #0F0F14 30%, #1A1A2E 60%, #2a1a4e 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  padding: 16px;
}

.auth-card {
  background: var(--glass-bg-thick);
  backdrop-filter: var(--glass-blur-heavy);
  -webkit-backdrop-filter: var(--glass-blur-heavy);
  border: 1px solid var(--glass-border);
  border-radius: 28px;
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
  text-align: center;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.2), 0 0 0 1px rgba(255,255,255,0.1);
  animation: authCardIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.auth-logo {
  font-size: 56px;
  line-height: 1;
  margin-bottom: 16px;
}

.auth-card h1 {
  font-size: 1.9rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
  letter-spacing: -0.3px;
}

.auth-subtitle {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin-bottom: 28px;
}

.auth-tabs {
  display: flex;
  background: var(--bg-secondary);
  border-radius: var(--radius-full);
  padding: 4px;
  margin-bottom: 24px;
  gap: 4px;
}

.auth-tab {
  flex: 1;
  padding: 10px 16px;
  border: none;
  background: none;
  color: var(--text-secondary);
  border-radius: var(--radius-full);
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.2s cubic-bezier(0.22, 1, 0.36, 1);
}

.auth-tab.active {
  background: var(--primary);
  color: var(--text-light);
  box-shadow: 0 2px 8px rgba(124, 92, 252, 0.35);
}

.auth-tab:not(.active):hover {
  color: var(--text);
  background: var(--bg-dark);
}

#auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#auth-form input {
  width: 100%;
  padding: 13px 18px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#auth-form input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-subtle);
}

#auth-form input::placeholder {
  color: var(--text-secondary);
}

#auth-submit {
  width: 100%;
  padding: 13px;
  background: var(--primary);
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-light);
  font-size: 0.95rem;
  font-weight: 600;
  transition: all 0.15s cubic-bezier(0.22, 1, 0.36, 1);
  margin-top: 4px;
}

#auth-submit:hover {
  background: var(--primary-dark);
  box-shadow: 0 4px 15px rgba(124, 92, 252, 0.35);
  transform: translateY(-1px);
}

#auth-submit:active {
  transform: translateY(0) scale(0.97);
  box-shadow: none;
}

#auth-error {
  color: var(--danger);
  font-size: 0.85rem;
  min-height: 20px;
  text-align: center;
}

/* ============================================================
   APP LAYOUT
   ============================================================ */
#app-screen {
  display: flex;
  height: 100vh;
  height: 100dvh;
  position: relative;
  overflow: hidden;
}

/* ============================================================
   ICON BAR
   ============================================================ */
.icon-bar {
  width: 60px;
  background: rgba(20, 20, 40, 0.88);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 0;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
  z-index: 20;
  justify-content: space-between;
}

.icon-bar-top {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 100%;
  padding: 0 8px;
}

.icon-bar-bottom {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 100%;
  padding: 0 8px 8px;
}

.icon-bar-btn-wrap {
  position: relative;
  width: 100%;
}

.icon-bar-btn {
  width: 100%;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: rgba(255,255,255,0.55);
  font-size: 20px;
  transition: all 0.2s cubic-bezier(0.22, 1, 0.36, 1);
  border: none;
  background: none;
}

.icon-bar-btn:hover {
  background: rgba(124, 92, 252, 0.2);
  color: #fff;
}

.icon-bar-btn.active {
  background: rgba(124, 92, 252, 0.3);
  color: #A78BFA;
}

.icon-bar-btn svg {
  pointer-events: none;
}

/* ============================================================
   HAMBURGER DROPDOWN MENU
   ============================================================ */
.hamburger-menu {
  position: absolute;
  left: 60px;
  top: 0;
  width: 280px;
  background: var(--glass-bg-thick);
  backdrop-filter: var(--glass-blur-heavy);
  -webkit-backdrop-filter: var(--glass-blur-heavy);
  border: 1px solid var(--glass-border);
  border-radius: 0 0 20px 0;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
  z-index: 500;
  overflow: hidden;
  animation: floatIn 0.2s cubic-bezier(0.22, 1, 0.36, 1);
}

.hamburger-profile {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 16px 16px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.hamburger-profile:hover {
  background: rgba(124, 92, 252, 0.1);
}

.hamburger-avatar {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--primary);
  overflow: hidden;
  flex-shrink: 0;
  border: 2px solid rgba(124, 92, 252, 0.3);
}

.hamburger-user-info {
  flex: 1;
  min-width: 0;
}

.hamburger-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: #F0F0F0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hamburger-username {
  font-size: 0.8rem;
  color: rgba(255,255,255,0.45);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hamburger-divider {
  height: 1px;
  background: rgba(255,255,255,0.08);
  margin: 4px 0;
}

.hamburger-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 16px;
  background: none;
  border: none;
  color: #E0E0E0;
  font-size: 0.9rem;
  font-family: var(--font-family);
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease;
}

.hamburger-item:hover {
  background: rgba(124, 92, 252, 0.12);
}

.hamburger-item.danger {
  color: #FF6B6B;
}

.hamburger-item-toggle {
  cursor: default;
}

.hamburger-item-icon {
  font-size: 1.1rem;
  width: 24px;
  text-align: center;
  flex-shrink: 0;
}

.hamburger-item span:not(.hamburger-item-icon) {
  flex: 1;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
#sidebar {
  width: 320px;
  min-width: 280px;
  background: var(--glass-bg-thick);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-right: 1px solid var(--glass-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
  transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
  z-index: 10;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--glass-bg-thin);
  backdrop-filter: var(--glass-blur-light);
  -webkit-backdrop-filter: var(--glass-blur-light);
  border-bottom: 1px solid var(--glass-border);
  min-height: 60px;
}

.sidebar-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.2px;
}

.sidebar-header button {
  background: none;
  border: none;
  color: var(--text-secondary);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s cubic-bezier(0.22, 1, 0.36, 1), color 0.2s ease;
  flex-shrink: 0;
}

.sidebar-header button:hover {
  background: var(--primary-subtle);
  color: var(--primary);
}

.sidebar-tabs {
  display: flex;
  background: var(--glass-bg-thin);
  backdrop-filter: var(--glass-blur-light);
  -webkit-backdrop-filter: var(--glass-blur-light);
  border-bottom: 1px solid var(--glass-border);
  flex-shrink: 0;
}

.sidebar-tab {
  flex: 1;
  padding: 13px 8px;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  border-bottom: 2.5px solid transparent;
  transition: color 0.2s cubic-bezier(0.22, 1, 0.36, 1), border-color 0.2s ease;
  position: relative;
  top: 1px;
}

.sidebar-tab:hover {
  color: var(--text);
}

.sidebar-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

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

.tab-panel {
  display: flex;
  flex-direction: column;
  flex: 1;
}

/* ============================================================
   CHAT LIST ITEMS
   ============================================================ */
#chat-list {
  flex: 1;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.22, 1, 0.36, 1);
  position: relative;
  min-height: 72px;
  border-left: 3px solid transparent;
}

.chat-item:hover {
  background: var(--primary-subtle);
  transform: translateX(2px);
}

.chat-item:active {
  transform: scale(0.98);
}

.chat-item.active {
  background: var(--primary-subtle);
  border-left-color: var(--primary);
}

.chat-item-avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.chat-item .avatar-medium {
  flex-shrink: 0;
}

.chat-item-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.chat-item-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.chat-item-name {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.chat-item-time {
  font-size: 0.75rem;
  color: var(--text-secondary);
  flex-shrink: 0;
  white-space: nowrap;
}

.chat-item-preview-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.chat-item-preview {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.chat-item-badge {
  background: var(--primary);
  color: var(--text-light);
  font-size: 0.7rem;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  flex-shrink: 0;
  animation: badgePulse 2s ease-in-out infinite;
}

/* ============================================================
   CONTACTS TAB
   ============================================================ */
.add-contact-bar {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.add-contact-bar input {
  flex: 1;
  padding: 9px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.add-contact-bar input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-subtle);
}

.add-contact-bar input::placeholder {
  color: var(--text-secondary);
}

.add-contact-bar button {
  padding: 9px 16px;
  background: var(--primary);
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-light);
  font-size: 0.875rem;
  font-weight: 600;
  transition: all 0.15s cubic-bezier(0.22, 1, 0.36, 1);
  white-space: nowrap;
}

.add-contact-bar button:hover {
  background: var(--primary-dark);
  box-shadow: 0 4px 15px rgba(124, 92, 252, 0.35);
  transform: translateY(-1px);
}

.add-contact-bar button:active {
  transform: translateY(0) scale(0.97);
}

.section-label {
  padding: 10px 16px 6px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--glass-bg-thin);
  backdrop-filter: var(--glass-blur-light);
  -webkit-backdrop-filter: var(--glass-blur-light);
  border-bottom: 1px solid var(--glass-border);
}

#requests-list,
#contacts-list {
  flex: 1;
}

.contact-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  transition: background 0.15s cubic-bezier(0.22, 1, 0.36, 1);
  position: relative;
}

.contact-item:hover {
  background: var(--primary-subtle);
}

.contact-item-body {
  flex: 1;
  min-width: 0;
}

.contact-item-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-item-username {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.contact-item-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.btn-accept {
  padding: 6px 12px;
  background: var(--primary);
  border: none;
  border-radius: var(--radius-xs);
  color: var(--text-light);
  font-size: 0.8rem;
  font-weight: 600;
  transition: all 0.15s cubic-bezier(0.22, 1, 0.36, 1);
}

.btn-accept:hover {
  background: var(--primary-dark);
  box-shadow: 0 4px 12px rgba(124, 92, 252, 0.3);
  transform: translateY(-1px);
}

.btn-reject {
  padding: 6px 12px;
  background: var(--bg-secondary);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 600;
  transition: background 0.2s ease, color 0.2s ease;
}

.btn-reject:hover {
  background: rgba(255, 59, 48, 0.08);
  color: var(--danger);
  border-color: rgba(255, 59, 48, 0.3);
}

/* ============================================================
   SETTINGS / PROFILE TAB (sidebar section)
   ============================================================ */
.profile-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 24px 24px;
  text-align: center;
  border-bottom: 1px solid var(--border);
}

.profile-hero h2 {
  margin-top: 14px;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

.profile-hero p {
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin-top: 4px;
}

.settings-group {
  margin: 16px 12px 0;
  background: var(--glass-bg-thin);
  backdrop-filter: var(--glass-blur-light);
  -webkit-backdrop-filter: var(--glass-blur-light);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.settings-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px 16px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 0.9375rem;
  text-align: left;
  transition: all 0.15s cubic-bezier(0.22, 1, 0.36, 1);
  border-radius: var(--radius-sm);
}

.settings-row:hover {
  background: var(--primary-subtle);
}

.settings-icon {
  font-size: 1.1rem;
  width: 24px;
  text-align: center;
  flex-shrink: 0;
}

.settings-row span:not(.settings-icon):not(.settings-chevron) {
  flex: 1;
}

.settings-chevron {
  font-size: 1.25rem;
  color: var(--text-secondary);
  margin-left: auto;
}

.settings-row.danger {
  color: var(--danger);
}

/* ============================================================
   SETTINGS PANEL (full design)
   ============================================================ */
.settings-panel-page {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow-y: auto;
}

.settings-profile-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 28px 20px 20px;
  text-align: center;
  background: var(--glass-bg-thin);
  backdrop-filter: var(--glass-blur-light);
  -webkit-backdrop-filter: var(--glass-blur-light);
  border-bottom: 1px solid var(--glass-border);
}

.settings-avatar-wrap {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s ease;
  border: 2px solid var(--primary-subtle);
}

.settings-avatar-wrap:hover {
  opacity: 0.85;
}

.settings-profile-hero h2 {
  margin-top: 12px;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
}

.settings-profile-hero p {
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin-top: 3px;
}

.settings-edit-profile-btn {
  margin-top: 12px;
  padding: 7px 18px;
  background: var(--primary-subtle);
  border: 1.5px solid rgba(124, 92, 252, 0.3);
  border-radius: var(--radius-full);
  color: var(--primary);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.22, 1, 0.36, 1);
  font-family: var(--font-family);
}

.settings-edit-profile-btn:hover {
  background: rgba(124, 92, 252, 0.2);
  box-shadow: 0 4px 12px rgba(124, 92, 252, 0.2);
}

.settings-section-label {
  padding: 14px 16px 6px;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.settings-value {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-left: auto;
  margin-right: 6px;
}

.settings-version {
  padding: 20px 16px;
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-secondary);
  opacity: 0.6;
}

/* Sub-panel header */
.settings-subpanel-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur-light);
  -webkit-backdrop-filter: var(--glass-blur-light);
  border-bottom: 1px solid var(--glass-border);
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  flex-shrink: 0;
  min-height: 52px;
  animation: slideInRight 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}

.settings-back-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 1.2rem;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-xs);
  transition: background 0.2s ease;
  flex-shrink: 0;
  font-family: var(--font-family);
}

.settings-back-btn:hover {
  background: var(--primary-subtle);
}

/* Toggle rows in settings */
.settings-row-toggle {
  cursor: default;
}

.settings-row-toggle span:not(.settings-icon):not(.settings-chevron) {
  flex: 1;
}

/* Font size buttons */
.settings-row-font {
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
}

.settings-row-inner {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.settings-row-inner-col {
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
}

.font-size-btns {
  display: flex;
  gap: 8px;
}

.font-size-btn {
  padding: 7px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-xs);
  background: var(--bg-secondary);
  color: var(--text);
  cursor: pointer;
  font-family: var(--font-family);
  font-size: 0.9rem;
  transition: all 0.15s cubic-bezier(0.22, 1, 0.36, 1);
  display: flex;
  align-items: center;
  gap: 4px;
}

.font-size-btn small {
  font-size: 0.65rem;
  color: var(--text-secondary);
}

.font-size-btn.active,
.font-size-btn:hover {
  border-color: var(--primary);
  background: var(--primary-subtle);
  color: var(--primary);
}

/* Theme buttons */
.theme-btns {
  display: flex;
  gap: 8px;
}

.theme-btn {
  padding: 7px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-xs);
  background: var(--bg-secondary);
  color: var(--text);
  cursor: pointer;
  font-family: var(--font-family);
  font-size: 0.85rem;
  transition: all 0.15s cubic-bezier(0.22, 1, 0.36, 1);
}

.theme-btn.active,
.theme-btn:hover {
  border-color: var(--primary);
  background: var(--primary-subtle);
  color: var(--primary);
}

/* Chat background swatches */
.chat-bg-swatches {
  display: flex;
  gap: 10px;
  align-items: center;
}

.chat-bg-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-xs);
  border: 2.5px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease;
  flex-shrink: 0;
}

.chat-bg-btn.active,
.chat-bg-btn:hover {
  border-color: var(--primary);
  transform: scale(1.08);
}

/* Settings hint text */
.settings-hint {
  padding: 10px 16px 16px;
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* Toggle switch */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 24px;
  flex-shrink: 0;
  cursor: pointer;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.15);
  border-radius: var(--radius-full);
  transition: background 0.25s ease;
  cursor: pointer;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--primary);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(18px);
}

/* Toggle in light settings panels */
.settings-panel-page .toggle-slider {
  background: #D1D1D6;
}

.settings-panel-page .toggle-switch input:checked + .toggle-slider {
  background: var(--primary);
}

/* ============================================================
   CHAT AREA
   ============================================================ */
#chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--chat-bg);
  position: relative;
}

#empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-secondary);
  text-align: center;
  padding: 24px;
  background: var(--chat-bg);
}

.empty-icon {
  font-size: 72px;
  opacity: 0.35;
  line-height: 1;
  margin-bottom: 4px;
}

#empty-state h3 {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text-secondary);
}

#empty-state p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  opacity: 0.7;
}

#chat-content {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* ============================================================
   CHAT HEADER
   ============================================================ */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--glass-border);
  box-shadow: 0 1px 8px rgba(0, 0, 0, 0.04);
  min-height: 60px;
  z-index: 5;
  flex-shrink: 0;
}

.back-btn {
  display: none;
  background: none;
  border: none;
  color: var(--primary);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  align-items: center;
  justify-content: center;
  transition: background 0.2s cubic-bezier(0.22, 1, 0.36, 1);
  flex-shrink: 0;
}

.back-btn:hover {
  background: var(--primary-subtle);
}

.chat-header-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.chat-header-info h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#chat-status {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

#typing-status {
  font-size: 0.8rem;
  color: var(--primary);
  font-style: italic;
}

#typing-status:not(:empty) {
  animation: typingFade 1.4s ease-in-out infinite;
}

.chat-header-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.chat-header-actions button {
  background: none;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  font-size: 1.1rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s cubic-bezier(0.22, 1, 0.36, 1), color 0.2s ease;
}

.chat-header-actions button:hover {
  background: var(--primary-subtle);
  color: var(--primary);
}

/* ============================================================
   MESSAGES AREA
   ============================================================ */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  background: var(--chat-bg);
}

/* ============================================================
   MESSAGE ROWS
   ============================================================ */
.message {
  display: flex;
  margin-bottom: 3px;
  padding: 0 10px;
}
.message.new-msg {
  animation: messageIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.message.own {
  justify-content: flex-end;
}

.message.other {
  justify-content: flex-start;
}

/* ============================================================
   AVATARS IN MESSAGES
   ============================================================ */
.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--text-light);
  font-size: 0.8rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  align-self: flex-end;
  margin: 0 6px;
  overflow: hidden;
  border: 2px solid var(--primary-subtle);
  transition: transform 0.15s ease;
}

.message-avatar:hover {
  transform: scale(1.05);
}

.message-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.message-avatar.hidden {
  visibility: hidden;
}

/* ============================================================
   MESSAGE BUBBLES
   ============================================================ */
.message-bubble {
  max-width: min(520px, 80vw);
  min-width: 80px;
  padding: 10px 14px 6px;
  border-radius: 22px;
  position: relative;
  word-break: break-word;
  transition: transform 0.2s cubic-bezier(0.22, 1, 0.36, 1),
              box-shadow 0.2s ease;
  line-height: 1.45;
  overflow: hidden;
}

/* ---- Outgoing (own) ---- */
.message.own .message-bubble {
  background: linear-gradient(135deg, #7C3AED, #2563EB);
  color: #FFFFFF;
  border-radius: 22px 22px 6px 22px;
  box-shadow: 0 2px 12px rgba(37, 99, 235, 0.22),
              inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.message.own .message-bubble:hover {
  transform: scale(1.01);
  box-shadow: 0 4px 18px rgba(37, 99, 235, 0.32),
              inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

/* ---- Incoming (other) ---- */
.message.other .message-bubble {
  background: var(--glass-bg-thick);
  backdrop-filter: var(--glass-blur-light);
  -webkit-backdrop-filter: var(--glass-blur-light);
  border: 1px solid var(--glass-border);
  color: var(--text);
  border-radius: 22px 22px 22px 6px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.message.other .message-bubble:hover {
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1);
}

/* ============================================================
   SENDER NAME
   ============================================================ */
.message-sender {
  font-size: 0.78rem;
  font-weight: 600;
  color: #2563EB;
  margin-bottom: 2px;
  display: block;
  letter-spacing: -0.01em;
}

.message.own .message-sender {
  color: rgba(255, 255, 255, 0.85);
}

/* ============================================================
   MESSAGE TEXT
   ============================================================ */
.message-text {
  font-size: var(--msg-font-size);
  line-height: 1.5;
  white-space: pre-wrap;
}

/* ============================================================
   MESSAGE META (time + ticks + edited)
   ============================================================ */
.message-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  margin-top: 4px;
  padding-top: 2px;
}

.message-time {
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.02em;
}

/* Default time color for incoming */
.message.other .message-time {
  color: var(--text-muted);
}

/* White time for outgoing */
.message.own .message-time {
  color: rgba(255, 255, 255, 0.65);
}

.message-tick {
  display: inline-flex;
  align-items: center;
  width: 16px;
  height: 16px;
  margin-left: 1px;
  flex-shrink: 0;
}

.message-tick svg {
  width: 100%;
  height: 100%;
}

.message-edited {
  font-size: 0.68rem;
  font-style: italic;
  margin-left: 2px;
}

.message.other .message-edited {
  color: var(--text-muted);
}

.message.own .message-edited {
  color: rgba(255, 255, 255, 0.5);
}

/* ============================================================
   AUDIO IN BUBBLES
   ============================================================ */
/* ============================================================
   VOICE PLAYER — Telegram-style audio bubbles
   ============================================================ */
.voice-player {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 240px;
  max-width: 320px;
  padding: 2px 0;
  user-select: none;
}

.vp-play {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.08);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.vp-play:hover { background: rgba(0,0,0,0.12); }
.vp-play:active { transform: scale(0.92); }
.vp-play svg { width: 18px; height: 18px; }
.vp-icon-play { margin-left: 2px; }

.message.own .vp-play {
  background: rgba(255,255,255,0.2);
  color: #fff;
}
.message.own .vp-play:hover { background: rgba(255,255,255,0.3); }

.vp-wave {
  flex: 1;
  position: relative;
  height: 32px;
  cursor: pointer;
  border-radius: 4px;
  overflow: hidden;
}

.vp-canvas {
  width: 100%;
  height: 32px;
  display: block;
}

.vp-progress {
  display: none;
}

.vp-time {
  flex-shrink: 0;
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
  min-width: 36px;
  text-align: right;
}
.message.own .vp-time { color: rgba(255,255,255,0.75); }

/* ============================================================
   VIDEO IN BUBBLES
   ============================================================ */
.message-video {
  margin-bottom: 4px;
  position: relative;
}

.message-video video {
  max-width: 300px;
  width: 100%;
  border-radius: 12px;
  display: block;
}

.mv-expand-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.5);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 2;
}

.message-video:hover .mv-expand-btn {
  opacity: 1;
}

.mv-expand-btn:hover {
  background: rgba(0,0,0,0.7);
}

/* ============================================================
   FILE ATTACHMENT IN BUBBLES
   ============================================================ */
.message-file-attach {
  margin-bottom: 4px;
}

.message-file-attach a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 12px;
  text-decoration: none;
  font-size: 0.875rem;
  word-break: break-all;
  transition: background 0.15s ease;
}

.message.other .message-file-attach a {
  background: rgba(0, 0, 0, 0.06);
  color: var(--primary);
}

.message.other .message-file-attach a:hover {
  background: rgba(0, 0, 0, 0.1);
}

.message.own .message-file-attach a {
  background: rgba(255, 255, 255, 0.18);
  color: #FFFFFF;
}

.message.own .message-file-attach a:hover {
  background: rgba(255, 255, 255, 0.28);
}

/* ============================================================
   IMAGE IN BUBBLES
   ============================================================ */
.message-image {
  margin-bottom: 4px;
}

.message-image img {
  max-width: 300px;
  max-height: 300px;
  border-radius: 12px;
  cursor: pointer;
  display: block;
  object-fit: cover;
  transition: opacity 0.15s ease;
}

.message-image img:hover {
  opacity: 0.92;
}

/* ============================================================
   GROUP SPACING
   ============================================================ */
.message + .message.own,
.message + .message.other {
  margin-top: 0;
}

.message.group-start {
  margin-top: 14px;
}

/* ============================================================
   REPLY INSIDE BUBBLE
   ============================================================ */
.message-reply {
  background: rgba(37, 99, 235, 0.07);
  border-left: 3px solid #2563EB;
  border-radius: 6px;
  padding: 6px 10px;
  margin-bottom: 6px;
  cursor: pointer;
  overflow: hidden;
  transition: background 0.15s ease;
}

.message-reply:hover {
  background: rgba(37, 99, 235, 0.12);
}

.message.own .message-reply {
  background: rgba(255, 255, 255, 0.12);
  border-left-color: rgba(255, 255, 255, 0.5);
}

.message.own .message-reply:hover {
  background: rgba(255, 255, 255, 0.18);
}

.message-reply-author {
  font-size: 0.75rem;
  font-weight: 600;
  color: #2563EB;
  margin-bottom: 2px;
}

.message.own .message-reply-author {
  color: rgba(255, 255, 255, 0.9);
}

.message-reply-text {
  font-size: 0.8rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.message.own .message-reply-text {
  color: rgba(255, 255, 255, 0.65);
}

/* ============================================================
   DATE SEPARATORS
   ============================================================ */
.date-separator {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 12px 0;
}

.date-separator span {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur-light);
  -webkit-backdrop-filter: var(--glass-blur-light);
  border: 1px solid var(--glass-border);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 5px 14px;
  border-radius: 999px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}

/* ============================================================
   SEARCH BAR
   ============================================================ */
.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--glass-bg-thin);
  backdrop-filter: var(--glass-blur-light);
  -webkit-backdrop-filter: var(--glass-blur-light);
  border-bottom: 1px solid var(--glass-border);
  flex-shrink: 0;
}

#search-input {
  flex: 1;
  padding: 9px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  color: var(--text);
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-subtle);
  background: var(--bg);
}

#search-input::placeholder {
  color: var(--text-secondary);
}

#search-close-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1rem;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
}

#search-close-btn:hover {
  background: var(--primary-subtle);
  color: var(--primary);
}

/* ============================================================
   REPLY BAR
   ============================================================ */
#reply-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur-light);
  -webkit-backdrop-filter: var(--glass-blur-light);
  border-top: 1px solid var(--glass-border);
  flex-shrink: 0;
  animation: slideUp 0.15s ease-out;
}

.reply-bar-content {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.reply-bar-line {
  width: 3px;
  height: 36px;
  background: var(--primary);
  border-radius: 2px;
  flex-shrink: 0;
}

.reply-bar-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.reply-name {
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--primary);
}

.reply-text {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reply-bar-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1rem;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, color 0.2s ease;
  flex-shrink: 0;
}

.reply-bar-close:hover {
  background: var(--primary-subtle);
  color: var(--primary);
}

/* ============================================================
   FILE PREVIEW BAR
   ============================================================ */
#file-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur-light);
  -webkit-backdrop-filter: var(--glass-blur-light);
  border-top: 1px solid var(--glass-border);
  flex-shrink: 0;
  animation: slideUp 0.15s ease-out;
}

.file-preview-content {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

#file-preview-img {
  height: 52px;
  width: 52px;
  border-radius: var(--radius-xs);
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid var(--border);
}

#file-preview-name {
  font-size: 0.85rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-preview-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1rem;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, color 0.2s ease;
  flex-shrink: 0;
}

.file-preview-close:hover {
  background: var(--primary-subtle);
  color: var(--primary);
}

/* ============================================================
   INPUT BAR
   ============================================================ */
.input-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  padding-bottom: calc(48px + env(safe-area-inset-bottom, 0px));
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-top: 1px solid var(--glass-border);
  flex-shrink: 0;
}

#attach-btn {
  background: none;
  border: none;
  font-size: 1.25rem;
  color: var(--text-secondary);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s cubic-bezier(0.22, 1, 0.36, 1), color 0.2s ease;
  align-self: flex-end;
  margin-bottom: 0;
}

#attach-btn:hover {
  background: var(--primary-subtle);
  color: var(--primary);
}

#message-input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--input-bg);
  color: var(--text);
  font-size: 0.9375rem;
  line-height: 1.45;
  outline: none;
  resize: none;
  max-height: 120px;
  overflow-y: auto;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#message-input:focus {
  border-color: var(--primary);
  background: var(--bg);
  box-shadow: 0 0 0 3px var(--primary-subtle);
}

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

#voice-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
  transition: all 0.15s ease;
  align-self: flex-end;
}
#voice-btn:hover { color: var(--primary); background: var(--primary-subtle); }
#voice-btn.recording {
  color: #FF3B30;
  background: rgba(255,59,48,0.1);
  animation: voicePulse 1.2s ease-in-out infinite;
}
@keyframes voicePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,59,48,0.3); }
  50% { box-shadow: 0 0 0 10px rgba(255,59,48,0); }
}

.voice-recording-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  padding: 0 12px;
}
.voice-recording-bar .vr-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #FF3B30;
  animation: voicePulse 1.2s ease-in-out infinite;
}
.voice-recording-bar .vr-timer {
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  min-width: 40px;
}
.voice-recording-bar .vr-cancel {
  margin-left: auto;
  color: var(--text-secondary);
  font-size: 0.85rem;
  cursor: pointer;
}
.voice-recording-bar .vr-cancel:hover { color: var(--danger); }

#send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary);
  border: none;
  color: var(--text-light);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s cubic-bezier(0.22, 1, 0.36, 1);
  align-self: flex-end;
}

#send-btn:hover {
  background: var(--primary-dark);
  box-shadow: 0 4px 15px rgba(124, 92, 252, 0.35);
  transform: translateY(-1px);
}

#send-btn:active {
  transform: translateY(0) scale(0.93);
  box-shadow: none;
}
#send-btn.editing {
  background: #22c55e;
}
#send-btn.editing:hover {
  background: #16a34a;
  box-shadow: 0 4px 15px rgba(34, 197, 94, 0.35);
}

#edit-bar {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
}

/* ============================================================
   PROFILE PANEL
   ============================================================ */
#profile-panel {
  width: 360px;
  min-width: 300px;
  background: var(--glass-bg-thick);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-left: 1px solid var(--glass-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  animation: slideInRight 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

.profile-panel-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: var(--glass-bg-thin);
  border-bottom: 1px solid var(--glass-border);
  min-height: 60px;
  flex-shrink: 0;
}

.profile-panel-header h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

#close-profile-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1rem;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
}

#close-profile-btn:hover {
  background: var(--primary-subtle);
  color: var(--primary);
}

.profile-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
}

.profile-panel-body h2 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
  margin-top: 8px;
}

#profile-panel-username {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

#profile-panel-status {
  font-size: 0.85rem;
  color: var(--online);
  font-weight: 500;
}

.profile-panel-section {
  width: 100%;
  margin-top: 16px;
  text-align: left;
}

.profile-panel-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

#profile-panel-bio {
  font-size: 0.9rem;
  color: var(--text);
  line-height: 1.5;
}

.profile-panel-actions {
  width: 100%;
  margin-top: 24px;
}

.profile-panel-actions .btn-primary {
  width: 100%;
  padding: 12px;
  font-size: 0.9375rem;
}

/* ============================================================
   CONTEXT MENU
   ============================================================ */
.context-menu {
  position: fixed;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur-heavy);
  -webkit-backdrop-filter: var(--glass-blur-heavy);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 6px 0;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12), 0 0 0 1px rgba(255,255,255,0.05);
  z-index: 9999;
  min-width: 200px;
  animation: floatIn 0.15s cubic-bezier(0.22, 1, 0.36, 1);
}

.context-menu button {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 10px 16px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 0.9rem;
  text-align: left;
  transition: background 0.15s ease;
  gap: 8px;
}

.context-menu button:hover {
  background: var(--primary-subtle);
}

.context-menu button[data-action="delete-all"],
.context-menu button[data-action="delete-me"] {
  color: var(--danger);
}

/* ============================================================
   MODALS
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9000;
  padding: 16px;
  animation: fadeIn 0.2s ease;
}

.modal-card {
  background: var(--glass-bg-thick);
  backdrop-filter: var(--glass-blur-heavy);
  -webkit-backdrop-filter: var(--glass-blur-heavy);
  border: 1px solid var(--glass-border);
  border-radius: 24px;
  padding: 24px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(255,255,255,0.05);
  animation: scaleIn 0.25s cubic-bezier(0.22, 1, 0.36, 1);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.modal-card h2 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 20px;
}

.modal-card input,
.modal-card textarea {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 0.9375rem;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  margin-bottom: 12px;
}

.modal-card input:focus,
.modal-card textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-subtle);
}

.modal-card input::placeholder,
.modal-card textarea::placeholder {
  color: var(--text-secondary);
}

.modal-card textarea {
  resize: vertical;
  min-height: 72px;
}

.modal-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 6px;
}

.modal-hint {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.modal-scroll {
  flex: 1;
  overflow-y: auto;
  max-height: 280px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 4px;
}

#profile-error {
  color: var(--danger);
  font-size: 0.85rem;
  min-height: 20px;
  text-align: center;
  margin-bottom: 8px;
}

/* Group member item in modal */
.group-member-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.group-member-item:hover {
  background: var(--primary-subtle);
}

.group-member-item input[type="checkbox"] {
  width: auto;
  margin: 0;
  accent-color: var(--primary);
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn-primary {
  padding: 10px 20px;
  background: var(--primary);
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-light);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s cubic-bezier(0.22, 1, 0.36, 1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-primary:hover {
  background: var(--primary-dark);
  box-shadow: 0 4px 15px rgba(124, 92, 252, 0.35);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0) scale(0.97);
  box-shadow: none;
}

.btn-secondary {
  padding: 10px 20px;
  background: var(--bg-secondary);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.btn-secondary:hover {
  background: var(--bg-dark);
  border-color: var(--text-muted);
}

/* ============================================================
   AVATARS
   ============================================================ */
.avatar-small,
.avatar-medium,
.avatar-large,
.avatar-xlarge {
  border-radius: 50%;
  background: var(--primary);
  color: var(--text-light);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
  border: 2px solid var(--primary-subtle);
  transition: transform 0.15s ease;
}

.avatar-small:hover,
.avatar-medium:hover,
.avatar-large:hover,
.avatar-xlarge:hover {
  transform: scale(1.05);
}

.avatar-small {
  width: 36px;
  height: 36px;
  font-size: 0.875rem;
}

.avatar-medium {
  width: 48px;
  height: 48px;
  font-size: 1.1rem;
}

.avatar-large {
  width: 100px;
  height: 100px;
  font-size: 2.2rem;
}

.avatar-xlarge {
  width: 120px;
  height: 120px;
  font-size: 2.75rem;
}

.avatar-small img,
.avatar-medium img,
.avatar-large img,
.avatar-xlarge img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ============================================================
   ONLINE DOT
   ============================================================ */
.online-dot {
  width: 11px;
  height: 11px;
  background: var(--online);
  border: 2px solid var(--bg);
  border-radius: 50%;
  position: absolute;
  bottom: 1px;
  right: 1px;
}

/* ============================================================
   BADGES
   ============================================================ */
.badge {
  background: var(--primary);
  color: var(--text-light);
  font-size: 0.72rem;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  animation: badgePulse 2s ease-in-out infinite;
}

/* ============================================================
   UTILITIES
   ============================================================ */
.empty-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 32px 24px;
  color: var(--text-secondary);
  font-size: 0.9rem;
  text-align: center;
}

/* ============================================================
   DRAG & DROP OVERLAY
   ============================================================ */
#chat-content.drag-over {
  position: relative;
}

#chat-content.drag-over::after {
  content: 'Отпустите файл для отправки';
  position: absolute;
  inset: 0;
  background: var(--primary-subtle);
  border: 3px dashed var(--primary);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--primary);
  z-index: 50;
  pointer-events: none;
}

/* ============================================================
   LOADING / SKELETON
   ============================================================ */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-secondary) 25%,
    var(--bg-dark) 50%,
    var(--bg-secondary) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-xs);
}

.skeleton-avatar { width: 48px; height: 48px; border-radius: 50%; }
.skeleton-text { height: 14px; margin: 6px 0; }
.skeleton-text.short { width: 60%; }
.skeleton-text.long { width: 90%; }

/* ============================================================
   FOCUS RING (accessibility)
   ============================================================ */
button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Smooth transitions on interactive elements */
.chat-item,
.contact-item,
.settings-row,
.context-menu button,
.sidebar-tab,
.auth-tab {
  transition-property: background, color, border-color, box-shadow, transform;
  transition-duration: 0.2s;
  transition-timing-function: cubic-bezier(0.22, 1, 0.36, 1);
}

/* ============================================================
   CUSTOM ICON SYSTEM (ci)
   ============================================================ */

/* Base container — inline-flex keeps icons vertically centred
   inside text flows and button labels without extra markup.    */
.ci {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  vertical-align: middle;
  line-height: 0;
}

.ci svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* Size variants */
.ci-sm  { width: 14px; height: 14px; }
.ci-md  { width: 20px; height: 20px; }
.ci-lg  { width: 24px; height: 24px; }
.ci-xl  { width: 32px; height: 32px; }
.ci-2xl { width: 48px; height: 48px; }
.ci-3xl { width: 64px; height: 64px; }

/* Auth logo — large branded mark */
.auth-logo .ci {
  width: 64px;
  height: 64px;
  color: var(--primary);
  filter: drop-shadow(0 4px 16px rgba(124, 92, 252, 0.4));
}

/* Hamburger and settings list icons */
.hamburger-item-icon .ci,
.settings-icon .ci {
  width: 20px;
  height: 20px;
  opacity: 0.85;
}

/* Empty-state decorative icon */
.empty-icon .ci {
  width: 72px;
  height: 72px;
  color: var(--primary);
  opacity: 0.35;
}

/* Context menu button icons */
.context-menu button .ci {
  width: 15px;
  height: 15px;
  margin-right: 5px;
  opacity: 0.9;
  flex-shrink: 0;
}

/* Chat header action buttons (search, kebab menu) */
.chat-header-actions button .ci {
  width: 22px;
  height: 22px;
}

/* Attach button */
#attach-btn .ci {
  width: 22px;
  height: 22px;
}

/* File-type icon inside message bubbles */
.file-icon-wrap {
  display: inline-flex;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  vertical-align: middle;
}
.file-icon-wrap svg {
  width: 100%;
  height: 100%;
}

/* Message tick (read-receipt) */
.message-tick .ci {
  width: 15px;
  height: 15px;
}

/* Theme-button icon inside button label */
.theme-btn .ci {
  width: 16px;
  height: 16px;
  margin-right: 4px;
  vertical-align: middle;
}

/* Language row checkmark */
.lang-check {
  display: inline-flex;
  width: 16px;
  height: 16px;
  color: var(--primary);
  margin-left: auto;
}
.lang-check svg {
  width: 100%;
  height: 100%;
}

/* Hamburger menu trigger button — icon-bar */
#hamburger-btn .ci {
  width: 22px;
  height: 22px;
}

/* Profile "Write" button icon */
#profile-message-btn .ci {
  width: 18px;
  height: 18px;
  margin-right: 5px;
}

/* Reduce motion: keep icons static */
@media (prefers-reduced-motion: reduce) {
  .ci svg { transition: none !important; }
}

/* ============================================================
   E2E ENCRYPTION (SECRET CHATS)
   ============================================================ */

/* Lock badge on chat list items for e2e rooms */
.e2e-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  line-height: 1;
  margin-left: 4px;
  vertical-align: middle;
  color: #22c55e;
  flex-shrink: 0;
}

/* Message bubble in a secret chat: greenish tint + subtle left border */
.e2e-bubble {
  background: #e6f9ee !important;
  box-shadow: inset 3px 0 0 #22c55e;
}

.dark .e2e-bubble {
  background: rgba(34, 197, 94, 0.12) !important;
  box-shadow: inset 3px 0 0 #22c55e;
}

/* The small lock indicator appended inside e2e message meta */
.e2e-lock-icon {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  color: #22c55e;
  margin-left: 4px;
  flex-shrink: 0;
  line-height: 1;
}

/* Chat header "Секретный чат" indicator */
.e2e-header-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.72rem;
  color: #22c55e;
  font-weight: 600;
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.25);
  border-radius: var(--radius-full);
  padding: 2px 8px;
  margin-left: 6px;
  vertical-align: middle;
  white-space: nowrap;
}

/* "Секретный чат" button in profile panel and chat menu */
.e2e-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  background: rgba(34, 197, 94, 0.12);
  border: 1.5px solid rgba(34, 197, 94, 0.4);
  border-radius: var(--radius-sm);
  color: #22c55e;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
  width: 100%;
  margin-top: 8px;
}

.e2e-btn:hover {
  background: rgba(34, 197, 94, 0.2);
  border-color: rgba(34, 197, 94, 0.6);
  transform: translateY(-1px);
}

.e2e-btn:active {
  transform: translateY(0);
}

/* Fingerprint verification display */
.fingerprint-section {
  margin-bottom: 16px;
}

.fingerprint-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.fingerprint-display {
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.82rem;
  line-height: 1.7;
  letter-spacing: 0.05em;
  color: var(--text);
  background: var(--bg-secondary);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  word-break: break-all;
  user-select: all;
  cursor: text;
}

.dark .fingerprint-display {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.1);
}

/* Own e2e message bubble keeps the primary colour but adds the green left border */
.message.own .e2e-bubble {
  background: var(--bubble-out) !important;
  border-left: 3px solid #4ade80;
}

.message.own .e2e-lock-icon {
  color: rgba(255, 255, 255, 0.75);
}

/* ============================================================
   SELF-DESTRUCTING MESSAGES
   ============================================================ */

.self-destruct-msg .message-bubble {
  background: rgba(239, 68, 68, 0.08) !important;
}

.message.own.self-destruct-msg .message-bubble {
  background: linear-gradient(135deg, var(--bubble-out), #9333ea) !important;
}

.self-destruct-timer {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  color: #ef4444;
  font-size: 0.7rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  margin-right: 2px;
}

.sd-circle {
  flex-shrink: 0;
  transition: stroke-dashoffset 0.3s ease;
}

.sd-circle-fg {
  transition: stroke-dashoffset 1s linear;
}

.message.own .self-destruct-timer {
  color: rgba(255, 220, 220, 0.9);
}

/* sd-bubble: subtle top accent bar */
.sd-bubble {
  position: relative;
}

.sd-bubble::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, #ef4444, #f97316);
  border-radius: 2px 2px 0 0;
}

/* Toggle button in input bar */
.self-destruct-toggle {
  width: 40px;
  height: 40px;
  background: transparent;
  border: none;
  cursor: pointer;
  border-radius: 50%;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  flex-shrink: 0;
  align-self: flex-end;
  position: relative;
}

.self-destruct-toggle:hover {
  color: var(--primary);
  background: var(--primary-subtle);
}

.self-destruct-toggle.active {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.12);
}

/* TTL picker popup */
.ttl-picker {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  background: var(--glass-bg-thick, var(--bg));
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px;
  display: flex;
  gap: 4px;
  box-shadow: var(--shadow-lg, 0 8px 32px rgba(0,0,0,0.18));
  z-index: 200;
  backdrop-filter: blur(12px);
}

.ttl-option {
  background: none;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--text);
  transition: all 0.15s ease;
}

.ttl-option:hover {
  background: var(--primary-subtle);
  color: var(--primary);
}

.ttl-option.selected {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* Dark mode */
.dark .self-destruct-msg .message-bubble {
  background: rgba(239, 68, 68, 0.1) !important;
}

.dark .ttl-picker {
  background: rgba(30, 30, 46, 0.95);
  border-color: rgba(255,255,255,0.08);
}

.dark .ttl-option {
  color: var(--text);
}

.dark .ttl-option:hover {
  background: rgba(124, 92, 252, 0.2);
}

/* ============================================================
   MEDIA VIEWER — Telegram-style fullscreen overlay
   ============================================================ */
.media-viewer-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.media-viewer-overlay.active {
  opacity: 1;
  visibility: visible;
}

/* ---- Header ---- */
.mv-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.6), transparent);
  z-index: 10;
}

.mv-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.mv-sender {
  color: #fff;
  font-size: 0.9rem;
  font-weight: 600;
}

.mv-time {
  color: rgba(255,255,255,0.6);
  font-size: 0.75rem;
}

.mv-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mv-counter {
  color: rgba(255,255,255,0.7);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  margin-right: 4px;
}

.mv-download {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  color: #fff;
  transition: background 0.15s;
  text-decoration: none;
}

.mv-download:hover {
  background: rgba(255,255,255,0.15);
}

.mv-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: #fff;
  cursor: pointer;
  transition: background 0.15s;
}

.mv-close:hover {
  background: rgba(255,255,255,0.15);
}

/* ---- Content area ---- */
.mv-content {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 60px 50px 50px;
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
}

.mv-media {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
  transition: transform 0.05s linear;
  user-select: none;
  -webkit-user-select: none;
}

img.mv-media {
  -webkit-user-drag: none;
}

video.mv-media {
  max-width: min(90vw, 1200px);
  max-height: 80vh;
  border-radius: 8px;
  outline: none;
  background: #000;
}

/* ---- Navigation arrows ---- */
.mv-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.1);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  transition: background 0.15s, transform 0.15s;
}

.mv-nav:hover {
  background: rgba(255,255,255,0.2);
  transform: translateY(-50%) scale(1.08);
}

.mv-nav:active {
  transform: translateY(-50%) scale(0.95);
}

.mv-prev {
  left: 12px;
}

.mv-next {
  right: 12px;
}

/* ---- Caption (filename) ---- */
.mv-caption {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  text-align: center;
  padding: 12px 16px;
  background: linear-gradient(to top, rgba(0,0,0,0.5), transparent);
  color: rgba(255,255,255,0.8);
  font-size: 0.8rem;
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mv-caption:empty {
  display: none;
}

/* ---- Responsive: hide nav arrows on mobile ---- */
@media (max-width: 768px) {
  .mv-nav {
    display: none;
  }

  .mv-content {
    padding: 56px 8px 40px;
  }

  .mv-header {
    padding: 8px 12px;
  }
}

/* ---- Animation for media entrance ---- */
.media-viewer-overlay.active .mv-media {
  animation: mvFadeIn 0.2s ease-out;
}

@keyframes mvFadeIn {
  from {
    opacity: 0;
    transform: scale(0.92);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* ============================================================
   RESPONSIVE — MOBILE (≤768px)
   ============================================================ */
@media (max-width: 768px) {
  #app-screen {
    position: relative;
  }

  .icon-bar {
    display: none;
  }

  .hamburger-menu {
    left: 0;
  }

  #sidebar {
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
    transform: translateX(0);
    min-width: unset;
  }

  #sidebar.hidden {
    display: none;
  }

  #chat-area {
    width: 100%;
  }

  #back-btn {
    display: flex !important;
  }

  #profile-panel {
    width: 100%;
    min-width: unset;
    position: absolute;
    inset: 0;
    z-index: 20;
  }

  .chat-header {
    padding: 10px 12px;
    gap: 8px;
  }

  #messages {
    padding: 12px 8px;
  }

  .message-bubble {
    max-width: 80%;
  }

  .input-bar {
    padding: 8px 10px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    gap: 6px;
  }

  .modal-card {
    padding: 20px 16px;
    border-radius: var(--radius-lg);
  }

  .auth-card {
    padding: 32px 24px;
  }
}

/* ============================================================
   RESPONSIVE — DESKTOP (≥769px)
   ============================================================ */
@media (min-width: 769px) {
  #back-btn {
    display: none;
  }
}

/* ============================================================
   DARK MODE OVERRIDES
   (component-specific dark mode rules not covered by variables)
   ============================================================ */

body.dark #auth-screen {
  background: linear-gradient(135deg, #1a0533 0%, #0F0F14 30%, #1A1A2E 60%, #2a1a4e 100%);
}

body.dark .auth-card {
  background: var(--glass-bg-thick);
  border: 1px solid var(--glass-border);
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255,255,255,0.05);
}

body.dark #auth-form input {
  background: var(--input-bg);
  color: var(--text);
  border-color: var(--border);
}

body.dark #auth-form input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(124, 92, 252, 0.2);
}

body.dark .chat-item.active {
  background: var(--primary-subtle);
}

body.dark .chat-item:hover {
  background: var(--bg-secondary);
}

body.dark #empty-state {
  background: var(--chat-bg);
}

body.dark #messages {
  background: var(--chat-bg);
}

body.dark .date-separator span {
  background: var(--glass-bg);
  border-color: var(--glass-border);
  color: var(--text-secondary);
}

body.dark .context-menu {
  background: var(--glass-bg);
  border-color: var(--glass-border);
  backdrop-filter: var(--glass-blur-heavy);
  -webkit-backdrop-filter: var(--glass-blur-heavy);
}

body.dark .modal-card {
  background: var(--glass-bg-thick);
  border-color: var(--glass-border);
}

body.dark .modal-card input,
body.dark .modal-card textarea {
  background: var(--input-bg);
  border-color: var(--border);
  color: var(--text);
}

body.dark .section-label {
  background: var(--glass-bg-thin);
  border-color: var(--glass-border);
}

body.dark .add-contact-bar input {
  background: var(--input-bg);
  border-color: var(--border);
  color: var(--text);
}

body.dark .btn-secondary {
  background: var(--bg-secondary);
  border-color: var(--border);
  color: var(--text);
}

body.dark #message-input {
  background: var(--input-bg);
  border-color: var(--border);
  color: var(--text);
}

body.dark #message-input:focus {
  box-shadow: 0 0 0 3px rgba(124, 92, 252, 0.2);
}

body.dark #search-input {
  background: var(--input-bg);
  border-color: var(--border);
  color: var(--text);
}

/* Dark mode message bubbles */
body.dark .message.own .message-bubble {
  background: linear-gradient(135deg, #7C3AED, #2563EB);
  box-shadow: 0 2px 14px rgba(124, 58, 237, 0.3),
              inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

body.dark .message.own .message-bubble:hover {
  box-shadow: 0 4px 20px rgba(124, 58, 237, 0.4),
              inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

body.dark .message.other .message-bubble {
  background: var(--glass-bg-thick);
  backdrop-filter: var(--glass-blur-light);
  -webkit-backdrop-filter: var(--glass-blur-light);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  border: 1px solid var(--glass-border);
}

body.dark .message.other .message-bubble:hover {
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.35);
}

/* Dark mode settings */
body.dark .settings-profile-hero {
  background: var(--glass-bg-thin);
  border-color: var(--glass-border);
}

body.dark .settings-subpanel-header {
  background: var(--glass-bg);
  border-color: var(--glass-border);
}

body.dark .settings-group {
  background: var(--glass-bg-thin);
  border-color: var(--glass-border);
}

body.dark .font-size-btn {
  background: var(--bg-secondary);
  border-color: var(--border);
  color: var(--text);
}

body.dark .theme-btn {
  background: var(--bg-secondary);
  border-color: var(--border);
  color: var(--text);
}

body.dark .chat-item-name,
body.dark .contact-item-name,
body.dark .chat-item-time {
  color: var(--text);
}

body.dark .settings-edit-profile-btn {
  background: rgba(124, 92, 252, 0.15);
  border-color: rgba(124, 92, 252, 0.35);
}

body.dark .sidebar-header {
  background: var(--glass-bg-thin);
  border-color: var(--glass-border);
}

body.dark .sidebar-tabs {
  background: var(--glass-bg-thin);
  border-color: var(--glass-border);
}

body.dark .chat-header {
  background: var(--glass-bg);
  border-color: var(--glass-border);
}

body.dark .input-bar {
  background: var(--glass-bg);
  border-color: var(--glass-border);
}

body.dark .profile-panel-header {
  background: var(--glass-bg-thin);
  border-color: var(--glass-border);
}

body.dark #profile-panel {
  background: var(--glass-bg-thick);
  border-color: var(--glass-border);
}

body.dark #reply-bar,
body.dark #file-preview {
  background: var(--glass-bg);
  border-color: var(--glass-border);
}
