/* ============================================================
   KVIBE MESSENGER — Design System & Styles
   ============================================================ */

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ---- Light Theme (default) ---- */
:root,
[data-theme="light"] {
  /* Surfaces */
  --bg-primary: #FFFFFF;
  --bg-secondary: #F5F7FA;
  --bg-tertiary: #EEF1F5;
  --bg-hover: #E8ECF1;
  --bg-active: #DFE6F0;
  --bg-sidebar: #FFFFFF;
  --bg-input: #F0F2F5;
  --bg-modal-overlay: rgba(0,0,0,0.35);

  /* Chat */
  --bg-message-own: #2AABEE;
  --bg-message-own-hover: #2499D9;
  --bg-message-other: #EEF1F5;
  --bg-message-other-hover: #E4E8ED;
  --text-message-own: #FFFFFF;
  --text-message-other: #1A1D26;

  /* Text */
  --text-primary: #1A1D26;
  --text-secondary: #6B7280;
  --text-tertiary: #9CA3AF;
  --text-inverse: #FFFFFF;
  --text-link: #2AABEE;

  /* Borders */
  --border-primary: #E5E7EB;
  --border-light: #F0F2F5;
  --border-input: #D1D5DB;
  --border-input-focus: #2AABEE;

  /* Accent */
  --accent: #2AABEE;
  --accent-hover: #2499D9;
  --accent-light: rgba(42,171,238,0.1);
  --accent-soft: rgba(42,171,238,0.15);

  /* Status */
  --online: #22C55E;
  --error: #EF4444;
  --error-light: rgba(239,68,68,0.08);
  --read-tick: #2AABEE;
  --delivered-tick: #9CA3AF;
  --sent-tick: #9CA3AF;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
  --shadow-card: 0 2px 8px rgba(0,0,0,0.06), 0 0 1px rgba(0,0,0,0.1);

  /* Radii */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  /* Spacing */
  --sp-xs: 4px;
  --sp-sm: 8px;
  --sp-md: 12px;
  --sp-lg: 16px;
  --sp-xl: 20px;
  --sp-2xl: 24px;
  --sp-3xl: 32px;

  /* Sidebar width */
  --sidebar-width: 360px;

  /* Skeleton */
  --skeleton-base: #E5E7EB;
  --skeleton-shine: #F3F4F6;

  /* Toggle */
  --toggle-bg: #D1D5DB;
  --toggle-bg-active: #2AABEE;
  --toggle-thumb: #FFFFFF;

  /* Scrollbar */
  --scrollbar-thumb: rgba(0,0,0,0.15);
  --scrollbar-thumb-hover: rgba(0,0,0,0.25);

  /* Transition */
  --transition-fast: 150ms ease;
  --transition-normal: 200ms ease;
  --transition-slow: 300ms ease;
}

/* ---- Dark Theme ---- */
[data-theme="dark"] {
  --bg-primary: #1A1A2E;
  --bg-secondary: #16162A;
  --bg-tertiary: #222240;
  --bg-hover: #282850;
  --bg-active: #2E2E5A;
  --bg-sidebar: #15152A;
  --bg-input: #222240;
  --bg-modal-overlay: rgba(0,0,0,0.6);

  --bg-message-own: #2AABEE;
  --bg-message-own-hover: #2499D9;
  --bg-message-other: #282850;
  --bg-message-other-hover: #2E2E5A;
  --text-message-own: #FFFFFF;
  --text-message-other: #E2E8F0;

  --text-primary: #E2E8F0;
  --text-secondary: #94A3B8;
  --text-tertiary: #64748B;
  --text-inverse: #FFFFFF;
  --text-link: #5BC0F8;

  --border-primary: #2D2D55;
  --border-light: #222240;
  --border-input: #3D3D65;
  --border-input-focus: #2AABEE;

  --accent: #2AABEE;
  --accent-hover: #5BC0F8;
  --accent-light: rgba(42,171,238,0.12);
  --accent-soft: rgba(42,171,238,0.2);

  --online: #22C55E;
  --error: #F87171;
  --error-light: rgba(248,113,113,0.1);
  --read-tick: #2AABEE;
  --delivered-tick: #64748B;
  --sent-tick: #64748B;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.4);
  --shadow-card: 0 2px 8px rgba(0,0,0,0.2), 0 0 1px rgba(0,0,0,0.3);

  --skeleton-base: #2D2D55;
  --skeleton-shine: #3A3A65;

  --toggle-bg: #3D3D65;
  --toggle-bg-active: #2AABEE;

  --scrollbar-thumb: rgba(255,255,255,0.12);
  --scrollbar-thumb-hover: rgba(255,255,255,0.22);
}

