:root {
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.15s ease;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body.theme-dark {
  --bg: #0f1419;
  --bg-elevated: #1a2029;
  --bg-input: #232a35;
  --bg-hover: #2a3340;
  --bg-active: #313c4d;
  --text: #e6e9ee;
  --text-secondary: #8b95a5;
  --text-muted: #5a6573;
  --border: #2a3340;
  --accent: #5b8def;
  --accent-hover: #4a7adf;
  --accent-text: #ffffff;
  --bubble-out: #2b5278;
  --bubble-in: #232a35;
  --danger: #e53e3e;
  --success: #38a169;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

body.theme-light {
  --bg: #ffffff;
  --bg-elevated: #f7f9fc;
  --bg-input: #eef2f7;
  --bg-hover: #e6ecf3;
  --bg-active: #d8e1ee;
  --text: #0f1419;
  --text-secondary: #5a6573;
  --text-muted: #8b95a5;
  --border: #e1e8ef;
  --accent: #5b8def;
  --accent-hover: #4a7adf;
  --accent-text: #ffffff;
  --bubble-out: #d0e6ff;
  --bubble-in: #f0f3f8;
  --danger: #e53e3e;
  --success: #38a169;
  --shadow: 0 4px 24px rgba(0,0,0,0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  cursor: pointer;
  background: none;
  border: none;
  color: inherit;
}

input, textarea {
  font: inherit;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  outline: none;
  transition: border-color var(--transition);
  width: 100%;
}
input:focus, textarea:focus {
  border-color: var(--accent);
}

html, body { height: 100%; overscroll-behavior: none; }
#app {
  height: 100vh;
  height: 100svh;
  height: 100dvh;
  display: flex;
}

/* ===================== AUTH ===================== */
.auth-screen {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.auth-card {
  background: var(--bg-elevated);
  border-radius: var(--radius);
  padding: 40px 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow);
}
.auth-logo {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  display: block;
}
.auth-card h1 {
  text-align: center;
  font-size: 24px;
  margin-bottom: 8px;
}
.auth-card .subtitle {
  text-align: center;
  color: var(--text-secondary);
  margin-bottom: 24px;
  font-size: 14px;
}
.auth-card form { display: flex; flex-direction: column; gap: 12px; }
.auth-btn {
  background: var(--accent);
  color: var(--accent-text);
  padding: 12px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  transition: background var(--transition);
}
.auth-btn:hover { background: var(--accent-hover); }
.auth-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.auth-toggle {
  text-align: center;
  margin-top: 16px;
  font-size: 14px;
  color: var(--text-secondary);
}
.auth-toggle a { color: var(--accent); cursor: pointer; text-decoration: none; }
.auth-error {
  background: rgba(229, 62, 62, 0.1);
  color: var(--danger);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  text-align: center;
}

/* ===================== MAIN LAYOUT ===================== */
.main {
  display: flex;
  width: 100%;
  height: 100%;
}
.sidebar {
  width: 340px;
  border-right: 1px solid var(--border);
  background: var(--bg-elevated);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.sidebar-header {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}
.sidebar-header .avatar {
  cursor: pointer;
}
.sidebar-header .me-info {
  flex: 1;
  overflow: hidden;
}
.sidebar-header .me-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-header .me-username {
  font-size: 12px;
  color: var(--text-secondary);
}
.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: background var(--transition), color var(--transition);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; }

.search-bar {
  padding: 8px 12px;
}
.search-bar input {
  background: var(--bg-input);
}

.folder-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 12px 8px;
}
.folder-tab {
  padding: 6px 12px;
  background: var(--bg-input);
  border-radius: 14px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), color var(--transition);
  user-select: none;
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.folder-tab:hover { background: var(--bg-hover); color: var(--text); }
.folder-tab.active {
  background: var(--accent);
  color: white;
}
.folder-tab-badge {
  display: inline-block;
  background: rgba(255,255,255,0.25);
  border-radius: 8px;
  padding: 0 5px;
  font-size: 11px;
  min-width: 16px;
  text-align: center;
}
.folder-tab:not(.active) .folder-tab-badge {
  background: var(--accent);
  color: white;
}
.folder-tab .folder-del {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(0,0,0,0.18);
  color: inherit;
  font-size: 14px;
  line-height: 1;
  opacity: 0;
  margin-left: 2px;
  transition: opacity 0.15s, background 0.15s;
}
.folder-tab.active .folder-del { background: rgba(255,255,255,0.25); }
.folder-tab:hover .folder-del { opacity: 1; }
.folder-tab .folder-del:hover { background: var(--danger); color: white; }
.folder-tab.folder-edit-mode .folder-del { opacity: 1; }
.folder-tab-add {
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--accent);
}
.folder-tab-add:hover { background: rgba(91,141,239,0.08); border-color: var(--accent); color: var(--accent); }

