/**
 * VYRE — motion polish: calls, voice, video notes, composer, messages, toasts.
 * Respects body.reduce-motion and prefers-reduced-motion.
 */

/* ── Shared springs ── */
:root {
  --vyre-spring: cubic-bezier(0.22, 1, 0.36, 1);
  --vyre-spring-bounce: cubic-bezier(0.2, 0.9, 0.2, 1.15);
  --vyre-duration-fast: 0.18s;
  --vyre-duration: 0.32s;
  --vyre-duration-slow: 0.42s;
}

/* ── Buttons & taps ── */
.icon-btn,
.call-btn,
.composer-tool,
.nav-btn,
.btn-action,
.send-btn,
.voice-btn,
.video-note-btn {
  transition:
    transform var(--vyre-duration-fast) var(--vyre-spring),
    background 0.2s ease,
    box-shadow 0.2s ease,
    opacity 0.2s ease;
}
.icon-btn:active:not(:disabled),
.call-btn:active:not(:disabled),
.composer-tool:active,
.nav-btn:active,
.btn-action:active:not(:disabled),
.send-btn:active,
.voice-btn:active,
.video-note-btn:active {
  transform: scale(0.92);
}
.chat-item {
  transition: background 0.18s ease, transform 0.22s var(--vyre-spring);
}
.chat-item:active {
  transform: scale(0.985);
}
.chat-item.active {
  box-shadow: inset 3px 0 0 var(--accent);
}

/* ── Tab panels ── */
.tab-panel.tab-enter {
  animation: tabPanelIn 0.34s var(--vyre-spring) both;
}
@keyframes tabPanelIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
.nav-btn.active,
.desk-app-tab.active {
  transition: color 0.2s ease, background 0.2s ease, transform 0.25s var(--vyre-spring-bounce);
}
.nav-btn.active {
  transform: translateY(-1px);
}

/* ── Reply / voice bars ── */
.reply-bar:not(.hidden) {
  animation: barSlideIn 0.28s var(--vyre-spring) both;
}
.voice-record-bar:not(.hidden) {
  animation: barSlideIn 0.28s var(--vyre-spring) both;
  box-shadow: 0 -4px 24px rgba(220, 38, 38, 0.08);
}
.voice-record-bar.is-active .voice-record-dot {
  animation: voicePulse 0.85s ease-in-out infinite, recordDotGlow 1.4s ease-in-out infinite;
}
.voice-draft-bar:not(.hidden) {
  animation: barSlideIn 0.26s var(--vyre-spring) both;
}
@keyframes barSlideIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}
@keyframes recordDotGlow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.45); }
  50% { box-shadow: 0 0 0 6px rgba(220, 38, 38, 0); }
}