/* ---- Base ---- */
html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-secondary);
  transition: background var(--transition-slow), color var(--transition-slow);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.screen {
  height: 100vh;
  width: 100%;
}

.hidden {
  display: none !important;
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-thumb-hover); }
* { scrollbar-width: thin; scrollbar-color: var(--scrollbar-thumb) transparent; }

/* ---- Typography ---- */
h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: 1.3;
}

a { color: var(--text-link); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-sm);
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-normal);
  outline: none;
  user-select: none;
  white-space: nowrap;
}

.btn:focus-visible {
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn-primary {
  background: var(--accent);
  color: var(--text-inverse);
}
.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: var(--shadow-md);
}
.btn-primary:active {
  transform: scale(0.98);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-full {
  width: 100%;
}

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

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}
.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.icon-btn:focus-visible {
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ============================================================
   FORMS
   ============================================================ */
.form-group {
  margin-bottom: var(--sp-lg);
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: var(--sp-xs);
}

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

.input-wrapper .input-icon {
  position: absolute;
  left: 12px;
  color: var(--text-tertiary);
  pointer-events: none;
  flex-shrink: 0;
}

.input-wrapper input {
  width: 100%;
  padding: 10px 12px 10px 40px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1.5px solid var(--border-input);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
}

.input-wrapper input::placeholder {
  color: var(--text-tertiary);
}

.input-wrapper input:focus {
  border-color: var(--border-input-focus);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: var(--bg-primary);
}

.input-wrapper input:hover:not(:focus) {
  border-color: var(--border-primary);
}

/* Search input */
.input-wrapper--search input {
  padding-left: 36px;
  padding-right: 36px;
}
.input-wrapper--search .search-clear {
  position: absolute;
  right: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: all var(--transition-fast);
}
.input-wrapper--search .search-clear:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* ============================================================
   AUTH SCREEN
   ============================================================ */
#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-secondary);
  padding: var(--sp-xl);
}

.auth-container {
  width: 100%;
  max-width: 400px;
  animation: fadeUp 0.4s ease;
}

.auth-card {
  background: var(--bg-primary);
  border-radius: var(--radius-xl);
  padding: var(--sp-3xl);
  box-shadow: var(--shadow-lg);
}

.auth-logo {
  text-align: center;
  margin-bottom: var(--sp-2xl);
}

.auth-logo-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: var(--radius-lg);
  margin-bottom: var(--sp-md);
}

.auth-logo-text {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--sp-xs);
}

.auth-logo-sub {
  font-size: 14px;
  color: var(--text-secondary);
}

/* Auth Tabs */
.auth-tabs {
  display: flex;
  position: relative;
  background: var(--bg-input);
  border-radius: var(--radius-md);
  padding: 3px;
  margin-bottom: var(--sp-2xl);
}

.auth-tab {
  flex: 1;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color var(--transition-fast);
  position: relative;
  z-index: 1;
}
.auth-tab.active {
  color: var(--accent);
}
.auth-tab:not(.active):hover {
  color: var(--text-primary);
}

.auth-tab-indicator {
  position: absolute;
  top: 3px;
  left: 3px;
  width: calc(50% - 3px);
  height: calc(100% - 6px);
  background: var(--bg-primary);
  border-radius: calc(var(--radius-sm) - 1px);
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-normal);
  z-index: 0;
}
.auth-tab-indicator.right {
  transform: translateX(100%);
}

.auth-form {
  animation: fadeIn 0.25s ease;
}

.auth-error {
  background: var(--error-light);
  color: var(--error);
  font-size: 13px;
  font-weight: 500;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: var(--sp-lg);
  border: 1px solid var(--error);
  animation: shake 0.3s ease;
}

.auth-form .btn {
  margin-top: var(--sp-sm);
  padding: 12px 20px;
}

/* ============================================================
   MESSENGER LAYOUT
   ============================================================ */
#app-screen {
  background: var(--bg-secondary);
}

.messenger {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-light);
  transition: background var(--transition-slow);
  z-index: 10;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-md) var(--sp-lg);
  min-height: 60px;
  border-bottom: 1px solid var(--border-light);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
}