@media (hover: none) {
  .folder-tab .folder-del { opacity: 1; }
}

.search-results-section {
  padding: 8px 16px 4px;
  font-size: 12px;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}
.search-message-item {
  padding: 10px 16px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: background var(--transition);
}
.search-message-item:hover { background: var(--bg-hover); }
.search-message-peer {
  font-size: 13px;
  color: var(--accent);
  font-weight: 600;
}
.search-message-text {
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.search-message-text mark {
  background: var(--accent);
  color: white;
  padding: 1px 3px;
  border-radius: 3px;
}
.search-message-time {
  font-size: 11px;
  color: var(--text-muted);
}

.chat-list {
  flex: 1;
  overflow-y: auto;
}
.chat-item {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: background var(--transition);
  border-bottom: 1px solid transparent;
}
.chat-item:hover { background: var(--bg-hover); }
.chat-item.active { background: var(--bg-active); }
.chat-info { flex: 1; overflow: hidden; }
.chat-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-preview {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}
.chat-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}
.chat-time { font-size: 12px; color: var(--text-muted); }
.chat-unread {
  background: var(--accent);
  color: var(--accent-text);
  font-size: 12px;
  font-weight: 600;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  padding: 0 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, #5b8def, #7c5bef);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  flex-shrink: 0;
  position: relative;
  font-size: 16px;
  text-transform: uppercase;
  user-select: none;
}
.avatar.small { width: 36px; height: 36px; font-size: 14px; }
.avatar.large { width: 96px; height: 96px; font-size: 32px; }
.avatar.saved { background: linear-gradient(135deg, #4a7adf, #2b5278); }
.avatar .online-dot {
  position: absolute;
  bottom: 0; right: 0;
  width: 12px; height: 12px;
  background: var(--success);
  border: 2px solid var(--bg-elevated);
  border-radius: 50%;
}

/* ===================== CHAT VIEW ===================== */
.chat-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  position: relative;
  min-width: 0;
}
.chat-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 14px;
  flex-direction: column;
  gap: 12px;
}
.chat-empty svg { width: 80px; height: 80px; opacity: 0.4; }
.chat-header {
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-header .chat-info { cursor: pointer; }
.chat-header-status { font-size: 12px; color: var(--text-secondary); }
.chat-header-status.online { color: var(--success); }
.chat-header-actions { display: flex; gap: 4px; }

.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.message {
  display: flex;
  margin: 1px 0;
  max-width: 70%;
}
.message.out {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.message.in { align-self: flex-start; }
.message + .message.out,
.message + .message.in {
  margin-top: 2px;
}
.message-bubble {
  background: var(--bubble-in);
  padding: 8px 12px;
  border-radius: 16px;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  position: relative;
  min-width: 60px;
}
.message.out .message-bubble {
  background: var(--bubble-out);
}
.message-text { white-space: pre-wrap; }
.message-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
  justify-content: flex-end;
}
.message.out .message-meta { color: rgba(255,255,255,0.6); }
.body.theme-light .message.out .message-meta { color: var(--text-muted); }
.read-check { width: 14px; height: 14px; }
.message-date-separator {
  text-align: center;
  margin: 16px 0 8px;
  font-size: 12px;
  color: var(--text-muted);
}
.message-date-separator span {
  background: var(--bg-elevated);
  padding: 4px 12px;
  border-radius: 12px;
}

.message-image {
  max-width: 320px;
  max-height: 320px;
  border-radius: 12px;
  display: block;
  cursor: pointer;
}
.message-file {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
  min-width: 200px;
}
.message-file-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.message-file-info { flex: 1; overflow: hidden; }
.message-file-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.message-file-size {
  font-size: 12px;
  color: var(--text-muted);
}
.message-voice {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 220px;
}
.voice-play {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.voice-waveform {
  flex: 1;
  height: 28px;
  display: flex;
  align-items: center;
  gap: 2px;
}
.voice-bar {
  flex: 1;
  background: currentColor;
  opacity: 0.4;
  border-radius: 2px;
}
.voice-bar.played { opacity: 1; }
.voice-duration { font-size: 12px; color: var(--text-muted); }

/* ===================== COMPOSER ===================== */
.composer {
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.composer-input-wrap {
  flex: 1;
  background: var(--bg-input);
  border-radius: 20px;
  padding: 8px 12px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  min-height: 40px;
}
.composer-input {
  flex: 1;
  background: transparent;
  border: none;
  resize: none;
  padding: 4px 0;
  max-height: 200px;
  min-height: 22px;
  line-height: 1.4;
}
.composer-input:focus { border: none; }
.composer-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  flex-shrink: 0;
  transition: background var(--transition), color var(--transition);
}
.composer-btn:hover { background: var(--bg-hover); color: var(--accent); }
.composer-btn.send { background: var(--accent); color: white; }
.composer-btn.send:hover { background: var(--accent-hover); color: white; }
.composer-btn.recording { background: var(--danger); color: white; animation: pulse 1.5s infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(229, 62, 62, 0.7); }
  50% { box-shadow: 0 0 0 10px rgba(229, 62, 62, 0); }
}

.recording-bar {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  background: var(--bg-input);
  border-radius: 20px;
  height: 40px;
}
.recording-dot {
  width: 10px;
  height: 10px;
  background: var(--danger);
  border-radius: 50%;
  animation: blink 1s infinite;
}
@keyframes blink { 50% { opacity: 0.3; } }

.attach-preview {
  position: absolute;
  bottom: 70px;
  left: 16px;
  right: 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow);
}

