/* ============================================================================
   chat.css - Sophia chat components
   ========================================================================== */

.chat-header {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 82px;
  padding: 1rem 1.35rem;
  border-bottom: 1px solid var(--chat-divider);
  background:
    linear-gradient(90deg, rgba(0, 117, 213, 0.08), transparent 34%),
    #ffffff;
  animation: load-in 0.52s ease 0.08s both;
}

.chat-agent {
  display: flex;
  align-items: center;
  gap: 0.82rem;
  min-width: 0;
}

.chat-agent__avatar {
  position: relative;
  flex: 0 0 auto;
  width: 3rem;
  height: 3rem;
}

.chat-agent__avatar img {
  width: 100%;
  height: 100%;
  border: 2px solid rgba(0, 117, 213, 0.24);
  border-radius: 999px;
  object-fit: cover;
  box-shadow: 0 8px 22px rgba(14, 45, 78, 0.13);
}

.status-dot {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 0.78rem;
  height: 0.78rem;
  border: 2px solid #ffffff;
  border-radius: 999px;
  background: var(--green);
  animation: ring-pulse 2.4s ease-out infinite;
}

.chat-agent__meta {
  min-width: 0;
}

.chat-agent__name {
  display: block;
  color: var(--brand-blue);
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.1;
}

.chat-agent__sub {
  display: flex;
  align-items: center;
  gap: 0.42rem;
  margin-top: 0.18rem;
  color: #10263d;
  font-size: 0.78rem;
  font-weight: 500;
  line-height: 1.2;
}

.chat-agent__sub .online {
  color: var(--green);
}

.chat-agent__sub .dot-sep {
  color: #8ca0b6;
}

.chat-actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.chat-icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.7rem;
  height: 2.7rem;
  padding: 0;
  border: 1px solid rgba(0, 117, 213, 0.34);
  border-radius: 999px;
  background: #f7fbff;
  color: var(--brand-blue);
  cursor: pointer;
  transition: transform 0.18s ease, background 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.chat-icon-button:hover {
  transform: translateY(-1px);
  border-color: var(--brand-blue);
  background: #eaf6ff;
  box-shadow: 0 10px 24px rgba(0, 117, 213, 0.18);
}

.chat-icon-button svg {
  width: 1.22rem;
  height: 1.22rem;
}

.chat-menu.dropdown-menu {
  min-width: 12.5rem;
  padding: 0.35rem;
  border: 1px solid var(--chat-divider);
  border-radius: var(--radius-sm);
  background: #ffffff;
  box-shadow: 0 18px 42px rgba(12, 34, 58, 0.2);
  color: var(--chat-ink);
  font-size: 0.86rem;
}

.chat-menu .dropdown-item {
  display: grid;
  grid-template-columns: 1.25rem minmax(0, 1fr);
  align-items: center;
  justify-items: start;
  column-gap: 0.62rem;
  width: 100%;
  min-height: 2.35rem;
  padding: 0.48rem 0.58rem;
  border-radius: 6px;
  color: var(--chat-ink);
  font-weight: 700;
  text-align: left;
}

.chat-menu__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  height: 1.25rem;
}

.chat-menu__icon svg {
  width: 1.05rem;
  height: 1.05rem;
}

.chat-menu .dropdown-item:hover,
.chat-menu .dropdown-item:focus {
  background: #edf6ff;
  color: var(--brand-blue);
}

.chat-menu .dropdown-item:active {
  background: var(--brand-blue);
  color: #ffffff;
}

.chat-body {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 0.78rem;
  min-height: 0;
  padding: 1.65rem clamp(1rem, 3.2vw, 2.6rem);
  overflow-y: auto;
  scroll-behavior: smooth;
  background:
    linear-gradient(90deg, rgba(0, 117, 213, 0.035) 1px, transparent 1px) 0 0 / 42px 42px,
    linear-gradient(0deg, rgba(0, 117, 213, 0.028) 1px, transparent 1px) 0 0 / 42px 42px,
    linear-gradient(180deg, var(--chat-body) 0%, var(--chat-body-2) 100%);
}

.chat-body::before {
  content: "";
  position: sticky;
  top: 0;
  z-index: 0;
  width: 100%;
  height: 1px;
  margin-bottom: -1px;
  background: linear-gradient(90deg, transparent, rgba(0, 117, 213, 0.34), transparent);
  pointer-events: none;
}

.chat-body::-webkit-scrollbar {
  width: 9px;
}

.chat-body::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: 999px;
  background: rgba(0, 117, 213, 0.24);
  background-clip: padding-box;
}

