.community-chat,
.community-chat * {
  box-sizing: border-box;
}

.community-chat {
  position: fixed;
  right: 24px;
  bottom: 88px;
  z-index: 9999;
  color: #172033;
  font-family: inherit;
}

.community-chat button,
.community-chat textarea {
  font: inherit;
}

.community-chat-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  width: 48px;
  min-height: 48px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: linear-gradient(135deg, #059669, #0d9488);
  box-shadow: 0 10px 28px rgba(5, 150, 105, .3);
  cursor: pointer;
  font-weight: 600;
  font-size: 20px;
}

.community-chat-toggle > span:nth-child(2) {
  max-width: 0;
  overflow: hidden;
  white-space: nowrap;
  font-size: 14px;
  opacity: 0;
  transition: max-width .3s ease, opacity .2s ease, margin .3s ease;
}

.community-chat-toggle:hover,
.community-chat-toggle:focus-visible {
  width: auto;
  padding: 0 16px;
}

.community-chat-toggle:hover > span:nth-child(2),
.community-chat-toggle:focus-visible > span:nth-child(2) {
  max-width: 140px;
  margin-left: 9px;
  opacity: 1;
}

.community-chat-unread {
  position: absolute;
  top: -6px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  color: #fff;
  background: #ef4444;
  border: 2px solid #fff;
  font-size: 11px;
  line-height: 16px;
  text-align: center;
}

.community-chat-panel {
  position: absolute;
  right: 0;
  bottom: 56px;
  display: flex;
  flex-direction: column;
  width: min(390px, calc(100vw - 32px));
  height: auto;
  min-height: 300px;
  max-height: min(520px, calc(100dvh - 180px));
  overflow: hidden;
  border: 1px solid #dbe3ef;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 20px 60px rgba(15, 23, 42, .24);
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  transform: translateY(18px) scale(.9);
  transform-origin: bottom right;
  transition:
    opacity .22s ease,
    transform .32s cubic-bezier(.34, 1.56, .64, 1),
    visibility 0s linear .32s;
}

.community-chat-panel.is-open {
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
  transform: translateY(0) scale(1);
  transition-delay: 0s;
}

.community-chat-toggle {
  transition: transform .2s cubic-bezier(.34, 1.56, .64, 1), box-shadow .2s ease, filter .2s ease, width .3s ease, padding .3s ease;
}

.community-chat-toggle:hover {
  transform: translateY(-3px) scale(1.04);
  box-shadow: 0 16px 34px rgba(5, 150, 105, .42);
  filter: brightness(1.06);
}

.community-chat-toggle:active {
  transform: scale(.95);
}

.community-chat-toggle > span:first-child {
  display: inline-block;
  animation: community-icon-wiggle 4s ease-in-out infinite;
}

@keyframes community-icon-wiggle {
  0%, 88%, 100% { transform: rotate(0); }
  92% { transform: rotate(-14deg); }
  96% { transform: rotate(12deg); }
}

.community-chat-message {
  animation: community-message-in .25s ease both;
}

@keyframes community-message-in {
  from { opacity: 0; transform: translateY(8px) scale(.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.community-chat-chip {
  animation: community-chip-pop .25s cubic-bezier(.34, 1.56, .64, 1) both;
}

@keyframes community-chip-pop {
  from { transform: scale(.4); }
  to { transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .community-chat-panel {
    transition: opacity .15s ease, visibility 0s linear .15s;
  }

  .community-chat-toggle > span:first-child,
  .community-chat-message,
  .community-chat-chip {
    animation: none;
  }
}

.community-chat-toggle.has-unread {
  animation: community-unread-blink 1s ease-in-out infinite;
}

.community-chat-toggle.has-unread > span:first-child {
  animation: community-unread-shake .8s ease-in-out infinite;
}

.community-chat-unread {
  animation: community-unread-pulse .8s ease-in-out infinite;
}

@keyframes community-unread-blink {
  0%, 100% { box-shadow: 0 10px 28px rgba(5, 150, 105, .3), 0 0 0 0 rgba(239, 68, 68, .7); }
  50% { box-shadow: 0 10px 28px rgba(5, 150, 105, .3), 0 0 0 10px rgba(239, 68, 68, 0); filter: brightness(1.25); }
}

@keyframes community-unread-shake {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-16deg); }
  75% { transform: rotate(16deg); }
}

@keyframes community-unread-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.3); }
}

@media (prefers-reduced-motion: reduce) {
  .community-chat-toggle.has-unread {
    animation: none;
    box-shadow: 0 0 0 4px rgba(239, 68, 68, .6);
  }

  .community-chat-toggle.has-unread > span:first-child,
  .community-chat-unread {
    animation: none;
  }
}

.community-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  color: #fff;
  background: linear-gradient(135deg, #059669, #0d9488);
}

.community-chat-header strong,
.community-chat-header span {
  display: block;
}

.community-chat-header span {
  margin-top: 2px;
  font-size: 12px;
  opacity: .85;
}

.community-chat-close {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: rgba(255, 255, 255, .18);
  font-size: 22px;
  cursor: pointer;
}

