:root {
  --bg: #0e1621;
  --dialogs-bg: #17212b;
  --chat-bg: #0e1621;
  --header-bg: #17212b;
  --composer-bg: #17212b;
  --line: #0a121a;
  --hover: #202b36;
  --active: #2b5278;
  --text: #f5f5f5;
  --muted: #6d7f8f;
  --accent: #64a9e5;
  --bubble-out: #2b5278;
  --bubble-in: #182533;
  --badge: #3e88c6;
  --radius-bubble: 12px;
  --dialogs-width: 340px;
  --dialogs-min: 72px;
  --dialogs-max: 480px;
  --dialogs-collapse-at: 120px;
  --scroll-thumb: rgba(255, 255, 255, 0.18);
  --scroll-thumb-hover: rgba(255, 255, 255, 0.32);
  font-family: "Roboto", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  touch-action: manipulation;
  -ms-touch-action: manipulation;
  overscroll-behavior: none;
}

body {
  overflow: auto;
}

/* Keep form controls ≥16px so mobile Safari does not auto-zoom on focus. */
input,
textarea,
select,
button {
  font-size: 16px;
}

body.lightbox-open {
  overflow: hidden;
}

#app {
  min-height: 100%;
}

#app:has(.chat-shell:not(.hidden)) {
  height: 100%;
  min-height: 0;
}

.panel {
  max-width: 420px;
  margin: 40px auto;
  padding: 20px;
  background: var(--dialogs-bg);
  border: 1px solid #243447;
  border-radius: 12px;
}

.hidden { display: none !important; }

h1, h2 { margin: 0 0 12px; font-weight: 600; }

.hint, .status { color: var(--muted); font-size: 0.95rem; }

label {
  display: grid;
  gap: 6px;
  margin: 12px 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.panel input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #243447;
  background: #0e1621;
  color: var(--text);
  font-size: 16px;
}

.panel button {
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  background: var(--accent);
  color: #0b141e;
  font-weight: 600;
  cursor: pointer;
}

.stack { display: grid; gap: 8px; }

/* —— Minimal scrollbars (Telegram-like) —— */
.thin-scroll {
  scrollbar-width: thin;
  scrollbar-color: transparent transparent;
}

.thin-scroll:hover,
.thin-scroll:focus-within,
.thin-scroll.is-scrolling {
  scrollbar-color: var(--scroll-thumb) transparent;
}

.thin-scroll::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.thin-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.thin-scroll::-webkit-scrollbar-thumb {
  background: transparent;
  border-radius: 8px;
}

.thin-scroll:hover::-webkit-scrollbar-thumb,
.thin-scroll:focus-within::-webkit-scrollbar-thumb,
.thin-scroll.is-scrolling::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
}

.thin-scroll::-webkit-scrollbar-thumb:hover {
  background: var(--scroll-thumb-hover);
}

/* —— Telegram-like shell —— */
.chat-shell,
.msg-menu,
.forward-modal,
.lightbox {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* Keep selection only where copying text is intentional */
.chat-shell input,
.chat-shell textarea,
.bubble .text,
.bubble .text * {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}

.chat-shell {
  display: flex;
  height: 100%;
  max-height: 100%;
  overflow: hidden;
  background: var(--bg);
}

.dialogs-pane {
  flex: 0 0 var(--dialogs-width);
  width: var(--dialogs-width);
  max-width: var(--dialogs-width);
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: var(--dialogs-bg);
  overflow: hidden;
}

.dialogs-resizer {
  flex: 0 0 4px;
  width: 4px;
  margin-left: -2px;
  margin-right: -2px;
  cursor: col-resize;
  position: relative;
  z-index: 5;
  background: transparent;
  touch-action: none;
}

.dialogs-resizer::after {
  content: "";
  position: absolute;
  inset: 0 -3px;
}

.dialogs-resizer:hover,
body.resizing-dialogs .dialogs-resizer {
  background: color-mix(in srgb, var(--accent) 55%, transparent);
}

body.resizing-dialogs {
  cursor: col-resize;
  user-select: none;
}

.dialogs-top {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 8px 8px 8px 10px;
  border-bottom: 1px solid var(--line);
  overflow: hidden;
  background: var(--dialogs-bg);
}

.folder-tabs {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 2px 0;
}

.folder-tabs::-webkit-scrollbar {
  display: none;
}

.folder-tab {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  margin: 0;
  padding: 7px 14px;
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.folder-tab:hover {
  background: rgba(255, 255, 255, 0.04);
}

.folder-tab.is-active {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.folder-tab-badge {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--badge);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
}

.folder-tab-badge.is-muted {
  background: rgba(255, 255, 255, 0.18);
  color: rgba(255, 255, 255, 0.85);
}

.conn-status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #3d9a5f;
  box-shadow: 0 0 0 3px rgba(61, 154, 95, 0.2);
  flex: 0 0 auto;
  margin-right: 6px;
}

.conn-status.is-offline {
  background: #c45c5c;
  box-shadow: 0 0 0 3px rgba(196, 92, 92, 0.22);
}

.dialogs-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.dialog {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid transparent;
}

.dialog:hover { background: var(--hover); }

.dialog.active { background: var(--active); }

.dialog-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 600;
  color: white;
  background: #65aadd;
  user-select: none;
  position: relative;
  flex: 0 0 auto;
  overflow: visible;
}

