/* ===========================================================================
   Палитра и темы
   =========================================================================== */

:root {
  --accent-100: #AFD895;
  --accent-300: #8DC662;
  --accent-500: #6FA747;

  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
  /* HTMX: смена #messenger-outlet, сайдбар не трогаем */
  --nav-ease: cubic-bezier(0.22, 1, 0.36, 1);
  --nav-messenger-pending-dur: 0.2s;
  --nav-messenger-in-dur: 0.34s;

  /* Светлая тема — значения по умолчанию */
  --bg: #f8fbf6;
  --bg-elevated: #ffffff;
  --bg-muted: #eef3eb;
  --fg: #1c2620;
  --fg-muted: #5b6962;
  --border: #d9e1d4;
  --bubble-other: #ffffff;
  --bubble-own: var(--accent-100);
}

[data-theme="dark"] {
  --bg: #0e1411;
  --bg-elevated: #161e1a;
  --bg-muted: #1c2520;
  --fg: #e8efe9;
  --fg-muted: #93a39a;
  --border: #25302a;
  --bubble-other: #1c2520;
  --bubble-own: var(--accent-500);
}

@media (prefers-color-scheme: dark) {
  [data-theme="system"] {
    --bg: #0e1411;
    --bg-elevated: #161e1a;
    --bg-muted: #1c2520;
    --fg: #e8efe9;
    --fg-muted: #93a39a;
    --border: #25302a;
    --bubble-other: #1c2520;
    --bubble-own: var(--accent-500);
  }
}

/* ===========================================================================
   Базовый сброс и типографика
   =========================================================================== */

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-500); text-decoration: none; }
a:hover { text-decoration: underline; }
input, button, select, textarea { font: inherit; color: inherit; }

[x-cloak] { display: none !important; }

/* ---------------------------------------------------------------------------
   HTMX: только #messenger-outlet — пока идёт запрос — мягкое «подзатенение». */

#messenger-outlet.messenger-outlet--pending {
  transition: opacity var(--nav-messenger-pending-dur) ease;
  opacity: 0.82;
}

#messenger-outlet.messenger-outlet--enter {
  animation: messenger-outlet-enter var(--nav-messenger-in-dur) var(--nav-ease) both;
  will-change: opacity;
}

@keyframes messenger-outlet-enter {
  from { opacity: 0.5; }
  to { opacity: 1; }
}

.messenger-outlet {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.messenger-outlet > .window {
  flex: 1;
  min-height: 0;
}

@media (prefers-reduced-motion: reduce) {
  #messenger-outlet.messenger-outlet--pending {
    transition: opacity 0.15s ease;
    filter: none;
    transform: none;
  }
  #messenger-outlet.messenger-outlet--enter {
    animation: messenger-outlet-enter-reduced 0.2s ease both;
  }
  @keyframes messenger-outlet-enter-reduced {
    from { opacity: 0.5; }
    to { opacity: 1; }
  }
}

/* Alpine: плавное появление/скрытие (сайдбар) */
.sfx-htmx,
.srs-htmx { transition: opacity 0.2s var(--nav-ease), transform 0.2s var(--nav-ease); }
.sfx-from { opacity: 0; transform: translateY(-5px) scale(0.98); }
.sfx-to { opacity: 1; transform: none; }
.srs-from { opacity: 0; transform: translateY(-4px); }
.srs-to { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) {
  .sfx-htmx, .srs-htmx { transition: opacity 0.12s ease; }
  .sfx-from, .srs-from { transform: none; }
}

/* ===========================================================================
   Кнопки
   =========================================================================== */

