.telegram-avatar {
  position: relative;
  overflow: hidden;
  flex: 0 0 auto;
}

.telegram-avatar .avatar-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
}

.telegram-avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
  background: var(--surface-2);
}

.telegram-message-media {
  margin-top: 7px;
  max-width: min(560px, 72vw);
}

.telegram-message-image,
.telegram-message-video {
  display: block;
  width: min(100%, 520px);
  max-height: 520px;
  object-fit: contain;
  border-radius: calc(var(--message-radius) - 4px);
  background: #05070b;
}

.telegram-message-video.video-note {
  width: min(280px, 70vw);
  aspect-ratio: 1;
  border-radius: 50%;
  object-fit: cover;
}

.telegram-sticker {
  display: block;
  width: min(220px, 52vw);
  max-height: 220px;
  object-fit: contain;
}

.telegram-message-audio {
  width: min(380px, 70vw);
  min-width: 240px;
}

.telegram-media-placeholder,
.telegram-document-link {
  width: min(420px, 70vw);
  min-height: 68px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--text);
  background: color-mix(in srgb, var(--surface-2) 82%, transparent);
  text-align: left;
  text-decoration: none;
  overflow: hidden;
}

.telegram-media-placeholder::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: var(--telegram-thumb);
  background-size: cover;
  background-position: center;
  opacity: 0.12;
  filter: blur(8px);
}

.telegram-media-placeholder {
  position: relative;
}

.telegram-media-placeholder > * {
  position: relative;
  z-index: 1;
}

.telegram-media-placeholder svg,
.telegram-document-link svg {
  width: 26px;
  height: 26px;
  color: var(--blue);
  flex: 0 0 auto;
}

