@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap');

/* ===== Дизайн-токены (палитра "Chat & Messaging App" + подобранная тёмная тема) ===== */
:root {
  color-scheme: light;

  --bg: #f1f5fd;
  --card-bg: #ffffff;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e4ecfc;
  --shadow: rgba(15, 23, 42, 0.06);
  --shadow-strong: rgba(15, 23, 42, 0.14);

  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft-bg: #e4ecfc;
  --on-accent: #ffffff;

  --secondary: #6366f1;

  --success: #059669;
  --online-dot: #059669;

  --danger: #dc2626;
  --danger-hover: #b91c1c;

  --secondary-bg: #eef1f8;
  --secondary-bg-hover: #e2e6f0;
  --secondary-text: #0f172a;

  --input-bg: #ffffff;
  --input-border: #d7e0f5;

  --error-bg: #fdecea;
  --error-text: #b91c1c;

  --msg-bg: #ffffff;
  --msg-border: #e4ecfc;
  --msg-me-bg: #2563eb;
  --msg-me-text: #eaf0ff;

  --hover-bg: #eef3fd;

  --organizer-border: #2563eb;
  --organizer-bg: #eef3fd;
  --invited-border: #d97706;
  --invited-bg: #fff8ec;
}

:root[data-theme='dark'] {
  color-scheme: dark;

  --bg: #0b1220;
  --card-bg: #131b2e;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --border: #26324a;
  --shadow: rgba(0, 0, 0, 0.35);
  --shadow-strong: rgba(0, 0, 0, 0.5);

  --accent: #3b82f6;
  --accent-hover: #60a5fa;
  --accent-soft-bg: #1e293b;
  --on-accent: #ffffff;

  --secondary: #818cf8;

  --success: #10b981;
  --online-dot: #10b981;

  --danger: #ef4444;
  --danger-hover: #f87171;

  --secondary-bg: #1c2536;
  --secondary-bg-hover: #26314a;
  --secondary-text: #e2e8f0;

  --input-bg: #0f172a;
  --input-border: #2a3752;

  --error-bg: #3a2224;
  --error-text: #ff8b81;

  --msg-bg: #1b2436;
  --msg-border: #263049;
  --msg-me-bg: #2563eb;
  --msg-me-text: #eaf0ff;

  --hover-bg: #1c2536;

  --organizer-border: #3b82f6;
  --organizer-bg: #16203a;
  --invited-border: #d97706;
  --invited-bg: #2a2013;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --bg: #0b1220;
    --card-bg: #131b2e;
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --border: #26324a;
    --shadow: rgba(0, 0, 0, 0.35);
    --shadow-strong: rgba(0, 0, 0, 0.5);
    --accent: #3b82f6;
    --accent-hover: #60a5fa;
    --accent-soft-bg: #1e293b;
    --secondary: #818cf8;
    --success: #10b981;
    --online-dot: #10b981;
    --danger: #ef4444;
    --danger-hover: #f87171;
    --secondary-bg: #1c2536;
    --secondary-bg-hover: #26314a;
    --secondary-text: #e2e8f0;
    --input-bg: #0f172a;
    --input-border: #2a3752;
    --error-bg: #3a2224;
    --error-text: #ff8b81;
    --msg-bg: #1b2436;
    --msg-border: #263049;
    --msg-me-bg: #2563eb;
    --msg-me-text: #eaf0ff;
    --hover-bg: #1c2536;
    --organizer-border: #3b82f6;
    --organizer-bg: #16203a;
    --invited-border: #d97706;
    --invited-bg: #2a2013;
  }
}

/* ===== Сброс и база ===== */
* {
  box-sizing: border-box;
  scrollbar-color: var(--text-muted) transparent;
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

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

::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: 4px;
}

html,
body {
  margin: 0;
  padding: 0;
}