.btn {
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--fg);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  cursor: pointer;
  transition: background 120ms ease, transform 80ms ease;
}
.btn:hover { background: var(--bg-muted); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn--primary {
  background: var(--accent-300);
  border-color: var(--accent-500);
  color: #0c1a08;
  font-weight: 600;
}
.btn--primary:hover { background: var(--accent-500); color: #fff; }

/* ===========================================================================
   Аутентификация (страницы login/register/profile)
   =========================================================================== */

.auth {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 32px 16px;
  background:
    radial-gradient(circle at 20% 0%, rgba(141, 198, 98, 0.18), transparent 50%),
    radial-gradient(circle at 100% 100%, rgba(111, 167, 71, 0.12), transparent 50%),
    var(--bg);
}
.auth__card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
}
.auth__title { margin: 0 0 4px; font-size: 28px; }
.auth__subtitle { margin: 0 0 24px; color: var(--fg-muted); font-size: 14px; }
.auth__form { display: grid; gap: 14px; }
.auth__field { display: grid; gap: 6px; font-size: 13px; color: var(--fg-muted); }
.auth__field input, .auth__field select {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: var(--bg);
  color: var(--fg);
  outline: none;
  transition: border-color 120ms ease;
}
.auth__field input:focus, .auth__field select:focus { border-color: var(--accent-500); }
.auth__alt { margin: 16px 0 0; text-align: center; color: var(--fg-muted); font-size: 13px; }
.auth__hint { margin: 4px 0 0; text-align: center; color: var(--fg-muted); font-size: 12px; }
.auth__error {
  padding: 10px 12px; border-radius: var(--radius-sm);
  background: rgba(220, 60, 60, 0.12); color: #c0392b;
}

/* ===========================================================================
   Главный layout
   =========================================================================== */

.app {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: 100vh;
  overflow: hidden;
  transition: grid-template-columns 0.28s var(--nav-ease);
}

.app--sidebar-rail {
  /* В шапке две кнопки — только в колонку; ширина хватает под 36px + паддинги */
  grid-template-columns: 52px 1fr;
  overflow: visible;
}

/* ---- Сайдбар ----
   Голова: гамбургер + поиск, ниже — список чатов. */

.sidebar {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  border-right: 1px solid var(--border);
  background: var(--bg-elevated);
}
.sidebar__head {
  flex: 0 0 auto;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.sidebar__head-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.sidebar__menu-anchor { position: relative; flex: 0 0 auto; }
.sidebar__menu-btn {
  display: grid;
  place-items: center;
  width: 40px; height: 40px;
  margin: 0; padding: 0;
  border: none; border-radius: 10px;
  background: transparent;
  color: var(--fg);
  cursor: pointer;
  transition: background 120ms ease;
}
.sidebar__menu-btn:hover,
.sidebar__menu-btn:focus-visible {
  background: var(--bg-muted);
  outline: none;
}
.sidebar__menu-icon { display: flex; line-height: 0; }

.sidebar__rail-btn {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 40px; height: 40px;
  margin: 0; padding: 0;
  border: none; border-radius: 10px;
  background: transparent;
  color: var(--fg);
  cursor: pointer;
  transition: background 120ms ease;
  font: inherit;
}
.sidebar__rail-btn:hover,
.sidebar__rail-btn:focus-visible {
  background: var(--bg-muted);
  outline: none;
}
.sidebar__rail-chevron {
  font-size: 14px;
  line-height: 1;
  font-weight: 600;
  letter-spacing: -0.1em;
  user-select: none;
}

/* Узкий сайдбар: только кнопки в шапке + аватары */
.app--sidebar-rail .sidebar__search { display: none; }
/* Две кнопки (≈40px) в ряд в колонку ~32–40px внутри = обрезка; в колонку + компактные hit-area */
.app--sidebar-rail .sidebar__head {
  padding: 8px 4px;
  overflow: visible;
}
.app--sidebar-rail .sidebar__head-row {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
}
.app--sidebar-rail .sidebar__menu-btn,
.app--sidebar-rail .sidebar__rail-btn {
  width: 36px;
  height: 36px;
  min-width: 0;
  flex-shrink: 0;
  box-sizing: border-box;
  border-radius: 8px;
}
.app--sidebar-rail .sidebar__menu-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}
.app--sidebar-rail .sidebar__menu-icon svg {
  display: block;
  width: 20px;
  height: 20px;
  max-width: 100%;
  max-height: 100%;
}
.app--sidebar-rail .sidebar__rail-chevron {
  font-size: 13px;
  letter-spacing: -0.05em;
  line-height: 1.2;
}
/* Меню у края — открываем вправо от колонки, иначе режется overflow */
.app--sidebar-rail .sidebar__dropdown {
  top: 0;
  left: 100%;
  right: auto;
  margin-top: 0;
  margin-left: 6px;
}
.app--sidebar-rail .sidebar { overflow: visible; }
.app--sidebar-rail .sidebar__result { grid-template-columns: 1fr; justify-items: center; }
.app--sidebar-rail .sidebar__result-text { display: none; }
.app--sidebar-rail .chat-item a {
  position: relative;
  grid-template-columns: 1fr;
  justify-items: center;
  padding: 6px 4px 6px 4px;
}
.app--sidebar-rail .chat-item__text { display: none; }
.app--sidebar-rail .chat-item__meta {
  position: absolute;
  top: 2px; right: 2px;
  display: block;
  padding: 0;
  justify-self: auto;
  line-height: 1;
}
.app--sidebar-rail .chat-item__unread {
  min-width: 16px; height: 16px; font-size: 10px; padding: 0 3px;
}
.app--sidebar-rail .chat-item--empty { font-size: 10px; line-height: 1.2; padding: 10px 4px; }
.sidebar__dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 50;
  min-width: 240px;
  padding: 6px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}