.brand-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: var(--accent);
  color: var(--text-inverse);
  border-radius: var(--radius-sm);
}

.brand-name {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

.sidebar-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

/* Theme toggle icons */
[data-theme="light"] .icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }

/* Sidebar Search */
.sidebar-search {
  padding: var(--sp-sm) var(--sp-md);
  border-bottom: 1px solid var(--border-light);
}

.sidebar-search .input-wrapper--search input {
  background: var(--bg-input);
  border: 1px solid transparent;
  padding: 8px 36px 8px 36px;
  font-size: 13px;
}
.sidebar-search .input-wrapper--search input:focus {
  border-color: var(--border-input-focus);
  background: var(--bg-primary);
}

/* Sidebar Content */
.sidebar-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
}

/* ============================================================
   CHAT LIST
   ============================================================ */
.chat-list {
  padding: var(--sp-xs) 0;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: var(--sp-md);
  padding: var(--sp-sm) var(--sp-lg);
  cursor: pointer;
  transition: background var(--transition-fast);
  position: relative;
  border-left: 3px solid transparent;
}
.chat-item:hover {
  background: var(--bg-hover);
}
.chat-item.active {
  background: var(--accent-light);
  border-left-color: var(--accent);
}

/* Avatar */
.avatar {
  position: relative;
  flex-shrink: 0;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: var(--text-inverse);
  user-select: none;
  overflow: hidden;
}
.avatar--sm { width: 40px; height: 40px; font-size: 15px; }
.avatar--md { width: 48px; height: 48px; font-size: 18px; }
.avatar--lg { width: 56px; height: 56px; font-size: 22px; }
.avatar--xl { width: 96px; height: 96px; font-size: 36px; }
.avatar--group { border-radius: var(--radius-md); }

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

/* Generate avatar colors from name */
.avatar[data-color="0"] { background: #2AABEE; }
.avatar[data-color="1"] { background: #8B5CF6; }
.avatar[data-color="2"] { background: #F59E0B; }
.avatar[data-color="3"] { background: #22C55E; }
.avatar[data-color="4"] { background: #EF4444; }
.avatar[data-color="5"] { background: #EC4899; }
.avatar[data-color="6"] { background: #06B6D4; }
.avatar[data-color="7"] { background: #F97316; }
.avatar[data-color="8"] { background: #6366F1; }
.avatar[data-color="9"] { background: #10B981; }

/* Online Dot */
.online-dot {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 12px;
  height: 12px;
  background: var(--online);
  border: 2px solid var(--bg-sidebar);
  border-radius: var(--radius-full);
}
.avatar--sm .online-dot { width: 10px; height: 10px; border-width: 2px; }
.avatar--lg .online-dot { width: 14px; height: 14px; border-width: 2.5px; }

/* Chat item content */
.item-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.item-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-sm);
}

.item-title .name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-time {
  font-size: 11px;
  color: var(--text-tertiary);
  white-space: nowrap;
  flex-shrink: 0;
}

.item-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-sm);
}

.item-preview .message-text {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  line-height: 1.4;
}

.item-preview .message-text em {
  font-style: normal;
  font-weight: 600;
  color: var(--text-primary);
}

/* Badge */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-inverse);
  background: var(--accent);
  border-radius: var(--radius-full);
  flex-shrink: 0;
}

/* ============================================================
   SEARCH RESULTS
   ============================================================ */
.search-results {
  padding: var(--sp-xs) 0;
}

.user-item {
  display: flex;
  align-items: center;
  gap: var(--sp-md);
  padding: var(--sp-sm) var(--sp-lg);
  cursor: pointer;
  transition: background var(--transition-fast);
}
.user-item:hover {
  background: var(--bg-hover);
}

.user-item .item-title {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.user-item .username {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.user-item .user-status {
  font-size: 12px;
  color: var(--text-secondary);
}

.user-item .user-status.online {
  color: var(--online);
}

/* ============================================================
   EMPTY STATES
   ============================================================ */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--sp-3xl) var(--sp-xl);
  min-height: 200px;
}

.empty-state-icon {
  color: var(--text-tertiary);
  margin-bottom: var(--sp-lg);
  opacity: 0.5;
}

.empty-state-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--sp-xs);
}

.empty-state-text {
  font-size: 13px;
  color: var(--text-secondary);
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
  background: var(--bg-secondary);
  transition: background var(--transition-slow);
}

/* ---- Chat Placeholder ---- */
.chat-placeholder {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.chat-placeholder-inner {
  animation: fadeUp 0.4s ease;
}

.chat-placeholder-icon {
  color: var(--text-tertiary);
  opacity: 0.35;
  margin-bottom: var(--sp-xl);
}

.chat-placeholder-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--sp-sm);
}

.chat-placeholder-text {
  font-size: 14px;
  color: var(--text-tertiary);
}

/* ============================================================
   CHAT VIEW
   ============================================================ */
.chat-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

/* ---- Chat Header ---- */
.chat-header {
  display: flex;
  align-items: center;
  gap: var(--sp-md);
  padding: var(--sp-sm) var(--sp-lg);
  min-height: 60px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-light);
  transition: background var(--transition-slow);
  z-index: 5;
}