.chat-body::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 117, 213, 0.42);
  background-clip: padding-box;
}

.chat-message-row {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: flex-end;
  gap: 0.72rem;
  width: 100%;
  animation: bubble-in 0.42s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.chat-message-row-sophia {
  justify-content: flex-start;
}

.chat-message-row-user {
  justify-content: flex-end;
}

.chat-message-avatar {
  flex: 0 0 auto;
  width: 2.5rem;
  height: 2.5rem;
  border: 2px solid rgba(0, 117, 213, 0.2);
  border-radius: 999px;
  object-fit: cover;
  box-shadow: 0 8px 18px rgba(18, 47, 78, 0.12);
}

.chat-message {
  max-width: min(760px, 76%);
  padding: 0.88rem 1rem;
  border-radius: 8px;
  font-size: 0.92rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-message-user {
  color: #ffffff;
  border-bottom-right-radius: 3px;
  background:
    linear-gradient(135deg, rgba(117, 228, 255, 0.22), transparent 32%),
    linear-gradient(135deg, #0075d5 0%, #005da7 100%);
  box-shadow: 0 12px 30px rgba(0, 117, 213, 0.22);
}

.chat-message-sophia {
  color: var(--chat-ink);
  border: 1px solid rgba(200, 214, 230, 0.74);
  border-bottom-left-radius: 3px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 12px 28px rgba(30, 60, 92, 0.1);
}

.chat-message__author {
  display: block;
  margin-bottom: 0.22rem;
  color: var(--brand-blue);
  font-size: 0.98rem;
  font-weight: 800;
  line-height: 1.1;
}

.chat-message__time {
  display: block;
  margin-top: 0.38rem;
  color: inherit;
  font-family: var(--font-mono);
  font-size: 0.64rem;
  opacity: 0.48;
}

.chat-message-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 0.38rem;
  margin-top: 0.64rem;
}

.chat-message-attachment {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  min-height: 1.65rem;
  padding: 0.26rem 0.52rem;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.18);
  color: inherit;
  font-size: 0.72rem;
  font-weight: 700;
}

.chat-message-sophia .chat-message-attachment {
  background: #edf6ff;
  color: var(--brand-blue);
}

.chat-status {
  align-self: center;
  color: var(--chat-muted);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0;
  text-transform: uppercase;
}

.typing-row {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: flex-end;
  gap: 0.72rem;
  animation: bubble-in 0.3s ease both;
}

.typing-row[hidden] {
  display: none;
}

.typing {
  display: inline-flex;
  flex-direction: column;
  gap: 0.42rem;
  min-width: 84px;
  padding: 0.74rem 0.95rem;
  border-radius: 8px;
  border-bottom-left-radius: 3px;
  background: var(--brand-blue);
  box-shadow: 0 12px 28px rgba(0, 117, 213, 0.22);
}

.typing__dots {
  display: inline-flex;
  align-items: center;
  gap: 0.34rem;
}

.typing__dots span {
  width: 0.42rem;
  height: 0.42rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.96);
  animation: typing-bounce 1.2s ease-in-out infinite;
}

.typing__dots span:nth-child(2) {
  animation-delay: 0.18s;
}

.typing__dots span:nth-child(3) {
  animation-delay: 0.36s;
}

.typing__sweep {
  position: relative;
  height: 2px;
  width: 100%;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
}

.typing__sweep::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.85), transparent);
  animation: pillar-sweep 1.55s ease-in-out infinite;
}

.quick-replies {
  position: relative;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 0.42rem;
  max-width: min(770px, calc(100% - 3.2rem));
  margin-left: 3.22rem;
  animation: load-in 0.4s ease 0.12s both;
}

.quick-replies:empty {
  display: none;
}

.quick-reply {
  min-height: 1.5rem;
  padding: 0.3rem 0.62rem;
  border: 0;
  border-radius: 7px;
  color: #ffffff;
  font-size: clamp(0.63rem, 0.6rem + 0.15vw, 0.72rem);
  font-weight: 800;
  line-height: 1.2;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(22, 49, 82, 0.14);
  transition: transform 0.16s ease, filter 0.16s ease, box-shadow 0.16s ease;
}

.quick-reply:nth-child(1) {
  background: #00aeef;
}

.quick-reply:nth-child(2) {
  background: var(--brand-blue);
}

.quick-reply:nth-child(3) {
  background: #009c57;
}

.quick-reply:hover {
  transform: translateY(-1px);
  filter: saturate(1.08) brightness(1.03);
  box-shadow: 0 12px 24px rgba(22, 49, 82, 0.2);
}

