/* Qorgon v11.6 — rich messages, restored gestures, real preference binding and Telegram-style lazy media. */

/* Preference controls must beat older group/channel-specific selectors. */
.main-panel .content-feed .message {
  max-width: min(72%, var(--message-max-width)) !important;
}
.main-panel .content-feed .message.lesson,
.main-panel .content-feed .message.document,
.main-panel .content-feed .message.experiment,
.main-panel .content-feed .message.has-telegram-media {
  max-width: min(78%, calc(var(--message-max-width) + 100px)) !important;
}
.main-panel .content-feed .message-content {
  border-radius: var(--message-radius) !important;
}
.main-panel .content-feed .message-body,
.main-panel .content-feed .telegram-rich-text,
.main-panel .content-feed .telegram-rich-message,
.main-panel .content-feed .telegram-rich-message p,
.main-panel .content-feed .telegram-rich-message li,
.main-panel .content-feed .telegram-rich-message td,
.main-panel .content-feed .telegram-rich-message th {
  font-size: calc(14px * var(--message-scale)) !important;
  line-height: var(--message-line-height) !important;
}
.main-panel .composer textarea,
.comments-form textarea {
  font-size: calc(13px * var(--message-scale)) !important;
  line-height: var(--message-line-height) !important;
}

/* Leave room for the curved bubble corner and for group/comment avatars. */
.main-panel .message-author-line {
  padding-inline-start: 10px !important;
}
.main-panel.message-avatar-mode .content-feed {
  padding-left: 62px !important;
  overflow-x: visible;
}
.message.with-avatar {
  overflow: visible;
}
.message.with-avatar .message-avatar {
  left: -36px !important;
  z-index: 4;
}

/* Telegram 2026 RichMessage blocks. */
.telegram-rich-message {
  display: grid;
  gap: .5em;
  min-width: 0;
  overflow-wrap: anywhere;
}
.telegram-rich-message > * { margin: 0; }
.telegram-rich-message h1,
.telegram-rich-message h2,
.telegram-rich-message h3,
.telegram-rich-message h4,
.telegram-rich-message h5,
.telegram-rich-message h6 { margin: .18em 0; line-height: 1.16; }
.telegram-rich-message ul,
.telegram-rich-message ol { margin: .1em 0; padding-inline-start: 1.35em; }
.telegram-rich-message blockquote,
.telegram-rich-pullquote {
  margin: .15em 0;
  padding: .25em .6em;
  border-inline-start: 3px solid var(--teal);
  background: color-mix(in srgb, var(--teal) 8%, transparent);
}
.telegram-rich-message cite { display: block; margin-top: .25em; color: var(--muted); }
.telegram-rich-pre { margin: .2em 0; padding: .55em; overflow: auto; border-radius: 7px; background: color-mix(in srgb, var(--ink) 88%, transparent); }
.telegram-rich-divider { width: 100%; border: 0; border-top: 1px solid color-mix(in srgb, var(--text) 18%, transparent); }
.telegram-rich-details > summary { cursor: pointer; font-weight: 700; }
.telegram-rich-table-wrap { max-width: 100%; overflow: auto; }
.telegram-rich-table { border-collapse: collapse; width: 100%; }
.telegram-rich-table td,
.telegram-rich-table th { padding: .35em .45em; }
.telegram-rich-table.is-bordered td,
.telegram-rich-table.is-bordered th { border: 1px solid color-mix(in srgb, var(--text) 18%, transparent); }
.telegram-rich-table.is-striped tr:nth-child(even) { background: color-mix(in srgb, var(--text) 5%, transparent); }
.telegram-rich-embedded { display: grid; gap: .25em; margin: .15em 0; }
.telegram-rich-embedded > span { display: flex; align-items: center; gap: .4em; padding: .55em; border-radius: 8px; background: color-mix(in srgb, var(--surface-2) 88%, transparent); }
.telegram-rich-unsupported { padding: .4em .55em; border-left: 2px solid var(--amber); }

/* Visual media: tiny real Telegram thumbnail beneath a circular download control. */
.telegram-media-placeholder.is-visual {
  min-height: 150px;
  background: color-mix(in srgb, var(--surface-2) 88%, transparent);
}
.telegram-media-placeholder.is-visual .telegram-media-download-action {
  width: 52px;
  height: 52px;
  min-width: 52px;
  padding: 0;
  border-radius: 50%;
  background: rgba(11, 18, 24, .58);
}
.telegram-media-placeholder.is-visual .telegram-media-download-copy { display: none !important; }
.telegram-media-placeholder.is-visual .telegram-media-download-icon { width: 36px; height: 36px; background: transparent; }
.telegram-media-placeholder.is-visual .telegram-media-download-progress { bottom: 8px; }

/* Audio, voice and documents remain compact rows; never pretend they are images. */
.telegram-media-placeholder.is-compact-file {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  place-items: stretch;
  align-items: center;
  width: min(100%, 390px);
  min-width: 210px;
  min-height: 58px;
  padding: 7px 9px;
  gap: 8px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--surface-2) 91%, transparent);
}
.telegram-media-placeholder.is-compact-file .telegram-media-generic-preview { display: none; }
.telegram-media-placeholder.is-compact-file .telegram-media-download-action {
  display: contents;
  color: var(--text);
  background: transparent;
  backdrop-filter: none;
}
.telegram-media-placeholder.is-compact-file .telegram-media-download-icon {
  grid-column: 1;
  width: 40px;
  height: 40px;
  background: color-mix(in srgb, var(--teal) 18%, var(--surface-3));
  color: var(--teal);
}
.telegram-media-placeholder.is-compact-file .telegram-media-download-copy {
  grid-column: 2;
  display: grid !important;
  text-align: left;
}
.telegram-media-placeholder.is-compact-file .telegram-media-download-copy strong { max-width: 100%; font-size: 12px; }
.telegram-media-placeholder.is-compact-file .telegram-media-download-copy small { color: var(--muted); font-size: 10px; }
.telegram-media-placeholder.is-compact-file .telegram-media-download-progress {
  position: static;
  grid-column: 1 / -1;
  width: 100%;
  padding: 3px 0 0;
  color: var(--text);
  background: transparent;
  backdrop-filter: none;
}
.telegram-media-placeholder.is-compact-file .telegram-media-download-progress > span { background: color-mix(in srgb, var(--text) 14%, transparent); }
.telegram-media-placeholder.is-compact-file .telegram-media-download-progress small { color: var(--muted); }
.telegram-media-placeholder.is-compact-file .telegram-media-download-progress button { color: var(--muted); background: color-mix(in srgb, var(--text) 8%, transparent); }

@media (max-width: 760px) {
  .main-panel .content-feed .message { max-width: min(88%, var(--message-max-width)) !important; }
  .main-panel.message-avatar-mode .content-feed { padding-left: 50px !important; }
  .message.with-avatar .message-avatar { left: -31px !important; }
}
.telegram-media-visual-status {
  position: absolute !important;
  z-index: 3 !important;
  left: 50%;
  top: calc(50% + 33px);
  transform: translateX(-50%);
  padding: 2px 6px;
  border-radius: 99px;
  color: rgba(255,255,255,.9);
  font-size: 9px;
  white-space: nowrap;
  background: rgba(11,18,24,.48);
  backdrop-filter: blur(5px);
}
.telegram-media-placeholder.is-visual:has(.telegram-media-download-progress:not([hidden])) .telegram-media-visual-status { display: none; }