/* ── Composer morph ── */
.composer-morph #send-btn,
.composer-morph #voice-btn,
.composer-morph #video-note-btn {
  transition:
    transform 0.26s var(--vyre-spring-bounce),
    opacity 0.2s ease,
    background 0.2s ease;
}
.chat-input-bar.is-send-mode #send-btn {
  animation: sendBtnPop 0.32s var(--vyre-spring-bounce);
}
@keyframes sendBtnPop {
  0% { transform: scale(0.6) rotate(-12deg); opacity: 0; }
  70% { transform: scale(1.08) rotate(0deg); opacity: 1; }
  100% { transform: scale(1); }
}
body.is-recording-voice .voice-btn {
  transform: scale(1.12);
  background: color-mix(in srgb, #dc2626 18%, transparent);
  color: #dc2626;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.2);
}
body.is-recording-video-note .video-note-btn {
  transform: scale(1.15);
  box-shadow: 0 0 0 4px rgba(51, 144, 236, 0.35);
  animation: videoNoteBtnPulse 1.2s ease-in-out infinite;
}
@keyframes videoNoteBtnPulse {
  0%, 100% { box-shadow: 0 0 0 4px rgba(51, 144, 236, 0.35); }
  50% { box-shadow: 0 0 0 8px rgba(51, 144, 236, 0.08); }
}

/* ── Messages ── */
.msg.msg-enter-mobile {
  animation: msgEnterMobile 0.26s var(--vyre-spring) both;
}
.msg.msg-enter-mobile.msg-enter-mine {
  animation-name: msgEnterMobileMine;
}
@keyframes msgEnterMobile {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
@keyframes msgEnterMobileMine {
  from { opacity: 0; transform: translateY(6px) translateX(8px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
.msg-bubble,
.msg-bubble-body {
  transition: box-shadow 0.2s ease, transform 0.2s var(--vyre-spring);
}

/* ── Voice messages ── */
.msg-voice-play {
  transition: transform 0.22s var(--vyre-spring-bounce), box-shadow 0.22s ease, background 0.2s ease;
  box-shadow: 0 2px 8px color-mix(in srgb, var(--accent) 28%, transparent);
}
.msg-voice-play:hover {
  transform: scale(1.06);
}
.msg-voice-play.playing {
  animation: voicePlayPulse 1.1s ease-in-out infinite;
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 40%, transparent);
}
@keyframes voicePlayPulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 35%, transparent); }
  50% { box-shadow: 0 0 0 7px color-mix(in srgb, var(--accent) 0%, transparent); }
}
.msg-voice.playing .msg-voice-wave i {
  animation: voiceBarLive 0.55s ease-in-out infinite alternate;
  animation-delay: calc(var(--i, 0) * 35ms);
}
.msg-voice-wave i { --i: 0; }
.msg-voice-wave i:nth-child(odd) { --i: 1; }
.msg-voice-wave i:nth-child(3n) { --i: 2; }
.msg-voice-wave i:nth-child(4n) { --i: 3; }
@keyframes voiceBarLive {
  from { transform: scaleY(0.55); opacity: 0.65; }
  to { transform: scaleY(1); opacity: 1; }
}

/* ── Video notes ── */
.msg-video-note {
  transition: transform 0.25s var(--vyre-spring), box-shadow 0.25s ease;
}
.msg-video-note:hover {
  transform: scale(1.03);
}
.msg-video-note.playing {
  animation: videoNotePlayRing 1.4s ease-in-out infinite;
  box-shadow: 0 0 0 3px var(--accent), 0 8px 28px rgba(51, 144, 236, 0.25);
}
@keyframes videoNotePlayRing {
  0%, 100% { box-shadow: 0 0 0 2px var(--accent), 0 6px 20px rgba(51, 144, 236, 0.18); }
  50% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent) 25%, transparent), 0 10px 32px rgba(51, 144, 236, 0.28); }
}
.msg-video-note .msg-voice-dur {
  transition: opacity 0.2s ease;
}
.msg-video-note.playing .msg-voice-dur {
  opacity: 1;
  background: rgba(51, 144, 236, 0.85);
}

/* ── Video note recorder overlay ── */
.video-note-overlay:not(.hidden) {
  animation: overlayFadeIn 0.28s ease both;
}
.video-note-overlay.is-recording .video-note-ring {
  animation: videoRingIn 0.38s var(--vyre-spring-bounce) both;
}
.video-note-overlay.is-recording .video-note-progress circle {
  transition: stroke-dashoffset 0.1s linear;
  filter: drop-shadow(0 0 6px rgba(24, 181, 170, 0.55));
}
.video-note-overlay.is-recording .video-note-hint {
  animation: hintFadeUp 0.4s var(--vyre-spring) 0.12s both;
}
@keyframes overlayFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes videoRingIn {
  from { opacity: 0; transform: scale(0.72); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes hintFadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* ── Call overlay ── */
.call-overlay:not(.hidden) {
  animation: overlayFadeIn 0.26s ease both;
}
.call-overlay.is-open .call-stage {
  animation: callStageIn 0.42s var(--vyre-spring) both;
}
.call-overlay.is-open.call-incoming .call-avatar-ring {
  animation: callPulse 1.6s ease-in-out infinite, callRingExpand 2s ease-in-out infinite;
}
.call-overlay.is-open .call-btn-accept {
  animation: acceptPulse 1.8s ease-in-out infinite;
}
@keyframes callStageIn {
  from { opacity: 0; transform: scale(0.9) translateY(20px); }
  to { opacity: 1; transform: none; }
}
@keyframes callRingExpand {
  0%, 100% { transform: scale(1); opacity: 0.85; }
  50% { transform: scale(1.06); opacity: 1; }
}
@keyframes acceptPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.45); }
  50% { box-shadow: 0 0 0 10px rgba(34, 197, 94, 0); }
}
.call-overlay.is-closing {
  animation: overlayFadeOut 0.28s ease both;
  pointer-events: none;
}
.call-overlay.is-closing .call-stage {
  animation: callStageOut 0.28s ease both;
}
@keyframes overlayFadeOut {
  to { opacity: 0; }
}
@keyframes callStageOut {
  to { opacity: 0; transform: scale(0.94) translateY(12px); }
}
.call-mini-bar:not(.hidden) {
  animation: miniBarUp 0.34s var(--vyre-spring) both;
}
@keyframes miniBarUp {
  from { opacity: 0; transform: translateY(100%); }
  to { opacity: 1; transform: none; }
}
.call-btn {
  transition: transform 0.2s var(--vyre-spring), background 0.2s ease, box-shadow 0.2s ease;
}
.call-btn:hover {
  transform: translateY(-2px);
}
.call-btn-hangup:hover {
  box-shadow: 0 6px 20px rgba(225, 29, 72, 0.35);
}

