/* ============================================================
   VOLNA MESSENGER v2.0.0 — STYLE SYSTEM
   ============================================================ */

/* === CSS CUSTOM PROPERTIES === */
:root {
  /* Colors - Light */
  --bg-primary: #ffffff;
  --bg-secondary: #f0f2f5;
  --bg-tertiary: #e4e6eb;
  --bg-hover: rgba(0, 0, 0, 0.04);
  --bg-active: rgba(102, 126, 234, 0.08);
  --bg-bubble-out: #667eea;
  --bg-bubble-in: #ffffff;
  --bg-system: rgba(0, 0, 0, 0.06);

  --text-primary: #1a1a2e;
  --text-secondary: #65676b;
  --text-tertiary: #8a8d91;
  --text-inverse: #ffffff;
  --text-link: #667eea;
  --text-bubble-out: #ffffff;
  --text-bubble-in: #1a1a2e;

  --accent: #667eea;
  --accent-hover: #5a6fd6;
  --accent-light: rgba(102, 126, 234, 0.12);
  --gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);

  --danger: #ef4444;
  --danger-hover: #dc2626;
  --danger-light: rgba(239, 68, 68, 0.1);
  --success: #10b981;
  --success-light: rgba(16, 185, 129, 0.1);
  --warning: #f59e0b;

  --border: #e4e6eb;
  --border-light: rgba(0, 0, 0, 0.06);
  --shadow-sm: 0 1px 2px 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-xl: 0 20px 60px rgba(0, 0, 0, 0.15);

  /* Layout */
  --sidebar-width: 360px;
  --header-height: 60px;
  --composer-height: 56px;
  --info-panel-width: 360px;
  --menu-panel-width: 320px;

  /* Typography */
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-size-xs: 11px;
  --font-size-sm: 13px;
  --font-size-md: 15px;
  --font-size-lg: 17px;
  --font-size-xl: 20px;
  --font-size-2xl: 24px;

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 50%;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow: 350ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Z-index layers */
  --z-base: 1;
  --z-dropdown: 100;
  --z-sticky: 200;
  --z-overlay: 500;
  --z-modal: 1000;
  --z-toast: 5000;
  --z-tooltip: 9000;
}

/* === DARK THEME === */
body.dark {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-tertiary: #0f3460;
  --bg-hover: rgba(255, 255, 255, 0.06);
  --bg-active: rgba(102, 126, 234, 0.15);
  --bg-bubble-out: #667eea;
  --bg-bubble-in: #16213e;
  --bg-system: rgba(255, 255, 255, 0.06);

  --text-primary: #e4e6eb;
  --text-secondary: #b0b3b8;
  --text-tertiary: #8a8d91;
  --text-inverse: #1a1a2e;
  --text-bubble-in: #e4e6eb;

  --border: #2d3748;
  --border-light: rgba(255, 255, 255, 0.08);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.4);
}

/* === RESET & BASE === */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-size-md);
  color: var(--text-primary);
  background: var(--bg-secondary);
  line-height: 1.5;
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
}

input, textarea, button {
  font-family: inherit;
  font-size: inherit;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

a {
  color: var(--text-link);
  text-decoration: none;
}

/* === SCROLLBAR === */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--text-tertiary);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* === ICON BUTTON === */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
  flex-shrink: 0;
}
.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.icon-btn:active {
  transform: scale(0.92);
}

/* ============================================================
   APP LAYOUT
   ============================================================ */

.app {
  display: flex;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  background: var(--bg-primary);
  overflow: hidden;
}

/* ============================================================
   SIDEBAR
   ============================================================ */

.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  border-right: 1px solid var(--border);
  z-index: var(--z-base);
}

.sidebar__header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  height: var(--header-height);
  border-bottom: 1px solid var(--border-light);
}