/* Мобильные браузеры (в первую очередь WebKit) по умолчанию показывают при тапе
   полупрозрачный ПРЯМОУГОЛЬНИК поверх элемента — игнорируя border-radius, отсюда
   "квадратная рамка" на круглых/скруглённых кнопках, ячейках календаря, строках чата. */
* {
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a {
  color: var(--accent);
}

button,
[role='button'],
a.btn,
.clickable {
  cursor: pointer;
}

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

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

h1,
h2,
h3 {
  margin-top: 0;
  font-weight: 700;
  letter-spacing: -0.01em;
}

h1 {
  font-size: 26px;
}

h2 {
  font-size: 20px;
}

h3 {
  font-size: 17px;
}

/* ===== Layout ===== */
.container {
  max-width: 480px;
  margin: 0 auto;
  padding: 24px 16px 80px;
}

.card {
  background: var(--card-bg);
  border-radius: 14px;
  padding: 20px;
  box-shadow: 0 1px 3px var(--shadow);
  margin-bottom: 16px;
}

.center {
  text-align: center;
}

.muted {
  color: var(--text-muted);
  font-size: 14px;
}

/* ===== Кнопки ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--accent);
  color: var(--on-accent);
  border: none;
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
  text-align: center;
  text-decoration: none;
  width: 100%;
  transition: background-color 150ms ease, transform 100ms ease;
  font-family: inherit;
}

.btn:hover {
  background: var(--accent-hover);
}

.btn:active {
  transform: scale(0.98);
}

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

.btn-secondary:hover {
  background: var(--secondary-bg-hover);
}

.btn-danger {
  background: var(--danger);
}

.btn-danger:hover {
  background: var(--danger-hover);
}

.icon-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-muted);
  flex-shrink: 0;
  text-decoration: none;
  transition: background-color 150ms ease, color 150ms ease;
}

.icon-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 16px;
  height: 16px;
  padding: 0 3px;
  border-radius: 8px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.icon-btn:hover {
  background: var(--hover-bg);
  color: var(--text);
}

/* ===== Формы ===== */
input,
select,
textarea {
  width: 100%;
  padding: 11px 13px;
  font-size: 15px;
  border: 1px solid var(--input-border);
  border-radius: 10px;
  margin-bottom: 12px;
  font-family: inherit;
  background: var(--input-bg);
  color: var(--text);
  transition: border-color 150ms ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
}

label {
  font-weight: 600;
  font-size: 14px;
  display: block;
  margin-bottom: 6px;
}

.field-row {
  display: flex;
  gap: 10px;
}

.field-row > div {
  flex: 1;
}

.error {
  background: var(--error-bg);
  color: var(--error-text);
  padding: 10px 14px;
  border-radius: 10px;
  margin-bottom: 12px;
  font-size: 14px;
}

/* ===== Аватары и бейджи ===== */
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
  overflow: hidden;
  flex-shrink: 0;
}

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

.avatar-lg {
  width: 84px;
  height: 84px;
  font-size: 32px;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  border-radius: 10px;
  padding: 2px 7px;
  vertical-align: middle;
  min-width: 18px;
}

.qr-wrap {
  text-align: center;
  margin: 16px 0;
}

.qr-wrap img {
  max-width: 220px;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
}

@media (max-width: 480px) {
  .container {
    padding: 16px 12px 80px;
  }
}

/* ===== Профиль-меню (в шапке сайдбара) ===== */
.profile-menu {
  position: relative;
}

.profile-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  padding: 0;
  border-radius: 50%;
}

.profile-dropdown {
  display: none;
  position: absolute;
  left: 0;
  top: 100%;
  margin-top: 6px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 16px var(--shadow-strong);
  min-width: 200px;
  z-index: 30;
  overflow: hidden;
}

.profile-dropdown.open {
  display: block;
}

.profile-dropdown a,
.profile-dropdown button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 10px 14px;
  background: none;
  border: none;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  box-sizing: border-box;
  font-family: inherit;
  transition: background-color 150ms ease;
}