.chat-composer {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 1rem;
  align-items: end;
  padding: 1rem 1rem 1rem 1.1rem;
  border-top: 1px solid var(--chat-divider);
  background:
    linear-gradient(90deg, rgba(0, 117, 213, 0.06), transparent 38%),
    #ffffff;
  animation: load-in 0.52s ease 0.2s both;
}

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
}

.file-preview {
  display: flex;
  grid-column: 1 / -1;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.file-preview:empty {
  display: none;
}

.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  max-width: min(100%, 18rem);
  min-height: 1.9rem;
  padding: 0.28rem 0.42rem 0.28rem 0.62rem;
  border: 1px solid rgba(0, 117, 213, 0.18);
  border-radius: 7px;
  background: #edf6ff;
  color: var(--chat-ink);
  font-size: 0.74rem;
  font-weight: 700;
  box-shadow: 0 8px 18px rgba(20, 58, 96, 0.08);
}

.file-chip__name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-chip__remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  height: 1.25rem;
  border: 0;
  border-radius: 999px;
  background: #ffffff;
  color: var(--brand-blue);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

.chat-composer__input {
  width: 100%;
  min-width: 0;
  min-height: 3.1rem;
  max-height: 7.5rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--input-line);
  border-radius: 8px;
  color: var(--chat-ink);
  background: var(--input-bg);
  font-family: var(--font-body);
  font-size: 0.9rem;
  line-height: 1.45;
  resize: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.chat-composer__input::placeholder {
  color: #72849a;
}

.chat-composer__input:focus {
  outline: none;
  border-color: var(--brand-blue);
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(0, 117, 213, 0.13);
}

.chat-attach,
.chat-voice,
.chat-stop,
.chat-send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 3.1rem;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.16s ease, box-shadow 0.16s ease, opacity 0.16s ease, background 0.16s ease;
}

.chat-attach {
  width: 3.1rem;
  border: 1px solid var(--input-line);
  background: #f7fbff;
  color: var(--brand-blue);
}

.chat-attach svg {
  width: 1.28rem;
  height: 1.28rem;
}

.chat-attach:hover {
  transform: translateY(-1px);
  border-color: var(--brand-blue);
  background: #eef8ff;
  box-shadow: 0 10px 24px rgba(0, 117, 213, 0.14);
}

.chat-voice {
  width: 3.1rem;
  border: 2px solid var(--brand-blue);
  background: #ffffff;
  color: var(--brand-blue);
}

.chat-voice svg {
  width: 1.35rem;
  height: 1.35rem;
}

.chat-voice:hover {
  transform: translateY(-1px);
  background: #eef8ff;
  box-shadow: 0 10px 24px rgba(0, 117, 213, 0.16);
}

.chat-voice.is-listening {
  border-color: #1494f5;
  background: linear-gradient(135deg, #1494f5, #0075d5);
  color: #ffffff;
  box-shadow:
    0 0 0 4px rgba(0, 117, 213, 0.14),
    0 12px 28px rgba(0, 117, 213, 0.24);
}

.chat-stop {
  grid-column: 4;
  gap: 0.48rem;
  min-width: 7.2rem;
  padding: 0 1.05rem;
  border: 1px solid rgba(230, 74, 74, 0.34);
  background: #fff5f5;
  color: #c82727;
  font-size: 0.86rem;
  font-weight: 800;
}

.chat-stop svg {
  width: 1rem;
  height: 1rem;
}

.chat-stop:hover {
  transform: translateY(-1px);
  border-color: #c82727;
  background: #ffecec;
  box-shadow: 0 10px 24px rgba(200, 39, 39, 0.12);
}

.chat-send {
  position: relative;
  grid-column: 4;
  overflow: hidden;
  gap: 0.55rem;
  min-width: 7.2rem;
  padding: 0 1.15rem;
  border: 0;
  background: linear-gradient(135deg, #1494f5, #0075d5);
  color: #ffffff;
  font-size: 0.88rem;
  font-weight: 800;
  box-shadow: 0 12px 26px rgba(0, 117, 213, 0.26);
}

.chat-send span,
.chat-send svg {
  position: relative;
  z-index: 1;
}

.chat-send svg {
  width: 1.25rem;
  height: 1.25rem;
}

.chat-send::before {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-120%);
  background: linear-gradient(120deg, transparent, rgba(255, 255, 255, 0.44), transparent);
  transition: transform 0.55s ease;
}

.chat-send:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 16px 34px rgba(0, 117, 213, 0.34);
}

.chat-send:hover:not(:disabled)::before {
  transform: translateX(120%);
}

