/* Telegram, светлая тема: шапка чата, обои, пузыри, кнопки под сообщениями, клавиатура, меню. */

.tg {
  --tg-accent: #3390ec;
  --tg-link: #2481cc;
  --tg-meta: #8e8e93;
  --tg-meta-out: #5ca853;
  --tg-bubble-out: #e1ffc7;
  --tg-glass: rgba(36, 72, 104, 0.52);
  --tg-glass-hover: rgba(36, 72, 104, 0.62);
  --tg-glass-active: rgba(36, 72, 104, 0.74);
  --tg-panel: rgba(247, 247, 247, 0.95);

  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #fff;
  color: #000;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

.tg button {
  font-family: inherit;
}

.tg button:focus-visible,
.tg a:focus-visible {
  outline: 2px solid var(--tg-accent);
  outline-offset: 2px;
}

/* --- Строка состояния и шапка чата --- */

.tg-top {
  position: relative;
  z-index: 5;
  flex: 0 0 auto;
  background: var(--tg-panel);
  border-bottom: 0.5px solid rgba(0, 0, 0, 0.2);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
}

.tg-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 50px;
  padding: 14px 30px 0 36px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.tg-status__icons {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.tg-status svg {
  fill: currentColor;
}

.tg-head {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  height: 52px;
  padding: 0 12px 2px 8px;
}

.tg-back {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--tg-accent);
  font-size: 17px;
  text-decoration: none;
}

a.tg-back[href] {
  cursor: pointer;
}

.tg-peer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  min-width: 0;
}

.tg-peer b {
  font-size: 16.5px;
  font-weight: 600;
  line-height: 1.2;
}

.tg-peer__sub {
  font-size: 13px;
  line-height: 1.2;
  color: var(--tg-meta);
}

.tg-ava {
  justify-self: end;
  display: block;
  width: 38px;
  height: 38px;
  border-radius: 50%;
}

/* --- Переписка на фирменных обоях --- */

.tg-chat {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  background-color: #cadfee;
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240' viewBox='0 0 240 240'%3E%3Cg fill='none' stroke='%23fff' stroke-opacity='.55' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m30 34 8-8 8 8-8 8z'/%3E%3Ccircle cx='96' cy='30' r='9'/%3E%3Ccircle cx='110' cy='46' r='4'/%3E%3Cpath d='M170 22v16m-8-8h16'/%3E%3Cpath d='m206 70 6-6 6 6-6 6z'/%3E%3Ccircle cx='56' cy='104' r='6'/%3E%3Cpath d='M140 96c6 0 10-4 10-10 0 6 4 10 10 10-6 0-10 4-10 10 0-6-4-10-10-10z'/%3E%3Ccircle cx='214' cy='140' r='10'/%3E%3Cpath d='M24 176v14m-7-7h14'/%3E%3Cpath d='m104 170 7-7 7 7-7 7z'/%3E%3Ccircle cx='168' cy='196' r='5'/%3E%3Cpath d='M60 224c5 0 8-3 8-8 0 5 3 8 8 8-5 0-8 3-8 8 0-5-3-8-8-8z'/%3E%3C/g%3E%3C/svg%3E"),
    linear-gradient(170deg, #dcebf5 0%, #c9dfee 45%, #b8d3e8 100%);
  background-size:
    240px 240px,
    100% 100%;
  background-attachment: local, scroll;
}

.tg-chat::-webkit-scrollbar {
  display: none;
}

.tg-feed {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 4px;
  padding: 10px 8px 12px;
}

.is-prestart .tg-feed {
  justify-content: center;
}

/* Описание бота в пустом чате, до нажатия «Старт» */
.tg-about {
  align-self: center;
  max-width: 300px;
  padding: 12px 14px 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.94);
  font-size: 14.5px;
  line-height: 1.4;
  box-shadow: 0 1px 2px rgba(16, 38, 58, 0.12);
  animation: tg-in 0.35s ease-out both;
}

.tg-about b {
  display: block;
  margin-bottom: 6px;
  font-size: 15px;
  font-weight: 600;
}

.tg-about p {
  margin: 0;
}