.sidebar__dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin: 0;
  padding: 10px 12px;
  border: none; border-radius: 8px;
  background: none;
  font: inherit; font-size: 14px;
  color: var(--fg);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: background 120ms ease;
}
a.sidebar__dropdown-item:hover,
a.sidebar__dropdown-item:focus-visible,
button.sidebar__dropdown-item:not(:disabled):hover,
button.sidebar__dropdown-item:not(:disabled):focus-visible {
  background: var(--bg-muted);
  text-decoration: none;
  outline: none;
  color: inherit;
}
.sidebar__dropdown-item--active { background: var(--bg-muted); }
.sidebar__dropdown-item--stub {
  opacity: 0.55;
  cursor: not-allowed;
}
.sidebar__dropdown-ico { flex: 0 0 auto; display: flex; line-height: 0; color: var(--fg-muted); }
.sidebar__search {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  padding: 10px 14px;
  border-radius: 999px;
  outline: none;
  transition: border-color 120ms ease;
}
.sidebar__search:focus { border-color: var(--accent-500); }

.sidebar__results {
  flex: 0 0 auto;
  list-style: none; margin: 0; padding: 8px 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg-muted);
  max-height: 240px; overflow-y: auto;
}
.sidebar__result {
  display: grid; grid-template-columns: 36px 1fr; gap: 10px;
  align-items: center; padding: 8px 14px; cursor: pointer;
}
.sidebar__result:hover { background: var(--bg-elevated); }
.sidebar__result-name { font-weight: 500; }
.sidebar__result-tag { font-size: 12px; color: var(--fg-muted); }