.sidebar__title {
  flex: 1;
  font-size: var(--font-size-xl);
  font-weight: 700;
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Connection status dot */
.connection-status {
  width: 10px;
  height: 10px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
  transition: background var(--transition-normal);
}
.connection-status--online {
  background: var(--success);
  box-shadow: 0 0 6px var(--success);
}
.connection-status--offline {
  background: var(--text-tertiary);
}

/* === SEARCH BAR === */
.search-bar {
  padding: 8px 12px;
  position: relative;
}
.search-bar__icon {
  position: absolute;
  left: 24px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  pointer-events: none;
}
.search-bar__input {
  width: 100%;
  padding: 10px 12px 10px 40px;
  border: none;
  border-radius: var(--radius-lg);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: var(--font-size-sm);
  outline: none;
  transition: background var(--transition-fast), box-shadow var(--transition-fast);
}
.search-bar__input:focus {
  background: var(--bg-tertiary);
  box-shadow: 0 0 0 2px var(--accent-light);
}
.search-bar__input::placeholder {
  color: var(--text-tertiary);
}

/* === SEARCH RESULTS === */
.search-results {
  position: absolute;
  top: calc(var(--header-height) + 56px);
  left: 0;
  width: var(--sidebar-width);
  max-height: 60vh;
  overflow-y: auto;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-dropdown);
}
.search-section {
  padding: 8px 0;
}
.search-section__title {
  padding: 6px 16px;
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.search-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  cursor: pointer;
  transition: background var(--transition-fast);
}
.search-item:hover {
  background: var(--bg-hover);
}
.search-item__avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: var(--gradient);
  color: var(--text-inverse);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: var(--font-size-md);
  flex-shrink: 0;
}
.search-item__info {
  flex: 1;
  min-width: 0;
}
.search-item__name {
  font-weight: 500;
  font-size: var(--font-size-sm);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-item__sub {
  font-size: var(--font-size-xs);
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-item__action {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: var(--radius-full);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}
.search-loading, .search-no-results {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-tertiary);
  font-size: var(--font-size-sm);
}

/* === CHAT LIST === */
.chat-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

.empty-list {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
}
.empty-list__icon {
  font-size: 48px;
  margin-bottom: 16px;
}
.empty-list__text {
  font-weight: 600;
  margin-bottom: 4px;
}
.empty-list__sub {
  font-size: var(--font-size-sm);
  color: var(--text-tertiary);
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  cursor: pointer;
  transition: background var(--transition-fast);
  border-bottom: 1px solid var(--border-light);
  user-select: none;
}
.chat-item:hover {
  background: var(--bg-hover);
}
.chat-item--active {
  background: var(--bg-active) !important;
}
.chat-item--pinned {
  border-left: 3px solid var(--accent);
}

.chat-item__avatar {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
  background: var(--gradient);
  color: var(--text-inverse);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: var(--font-size-lg);
  flex-shrink: 0;
  overflow: hidden;
}
.chat-item__avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: var(--radius-full);
}

.chat-item__body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.chat-item__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.chat-item__name {
  font-weight: 600;
  font-size: var(--font-size-md);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-item__time {
  font-size: var(--font-size-xs);
  color: var(--text-tertiary);
  flex-shrink: 0;
}
.chat-item__bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.chat-item__preview {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-item__badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--text-inverse);
  font-size: var(--font-size-xs);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ============================================================
   CHAT AREA
   ============================================================ */

.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-width: 0;
  background: var(--bg-secondary);
  position: relative;
}

/* Drag & Drop overlay */
.chat-area.drag-over::after {
  content: '📎 Отпустите для отправки';
  position: absolute;
  inset: 0;
  background: rgba(102, 126, 234, 0.1);
  border: 3px dashed var(--accent);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-size-xl);
  font-weight: 600;
  color: var(--accent);
  z-index: var(--z-overlay);
  pointer-events: none;
}