/* ===================== MODAL ===================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal {
  background: var(--bg-elevated);
  border-radius: var(--radius);
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h2 { font-size: 18px; }
.modal-body { padding: 20px; }
.modal-body .field { margin-bottom: 14px; }
.modal-body label {
  display: block;
  font-size: 13px;
  margin-bottom: 6px;
  color: var(--text-secondary);
}
.modal-body .row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
}
.modal-body .row + .row { border-top: 1px solid var(--border); }

.switch {
  position: relative;
  width: 44px;
  height: 24px;
  background: var(--bg-input);
  border-radius: 12px;
  transition: background var(--transition);
  flex-shrink: 0;
}
.switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
  transition: transform var(--transition);
}
.switch.on { background: var(--accent); }
.switch.on::after { transform: translateX(20px); }

/* ===================== CALL UI ===================== */
.call-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.call-remote-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}
.call-local-video {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 160px;
  height: 240px;
  border-radius: var(--radius);
  background: #000;
  object-fit: cover;
  z-index: 1;
}
.call-info {
  position: relative;
  z-index: 1;
  text-align: center;
  color: white;
  text-shadow: 0 2px 8px rgba(0,0,0,0.6);
}
.call-info .name { font-size: 28px; font-weight: 600; margin: 16px 0 8px; }
.call-info .status { font-size: 14px; opacity: 0.8; }
.call-controls {
  position: relative;
  z-index: 1;
  margin-top: 40px;
  display: flex;
  gap: 16px;
}
.call-btn {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  background: rgba(255,255,255,0.15);
  backdrop-filter: blur(10px);
  transition: background var(--transition);
}
.call-btn:hover { background: rgba(255,255,255,0.25); }
.call-btn.end { background: var(--danger); }
.call-btn.accept { background: var(--success); }
.call-btn.off { background: rgba(255,255,255,0.4); }