.sidebar__chats {
  flex: 1 1 auto;
  min-height: 0;
  list-style: none; margin: 0; padding: 0;
  overflow-y: auto;
}
.chat-item a {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  gap: 8px 6px;
  padding: 8px 10px 8px 12px;
  align-items: start;
  color: inherit;
}
.chat-item a:hover { background: var(--bg-muted); text-decoration: none; }
.chat-item--active a { background: var(--bg-muted); }
.chat-item__text { min-width: 0; margin-top: -1px; }
.chat-item__title {
  font-weight: 600;
  font-size: 14px;
  line-height: 1.2;
  min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-item__preview {
  font-size: 12px;
  line-height: 1.2;
  margin-top: 1px;
  color: var(--fg-muted);
  min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-item__preview--muted { opacity: 0.85; }
.chat-item__meta { justify-self: end; padding-top: 1px; flex-shrink: 0; }
.chat-item__unread {
  min-width: 20px; height: 20px; padding: 0 5px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 999px; background: var(--accent-500);
  color: #fff; font-size: 11px; font-weight: 600;
  line-height: 1;
  box-shadow: 0 0 0 1px var(--bg-elevated);
}
[data-theme="dark"] .chat-item__unread { color: #0b120d; }
@media (prefers-color-scheme: dark) {
  [data-theme="system"] .chat-item__unread { color: #0b120d; }
}
.chat-item--empty {
  padding: 24px 18px; color: var(--fg-muted); font-size: 13px; text-align: center;
}

/* ---- Аватар ---- */

.avatar {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-300), var(--accent-500));
  color: #0c1a08; font-weight: 700; font-size: 14px;
  flex-shrink: 0;
}
.avatar--lg { width: 44px; height: 44px; font-size: 16px; }
.chat-item .avatar, .sidebar__result .avatar { width: 36px; height: 36px; }
.avatar--img {
  display: block;
  object-fit: cover;
  padding: 0;
  background: var(--bg-muted);
}
.chat-item .avatar--img, .sidebar__result .avatar--img {
  width: 36px; height: 36px;
}
.avatar--lg.avatar--img { width: 44px; height: 44px; }
.avatar-wrap {
  width: 36px; height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ---- Окно чата ---- */

.window {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 0;
  background: var(--bg);
}
.window__head {
  display: grid; grid-template-columns: 44px 1fr; gap: 12px;
  align-items: center; padding: 12px 18px;
  border-bottom: 1px solid var(--border); background: var(--bg-elevated);
}
.window__head-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
}
.window__name { font-weight: 600; }
.window__sub { font-size: 12px; color: var(--fg-muted); }
.window--splash {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
  background:
    radial-gradient(circle at 20% 0%, rgba(141, 198, 98, 0.18), transparent 50%),
    radial-gradient(circle at 100% 100%, rgba(111, 167, 71, 0.12), transparent 50%),
    var(--bg);
}
[data-theme="dark"] .window--splash {
  background:
    radial-gradient(circle at 20% 0%, rgba(141, 198, 98, 0.14), transparent 50%),
    radial-gradient(circle at 100% 100%, rgba(111, 167, 71, 0.1), transparent 50%),
    var(--bg);
}
@media (prefers-color-scheme: dark) {
  [data-theme="system"] .window--splash {
    background:
      radial-gradient(circle at 20% 0%, rgba(141, 198, 98, 0.14), transparent 50%),
      radial-gradient(circle at 100% 100%, rgba(111, 167, 71, 0.1), transparent 50%),
      var(--bg);
  }
}
.window__placeholder {
  color: var(--fg-muted);
  padding: 32px;
}
.window__placeholder--center {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.window__splash-title {
  margin: 0;
  color: var(--fg);
  font-size: clamp(22px, 4vw, 30px);
  font-weight: 600;
  letter-spacing: -0.02em;
}

.messages {
  list-style: none; margin: 0; padding: 12px 14px 16px;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 2px;
}
.messages__empty {
  margin: auto; color: var(--fg-muted); font-size: 13px;
}
.message-row {
  display: flex; align-items: flex-start; gap: 6px;
  max-width: min(88%, 520px);
  align-self: flex-start;
}
.message-row--own {
  align-self: flex-end;
}
.message-ava--in {
  /* верх пузыря = верх колонки; + смещение к первой строке текста внутри padding */
  margin-top: 6px;
}
.message-ava {
  flex: 0 0 28px;
  width: 28px; height: 28px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--bg-muted);
  display: flex; align-items: center; justify-content: center;
}
.message-ava__img {
  width: 100%; height: 100%;
  object-fit: cover; display: block;
}
.message-ava__fallback {
  width: 100%; height: 100%;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 700;
  color: #0c1a08;
  background: linear-gradient(135deg, var(--accent-300), var(--accent-500));
}
.message__col {
  min-width: 0; flex: 1; max-width: 100%;
  display: flex; flex-direction: column; align-items: flex-start;
}
.message-row--own .message__col { align-items: flex-end; }
.message__bubble {
  background: var(--bubble-other);
  border: 1px solid var(--border);
  border-radius: 16px 16px 16px 4px;
  padding: 7px 11px 6px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 15px;
  line-height: 1.35;
  display: inline-block;
  max-width: 100%;
}
.message-row--own .message__bubble {
  background: var(--bubble-own);
  border-color: transparent;
  border-radius: 16px 16px 4px 16px;
  color: #0c1a08;
}

/* Вложения: message__file-imgwrap, message__file-thumb, message__file-video-c */
body.gh-lightbox-open {
  overflow: hidden;
}

.message__files {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  width: 100%;
  min-width: 0;
  max-width: min(100%, min(95vw, 520px));
  margin-top: 2px;
  margin-bottom: 2px;
  box-sizing: border-box;
}
.message-row--own .message__files {
  margin-left: auto;
  align-self: flex-end;
}
.message__files--media {
  display: grid;
  gap: 4px;
  max-width: min(100%, min(95vw, 520px));
  align-content: start;
}
.message__files--c1 {
  grid-template-columns: 1fr;
}
.message__files--c1 .message__file {
  max-width: 100%;
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg-muted);
}
.message__files--c2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: minmax(0, min(40vw, 200px));
}
.message__files--c2 .message__file {
  min-height: 0;
  aspect-ratio: 1;
  max-height: 260px;
}
.message__files--c3 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: auto;
}
.message__files--c3 .message__file:nth-child(1) {
  grid-column: 1 / -1;
  aspect-ratio: 16 / 10;
  min-height: 150px;
  max-height: 300px;
}
.message__files--c3 .message__file:nth-child(2),
.message__files--c3 .message__file:nth-child(3) {
  aspect-ratio: 1;
  min-height: 100px;
  max-height: 200px;
}
.message__files--c4 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: minmax(120px, min(30vw, 200px));
}
.message__files--c4 .message__file {
  min-height: 0;
  aspect-ratio: 1;
  max-height: 220px;
}
.message__files--c5,
.message__files--c6,
.message__files--c7,
.message__files--c8,
.message__files--c9,
.message__files--c10 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-auto-rows: minmax(100px, min(26vw, 180px));
}
.message__files--c5 .message__file,
.message__files--c6 .message__file,
.message__files--c7 .message__file,
.message__files--c8 .message__file,
.message__files--c9 .message__file,
.message__files--c10 .message__file {
  min-height: 0;
  aspect-ratio: 1;
  max-height: 200px;
}
.message__files--media .message__file {
  min-width: 0;
  position: relative;
  border-radius: 6px;
  overflow: hidden;
  background: var(--bg-muted);
}
.message__file {
  display: block;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}