.community-chat-notice {
  padding: 8px 14px;
  color: #475569;
  background: #ecfdf5;
  font-size: 12px;
  line-height: 1.4;
}

.community-chat-messages {
  flex: 1 1 auto;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  background: #f8fafc;
}

.community-chat-message {
  position: relative;
  align-self: flex-start;
  max-width: 85%;
  padding: 7px 11px;
  border: 1px solid #e2e8f0;
  border-radius: 12px 12px 12px 4px;
  background: #fff;
  font-size: 14px;
  line-height: 1.45;
}

.community-chat-message.is-mine {
  align-self: flex-end;
  border-color: transparent;
  border-radius: 12px 12px 4px 12px;
  color: #fff;
  background: #059669;
}

.community-chat-message small {
  display: block;
  margin-bottom: 2px;
  font-size: 11px;
  opacity: .8;
}

.community-chat-staff {
  margin-left: 6px;
  padding: 0 6px;
  border-radius: 999px;
  color: #fff;
  background: #dc2626;
  font-size: 10px;
}

.community-chat-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.community-chat-delete {
  position: absolute;
  top: -8px;
  right: -8px;
  display: none;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: #fee2e2;
  font-size: 11px;
  cursor: pointer;
}

.community-chat-message:hover .community-chat-delete {
  display: block;
}

.community-chat-form {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid #e5e7eb;
}

.community-chat-input {
  flex: 1;
  min-height: 40px;
  max-height: 96px;
  padding: 8px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  resize: none;
}

.community-chat-attach {
  width: 40px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  background: #fff;
  font-size: 18px;
  cursor: pointer;
}

.community-chat-attachment {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 12px;
  background: #ecfdf5;
  font-size: 12px;
}

.community-chat-attachment[hidden],
.community-chat-replybar[hidden],
.community-chat-picker[hidden] {
  display: none;
}

.community-chat-replybar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 12px;
  border-left: 3px solid #059669;
  background: #f0fdf4;
  font-size: 12px;
}

.community-chat-replybar-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.community-chat-replybar-cancel {
  border: 0;
  background: transparent;
  font-size: 18px;
  cursor: pointer;
}

.community-chat-quote {
  display: block;
  width: 100%;
  margin: 2px 0 4px;
  padding: 3px 8px;
  border: 0;
  border-left: 3px solid #059669;
  border-radius: 4px;
  background: rgba(5, 150, 105, .12);
  font-size: 12px;
  text-align: left;
  cursor: pointer;
}

.community-chat-quote b,
.community-chat-quote span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.community-chat-message.is-mine .community-chat-quote {
  border-left-color: #fff;
  color: #fff;
  background: rgba(255, 255, 255, .2);
}

.community-chat-message.is-highlight {
  box-shadow: 0 0 0 2px #fbbf24;
}

.community-chat-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
}

.community-chat-reactions {
  display: contents;
}

.community-chat-chip,
.community-chat-action {
  min-width: 24px;
  height: 22px;
  padding: 0 7px;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  color: #334155;
  background: #fff;
  font-size: 12px;
  line-height: 20px;
  cursor: pointer;
}

.community-chat-action {
  opacity: .55;
}

.community-chat-message:hover .community-chat-action,
.community-chat-action:focus-visible {
  opacity: 1;
}

.community-chat-chip.is-mine {
  border-color: #059669;
  background: #d1fae5;
}

.community-chat-picker {
  display: flex;
  gap: 2px;
  margin-top: 4px;
  padding: 3px 6px;
  border: 1px solid #e2e8f0;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 4px 14px rgba(15, 23, 42, .15);
}

.community-chat-picker button {
  padding: 2px 4px;
  border: 0;
  background: transparent;
  font-size: 18px;
  cursor: pointer;
}

.community-chat-attachment-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.community-chat-attachment-remove {
  border: 0;
  background: transparent;
  font-size: 18px;
  cursor: pointer;
}

.community-chat-media {
  margin: 2px 0 4px;
}

.community-chat-media img,
.community-chat-media video {
  display: block;
  max-width: 100%;
  max-height: 220px;
  border-radius: 8px;
}

.community-chat-media audio {
  max-width: 100%;
}

.community-chat-file-link {
  color: inherit;
  font-size: 13px;
  text-decoration: underline;
  overflow-wrap: anywhere;
}

.community-chat-send {
  min-width: 52px;
  padding: 0 16px;
  border: 0;
  border-radius: 10px;
  color: #fff;
  background: #059669;
  font-weight: 600;
  cursor: pointer;
}

.community-chat-send:disabled {
  opacity: .5;
  cursor: not-allowed;
}

.community-chat-status {
  min-height: 0;
  margin: 0;
  padding: 0 12px 6px;
  color: #dc2626;
  font-size: 12px;
}

.community-chat-status:empty {
  display: none;
}

.community-chat-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

@media (max-width: 480px) {
  .community-chat {
    right: 12px;
    bottom: 80px;
  }

  /* Chiều cao cố định để vùng tin nhắn có giới hạn và cuộn được trên mobile */
  .community-chat-panel {
    height: min(520px, calc(100vh - 180px));
    height: min(520px, calc(100dvh - 180px));
  }
}