.profile-dropdown a:hover,
.profile-dropdown button:hover {
  background: var(--hover-bg);
}

/* ===== Двухколоночный мессенджер (в стиле Telegram Desktop) ===== */
body:has(.chat-layout) {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.chat-layout {
  display: flex;
  flex: 1;
  min-height: 0;
  width: 100%;
  background: var(--bg);
}

.chat-sidebar {
  width: 340px;
  flex-shrink: 0;
  background: var(--card-bg);
  border-right: 1px solid var(--border);
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.sidebar-header .brand {
  flex: 1;
  font-weight: 800;
  font-size: 18px;
  letter-spacing: -0.01em;
}

.chat-list {
  overflow-y: auto;
  flex: 1;
}

.chat-list-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 10px;
  text-decoration: none;
  color: var(--text);
  margin-bottom: 2px;
  transition: background-color 150ms ease;
}

.chat-list-item:hover {
  background: var(--hover-bg);
}

.chat-row-menu-btn {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: 50%;
  color: var(--text-muted);
  opacity: 0;
  cursor: pointer;
  padding: 0;
}

.chat-list-item:hover .chat-row-menu-btn,
.chat-row-menu-btn:focus-visible {
  opacity: 1;
}

.chat-row-menu-btn:hover {
  background: rgba(127, 127, 127, 0.2);
  color: var(--text);
}

/* На сенсорных экранах наведения не существует — без этого кнопка была бы недоступна вообще. */
@media (hover: none) {
  .chat-row-menu-btn {
    opacity: 1;
  }
}

.chat-action-menu {
  display: none;
  position: absolute;
  z-index: 600;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 16px var(--shadow-strong);
  min-width: 180px;
  overflow: hidden;
}

.chat-action-menu.open {
  display: block;
}

.chat-action-menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 10px 14px;
  background: none;
  border: none;
  font-size: 14px;
  color: var(--danger);
  cursor: pointer;
  font-family: inherit;
}

.chat-action-menu button:hover {
  background: var(--hover-bg);
}

.chat-list-item.active {
  background: var(--accent-soft-bg);
}

.avatar-saved {
  background: linear-gradient(135deg, var(--accent), var(--secondary));
}

.avatar-system {
  background: var(--secondary-bg);
  color: var(--text-muted);
}

.chat-main {
  flex: 1;
  min-width: 0;
  min-height: 0;
  padding: 16px;
  display: flex;
  flex-direction: column;
}

.chat-main--empty {
  align-items: center;
  justify-content: center;
  text-align: center;
}

.chat-main--form {
  overflow-y: auto;
  align-items: center;
  padding-top: 40px;
}

.chat-main--form .card {
  width: 100%;
  max-width: 460px;
}

.friend-row {
  margin-bottom: 2px;
}

.friend-row label {
  font-weight: normal;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 150ms ease;
  margin-bottom: 0;
}

.friend-row label:hover {
  background: var(--hover-bg);
}

.friend-row input[type='checkbox'] {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
}

.member-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.member-row:last-of-type {
  border-bottom: none;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  margin: -16px -16px 12px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
}

/* ===== Панель "Участники группы" — оверлей поверх чата ===== */
.chat-main.blurred {
  filter: blur(4px);
  pointer-events: none;
  user-select: none;
}

.group-panel-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 500;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.group-panel-overlay.open {
  display: flex;
}

.group-panel {
  background: var(--card-bg);
  border-radius: 14px;
  width: 100%;
  max-width: 420px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px var(--shadow-strong);
}

.group-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--card-bg);
}

.group-panel-body {
  padding: 16px;
}

/* ===== Галерея вложений чата ===== */
.media-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.media-grid-item {
  display: block;
  padding: 0;
  border: none;
  border-radius: 8px;
  overflow: hidden;
  background: var(--secondary-bg);
  cursor: zoom-in;
  aspect-ratio: 1 / 1;
}

