.ai-chat-root {
  --ai-chat-footer-offset: 0px;
  position: fixed;
  right: 20px;
  bottom: calc(20px + var(--ai-chat-footer-offset));
  z-index: 5000;
  display: block;
  transition: bottom 0.12s linear;
}

.ai-chat-root.is-open:not(.ai-chat-root--expanded) {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}

.ai-chat-root.ai-chat-root--expanded {
  inset: 0;
  right: auto;
  bottom: auto;
  width: 100%;
  height: 100%;
  display: block;
}

.ai-chat-backdrop {
  position: fixed;
  inset: 0;
  z-index: 5001;
  display: none;
  background: rgba(16, 24, 40, 0.52);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.ai-chat-backdrop.is-visible {
  display: block;
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.ai-chat-root.ai-chat-root--expanded .ai-chat-panel {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 5002;
}

body.ai-chat-modal-open {
  overflow: hidden;
}

.ai-chat-toggle {
  border: 0;
  border-radius: 999px;
  padding: 14px 18px;
  background: linear-gradient(135deg, var(--blue), var(--blue-dark));
  color: var(--white);
  font: 600 14px/1 Inter, Arial, sans-serif;
  box-shadow: var(--shadow);
  cursor: pointer;
}

.ai-chat-panel {
  width: min(420px, calc(100vw - 24px));
  max-height: max(320px, min(560px, calc(100vh - 120px - var(--ai-chat-footer-offset))));
  display: none;
  grid-template-rows: auto minmax(200px, 1fr) auto auto auto;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: width 0.2s ease, max-height 0.2s ease;
}

.ai-chat-panel.is-open {
  display: grid;
}

.ai-chat-panel--expanded {
  width: min(760px, calc(100vw - 32px));
  height: min(86vh, 860px);
  max-height: min(86vh, 860px);
  grid-template-rows: auto minmax(0, 1fr) auto auto auto;
  box-shadow: 0 24px 64px rgba(0, 55, 130, 0.22);
}

.ai-chat-toggle.is-hidden {
  display: none;
}

.ai-chat-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 10px 8px;
  padding: 14px 14px 12px;
  background: var(--blue-soft);
  border-bottom: 1px solid var(--line-light);
}

.ai-chat-header > div:first-child {
  min-width: 0;
}

.ai-chat-header-actions {
  display: flex;
  flex-wrap: nowrap;
  flex-shrink: 0;
  align-items: center;
  gap: 4px;
  justify-content: flex-end;
}

.ai-chat-icon-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 7px;
  background: var(--white);
  color: var(--ink);
  font: 600 11px/1.15 Inter, Arial, sans-serif;
  white-space: nowrap;
  cursor: pointer;
}

.ai-chat-icon-button--close {
  min-width: 28px;
  font-size: 17px;
  line-height: 1;
  padding: 4px 6px;
}

.ai-chat-header strong {
  display: block;
  font-size: 16px;
}

.ai-chat-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

@media (max-width: 400px) {
  .ai-chat-header {
    grid-template-columns: 1fr;
  }

  .ai-chat-header-actions {
    width: 100%;
  }
}

.ai-chat-close {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.ai-chat-messages {
  padding: 14px 16px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 200px;
  min-width: 0;
  background: var(--soft);
}

.ai-chat-panel.is-open .ai-chat-messages {
  min-height: 0;
}

.ai-chat-empty {
  color: var(--muted);
  font-size: 14px;
}

.ai-chat-message {
  max-width: 92%;
  padding: 10px 12px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.45;
  word-break: break-word;
}

.ai-chat-message--user {
  align-self: flex-end;
  background: var(--blue);
  color: var(--white);
}

.ai-chat-message--assistant {
  align-self: flex-start;
  background: var(--white);
  border: 1px solid var(--line-light);
}

.ai-chat-message--assistant strong {
  font-weight: 700;
}

.ai-chat-message--assistant em {
  font-style: italic;
}

.ai-chat-p + .ai-chat-p,
.ai-chat-p + ol,
.ai-chat-p + ul,
ol + .ai-chat-p,
ul + .ai-chat-p,
.ai-chat-table-wrap + .ai-chat-p {
  margin-top: 8px;
}

.ai-chat-heading {
  margin: 10px 0 4px;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.3;
}

.ai-chat-heading:first-child {
  margin-top: 0;
}

.ai-chat-message ol,
.ai-chat-message ul {
  margin: 6px 0 0;
  padding-left: 20px;
  display: grid;
  gap: 8px;
}

.ai-chat-message li {
  padding-left: 2px;
}

.ai-chat-message code {
  padding: 1px 4px;
  border-radius: 4px;
  background: var(--soft, #f2f4f7);
  font-size: 12px;
}

.ai-chat-table-wrap {
  max-width: 100%;
  margin: 8px 0;
  overflow-x: auto;
}

.ai-chat-table {
  width: 100%;
  min-width: 320px;
  margin: 0;
  border-collapse: collapse;
  font-size: 12px;
  line-height: 1.35;
}

.ai-chat-table th,
.ai-chat-table td {
  border: 1px solid var(--line-light);
  padding: 6px 8px;
  text-align: left;
  vertical-align: top;
}

.ai-chat-table th {
  background: var(--blue-soft);
  font-weight: 600;
}

.ai-chat-message--typing {
  display: inline-flex;
  align-self: flex-start;
  align-items: center;
  gap: 8px;
  max-width: 92%;
  padding: 10px 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  background: var(--white);
  border: 1px solid var(--line-light);
  border-radius: 14px;
}

.ai-chat-typing-dots {
  flex: 0 0 auto;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 12px 0 0 var(--muted), 24px 0 0 var(--muted);
  animation: ai-chat-typing 1s infinite ease-in-out;
}

@keyframes ai-chat-typing {
  0%,
  80%,
  100% {
    opacity: 0.35;
  }

  40% {
    opacity: 1;
  }
}

.ai-chat-message a {
  color: inherit;
  text-decoration: underline;
}

.ai-chat-error {
  margin: 0;
  padding: 0 16px 8px;
  color: #b42318;
  font-size: 13px;
}

.ai-chat-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 0 16px 10px;
  color: var(--muted);
  font-size: 13px;
}

.ai-chat-whatsapp-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 999px;
  padding: 10px 14px;
  background: #128c7e;
  color: var(--white) !important;
  font: 600 13px/1 Inter, Arial, sans-serif;
  text-decoration: none !important;
  cursor: pointer;
}