.telegram-media-placeholder span,
.telegram-document-link span {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.telegram-media-placeholder strong,
.telegram-document-link span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.telegram-media-placeholder small,
.telegram-document-link small {
  color: var(--muted);
}

.telegram-bot-keyboard button,
.telegram-bot-keyboard a {
  min-height: 34px;
  display: grid;
  place-items: center;
  padding: 7px 12px;
  border: 1px solid color-mix(in srgb, var(--blue) 35%, var(--line));
  border-radius: 9px;
  color: var(--blue);
  background: var(--blue-soft);
  text-decoration: none;
  font-weight: 700;
}

.telegram-bot-keyboard button:hover,
.telegram-bot-keyboard a:hover {
  filter: brightness(1.06);
}

.telegram-bot-keyboard button:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.settings-subsection-head {
  display: grid;
  gap: 3px;
  margin-top: 12px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.settings-subsection-head small {
  color: var(--muted);
}

.member-preview-avatar {
  position: relative;
  overflow: hidden;
}

.member-preview-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
}

.telegram-bot-keyboard-row button:not(:disabled) {
  cursor: pointer;
  opacity: 1;
}

.message-avatar.telegram-avatar {
  position: absolute;
  overflow: hidden;
}

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

/* V10.1 albums and persistent audio */
.telegram-album-grid {
  display: grid;
  width: min(520px, 72vw);
  max-height: 620px;
  gap: 3px;
  overflow: hidden;
  border-radius: calc(var(--message-radius) - 2px);
  background: color-mix(in srgb, var(--surface-2) 82%, transparent);
}

.telegram-album-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.telegram-album-grid.three { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.telegram-album-grid.three .telegram-album-item:first-child { grid-row: span 2; }
.telegram-album-grid.many { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.telegram-album-item {
  display: grid;
  min-width: 0;
  min-height: 150px;
  overflow: hidden;
  background: color-mix(in srgb, var(--surface-2) 86%, transparent);
}

.telegram-album-item .telegram-message-image,
.telegram-album-item .telegram-message-video,
.telegram-album-item .telegram-media-placeholder {
  width: 100%;
  height: 100%;
  min-height: 150px;
  max-height: 310px;
  object-fit: cover;
  border-radius: 0;
}

.telegram-audio-trigger {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  width: min(360px, 68vw);
  padding: 9px 12px;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 16px;
  background: color-mix(in srgb, var(--surface-2) 86%, transparent);
  text-align: left;
}

.telegram-audio-trigger > i {
  width: 38px;
  height: 38px;
  padding: 9px;
  border-radius: 50%;
  color: #fff;
  background: linear-gradient(135deg, var(--blue), var(--teal));
}

.telegram-audio-trigger span { display: grid; min-width: 0; gap: 2px; }
.telegram-audio-trigger strong,
.telegram-audio-trigger small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.telegram-audio-trigger small { color: var(--muted); }

.telegram-audio-trigger.telegram-voice-trigger {
  grid-template-columns: 36px minmax(0, 1fr) !important;
  grid-template-rows: 23px auto;
  gap: 2px 9px;
  width: min(260px, 100%);
  min-width: min(210px, 62vw);
  max-width: 100%;
  padding: 7px 9px;
  border: 0;
}

.telegram-voice-trigger .telegram-audio-icon {
  grid-area: 1 / 1 / 3 / 2;
  width: 36px;
  height: 36px;
}

.telegram-voice-trigger .telegram-audio-time { grid-area: 2 / 2; justify-self: start; }

.telegram-voice-trigger:not(:has(.telegram-voice-waveform)) {
  grid-template-rows: auto;
  min-width: 88px;
  width: auto;
}

.telegram-voice-trigger:not(:has(.telegram-voice-waveform)) .telegram-audio-time { grid-area: 1 / 2; }

.telegram-voice-trigger .telegram-voice-waveform {
  position: relative;
  display: block;
  grid-area: 1 / 2;
  height: 23px;
}

.telegram-voice-waveform .telegram-voice-bars {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  gap: 1px;
  color: var(--muted);
}

.telegram-voice-waveform .telegram-voice-bars.is-played {
  color: var(--teal);
  clip-path: inset(0 calc(100% - var(--voice-progress, 0%)) 0 0);
}

.telegram-voice-waveform .telegram-voice-bars > span {
  flex: 1 1 0;
  min-width: 0;
  height: calc(2px + var(--voice-level) * .59px);
  border-radius: 1px;
  background: currentColor;
}

.telegram-message-media .telegram-media-placeholder.is-voice-preview {
  width: fit-content;
  min-width: 0;
  max-width: 100%;
  min-height: 0;
  background: transparent;
}

.is-voice-preview .telegram-voice-trigger[hidden] { display: none; }
.is-voice-preview .telegram-media-download-progress:not([hidden]) {
  position: relative;
  inset: auto;
  min-width: min(190px, 60vw);
}


.qorgon-global-audio {
  display: grid;
  grid-template-columns: 28px minmax(120px, 260px) auto minmax(90px, 1fr) auto 26px;
  align-items: center;
  gap: 7px;
  width: min(640px, 48vw);
  min-width: 300px;
  min-height: 38px;
  margin-left: auto;
  padding: 2px 8px;
  color: var(--text);
  border: 1px solid color-mix(in srgb, var(--line) 75%, transparent);
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface-2) 78%, transparent);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.08);
  backdrop-filter: blur(16px) saturate(1.15);
}
.qorgon-global-audio[hidden] { display: none; }
.qorgon-global-audio audio { display: none; }
.qorgon-audio-play,
.qorgon-audio-close {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  color: var(--text);
  border: 0;
  border-radius: 50%;
  background: transparent;
}
.qorgon-audio-play { color: var(--teal); }
.qorgon-audio-play:hover,
.qorgon-audio-close:hover { background: color-mix(in srgb, var(--blue) 14%, transparent); }
.qorgon-audio-copy { display: grid; min-width: 0; gap: 0; }
.qorgon-audio-copy strong,
.qorgon-audio-copy small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qorgon-audio-copy strong { font-size: 11px; }
.qorgon-audio-copy small { color: var(--muted); font-size: 9px; }
.qorgon-audio-time { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 9px; }
.qorgon-global-audio input[type="range"] { width: 100%; min-width: 0; accent-color: var(--blue); }

@media (max-width: 900px) {
  .qorgon-global-audio { width: min(420px, 54vw); grid-template-columns: 26px minmax(0, 1fr) minmax(70px, 1fr) 26px; min-width: 220px; }
  .qorgon-audio-time { display: none; }
}
@media (max-width: 620px) {
  .qorgon-global-audio { width: auto; min-width: 0; flex: 1; grid-template-columns: 26px minmax(0, 1fr) 26px; }
  .qorgon-global-audio input { display: none; }
  .topbar .brand p { display: none; }
}


.telegram-image-button {
  display: block;
  max-width: 100%;
  padding: 0;
  border: 0;
  border-radius: inherit;
  background: transparent;
  overflow: hidden;
  cursor: zoom-in;
}