.chat-send:active:not(:disabled),
.chat-attach:active,
.chat-voice:active,
.chat-stop:active {
  transform: translateY(0) scale(0.98);
}

.chat-send:disabled {
  opacity: 0.52;
  cursor: not-allowed;
  box-shadow: none;
}

.chat-send[hidden],
.chat-stop[hidden] {
  display: none !important;
}

.chat-closed {
  width: min(92vw, 480px);
  padding: 2rem;
  border: 1px solid rgba(170, 213, 255, 0.36);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(0, 117, 213, 0.18), transparent 36%),
    rgba(255, 255, 255, 0.96);
  color: var(--chat-ink);
  text-align: center;
  box-shadow:
    0 30px 84px rgba(0, 0, 0, 0.36),
    0 0 0 10px rgba(3, 13, 28, 0.62);
  animation: shell-enter 0.42s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.chat-closed__avatar {
  width: 4.4rem;
  height: 4.4rem;
  margin: 0 auto 1rem;
  border: 2px solid rgba(0, 117, 213, 0.28);
  border-radius: 999px;
  object-fit: cover;
}

.chat-closed h2 {
  margin: 0;
  color: var(--brand-blue);
  font-size: 1.35rem;
  font-weight: 800;
}

.chat-closed p {
  margin: 0.65rem auto 1.25rem;
  max-width: 22rem;
  color: #4d6077;
  font-size: 0.92rem;
}

.chat-closed__button {
  min-height: 2.75rem;
  padding: 0 1.15rem;
  border: 0;
  border-radius: 8px;
  background: linear-gradient(135deg, #1494f5, #0075d5);
  color: #ffffff;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 14px 30px rgba(0, 117, 213, 0.28);
}

@keyframes load-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes bubble-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes typing-bounce {
  0%, 60%, 100% {
    opacity: 0.6;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-4px);
  }
}

@keyframes ring-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(28, 191, 99, 0.55);
  }
  70% {
    box-shadow: 0 0 0 9px rgba(28, 191, 99, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(28, 191, 99, 0);
  }
}

@keyframes pillar-sweep {
  0% {
    transform: translateX(-100%);
  }
  60% {
    transform: translateX(100%);
  }
  100% {
    transform: translateX(100%);
  }
}

@media (max-width: 720px) {
  .chat-header {
    min-height: 72px;
    padding: 0.85rem 0.9rem;
  }

  .chat-agent__avatar {
    width: 2.7rem;
    height: 2.7rem;
  }

  .chat-actions {
    gap: 0.42rem;
  }

  .chat-icon-button {
    width: 2.45rem;
    height: 2.45rem;
  }

  .chat-body {
    padding: 1rem 0.82rem;
  }

  .chat-message {
    max-width: calc(100% - 3.6rem);
    font-size: 0.86rem;
  }

  .quick-replies {
    max-width: calc(100% - 3.2rem);
    margin-left: 3.1rem;
  }

  .quick-reply {
    max-width: 100%;
  }

  .chat-composer {
    grid-template-columns: 2.85rem minmax(0, 1fr) 2.85rem 2.85rem;
    gap: 0.55rem;
    padding: 0.8rem 0.75rem max(0.8rem, env(safe-area-inset-bottom));
  }

  .chat-composer__input,
  .chat-attach,
  .chat-voice,
  .chat-stop,
  .chat-send {
    min-height: 2.85rem;
  }

  .chat-composer__input {
    min-height: 3.25rem;
    padding: 0.95rem 1.05rem;
    line-height: 1.4;
  }

  .chat-attach,
  .chat-voice {
    width: 2.85rem;
  }

  .chat-send {
    width: 2.85rem;
    min-width: 2.85rem;
    padding: 0;
  }

  .chat-stop {
    width: 2.85rem;
    min-width: 2.85rem;
    padding: 0;
  }

  .chat-send span,
  .chat-stop span {
    display: none;
  }
}

@media (max-width: 420px) {
  .chat-agent__sub {
    flex-wrap: wrap;
    gap: 0.22rem 0.32rem;
    max-width: none;
    overflow: visible;
    white-space: normal;
    font-size: 0.72rem;
  }

  .chat-message-avatar {
    width: 2.25rem;
    height: 2.25rem;
  }

  .chat-message {
    max-width: calc(100% - 3.15rem);
    padding: 0.75rem 0.82rem;
  }

  .quick-replies {
    margin-left: 2.95rem;
  }

  .quick-reply {
    width: 100%;
    text-align: left;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
  }

  .chat-body {
    scroll-behavior: auto;
  }
}