/* === CHAT HEADER === */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  height: var(--header-height);
  min-height: var(--header-height);
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  z-index: var(--z-sticky);
}
.chat-header__back {
  display: none;
}
.chat-header__info {
  flex: 1;
  min-width: 0;
  cursor: pointer;
}
.chat-header__title {
  font-weight: 600;
  font-size: var(--font-size-lg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-header__status {
  font-size: var(--font-size-xs);
  color: var(--text-tertiary);
}
.chat-header__actions {
  display: flex;
  gap: 4px;
}

/* === MESSAGES === */
.messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  text-align: center;
  padding: 40px;
  color: var(--text-tertiary);
}
.empty-state__logo {
  margin-bottom: 20px;
  border-radius: var(--radius-xl);
  filter: drop-shadow(0 4px 12px rgba(102, 126, 234, 0.3));
}
.empty-state h3 {
  font-size: var(--font-size-xl);
  color: var(--text-primary);
  margin-bottom: 8px;
}
.empty-state p {
  font-size: var(--font-size-sm);
}

/* Date separator */
.date-separator {
  text-align: center;
  padding: 12px 0;
  font-size: var(--font-size-xs);
  color: var(--text-tertiary);
  position: relative;
}
.date-separator::before,
.date-separator::after {
  content: '';
  position: absolute;
  top: 50%;
  width: calc(50% - 50px);
  height: 1px;
  background: var(--border-light);
}
.date-separator::before { left: 0; }
.date-separator::after { right: 0; }

/* === MESSAGE BUBBLES === */
.msg {
  display: flex;
  max-width: 75%;
  animation: msgAppear 200ms ease;
}
@keyframes msgAppear {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg--out {
  align-self: flex-end;
}
.msg--in {
  align-self: flex-start;
}
.msg--system {
  align-self: center;
  max-width: 80%;
}
.msg--system span {
  display: inline-block;
  padding: 4px 12px;
  background: var(--bg-system);
  border-radius: var(--radius-lg);
  font-size: var(--font-size-xs);
  color: var(--text-tertiary);
}

.msg__bubble {
  padding: 8px 12px;
  border-radius: var(--radius-lg);
  max-width: 100%;
  word-wrap: break-word;
  overflow-wrap: break-word;
  position: relative;
}
.msg--out .msg__bubble {
  background: var(--bg-bubble-out);
  color: var(--text-bubble-out);
  border-bottom-right-radius: 4px;
}
.msg--in .msg__bubble {
  background: var(--bg-bubble-in);
  color: var(--text-bubble-in);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-sm);
}

.msg__sender {
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 2px;
}
.msg--out .msg__sender {
  color: rgba(255, 255, 255, 0.8);
}

.msg__forwarded {
  font-size: var(--font-size-xs);
  font-style: italic;
  opacity: 0.7;
  margin-bottom: 4px;
  padding-left: 8px;
  border-left: 2px solid currentColor;
}

.msg__text {
  white-space: pre-wrap;
  line-height: 1.45;
}

.msg__meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 4px;
  font-size: var(--font-size-xs);
  opacity: 0.7;
}
.msg__edited {
  font-style: italic;
  margin-right: 4px;
}
.msg__time {
  white-space: nowrap;
}