.dialog-avatar .avatar-letter,
.msg-avatar .avatar-letter {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  overflow: hidden;
}

.dialog-avatar img,
.msg-avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  z-index: 1;
  background: var(--dialogs-bg);
}

.dialog-body { min-width: 0; }

.dialog-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.dialog .title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dialog .time {
  color: var(--muted);
  font-size: 0.75rem;
  flex: 0 0 auto;
}

.dialog .preview {
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.dialog .preview.is-typing {
  color: var(--accent);
}

.dialog .badge {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  margin-top: 4px;
  border-radius: 10px;
  background: var(--badge);
  color: white;
  font-size: 0.72rem;
  font-weight: 700;
}

.dialog-avatar .badge-dot {
  position: absolute;
  right: -2px;
  bottom: -2px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--badge);
  color: white;
  font-size: 0.65rem;
  font-weight: 700;
  display: none;
  place-items: center;
  border: 2px solid var(--dialogs-bg);
  z-index: 3;
  pointer-events: none;
}

.badge.is-muted,
.dialog-avatar .badge-dot.is-muted {
  background: rgba(255, 255, 255, 0.22);
  color: rgba(255, 255, 255, 0.9);
}

/* Collapsed to icons only (Telegram desktop) */
.dialogs-pane.is-collapsed .folder-tabs {
  display: none;
}

.dialogs-pane.is-collapsed .dialogs-top {
  justify-content: center;
  padding: 0;
}

.dialogs-pane.is-collapsed .dialog {
  grid-template-columns: 1fr;
  justify-items: center;
  padding: 8px 0;
  gap: 0;
}

.dialogs-pane.is-collapsed .dialog-body {
  display: none;
}

.dialogs-pane.is-collapsed .dialog-avatar .badge-dot {
  display: grid;
}

.chat-pane {
  position: relative;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(circle at 20% 10%, rgba(50, 80, 120, 0.18), transparent 40%),
    radial-gradient(circle at 80% 90%, rgba(40, 70, 110, 0.14), transparent 35%),
    var(--chat-bg);
}

.chat-pane.is-empty .chat-footer,
.chat-pane.is-empty .chat-header-row,
.chat-pane.is-empty .pinned-bar {
  visibility: hidden;
}

.chat-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 10px 6px;
  background: transparent;
  border-bottom: 0;
  pointer-events: none;
}

.chat-header-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  pointer-events: auto;
}

.chat-back {
  flex: 0 0 auto;
  display: none;
  align-items: center;
  gap: 2px;
  min-width: 44px;
  height: 44px;
  padding: 0 10px 0 6px;
  border: 0;
  border-radius: 999px;
  background: rgba(23, 33, 43, 0.78);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  color: var(--text);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.chat-back-badge {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.92);
  color: #1a2430;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1;
}

.chat-header-info {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 6px 16px;
  border: 0;
  border-radius: 999px;
  background: rgba(23, 33, 43, 0.78);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  color: inherit;
  cursor: pointer;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
}

.chat-header-text {
  min-width: 0;
  width: 100%;
}

