/* =========================================================
   Hermes Messenger — современный UI в стиле Telegram
   ========================================================= */

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f4f4f5;
  --bg-tertiary: #eaeaec;
  --bg-chat: #e1eaf2;
  --bg-pattern-opacity: 0.06;
  --text-primary: #0f1419;
  --text-secondary: #707579;
  --text-muted: #a1a5a8;
  --border: #dadce0;
  --accent: #3390ec;
  --accent-hover: #2483d6;
  --accent-light: #4ea4f0;
  --bubble-out: #effdde;
  --bubble-out-text: #0f1419;
  --bubble-in: #ffffff;
  --bubble-in-text: #0f1419;
  --bubble-bot: #f0e7ff;
  --bubble-bot-border: #c2a3ff;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-xl: 22px;
  --transition: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --header-height: 60px;
  --sidebar-width: 360px;
}

[data-theme="dark"] {
  --bg-primary: #17212b;
  --bg-secondary: #0e1621;
  --bg-tertiary: #232e3c;
  --bg-chat: #0e1621;
  --bg-pattern-opacity: 0.04;
  --text-primary: #ffffff;
  --text-secondary: #708499;
  --text-muted: #5f6f81;
  --border: #232e3c;
  --accent: #5680a5;
  --accent-hover: #6c9bbf;
  --bubble-in: #182533;
  --bubble-in-text: #ffffff;
  --bubble-bot: #3a2f5c;
  --bubble-bot-border: #6a4dff;
}