/* Message status */
.msg-status {
  font-size: 12px;
}
.status-sent { opacity: 0.5; }
.status-delivered { opacity: 0.7; }
.status-read { color: #34d058; opacity: 1; }
.msg--out .status-read { color: #a0e8ff; }

/* Message image */
.msg__image {
  margin: 4px -4px;
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: pointer;
}
.msg__image img {
  max-width: 320px;
  max-height: 400px;
  width: 100%;
  border-radius: var(--radius-md);
  transition: opacity var(--transition-fast);
}
.msg__image img:hover {
  opacity: 0.9;
}

/* Message file */
.msg__file {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  background: rgba(0, 0, 0, 0.06);
  border-radius: var(--radius-md);
  margin: 4px 0;
}
.msg--out .msg__file {
  background: rgba(255, 255, 255, 0.15);
}
.msg__file-icon {
  font-size: 28px;
  flex-shrink: 0;
}
.msg__file-info {
  flex: 1;
  min-width: 0;
}
.msg__file-name {
  font-weight: 500;
  font-size: var(--font-size-sm);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.msg__file-size {
  font-size: var(--font-size-xs);
  opacity: 0.7;
}
.msg__file-download {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--accent-light);
  border-radius: var(--radius-full);
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--transition-fast);
}
.msg__file-download:hover {
  background: var(--accent);
  color: white;
}

/* Voice message */
.msg__voice {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 180px;
}
.msg__voice-play {
  width: 36px;
  height: 36px;
  border: none;
  background: rgba(0, 0, 0, 0.1);
  border-radius: var(--radius-full);
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--transition-fast);
}
.msg--out .msg__voice-play {
  background: rgba(255, 255, 255, 0.2);
}
.msg__voice-play:hover {
  background: rgba(0, 0, 0, 0.2);
}
.msg__voice-wave {
  flex: 1;
  height: 24px;
  display: flex;
  align-items: center;
  gap: 2px;
}
.msg__voice-wave::before {
  content: '';
  display: block;
  width: 100%;
  height: 2px;
  background: currentColor;
  opacity: 0.3;
  border-radius: 1px;
}
.msg__voice-dur {
  font-size: var(--font-size-xs);
  flex-shrink: 0;
  opacity: 0.7;
}

/* === TYPING INDICATOR === */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 16px 8px;
  font-size: var(--font-size-xs);
  color: var(--text-tertiary);
}
.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--text-tertiary);
  animation: typingBounce 1.4s infinite both;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-6px); opacity: 1; }
}

/* ============================================================
   COMPOSER
   ============================================================ */

.composer {
  background: var(--bg-primary);
  border-top: 1px solid var(--border);
  padding: 8px 12px;
  position: relative;
}
.composer__row {
  display: flex;
  align-items: center;
  gap: 4px;
}
.composer__input {
  flex: 1;
  padding: 10px 14px;
  border: none;
  border-radius: var(--radius-xl);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: var(--font-size-md);
  outline: none;
  transition: background var(--transition-fast);
  min-width: 0;
}
.composer__input:focus {
  background: var(--bg-tertiary);
}
.composer__input::placeholder {
  color: var(--text-tertiary);
}
.composer__action {
  font-size: 18px;
}
.composer__send {
  color: var(--accent);
}
.composer__send:hover {
  background: var(--accent-light);
  color: var(--accent);
}

/* === RECORDING BAR === */
.recording-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--bg-primary);
  border-top: 1px solid var(--border);
}
.recording-bar__pulse {
  width: 12px;
  height: 12px;
  border-radius: var(--radius-full);
  background: var(--danger);
  animation: pulse 1s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.8); }
}
.recording-bar__time {
  font-weight: 600;
  font-size: var(--font-size-md);
  font-variant-numeric: tabular-nums;
}
.recording-bar__label {
  flex: 1;
  font-size: var(--font-size-sm);
  color: var(--text-tertiary);
}
.recording-bar__cancel {
  color: var(--danger);
}

/* === EMOJI PANEL === */
.emoji-panel {
  position: absolute;
  bottom: calc(var(--composer-height) + 8px);
  left: 12px;
  width: 340px;
  max-height: 360px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-dropdown);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.emoji-panel__tabs {
  display: flex;
  overflow-x: auto;
  padding: 8px 8px 0;
  gap: 4px;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}
.emoji-tab {
  padding: 6px 10px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: var(--font-size-xs);
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.emoji-tab:hover {
  background: var(--bg-hover);
}
.emoji-tab.active {
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 600;
}
.emoji-panel__grid {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
}
.emoji-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  font-size: 22px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast), transform var(--transition-fast);
}
.emoji-btn:hover {
  background: var(--bg-hover);
  transform: scale(1.2);
}

/* === ATTACH MENU === */
.attach-menu {
  position: absolute;
  bottom: calc(var(--composer-height) + 8px);
  left: 56px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-dropdown);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 180px;
}
.attach-menu__item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: var(--font-size-sm);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition-fast);
}
.attach-menu__item:hover {
  background: var(--bg-hover);
}
.attach-menu__item svg {
  color: var(--accent);
  flex-shrink: 0;
}