.media-grid-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ===== Системные сообщения в ленте чата (удаление/роли/выход) ===== */
.msg-system {
  align-self: center;
  background: var(--secondary-bg);
  color: var(--text-muted);
  font-size: 12px;
  padding: 5px 14px;
  border-radius: 20px;
  margin: 4px 0;
  text-align: center;
}

.chat-back {
  display: none;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  text-decoration: none;
  color: var(--text);
}

@media (max-width: 800px) {
  body:has(.chat-layout) {
    /* dvh — реальная видимая высота экрана на мобильных (без адресной строки браузера).
       Строка выше — фолбэк для браузеров без поддержки dvh, ниже её переопределяет там, где есть. */
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }

  /* .chat-layout остаётся flex-строкой (как на десктопе) — на мобильном виден только один
     из двух блоков (список или контент), второй просто display:none, поэтому видимый блок
     сам растягивается на всю ширину. Это же сохраняет вложенный скролл внутри .chat-main
     (например, #messages), а инпут сообщения — прижатым к низу экрана. */
  .chat-sidebar {
    width: 100%;
    border-right: none;
  }

  .chat-layout--active .chat-sidebar {
    display: none;
  }

  .chat-main {
    display: none;
  }

  .chat-layout--active .chat-main {
    display: flex;
  }

  .chat-back {
    display: inline-flex;
  }

  /* Заголовки на мобильном — иначе h1 (26px) слишком крупный и длинные названия
     мероприятий/групп переносятся в несколько строк без необходимости. */
  h1 {
    font-size: 21px;
  }

  h2 {
    font-size: 18px;
  }

  h3 {
    font-size: 16px;
  }

  /* Календарь мероприятий на весь экран — сетка растягивается по высоте вместо
     фиксированной высоты ячеек с пустым отступом снизу. */
  .calendar-card {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
  }

  .calendar-grid {
    flex: 1;
    grid-auto-rows: 1fr;
  }

  .calendar-cell {
    min-height: 0;
  }
}

/* ===== Сообщения ===== */
#messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
  padding: 4px;
}

.msg-row {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  align-self: flex-start;
  max-width: 75%;
}

.msg-row.me {
  align-self: flex-end;
}

/* ===== Свайп сообщения влево — быстрый ответ (только сенсорные экраны, см. chat.js) ===== */
.msg-swipe-icon {
  position: absolute;
  top: 50%;
  right: -34px;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--accent-soft-bg);
  color: var(--accent);
  opacity: 0;
  transform: translateY(-50%) scale(0.5);
  pointer-events: none;
}

.msg-avatar {
  margin-bottom: 4px;
}

.msg-col {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.msg-row:not(.me) .msg-col {
  align-items: flex-start;
}

.msg-row.me .msg-col {
  align-items: flex-end;
}

.msg {
  position: relative;
  background: color-mix(in srgb, var(--msg-bg) 88%, transparent);
  color: var(--text);
  border: 1px solid var(--msg-border);
  border-radius: 14px;
  padding: 8px 32px 8px 12px;
  min-width: 0;
}

.msg.me {
  background: color-mix(in srgb, var(--msg-me-bg) 88%, transparent);
  color: #fff;
  border-color: var(--msg-me-bg);
}

/* У сообщений без кнопки "..." (например, приглашение на мероприятие) правый отступ
   не нужно резервировать под неё — иначе текст/кнопки выглядят прижатыми влево. */
.msg.msg-no-actions {
  padding-right: 12px;
}

.msg.msg-no-actions .msg-time {
  margin-right: 0;
}

/* Фото без подписи — пузырька нет вообще, само изображение выступает "пузырьком" (как в Telegram). */
.msg.msg-image-only {
  background: none;
  border: none;
  padding: 0;
}

.msg.msg-image-only .msg-menu-btn {
  background: rgba(0, 0, 0, 0.4);
  color: #fff;
  opacity: 0.85;
}

.msg.msg-image-only .msg-menu-btn:hover {
  background: rgba(0, 0, 0, 0.6);
}

.msg.msg-image-only .msg-forwarded,
.msg.msg-image-only .msg-author,
.msg.msg-image-only .msg-reply-preview {
  margin-left: 8px;
  margin-right: 8px;
}

.msg.msg-image-only .msg-time {
  position: absolute;
  bottom: 6px;
  right: 8px;
  margin: 0;
  padding: 2px 7px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  opacity: 1;
}

.msg-menu-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: 50%;
  color: inherit;
  opacity: 0.45;
  cursor: pointer;
  padding: 0;
}