.back-btn {
  display: none;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: var(--sp-md);
  flex: 1;
  min-width: 0;
  cursor: pointer;
  padding: 4px 0;
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
}
.chat-header-info:hover {
  background: var(--bg-hover);
  padding: 4px var(--sp-sm);
  margin-left: calc(-1 * var(--sp-sm));
}

.chat-header-text {
  min-width: 0;
}

.chat-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-status {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-height: 16px;
  transition: color var(--transition-fast);
}

.chat-status.status-online {
  color: var(--online);
}

.chat-status.status-typing {
  color: var(--accent);
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

/* ---- Messages ---- */
.messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--sp-lg);
  display: flex;
  flex-direction: column;
  gap: var(--sp-xs);
  scroll-behavior: smooth;
}

/* ---- Message Bubble ---- */
.message {
  display: flex;
  flex-direction: column;
  max-width: 72%;
  animation: msgIn 0.25s ease;
  position: relative;
}

.message.own {
  align-self: flex-end;
  align-items: flex-end;
}

.message:not(.own) {
  align-self: flex-start;
  align-items: flex-start;
}

.message-bubble {
  padding: 8px 14px;
  border-radius: var(--radius-lg);
  word-wrap: break-word;
  word-break: break-word;
  overflow-wrap: break-word;
  line-height: 1.45;
  position: relative;
  transition: background var(--transition-fast);
}

.message.own .message-bubble {
  background: var(--bg-message-own);
  color: var(--text-message-own);
  border-bottom-right-radius: 4px;
}

.message:not(.own) .message-bubble {
  background: var(--bg-message-other);
  color: var(--text-message-other);
  border-bottom-left-radius: 4px;
}

.message:not(.own) .message-bubble:hover {
  background: var(--bg-message-other-hover);
}

.message.own .message-bubble:hover {
  background: var(--bg-message-own-hover);
}

.message-content {
  font-size: 14px;
  white-space: pre-wrap;
}

/* Message meta: time + status */
.message-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
  padding: 0 4px;
}

.message-time {
  font-size: 11px;
  opacity: 0.65;
}

.message-status {
  display: inline-flex;
  align-items: center;
}

.message-status svg {
  width: 16px;
  height: 11px;
}

/* Status colors */
.message-status.status-sent svg { color: var(--sent-tick); }
.message-status.status-delivered svg { color: var(--delivered-tick); }
.message-status.status-read svg { color: var(--read-tick); }

/* ---- Typing Indicator ---- */
.typing-indicator {
  padding: 0 var(--sp-lg) var(--sp-sm);
}

.typing-indicator-inner {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-sm);
  padding: 6px 14px;
  background: var(--bg-message-other);
  border-radius: var(--radius-lg);
  border-bottom-left-radius: 4px;
}

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

.typing-dots span {
  width: 6px;
  height: 6px;
  background: var(--text-tertiary);
  border-radius: var(--radius-full);
  animation: typingBounce 1.4s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

.typing-text {
  font-size: 12px;
  color: var(--text-tertiary);
}

/* ============================================================
   MESSAGE FORM
   ============================================================ */
.message-form {
  padding: var(--sp-sm) var(--sp-lg);
  background: var(--bg-primary);
  border-top: 1px solid var(--border-light);
  transition: background var(--transition-slow);
}

.message-input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: var(--sp-sm);
  background: var(--bg-input);
  border: 1.5px solid var(--border-input);
  border-radius: var(--radius-lg);
  padding: 4px 4px 4px 0;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.message-input-wrapper:focus-within {
  border-color: var(--border-input-focus);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: var(--bg-primary);
}

.attach-btn {
  margin-left: 4px;
  color: var(--text-tertiary);
}
.attach-btn:hover {
  color: var(--accent);
}

.message-input {
  flex: 1;
  padding: 8px 12px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text-primary);
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  line-height: 1.45;
  max-height: 120px;
  min-height: 22px;
}