/* ============================================================
   MENU PANEL (SLIDE-IN)
   ============================================================ */

.menu-panel {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--menu-panel-width);
  height: 100%;
  background: var(--bg-primary);
  box-shadow: var(--shadow-xl);
  z-index: var(--z-modal);
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform var(--transition-slow);
  will-change: transform;
}
.menu-panel--open {
  transform: translateX(0);
}

.menu-panel__header {
  padding: 20px 16px;
  background: var(--gradient);
  color: var(--text-inverse);
}
.menu-panel__close {
  color: var(--text-inverse);
  margin-bottom: 16px;
}
.menu-panel__close:hover {
  background: rgba(255, 255, 255, 0.15);
}
.menu-panel__user {
  display: flex;
  align-items: center;
  gap: 12px;
}
.menu-panel__avatar {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: var(--font-size-xl);
  flex-shrink: 0;
}
.menu-panel__name {
  font-weight: 600;
  font-size: var(--font-size-lg);
}
.menu-panel__phone {
  font-size: var(--font-size-sm);
  opacity: 0.8;
}

.menu-panel__body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 20px;
  cursor: pointer;
  transition: background var(--transition-fast);
  color: var(--text-primary);
}
.menu-item:hover {
  background: var(--bg-hover);
}
.menu-item svg {
  color: var(--text-secondary);
  flex-shrink: 0;
}
.menu-item span {
  font-size: var(--font-size-md);
}
.menu-item--toggle {
  justify-content: flex-start;
}
.menu-item--toggle span {
  flex: 1;
}
.menu-item--danger {
  color: var(--danger);
}
.menu-item--danger svg {
  color: var(--danger);
}

.menu-separator {
  height: 1px;
  background: var(--border);
  margin: 8px 16px;
}

.menu-panel__footer {
  padding: 12px 20px;
  text-align: center;
  font-size: var(--font-size-xs);
  color: var(--text-tertiary);
  border-top: 1px solid var(--border);
}

/* Menu overlay */
.menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: calc(var(--z-modal) - 1);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-slow), visibility var(--transition-slow);
}
.menu-overlay.active {
  opacity: 1;
  visibility: visible;
}

/* === TOGGLE SWITCH === */
.toggle {
  position: relative;
  display: inline-block;
}
.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}
.toggle__track {
  display: block;
  width: 44px;
  height: 24px;
  background: var(--text-tertiary);
  border-radius: 12px;
  cursor: pointer;
  transition: background var(--transition-normal);
  position: relative;
}
.toggle__thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: white;
  border-radius: var(--radius-full);
  transition: transform var(--transition-normal);
  box-shadow: var(--shadow-sm);
}
.toggle input:checked + .toggle__track {
  background: var(--accent);
}
.toggle input:checked + .toggle__track .toggle__thumb {
  transform: translateX(20px);
}

/* ============================================================
   INFO PANEL (RIGHT SIDE)
   ============================================================ */

.info-panel {
  width: var(--info-panel-width);
  min-width: var(--info-panel-width);
  height: 100%;
  background: var(--bg-primary);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: var(--z-base);
  animation: slideInRight 250ms ease;
}
@keyframes slideInRight {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}
.info-panel__header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  height: var(--header-height);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.info-panel__body {
  flex: 1;
  overflow-y: auto;
  padding: 24px 16px;
  text-align: center;
}
.info-panel__avatar {
  width: 80px;
  height: 80px;
  border-radius: var(--radius-full);
  background: var(--gradient);
  color: var(--text-inverse);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: var(--font-size-2xl);
  margin: 0 auto 12px;
}
.info-panel__name {
  font-weight: 600;
  font-size: var(--font-size-xl);
  margin-bottom: 4px;
}
.info-panel__desc {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  margin-bottom: 24px;
}
.info-panel__section {
  text-align: left;
}
.info-panel__section h4 {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 8px;
}