.chat-name {
  font-weight: 600;
  font-size: 0.98rem;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-subtitle {
  color: rgba(255, 255, 255, 0.55);
  font-size: 0.78rem;
  line-height: 1.2;
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-subtitle.is-accent {
  color: var(--accent);
}

.chat-header-avatar-btn {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.chat-header-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
  color: #fff;
  font-weight: 600;
  font-size: 0.95rem;
  background: #65aadd;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}

.chat-header-avatar .avatar-letter {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
}

.chat-header-avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.pinned-bar {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 8px 12px 8px 10px;
  border: 0;
  border-radius: 18px;
  background: rgba(23, 33, 43, 0.78);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.pinned-bar-accent {
  flex: 0 0 3px;
  align-self: stretch;
  min-height: 28px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.85);
}

.pinned-bar-body {
  flex: 1 1 auto;
  min-width: 0;
}

.pinned-bar-label {
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.2;
}

.pinned-bar-text {
  margin-top: 2px;
  color: rgba(255, 255, 255, 0.62);
  font-size: 0.82rem;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pinned-bar-icon {
  flex: 0 0 auto;
  color: rgba(255, 255, 255, 0.85);
  display: grid;
  place-items: center;
}

.icon-btn {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
}

.icon-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}

.icon-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.back-btn { display: none; }

.messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-anchor: none; /* JS anchors media/history; flex+anchor is flaky */
  overscroll-behavior: contain;
  /* --footer-h is measured from .chat-footer (composer + reply bar + sticker sheet). */
  padding: 72px 12px calc(var(--footer-h, 60px) + 20px);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-pane:has(.pinned-bar:not(.hidden)) .messages {
  padding-top: 128px;
}


.day-sep {
  align-self: center;
  margin: 10px 0;
  padding: 4px 10px;
  border-radius: 12px;
  background: rgba(24, 37, 51, 0.85);
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 500;
}

.message-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: min(75%, 520px);
  position: relative;
  overflow-anchor: auto;
}

.message-row.in {
  align-self: flex-start;
}

.message-row.out {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  position: relative;
  flex: 0 0 auto;
  overflow: visible;
  background: #65aadd;
  color: white;
  font-size: 0.75rem;
  font-weight: 600;
}

.msg-avatar .avatar-letter,
.msg-avatar img {
  border-radius: 50%;
  overflow: hidden;
}

.bubble {
  width: fit-content;
  max-width: 100%;
  min-width: 0;
  padding: 6px 10px 4px;
  border-radius: var(--radius-bubble);
  overflow-wrap: break-word;
  word-break: normal;
  line-height: 1.35;
  position: relative;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: visible;
}

.message-row.with-avatar {
  max-width: min(70%, 480px);
}

.bubble.out {
  background: var(--bubble-out);
  border-bottom-right-radius: 4px;
}

.bubble.in {
  background: var(--bubble-in);
  border-bottom-left-radius: 4px;
}

.bubble .sender {
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 2px;
}

.bubble .text {
  font-size: 0.95rem;
  white-space: pre-wrap;
}

.msg-mention,
.msg-tag {
  color: #6ab3f3;
  font-weight: 600;
}

.bubble.out .msg-mention,
.bubble.out .msg-tag {
  color: #c5e4ff;
}

.msg-link {
  color: #6ab3f3;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.bubble.out .msg-link {
  color: #c5e4ff;
}

.msg-bold { font-weight: 700; }
.msg-italic { font-style: italic; }
.msg-underline { text-decoration: underline; }
.msg-strike { text-decoration: line-through; }
.msg-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 4px;
  padding: 0 4px;
}
.msg-spoiler {
  background: rgba(255, 255, 255, 0.18);
  color: transparent;
  border-radius: 4px;
  transition: color 0.15s ease, background 0.15s ease;
}
.msg-spoiler:hover,
.msg-spoiler:focus {
  color: inherit;
  background: rgba(255, 255, 255, 0.08);
}

.bubble-media {
  margin: 2px 0 4px;
  align-self: stretch;
  line-height: 0;
}

.bubble-link-media {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px;
}

.media-link-gif img {
  background: rgba(0, 0, 0, 0.12);
}

.media-photo,
.media-sticker {
  display: block;
  border-radius: 10px;
  overflow: hidden;
  line-height: 0;
  isolation: isolate;
  cursor: zoom-in;
  border: 0;
  padding: 0;
  background: rgba(0, 0, 0, 0.18);
  width: auto;
  max-width: 100%;
  flex: 0 0 auto;
}

.media-sticker {
  background: transparent;
  border-radius: 0;
}

.media-photo img {
  display: block;
  max-width: min(100%, 360px);
  max-height: 420px;
  width: auto;
  height: auto;
  object-fit: cover;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 10px;
  vertical-align: top;
}

.media-sticker img,
.media-sticker .sticker-visual,
.media-sticker .sticker-video,
.media-sticker .sticker-lottie,
.media-sticker .sticker-lottie-fallback {
  display: block;
  max-width: 160px;
  max-height: 160px;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: transparent;
  border-radius: 0;
}

.sticker-visual {
  position: relative;
  width: 100%;
  height: 100%;
  line-height: 0;
}

.sticker-video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: transparent;
  border: 0;
}

