.alg-chat-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 99999;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: #1229ad;
  border: 0;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 6px 28px rgba(18, 41, 173, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
}
.alg-chat-fab:hover {
  transform: scale(1.08);
  box-shadow: 0 10px 36px rgba(18, 41, 173, 0.4);
}
.alg-chat-fab:active {
  transform: scale(0.94);
}
.alg-chat-fab svg {
  width: 24px;
  height: 24px;
}
.alg-chat-fab .close-icon {
  display: none;
}
.alg-chat-fab.is-open .open-icon {
  display: none;
}
.alg-chat-fab.is-open .close-icon {
  display: block;
}

.alg-chat-fab-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 20px;
  height: 20px;
  background: #22c55e;
  border: 2.5px solid #fff;
  border-radius: 50%;
  animation: algPulse 2s infinite;
}

.alg-chat-widget {
  position: fixed;
  bottom: 92px;
  right: 24px;
  z-index: 99998;
  width: 380px;
  max-width: calc(100vw - 48px);
  height: 580px;
  max-height: calc(100dvh - 140px);
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.14), 0 8px 24px rgba(0, 0, 0, 0.06);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(0.96);
  pointer-events: none;
  transition: opacity 0.3s cubic-bezier(0.22, 1, 0.36, 1), transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
  transform-origin: bottom right;
}
.alg-chat-widget.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.alg-chat-head {
  flex-shrink: 0;
  padding: 16px 20px;
  background: linear-gradient(135deg, #1229ad 0%, #1f41db 100%);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
  overflow: hidden;
}
.alg-chat-head::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: radial-gradient(circle at 20% 30%, rgba(255,255,255,0.08), transparent 60%);
  pointer-events: none;
}
.alg-chat-head-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
}
.alg-chat-head-avatar svg {
  width: 20px;
  height: 20px;
}
.alg-chat-head-info {
  flex: 1;
  min-width: 0;
  position: relative;
  z-index: 1;
}
.alg-chat-head-info h5 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.3;
  color: #fff;
}
.alg-chat-head-info .alg-status {
  font-size: 0.7rem;
  opacity: 0.82;
  display: flex;
  align-items: center;
  gap: 5px;
}
.alg-chat-head-info .alg-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #22c55e;
  display: inline-block;
  animation: algPulse 2s infinite;
}
.alg-chat-head-close {
  background: none;
  border: 0;
  color: rgba(255, 255, 255, 0.7);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  transition: background 0.2s, color 0.2s;
  display: flex;
  position: relative;
  z-index: 1;
}
.alg-chat-head-close:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.alg-chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: linear-gradient(180deg, #f8faff 0%, #f0f5ff 100%);
}
.alg-chat-body::-webkit-scrollbar {
  width: 4px;
}
.alg-chat-body::-webkit-scrollbar-track {
  background: transparent;
}
.alg-chat-body::-webkit-scrollbar-thumb {
  background: #d0d7ec;
  border-radius: 4px;
}

.alg-chat-date-sep {
  text-align: center;
  font-size: 0.68rem;
  color: #aab3cc;
  padding: 4px 0;
  font-weight: 500;
}

.alg-chat-bubble {
  max-width: 85%;
  padding: 11px 15px;
  border-radius: 18px;
  font-size: 0.92rem;
  line-height: 1.5;
  word-wrap: break-word;
  position: relative;
  animation: algBubbleIn 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}
.alg-chat-bubble .alg-time {
  font-size: 0.6rem;
  opacity: 0.5;
  margin-top: 4px;
  display: block;
}
.alg-chat-bubble.bot .alg-time {
  color: #6d7a9e;
}
.alg-chat-bubble.user .alg-time {
  color: rgba(255, 255, 255, 0.6);
  text-align: right;
}
.alg-chat-bubble.bot {
  align-self: flex-start;
  background: #fff;
  border: 1px solid #e8ecf5;
  color: #1a2038;
  border-bottom-left-radius: 5px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}
.alg-chat-bubble.user {
  align-self: flex-end;
  background: linear-gradient(135deg, #1229ad, #1f41db);
  color: #fff;
  border-bottom-right-radius: 5px;
  box-shadow: 0 2px 8px rgba(18, 41, 173, 0.18);
}

.alg-chat-typing {
  align-self: flex-start;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 15px 12px;
  background: #fff;
  border: 1px solid #e8ecf5;
  border-radius: 18px;
  border-bottom-left-radius: 5px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
  max-width: 85%;
  animation: algBubbleIn 0.25s ease;
}
.alg-chat-typing-label {
  font-size: 0.72rem;
  color: #6d7a9e;
  font-weight: 500;
}
.alg-chat-typing-dots {
  display: flex;
  gap: 5px;
}
.alg-chat-typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #aab3cc;
  animation: algDotBounce 1.2s infinite ease-in-out;
}
.alg-chat-typing-dots span:nth-child(2) {
  animation-delay: 0.15s;
}
.alg-chat-typing-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