.telegram-image-button .telegram-message-image { display: block; }
body.telegram-lightbox-open { overflow: hidden; }
.telegram-lightbox {
  position: fixed;
  z-index: 9000;
  inset: 0;
  display: grid;
  place-items: center;
}
.telegram-lightbox[hidden] { display: none; }
.telegram-lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 8, 14, 0.88);
  backdrop-filter: blur(12px);
}
.telegram-lightbox-dialog {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) 52px;
  grid-template-rows: 48px minmax(0, 1fr) 32px;
  width: min(96vw, 1400px);
  height: min(94vh, 940px);
  color: #fff;
}
.telegram-lightbox-dialog header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.telegram-lightbox-dialog header > div { display: flex; gap: 8px; }
.telegram-lightbox-dialog header button,
.telegram-lightbox-dialog header a,
.telegram-lightbox-nav {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  color: #fff;
  border-radius: 50%;
  background: rgba(255,255,255,0.12);
}
.telegram-lightbox-dialog > img {
  grid-column: 2;
  grid-row: 2;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
}
.telegram-lightbox-nav { align-self: center; }
.telegram-lightbox-nav.prev { grid-column: 1; grid-row: 2; }
.telegram-lightbox-nav.next { grid-column: 3; grid-row: 2; }
.telegram-lightbox-dialog footer {
  grid-column: 1 / -1;
  display: grid;
  place-items: center;
  font-size: 12px;
  color: rgba(255,255,255,0.74);
}

.telegram-upload-tray {
  display: grid;
  gap: 8px;
  margin: 0 8px 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: color-mix(in srgb, var(--surface-2) 92%, transparent);
}
.telegram-upload-tray[hidden] { display: none; }
.telegram-upload-tray > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.telegram-upload-tray > header > div { display: grid; gap: 1px; }
.telegram-upload-tray > header small { color: var(--muted); }
.telegram-upload-tray > header button,
.telegram-upload-add {
  color: var(--blue);
  background: transparent;
  font-weight: 800;
}
.telegram-upload-items {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}
.telegram-upload-item {
  position: relative;
  flex: 0 0 176px;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 24px;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
}
.telegram-upload-item > img,
.telegram-upload-item > span {
  width: 48px;
  height: 48px;
  object-fit: cover;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--surface-2);
}
.telegram-upload-item > div { display: grid; min-width: 0; gap: 2px; }
.telegram-upload-item strong,
.telegram-upload-item small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.telegram-upload-item small { color: var(--muted); }
.telegram-upload-item > button {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  color: var(--muted);
  border-radius: 50%;
  background: var(--surface-2);
}
.telegram-upload-add {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.telegram-upload-add svg { width: 15px; height: 15px; }

/* V10.3 compact Telegram message presentation */
.message-link {
  color: var(--blue);
  font-weight: 650;
  text-decoration: none;
  overflow-wrap: anywhere;
}
.message-link:hover { text-decoration: underline; }
.message-link:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--blue) 48%, transparent);
  outline-offset: 2px;
  border-radius: 3px;
}

.message.has-telegram-media .message-content {
  gap: 0;
  padding: 0;
  border-width: 1px;
  border-radius: min(var(--message-radius), 16px);
  overflow: hidden;
}
.message.has-telegram-media .message-content::before { opacity: 0.18; }
.message.has-telegram-media .telegram-message-media {
  margin: 0;
  max-width: min(560px, 76vw);
}
.message.has-telegram-media .telegram-message-image,
.message.has-telegram-media .telegram-message-video {
  width: min(100%, 560px);
  max-height: 620px;
  border-radius: 0;
}
.message.has-telegram-media .telegram-album-grid {
  width: min(560px, 76vw);
  border-radius: 0;
  background: transparent;
}
.message.has-telegram-media .message-author-line,
.message.has-telegram-media .reply-card,
.message.has-telegram-media .forward-card,
.message.has-telegram-media .reference-card {
  margin-inline: 9px;
}
.message.has-telegram-media .message-author-line { margin-top: 7px; }
.message.has-telegram-media .message-body {
  padding: 7px 10px 1px;
}
.message.has-telegram-media .message-footer {
  min-height: 18px;
  padding: 0 9px 6px;
}
.message.telegram-media-only .message-footer {
  margin-top: 0;
  padding-top: 4px;
}

.message.has-telegram-media .message-content {
  position: relative;
  max-width: min(400px, 100%);
}

.message.has-telegram-media .telegram-message-media > .telegram-image-button .telegram-message-image,
.message.has-telegram-media .telegram-message-media > .telegram-message-video {
  max-height: min(22rem, 54vh);
}

.message.has-telegram-media .telegram-message-media > .telegram-message-video.video-note {
  max-width: min(12rem, 100%) !important;
  max-height: none;
  border-radius: 50% !important;
}

.message.telegram-media-only:has(.telegram-message-media > .telegram-image-button):not(:has(.comment-button)) .message-footer {
  position: absolute;
  inset: auto 6px 6px auto;
  padding: 2px 6px;
  border-radius: 8px;
  background: rgb(0 0 0 / 64%);
  color: white !important;
  pointer-events: none;
}

