/* ============================================================
   Chat assistant widget
   Loaded only when an API key is configured.
   ============================================================ */

.sdcmt-chat {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 9000;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

/* ---------- launcher ---------- */

.sdcmt-chat__launcher {
  position: relative;
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  background: linear-gradient(140deg, var(--indigo, #3433c9) 0%, var(--indigo-darker, #15134f) 100%);
  color: #fff;
  box-shadow: 0 14px 34px rgba(21, 19, 79, 0.34);
  transition: transform 0.28s cubic-bezier(.16, 1, .3, 1), box-shadow 0.28s ease;
}

.sdcmt-chat__launcher:hover {
  transform: translateY(-3px) scale(1.04);
  box-shadow: 0 20px 42px rgba(21, 19, 79, 0.42);
}

.sdcmt-chat__launcher:focus-visible {
  outline: 3px solid var(--orange, #f97316);
  outline-offset: 3px;
}

.sdcmt-chat__launcher svg {
  width: 25px;
  height: 25px;
}

.sdcmt-chat__launcher-icon,
.sdcmt-chat__launcher-close {
  grid-area: 1 / 1;
  display: grid;
  place-items: center;
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.sdcmt-chat__launcher-close {
  opacity: 0;
  transform: rotate(-90deg) scale(0.6);
}

.sdcmt-chat[data-open='true'] .sdcmt-chat__launcher-icon {
  opacity: 0;
  transform: rotate(90deg) scale(0.6);
}

.sdcmt-chat[data-open='true'] .sdcmt-chat__launcher-close {
  opacity: 1;
  transform: none;
}

/* A quiet pulse to draw the eye once, without the widget becoming a nuisance. */
.sdcmt-chat__launcher::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--indigo, #3433c9);
  animation: sdcmt-chat-pulse 2.6s ease-out 3;
  pointer-events: none;
}

.sdcmt-chat[data-open='true'] .sdcmt-chat__launcher::after {
  display: none;
}

@keyframes sdcmt-chat-pulse {
  0% { opacity: 0.55; transform: scale(1); }
  70% { opacity: 0; transform: scale(1.55); }
  100% { opacity: 0; transform: scale(1.55); }
}

/* ---------- panel ---------- */

.sdcmt-chat__panel {
  position: absolute;
  right: 0;
  bottom: 74px;
  display: flex;
  flex-direction: column;
  width: min(384px, calc(100vw - 44px));
  height: min(560px, calc(100vh - 130px));
  background: #fff;
  border: 1px solid var(--line, #e6e9ef);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 30px 70px rgba(15, 23, 42, 0.22);
  transform-origin: bottom right;
  animation: sdcmt-chat-in 0.3s cubic-bezier(.16, 1, .3, 1);
}

.sdcmt-chat__panel[hidden] {
  display: none;
}

@keyframes sdcmt-chat-in {
  from { opacity: 0; transform: translateY(14px) scale(0.96); }
  to { opacity: 1; transform: none; }
}

.sdcmt-chat__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 16px;
  background: linear-gradient(140deg, var(--indigo, #3433c9) 0%, var(--indigo-darker, #15134f) 100%);
  color: #fff;
  flex: none;
}

.sdcmt-chat__header-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.sdcmt-chat__header-text strong {
  font-family: 'Plus Jakarta Sans', 'Inter', sans-serif;
  font-size: 15px;
  font-weight: 800;
  line-height: 1.2;
}

.sdcmt-chat__header-text span {
  font-size: 11.5px;
  color: rgba(255, 255, 255, 0.72);
}

.sdcmt-chat__close {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex: none;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  cursor: pointer;
  transition: background 0.2s ease;
}

.sdcmt-chat__close:hover {
  background: rgba(255, 255, 255, 0.26);
}

.sdcmt-chat__close svg {
  width: 15px;
  height: 15px;
}

/* ---------- message log ---------- */

.sdcmt-chat__log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 16px 6px;
  display: flex;
  flex-direction: column;
  gap: 11px;
  background: var(--soft, #f7f8fb);
}

.sdcmt-chat__msg {
  display: flex;
  max-width: 88%;
}

.sdcmt-chat__msg--user {
  align-self: flex-end;
  justify-content: flex-end;
}

.sdcmt-chat__msg--assistant {
  align-self: flex-start;
}

.sdcmt-chat__bubble {
  padding: 11px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
}

.sdcmt-chat__msg--assistant .sdcmt-chat__bubble {
  background: #fff;
  border: 1px solid var(--line, #e6e9ef);
  border-bottom-left-radius: 5px;
  color: var(--ink, #0f172a);
}

.sdcmt-chat__msg--user .sdcmt-chat__bubble {
  background: var(--indigo, #3433c9);
  border-bottom-right-radius: 5px;
  color: #fff;
}

.sdcmt-chat__bubble a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.sdcmt-chat__msg--assistant .sdcmt-chat__bubble a {
  color: var(--indigo, #3433c9);
  font-weight: 600;
}

.sdcmt-chat__error {
  align-self: center;
  max-width: 92%;
  padding: 9px 13px;
  border-radius: 12px;
  background: #fff2f2;
  border: 1px solid #f7cccc;
  color: #a01a20;
  font-size: 12.5px;
  line-height: 1.55;
  text-align: center;
}

.sdcmt-chat__error a {
  color: #a01a20;
  font-weight: 700;
}

/* ---------- typing indicator ---------- */

.sdcmt-chat__dots {
  display: inline-flex;
  gap: 4px;
  padding: 2px 0;
}

.sdcmt-chat__dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted, #5b6577);
  opacity: 0.4;
  animation: sdcmt-chat-blink 1.3s infinite ease-in-out;
}

.sdcmt-chat__dots i:nth-child(2) { animation-delay: 0.18s; }
.sdcmt-chat__dots i:nth-child(3) { animation-delay: 0.36s; }

@keyframes sdcmt-chat-blink {
  0%, 60%, 100% { opacity: 0.28; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* ---------- starters ---------- */

.sdcmt-chat__starters {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 10px 16px 4px;
  background: var(--soft, #f7f8fb);
  flex: none;
}

.sdcmt-chat__starters[hidden] {
  display: none;
}

.sdcmt-chat__starter {
  padding: 7px 12px;
  border: 1px solid var(--line, #e6e9ef);
  border-radius: 99px;
  background: #fff;
  color: var(--indigo, #3433c9);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.3;
  cursor: pointer;
  transition: border-color 0.2s ease, transform 0.2s ease;
}

.sdcmt-chat__starter:hover {
  border-color: var(--indigo, #3433c9);
  transform: translateY(-1px);
}

/* ---------- composer ---------- */

.sdcmt-chat__form {
  display: flex;
  align-items: flex-end;
  gap: 9px;
  padding: 12px 14px 8px;
  background: #fff;
  border-top: 1px solid var(--line, #e6e9ef);
  flex: none;
}

.sdcmt-chat__form textarea {
  flex: 1;
  min-width: 0;
  height: 40px;
  max-height: 120px;
  padding: 10px 14px;
  border: 1px solid var(--line, #e6e9ef);
  border-radius: 18px;
  background: var(--soft, #f7f8fb);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink, #0f172a);
  resize: none;
  overflow-y: auto;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.sdcmt-chat__form textarea:focus {
  outline: none;
  border-color: var(--indigo, #3433c9);
  background: #fff;
}

.sdcmt-chat__form textarea:disabled {
  opacity: 0.6;
}

.sdcmt-chat__form button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  border: none;
  border-radius: 50%;
  background: var(--indigo, #3433c9);
  color: #fff;
  cursor: pointer;
  transition: background 0.2s ease, opacity 0.2s ease;
}

.sdcmt-chat__form button:hover:not(:disabled) {
  background: var(--indigo-deep, #211f8a);
}

.sdcmt-chat__form button:disabled {
  opacity: 0.45;
  cursor: default;
}

.sdcmt-chat__form button svg {
  width: 17px;
  height: 17px;
  margin-right: 1px;
}

.sdcmt-chat__disclaimer {
  padding: 0 16px 11px;
  background: #fff;
  font-size: 10.5px;
  line-height: 1.45;
  color: var(--muted, #5b6577);
  text-align: center;
  flex: none;
}

/* ---------- mobile ---------- */

@media (max-width: 620px) {
  .sdcmt-chat {
    right: 16px;
    bottom: 16px;
  }

  .sdcmt-chat__launcher {
    width: 52px;
    height: 52px;
  }

  /* Near full screen on a phone. A 380px floating card on a small display
     leaves the message log too short to hold a conversation. */
  .sdcmt-chat__panel {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    height: 100dvh;
    border: none;
    border-radius: 0;
    animation: sdcmt-chat-in-mobile 0.26s ease-out;
  }

  @keyframes sdcmt-chat-in-mobile {
    from { opacity: 0; transform: translateY(18px); }
    to { opacity: 1; transform: none; }
  }

  .sdcmt-chat__header {
    padding: 14px 16px;
    padding-top: max(14px, env(safe-area-inset-top));
  }

  .sdcmt-chat__disclaimer {
    padding-bottom: max(11px, env(safe-area-inset-bottom));
  }

  /* The launcher would otherwise sit on top of the open full-screen panel. */
  .sdcmt-chat[data-open='true'] .sdcmt-chat__launcher {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sdcmt-chat__panel,
  .sdcmt-chat__launcher::after,
  .sdcmt-chat__dots i {
    animation: none;
  }

  .sdcmt-chat__launcher:hover {
    transform: none;
  }
}