.tg-service {
  align-self: center;
  margin: 8px 0 4px;
  padding: 3px 10px 4px;
  border-radius: 999px;
  background: var(--tg-glass);
  color: #fff;
  font-size: 13.5px;
  font-weight: 500;
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

/* --- Сообщения --- */

.tg-msg {
  display: flex;
  flex-direction: column;
  align-self: flex-start;
  max-width: 82%;
  margin-top: 2px;
}

.tg-msg--out {
  align-self: flex-end;
}

/* Пузырь проявляется от «хвостика»: входящий из левого нижнего угла, исходящий из правого */
.tg-msg--in .tg-bubble {
  transform-origin: 0 100%;
}

.tg-msg--out .tg-bubble {
  transform-origin: 100% 100%;
}

.tg-msg.has-kb {
  width: 82%;
}

.tg-bubble {
  position: relative;
  padding: 6px 9px 7px 11px;
  border-radius: 17px 17px 17px 5px;
  background: #fff;
  font-size: 16px;
  line-height: 1.34;
  overflow-wrap: anywhere;
  box-shadow: 0 1px 1px rgba(16, 38, 58, 0.13);
}

.tg-msg--out .tg-bubble {
  background: var(--tg-bubble-out);
  border-radius: 17px 17px 5px 17px;
}

.tg-text b {
  font-weight: 600;
}

.tg-text::after {
  content: '';
  display: block;
  clear: both;
}

.tg-meta {
  float: right;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin: 7px -1px -5px 12px;
  font-size: 11.5px;
  line-height: 1;
  color: var(--tg-meta);
  white-space: nowrap;
}

.tg-msg--out .tg-meta {
  color: var(--tg-meta-out);
}

.tg-meta__checks {
  width: 16px;
  height: 10px;
}

.tg-link {
  color: var(--tg-link);
  white-space: nowrap;
}

.tg-cmd {
  padding: 0;
  border: 0;
  background: none;
  font-size: inherit;
  line-height: inherit;
  color: var(--tg-link);
  cursor: pointer;
}

/* Карточка контакта после «Отправить мой номер» */
.tg-bubble--contact {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 220px;
  padding: 9px 10px 8px;
}

.tg-contact__ava {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(180deg, #72d5fd, #2a9ef1);
  color: #fff;
  font-size: 17px;
  font-weight: 600;
}

.tg-contact__body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1 1 auto;
  font-size: 15px;
}

.tg-contact__body b {
  font-weight: 600;
}

.tg-bubble--contact .tg-meta {
  align-self: flex-end;
  margin: 0 0 -2px;
}

/* --- Кнопки под сообщением --- */

.tg-ikb {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 4px;
}

.tg-ikb__row {
  display: flex;
  gap: 4px;
}

.tg-ikb__btn {
  flex: 1 1 0;
  min-width: 0;
  min-height: 40px;
  padding: 7px 8px;
  border: 0;
  border-radius: 9px;
  background: var(--tg-glass);
  color: #fff;
  font-size: 14.5px;
  font-weight: 500;
  line-height: 1.2;
  text-align: center;
  cursor: pointer;
  /* Без размытия фона: оно захватывает соседние кнопки, и подсветка одной расползается на другие */
  transition: background-color 0.15s;
}

@media (hover: hover) {
  .tg-ikb__btn:hover {
    background: var(--tg-glass-hover);
  }
}

.tg-ikb__btn:active,
.tg-ikb__btn.is-pressed {
  background: var(--tg-glass-active);
}

/* --- Нижняя панель: «Старт», поле ввода, подсказки, клавиатура с номером --- */

.tg-bottom {
  position: relative;
  z-index: 6;
  flex: 0 0 auto;
  background: var(--tg-panel);
  border-top: 0.5px solid rgba(0, 0, 0, 0.2);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
}

.tg-start {
  display: none;
  width: 100%;
  height: 52px;
  border: 0;
  background: none;
  color: var(--tg-accent);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
}

.tg-start:hover {
  background: rgba(51, 144, 236, 0.06);
}

.is-prestart .tg-start {
  display: block;
  transition: opacity 0.2s ease;
}

.is-starting .tg-start {
  opacity: 0;
}

/* После «Старт» поле ввода проявляется на месте кнопки */
.tg-composer {
  animation: tg-fade 0.36s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.is-prestart .tg-composer,
.is-prestart .tg-hints,
.is-prestart .tg-rkb {
  display: none;
}

.tg-hints {
  display: none;
  align-items: center;
  gap: 6px;
  padding: 8px 10px 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.tg-hints::-webkit-scrollbar {
  display: none;
}

.has-hints .tg-hints {
  display: flex;
}

.tg-hints__label {
  flex: 0 0 auto;
  font-size: 12.5px;
  color: var(--tg-meta);
}

.tg-hint {
  flex: 0 0 auto;
  height: 30px;
  padding: 0 12px;
  border: 1px solid rgba(51, 144, 236, 0.4);
  border-radius: 999px;
  background: #fff;
  color: var(--tg-link);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.tg-hint:hover {
  border-color: var(--tg-accent);
}

.tg-composer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
}

.tg-menu-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px 0 10px;
  border: 0;
  border-radius: 16px;
  background: var(--tg-accent);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.tg-input {
  flex: 1 1 auto;
  min-width: 0;
  height: 36px;
  padding: 0 14px;
  border: 0.5px solid #d0d0d5;
  border-radius: 18px;
  background: #fff;
  color: #000;
  font-family: inherit;
  font-size: 16px;
  outline: none;
}

.tg-input:focus {
  border-color: #9cc7f2;
}

.tg-input::placeholder {
  color: #a4a4aa;
}

.tg-send,
.tg-mic {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  align-items: center;
  justify-content: center;
}

.tg-send {
  display: none;
  border: 0;
  border-radius: 50%;
  background: var(--tg-accent);
  color: #fff;
  cursor: pointer;
}

.tg-mic {
  display: inline-flex;
  color: var(--tg-meta);
}

.has-text .tg-send {
  display: inline-flex;
}

.has-text .tg-mic {
  display: none;
}

.tg-rkb {
  display: none;
  padding: 6px 6px 8px;
  background: #d2d5db;
}

.has-reply .tg-rkb {
  display: block;
}

.tg-rkb__row {
  display: flex;
  gap: 6px;
}

.tg-rkb__btn {
  flex: 1 1 0;
  height: 44px;
  border: 0;
  border-radius: 8px;
  background: #fff;
  color: #000;
  font-size: 16px;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.3);
  cursor: pointer;
}

.tg-rkb__btn:active {
  background: #eceef1;
}

.tg-home {
  position: relative;
  height: 22px;
}

.tg-home::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: 8px;
  width: 134px;
  height: 5px;
  margin-left: -67px;
  border-radius: 3px;
  background: #000;
}

.has-reply .tg-home {
  background: #d2d5db;
}

/* Меню команд над полем ввода */
.tg-menu {
  position: absolute;
  left: 8px;
  bottom: calc(100% + 6px);
  z-index: 30;
  width: 272px;
  padding: 6px 0;
  border-radius: 13px;
  background: #fff;
  box-shadow: 0 12px 34px -8px rgba(0, 0, 0, 0.3);
  animation: tg-pop 0.18s ease-out;
}

.tg-menu[hidden] {
  display: none;
}

.tg-menu__item {
  display: flex;
  align-items: baseline;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
}

.tg-menu__item:hover {
  background: #f2f2f7;
}

.tg-menu__cmd {
  font-size: 15px;
  font-weight: 600;
  color: #000;
}

.tg-menu__desc {
  font-size: 14px;
  color: var(--tg-meta);
}

/* Всплывающее окно, как у кнопок, которые уже не работают */
.tg-alert {
  position: absolute;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.25);
}

