:root {
  --motion-ease: cubic-bezier(0.19, 1, 0.22, 1);
  --motion-duration: 0.65s;
  --motion-blur: 10px;
}

/* Page intro */
body.motion-ready .layout {
  animation: page-intro var(--motion-duration) var(--motion-ease) both;
}

@keyframes page-intro {
  0% {
    opacity: 0;
    transform: translateY(10px);
    filter: blur(3px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
    filter: blur(0px);
  }
}

/* Chat message reveal */
.msg.motion-fresh {
  animation: msg-rise 0.38s var(--motion-ease) both;
  animation-delay: var(--msg-delay, 0ms);
  transform-origin: center;
  will-change: transform, opacity, filter;
}

@keyframes msg-rise {
  0% {
    opacity: 0;
    transform: translateY(12px);
    filter: blur(6px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
    filter: blur(0px);
  }
}

/* Input + button micro interactions */
.input-pill {
  transition: box-shadow 0.3s ease;
}

.input-pill:focus-within {
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.2), 0 0 0 1px rgba(17, 24, 39, 0.06);
}

.input-pill button,
.chats-new,
.chat-item,
.sidebar-auth-btn,
.user-logout,
#newChatBtn {
  transition: box-shadow 0.35s ease, transform 0.25s ease, filter 0.25s ease;
}

.input-pill button:hover,
.chats-new:hover,
.chat-item:hover,
.sidebar-auth-btn:hover,
.user-logout:hover,
#newChatBtn:hover {
  box-shadow: 0 14px 30px rgba(15, 23, 42, 0.22);
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.05));
}

.input-pill button:focus-visible,
.chats-new:focus-visible,
.sidebar-auth-btn:focus-visible,
.user-logout:focus-visible,
#newChatBtn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(17, 24, 39, 0.24);
}

.input-pill input:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 1px rgba(17, 24, 39, 0.12);
}

/* Typing shimmer */
.msg.loading span:first-child {
  position: relative;
  overflow: hidden;
}

.msg.loading span:first-child::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 0%, rgba(15, 23, 42, 0.06) 40%, transparent 80%);
  animation: shimmer 1.4s ease-in-out infinite;
}

@keyframes shimmer {
  0% { transform: translateX(-60%); }
  100% { transform: translateX(120%); }
}

/* Focus dropdown */
.focus-dropdown {
  position: relative;
  display: inline-flex;
  align-items: center;
  margin-left: 10px;
}

.topbar-right {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.focus-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  background: rgba(255, 255, 255, 0.65);
  color: inherit;
  cursor: pointer;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  transition: box-shadow 0.3s ease, transform 0.2s ease;
}

.focus-trigger:hover,
.focus-trigger:focus-visible {
  outline: none;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.16);
}

.focus-caret {
  font-size: 10px;
  opacity: 0.6;
}

.focus-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 148px;
  padding: 8px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 20px 45px rgba(15, 23, 42, 0.26);
  display: grid;
  gap: 4px;
  opacity: 0;
  transform: translateY(-8px) scale(0.98);
  pointer-events: none;
  transition: opacity 0.26s var(--motion-ease), transform 0.26s var(--motion-ease);
  backdrop-filter: blur(14px);
  z-index: 4;
}

.focus-dropdown.open .focus-menu {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.focus-menu button {
  border: none;
  background: rgba(17, 24, 39, 0.05);
  border-radius: 10px;
  padding: 8px 10px;
  text-align: left;
  cursor: pointer;
  color: inherit;
  font-size: 12px;
  transition: background 0.2s ease, transform 0.2s ease;
}

.focus-menu button:hover,
.focus-menu button:focus-visible {
  outline: none;
  background: rgba(17, 24, 39, 0.08);
  transform: translateX(1px);
}

.focus-menu button.active {
  background: rgba(17, 24, 39, 0.12);
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