/* ===================== TOAST ===================== */
#toasts {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--bg-elevated);
  color: var(--text);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-size: 14px;
  animation: slideDown 0.3s ease;
  pointer-events: auto;
}
.toast.error { background: var(--danger); color: white; }
.toast.success { background: var(--success); color: white; }
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===================== SCROLLBARS ===================== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===================== IMAGE VIEWER (lightbox) ===================== */
.img-viewer {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: ivIn 0.18s ease;
  touch-action: pinch-zoom;
}
@keyframes ivIn { from { opacity: 0; } to { opacity: 1; } }
.img-viewer-stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.img-viewer img {
  max-width: 92vw;
  max-height: 92vh;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 10px 60px rgba(0,0,0,0.5);
  user-select: none;
  -webkit-user-drag: none;
  cursor: zoom-in;
  background: #222;
  transform-origin: center center;
  transition: transform 0.15s ease;
  will-change: transform;
  touch-action: none;
}
.img-viewer.zoomed img { cursor: grab; transition: none; }
.img-viewer.panning img { cursor: grabbing; transition: none; }
.img-viewer-controls {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(0,0,0,0.65);
  padding: 6px 8px;
  border-radius: 28px;
  z-index: 1001;
  backdrop-filter: blur(6px);
}
.img-viewer-controls button {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: transparent;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 20px;
  font-weight: 600;
  transition: background 0.15s;
  user-select: none;
}
.img-viewer-controls button:hover { background: rgba(255,255,255,0.15); }
.img-viewer-controls .zoom-percent {
  color: white;
  min-width: 56px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  user-select: none;
}
.img-viewer-close {
  position: fixed;
  top: 18px;
  right: 18px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 1001;
  transition: background 0.15s;
}
.img-viewer-close:hover { background: rgba(255,255,255,0.22); }
.img-viewer-download {
  position: fixed;
  top: 18px;
  right: 72px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 1001;
  transition: background 0.15s;
}
.img-viewer-download:hover { background: rgba(255,255,255,0.22); }
.img-viewer-caption {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 80vw;
  color: white;
  background: rgba(0,0,0,0.6);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 1001;
  text-align: center;
}
.message-image { cursor: zoom-in; }

/* ===================== COOKIE BANNER ===================== */
.cookie-banner {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: 580px;
  width: calc(100% - 40px);
  z-index: 9000;
  animation: cookieIn 0.25s ease-out;
}
@keyframes cookieIn { from { opacity: 0; transform: translate(-50%, 20px); } to { opacity: 1; transform: translate(-50%, 0); } }
.cookie-banner-text {
  flex: 1;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.4;
}
.cookie-banner-text a { color: var(--accent); text-decoration: none; }
.cookie-banner-text a:hover { text-decoration: underline; }
.cookie-banner-btn {
  padding: 8px 16px;
  background: var(--accent);
  color: white;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  border: none;
  flex-shrink: 0;
}
.cookie-banner-btn:hover { background: var(--accent-hover); }
@media (max-width: 600px) {
  .cookie-banner {
    flex-direction: column;
    text-align: center;
  }
  .cookie-banner-btn { width: 100%; }
}

@keyframes messagePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(91,141,239,0); background: transparent; }
  20% { box-shadow: 0 0 0 6px rgba(91,141,239,0.18); background: rgba(91,141,239,0.12); }
  50% { box-shadow: 0 0 0 0 rgba(91,141,239,0.08); background: rgba(91,141,239,0.06); }
}
.message.highlight-pulse {
  animation: messagePulse 1.4s ease-in-out 3;
  border-radius: 12px;
}