.tg-alert[hidden] {
  display: none;
}

.tg-alert__box {
  width: 270px;
  border-radius: 14px;
  background: rgba(248, 248, 248, 0.97);
  text-align: center;
  overflow: hidden;
  animation: tg-pop 0.2s ease-out;
}

.tg-alert__text {
  margin: 0;
  padding: 19px 16px 18px;
  font-size: 14.5px;
  line-height: 1.35;
}

.tg-alert__ok {
  width: 100%;
  height: 44px;
  border: 0;
  border-top: 0.5px solid rgba(60, 60, 67, 0.3);
  background: none;
  color: #007aff;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
}

/* --- Режимы --- */

.is-preview .tg-hints {
  display: none;
}

.is-bare .tg-status,
.is-bare .tg-home::after {
  display: none;
}

.is-bare .tg-home {
  height: env(safe-area-inset-bottom, 0);
}

.is-bare .tg-top {
  padding-top: env(safe-area-inset-top, 0);
}

@keyframes tg-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
}

@keyframes tg-pop {
  from {
    opacity: 0;
    transform: scale(1.06);
  }
}

@keyframes tg-fade {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

.is-reduced .tg-composer,
.is-reduced .tg-about,
.is-reduced .tg-alert__box,
.is-reduced .tg-menu {
  animation: none;
}