.sticker-lottie {
  width: 100%;
  height: 100%;
}

.sticker-lottie svg {
  width: 100% !important;
  height: 100% !important;
}

.sticker-lottie-fallback {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.media-video {
  display: block;
  max-width: min(100%, 360px);
  max-height: 320px;
  border-radius: 10px;
  background: #000;
}

/* Photo/video without caption: no bubble frame */
.bubble.bubble-media-only {
  padding: 0;
  gap: 0;
  background: transparent;
  box-shadow: none;
  overflow: hidden;
}

.bubble.bubble-media-only.out,
.bubble.bubble-media-only.in {
  background: transparent;
}

.bubble.bubble-media-only .bubble-media {
  margin: 0;
}

.bubble.bubble-media-only .media-photo,
.bubble.bubble-media-only .media-video,
.bubble.bubble-media-only .media-sticker {
  border-radius: 0;
}

.bubble.bubble-media-only .media-photo img,
.bubble.bubble-media-only .media-video {
  max-width: min(100%, 360px);
  width: auto;
  border-radius: 0;
}

.bubble.bubble-media-only .media-sticker img,
.bubble.bubble-media-only .media-sticker .sticker-visual,
.bubble.bubble-media-only .media-sticker .sticker-video,
.bubble.bubble-media-only .media-sticker .sticker-lottie {
  max-width: 180px;
  max-height: 180px;
  background: transparent;
  border-radius: 0;
}

.bubble.bubble-media-only.is-sticker {
  background: transparent;
  box-shadow: none;
}

.bubble.bubble-media-only.is-sticker .meta-row {
  background: rgba(0, 0, 0, 0.45);
}

.bubble.bubble-media-only .meta-row {
  position: absolute;
  right: 6px;
  bottom: 5px;
  margin: 0;
  padding: 1px 6px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.45);
  align-self: auto;
}

.bubble.bubble-media-only .time,
.bubble.bubble-media-only .checks {
  color: rgba(255, 255, 255, 0.92);
}

.bubble.bubble-media-only .sender {
  padding: 0 4px 4px;
  margin: 0;
}

/* Photo/video + caption: image flush, caption under without side gaps */
.bubble.bubble-media-caption {
  padding: 0;
  gap: 0;
  overflow: hidden;
  max-width: min(70%, 360px);
}

.message-row.with-avatar .bubble.bubble-media-caption {
  max-width: 100%;
}

.bubble.bubble-media-caption > .msg-reply,
.bubble.bubble-media-caption > .msg-forward,
.bubble.bubble-media-caption > .sender {
  margin-left: 10px;
  margin-right: 10px;
}

.bubble.bubble-media-caption > .sender {
  padding-top: 6px;
  margin-bottom: 2px;
}

.bubble.bubble-media-caption > .msg-forward {
  margin-top: 6px;
}

.bubble.bubble-media-caption > .msg-reply {
  margin-top: 4px;
  margin-bottom: 6px;
}

.bubble.bubble-flash {
  outline: 2px solid rgba(106, 179, 243, 0.85);
  outline-offset: 2px;
  transition: outline-color 0.8s ease;
}