.media-grid-item .ph {
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, var(--bg-input) 30%, var(--bg-hover) 50%, var(--bg-input) 70%);
  background-size: 200% 100%;
  animation: mediaShimmer 1.4s linear infinite;
}
@keyframes mediaShimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ===================== USER INFO ===================== */
.user-info-head {
  text-align: center;
  padding: 20px 0 12px;
}
.user-info-head .avatar {
  margin: 0 auto 14px;
}
.user-info-name {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
}
.user-info-status {
  font-size: 13px;
  color: var(--text-secondary);
}
.user-info-status.online { color: var(--success); }
.user-info-fields {
  background: var(--bg-input);
  border-radius: var(--radius);
  padding: 4px 0;
  margin-bottom: 16px;
}
.user-info-field {
  display: flex;
  gap: 14px;
  padding: 12px 16px;
  align-items: flex-start;
}
.user-info-field + .user-info-field { border-top: 1px solid var(--border); }
.user-info-field .icon {
  color: var(--text-muted);
  margin-top: 2px;
  flex-shrink: 0;
}
.user-info-field .icon svg { width: 18px; height: 18px; }
.user-info-field .value {
  font-size: 14px;
  word-break: break-word;
}
.user-info-field .label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.user-info-field.row {
  align-items: center;
  justify-content: space-between;
}
.user-info-tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding: 4px 0 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
  scrollbar-width: none;
}
.user-info-tabs::-webkit-scrollbar { display: none; }
.user-info-tab {
  padding: 6px 12px;
  border-radius: 14px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 6px;
}
.user-info-tab.active {
  background: var(--accent);
  color: white;
}
.user-info-tab-count {
  font-size: 11px;
  background: rgba(255,255,255,0.18);
  border-radius: 8px;
  padding: 0 6px;
  min-width: 18px;
  text-align: center;
}
.user-info-tab:not(.active) .user-info-tab-count {
  background: var(--bg-input);
  color: var(--text-muted);
}
.user-info-pane {
  min-height: 200px;
  max-height: 360px;
  overflow-y: auto;
}
.media-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}
.media-grid-item {
  position: relative;
  aspect-ratio: 1 / 1;
  background: var(--bg-input);
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
}
.media-grid-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.media-empty {
  text-align: center;
  color: var(--text-secondary);
  padding: 40px 20px;
  font-size: 14px;
}
.media-list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.media-list-item:hover { background: var(--bg-hover); border-radius: 6px; }
.media-list-item:last-child { border-bottom: none; }
.media-list-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.media-list-meta {
  flex: 1;
  overflow: hidden;
}
.media-list-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.media-list-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ===================== GIF PICKER ===================== */
.gif-picker {
  display: flex;
  flex-direction: column;
  height: 480px;
  max-height: 80vh;
}
.gif-search {
  margin-bottom: 10px;
}
.gif-section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
  color: var(--text-muted);
  margin: 6px 0 6px;
  padding: 0 2px;
}
.gif-recent-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 10px;
}
.gif-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  padding-right: 4px;
}
.gif-grid-item {
  cursor: pointer;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-input);
  position: relative;
  min-height: 80px;
}
.gif-grid-item img {
  width: 100%;
  display: block;
}
.gif-grid-item:hover::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(91,141,239,0.15);
  border: 2px solid var(--accent);
  border-radius: 8px;
}
.gif-status {
  text-align: center;
  color: var(--text-secondary);
  padding: 20px;
  font-size: 14px;
}
.gif-attribution {
  font-size: 10px;
  color: var(--text-muted);
  text-align: right;
  margin-top: 6px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}
.gif-attribution img {
  height: 14px;
  width: auto;
  display: inline-block;
  vertical-align: middle;
}

.gif-categories {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 4px 0 8px;
  margin-bottom: 4px;
  scrollbar-width: none;
}
.gif-categories::-webkit-scrollbar { display: none; }
.gif-category {
  flex-shrink: 0;
  padding: 6px 12px;
  background: var(--bg-input);
  border-radius: 14px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  transition: background var(--transition);
}
.gif-category:hover { background: var(--bg-hover); }
.gif-category.active { background: var(--accent); color: white; }

.message-gif {
  display: block;
  max-width: 280px;
  max-height: 280px;
  border-radius: 10px;
  cursor: zoom-in;
  background: var(--bg-input);
}

/* ===================== PASSCODE LOCK ===================== */
.passcode-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 99999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  user-select: none;
}
.passcode-lock-icon {
  margin-bottom: 24px;
  color: var(--accent);
}
.passcode-lock-icon svg { width: 56px; height: 56px; }
.passcode-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
  text-align: center;
}
.passcode-subtitle {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 30px;
  text-align: center;
}
.passcode-dots {
  display: flex;
  gap: 18px;
  margin-bottom: 36px;
  transition: transform 0.18s;
}
.passcode-dots.shake { animation: pcShake 0.4s ease; }
@keyframes pcShake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}
.passcode-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--text-muted);
  transition: background var(--transition), border-color var(--transition);
}
.passcode-dot.filled {
  background: var(--accent);
  border-color: var(--accent);
}
.passcode-numpad {
  display: grid;
  grid-template-columns: repeat(3, 78px);
  gap: 14px;
}
.passcode-key {
  width: 78px;
  height: 78px;
  border-radius: 50%;
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.1s, transform 0.05s;
  user-select: none;
}
.passcode-key:hover { background: var(--bg-hover); }
.passcode-key:active { transform: scale(0.92); background: var(--bg-active); }
.passcode-key.empty { background: transparent; cursor: default; }
.passcode-key.empty:hover { background: transparent; }
.passcode-key.action { font-size: 20px; color: var(--text-secondary); }
.passcode-action-row {
  margin-top: 22px;
  display: flex;
  gap: 14px;
  font-size: 13px;
}
.passcode-action-row a {
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
}
.passcode-action-row a:hover { text-decoration: underline; }

