.sosafe-ai-chat-widget {
  --sosafe-ai-chat-bg: #ffffff;
  --sosafe-ai-chat-border: #1b1b1b;
  --sosafe-ai-chat-text: #1b1b1b;
  --sosafe-ai-chat-muted: rgba(27, 27, 27, 0.8);
  --sosafe-ai-chat-user-text: #ffffff;
  --sosafe-ai-chat-assistant-bg: #eef4fb;
  --sosafe-ai-chat-assistant-text: #1b1b1b;

  width: 100%;
  max-width: 880px;
  margin-top: 2rem;
}

.sosafe-ai-chat {
  width: 100%;
  display: flex;
  flex-direction: column;
  padding: 1rem;
  border: 1px solid var(--sosafe-ai-chat-border);
  border-radius: 1rem;
  background: var(--sosafe-ai-chat-bg);
  color: var(--sosafe-ai-chat-text);
  transition: padding 0.22s ease, box-shadow 0.22s ease, border-radius 0.22s ease;
}

.sosafe-ai-chat__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 1rem;
  gap: 1rem;
  border-bottom: 1px solid rgba(18, 32, 51, 0.14);
}

.sosafe-ai-chat__title {
  margin: 0;
}

.sosafe-ai-chat__messages {
  min-height: var(--sosafe-ai-chat-min-height, 360px);
  max-height: 560px;
  display: none;
  flex-direction: column;
  gap: 0.85rem;
  overflow-y: auto;
  padding-right: 0.25rem;
}

.sosafe-ai-chat__empty {
  margin: auto 0;
  padding: 1.25rem;
  border: 1px dashed var(--sosafe-ai-chat-border);
  border-radius: 18px;
  text-align: center;
  color: var(--sosafe-ai-chat-muted);
  background: #f8fbff;
}

.sosafe-ai-chat__message {
  display: flex;
}

.sosafe-ai-chat__message--assistant {
  justify-content: flex-start;
}

.sosafe-ai-chat__message--user {
  justify-content: flex-end;
}

.sosafe-ai-chat__bubble {
  max-width: min(85%, 42rem);
  padding: 0.9rem 1rem;
  border-radius: 20px;
  line-height: 1.5;
  word-break: break-word;
  text-align: left;
  font-size: 0.875rem;
}

.sosafe-ai-chat__message--assistant .sosafe-ai-chat__bubble {
  background: var(--sosafe-ai-chat-assistant-bg);
  color: var(--sosafe-ai-chat-assistant-text);
  border-bottom-left-radius: 2px;
}

.sosafe-ai-chat__message--user .sosafe-ai-chat__bubble {
  background: #42033D;
  color: var(--sosafe-ai-chat-user-text);
  border-bottom-right-radius: 2px;
}

.sosafe-ai-chat__bubble p,
.sosafe-ai-chat__bubble ul,
.sosafe-ai-chat__bubble ol,
.sosafe-ai-chat__bubble pre {
  margin: 0;
}

.sosafe-ai-chat__bubble p+p,
.sosafe-ai-chat__bubble p+ul,
.sosafe-ai-chat__bubble p+ol,
.sosafe-ai-chat__bubble ul+p,
.sosafe-ai-chat__bubble ol+p,
.sosafe-ai-chat__bubble pre+p {
  margin-top: 0.75rem;
}

.sosafe-ai-chat__bubble ul,
.sosafe-ai-chat__bubble ol {
  padding-left: 1.25rem;
}

.sosafe-ai-chat__bubble code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.95em;
  padding: 0.15rem 0.35rem;
  border-radius: 6px;
  background: rgba(18, 32, 51, 0.08);
}

.sosafe-ai-chat__code {
  overflow-x: auto;
  padding: 0.85rem;
  border-radius: 14px;
  background: #0f172a;
  color: #e2e8f0;
}

.sosafe-ai-chat__code code {
  padding: 0;
  background: transparent;
  color: inherit;
}

.sosafe-ai-chat__bubble a {
  color: inherit;
  text-decoration: underline;
  font-weight: bold;
}

.sosafe-ai-chat__bubble a:hover {
  color: #42033D;
}

.sosafe-ai-chat__bubble--typing {
  position: relative;
  color: var(--sosafe-ai-chat-muted);
}

.sosafe-ai-chat__bubble--typing::after {
  content: "...";
  display: inline-block;
  width: 1.25rem;
  margin-left: 0.3rem;
  animation: sosafe-ai-chat-pulse 1.2s ease-in-out infinite;
}

.sosafe-ai-chat__form {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 0.85rem;
  align-items: center;
  padding-top: 0;
  border-top: 0;
}

.sosafe-ai-chat__search-icon {
  width: 3.5rem;
  height: 3.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-radius: 999px;
  background: rgba(22, 230, 255, 0.15);
  color: #122033;
}

.sosafe-ai-chat__search-icon svg {
  width: 1.35rem;
  height: 1.35rem;
  fill: currentColor;
}

.sosafe-ai-chat__input {
  min-height: 56px;
  max-height: 160px;
  width: 100%;
  margin: 0;
  resize: none;
  padding: 1.125rem 0 0.5rem;
  border: 0;
  border-radius: 0;
  font: inherit;
  line-height: 1.35;
  color: var(--sosafe-ai-chat-text);
  background: transparent;
  box-shadow: none;
}

