.catec-chat {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 100;
  font-family: "Inter", "Segoe UI", sans-serif;
}

.catec-chat [hidden] {
  display: none !important;
}

.catec-chat-launcher {
  position: relative;
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  margin-left: auto;
  border: 0;
  border-radius: 50%;
  color: #fff;
  background: #ed1c2e;
  box-shadow: 0 8px 24px rgba(35, 31, 32, .3);
  cursor: pointer;
  transition: transform .2s ease, background .2s ease;
}

.catec-chat-unread,
.admin-chat-nav-badge,
.admin-chat-item-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border: 2px solid #fff;
  border-radius: 999px;
  color: #fff;
  background: #231f20;
  font-size: .72rem;
  font-weight: 700;
  line-height: 1;
}

.catec-chat-unread {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 23px;
  height: 23px;
  background: #178340;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .24);
}

.admin-chat-nav-badge {
  margin-left: 5px;
  border-width: 1px;
  vertical-align: middle;
}

.catec-chat-launcher:hover {
  background: #c8102e;
  transform: translateY(-2px);
}

.catec-chat-launcher svg {
  width: 30px;
  height: 30px;
  fill: currentColor;
}

.catec-chat-panel {
  position: absolute;
  right: 0;
  bottom: 78px;
  display: flex;
  flex-direction: column;
  width: min(390px, calc(100vw - 32px));
  height: min(570px, calc(100dvh - 120px));
  min-height: 360px;
  overflow: hidden;
  color: #231f20;
  background: #fff;
  border: 1px solid rgba(35, 31, 32, .1);
  border-radius: 20px;
  box-shadow: 0 18px 55px rgba(35, 31, 32, .28);
}

.catec-chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 74px;
  padding: 12px 16px;
  color: #fff;
  background: #c8102e;
}

.catec-chat-header img {
  width: 42px;
  height: 42px;
  border: 2px solid rgba(255, 255, 255, .75);
  border-radius: 50%;
  object-fit: cover;
}

.catec-chat-header div {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.catec-chat-header strong {
  font-size: .96rem;
}

.catec-chat-header span {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .78rem;
  opacity: .9;
}

.catec-chat-header i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9df0bf;
}

.catec-chat-close {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  color: #fff;
  background: rgba(255, 255, 255, .16);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}

.catec-chat-messages {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  padding: 18px 14px;
  background: #f7f7f8;
}

.catec-chat-welcome,
.catec-chat-bubble {
  max-width: 88%;
  margin: 0;
  padding: 11px 13px;
  border: 1px solid #ecebed;
  border-radius: 15px 15px 15px 4px;
  color: #292526;
  background: #fff;
  font-size: .9rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.catec-chat-bubble--visitor {
  align-self: flex-end;
  border-color: #c8102e;
  border-radius: 15px 15px 4px 15px;
  color: #fff;
  background: #c8102e;
}

.catec-chat-bubble--admin {
  border-color: #d7e6dc;
  background: #f0f8f2;
}

.catec-chat-bubble time {
  display: block;
  margin-top: 5px;
  font-size: .68rem;
  opacity: .72;
}

.catec-chat-status {
  margin: 0;
  padding: 8px 14px;
  color: #716b6c;
  background: #fff;
  font-size: .74rem;
  line-height: 1.4;
}

.catec-chat-form {
  display: grid;
  gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid #ecebed;
  background: #fff;
}

.catec-chat-form > input {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid #e6e3e4;
  border-radius: 8px;
  outline-color: #ed1c2e;
  font-size: .8rem;
}

.catec-chat-compose {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.catec-chat-compose textarea {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  max-height: 100px;
  resize: vertical;
  padding: 11px 12px;
  border: 1px solid #e6e3e4;
  border-radius: 12px;
  outline-color: #ed1c2e;
  font-size: .88rem;
}

.catec-chat-compose button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border: 0;
  border-radius: 12px;
  color: #fff;
  background: #ed1c2e;
  cursor: pointer;
}

.catec-chat-compose button:disabled {
  opacity: .55;
  cursor: wait;
}

.catec-chat-compose button svg {
  width: 21px;
  height: 21px;
  fill: currentColor;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  clip-path: inset(50%);
}

.admin-chat-grid {
  display: grid;
  grid-template-columns: minmax(210px, .75fr) minmax(0, 1.6fr);
  gap: 16px;
}

.admin-chat-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 430px;
  overflow-y: auto;
}

.admin-chat-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  padding: 11px;
  border: 1px solid #ddd;
  border-radius: 10px;
  color: inherit;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.admin-chat-item-badge {
  align-self: flex-start;
  border: 0;
  background: #ed1c2e;
}

.catec-chat [hidden],
.admin-chat-nav-badge[hidden],
.admin-chat-item-badge[hidden] {
  display: none !important;
}

.admin-chat-item[aria-current="true"] {
  border-color: #ed1c2e;
  background: rgba(237, 28, 46, .09);
}

.admin-chat-item span,
.admin-chat-item time {
  overflow: hidden;
  color: var(--muted, #777);
  font-size: .78rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-chat-conversation {
  display: flex;
  min-height: 320px;
  flex-direction: column;
  gap: 10px;
  max-height: 430px;
  overflow-y: auto;
  padding: 12px;
  border: 1px solid #ddd;
  border-radius: 10px;
}

.admin-chat-message {
  max-width: 88%;
  padding: 9px 11px;
  border-radius: 12px;
  background: rgba(127, 127, 127, .12);
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.admin-chat-message--visitor {
  align-self: flex-start;
}

.admin-chat-message--assistant {
  align-self: flex-start;
  border: 1px solid rgba(237, 28, 46, .2);
}

.admin-chat-message--admin {
  align-self: flex-end;
  color: #fff;
  background: #c8102e;
}

.admin-chat-message time {
  display: block;
  margin-top: 4px;
  font-size: .68rem;
  opacity: .72;
}

.admin-chat-reply {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.admin-chat-reply textarea {
  flex: 1;
  min-width: 0;
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 8px;
  resize: vertical;
}

.admin-chat-feedback {
  min-height: 1.3em;
  margin: 8px 0 0;
  color: #ed1c2e;
  font-size: .85rem;
}

@media (max-width: 640px) {
  .catec-chat {
    right: 14px;
    bottom: 14px;
  }

  .catec-chat-panel {
    right: -2px;
    bottom: 74px;
    width: calc(100vw - 24px);
    height: min(620px, calc(100dvh - 100px));
  }

  .admin-chat-grid {
    grid-template-columns: 1fr;
  }

  .admin-chat-list {
    max-height: 180px;
  }
}