.view-once-photo {
  position: relative;
  display: inline-block;
  max-width: 320px;
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  background: var(--bg-input);
  user-select: none;
}
.view-once-photo .blurred {
  filter: blur(28px);
  transform: scale(1.1);
  display: block;
  width: 100%;
  height: auto;
  min-height: 180px;
  max-height: 320px;
  object-fit: cover;
}
.view-once-photo .veil {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.35);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: white;
  gap: 10px;
  text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}
.view-once-photo .veil svg { width: 38px; height: 38px; }
.view-once-photo .veil .label { font-size: 13px; font-weight: 600; }
.view-once-photo .veil .sublabel { font-size: 11px; opacity: 0.8; }
.view-once-photo:hover .veil { background: rgba(0,0,0,0.45); }

/* ===================== LINK PREVIEW ===================== */
.link-preview {
  margin-top: 8px;
  border-left: 3px solid var(--accent);
  padding: 6px 10px;
  background: rgba(91, 141, 239, 0.08);
  border-radius: 0 8px 8px 0;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  max-width: 100%;
}
.link-preview:hover { background: rgba(91, 141, 239, 0.14); }
.link-preview-img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
  background: var(--bg-input);
}
.link-preview-text { flex: 1; min-width: 0; overflow: hidden; }
.link-preview-site {
  font-size: 11px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  font-weight: 600;
}
.link-preview-title {
  font-weight: 600;
  font-size: 14px;
  margin: 2px 0;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.link-preview-desc {
  font-size: 12px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.linkified {
  color: var(--accent);
  text-decoration: underline;
  word-break: break-all;
}
.linkified:hover { opacity: 0.85; }

/* ===================== CONTEXT MENU ===================== */
.ctx-menu {
  position: fixed;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 6px;
  min-width: 200px;
  z-index: 300;
  animation: ctxIn 0.12s ease-out;
}
@keyframes ctxIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}
.ctx-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  user-select: none;
  transition: background var(--transition);
}
.ctx-item:hover { background: var(--bg-hover); }
.ctx-item.danger { color: var(--danger); }
.ctx-item.danger:hover { background: rgba(229, 62, 62, 0.1); }
.ctx-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.ctx-separator {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

/* ===================== REPLY / FORWARD ===================== */
.message-reply-quote {
  border-left: 3px solid var(--accent);
  padding: 4px 8px;
  margin-bottom: 6px;
  background: rgba(91, 141, 239, 0.08);
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  max-width: 100%;
}
.message-reply-quote-name {
  font-weight: 600;
  color: var(--accent);
  font-size: 12px;
}
.message-reply-quote-text {
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 240px;
}
.message-forwarded {
  font-size: 12px;
  color: var(--accent);
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.message-edited {
  font-style: italic;
  font-size: 11px;
  opacity: 0.7;
  margin-right: 4px;
}

.composer-banner {
  padding: 6px 12px 8px;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.composer-banner-info {
  flex: 1;
  border-left: 3px solid var(--accent);
  padding: 2px 0 2px 10px;
  overflow: hidden;
}
.composer-banner-label {
  font-size: 12px;
  color: var(--accent);
  font-weight: 600;
}
.composer-banner-text {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===================== MUTED / PINNED ===================== */
.chat-meta-icons {
  display: flex;
  gap: 4px;
  align-items: center;
  color: var(--text-muted);
}
.chat-meta-icons svg { width: 14px; height: 14px; }

/* ===================== SELF-DESTRUCT ===================== */
.message-burning {
  position: relative;
}
.message-burn-timer {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  color: var(--danger);
  font-weight: 600;
  margin-left: 4px;
}
.message-burn-timer svg { width: 11px; height: 11px; }
.message-burning.expiring {
  animation: burnFade 1s linear infinite;
}
@keyframes burnFade {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* ===================== PROFILE / AVATAR UPLOAD ===================== */
.profile-avatar-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}
.profile-avatar-upload {
  position: relative;
  cursor: pointer;
}
.profile-avatar-upload .upload-overlay {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity var(--transition);
  color: white;
}
.profile-avatar-upload:hover .upload-overlay { opacity: 1; }
.profile-avatar-upload .upload-overlay svg { width: 28px; height: 28px; }
.profile-bio {
  width: 100%;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font: inherit;
  min-height: 60px;
  resize: vertical;
  font-family: inherit;
}
.profile-bio:focus { border-color: var(--accent); outline: none; }
.profile-emoji-input {
  width: 60px;
  text-align: center;
  font-size: 22px;
}

.emoji-status-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.emoji-status-current {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--bg-input);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--transition);
}
.emoji-status-current:hover { background: var(--bg-hover); }
.emoji-status-current.empty { color: var(--text-muted); font-size: 22px; }
.emoji-status-clear {
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 6px;
}
.emoji-status-clear:hover { background: var(--bg-hover); color: var(--danger); }

.emoji-picker {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  max-height: 320px;
  overflow-y: auto;
  padding: 8px;
  background: var(--bg-input);
  border-radius: 8px;
}
.emoji-picker-item {
  font-size: 22px;
  padding: 6px;
  text-align: center;
  cursor: pointer;
  border-radius: 6px;
  transition: background var(--transition);
  user-select: none;
}
.emoji-picker-item:hover { background: var(--bg-hover); }
.emoji-picker-group-title {
  grid-column: 1 / -1;
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
  padding: 8px 4px 4px;
  letter-spacing: 0.5px;
}

/* ===================== SESSIONS ===================== */
.session-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.session-item:last-child { border-bottom: none; }
.session-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-input);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  flex-shrink: 0;
}
.session-info { flex: 1; overflow: hidden; }
.session-label {
  font-weight: 600;
  font-size: 14px;
}
.session-meta {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 2px;
}
.session-current {
  color: var(--success);
  font-size: 12px;
  font-weight: 600;
}
.btn-revoke {
  color: var(--danger);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  transition: background var(--transition);
}
.btn-revoke:hover { background: rgba(229, 62, 62, 0.1); }