.message__file-imgwrap {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  border-radius: 12px;
  overflow: hidden;
  line-height: 0;
  background: var(--bg-muted);
  cursor: zoom-in;
}
.message__file-thumb {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  max-height: min(50vh, 420px);
  object-fit: contain;
  object-position: center;
}
.message__files--media:not(.message__files--c1) .message__file-imgwrap {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 0;
  max-height: none;
  cursor: pointer;
}
.message__files--media:not(.message__files--c1) .message__file-thumb {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-height: none;
  object-fit: cover;
}
.message__file-video-c {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  border-radius: 12px;
  overflow: hidden;
  line-height: 0;
  background: #0a0a0a;
  position: relative;
}
.message__file-openlb {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  cursor: pointer;
  transition: background 0.12s ease;
}
.message__file-openlb:hover {
  background: rgba(0, 0, 0, 0.7);
}
.message__file-openlb .material-symbols-outlined {
  font-size: 20px;
  line-height: 1;
}
.message__file-video {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  max-height: min(50vh, 360px);
  border-radius: 0;
  background: #000;
  vertical-align: middle;
}
.message__files--media:not(.message__files--c1) .message__file-video-c {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-height: none;
  border-radius: 0;
}
.message__files--media:not(.message__files--c1) .message__file-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-height: none;
  object-fit: cover;
}
.message__file-doc {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  min-width: 0;
  max-width: 100%;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--bg-muted);
  color: var(--fg);
  text-decoration: none;
  font-size: 13px;
  line-height: 1.3;
  border: 1px solid var(--border);
  word-break: break-word;
  overflow-wrap: anywhere;
  transition: background 0.1s ease;
}
.message__file-doc:hover {
  background: var(--bg-elevated);
}
.message__file-doc-ico {
  font-size: 30px;
  line-height: 1;
  color: var(--accent-500);
  flex: 0 0 auto;
  font-variation-settings: "FILL" 0, "wght" 400, "GRAD" 0, "opsz" 24;
  user-select: none;
}
.message__file-doc-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}
.message__file-name {
  font-weight: 500;
  color: var(--fg);
}
.message__file-meta {
  font-size: 12px;
  color: var(--fg-muted);
}
.message-row--own[data-pending="1"] .message__files {
  opacity: 0.6;
}

/* Лайтбокс: затемнение чата, навигация, счётчик */
.media-lightbox {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  z-index: 5000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-sizing: border-box;
}
.media-lightbox__backdrop {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.82);
  z-index: 0;
  cursor: zoom-out;
}
.media-lightbox__stage {
  position: relative;
  z-index: 1;
  max-width: min(96vw, 1200px);
  max-height: 88vh;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  padding: 48px 56px 72px;
  pointer-events: auto;
}
.media-lightbox__img {
  max-width: 100%;
  max-height: 82vh;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
  pointer-events: auto;
}
.media-lightbox__video {
  max-width: 100%;
  max-height: 82vh;
  width: auto;
  background: #000;
  border-radius: 4px;
  pointer-events: auto;
}
.media-lightbox__nav {
  position: absolute;
  z-index: 2;
  top: 0;
  bottom: 0;
  width: 48px;
  margin: 0;
  padding: 0;
  border: none;
  background: rgba(0, 0, 0, 0.25);
  color: #fff;
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
  pointer-events: auto;
}
.media-lightbox__nav:hover,
.media-lightbox__nav:focus-visible {
  background: rgba(0, 0, 0, 0.5);
  outline: none;
}
.media-lightbox__nav--prev {
  left: 0;
  padding-left: 4px;
  border-radius: 0 8px 8px 0;
}
.media-lightbox__nav--next {
  right: 0;
  padding-right: 4px;
  border-radius: 8px 0 0 8px;
}
.media-lightbox__nav-sym {
  display: block;
  font-size: 2.2rem;
  font-weight: 300;
  line-height: 1;
  opacity: 0.95;
  user-select: none;
}
.media-lightbox__bar {
  position: absolute;
  z-index: 2;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 12px 16px 20px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.75));
  color: #e8e8e8;
  font-size: 13px;
  text-align: center;
  pointer-events: none;
}
.media-lightbox__bar-count {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  letter-spacing: 0.02em;
  opacity: 0.95;
}
.media-lightbox__bar-name {
  max-width: min(90vw, 640px);
  word-break: break-word;
  opacity: 0.85;
  font-size: 12px;
}
@media (max-width: 520px) {
  .media-lightbox__stage {
    padding: 40px 40px 68px;
  }
  .media-lightbox__nav {
    width: 40px;
  }
}