.bubble.bubble-media-caption .bubble-media {
  margin: 0;
}

.bubble.bubble-media-caption .media-photo,
.bubble.bubble-media-caption .media-video {
  border-radius: 0;
}

.bubble.bubble-media-caption .media-photo img,
.bubble.bubble-media-caption .media-video {
  width: 100%;
  max-width: 100%;
  max-height: 420px;
  height: auto;
  object-fit: contain;
  border-radius: 0;
  background: #000;
}

.bubble.bubble-media-caption .bubble-caption {
  padding: 6px 10px 5px;
  line-height: 1.35;
}

.bubble.bubble-media-caption .bubble-caption .text {
  white-space: pre-wrap;
}

.bubble.bubble-media-caption .bubble-caption .meta-row {
  display: inline-flex;
  margin: 0 0 0 8px;
  vertical-align: bottom;
  align-self: auto;
  float: none;
}

.media-audio {
  width: min(100%, 280px);
  margin: 4px 0;
}

.media-file {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.18);
  color: inherit;
  text-decoration: none;
  max-width: 280px;
}

.media-file:hover {
  background: rgba(0, 0, 0, 0.28);
}

.file-icon {
  font-size: 1.2rem;
}

.file-meta {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.file-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-size {
  color: var(--muted);
  font-size: 0.75rem;
}

.media-fallback {
  color: var(--muted);
  font-size: 0.9rem;
  padding: 4px 0;
}

.bubble .meta-row {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
  align-self: flex-end;
  flex-shrink: 0;
  white-space: nowrap;
}

.bubble .time {
  color: rgba(255, 255, 255, 0.45);
  font-size: 0.7rem;
  white-space: nowrap;
}

.bubble.out .time { color: rgba(185, 214, 240, 0.75); }

/* Fixed box so sending → sent → read never changes the bubble width. */
.bubble .checks {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 14px;
  color: #7ec0f5;
  line-height: 1;
  flex-shrink: 0;
}

.bubble .checks svg {
  display: block;
}

.bubble .checks[data-state="sending"] {
  color: rgba(185, 214, 240, 0.75);
}

.bubble .checks[data-state="failed"] {
  cursor: pointer;
}

.bubble .edited {
  color: rgba(255, 255, 255, 0.45);
  font-size: 0.7rem;
  white-space: nowrap;
}

.bubble.out .edited { color: rgba(185, 214, 240, 0.75); }

.bubble.bubble-media-only .edited {
  color: rgba(255, 255, 255, 0.92);
}

.chat-footer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 10px calc(8px + env(safe-area-inset-bottom));
  pointer-events: none;
}

.chat-footer > * {
  pointer-events: auto;
}

.composer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 2px;
  min-height: 48px;
  padding: 4px 6px 4px 8px;
  border-radius: 24px;
  background: rgba(23, 33, 43, 0.78);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 0;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.22);
}

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  width: 100%;
}

.composer-circle {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 50%;
  background: rgba(23, 33, 43, 0.72);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  color: var(--text);
  display: grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  -webkit-tap-highlight-color: transparent;
}

.composer-circle:disabled {
  opacity: 0.55;
  cursor: default;
}

.composer-pill {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  /* Multi-line draft grows upward; buttons stay on the last line like Telegram. */
  align-items: flex-end;
  gap: 2px;
  min-height: 44px;
  padding: 4px 8px 4px 14px;
  border-radius: 22px;
  background: rgba(20, 28, 38, 0.55);
  backdrop-filter: blur(22px) saturate(1.2);
  -webkit-backdrop-filter: blur(22px) saturate(1.2);
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.22);
}