.ai-chat-message .ai-chat-whatsapp-button {
  margin-top: 8px;
}

.ai-chat-product-link {
  font-weight: 600;
}

.ai-chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 12px 16px 16px;
  border-top: 1px solid var(--line-light);
  background: var(--white);
}

.ai-chat-form textarea {
  resize: vertical;
  min-height: 44px;
  max-height: 120px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font: inherit;
}

.ai-chat-form button {
  align-self: end;
  border: 0;
  border-radius: 12px;
  padding: 12px 16px;
  background: var(--blue);
  color: var(--white);
  font: 600 14px/1 Inter, Arial, sans-serif;
  cursor: pointer;
}

.ai-chat-form button:disabled {
  opacity: 0.65;
  cursor: wait;
}

.ai-chat-product-cards {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.ai-chat-product-card {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--white);
}

.ai-chat-product-card__image {
  width: 72px;
  height: 72px;
  object-fit: contain;
  border-radius: 8px;
  background: #f6f8fb;
}

.ai-chat-product-card__image--placeholder {
  background: #eef2f7;
}

.ai-chat-product-card__media {
  display: block;
  line-height: 0;
  text-decoration: none !important;
}

.ai-chat-product-card--inline {
  margin-top: 8px;
  grid-template-columns: 64px minmax(0, 1fr);
  background: var(--soft, #f9fafb);
}

.ai-chat-product-card--inline .ai-chat-product-card__image {
  width: 64px;
  height: 64px;
}

.ai-chat-product-card__body {
  min-width: 0;
}

.ai-chat-product-card__body strong {
  display: block;
  font-size: 13px;
  line-height: 1.35;
}

.ai-chat-product-card__price,
.ai-chat-product-card__stock {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--muted, #667085);
}

.ai-chat-product-card__price {
  color: var(--text, #101828);
  font-weight: 600;
}

@media (max-width: 640px) {
  .ai-chat-root {
    right: 12px;
    bottom: calc(12px + var(--ai-chat-footer-offset));
  }

  .ai-chat-root.is-open:not(.ai-chat-root--expanded) {
    left: 8px;
    right: 8px;
    bottom: calc(8px + var(--ai-chat-footer-offset));
    align-items: stretch;
  }

  .ai-chat-panel {
    width: 100%;
    max-height: max(320px, calc(100dvh - 16px - var(--ai-chat-footer-offset)));
    border-radius: 16px;
  }

  .ai-chat-root.ai-chat-root--expanded .ai-chat-panel {
    left: 0;
    top: 0;
    transform: none;
  }

  .ai-chat-panel--expanded {
    width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border: 0;
    border-radius: 0;
  }

  .ai-chat-header {
    padding: 12px;
  }

  .ai-chat-header p {
    font-size: 11px;
  }

  .ai-chat-messages {
    padding: 12px;
  }

  .ai-chat-message {
    max-width: 100%;
    font-size: 14px;
  }

  .ai-chat-message--user {
    max-width: 88%;
  }

  .ai-chat-footer {
    padding: 0 12px 8px;
    font-size: 12px;
  }

  .ai-chat-form {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    padding: 10px 12px 12px;
  }

  .ai-chat-form textarea {
    font-size: 16px;
  }

  .ai-chat-form button {
    padding: 12px 14px;
  }

  .ai-chat-product-card {
    grid-template-columns: 56px minmax(0, 1fr);
    gap: 8px;
    padding: 8px;
  }

  .ai-chat-product-card__image,
  .ai-chat-product-card--inline .ai-chat-product-card__image {
    width: 56px;
    height: 56px;
  }
}