.telegram-location-card {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  max-width: 100%;
  padding: 8px 10px;
  border: 0;
  color: var(--text);
  background: var(--surface-2);
  text-align: start;
}

.telegram-location-card > span:nth-child(2) {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.telegram-location-card small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
}

.telegram-location-pin {
  flex: none;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--teal) 20%, var(--surface-2));
  color: var(--text);
}

.telegram-location-card svg { width: 18px; height: 18px; flex: none; }

.telegram-location-dialog {
  width: min(420px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  margin: auto;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
}

.telegram-location-dialog::backdrop { background: rgb(0 0 0 / 56%); }
.telegram-location-dialog header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  overflow-wrap: anywhere;
}
.telegram-location-dialog button { width: 32px; min-height: 32px; }
.telegram-location-dialog iframe {
  display: block;
  width: 100%;
  height: min(310px, 62dvh);
  border: 0;
}
.telegram-location-dialog > a {
  display: block;
  padding: 8px 10px;
  color: var(--blue);
  text-align: end;
}

.telegram-message-actions {
  width: 100%;
  min-width: min(260px, 68vw);
  margin-top: 2px;
}
.telegram-bot-keyboard {
  display: grid;
  gap: 2px;
  width: 100%;
  margin: 0;
}
.telegram-bot-keyboard-row {
  display: grid;
  grid-template-columns: repeat(var(--telegram-button-count, 1), minmax(0, 1fr));
  gap: 2px;
}
.telegram-bot-keyboard .telegram-inline-button {
  min-width: 0;
  min-height: 36px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  justify-items: center;
  gap: 6px;
  padding: 7px 10px;
  border: 0;
  border-radius: 8px;
  color: var(--blue);
  background: color-mix(in srgb, var(--surface-2) 86%, var(--blue) 7%);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--line) 70%, transparent);
  font: inherit;
  font-size: 12px;
  font-weight: 750;
  line-height: 1.15;
  text-decoration: none;
  cursor: pointer;
}
.telegram-bot-keyboard .telegram-inline-button span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.telegram-bot-keyboard .telegram-inline-button svg {
  width: 14px;
  height: 14px;
  justify-self: end;
}
.telegram-bot-keyboard .telegram-inline-button:not(:disabled):hover {
  filter: none;
  background: color-mix(in srgb, var(--surface-2) 74%, var(--blue) 14%);
}
.telegram-bot-keyboard .telegram-inline-button:disabled {
  color: var(--muted);
  opacity: 0.55;
  cursor: not-allowed;
}

@media (max-width: 720px) {
  .message.has-telegram-media .telegram-message-media,
  .message.has-telegram-media .telegram-album-grid { max-width: 82vw; }
  .telegram-message-actions { min-width: min(240px, 76vw); }
}


/* V10.4 Telegram hyperlink and forwarded-origin polish */
.telegram-forwarded {
  display: grid;
  gap: 3px;
  min-width: 0;
  margin: 0 0 5px;
  padding-left: 9px;
  border-left: 2px solid color-mix(in srgb, var(--blue) 72%, transparent);
}
.telegram-forward-label {
  color: var(--blue);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.1;
}
.telegram-forward-identity {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.telegram-forward-avatar {
  position: relative;
  flex: 0 0 22px;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  overflow: hidden;
  border-radius: 50%;
  color: var(--text);
  background: var(--surface-2);
  font-size: 8px;
  font-weight: 800;
}
.telegram-forward-avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.telegram-forward-source {
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 5px;
  color: var(--text);
  text-decoration: none;
}
.telegram-forward-source strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}
.telegram-forward-source small {
  flex: 0 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 10px;
}
a.telegram-forward-source:hover strong { color: var(--blue); }
.message-link { position: relative; z-index: 3; cursor: pointer; touch-action: manipulation; }
.topbar:has(.qorgon-global-audio:not([hidden])) .top-actions { margin-left: 0; }

/* V11.2 forwarded-source navigation: Qorgon-internal by default, Telegram external as a secondary action. */
button.telegram-forward-source {
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

button.telegram-forward-source:hover strong,
button.telegram-forward-source:focus-visible strong {
  color: var(--blue);
}

.telegram-forward-external {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  color: var(--muted);
  text-decoration: none;
}

.telegram-forward-external:hover,
.telegram-forward-external:focus-visible {
  color: var(--blue);
  background: color-mix(in srgb, var(--surface-2) 84%, transparent);
}

.telegram-forward-external svg {
  width: 13px;
  height: 13px;
}

.telegram-lightbox {
  z-index: 12000;
}