.message-input::placeholder {
  color: var(--text-tertiary);
}

.send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: var(--text-inverse);
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--transition-fast);
}
.send-btn:hover {
  background: var(--accent-hover);
  box-shadow: var(--shadow-sm);
}
.send-btn:active {
  transform: scale(0.92);
}
.send-btn:focus-visible {
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ============================================================
   PROFILE PANEL (slide-in)
   ============================================================ */
.profile-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: 360px;
  height: 100%;
  background: var(--bg-primary);
  border-left: 1px solid var(--border-light);
  box-shadow: var(--shadow-lg);
  z-index: 20;
  display: flex;
  flex-direction: column;
  animation: slideInRight 0.25s ease;
  transition: background var(--transition-slow);
}

.profile-panel-header {
  display: flex;
  align-items: center;
  gap: var(--sp-md);
  padding: var(--sp-md) var(--sp-lg);
  min-height: 60px;
  border-bottom: 1px solid var(--border-light);
}

.profile-panel-title {
  font-size: 16px;
  font-weight: 600;
}

.profile-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-2xl);
}

/* Profile content components */
.profile-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding-bottom: var(--sp-xl);
  margin-bottom: var(--sp-lg);
  border-bottom: 1px solid var(--border-light);
}

.profile-hero .avatar {
  margin-bottom: var(--sp-md);
}

.profile-hero .profile-name {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: var(--sp-xs);
}

.profile-hero .profile-status {
  font-size: 13px;
  color: var(--text-secondary);
}
.profile-hero .profile-status.online {
  color: var(--online);
}

.profile-info-list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-md);
}

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

.profile-info-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.profile-info-value {
  font-size: 14px;
  color: var(--text-primary);
}

.profile-action-btn {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  width: 100%;
  padding: 12px var(--sp-lg);
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  color: var(--accent);
  background: var(--accent-light);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  margin-top: var(--sp-lg);
}
.profile-action-btn:hover {
  background: var(--accent-soft);
}

/* Group members list */
.group-members-list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-xs);
}

.group-member {
  display: flex;
  align-items: center;
  gap: var(--sp-md);
  padding: var(--sp-sm);
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
}
.group-member:hover {
  background: var(--bg-hover);
}

.group-member-info {
  flex: 1;
  min-width: 0;
}

.group-member-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.group-member-role {
  font-size: 12px;
  color: var(--text-tertiary);
}

/* ============================================================
   MODALS
   ============================================================ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-xl);
  animation: fadeIn 0.2s ease;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  background: var(--bg-modal-overlay);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  background: var(--bg-primary);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: scaleIn 0.25s ease;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-xl) var(--sp-2xl) var(--sp-md);
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
}

.modal-body {
  padding: 0 var(--sp-2xl) var(--sp-lg);
  overflow-y: auto;
  flex: 1;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-sm);
  padding: var(--sp-md) var(--sp-2xl) var(--sp-xl);
  border-top: 1px solid var(--border-light);
}

/* Group chips */
.group-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-sm);
  margin-bottom: var(--sp-md);
}

.group-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-xs);
  padding: 4px 10px 4px 6px;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 500;
  animation: chipIn 0.2s ease;
}

.group-chip-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border: none;
  background: transparent;
  color: var(--accent);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: background var(--transition-fast);
  font-size: 14px;
  line-height: 1;
}
.group-chip-remove:hover {
  background: var(--accent-soft);
}

.group-results {
  max-height: 240px;
  overflow-y: auto;
}

/* ============================================================
   MY PROFILE MODAL
   ============================================================ */
.modal-card--profile {
  max-width: 400px;
}

.my-profile-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: var(--sp-xl) 0;
}

.my-profile-hero .avatar {
  margin-bottom: var(--sp-lg);
}

.my-profile-name {
  font-size: 20px;
  font-weight: 700;
}

.my-profile-email {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: var(--sp-xs);
}

.my-profile-actions {
  display: flex;
  flex-direction: column;
  gap: var(--sp-xs);
  margin-top: var(--sp-md);
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-md);
  padding: 12px var(--sp-md);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition-fast);
  border: none;
  background: transparent;
  width: 100%;
  font-family: inherit;
  font-size: 14px;
  color: var(--text-primary);
}
.setting-row:hover {
  background: var(--bg-hover);
}