.msg-menu-btn:hover,
.msg-menu-btn:focus-visible {
  opacity: 1;
  background: rgba(127, 127, 127, 0.2);
}

/* На сенсорных экранах наведения не существует — кнопка "..." должна быть видна всегда,
   а не только по hover (иначе на телефоне до неё не добраться). */
@media (hover: none) {
  .msg-menu-btn {
    opacity: 1;
  }
}

/* ===== Плавающий бар реакций над меню действий сообщения ===== */
.msg-reaction-bar {
  display: none;
  position: absolute;
  z-index: 601;
  align-items: center;
  gap: 2px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: 0 4px 16px var(--shadow-strong);
  padding: 6px 8px;
  max-width: min(90vw, 380px);
  overflow-x: auto;
  /* Скрываем визуальную полосу прокрутки (торчала за пределы скруглённой пилюли) —
     прокрутка свайпом/колесом при этом продолжает работать. */
  scrollbar-width: none;
}

.msg-reaction-bar::-webkit-scrollbar {
  display: none;
}

.msg-reaction-bar.open {
  display: flex;
}

.reaction-option {
  flex-shrink: 0;
  border: none;
  background: none;
  font-size: 20px;
  line-height: 1;
  padding: 4px;
  border-radius: 50%;
  cursor: pointer;
  transition: transform 100ms ease, background-color 150ms ease;
}

.reaction-option:hover {
  background: var(--hover-bg);
  transform: scale(1.15);
}

/* ===== Пилюли реакций — под пузырьком сообщения, не внутри него ===== */
.msg-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.msg-reaction-pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 12px;
  padding: 2px 7px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--secondary-bg);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
}

.msg-reaction-pill.mine {
  border-color: var(--accent);
  background: var(--accent-soft-bg);
  color: var(--accent);
}

/* ===== Плавающее меню действий с сообщением (Переслать/Редактировать/Удалить) ===== */
.msg-action-menu {
  display: none;
  position: absolute;
  z-index: 600;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 16px var(--shadow-strong);
  min-width: 180px;
  overflow: hidden;
}

.msg-action-menu.open {
  display: block;
}

.msg-action-menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 10px 14px;
  background: none;
  border: none;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
}

.msg-action-menu button:hover {
  background: var(--hover-bg);
}

.msg-action-menu .msg-action-delete {
  color: var(--danger);
}

.msg-action-menu .event-action-delete {
  color: var(--danger);
}

/* ===== Панель редактирования (над полем ввода) ===== */
.edit-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--accent-soft-bg);
  color: var(--accent);
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 13px;
  margin-bottom: 8px;
}

.edit-bar span {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ===== Превью прикреплённых фото перед отправкой ===== */
.attach-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  /* Без этого превью — как flex-элемент .chat-main — растягивалось на всю ширину чата,
     и кнопка удаления (right: -8px) оказывалась у самого края экрана, а не у картинки. */
  align-self: flex-start;
  margin-bottom: 8px;
}

.attach-preview-item {
  position: relative;
  display: inline-block;
}

.attach-preview-item img {
  max-width: 120px;
  max-height: 120px;
  border-radius: 10px;
  display: block;
}