/* ── Toasts ── */
.toast.show {
  transition:
    opacity 0.32s var(--vyre-spring),
    transform 0.36s var(--vyre-spring-bounce);
}
.toast.hide {
  transition:
    opacity 0.22s ease,
    transform 0.22s ease;
}
.toast-bubble {
  transition: box-shadow 0.2s ease;
}
.toast.show .toast-bubble {
  animation: toastBubbleIn 0.36s var(--vyre-spring-bounce);
}
@keyframes toastBubbleIn {
  0% { transform: scale(0.88) translateY(6px); }
  65% { transform: scale(1.02); }
  100% { transform: none; }
}

/* ── Scroll FAB ── */
.scroll-down-fab:not(.hidden) {
  animation: fabIn 0.32s var(--vyre-spring-bounce);
}
@keyframes fabIn {
  from { opacity: 0; transform: translateY(12px) scale(0.85); }
  to { opacity: 1; transform: none; }
}
.scroll-down-fab-badge {
  animation: badgePop 0.35s var(--vyre-spring-bounce);
}

/* ── Sheets & modals ── */
.terms-modal:not(.hidden) .terms-modal-box,
.peer-sheet:not(.hidden) .peer-sheet-box {
  animation: sheetUp 0.36s var(--vyre-spring) both;
}
@keyframes sheetUp {
  from { opacity: 0; transform: translateY(24px) scale(0.97); }
  to { opacity: 1; transform: none; }
}
.terms-modal:not(.hidden) .terms-modal-backdrop {
  animation: overlayFadeIn 0.24s ease both;
}

/* ── Calls tab ── */
.calls-start {
  transition: box-shadow 0.2s ease, transform 0.2s var(--vyre-spring);
}
.calls-start-actions .btn-action:not(:disabled):hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 18%, transparent);
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  .tab-panel.tab-enter,
  .msg.msg-enter,
  .msg.msg-enter-mobile,
  .msg.msg-enter.msg-enter-mine,
  .call-overlay.is-open .call-stage,
  .video-note-overlay.is-recording .video-note-ring,
  .toast.show .toast-bubble,
  .reply-bar:not(.hidden),
  .voice-record-bar:not(.hidden),
  .call-mini-bar:not(.hidden),
  .scroll-down-fab:not(.hidden) {
    animation: none !important;
  }
  .icon-btn:active,
  .chat-item:active,
  .msg-video-note:hover {
    transform: none !important;
  }
}
body.reduce-motion .tab-panel.tab-enter,
body.reduce-motion .msg.msg-enter-mobile,
body.reduce-motion .call-overlay.is-open .call-stage,
body.reduce-motion .video-note-overlay.is-recording .video-note-ring {
  animation: none !important;
}

/* ── Forum topics ── */
.chat-topics-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px 4px;
  border-bottom: 1px solid var(--glass-border);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
}
.chat-topics-bar.hidden { display: none; }
.chat-topics-scroll {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  flex: 1;
  scrollbar-width: none;
}
.chat-topics-scroll::-webkit-scrollbar { display: none; }
.chat-topic-chip {
  flex: 0 0 auto;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  color: var(--text);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}
.chat-topic-chip.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.chat-topics-add { flex-shrink: 0; }

/* ── Channel stats ── */
.channel-sheet-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 10px 0 4px;
}
.channel-sheet-stats.hidden { display: none; }
.channel-stat {
  text-align: center;
  padding: 8px 6px;
  border-radius: 10px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
}
.channel-stat strong {
  display: block;
  font-size: 16px;
  font-weight: 700;
}
.channel-stat span {
  font-size: 11px;
  color: var(--text-muted);
}