.sosafe-ai-chat__input:focus {
  outline: none;
  box-shadow: none;
}

.sosafe-ai-chat__button {
  width: 3.5rem;
  min-width: 3.5rem;
  height: 3.5rem;
  min-height: 3.5rem;
  padding: 0;
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-weight: 600;
  color: #1d1d1d;
  background: #16e6ff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, opacity 0.15s ease, box-shadow 0.15s ease;
}

.sosafe-ai-chat__button svg {
  width: 1.5rem;
  height: 1.5rem;
  display: block;
  fill: currentColor;
  transition: all 0.2s ease;
}

.sosafe-ai-chat__button:hover:not(:disabled) svg {
  transform: rotate(-45deg);
}

.sosafe-ai-chat__button:disabled,
.sosafe-ai-chat__input:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

.sosafe-ai-chat__notice {
  padding: 0.85rem 1rem;
  border-radius: 14px;
  background: #fff8e8;
  color: #7b5b16;
  border: 1px solid #f0d897;
}

.sosafe-ai-chat__notice-detail {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.92rem;
}

.sosafe-ai-chat:not(.sosafe-ai-chat--active) .sosafe-ai-chat__header {
  display: none;
}

.sosafe-ai-chat:not(.sosafe-ai-chat--active) .sosafe-ai-chat__empty {
  display: none;
}

.sosafe-ai-chat--active {
  padding: 1rem;
  border-radius: 24px;
}

.sosafe-ai-chat--active .sosafe-ai-chat__messages {
  display: flex;
  padding: 0.5rem 0;
}

.sosafe-ai-chat--active .sosafe-ai-chat__form {
  padding-top: 1rem;
  border-top: 1px solid rgba(18, 32, 51, 0.14);
}

.sosafe-ai-chat--active .sosafe-ai-chat__input {
  min-height: 52px;
  padding: 0.75rem 0 0;
}

.sosafe-ai-chat--active .sosafe-ai-chat__button {
  width: 3.25rem;
  min-width: 3.25rem;
  height: 3.25rem;
  min-height: 3.25rem;
}

.sosafe-ai-chat[aria-busy="true"] .sosafe-ai-chat__messages {
  cursor: progress;
}

@keyframes sosafe-ai-chat-pulse {

  0%,
  100% {
    opacity: 0.35;
  }

  50% {
    opacity: 1;
  }
}

.sosafe-ai-chat__suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
  justify-content: center;
}

.sosafe-ai-chat__pill {
  white-space: nowrap;
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  color: var(--sosafe-ai-chat-muted);
  background: #fff;
  border: 1px solid rgba(18, 32, 51, 0.1);
  border-radius: 999px;
  padding: 0.25rem 0.75rem;
  cursor: pointer;
  transition: all 0.25s ease;
  line-height: 1.3;
}

.sosafe-ai-chat__pill:hover:not(:disabled) {
  color: var(--sosafe-ai-chat-text);
  background: #fff;
  border-color: var(--sosafe-ai-chat-border);
  transform: translateY(-1px);
}

.sosafe-ai-chat__pill:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

@media (max-width: 640px) {
  .sosafe-ai-chat {
    padding: 0.85rem;
  }

  .sosafe-ai-chat__messages {
    min-height: 320px;
  }

  .sosafe-ai-chat__form {
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 0.5rem;
  }

  .sosafe-ai-chat__search-icon {
    width: auto;
    height: auto;
    background: transparent;
    border-radius: 0;
  }

  .sosafe-ai-chat__search-icon svg {
    width: 1rem;
    height: 1rem;
  }

  .sosafe-ai-chat__button {
    width: 2.5rem;
    min-width: 2.5rem;
    height: 2.5rem;
    min-height: 2.5rem;
  }

  .sosafe-ai-chat--active .sosafe-ai-chat__button {
    width: 2.5rem;
    min-width: 2.5rem;
    height: 2.5rem;
    min-height: 2.5rem;
  }

  .sosafe-ai-chat__button svg {
    width: 1.15rem;
    height: 1.15rem;
  }

  .sosafe-ai-chat__input {
    min-height: 40px;
    padding: 0.75rem 0 0.35rem;
  }

  .sosafe-ai-chat--active .sosafe-ai-chat__input {
    min-height: 40px;
    padding: 0.75rem 0 0;
  }

  .sosafe-ai-chat__suggestions {
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-inline: 1.25rem;
    margin-inline: -1.25rem;
    -webkit-mask-image: linear-gradient(
      to right,
      transparent,
      #000 1.25rem,
      #000 calc(100% - 1.25rem),
      transparent
    );
    mask-image: linear-gradient(
      to right,
      transparent,
      #000 1.25rem,
      #000 calc(100% - 1.25rem),
      transparent
    );
  }

  .sosafe-ai-chat__suggestions::-webkit-scrollbar {
    display: none;
  }

  .sosafe-ai-chat__pill {
    flex-shrink: 0;
  }

  .sosafe-ai-chat__bubble {
    max-width: 100%;
  }
}