.attach-preview-remove {
  position: absolute;
  top: -8px;
  right: -8px;
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.msg-author {
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 2px;
}

.msg-forwarded {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  opacity: 0.7;
  margin-bottom: 2px;
  font-style: italic;
}

.msg-reply-preview {
  display: block;
  border-left: 3px solid currentColor;
  opacity: 0.85;
  background: rgba(127, 127, 127, 0.12);
  border-radius: 6px;
  padding: 4px 8px;
  margin-bottom: 4px;
  cursor: pointer;
  max-width: 100%;
}

.msg-reply-preview-author {
  font-size: 12px;
  font-weight: 700;
}

.msg-reply-preview-text {
  font-size: 12px;
  opacity: 0.85;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg-mention {
  font-weight: 700;
  color: var(--accent);
  cursor: pointer;
}

.msg.me .msg-mention {
  color: #fff;
  text-decoration: underline;
}

/* ===== Выпадающий список тегов "@" в поле ввода ===== */
.mention-dropdown {
  display: none;
  position: absolute;
  z-index: 600;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 16px var(--shadow-strong);
  min-width: 180px;
  max-height: 220px;
  overflow-y: auto;
}

.mention-dropdown.open {
  display: block;
}

.mention-option {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  background: none;
  border: none;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
}

.mention-option:hover,
.mention-option.active {
  background: var(--hover-bg);
}

.msg-text {
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-time {
  display: flex;
  justify-content: flex-end;
  font-size: 10px;
  opacity: 0.6;
  margin-top: 2px;
  /* .msg резервирует 32px справа под кнопку "..." (padding: 8px 32px 8px 12px) — без этой компенсации
     время оказывалось на 20px левее реального края пузырька, а не строго по правому краю. */
  margin-right: -20px;
}

.msg.me .msg-time {
  color: var(--msg-me-text);
}

.msg-image {
  display: block;
  max-width: 240px;
  max-height: 320px;
  width: 100%;
  height: auto;
  border-radius: 10px;
  object-fit: cover;
  cursor: zoom-in;
}

.chat-main.drag-over {
  outline: 3px dashed var(--accent);
  outline-offset: -3px;
}

/* ===== Форма отправки ===== */
#send-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.input-wrap {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 999px;
  padding-right: 4px;
  transition: border-color 150ms ease;
}

.input-wrap:focus-within {
  border-color: var(--accent);
}

.input-wrap input {
  flex: 1;
  min-width: 0;
  margin-bottom: 0;
  border: none;
  background: none;
  padding: 11px 4px 11px 18px;
}

.input-wrap input:focus {
  border-color: transparent;
  outline: none;
}

/* Подсветку фокуса показываем один раз — рамкой всей пилюли (.input-wrap:focus-within),
   а не отдельно у текстового поля и у кнопок внутри неё. */
.input-wrap button:focus-visible {
  outline: none;
}

#emoji-trigger,
.input-send-btn {
  flex-shrink: 0;
  font-size: 19px;
}

.input-send-btn {
  color: var(--accent);
}

.emoji-panel {
  display: none;
  position: absolute;
  bottom: 100%;
  right: 0;
  margin-bottom: 6px;
  width: 322px; /* хватает на 7 колонок по 40px + отступы, без горизонтального переполнения */
  max-height: 280px;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-gutter: stable; /* место под вертикальный скроллбар зарезервировано всегда — панель не "дёргается» */
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 16px var(--shadow-strong);
  padding: 8px;
  z-index: 30;
}

.emoji-panel.open {
  display: block;
}

.emoji-panel-heading {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  margin: 8px 4px 4px;
}

.emoji-panel-grid {
  display: grid;
  /* minmax(0, 1fr) — без этого колонки грида могут "распираться" по ширине содержимым
     (у грид-треков по умолчанию min-width: auto), что и вызывало горизontальный скролл. */
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 2px;
}

.emoji-btn {
  background: none;
  border: none;
  font-size: 20px;
  padding: 4px;
  cursor: pointer;
  border-radius: 6px;
  line-height: 1.2;
  min-width: 0;
  overflow: hidden;
}

.emoji-btn:hover {
  background: var(--hover-bg);
}

.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  padding: 20px;
}

.lightbox.open {
  display: flex;
}

.lightbox img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 10px;
}