.composer-side {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

/* Floats above the mic button: showing/hiding it must not change the footer
   height (that would resize the list padding and re-stick to the bottom). */
.scroll-bottom-btn {
  position: absolute;
  left: 0;
  bottom: calc(100% + 8px);
  animation: scroll-bottom-in 0.18s ease-out;
}

@keyframes scroll-bottom-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.composer-sticker-btn,
.composer-send-inline {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: rgba(255, 255, 255, 0.78);
  display: grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
}

.composer-sticker-btn:disabled,
.composer-send-inline:disabled {
  opacity: 0.4;
  cursor: default;
}

.composer-send-inline {
  color: var(--accent);
}

.sticker-backdrop {
  position: absolute;
  inset: 0;
  z-index: 2;
  border: 0;
  padding: 0;
  margin: 0;
  background: transparent;
  cursor: default;
}

.sticker-backdrop.hidden {
  display: none;
}

.sticker-sheet {
  margin-top: 2px;
  max-height: min(52vh, 460px);
  border-radius: 18px 18px 14px 14px;
  background: rgba(18, 24, 32, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.08);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.35);
  animation: sticker-sheet-in 0.22s ease-out;
}

.sticker-sheet.hidden {
  display: none;
}

@keyframes sticker-sheet-in {
  from { opacity: 0; transform: translateY(24px); }
  to { opacity: 1; transform: translateY(0); }
}

.sticker-sheet-handle {
  flex: 0 0 auto;
  width: 36px;
  height: 4px;
  margin: 10px auto 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.22);
}

.sticker-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 8px 8px;
  -webkit-overflow-scrolling: touch;
}

.sticker-pack {
  margin-bottom: 10px;
}

.sticker-pack-title {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 8px 6px 6px;
  font-size: 0.78rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.62);
  background: linear-gradient(rgba(18, 24, 32, 0.98), rgba(18, 24, 32, 0.92));
}

.sticker-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  padding: 0 2px;
}