/* Member item */
.member-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
}
.member-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--gradient);
  color: var(--text-inverse);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: var(--font-size-sm);
  flex-shrink: 0;
}
.member-info {
  flex: 1;
  min-width: 0;
}
.member-name {
  font-weight: 500;
  font-size: var(--font-size-sm);
}
.member-status {
  font-size: var(--font-size-xs);
  color: var(--text-tertiary);
}

/* ============================================================
   CONTEXT MENU
   ============================================================ */

.ctx-menu {
  min-width: 200px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  animation: ctxAppear 150ms ease;
  z-index: var(--z-modal);
}
@keyframes ctxAppear {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}
.ctx-title {
  padding: 8px 12px 4px;
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--text-tertiary);
}
.ctx-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: var(--font-size-sm);
  color: var(--text-primary);
  transition: background var(--transition-fast);
}
.ctx-item:hover {
  background: var(--bg-hover);
}
.ctx-item--danger {
  color: var(--danger);
}
.ctx-item--danger:hover {
  background: var(--danger-light);
}
.ctx-separator {
  height: 1px;
  background: var(--border-light);
  margin: 4px 8px;
}

/* ============================================================
   CALL MODAL
   ============================================================ */

.call-modal {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
}
.call-modal__bg {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(12px);
}
.call-modal__content {
  position: relative;
  width: 100%;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px 24px;
}
.call-modal__info {
  text-align: center;
  color: white;
  margin-bottom: 40px;
}
.call-modal__icon {
  font-size: 64px;
  margin-bottom: 16px;
  animation: callPulse 2s infinite;
}
@keyframes callPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}
.call-modal__title {
  font-size: var(--font-size-2xl);
  font-weight: 600;
  margin-bottom: 8px;
}
.call-modal__status {
  font-size: var(--font-size-md);
  opacity: 0.7;
}
.call-modal__timer {
  font-size: var(--font-size-xl);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  margin-top: 8px;
}
.call-modal__controls {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: center;
  position: relative;
}
.call-controls-incoming,
.call-controls-active {
  display: flex;
  gap: 16px;
  align-items: center;
}

/* Call buttons */
.call-btn {
  width: 56px;
  height: 56px;
  border: none;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.15);
  color: white;
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast), transform var(--transition-fast);
  backdrop-filter: blur(4px);
}
.call-btn:hover {
  background: rgba(255, 255, 255, 0.25);
  transform: scale(1.05);
}
.call-btn--end {
  background: var(--danger);
}
.call-btn--end:hover {
  background: var(--danger-hover);
}
.call-btn--accept {
  background: var(--success);
}
.call-btn--accept:hover {
  background: #059669;
}
.call-btn.recording {
  background: var(--danger);
  animation: pulse 1s infinite;
}

/* Call recording indicator */
.call-rec-indicator {
  position: absolute;
  top: -30px;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--danger);
  font-size: var(--font-size-xs);
  font-weight: 600;
}
.call-rec-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--danger);
  animation: pulse 1s infinite;
}

/* Call video */
.call-video-container {
  position: absolute;
  inset: 0;
  z-index: -1;
}
.call-video--remote {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.call-video--local {
  position: absolute;
  bottom: 120px;
  right: 20px;
  width: 160px;
  height: 120px;
  border-radius: var(--radius-md);
  object-fit: cover;
  border: 2px solid rgba(255, 255, 255, 0.3);
  z-index: 1;
}

/* ============================================================
   MODAL OVERLAY (generic)
   ============================================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
  animation: fadeIn 200ms ease;
  backdrop-filter: blur(4px);
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.modal-content {
  background: var(--bg-primary);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  width: 90%;
  max-width: 480px;
  max-height: 90vh;
  overflow: hidden;
  animation: modalSlideUp 250ms ease;
}
@keyframes modalSlideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 {
  font-size: var(--font-size-lg);
}
.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 24px;
  cursor: pointer;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-close:hover {
  background: var(--bg-hover);
}
.modal-body {
  padding: 16px 20px;
}
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
}

/* Form inside modal */
.form-group {
  margin-bottom: 16px;
}
.form-label {
  display: block;
  margin-bottom: 6px;
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--text-secondary);
}
.form-input {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: var(--font-size-md);
  outline: none;
  transition: border-color var(--transition-fast);
}
.form-input:focus {
  border-color: var(--accent);
}
textarea.form-input {
  resize: vertical;
  min-height: 60px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition-fast), transform var(--transition-fast);
}
.btn:active {
  transform: scale(0.97);
}
.btn--primary {
  background: var(--accent);
  color: var(--text-inverse);
}
.btn--primary:hover {
  background: var(--accent-hover);
}
.btn--secondary {
  background: var(--bg-secondary);
  color: var(--text-primary);
}
.btn--secondary:hover {
  background: var(--bg-tertiary);
}
.btn--danger {
  background: var(--danger);
  color: var(--text-inverse);
}
.btn--danger:hover {
  background: var(--danger-hover);
}

