.lglg-chat {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  z-index: 9999;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #1e293b;
}

.lglg-chat__trigger {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-width: 3.5rem;
  height: 3.5rem;
  padding: 0 1rem;
  border: 1px solid var(--lglg-accent, #2563eb);
  border-radius: 9999px;
  background: var(--lglg-accent, #2563eb);
  color: var(--lglg-accent-contrast, #ffffff);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.18);
}

.lglg-chat__trigger svg {
  flex-shrink: 0;
}

.lglg-chat__badge {
  position: absolute;
  top: -0.25rem;
  right: -0.25rem;
  min-width: 1.35rem;
  height: 1.35rem;
  padding: 0 0.35rem;
  border-radius: 9999px;
  background: #dc2626;
  color: #ffffff;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.35rem;
  text-align: center;
}

.lglg-chat__badge:empty,
.lglg-chat__badge[hidden] {
  display: none;
}

.lglg-chat__trigger:focus-visible,
.lglg-chat button:focus-visible,
.lglg-chat textarea:focus-visible,
.lglg-chat input:focus-visible,
.lglg-chat select:focus-visible {
  outline: 3px solid var(--lglg-accent, #2563eb);
  outline-offset: 2px;
}

.lglg-chat__panel {
  position: absolute;
  right: 0;
  bottom: 4.5rem;
  display: none;
  width: 320px;
  height: 450px;
  min-width: 320px;
  min-height: 320px;
  overflow: hidden;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  background: #ffffff;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.2);
}

.lglg-chat--open .lglg-chat__panel {
  display: flex;
  flex-direction: column;
}

.lglg-chat__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  background: #1e293b;
  color: #ffffff;
}

.lglg-chat__header strong,
.lglg-chat__header span {
  display: block;
}

.lglg-chat__header span {
  margin-top: 0.15rem;
  color: #cbd5e1;
  font-size: 0.75rem;
}

.lglg-chat__avatar {
  width: 2rem;
  height: 2rem;
  border-radius: 9999px;
  object-fit: cover;
  flex-shrink: 0;
}

.lglg-chat__close {
  border: 0;
  background: transparent;
  color: #ffffff;
  font-size: 1.5rem;
  cursor: pointer;
}

.lglg-chat__offline {
  margin: 0;
  padding: 0.5rem 1rem;
  background: #fff7ed;
  color: #9a3412;
  font-size: 0.75rem;
}

.lglg-chat__messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  background: #f1f5f9;
}

.lglg-chat__onboarding { flex: 1; overflow-y: auto; padding: 1rem; background: #f8fafc; }
.lglg-chat__setup { display: grid; gap: 0.75rem; }
.lglg-chat__field { display: grid; gap: 0.3rem; font-size: 0.8rem; font-weight: 600; }
.lglg-chat__field input, .lglg-chat__field select { min-width: 0; border: 1px solid #cbd5e1; border-radius: 8px; padding: 0.65rem; background: #fff; color: #1e293b; }
.lglg-chat__setup button, .lglg-chat__change { border: 1px solid var(--lglg-accent, #2563eb); border-radius: 8px; padding: 0.65rem; background: var(--lglg-accent, #2563eb); color: var(--lglg-accent-contrast, #ffffff); font-weight: 600; cursor: pointer; }
.lglg-chat__change { align-self: center; background: #fff; color: #1e293b; border-color: #cbd5e1; padding: 0.45rem; }

.lglg-chat__message,
.lglg-chat__welcome {
  width: fit-content;
  max-width: 85%;
  margin: 0 0 0.75rem;
  padding: 0.65rem 0.8rem;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  background: #ffffff;
  line-height: 1.4;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.lglg-chat__resume-banner {
  width: fit-content;
  max-width: 90%;
  margin: 0 auto 0.75rem;
  padding: 0.45rem 0.8rem;
  border-radius: 999px;
  background: #e2e8f0;
  color: #475569;
  font-size: 0.75rem;
  text-align: center;
}

.lglg-chat__message {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.lglg-chat__message p {
  margin: 0;
}

.lglg-chat__message time {
  font-size: 0.7rem;
  color: #64748b;
}

.lglg-chat__message--client {
  margin-left: auto;
  border-color: var(--lglg-accent, #2563eb);
  background: var(--lglg-accent, #2563eb);
  color: var(--lglg-accent-contrast, #ffffff);
}

.lglg-chat__message--client time {
  color: var(--lglg-accent-contrast, #ffffff);
  opacity: 0.8;
}

.lglg-chat__message[data-pending="1"] {
  opacity: 0.7;
}

.lglg-chat__message[data-failed="1"] {
  border-color: #dc2626;
  background: #fef2f2;
  color: #1e293b;
}

.lglg-chat__retry {
  align-self: flex-start;
  margin-top: 0.25rem;
  border: 1px solid #dc2626;
  border-radius: 6px;
  padding: 0.25rem 0.5rem;
  background: #ffffff;
  color: #dc2626;
  font-size: 0.75rem;
  cursor: pointer;
}

.lglg-chat__status {
  min-height: 1.25rem;
  margin: 0;
  padding: 0 1rem;
  color: #b91c1c;
  background: #ffffff;
  font-size: 0.75rem;
}

.lglg-chat__status--loading {
  color: #64748b;
}

.lglg-chat__form {
  padding: 0.75rem;
  border-top: 1px solid #e5e7eb;
  background: #ffffff;
}

.lglg-chat__composer {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.lglg-chat__form textarea {
  flex: 1;
  min-width: 0;
  resize: none;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  padding: 0.65rem;
  color: #1e293b;
  background: #ffffff;
}

.lglg-chat__form textarea:disabled {
  background: #f1f5f9;
  opacity: 0.7;
}

.lglg-chat__form button[type="submit"] {
  align-self: stretch;
  flex-shrink: 0;
  white-space: nowrap;
  border: 1px solid var(--lglg-accent, #2563eb);
  border-radius: 12px;
  padding: 0 0.9rem;
  background: var(--lglg-accent, #2563eb);
  color: var(--lglg-accent-contrast, #ffffff);
  font-weight: 600;
  cursor: pointer;
}

.lglg-chat__form button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.lglg-chat__file {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.lglg-chat__file-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 2.5rem;
  min-width: 2.5rem;
  height: 2.5rem;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  background: #ffffff;
  color: #64748b;
  cursor: pointer;
}

.lglg-chat__attachment-area:empty {
  display: none;
}

.lglg-chat__attachment-preview {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 0.5rem;
  padding: 0.5rem;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  background: #f8fafc;
  font-size: 0.8rem;
  min-width: 0;
}

.lglg-chat__attachment-thumb {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 8px;
  background: #ffffff;
  overflow: hidden;
}

.lglg-chat__attachment-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.lglg-chat__attachment-icon {
  font-size: 1.25rem;
  line-height: 1;
}

.lglg-chat__attachment-info {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  gap: 0.15rem;
}

.lglg-chat__attachment-name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #1e293b;
  font-weight: 500;
}

.lglg-chat__attachment-size {
  display: block;
  color: #64748b;
  font-size: 0.7rem;
}

.lglg-chat__attachment-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 1.75rem;
  height: 1.75rem;
  margin-inline-start: auto;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #64748b;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.lglg-chat__attachment-remove:hover,
.lglg-chat__attachment-remove:focus {
  background: #f1f5f9;
  color: #1e293b;
}

.lglg-chat__sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.lglg-chat[dir="rtl"] {
  right: auto;
  left: 1.5rem;
}

.lglg-chat[dir="rtl"] .lglg-chat__panel {
  right: auto;
  left: 0;
}

.lglg-chat[dir="rtl"] .lglg-chat__badge {
  right: auto;
  left: -0.25rem;
}

.lglg-chat[dir="rtl"] .lglg-chat__message--client {
  margin-left: 0;
  margin-right: auto;
}

.lglg-chat--left {
  right: auto;
  left: 1.5rem;
}

.lglg-chat--left .lglg-chat__panel {
  right: auto;
  left: 0;
}

.lglg-chat--left .lglg-chat__badge {
  right: auto;
  left: -0.25rem;
}

.lglg-chat--left[dir="rtl"] {
  left: auto;
  right: 1.5rem;
}

.lglg-chat--left[dir="rtl"] .lglg-chat__panel {
  left: auto;
  right: 0;
}

.lglg-chat--left[dir="rtl"] .lglg-chat__badge {
  left: auto;
  right: -0.25rem;
}

@media (max-width: 420px) {
  .lglg-chat {
    right: 1rem;
    bottom: 1rem;
  }

  .lglg-chat[dir="rtl"] {
    right: auto;
    left: 1rem;
  }

  .lglg-chat--left {
    left: 1rem;
  }

  .lglg-chat--left[dir="rtl"] {
    right: 1rem;
    left: auto;
  }

  .lglg-chat__panel {
    position: fixed;
    inset: 1rem;
    width: auto;
    height: auto;
    min-width: auto;
    max-height: calc(100dvh - 2rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  .lglg-chat * {
    scroll-behavior: auto;
  }
}