.sticker-tabs {
  flex: 0 0 auto;
  display: flex;
  gap: 4px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.sticker-tabs::-webkit-scrollbar {
  display: none;
}

.sticker-tab {
  flex: 0 0 auto;
  min-width: 40px;
  height: 36px;
  padding: 0 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: rgba(255, 255, 255, 0.7);
  font: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
  max-width: 96px;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

.sticker-tab.is-active {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.sticker-cell {
  aspect-ratio: 1;
  border: 0;
  border-radius: 10px;
  background: transparent;
  padding: 4px;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.sticker-cell:hover,
.sticker-cell:active {
  background: rgba(255, 255, 255, 0.06);
}

.sticker-cell img,
.sticker-cell .sticker-visual,
.sticker-cell .sticker-video,
.sticker-cell .sticker-lottie {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.sticker-empty {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  padding: 24px 8px;
}


.reply-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0;
  margin: 0;
  padding: 8px 8px 8px 10px;
  border-radius: 18px;
  background: rgba(20, 28, 38, 0.55);
  backdrop-filter: blur(22px) saturate(1.2);
  -webkit-backdrop-filter: blur(22px) saturate(1.2);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.18);
}

.reply-bar.hidden {
  display: none;
}

.reply-bar-accent {
  width: 3px;
  align-self: stretch;
  min-height: 28px;
  border-radius: 2px;
  background: var(--accent);
  margin-right: 10px;
  flex: 0 0 auto;
}

.reply-bar-body {
  min-width: 0;
  flex: 1 1 auto;
  padding: 2px 4px;
  margin: 0;
  border-radius: 0;
  background: transparent;
}

.reply-bar-title {
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 600;
}

.reply-bar-text {
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reply-bar-close {
  color: var(--muted);
  font-size: 1.2rem;
  align-self: center;
}

.msg-forward {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 600;
  margin-bottom: 2px;
}

.msg-forward-icon {
  font-size: 0.85rem;
  opacity: 0.9;
}

.msg-reply {
  display: flex;
  align-items: stretch;
  gap: 8px;
  margin: 0 0 4px;
  padding: 4px 8px 4px 0;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  background: rgba(106, 179, 243, 0.18);
  max-width: 100%;
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
}

.msg-reply-accent {
  width: 3px;
  border-radius: 2px 0 0 2px;
  background: var(--accent);
  flex: 0 0 auto;
}

.msg-reply-body {
  min-width: 0;
  padding: 2px 0;
}

.msg-reply-name {
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg-reply-text {
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.message-row.is-swiping {
  z-index: 2;
}

.message-row.is-swiping .bubble {
  will-change: transform;
}

.message-row.in.is-swiping::before,
.message-row.out.is-swiping::after {
  content: "↩";
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(106, 179, 243, 0.2);
  color: var(--accent);
  font-size: 0.9rem;
  pointer-events: none;
}

.message-row.in.is-swiping::before {
  left: 4px;
}

.message-row.out.is-swiping::after {
  right: 4px;
}

/* Telegram-like message context menu */
.msg-menu {
  position: fixed;
  inset: 0;
  z-index: 45;
}

.msg-menu.hidden {
  display: none !important;
}

.msg-menu-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  padding: 0;
  margin: 0;
  background: transparent;
  cursor: default;
}

.msg-menu.is-sheet .msg-menu-backdrop {
  background: rgba(0, 0, 0, 0.45);
}

.msg-menu-panel {
  position: absolute;
  min-width: 220px;
  padding: 8px;
  border-radius: 14px;
  background: #1c2733;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.04);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.msg-menu.is-sheet {
  display: grid;
  place-items: end center;
}

.msg-menu.is-sheet .msg-menu-panel {
  position: relative;
  width: min(100%, 420px);
  border-radius: 14px 14px 0 0;
  padding: 12px 10px calc(12px + env(safe-area-inset-bottom));
  min-width: 0;
}

.msg-react-bar,
.msg-react-more {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 2px;
  padding: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  min-height: 44px;
}

.msg-react-more {
  flex-wrap: wrap;
  border-radius: 12px;
  justify-content: flex-start;
}

.msg-react-more.hidden {
  display: none;
}

.msg-react-btn,
.msg-react-more-btn {
  border: 0;
  background: transparent;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 1.25rem;
  line-height: 1;
  color: var(--text);
}

.msg-react-btn:hover,
.msg-react-more-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

.msg-react-btn.is-chosen {
  background: rgba(106, 179, 243, 0.22);
}

.msg-react-more-btn {
  color: var(--muted);
}

.msg-menu-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 2px 0;
}

.msg-menu-item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.98rem;
  text-align: left;
  padding: 11px 12px;
  border-radius: 10px;
  cursor: pointer;
}

.msg-menu-item:hover,
.msg-menu-item:focus-visible {
  background: rgba(255, 255, 255, 0.06);
  outline: none;
}

.msg-menu-item:disabled {
  opacity: 0.4;
  cursor: default;
}

.msg-menu-item:disabled:hover {
  background: transparent;
}

.msg-menu-item-danger {
  color: #e36d6d;
}

.msg-menu-icon {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  color: inherit;
  opacity: 0.92;
}

.msg-menu-item-danger .msg-menu-icon {
  color: #e36d6d;
}

.bubble-stack {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  max-width: 100%;
  min-width: 0;
  gap: 2px;
}

.message-row.out .bubble-stack {
  align-items: flex-end;
}

.msg-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: -2px;
  padding: 0 2px;
  position: relative;
  z-index: 2;
  max-width: 100%;
}

.msg-reaction-chip {
  border: 1px solid rgba(255, 255, 255, 0.08);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #1a2430;
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.msg-reaction-chip.is-chosen {
  background: rgba(106, 179, 243, 0.28);
  border-color: rgba(106, 179, 243, 0.45);
}

.msg-reaction-emoji {
  font-size: 1rem;
  line-height: 1;
}

.msg-reaction-count {
  color: rgba(255, 255, 255, 0.8);
  font-size: 0.8rem;
}

.forward-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.55);
  display: grid;
  place-items: end center;
  padding: 0;
}

.forward-modal.hidden {
  display: none;
}

.forward-sheet {
  width: min(100%, 420px);
  max-height: min(78vh, 640px);
  background: var(--panel, #17212b);
  border-radius: 14px 14px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.35);
}

.forward-sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.forward-sheet-title {
  font-weight: 700;
}

.forward-preview {
  padding: 10px 14px;
  color: var(--muted);
  font-size: 0.85rem;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.forward-dialogs {
  overflow: auto;
  flex: 1 1 auto;
  -webkit-overflow-scrolling: touch;
}

.forward-dialog {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  padding: 10px 14px;
  cursor: pointer;
  font: inherit;
}

.forward-dialog:hover {
  background: var(--hover);
}

.forward-dialog .dialog-avatar {
  width: 40px;
  height: 40px;
  font-size: 0.9rem;
}

.forward-dialog-title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (min-width: 801px) {
  .forward-modal {
    place-items: center;
    padding: 24px;
  }

  .forward-sheet {
    border-radius: 14px;
    max-height: min(70vh, 560px);
  }
}

.composer-field {
  flex: 1 1 auto;
  min-width: 0;
}

.composer-field textarea {
  display: block;
  width: 100%;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 16px;
  line-height: 1.35;
  padding: 9px 4px;
  margin: 0;
  resize: none;
  overflow-y: hidden;
  max-height: 160px;
}

.composer-field textarea::placeholder { color: var(--muted); }

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

.send-btn:disabled { color: var(--muted); }

/* —— Photo lightbox (Telegram-like) —— */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  grid-template-rows: 1fr auto;
  background: rgba(0, 0, 0, 0.92);
  color: #fff;
  user-select: none;
}

.lightbox.hidden {
  display: none !important;
}

.lightbox-stage {
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 48px 64px 24px;
  touch-action: pan-y;
}

.lightbox-stage img {
  max-width: min(96vw, 1400px);
  max-height: calc(100vh - 96px);
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.45);
}