/* Customization overrides — set via JS */
/* These MUST come after [data-theme="dark"] to take precedence */
:root[data-accent="blue"]   { --accent: #3390ec; --accent-hover: #2483d6; }
:root[data-accent="green"]  { --accent: #43a047; --accent-hover: #2e7d32; }
:root[data-accent="purple"] { --accent: #8e24aa; --accent-hover: #6a1b9a; }
:root[data-accent="orange"] { --accent: #fb8c00; --accent-hover: #ef6c00; }
:root[data-accent="pink"]   { --accent: #e91e63; --accent-hover: #c2185b; }
:root[data-accent="teal"]   { --accent: #00897b; --accent-hover: #00695c; }
:root[data-accent="red"]    { --accent: #e53935; --accent-hover: #c62828; }
:root[data-accent="indigo"] { --accent: #5e35b1; --accent-hover: #4527a0; }

:root[data-bubble="green"]  { --bubble-out: #effdde; --bubble-out-text: #0f1419; }
:root[data-bubble="blue"]   { --bubble-out: #dcf0ff; --bubble-out-text: #0f1419; }
:root[data-bubble="purple"] { --bubble-out: #efe7ff; --bubble-out-text: #0f1419; }
:root[data-bubble="pink"]   { --bubble-out: #ffe0eb; --bubble-out-text: #0f1419; }
:root[data-bubble="orange"] { --bubble-out: #ffe8c2; --bubble-out-text: #0f1419; }
:root[data-bubble="teal"]   { --bubble-out: #d0f4f0; --bubble-out-text: #0f1419; }
:root[data-bubble="gray"]   { --bubble-out: #e7e8ea; --bubble-out-text: #0f1419; }

/* Dark bubble variants for dark theme */
[data-theme="dark"][data-bubble="green"]  { --bubble-out: #2b5278; --bubble-out-text: #ffffff; }
[data-theme="dark"][data-bubble="blue"]   { --bubble-out: #1e3a5f; --bubble-out-text: #ffffff; }
[data-theme="dark"][data-bubble="purple"] { --bubble-out: #3a2f5c; --bubble-out-text: #ffffff; }
[data-theme="dark"][data-bubble="pink"]   { --bubble-out: #5a2a3f; --bubble-out-text: #ffffff; }
[data-theme="dark"][data-bubble="orange"] { --bubble-out: #5a3a1a; --bubble-out-text: #ffffff; }
[data-theme="dark"][data-bubble="teal"]   { --bubble-out: #1a3f3a; --bubble-out-text: #ffffff; }
[data-theme="dark"][data-bubble="gray"]   { --bubble-out: #2c333d; --bubble-out-text: #ffffff; }

:root[data-bg="default"]    { --bg-chat: #e1eaf2; }
:root[data-bg="lavender"]   { --bg-chat: #dcd6f3; }
:root[data-bg="mint"]       { --bg-chat: #d4ecdd; }
:root[data-bg="peach"]      { --bg-chat: #f4dfd0; }
:root[data-bg="sky"]        { --bg-chat: #d3eaf7; }
:root[data-bg="dark"]       { --bg-chat: #1c2733; }
:root[data-bg="black"]      { --bg-chat: #000000; }
:root[data-bg="gradient1"]  { --bg-chat: #667eea; }
:root[data-bg="gradient2"]  { --bg-chat: #f093fb; }

/* Dark theme bg overrides */
[data-theme="dark"][data-bg="default"]   { --bg-chat: #0e1621; }
[data-theme="dark"][data-bg="lavender"]  { --bg-chat: #1a1729; }
[data-theme="dark"][data-bg="mint"]      { --bg-chat: #0f1f18; }
[data-theme="dark"][data-bg="peach"]     { --bg-chat: #2a1f15; }
[data-theme="dark"][data-bg="sky"]       { --bg-chat: #0f1a2a; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", "Segoe UI", Roboto, "Inter", system-ui, sans-serif;
  font-size: 15px;
  color: var(--text-primary);
  background: var(--bg-secondary);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button { font: inherit; cursor: pointer; border: 0; background: none; color: inherit; }
input, textarea { font: inherit; color: inherit; outline: none; }
.hidden { display: none !important; }

/* =========================================================
   AUTH SCREEN
   ========================================================= */
.auth-screen {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #1e3c72 0%, #2a5298 50%, #56a8f5 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}
.auth-card {
  background: var(--bg-primary);
  border-radius: 16px;
  padding: 40px 32px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.auth-logo { display: flex; justify-content: center; margin-bottom: 16px; }
.auth-logo-icon { width: 80px; height: 80px; border-radius: 18px; box-shadow: 0 4px 16px rgba(51,144,236,0.3); }
.empty-icon-big-img { width: 160px; height: 160px; opacity: 0.85; }

/* Profile actions row */
.profile-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.profile-actions .btn { flex: 1; min-width: 140px; }

/* Username row in edit form */
.username-row { display: flex; align-items: center; gap: 4px; position: relative; }
.username-row input { flex: 1; padding-left: 24px; }
.username-prefix { position: absolute; left: 12px; color: var(--text-muted); font-weight: 600; pointer-events: none; }
.username-status { font-size: 12px; padding: 0 8px; flex-shrink: 0; }
.username-status.ok { color: var(--accent); }
.username-status.taken { color: var(--danger, #e53935); }
.username-status.checking { color: var(--text-muted); }

/* User profile view modal */
.user-profile-view { display: flex; flex-direction: column; align-items: center; padding: 16px 0 8px; }
.upv-avatar {
  width: 100px; height: 100px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 36px; font-weight: 600;
  position: relative; margin-bottom: 12px;
}
.upv-avatar:has(img) { overflow: hidden; }
.upv-avatar img, .upv-avatar img.avatar-img {
  width: 100%; height: 100%; object-fit: cover; border-radius: 50%; display: block;
}
.upv-avatar.online::after {
  content: ''; position: absolute;
  bottom: 0; right: 0;
  transform: translate(50%, 50%);
  width: 24px; height: 24px; border-radius: 50%;
  background: #43a047;
  box-shadow: 0 0 0 4px var(--bg-modal, #fff);
  z-index: 5;
}
.upv-display-name { font-size: 22px; font-weight: 600; margin: 4px 0; color: var(--text-primary); }
.upv-username { color: var(--text-secondary); font-size: 14px; }
.upv-status { color: var(--text-muted); font-size: 13px; margin: 6px 0 12px; min-height: 18px; }
.upv-status.online { color: #43a047; }
.upv-bio { color: var(--text-secondary); font-size: 14px; text-align: center; max-width: 380px; margin-top: 8px; line-height: 1.4; }
.upv-actions { display: flex; gap: 8px; margin-top: 20px; flex-wrap: wrap; justify-content: center; }
.upv-actions .btn { min-width: 140px; }

/* Online dot on small chat-item avatar — полумесяцем вылезает за границу аватарки,
   поверх бордера */
.chat-item-avatar.online::before {
  content: ''; position: absolute;
  bottom: 0; right: 0;
  transform: translate(50%, 50%);
  width: 14px; height: 14px; border-radius: 50%;
  background: #43a047;
  box-shadow: 0 0 0 2.5px var(--bg-sidebar, #17212b);
  z-index: 5;
}
.chat-item-avatar.offline { /* nothing */ }

/* Settings label reuse */
.settings-label { display: block; font-size: 13px; font-weight: 500; color: var(--text-secondary); margin: 14px 0 6px; }
.modal-body textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg-input, var(--bg-tertiary)); color: var(--text-primary); font-size: 14px; resize: vertical; min-height: 60px; font-family: inherit; }
.modal-body textarea:focus { outline: none; border-color: var(--accent); }
.auth-card h1 { font-size: 28px; font-weight: 700; margin-bottom: 6px; color: var(--text-primary); }
.auth-subtitle { color: var(--text-secondary); margin-bottom: 28px; font-size: 14px; }
.auth-tabs { display: flex; background: var(--bg-tertiary); border-radius: 10px; padding: 4px; margin-bottom: 24px; }
.auth-tab {
  flex: 1; padding: 10px; border-radius: 8px; font-weight: 500; color: var(--text-secondary);
  transition: var(--transition);
}
.auth-tab.active { background: var(--bg-primary); color: var(--text-primary); box-shadow: var(--shadow-sm); }
.auth-form { display: none; flex-direction: column; gap: 12px; }
.auth-form.active { display: flex; }
.auth-form input {
  background: var(--bg-tertiary); border: 1.5px solid transparent; padding: 14px 16px;
  border-radius: 12px; font-size: 15px; transition: var(--transition);
}
.auth-form input:focus { border-color: var(--accent); background: var(--bg-primary); }
.auth-error { color: #e53935; font-size: 13px; min-height: 18px; }

/* =========================================================
   BUTTONS
   ========================================================= */
.btn {
  padding: 12px 20px; border-radius: 10px; font-weight: 500; font-size: 15px;
  transition: var(--transition); display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-tertiary); color: var(--text-primary); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: #e53935; color: white; }
.btn-danger:hover { background: #c62828; }
.btn-block { width: 100%; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-secondary); transition: var(--transition); flex-shrink: 0;
}
.icon-btn:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.icon-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* =========================================================
   APP LAYOUT
   ========================================================= */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  height: 100vh;
  background: var(--bg-primary);
}

/* SIDEBAR */
.sidebar {
  display: flex; flex-direction: column;
  background: var(--bg-primary);
  border-right: 1px solid var(--border);
  min-width: 0;
  position: relative;
}
.sidebar-header {
  height: var(--header-height);
  display: flex; align-items: center; gap: 8px;
  padding: 0 8px 0 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-title { flex: 1; font-weight: 600; font-size: 18px; color: var(--text-primary); display: flex; align-items: center; gap: 8px; }
.sidebar-title-icon { width: 28px; height: 28px; border-radius: 6px; flex-shrink: 0; }

.search-box {
  display: flex; align-items: center; gap: 8px;
  margin: 8px 12px;
  background: var(--bg-tertiary);
  border-radius: 22px;
  padding: 0 14px;
  height: 38px;
  color: var(--text-muted);
  flex-shrink: 0;
}
.search-box input { flex: 1; background: transparent; border: 0; font-size: 14px; }

.chat-tabs {
  display: flex; gap: 2px; padding: 4px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-tab {
  padding: 8px 14px; border-radius: 8px; font-size: 13px; font-weight: 500;
  color: var(--text-secondary); transition: var(--transition);
}
.chat-tab.active { background: var(--accent); color: white; }
.chat-tab:hover:not(.active) { background: var(--bg-tertiary); }

.chat-list { flex: 1; overflow-y: auto; padding: 4px 0; }
.chat-item {
  display: flex; gap: 12px; padding: 10px 14px 10px 12px; cursor: pointer;
  transition: background var(--transition); position: relative;
  border-bottom: 1px solid transparent;
}
.chat-item:hover { background: var(--bg-tertiary); }
.chat-item.active { background: var(--bg-tertiary); }
.chat-item-avatar {
  width: 52px; height: 52px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 18px; font-weight: 600; flex-shrink: 0;
  background: var(--accent); position: relative;
}
.chat-item-avatar:has(img) { overflow: hidden; }
.chat-item-avatar img.avatar-img,
.chat-item-avatar img {
  width: 100%; height: 100%; object-fit: cover; border-radius: 50%; display: block;
}
.chat-item-avatar.bot::after {
  content: "✓"; position: absolute; bottom: 0; right: 0;
  background: var(--accent); color: white; border-radius: 50%;
  width: 18px; height: 18px; display: flex; align-items: center; justify-content: center;
  font-size: 10px; border: 2px solid var(--bg-primary);
}
.chat-item-info { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; }
.chat-item-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.chat-item-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-primary); }
.chat-item-time { font-size: 12px; color: var(--text-muted); flex-shrink: 0; }
.chat-item-last { font-size: 13px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.chat-item-unread {
  background: var(--accent); color: white; border-radius: 12px;
  min-width: 22px; height: 22px; display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600; padding: 0 6px;
  align-self: center; flex-shrink: 0; margin-left: 4px;
}
.chat-item-unread.muted { background: var(--text-muted); }
/* When there's an unread badge, give the last text room to truncate before it */
.chat-item:has(.chat-item-unread) .chat-item-last {
  padding-right: 8px;
  max-width: calc(100% - 30px);
}

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 8px;
  flex-shrink: 0;
}
.footer-btn {
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 10px 12px; border-radius: 8px;
  color: var(--text-secondary); font-size: 14px; font-weight: 500;
  transition: var(--transition);
}
.footer-btn:hover { background: var(--bg-tertiary); color: var(--text-primary); }

/* =========================================================
   CHAT AREA
   ========================================================= */
.chat-area { display: flex; flex-direction: column; min-width: 0; background: var(--bg-chat); position: relative; }
.chat-empty {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--text-muted); text-align: center; padding: 20px;
}
.chat-empty h2 { margin-top: 20px; color: var(--text-secondary); font-weight: 500; }
.chat-empty p { color: var(--text-muted); font-size: 14px; }

.chat-active { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-header {
  height: var(--header-height); display: flex; align-items: center; gap: 8px;
  padding: 0 12px; background: var(--bg-primary); border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.chat-header-info { flex: 1; min-width: 0; cursor: pointer; display: flex; align-items: center; gap: 10px; }
.chat-header-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 14px; font-weight: 600; flex-shrink: 0;
  position: relative; background: var(--accent);
}
.chat-header-avatar:has(img) { overflow: hidden; }
.chat-header-avatar img, .chat-header-avatar img.avatar-img {
  width: 100%; height: 100%; object-fit: cover; border-radius: 50%; display: block;
}
.chat-header-avatar.online::after {
  content: ''; position: absolute;
  bottom: 0; right: 0;
  transform: translate(50%, 50%);
  width: 12px; height: 12px; border-radius: 50%;
  background: #43a047;
  box-shadow: 0 0 0 2.5px var(--bg-primary);
  z-index: 5;
}
.chat-header-text { flex: 1; min-width: 0; }
.chat-header-title { font-weight: 600; font-size: 15px; line-height: 1.2; }
.chat-header-sub { font-size: 12px; color: var(--text-secondary); }

.back-btn {
  display: inline-flex;
  transition: var(--transition);
}
.back-btn:hover {
  background: var(--bg-tertiary);
  transform: translateX(-2px);
}
.back-btn:active {
  transform: translateX(-4px);
}

/* MESSAGES */
.messages {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 0;
  position: relative;
  background:
    radial-gradient(circle at 20% 30%, var(--accent) 0%, transparent 40%),
    radial-gradient(circle at 80% 70%, var(--accent-light) 0%, transparent 40%),
    var(--bg-chat);
  background-blend-mode: overlay;
  background-size: 200% 200%;
}
[data-theme="dark"] .messages {
  background:
    radial-gradient(circle at 20% 30%, #1c2a3d 0%, transparent 40%),
    radial-gradient(circle at 80% 70%, #1c2a3d 0%, transparent 40%),
    var(--bg-chat);
  background-blend-mode: normal;
}
.messages-inner { display: flex; flex-direction: column; gap: 4px; max-width: 800px; margin: 0 auto; padding: 8px 6px; }

.message {
  display: block;
  position: relative;
  max-width: 78%;
  padding-left: 0;
  animation: messageIn 0.2s ease;
}
.message.out { margin-left: auto; padding-left: 0; margin-right: 0; }
.message:not(.out) { margin-right: auto; margin-left: 0; }
.message .user-row-avatar { display: none; }
.message .bubble { display: block; width: 100%; max-width: 100%; box-sizing: border-box; }
@keyframes messageIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.bubble {
  background: var(--bubble-in);
  color: var(--bubble-in-text);
  padding: 6px 10px 5px;
  border-radius: 14px 14px 14px 4px;
  box-shadow: var(--shadow-sm);
  position: relative;
  word-wrap: break-word;
  overflow-wrap: break-word;
  border: 1px solid var(--border);
}
.message.out .bubble {
  background: var(--bubble-out);
  color: var(--bubble-out-text);
  border-radius: 14px 14px 4px 14px;
  border-color: transparent;
  overflow: hidden;
}
.message.bot .bubble {
  background: var(--bubble-bot);
  border-color: var(--bubble-bot-border);
  border-radius: 14px;
}
.bubble-sender { font-size: 12px; font-weight: 600; margin-bottom: 2px; color: var(--accent); }
.bubble-text { white-space: pre-wrap; line-height: 1.4; font-size: 15px; overflow-wrap: break-word; }
.bubble-meta { display: flex; align-items: center; justify-content: flex-end; gap: 4px; margin-top: 2px; }
.bubble-time { font-size: 11px; color: var(--text-muted); }
.bubble-edited { font-size: 11px; color: var(--text-muted); }
.bubble-checks { font-size: 14px; line-height: 1; color: var(--text-muted); font-weight: 700; }
.bubble-checks.read { color: #4fa6e4; }

.attachment-img-wrap {
  position: relative;
  display: block;
  max-width: 320px;
  min-width: 120px;
  min-height: 120px;
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg-tertiary);
}
.attachment-skeleton {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    var(--bg-tertiary) 0%,
    var(--border) 50%,
    var(--bg-tertiary) 100%
  );
  background-size: 200% 100%;
  animation: skeletonShimmer 1.5s ease-in-out infinite;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 13px;
  border-radius: 12px;
}
.attachment-skeleton.error {
  background: rgba(229, 57, 53, 0.1);
  color: #e53935;
  animation: none;
}
@keyframes skeletonShimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.attachment-img {
  display: block;
  max-width: 320px;
  max-height: 320px;
  width: auto;
  height: auto;
  border-radius: 12px;
  cursor: pointer;
  transition: opacity 0.3s ease, transform 0.15s ease;
  object-fit: contain;
}
.attachment-img.loading { opacity: 0; }
.attachment-img:hover { transform: scale(1.02); }

/* Lightbox */
.lightbox {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.92);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
  cursor: zoom-out;
  animation: fadeIn 0.2s ease;
  padding: 20px;
}
.lightbox img {
  max-width: 100%; max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  animation: lightboxIn 0.2s ease;
  cursor: default;
}
@keyframes lightboxIn {
  from { transform: scale(0.9); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.lightbox-close {
  position: absolute; top: 20px; right: 20px;
  width: 44px; height: 44px;
  background: rgba(255, 255, 255, 0.15);
  color: white;
  border-radius: 50%;
  font-size: 24px;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(10px);
  transition: var(--transition);
}
.lightbox-close:hover { background: rgba(255, 255, 255, 0.3); transform: rotate(90deg); }
.attachment-file {
  display: flex; align-items: center; gap: 10px;
  background: rgba(0,0,0,0.05); padding: 10px;
  border-radius: 10px; min-width: 200px; text-decoration: none; color: inherit;
}
.attachment-file-icon {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--accent); color: white;
  display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0;
}
.attachment-file-info { display: flex; flex-direction: column; min-width: 0; }
.attachment-file-name { font-weight: 500; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.attachment-file-size { font-size: 12px; color: var(--text-muted); }

.reply-quote {
  display: flex; gap: 8px; padding: 4px 0 6px;
  border-left: 3px solid var(--accent); padding-left: 8px;
  margin-bottom: 4px; opacity: 0.9;
}
.reply-quote-sender { font-size: 12px; font-weight: 600; color: var(--accent); }
.reply-quote-text { font-size: 13px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }

.message-group { display: block; margin: 3px 0; }
.message-group + .message-group { margin-top: 6px; }
.message-group .message { max-width: 70%; margin-top: 2px; }
.message-group.in  .message:not(.out) { margin-right: auto; }
.message-group.out .message { margin-left: auto; }
.message-group .message .bubble { border-radius: 14px 14px 14px 4px; }
.message-group.out .message .bubble { border-radius: 14px 14px 4px 14px; }
.message-group .message.continuation .bubble { border-radius: 12px 12px 12px 4px; }
.message-group.out .message.continuation .bubble { border-radius: 12px 12px 4px 12px; }

.message-group.in  .message.continuation:not(:last-child) .bubble { border-bottom-left-radius: 12px; }
.message-group.out .message.continuation:not(:last-child) .bubble { border-bottom-right-radius: 12px; }

.message-group.in  .message:last-child:not(.continuation) .bubble { border-bottom-left-radius: 12px; }
.message-group.out .message:last-child:not(.continuation) .bubble { border-bottom-right-radius: 12px; }

.message-day { text-align: center; margin: 12px 0; }
.message-day span {
  background: rgba(0,0,0,0.4); color: white; padding: 4px 12px; border-radius: 12px;
  font-size: 12px; font-weight: 500;
}

.typing-indicator {
  padding: 4px 16px; font-size: 13px; color: var(--text-secondary); font-style: italic;
  min-height: 20px; max-width: 800px; margin: 0 auto;
}

/* COMPOSER */
.composer {
  display: flex; gap: 6px; align-items: flex-end;
  padding: 8px 12px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  background: var(--bg-primary);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;   /* anchor for .rec-overlay (position: absolute) */
}
.composer-input-wrap {
  flex: 1; display: flex; align-items: center; gap: 4px;
  background: var(--bg-tertiary);
  border-radius: 20px;
  padding: 4px 6px 4px 12px;
  min-height: 36px;
}
.composer-input-wrap:focus-within { background: var(--bg-primary); border: 1.5px solid var(--accent); padding: 2.5px 4.5px 2.5px 10.5px; }
#messageInput {
  flex: 1; background: transparent; border: 0; resize: none;
  max-height: 120px; padding: 4px 4px; font-size: 15px; line-height: 1.4;
  text-align: left;
}
#messageInput::placeholder { text-align: left; }
.emoji-btn, .send-btn { color: var(--text-secondary); }
.send-btn { color: var(--accent); }
.mic-btn {
  color: var(--accent);
  background: var(--bg-tertiary);
  touch-action: manipulation;   /* don't delay taps on mobile */
  -webkit-tap-highlight-color: transparent;
  position: relative;
  transition: background 0.15s, transform 0.12s;
}
.mic-btn:hover { background: var(--accent); color: #fff; }
.mic-btn:active {
  background: #e53935;
  color: #fff;
  transform: scale(0.88);
  box-shadow: 0 0 0 6px rgba(229, 57, 53, 0.25);
}
.mic-btn.recording {
  color: #e53935;
  background: rgba(229, 57, 53, 0.12);
  animation: micPulse 1.2s ease-in-out infinite;
}
@keyframes micPulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(229, 57, 53, 0.5); }
  50%      { transform: scale(1.12); box-shadow: 0 0 0 10px rgba(229, 57, 53, 0); }
}

/* RECORDING OVERLAY — strip above the composer, visible while recording */
.rec-overlay {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: 56px;
  background: var(--bg-primary);
  border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  z-index: 10;
  user-select: none;
}
.rec-overlay.hidden { display: none; }
.rec-overlay .rec-center {
  display: flex; align-items: center; gap: 12px;
  color: #e53935; font-weight: 600; font-size: 18px;
  font-variant-numeric: tabular-nums;
}
.rec-overlay .rec-pulse {
  width: 12px; height: 12px; border-radius: 50%;
  background: #e53935;
  box-shadow: 0 0 0 0 rgba(229, 57, 53, 0.6);
  animation: recPulse 1.4s ease-in-out infinite;
}
@keyframes recPulse {
  0%   { box-shadow: 0 0 0 0   rgba(229, 57, 53, 0.6); }
  70%  { box-shadow: 0 0 0 12px rgba(229, 57, 53, 0); }
  100% { box-shadow: 0 0 0 0   rgba(229, 57, 53, 0); }
}
.rec-overlay .rec-actions {
  position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
  display: flex; gap: 8px;
}
.rec-overlay .rec-cancel-btn,
.rec-overlay .rec-send-btn {
  width: 44px; height: 44px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  border: 0; cursor: pointer;
  transition: transform 0.15s;
}
.rec-overlay .rec-cancel-btn { background: var(--bg-tertiary); color: var(--text-secondary); }
.rec-overlay .rec-send-btn   { background: var(--accent); color: #fff; box-shadow: 0 2px 6px rgba(0,0,0,0.3); }
.rec-overlay .rec-cancel-btn:active { transform: scale(0.92); }
.rec-overlay .rec-send-btn:active   { transform: scale(0.92); }
.emoji-picker {
  position: fixed; bottom: 80px; right: 20px;
  background: var(--bg-primary); border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  width: 340px; max-width: calc(100vw - 24px);
  overflow: hidden;
  display: flex; flex-direction: column;
  z-index: 100;
}
.emoji-picker.hidden { display: none; }
.emoji-picker span { font-size: 22px; cursor: pointer; padding: 4px; border-radius: 6px; text-align: center; }
.emoji-picker span:hover { background: var(--bg-tertiary); }

.attachment-preview {
  position: absolute; bottom: 80px; left: 20px;
  background: var(--bg-primary); border: 1px solid var(--border);
  border-radius: 12px; padding: 8px;
  box-shadow: var(--shadow-md);
  display: flex; align-items: center; gap: 10px;
  max-width: 400px;
}
.attachment-preview img { max-width: 80px; max-height: 60px; border-radius: 8px; }
.attachment-preview .file-info { font-size: 13px; }
.attachment-preview button { color: var(--text-muted); }

/* =========================================================
   MODAL
   ========================================================= */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  z-index: 1000;
  animation: fadeIn 0.15s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--bg-primary); border-radius: 14px; width: 100%; max-width: 480px;
  max-height: calc(100vh - 40px); display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg); animation: scaleIn 0.15s ease;
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  margin: 0;
}
@keyframes scaleIn { from { transform: scale(0.95); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.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: 18px; font-weight: 600; }
.modal-tabs { display: flex; padding: 0 20px; border-bottom: 1px solid var(--border); }
.modal-tab {
  padding: 12px 8px; font-size: 14px; color: var(--text-secondary); font-weight: 500;
  border-bottom: 2px solid transparent; transition: var(--transition);
}
.modal-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-pane { display: none; flex-direction: column; gap: 12px; }
.modal-pane.active { display: flex; }
.modal-body input[type="text"] {
  width: 100%; padding: 12px 14px;
  background: var(--bg-tertiary); border: 1.5px solid transparent;
  border-radius: 10px; font-size: 14px;
  transition: var(--transition);
}
.modal-body input:focus { border-color: var(--accent); background: var(--bg-primary); }
.modal-body h4 { font-size: 14px; color: var(--text-secondary); font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; margin: 8px 0 4px; }
.hint { font-size: 12px; color: var(--text-muted); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* USER LIST */
.user-list { display: flex; flex-direction: column; gap: 4px; max-height: 320px; overflow-y: auto; }
.user-row {
  display: flex; gap: 12px; align-items: center; padding: 10px; border-radius: 10px;
  cursor: pointer; transition: var(--transition);
}
.user-row:hover { background: var(--bg-tertiary); }
.user-row.selected { background: var(--accent); color: white; }
.user-row.selected .user-row-name, .user-row.selected .user-row-username { color: white; }
.user-row-avatar {
  width: 44px; height: 44px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 16px; font-weight: 600; flex-shrink: 0;
  position: relative;
}
.user-row-avatar.bot::after {
  content: "✓"; position: absolute; bottom: -2px; right: -2px;
  background: var(--accent); color: white; border-radius: 50%;
  width: 16px; height: 16px; display: flex; align-items: center; justify-content: center;
  font-size: 9px; border: 2px solid var(--bg-primary);
}
.user-row-info { flex: 1; min-width: 0; }
.user-row-name { font-weight: 500; font-size: 14px; }
.user-row-username { font-size: 12px; color: var(--text-secondary); }
.user-row-status { font-size: 12px; color: var(--text-muted); }

.selected-users { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.selected-user-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent); color: white; padding: 4px 10px;
  border-radius: 14px; font-size: 12px;
}
.selected-user-chip button { color: white; font-size: 14px; line-height: 1; }

.bot-command-row { display: flex; gap: 6px; align-items: center; }
.bot-command-row input { flex: 1; }
.bot-command-row button { color: var(--text-muted); font-size: 16px; }

.settings-section { margin-bottom: 24px; }
.settings-section h4 { font-size: 13px; color: var(--text-secondary); font-weight: 600; text-transform: uppercase; margin-bottom: 8px; }
.settings-label { display: block; font-size: 12px; color: var(--text-secondary); font-weight: 500; margin: 12px 0 6px; }
.theme-picker { display: flex; gap: 8px; }
.theme-swatch {
  flex: 1; height: 56px; border-radius: 10px;
  border: 2px solid var(--border);
  font-size: 24px;
  transition: var(--transition);
  position: relative;
  display: flex; align-items: center; justify-content: center;
}
.theme-swatch.theme-light { background: linear-gradient(135deg, #fff 0%, #e8eaed 100%); }
.theme-swatch.theme-dark { background: linear-gradient(135deg, #2b3a4f 0%, #0e1621 100%); }
.theme-swatch.active { border-color: var(--accent); transform: scale(1.05); }
.theme-swatch.active::after {
  content: '✓'; position: absolute; top: 4px; right: 8px;
  color: var(--accent); font-weight: bold; font-size: 16px;
}
.color-picker { display: flex; flex-wrap: wrap; gap: 10px; }
.color-dot, .bubble-dot {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
}
.color-dot:hover, .bubble-dot:hover { transform: scale(1.15); }
.color-dot.active, .bubble-dot.active {
  border-color: var(--text-primary);
  box-shadow: 0 0 0 2px var(--bg-primary), 0 0 0 4px var(--accent);
}
.bubble-dot { border: 2px solid var(--border); }
.bubble-dot.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--bg-primary), 0 0 0 4px var(--accent); }
.bg-picker { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.bg-swatch {
  aspect-ratio: 1;
  border-radius: 10px;
  border: 2px solid var(--border);
  cursor: pointer;
  transition: var(--transition);
  position: relative;
}
.bg-swatch:hover { transform: scale(1.05); }
.bg-swatch.active { border-color: var(--accent); transform: scale(1.05); }
.bg-swatch.active::after {
  content: '✓'; position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 18px; font-weight: bold;
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}
.volume-slider {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--bg-tertiary);
  appearance: none;
  -webkit-appearance: none;
  outline: none;
  margin: 8px 0;
}
.volume-slider::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 3px solid var(--bg-primary);
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}
.volume-slider::-moz-range-thumb {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 3px solid var(--bg-primary);
}
.profile-card { display: flex; gap: 12px; align-items: center; padding: 12px; background: var(--bg-tertiary); border-radius: 10px; margin-bottom: 8px; }
.profile-card-avatar {
  width: 48px; height: 48px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 16px; font-weight: 600; flex-shrink: 0;
  position: relative;
}
.profile-card-avatar:has(img) { overflow: hidden; }
.profile-card-avatar img, .profile-card-avatar img.avatar-img {
  width: 100%; height: 100%; object-fit: cover; border-radius: 50%; display: block;
}
.profile-card-info { flex: 1; min-width: 0; }
.profile-card-name { font-weight: 600; font-size: 15px; }
.profile-card-username { font-size: 13px; color: var(--text-secondary); }
.profile-card-bio { font-size: 12px; color: var(--text-muted); margin-top: 4px; line-height: 1.3; }

/* Online dot indicator on profile-card avatar — вылезает за границу полумесяцем */
.profile-card-avatar.online::after {
  content: ''; position: absolute;
  bottom: 0; right: 0;
  transform: translate(50%, 50%);
  width: 14px; height: 14px; border-radius: 50%;
  background: #43a047;
  box-shadow: 0 0 0 2.5px var(--bg-tertiary);
  z-index: 5;
}
.profile-card-avatar { position: relative; }
.bot-list { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.theme-toggle { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 8px 0; }
.theme-toggle input { width: 18px; height: 18px; accent-color: var(--accent); }

/* CONTEXT MENU */
.context-menu {
  position: fixed; background: var(--bg-primary); border: 1px solid var(--border);
  border-radius: 10px; padding: 6px; min-width: 180px;
  box-shadow: var(--shadow-lg); z-index: 2000;
}
.context-menu button {
  display: block; width: 100%; text-align: left;
  padding: 8px 12px; border-radius: 6px; font-size: 14px; color: var(--text-primary);
}
.context-menu button:hover { background: var(--bg-tertiary); }
.context-menu button.danger { color: #e53935; }

/* TOASTS */
.toasts {
  position: fixed; bottom: 24px; right: 24px; z-index: 3000;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--bg-primary); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 16px;
  box-shadow: var(--shadow-lg); min-width: 240px;
  display: flex; align-items: center; gap: 10px;
  animation: toastIn 0.2s ease;
}
@keyframes toastIn { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
.toast.success { border-left: 4px solid #43a047; }
.toast.error { border-left: 4px solid #e53935; }
.toast.info { border-left: 4px solid var(--accent); }

/* EMPTY STATE */
.empty-state { padding: 40px 20px; text-align: center; color: var(--text-muted); }
.empty-state.small { padding: 20px; }
.empty-icon { font-size: 48px; margin-bottom: 12px; }

/* PULL-TO-REFRESH */
.ptr-indicator {
  position: fixed;
  top: -80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow-md);
  z-index: 6000;
  transition: top 0.25s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s;
  opacity: 0;
  pointer-events: none;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
}
.ptr-indicator.pulling { top: 16px; opacity: 1; }
.ptr-indicator.refreshing .ptr-spinner { animation: spin 0.8s linear infinite; }
.ptr-indicator.refreshing .ptr-text::before { content: 'Обновление...'; }
.ptr-indicator.refreshing .ptr-text { font-size: 0; }
.ptr-indicator.refreshing .ptr-text::before { font-size: 13px; }
.ptr-spinner {
  width: 18px; height: 18px;
  border: 2.5px solid var(--bg-tertiary);
  border-top-color: var(--accent);
  border-radius: 50%;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* PWA INSTALL BANNER */
.pwa-install {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 16px;
  display: flex; align-items: center; gap: 12px;
  box-shadow: var(--shadow-lg);
  z-index: 50;
  max-width: 480px;
  width: calc(100% - 32px);
  animation: slideUp 0.3s ease;
}
@keyframes slideUp {
  from { transform: translate(-50%, 20px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}
.pwa-install-icon { font-size: 32px; flex-shrink: 0; }
.pwa-install-text { flex: 1; display: flex; flex-direction: column; }
.pwa-install-text strong { font-size: 14px; font-weight: 600; }
.pwa-install-text span { font-size: 12px; color: var(--text-secondary); }
.pwa-install .btn { padding: 8px 14px; font-size: 13px; }
@media (max-width: 480px) {
  .pwa-install { padding: 10px 12px; gap: 8px; }
  .pwa-install-text span { display: none; }
}

/* 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); }

/* MOBILE */
@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0; z-index: 10; width: 100vw; }
  .sidebar.hidden { display: none; }
  .chat-area { width: 100vw; }
  .back-btn { display: inline-flex !important; }
  :root { --sidebar-width: 100vw; }
  .message { max-width: 90%; }
  .messages { padding: 12px; }
  .emoji-picker { right: 10px; left: 10px; max-width: none; }
}

/* ===== Customization Indicator (Telegram-style "Обновление..." overlay) ===== */
.customization-indicator {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%) translateY(-30px);
  background: var(--accent);
  color: #fff;
  padding: 8px 18px;
  border-radius: 22px;
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 10000;
}
.customization-indicator.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.customization-indicator.done {
  background: #43a047;
}
.customization-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: customization-spin 0.8s linear infinite;
  display: inline-block;
}
.customization-check {
  font-size: 16px;
  font-weight: 700;
  display: inline-block;
  animation: customization-pop 0.25s ease;
}
@keyframes customization-spin {
  to { transform: rotate(360deg); }
}
@keyframes customization-pop {
  0% { transform: scale(0.5); opacity: 0; }
  60% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* ===== Picker tabs (emoji / stickers) ===== */
.picker-tabs {
  display: flex; gap: 4px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-tertiary);
}
.picker-tab {
  flex: 1;
  background: transparent; border: 0;
  padding: 6px 8px; border-radius: 8px;
  font-size: 13px; color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
}
.picker-tab:hover { background: var(--bg-primary); }
.picker-tab.active {
  background: var(--accent);
  color: #fff;
}
.emoji-grid, .sticker-grid {
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px;
  padding: 8px; max-height: 240px; overflow-y: auto;
}
.emoji-grid span, .sticker-item {
  font-size: 22px; cursor: pointer; padding: 4px; border-radius: 6px;
  text-align: center; transition: var(--transition);
}
.emoji-grid span:hover, .sticker-item:hover { background: var(--bg-tertiary); }
.sticker-grid { grid-template-columns: repeat(6, 1fr); }
.sticker-item { font-size: 28px; }
.sticker-pack-bar {
  display: flex; gap: 2px;
  padding: 6px 8px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.sticker-pack-tab {
  background: transparent; border: 0;
  font-size: 22px; padding: 4px 8px; border-radius: 8px;
  cursor: pointer; flex-shrink: 0;
  opacity: 0.55;
  transition: var(--transition);
}
.sticker-pack-tab:hover { opacity: 1; background: var(--bg-tertiary); }
.sticker-pack-tab.active { opacity: 1; background: var(--accent-light, var(--bg-tertiary)); }

/* ===== Push notification status ===== */
.push-status {
  font-size: 13px; color: var(--text-secondary);
  margin-top: 6px;
}
.push-status.subscribed { color: #43a047; }
.push-status.denied { color: #e53935; }
.settings-help {
  font-size: 12px; color: var(--text-muted);
  margin: 4px 0 8px; line-height: 1.4;
}

/* ===== Voice / audio player (Telegram-style) ===== */
.voice-player {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 2px 6px;
  min-width: 220px; max-width: 100%;
  width: 100%;
  box-sizing: border-box;
  font-variant-numeric: tabular-nums;
}
.voice-note-icon { display: none; }
.voice-play-btn {
  width: 42px; height: 42px; border-radius: 50%;
  border: none; cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.95);
  color: #5b8cc7;
  transition: transform 0.15s, background 0.2s;
  padding: 0;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
.voice-play-btn:hover { transform: scale(1.06); background: #fff; }
.voice-play-btn:active { transform: scale(0.94); }
.voice-play-btn svg { width: 20px; height: 20px; display: block; }
.voice-play-btn .icon-pause { display: none; }
.voice-play-btn.playing .icon-play { display: none; }
.voice-play-btn.playing .icon-pause { display: block; }

.voice-progress {
  flex: 1; min-width: 80px;
  display: flex; flex-direction: column; gap: 4px;
  cursor: pointer;
}
.voice-waveform {
  height: 28px; position: relative; overflow: hidden;
  display: flex; align-items: center;
}
.voice-waveform-bar {
  flex: 1; height: 100%; position: relative;
  background: linear-gradient(to right,
    currentColor 0%, currentColor var(--prog, 0%),
    rgba(255,255,255,0.35) var(--prog, 0%), rgba(255,255,255,0.35) 100%);
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' preserveAspectRatio='none' viewBox='0 0 100 28'><g fill='black'><rect x='1'  y='12' width='2' height='4'/><rect x='4'  y='10' width='2' height='8'/><rect x='7'  y='6'  width='2' height='16'/><rect x='10' y='9'  width='2' height='10'/><rect x='13' y='4'  width='2' height='20'/><rect x='16' y='8'  width='2' height='12'/><rect x='19' y='11' width='2' height='6'/><rect x='22' y='7'  width='2' height='14'/><rect x='25' y='2'  width='2' height='24'/><rect x='28' y='8'  width='2' height='12'/><rect x='31' y='12' width='2' height='4'/><rect x='34' y='9'  width='2' height='10'/><rect x='37' y='5'  width='2' height='18'/><rect x='40' y='10' width='2' height='8'/><rect x='43' y='3'  width='2' height='22'/><rect x='46' y='9'  width='2' height='10'/><rect x='49' y='12' width='2' height='4'/><rect x='52' y='7'  width='2' height='14'/><rect x='55' y='4'  width='2' height='20'/><rect x='58' y='10' width='2' height='8'/><rect x='61' y='2'  width='2' height='24'/><rect x='64' y='9'  width='2' height='10'/><rect x='67' y='6'  width='2' height='16'/><rect x='70' y='11' width='2' height='6'/><rect x='73' y='8'  width='2' height='12'/><rect x='76' y='3'  width='2' height='22'/><rect x='79' y='9'  width='2' height='10'/><rect x='82' y='5'  width='2' height='18'/><rect x='85' y='11' width='2' height='6'/><rect x='88' y='7'  width='2' height='14'/><rect x='91' y='10' width='2' height='8'/><rect x='94' y='4'  width='2' height='20'/><rect x='97' y='12' width='2' height='4'/></g></svg>") center/100% 100% no-repeat;
          mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' preserveAspectRatio='none' viewBox='0 0 100 28'><g fill='black'><rect x='1'  y='12' width='2' height='4'/><rect x='4'  y='10' width='2' height='8'/><rect x='7'  y='6'  width='2' height='16'/><rect x='10' y='9'  width='2' height='10'/><rect x='13' y='4'  width='2' height='20'/><rect x='16' y='8'  width='2' height='12'/><rect x='19' y='11' width='2' height='6'/><rect x='22' y='7'  width='2' height='14'/><rect x='25' y='2'  width='2' height='24'/><rect x='28' y='8'  width='2' height='12'/><rect x='31' y='12' width='2' height='4'/><rect x='34' y='9'  width='2' height='10'/><rect x='37' y='5'  width='2' height='18'/><rect x='40' y='10' width='2' height='8'/><rect x='43' y='3'  width='2' height='22'/><rect x='46' y='9'  width='2' height='10'/><rect x='49' y='12' width='2' height='4'/><rect x='52' y='7'  width='2' height='14'/><rect x='55' y='4'  width='2' height='20'/><rect x='58' y='10' width='2' height='8'/><rect x='61' y='2'  width='2' height='24'/><rect x='64' y='9'  width='2' height='10'/><rect x='67' y='6'  width='2' height='16'/><rect x='70' y='11' width='2' height='6'/><rect x='73' y='8'  width='2' height='12'/><rect x='76' y='3'  width='2' height='22'/><rect x='79' y='9'  width='2' height='10'/><rect x='82' y='5'  width='2' height='18'/><rect x='85' y='11' width='2' height='6'/><rect x='88' y='7'  width='2' height='14'/><rect x='91' y='10' width='2' height='8'/><rect x='94' y='4'  width='2' height='20'/><rect x='97' y='12' width='2' height='4'/></g></svg>") center/100% 100% no-repeat;
  color: rgba(255,255,255,0.9);
  transition: background 0.05s linear;
}
.voice-play-btn.playing + .voice-progress .voice-waveform-bar,
.voice-progress.playing .voice-waveform-bar {
  /* live color shift handled via currentColor on the bar itself */
}
.voice-times {
  display: flex; justify-content: space-between;
  font-size: 11px; opacity: 0.75; letter-spacing: 0.2px;
}

/* Incoming (light) bubbles — override progress color */
.bubble:not(.out) .voice-play-btn {
  background: #5b8cc7; color: #fff;
}
.bubble:not(.out) .voice-play-btn:hover { background: #4d7eb8; }
.bubble:not(.out) .voice-waveform-bar {
  color: #5b8cc7;
  background: linear-gradient(to right,
    #5b8cc7 0%, #5b8cc7 var(--prog, 0%),
    rgba(0,0,0,0.18) var(--prog, 0%), rgba(0,0,0,0.18) 100%);
}
.bubble:not(.out) .voice-times { color: #5a6b7d; }

/* Speed button */
.voice-speed {
  width: 28px; height: 28px; border-radius: 50%;
  border: none; cursor: pointer; flex-shrink: 0;
  background: rgba(255,255,255,0.18);
  color: inherit;
  font-size: 10px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  padding: 0;
  transition: background 0.2s;
}
.voice-speed:hover { background: rgba(255,255,255,0.3); }
.bubble:not(.out) .voice-speed {
  background: rgba(0,0,0,0.08);
}
.bubble:not(.out) .voice-speed:hover { background: rgba(0,0,0,0.15); }

/* Fallback: hide the native <audio> tag — we drive it via JS */
.attachment-audio-native { display: none; }

/* ===== Document / generic file card ===== */
.attachment-doc {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 12px;
  min-width: 220px;
  color: inherit;
  text-decoration: none;
}
.attachment-doc:hover { background: rgba(255,255,255,0.2); }
.attachment-doc .doc-icon {
  font-size: 32px; flex-shrink: 0;
}
.attachment-doc .doc-name {
  font-weight: 500; font-size: 14px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 180px;
}
.attachment-doc .doc-size {
  font-size: 12px; opacity: 0.75; margin-top: 2px;
}

/* ===== Video ===== */
.attachment-video {
  max-width: 100%; max-height: 360px; border-radius: 12px; display: block;
}

/* ===== Sticker bubble ===== */
.sticker-bubble {
  font-size: 96px;
  text-align: center;
  padding: 8px;
  line-height: 1;
}
.message .bubble:has(.sticker-bubble) {
  background: transparent !important;
  border: 0 !important;
  padding: 0 !important;
  box-shadow: none !important;
}

/* ===== Message send animation ===== */
.message { animation: msgIn 0.22s cubic-bezier(0.2, 0.8, 0.2, 1); }
@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.message.outgoing { animation-name: msgOut; }
@keyframes msgOut {
  from { opacity: 0; transform: translateY(8px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ===== Chat list tab switch fade ===== */
.chat-list { transition: opacity 0.18s ease; }
.chat-list.fading { opacity: 0; }

/* ===== Edit profile avatar row ===== */
.avatar-edit-row { display: flex; align-items: center; gap: 16px; margin-bottom: 14px; }
.edit-avatar {
  width: 80px; height: 80px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 600; font-size: 28px;
  overflow: hidden; flex-shrink: 0;
}
.avatar-edit-actions { display: flex; flex-direction: column; gap: 6px; }
.avatar-edit-actions .btn { font-size: 13px; padding: 6px 12px; }

/* Sub-modal: opens on top of another modal (e.g. edit-profile over settings) */
.modal.sub-modal { box-shadow: 0 16px 48px rgba(0,0,0,0.6); }

/* Универсально: любая картинка аватарки — круглая, обрезанная по центру */
img.avatar-img {
  width: 100%; height: 100%; object-fit: cover; border-radius: 50%; display: block;
}

/* Floating Action Button — обновить чаты */
.fab-refresh {
  position: absolute;
  right: 16px;
  bottom: 18px;
  width: 48px; height: 48px;
  border-radius: 50%;
  background: var(--accent, #5e81f4);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  border: none;
  box-shadow: 0 4px 14px rgba(0,0,0,0.35), 0 0 0 1px rgba(255,255,255,0.06) inset;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
  z-index: 5;
}
.fab-refresh:hover { transform: translateY(-1px); background: var(--accent-hover, #6f8ff5); }
.fab-refresh:active { transform: translateY(0) scale(0.96); }
.fab-refresh.spinning svg { animation: fab-spin 0.8s linear infinite; }
@keyframes fab-spin { from { transform: rotate(0); } to { transform: rotate(360deg); } }

/* Floating Action Button — настройки (нижний левый угол) */
.fab-settings {
  position: absolute;
  left: 16px;
  bottom: 18px;
  width: 48px; height: 48px;
  border-radius: 50%;
  background: var(--bg-tertiary, #2a2f3a);
  color: var(--text-primary, #fff);
  display: flex; align-items: center; justify-content: center;
  border: none;
  box-shadow: 0 4px 14px rgba(0,0,0,0.35), 0 0 0 1px rgba(255,255,255,0.06) inset;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
  z-index: 5;
}
.fab-settings:hover { transform: translateY(-1px) rotate(45deg); background: var(--accent, #5e81f4); color: #fff; }
.fab-settings:active { transform: translateY(0) scale(0.96) rotate(45deg); }