/* ===================== BLOCKS LIST ===================== */
.blocked-list { display: flex; flex-direction: column; }
.blocked-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.blocked-item:last-child { border-bottom: none; }
.blocked-empty {
  text-align: center;
  padding: 20px;
  color: var(--text-secondary);
  font-size: 14px;
}

/* ===================== DRAG-AND-DROP ===================== */
.chat-view.dragover::before {
  content: '';
  position: absolute;
  inset: 12px;
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  background: rgba(91, 141, 239, 0.06);
  pointer-events: none;
  z-index: 10;
}
.chat-view.dragover::after {
  content: 'Отпустите файл, чтобы прикрепить';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--accent);
  font-weight: 600;
  font-size: 16px;
  pointer-events: none;
  z-index: 11;
}

/* ===================== TTL PICKER ===================== */
.ttl-picker-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.ttl-option {
  padding: 12px;
  text-align: center;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
  font-size: 14px;
}
.ttl-option:hover { background: var(--bg-hover); }
.ttl-option.active { background: var(--accent); color: white; }

.autolock-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--bg-input);
  border-radius: var(--radius);
  padding: 4px;
}
.autolock-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
  user-select: none;
}
.autolock-option:hover { background: var(--bg-hover); }
.autolock-option.active { background: var(--accent); color: white; }
.autolock-option .check {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition);
}
.autolock-option.active .check {
  background: white;
  border-color: white;
  color: var(--accent);
}
.autolock-option .check svg {
  width: 14px;
  height: 14px;
  opacity: 0;
  transition: opacity var(--transition);
}
.autolock-option.active .check svg { opacity: 1; }

/* ===================== RESPONSIVE ===================== */
@media (max-width: 768px) {
  .sidebar { width: 100%; }
  .chat-view { display: none; }
  body.in-chat .sidebar { display: none; }
  body.in-chat .chat-view { display: flex; }
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