.lightbox-btn {
  position: absolute;
  border: 0;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
}

.lightbox-btn:hover {
  background: rgba(255, 255, 255, 0.16);
}

.lightbox-close {
  top: 14px;
  right: 14px;
  font-size: 1.8rem;
}

.lightbox-prev {
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
}

.lightbox-next {
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
}

.lightbox-btn:disabled {
  opacity: 0.25;
  cursor: default;
}

.lightbox-counter {
  text-align: center;
  padding: 0 16px 18px;
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.9rem;
}

@media (max-width: 800px) {
  .lightbox-stage {
    padding: 56px 12px 16px;
  }

  .lightbox-prev,
  .lightbox-next {
    display: none;
  }

  .chat-shell {
    display: grid;
    grid-template-columns: 1fr;
  }

  .dialogs-pane {
    flex: none;
    width: 100% !important;
    max-width: none !important;
  }

  .dialogs-resizer { display: none; }

  .chat-shell.show-chat .dialogs-pane { display: none; }
  .chat-shell:not(.show-chat) .chat-pane { display: none; }

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

  .message-row { max-width: 88%; }
  .message-row.with-avatar { max-width: 88%; }

  .dialogs-pane.is-collapsed .dialog-body { display: block; }
  .dialogs-pane.is-collapsed .folder-tabs { display: flex; }
  .dialogs-pane.is-collapsed .dialogs-top {
    justify-content: flex-start;
    padding: 8px 8px 8px 10px;
  }
  .dialogs-pane.is-collapsed .dialog {
    grid-template-columns: 48px minmax(0, 1fr);
    justify-items: stretch;
    padding: 10px 14px;
    gap: 12px;
  }
  .dialogs-pane.is-collapsed .dialog-avatar .badge-dot { display: none; }
}


/* —— Unread divider (Telegram "Unread messages") —— */
.unread-divider {
  align-self: stretch;
  margin: 8px -12px;
  padding: 5px 0;
  text-align: center;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--accent);
  background: rgba(23, 33, 43, 0.85);
}

/* —— Floating date while scrolling —— */
.floating-date {
  position: absolute;
  left: 50%;
  z-index: 2;
  transform: translateX(-50%);
  padding: 4px 10px;
  border-radius: 12px;
  background: rgba(24, 37, 51, 0.85);
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 500;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.floating-date.is-visible {
  opacity: 1;
}

/* —— Scroll-down button unread badge —— */
.scroll-bottom-badge {
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--badge);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 20px;
  text-align: center;
  pointer-events: none;
}

/* —— Albums —— */
.album-grid {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: min(340px, 68vw);
  max-width: 100%;
  overflow: hidden;
  border-radius: inherit;
}

.album-row {
  display: flex;
  gap: 2px;
  width: 100%;
}

.album-tile {
  position: relative;
  flex-basis: 0;
  min-width: 0;
  padding: 0;
  border: 0;
  background: rgba(255, 255, 255, 0.06);
  cursor: pointer;
  overflow: hidden;
}

.album-tile img,
.album-tile video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.album-play {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  pointer-events: none;
}

.album-stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