.message__time {
  display: block; font-size: 11px; color: var(--fg-muted);
  margin-top: 2px; padding: 0 2px 0 4px;
}
.message__time--own { text-align: right; padding: 0 4px 0 2px; }
.message-row--own[data-pending="1"] .message__bubble { opacity: 0.6; }

/* Подсветка при «переходе к ответу»: вся ширина ленты, на всю высоту карточки, без квадратиков/скруглений */
.message-row--flash {
  --msg-bleed: 14px; /* = гориз. padding .messages; полоска на полную ширину области чата */
  position: relative;
  z-index: 0;
  align-self: stretch !important;
  box-sizing: border-box;
  width: auto !important;
  max-width: none !important;
  margin-left: calc(-1 * var(--msg-bleed));
  margin-right: calc(-1 * var(--msg-bleed));
  padding: 5px var(--msg-bleed) 6px;
  border-radius: 0;
  justify-content: flex-start;
}
.message-row--own.message-row--flash {
  justify-content: flex-end;
}
.message-row--flash::before {
  content: "";
  position: absolute;
  z-index: 0;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  border-radius: 0;
  background: rgba(141, 198, 98, 0.2);
  pointer-events: none;
  animation: message-row-flash-wash 1.55s ease-out forwards;
}
.message-row--flash > * {
  position: relative;
  z-index: 1;
}
@keyframes message-row-flash-wash {
  0% { opacity: 1; }
  40% { opacity: 0.6; }
  100% { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .message-row--flash { padding: 4px 0; }
  .message-row--flash::before {
    animation: message-row-flash-wash-reduce 0.45s ease-out forwards;
  }
  @keyframes message-row-flash-wash-reduce {
    0% { opacity: 0.9; }
    100% { opacity: 0; }
  }
}

/* Цитата (ответ) над пузырём — как в Telegram; кнопка — переход к исходному */
button.message__quote {
  display: flex; gap: 6px; align-items: stretch;
  max-width: 100%;
  margin: 0 0 3px; padding: 2px 4px 2px 1px;
  border: none; border-radius: 8px;
  background: transparent; font: inherit; text-align: left;
  cursor: pointer; color: inherit;
  -webkit-tap-highlight-color: transparent;
}
button.message__quote:hover,
button.message__quote:focus-visible {
  background: rgba(0, 0, 0, 0.05);
  outline: none;
}
.message-row--own button.message__quote:hover,
.message-row--own button.message__quote:focus-visible {
  background: rgba(0, 0, 0, 0.06);
}
.message__quote-bar {
  width: 3px; border-radius: 2px; flex: 0 0 auto;
  background: var(--accent-500);
}
.message-row--own .message__quote-bar { background: #4a6b35; }
.message__quote-text { min-width: 0; }
.message__quote-name {
  font-size: 12px; font-weight: 600; color: var(--accent-500);
  line-height: 1.2;
  margin-bottom: 1px;
}
.message-row--own .message__quote-name { color: #3d5a2a; }
.message__quote-preview {
  font-size: 12px; line-height: 1.2;
  color: var(--fg-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: min(280px, 100%);
}
.message__bubble--deleted {
  font-style: italic;
  opacity: 0.8;
  color: var(--fg-muted);
}
.message-row--deleted .message__quote { opacity: 0.85; }

/* ПКМ-меню */
.message-ctx {
  min-width: 168px; padding: 4px 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}
.message-ctx__btn {
  display: block; width: 100%;
  margin: 0; padding: 9px 14px; border: none; background: none;
  font: inherit; font-size: 14px; text-align: left; cursor: pointer;
  color: var(--fg);
  transition: background 0.1s ease;
}
.message-ctx__btn:hover,
.message-ctx__btn:focus-visible {
  background: var(--bg-muted);
  outline: none;
}
.message-ctx__btn--danger { color: #c0392b; }
.message-ctx__btn--danger:hover,
.message-ctx__btn--danger:focus-visible { background: rgba(192, 57, 43, 0.1); }

.composer {
  display: flex; flex-direction: column;
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
  padding: 0;
  gap: 0;
}
.composer__reply {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 8px 12px; border-bottom: 1px solid var(--border);
  background: var(--bg-muted);
}
.composer__reply-goto {
  flex: 1; min-width: 0; margin: 0; padding: 0;
  border: none; border-radius: 8px;
  background: transparent; font: inherit; text-align: left;
  cursor: pointer; color: inherit;
  -webkit-tap-highlight-color: transparent;
}
.composer__reply-goto:hover,
.composer__reply-goto:focus-visible {
  background: rgba(0, 0, 0, 0.05);
  outline: none;
}
.composer__reply-text { flex: 1; min-width: 0; }
.composer__reply-line { font-size: 12px; color: var(--accent-500); font-weight: 600; }
.composer__reply-preview { font-size: 12px; color: var(--fg-muted); margin-top: 2px; line-height: 1.25; }
.composer__reply-close {
  flex: 0 0 28px; width: 28px; height: 28px; margin: 0; padding: 0; border: none;
  border-radius: 8px; background: transparent; color: var(--fg-muted);
  font-size: 20px; line-height: 1; cursor: pointer;
}
.composer__reply-close:hover { background: var(--bg-elevated); color: var(--fg); }

.composer__attach-opts {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px;
  padding: 8px 14px; border-bottom: 1px solid var(--border);
  background: var(--bg-muted);
  font-size: 12px; color: var(--fg);
}
.composer__opt { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }
.composer__opt input { width: 14px; height: 14px; accent-color: var(--accent-500); }
.composer__chips {
  list-style: none; margin: 0; padding: 6px 12px; border-bottom: 1px solid var(--border);
  display: flex; flex-wrap: wrap; gap: 6px; max-height: 120px; overflow-y: auto;
  background: var(--bg);
}
.composer__chip {
  display: inline-flex; align-items: center; gap: 4px; max-width: 100%;
  padding: 3px 6px 3px 8px; border-radius: 6px; background: var(--bg-muted);
  font-size: 12px; color: var(--fg); border: 1px solid var(--border);
}
.composer__chip-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.composer__chip-x {
  margin: 0; padding: 0 2px; border: none; background: none; cursor: pointer;
  font-size: 16px; line-height: 1; color: var(--fg-muted);
}
.composer__chip-x:hover { color: var(--fg); }

.composer__row {
  display: grid; grid-template-columns: 40px 1fr auto; gap: 4px 8px; align-items: center;
  padding: 12px 16px;
}
.composer__clip {
  display: grid; place-items: center; width: 40px; height: 40px; margin: 0; padding: 0;
  border: none; border-radius: 10px; background: transparent; color: var(--fg-muted);
  cursor: pointer; flex-shrink: 0;
  transition: background 0.12s ease, color 0.12s ease;
}
.composer__clip:hover:not(:disabled),
.composer__clip:focus-visible {
  background: var(--bg-muted); color: var(--accent-500); outline: none;
}
.composer__clip:disabled { opacity: 0.4; cursor: not-allowed; }
.composer__clip-ico {
  display: block;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  pointer-events: none;
  transform: translate(0.5px, 0.5px);
  opacity: 0.9;
  transition: opacity 0.12s ease;
}
.composer__clip:hover:not(:disabled) .composer__clip-ico,
.composer__clip:focus-visible:not(:disabled) .composer__clip-ico {
  opacity: 1;
}
.composer__input {
  border: 1px solid var(--border); background: var(--bg); color: var(--fg);
  border-radius: 999px; padding: 10px 16px; outline: none;
  transition: border-color 120ms ease;
}
.composer__input:focus { border-color: var(--accent-500); }
.composer__send {
  display: grid;
  place-items: center;
  padding: 6px 8px;
  margin: 0;
  min-width: 40px;
  min-height: 40px;
  background: transparent;
  border: none;
  color: var(--accent-500);
  cursor: pointer;
  box-shadow: none;
  border-radius: var(--radius-sm);
  transition: opacity 120ms ease, transform 80ms ease;
}
.composer__send:hover {
  background: transparent;
  color: var(--accent-300);
  opacity: 0.9;
}
.composer__send:disabled { opacity: 0.4; cursor: not-allowed; }
.composer__send-icon {
  display: block;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

/* ---- Профиль справа ---- */

.profile-pane {
  display: block;
  overflow-y: auto;
  padding: 20px 24px 40px;
}
.profile-stack {
  width: 100%;
  max-width: min(640px, 100%);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 22px;
  box-sizing: border-box;
}
.profile-flash {
  list-style: none;
  margin: 0 0 8px;
  padding: 10px 14px;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  border-radius: var(--radius-sm);
  background: rgba(141, 198, 98, 0.2);
  border: 1px solid var(--accent-300);
  color: var(--fg);
  font-size: 14px;
}
/* Секции профиля — только отступы, без линий-разделителей */
.profile-sec { margin: 0; padding: 0; }
.profile-block__h {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 600;
  color: var(--fg);
}
.profile-fields { display: grid; gap: 12px; }
/* Размер/цвет иконок (семейство задаётся стилями Google Fonts Material Symbols) */
.profile-ico {
  font-size: 24px;
  line-height: 1;
  color: var(--accent-500);
  user-select: none;
}
.profile-ico--btn {
  font-size: 20px;
  color: inherit;
  opacity: 0.95;
}
.profile-hero__page-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 16px;
}
.profile-hero__h1 { margin: 0; font-size: 26px; font-weight: 700; }
.profile-hero {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 20px 28px;
  align-items: start;
  padding: 0;
  margin: 0;
  border: none;
}
.profile-hero__subhead {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 600;
  color: var(--fg);
}
.profile-hero__avatar .profile-avatar-label {
  margin: 0;
  justify-items: start;
  max-width: none;
  gap: 0;
}
.profile-sec--actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 4px;
}
.profile-sec--actions .btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  box-sizing: border-box;
}
/* Выпадающий список темы */
select.select-theme {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding: 11px 44px 11px 14px;
  font-size: 14px;
  line-height: 1.4;
  font-weight: 500;
  color: var(--fg);
  background-color: var(--bg-elevated);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%236FA747' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 1.1rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
select.select-theme:hover {
  border-color: var(--accent-300);
}
select.select-theme:focus {
  outline: none;
  border-color: var(--accent-500);
  box-shadow: 0 0 0 3px rgba(111, 167, 71, 0.22);
}
[data-theme="dark"] select.select-theme {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23AFD895' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}
@media (prefers-color-scheme: dark) {
  [data-theme="system"] select.select-theme {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23AFD895' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  }
}
.profile-avatar-label {
  display: grid;
  justify-items: center;
  gap: 10px;
  cursor: pointer;
  max-width: 220px;
  margin: 0 auto;
}
.profile-avatar-target {
  position: relative;
  width: 112px;
  height: 112px;
  border-radius: 50%;
}
.profile-avatar-ring {
  width: 112px;
  height: 112px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--accent-300);
  box-shadow: 0 6px 24px rgba(111, 167, 71, 0.25);
  background: var(--bg-muted);
}
.profile-avatar-ring--fallback {
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, var(--accent-100), var(--accent-500));
  color: #0c1a08;
  font-size: 40px;
  font-weight: 800;
}
.profile-avatar-hint { font-size: 12px; color: var(--accent-500); text-align: center; }
.profile-avatar-input {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  margin: 0;
  padding: 0;
  opacity: 0;
  cursor: pointer;
  font-size: 0;
}
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---- Модалка ---- */

.modal {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: grid; place-items: center;
  z-index: 100;
}
.modal__card {
  background: var(--bg-elevated);
  border-radius: var(--radius);
  padding: 24px;
  width: min(420px, 90vw);
  display: grid; gap: 14px;
  box-shadow: var(--shadow);
}
.modal__card h3 { margin: 0; }

/* ===========================================================================
   Адаптив
   =========================================================================== */

@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .app--sidebar-rail { grid-template-columns: 52px 1fr; }
  .window__head, .composer__row { padding: 10px 12px; }
  .composer__reply { padding-left: 10px; padding-right: 10px; }
  .messages { padding: 10px; }
  .message-row--flash { --msg-bleed: 10px; }
  .profile-hero { grid-template-columns: 1fr; }
  .profile-pane { padding: 16px 14px 32px; }
}