/* ===== In-app модалка подтверждения (замена window.confirm) ===== */
#fn-modal-root {
  position: fixed;
  inset: 0;
  z-index: 2000;
  pointer-events: none;
}

#fn-modal-root.open {
  pointer-events: auto;
}

.fn-modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.fn-modal-box {
  background: var(--card-bg);
  border-radius: 14px;
  padding: 20px;
  width: 100%;
  max-width: 340px;
  box-shadow: 0 8px 32px var(--shadow-strong);
}

.fn-modal-text {
  margin: 0 0 18px;
  color: var(--text);
  font-size: 15px;
}

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

.fn-modal-actions .btn {
  width: auto;
  padding: 10px 16px;
}

/* ===== In-app тост-уведомления (замена window.alert для некритичных сообщений) ===== */
#fn-toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}

.fn-toast {
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 14px;
  box-shadow: 0 4px 16px var(--shadow-strong);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 200ms ease, transform 200ms ease;
  max-width: 90vw;
  text-align: center;
}

.fn-toast.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ===== Поиск (глобальный + локальный) ===== */
#search-overlay .group-panel {
  max-width: 460px;
}

#search-input {
  margin-bottom: 10px;
}

.search-scope-toggle {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
}

.search-scope-btn {
  flex: 1;
  padding: 8px 10px;
  border-radius: 8px;
  border: none;
  background: var(--secondary-bg);
  color: var(--secondary-text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background-color 150ms ease, color 150ms ease;
}

.search-scope-btn.active {
  background: var(--accent);
  color: var(--on-accent);
}

.search-section-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin: 14px 4px 6px;
}

.search-section-title:first-child {
  margin-top: 0;
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 10px;
  text-decoration: none;
  color: var(--text);
  transition: background-color 150ms ease;
}

.search-result-item:hover {
  background: var(--hover-bg);
}

.search-snippet {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ===== Подсветка найденного сообщения при переходе из поиска ===== */
.msg.highlight {
  animation: fn-highlight-flash 1800ms ease;
}

@keyframes fn-highlight-flash {
  0%, 100% { box-shadow: none; }
  15%, 60% { box-shadow: 0 0 0 3px var(--accent); }
}

/* ===== Дни рождения ===== */
.birthday-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.birthday-row:last-child {
  border-bottom: none;
}

.birthday-countdown {
  flex-shrink: 0;
  text-align: right;
  font-size: 13px;
}

/* ===== Мероприятия ===== */
.event-card {
  border-left: 4px solid transparent;
  position: relative;
}

.event-card--organizer {
  border-left-color: var(--organizer-border);
  background: var(--organizer-bg);
}

.event-card--invited {
  border-left-color: var(--invited-border);
  background: var(--invited-bg);
}

.event-role-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  margin-bottom: 6px;
}

.event-card--organizer .event-role-tag {
  color: var(--organizer-border);
}

.event-card--invited .event-role-tag {
  color: var(--invited-border);
}

.event-invite-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.event-invite-row:last-child {
  border-bottom: none;
}

.event-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.event-actions .btn {
  width: auto;
  /* Асимметрично: у шрифта Plus Jakarta Sans надстрочная часть визуально "тяжелее" подстрочной,
     из-за чего текст при чисто симметричном padding/line-height всё равно выглядит чуть ниже центра. */
  padding: 5px 10px 7px;
  font-size: 13px;
}