.alg-chat-typing-ctx {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: #8892b0;
  padding: 2px 0 2px 4px;
  animation: algBubbleIn 0.2s ease;
}
.alg-chat-typing-ctx .ctx-pulse {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #22c55e;
  animation: algPulse 1.5s infinite;
}

.alg-chat-actions {
  flex-shrink: 0;
  padding: 8px 14px 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  background: #fff;
  border-top: 1px solid #eff1f7;
}
.alg-chat-chip {
  border: 1px solid #dce2f2;
  background: #fff;
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 0.8rem;
  color: #1a2444;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.22, 1, 0.36, 1);
  white-space: nowrap;
  font-family: inherit;
}
.alg-chat-chip:hover {
  border-color: #1229ad;
  color: #1229ad;
  background: #f5f7ff;
  transform: translateY(-1px);
}
.alg-chat-chip:active {
  transform: scale(0.96);
}

.alg-chat-foot {
  flex-shrink: 0;
  display: flex;
  gap: 8px;
  padding: 10px 14px 14px;
  background: #fff;
  border-top: 1px solid #eff1f7;
  align-items: center;
}
.alg-chat-foot input {
  flex: 1;
  border: 1.5px solid #dce2f2;
  border-radius: 999px;
  padding: 10px 16px;
  font-size: 0.9rem;
  outline: 0;
  transition: border-color 0.2s, box-shadow 0.2s;
  font-family: inherit;
}
.alg-chat-foot input:focus {
  border-color: #1229ad;
  box-shadow: 0 0 0 3px rgba(18, 41, 173, 0.1);
}
.alg-chat-foot input::placeholder {
  color: #aab3cc;
}
.alg-chat-foot input:disabled {
  background: #f5f7fc;
  cursor: not-allowed;
}
.alg-chat-foot button {
  flex-shrink: 0;
  border: 0;
  background: #1229ad;
  color: #fff;
  border-radius: 999px;
  padding: 10px 20px;
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  line-height: 1;
}
.alg-chat-foot button:hover {
  background: #0f2393;
  box-shadow: 0 4px 12px rgba(18, 41, 173, 0.25);
}
.alg-chat-foot button:active {
  transform: scale(0.96);
}
.alg-chat-foot button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}
.alg-chat-foot button .send-label {
  display: none;
}
@media (min-width: 420px) {
  .alg-chat-foot button .send-label {
    display: inline;
  }
}
.alg-chat-foot button svg {
  width: 16px;
  height: 16px;
}

@keyframes algBubbleIn {
  0% {
    opacity: 0;
    transform: translateY(10px) scale(0.96);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}
@keyframes algDotBounce {
  0%, 80%, 100% {
    opacity: 0.4;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-4px);
  }
}
@keyframes algPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4);
  }
  70% {
    box-shadow: 0 0 0 6px rgba(34, 197, 94, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0);
  }
}

.alg-chat-msg-hidden {
  visibility: hidden;
  position: absolute;
  white-space: pre-wrap;
}

@media (max-width: 768px) {
  .alg-chat-widget {
    right: 12px;
    bottom: 80px;
    width: calc(100vw - 24px);
    max-width: 420px;
    height: calc(100dvh - 130px);
    max-height: 600px;
    border-radius: 18px;
  }
  .alg-chat-fab {
    bottom: 18px;
    right: 18px;
    width: 54px;
    height: 54px;
  }
}

@media (max-width: 480px) {
  .alg-chat-widget {
    right: 0;
    bottom: 0;
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    box-shadow: none;
  }
  .alg-chat-fab {
    bottom: 14px;
    right: 14px;
    width: 50px;
    height: 50px;
  }
  .alg-chat-head {
    padding: 12px 14px;
  }
  .alg-chat-body {
    padding: 12px;
  }
  .alg-chat-bubble {
    max-width: 88%;
    font-size: 0.9rem;
    padding: 10px 13px;
  }
  .alg-chat-actions {
    padding: 6px 10px 10px;
  }
  .alg-chat-chip {
    font-size: 0.76rem;
    padding: 6px 11px;
  }
  .alg-chat-foot {
    padding: 8px 10px 12px;
    gap: 6px;
  }
  .alg-chat-foot input {
    padding: 9px 13px;
    font-size: 0.88rem;
  }
  .alg-chat-foot button {
    padding: 9px 14px;
    font-size: 0.85rem;
  }
  .alg-chat-foot button .send-label {
    display: none;
  }
  .alg-chat-typing-ctx {
    font-size: 0.68rem;
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  .alg-chat-widget {
    height: 100dvh;
    max-height: 100dvh;
    bottom: 0;
    right: 0;
    width: 100vw;
    max-width: 100vw;
    border-radius: 0;
  }
  .alg-chat-body {
    max-height: none;
  }
  .alg-chat-fab {
    display: none;
  }
}
