/* Адаптив, анимации, микровзаимодействия */

.gate-card.view-in {
  /* without fill-mode:both — иначе при сбое анимации форма остаётся прозрачной */
  animation: view-rise 0.4s var(--ease-out);
}

.messenger.view-in {
  animation: view-fade 0.42s var(--ease-out) both;
}

@keyframes view-rise {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes view-fade {
  from {
    opacity: 0;
    transform: scale(0.985);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes call-stage-in {
  from {
    opacity: 0;
    transform: scale(0.94) translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.bubble-enter {
  animation: bubble-pop 0.36s var(--ease-spring) both;
}

@keyframes bubble-pop {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.call-status {
  animation: status-pulse 1.8s ease-in-out infinite;
}

.call-status.call-status-live {
  animation: none;
  opacity: 1;
}

@keyframes status-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.72;
  }
}

.chat-list-item {
  transition: background 0.12s var(--ease-out);
}

@media (hover: hover) {
  .chat-list-item:active {
    transform: scale(0.995);
    transition: background 0.12s var(--ease-out), transform 0.1s var(--ease-out);
  }
}

.btn-primary,
.btn-send,
.btn,
.tg-icon-btn,
.btn-icon,
.btn-attach,
.tg-back,
.tg-done,
.segment {
  transition:
    background var(--motion) var(--ease-out),
    color var(--motion) var(--ease-out),
    border-color var(--motion) var(--ease-out),
    transform 0.16s var(--ease-out),
    opacity var(--motion) var(--ease-out);
}

.btn-primary:active:not(:disabled),
.btn-send:active,
.tg-icon-btn:active,
.btn-icon:active,
.btn-attach:active {
  transform: scale(0.94);
}

.btn-hangup {
  transition: transform 0.16s var(--ease-out), filter var(--motion);
  box-shadow: 0 8px 24px rgba(224, 92, 92, 0.35);
}

.btn-hangup:active {
  transform: scale(0.96);
}

.gate-card input:not([type="checkbox"]),
.composer textarea,
.sidebar-search input {
  transition: border-color var(--motion), box-shadow var(--motion), background var(--motion);
}

.gate-card input:focus:not([type="checkbox"]),
.composer textarea:focus {
  box-shadow: 0 0 0 3px rgba(232, 135, 58, 0.28);
}

.tg-modal:not(.hidden) .tg-modal-scrim {
  animation: scrim-in 0.28s var(--ease-out) both;
}

.tg-modal-panel {
  animation: modal-sheet-in 0.38s var(--ease-out) both;
}

@keyframes scrim-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes modal-sheet-in {
  from {
    opacity: 0.92;
    transform: translateX(28px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.segment {
  position: relative;
}

.segment.active {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

@media (max-width: 1024px) {
  .messenger {
    grid-template-columns: minmax(220px, 42vw) minmax(0, 1fr);
    max-width: 100%;
  }

  .bubble {
    max-width: min(82%, 26rem);
  }
}

@media (max-width: 768px) {
  .messenger {
    grid-template-columns: 1fr;
  }

  /* Без scale — иначе на iOS «мылит» текст в сайдбаре */
  .messenger.view-in {
    animation: view-fade-mobile 0.35s var(--ease-out) both;
  }

  @keyframes view-fade-mobile {
    from {
      opacity: 0;
    }
    to {
      opacity: 1;
    }
  }

  .messenger .sidebar {
    padding-top: 0;
  }

  /* slide transition живёт в styles.css — не прячем через display:none */

  .messenger.chat-open .conv-head {
    padding-left: max(0.35rem, var(--safe-left));
  }

  .conv-welcome {
    padding: 1.5rem;
  }

  .call-stage {
    width: 100%;
    max-height: min(56dvh, 28rem);
    aspect-ratio: 4 / 5;
  }

  .call-overlay.call-video:not(.group-video) .call-stage {
    max-height: min(72dvh, calc(100vw - 1rem));
    aspect-ratio: 9 / 16;
  }

  .tg-modal {
    justify-content: center;
    align-items: flex-end;
  }

  .tg-modal-panel {
    width: 100%;
    max-height: min(92dvh, 640px);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.45);
    animation: modal-sheet-up 0.4s var(--ease-out) both;
  }

  @keyframes modal-sheet-up {
    from {
      opacity: 0.95;
      transform: translateY(100%);
    }
    to {
      opacity: 1;
      transform: none;
    }
  }
}

@media (max-width: 420px) {
  .gate-card {
    width: 100%;
    border-radius: 20px;
  }

  .conv-actions .btn-call-text {
    font-size: 0.76rem;
    padding: 0.35rem 0.55rem;
  }

  .bubble {
    max-width: 88%;
    font-size: 0.95rem;
  }
}

@media (min-width: 769px) {
  .messenger {
    box-shadow: 0 0 0 1px var(--stroke);
  }

}

@media (prefers-reduced-motion: reduce) {
  .view-in,
  .bubble-enter,
  .messenger.view-in,
  .call-overlay.call-live .call-stage,
  .tg-modal-panel,
  .tg-modal:not(.hidden) .tg-modal-scrim,
  .call-status,
  .ring-app-name,
  .ring-panel {
    animation: none !important;
  }

  .thread {
    scroll-behavior: auto;
  }

  .chat-list-item:active,
  .btn-primary:active:not(:disabled),
  .btn-send:active,
  .btn-hangup:active {
    transform: none;
  }
}