/* ===== Свой календарь / выбор времени (вместо нативных input[type=date/time]) ===== */
.picker-display {
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%2365676b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='18' rx='2'/%3E%3Cline x1='16' y1='2' x2='16' y2='6'/%3E%3Cline x1='8' y1='2' x2='8' y2='6'/%3E%3Cline x1='3' y1='10' x2='21' y2='10'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 40px;
}

input.picker-display[data-picker='time'] {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%2365676b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpolyline points='12 6 12 12 16 14'/%3E%3C/svg%3E");
}

.picker-popup {
  display: none;
  position: absolute;
  z-index: 700;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 24px var(--shadow-strong);
  padding: 12px;
}

.picker-popup.open {
  display: block;
}

.date-picker-popup {
  width: 280px;
}

.picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.picker-header-title {
  font-weight: 700;
  font-size: 14px;
}

.picker-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  margin-bottom: 4px;
}

.picker-weekdays div {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 700;
}

.picker-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 2px;
}

.picker-day {
  background: none;
  border: none;
  border-radius: 8px;
  padding: 8px 0;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
}

.picker-day:hover:not(:disabled) {
  background: var(--hover-bg);
}

.picker-day--muted {
  color: var(--text-muted);
  opacity: 0.4;
  cursor: default;
}

.picker-day--today {
  box-shadow: inset 0 0 0 1px var(--accent);
  font-weight: 700;
}

.picker-day--selected {
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
}

.time-picker-popup {
  width: 160px;
}

.time-picker-columns {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.time-picker-col {
  flex: 1;
  max-height: 200px;
  overflow-y: auto;
  scrollbar-gutter: stable;
}

.time-picker-item {
  display: block;
  width: 100%;
  background: none;
  border: none;
  border-radius: 8px;
  padding: 8px 0;
  text-align: center;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  margin-bottom: 2px;
}

.time-picker-item:hover {
  background: var(--hover-bg);
}

.time-picker-item.selected {
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
}

.time-picker-done {
  width: 100%;
}

/* ===== Календарь мероприятий ===== */
.chat-main--calendar {
  overflow-y: auto;
  align-items: stretch;
}

.calendar-card {
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  margin-bottom: 0;
}

.calendar-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.calendar-toolbar .btn {
  flex-shrink: 0;
}

.calendar-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.calendar-month-title {
  font-weight: 700;
  font-size: 16px;
  min-width: 160px;
  text-align: center;
}

.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  margin-bottom: 4px;
}

.calendar-weekdays div {
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  padding-bottom: 6px;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
}

.calendar-cell {
  min-height: 78px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  overflow: hidden;
}

.calendar-cell--muted {
  opacity: 0.4;
  background: var(--bg);
}

.calendar-cell--today {
  border-color: var(--accent);
  border-width: 2px;
}

.calendar-cell-day {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
}

.calendar-event-chip {
  display: block;
  font-size: 11px;
  padding: 2px 5px;
  border-radius: 5px;
  text-decoration: none;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border-left: 3px solid transparent;
}

.calendar-event-chip--organizer {
  background: var(--organizer-bg);
  border-left-color: var(--organizer-border);
}

.calendar-event-chip--invited {
  background: var(--invited-bg);
  border-left-color: var(--invited-border);
}

.calendar-birthday-chip {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  padding: 2px 5px;
  border-radius: 5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: linear-gradient(135deg, var(--accent-soft-bg), transparent);
  color: var(--text);
  border: none;
  font-family: inherit;
  width: 100%;
  text-align: left;
}

.calendar-birthday-chip--clickable {
  cursor: pointer;
}

.calendar-birthday-chip--clickable:hover {
  background: var(--hover-bg);
}

.calendar-birthday-chip svg {
  flex-shrink: 0;
  color: var(--accent);
}

@media (max-width: 700px) {
  .calendar-cell {
    min-height: 60px;
  }

  .calendar-cell-day {
    font-size: 11px;
  }

  .calendar-event-chip {
    font-size: 10px;
  }

  .calendar-month-title {
    min-width: auto;
  }
}