/* ── Message comments (channels) ── */
.msg-comments-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
}
.msg-comments-btn:hover {
  color: var(--accent);
  border-color: var(--accent-soft);
}

/* ── Global search tabs ── */
.global-search-tabs {
  display: flex;
  gap: 4px;
  padding: 8px 10px 4px;
  border-bottom: 1px solid var(--glass-border);
}
.global-search-tab {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 999px;
  cursor: pointer;
}
.global-search-tab.active {
  background: var(--accent-soft);
  color: var(--accent);
}
.global-search-media-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 8px;
}
.global-search-media-cell {
  aspect-ratio: 1;
  border: none;
  padding: 0;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  background: var(--glass-bg);
}
.global-search-media-cell img,
.global-search-media-cell video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ── Mobile safe areas (notch / home indicator) ── */
html.is-mobile .app {
  height: 100dvh;
  min-height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}
html.is-mobile .main-screen.active {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
html.is-mobile .header {
  padding-top: max(16px, var(--vyre-safe-top-fallback, env(safe-area-inset-top, 54px)));
  padding-bottom: 8px;
}
html.is-mobile #tab-chats.active,
html.is-mobile #tab-contacts.active,
html.is-mobile #tab-calls.active,
html.is-mobile #tab-map.active,
html.is-mobile #tab-admin.active {
  padding-bottom: calc(var(--vyre-mobile-nav-h, 72px) + var(--vyre-safe-bottom-fallback, env(safe-area-inset-bottom, 16px)) + 16px);
}
html.is-mobile .bottom-nav {
  padding: 6px 8px max(8px, env(safe-area-inset-bottom, 0px));
}
html.is-mobile .nav-btn {
  padding: 4px 2px 2px;
  gap: 2px;
}
html.is-mobile body.mobile-chat-open .chat-area {
  padding-top: 0 !important;
  box-sizing: border-box;
}
html.is-mobile body.mobile-chat-open .chat-header-row {
  padding-top: max(10px, env(safe-area-inset-top, 0px), var(--vyre-safe-top, 28px)) !important;
  padding-bottom: 8px !important;
}
html.is-mobile body.mobile-chat-open .chat-header-meta {
  min-width: 0;
}
html.is-mobile body.mobile-chat-open .chat-header,
html.is-mobile body.mobile-chat-open .chat-subtitle {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
html.is-mobile .chat-input-bar {
  padding-bottom: max(6px, env(safe-area-inset-bottom, 6px));
}

/* Телефоны и планшеты: полноэкранный чат + видимый composer */
@media (max-width: 1024px) {
  html.is-mobile .chat-list-panel { width: 100%; }
  html.is-mobile .chat-area { display: none; flex: 1; min-height: 0; min-width: 0; }
  html.is-mobile .chat-back-btn { display: flex !important; }
  html.is-mobile .chats-layout.chat-open .chat-list-panel { display: none; }
  html.is-mobile .chats-layout.chat-open .chat-area {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    min-height: 0;
  }
  html.is-mobile .chat-header-desk { display: none !important; }
  html.is-mobile .chat-header-more { display: inline-flex !important; }
  html.is-mobile .composer-desktop-only { display: none !important; }
  html.is-mobile .composer-more-btn { display: inline-flex !important; }
  html.is-mobile .chat-input-bar {
    flex-shrink: 0;
    position: relative;
    z-index: 12;
    background: var(--card);
  }
  html.is-mobile .emoji-bar { flex-shrink: 0; }
  html.is-mobile body.mobile-chat-open .header { display: none !important; }
  html.is-mobile body.mobile-chat-open .bottom-nav { display: none !important; }
  html.is-mobile body.mobile-chat-open .main-screen.active { padding-bottom: 0 !important; }
  html.is-mobile body.mobile-chat-open .content {
    margin: 0 !important;
    border-radius: 0 !important;
    border-left: none;
    border-right: none;
    box-shadow: none;
  }
  html.is-mobile body.mobile-chat-open #tab-chats {
    padding-bottom: 0 !important;
    border-radius: 0;
  }
  html.is-mobile body.mobile-chat-open .chats-layout {
    height: 100%;
    min-height: 0;
  }
}