/* Forward dialog item */
.forward-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: background var(--transition-fast);
}
.forward-item:hover {
  background: var(--bg-hover);
}
.forward-item__avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: var(--gradient);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  flex-shrink: 0;
}

/* Image preview overlay */
.image-preview-overlay {
  background: rgba(0, 0, 0, 0.95) !important;
  cursor: zoom-out;
}
.image-preview-container {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
}
.image-preview-container img {
  max-width: 90vw;
  max-height: 85vh;
  border-radius: var(--radius-md);
  object-fit: contain;
}
.image-preview-close {
  position: absolute;
  top: -40px;
  right: 0;
  background: none;
  border: none;
  color: white;
  font-size: 32px;
  cursor: pointer;
}

/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */

.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: var(--z-toast);
  pointer-events: none;
}
.toast {
  padding: 12px 20px;
  border-radius: var(--radius-md);
  color: white;
  font-size: var(--font-size-sm);
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  opacity: 0;
  transform: translateX(100%);
  transition: opacity var(--transition-normal), transform var(--transition-normal);
  max-width: 360px;
}
.toast--show {
  opacity: 1;
  transform: translateX(0);
}
.toast--hide {
  opacity: 0;
  transform: translateX(100%);
}
.toast--info {
  background: var(--accent);
}
.toast--success {
  background: var(--success);
}
.toast--error {
  background: var(--danger);
}

/* ============================================================
   RESPONSIVE — MOBILE
   ============================================================ */

@media (max-width: 768px) {
  :root {
    --sidebar-width: 100vw;
    --info-panel-width: 100vw;
  }

  .app {
    position: relative;
  }

  .sidebar {
    position: absolute;
    inset: 0;
    z-index: var(--z-base);
    transition: transform var(--transition-slow);
  }

  .chat-area {
    position: absolute;
    inset: 0;
    z-index: calc(var(--z-base) + 1);
    transform: translateX(100%);
    transition: transform var(--transition-slow);
  }
  .chat-area--active {
    transform: translateX(0);
  }

  .chat-header__back {
    display: flex;
  }

  .info-panel {
    position: fixed;
    inset: 0;
    z-index: var(--z-overlay);
  }

  .search-results {
    width: 100vw;
  }

  .emoji-panel {
    width: calc(100vw - 24px);
    left: 12px;
    right: 12px;
  }

  .msg {
    max-width: 85%;
  }

  .call-video--local {
    width: 100px;
    height: 80px;
    bottom: 140px;
    right: 12px;
  }
}

/* Tablet */
@media (min-width: 769px) and (max-width: 1024px) {
  :root {
    --sidebar-width: 300px;
  }
}

/* ============================================================
   ANIMATIONS
   ============================================================ */

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideInLeft {
  from { transform: translateX(-100%); }
  to { transform: translateX(0); }
}

/* Selection color */
::selection {
  background: var(--accent);
  color: white;
}

/* Focus visible */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Print */
@media print {
  .sidebar, .composer, .chat-header__actions, .menu-panel { display: none !important; }
  .chat-area { position: static; transform: none; }
  .messages { overflow: visible; }
}