.setting-row-info {
  display: flex;
  align-items: center;
  gap: var(--sp-md);
  color: var(--text-primary);
}

.setting-row--danger {
  color: var(--error);
}
.setting-row--danger .setting-row-info {
  color: var(--error);
}

/* Toggle Button */
.toggle-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}

.toggle-track {
  display: block;
  width: 44px;
  height: 24px;
  background: var(--toggle-bg);
  border-radius: var(--radius-full);
  position: relative;
  transition: background var(--transition-fast);
}

.toggle-btn .toggle-track.active {
  background: var(--toggle-bg-active);
}

.toggle-thumb {
  display: block;
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: var(--toggle-thumb);
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-fast);
}

.toggle-btn .toggle-track.active .toggle-thumb {
  transform: translateX(20px);
}

/* ============================================================
   SKELETONS
   ============================================================ */
.skeleton-list,
.skeleton-messages {
  padding: var(--sp-md);
}

.skeleton-item {
  display: flex;
  align-items: center;
  gap: var(--sp-md);
  padding: var(--sp-sm) 0;
}

.skeleton-avatar {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
  background: var(--skeleton-base);
  animation: skeletonPulse 1.8s ease-in-out infinite;
  flex-shrink: 0;
}

.skeleton-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.skeleton-line {
  height: 12px;
  background: var(--skeleton-base);
  border-radius: var(--radius-sm);
  animation: skeletonPulse 1.8s ease-in-out infinite;
}

.skeleton-line--short { width: 40%; }
.skeleton-line:not(.skeleton-line--short) { width: 80%; }

.skeleton-message {
  display: flex;
  margin-bottom: var(--sp-sm);
}
.skeleton-message--own { justify-content: flex-end; }
.skeleton-message--other { justify-content: flex-start; }

.skeleton-bubble {
  width: 180px;
  height: 40px;
  background: var(--skeleton-base);
  border-radius: var(--radius-lg);
  animation: skeletonPulse 1.8s ease-in-out infinite;
}
.skeleton-bubble--long { width: 240px; height: 56px; }

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

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

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

@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes chipIn {
  from { opacity: 0; transform: scale(0.8); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

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

@keyframes skeletonPulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

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

/* ============================================================
   RESPONSIVE — TABLET
   ============================================================ */
@media (max-width: 1024px) {
  :root {
    --sidebar-width: 300px;
  }
}

/* ============================================================
   RESPONSIVE — MOBILE
   ============================================================ */
@media (max-width: 768px) {
  .messenger {
    position: relative;
  }

  .sidebar {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    min-width: 100%;
    height: 100%;
    z-index: 10;
    transition: transform 0.25s ease;
  }

  .sidebar.hidden-mobile {
    transform: translateX(-100%);
    pointer-events: none;
  }

  .main-content {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 5;
  }

  .back-btn {
    display: flex;
  }

  .chat-header-info:hover {
    background: transparent;
    padding: 4px 0;
    margin-left: 0;
  }

  .message {
    max-width: 88%;
  }

  .profile-panel {
    width: 100%;
    animation: slideInRightMobile 0.25s ease;
  }

  @keyframes slideInRightMobile {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
  }

  .modal {
    padding: var(--sp-sm);
    align-items: flex-end;
  }

  .modal-card {
    max-height: 85vh;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    animation: slideUp 0.25s ease;
  }

  @keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }
}

@media (max-width: 480px) {
  .auth-card {
    padding: var(--sp-2xl);
    border-radius: var(--radius-lg);
  }

  .messages {
    padding: var(--sp-sm);
  }

  .message-form {
    padding: var(--sp-sm);
  }
}

/* ============================================================
   UTILITY
   ============================================================ */
.text-center { text-align: center; }
.mt-sm { margin-top: var(--sp-sm); }
.mt-md { margin-top: var(--sp-md); }
.mt-lg { margin-top: var(--sp-lg); }
.mb-sm { margin-bottom: var(--sp-sm); }
.mb-md { margin-bottom: var(--sp-md); }
.mb-lg { margin-bottom: var(--sp-lg); }

/* ============================================================
   MESSAGE SENDER NAME (group chats)
   ============================================================ */
.message-sender-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 2px;
  padding: 0 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
