/* DesIDEA AI Chatbot widget — scoped styles only (safe for ASP.NET site-wide include) */

#desidea-chatbot-root {
  --cb-green: #6f9d2e;
  --cb-green-dark: #557821;
  --cb-ink: #1c2430;
  --cb-muted: #5b6573;
  --cb-line: #d7dde6;
  --cb-surface: #ffffff;
  --cb-user: #e8f2d9;
  --cb-assistant: #f5f7fa;
  --cb-shadow: 0 16px 36px rgba(28, 36, 48, 0.2);
  --cb-z: 2147483000;
  --cb-right: max(16px, env(safe-area-inset-right, 0px));
  --cb-bottom: max(16px, env(safe-area-inset-bottom, 0px));
  --cb-launcher-size: 56px;
  --cb-gap: 12px;
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  color: var(--cb-ink);
  position: relative;
  z-index: var(--cb-z);
  line-height: 1.45;
}

#desidea-chatbot-root *,
#desidea-chatbot-root *::before,
#desidea-chatbot-root *::after {
  box-sizing: border-box;
}

#desidea-chatbot-root button,
#desidea-chatbot-root textarea {
  font: inherit;
}

/*
  Vertical stack:
  Chat launcher ABOVE, Back-to-Top at the very bottom-right.
*/
body.desidea-chatbot-present #back-to-top,
body:has(#desidea-chatbot-root) #back-to-top {
  right: max(16px, env(safe-area-inset-right, 0px)) !important;
  bottom: max(16px, env(safe-area-inset-bottom, 0px)) !important;
  width: 48px !important;
  height: 48px !important;
  line-height: 48px !important;
  font-size: 16px !important;
  padding: 0 !important;
  z-index: 9998 !important;
}

body.desidea-chat-open #back-to-top {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

.desidea-cb-launcher {
  position: fixed !important;
  right: var(--cb-right) !important;
  /* Sit above the back-to-top arrow */
  bottom: calc(var(--cb-bottom) + 48px + var(--cb-gap)) !important;
  width: var(--cb-launcher-size);
  height: var(--cb-launcher-size);
  border: 0;
  border-radius: 50%;
  background:
    radial-gradient(circle at 30% 28%, rgba(255, 255, 255, 0.28), transparent 42%),
    linear-gradient(155deg, #8fc63d 0%, #6f9d2e 48%, #4f7220 100%);
  color: #fff;
  box-shadow:
    0 10px 24px rgba(79, 114, 32, 0.38),
    0 2px 6px rgba(28, 36, 48, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.28);
  cursor: pointer;
  display: grid;
  place-items: center;
  z-index: var(--cb-z) !important;
  transition: transform 0.22s ease, box-shadow 0.22s ease, filter 0.22s ease;
  -webkit-tap-highlight-color: transparent;
  overflow: visible;
}

.desidea-cb-launcher__pulse {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid rgba(143, 198, 61, 0.55);
  animation: desidea-cb-pulse 2.4s ease-out infinite;
  pointer-events: none;
}

.desidea-cb-launcher__icon {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
}

.desidea-cb-launcher__icon svg {
  width: 28px;
  height: 28px;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.18));
}

.desidea-cb-launcher__badge {
  position: absolute;
  top: -6px;
  left: -8px;
  z-index: 2;
  padding: 3px 8px;
  border-radius: 999px;
  background: #1c2430;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  line-height: 1.2;
  box-shadow: 0 4px 10px rgba(28, 36, 48, 0.25);
  white-space: nowrap;
}

.desidea-cb-launcher:hover {
  transform: translateY(-3px) scale(1.04);
  box-shadow:
    0 14px 28px rgba(79, 114, 32, 0.42),
    0 4px 10px rgba(28, 36, 48, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.32);
  filter: saturate(1.05);
}

.desidea-cb-launcher:active {
  transform: translateY(-1px) scale(0.98);
}

.desidea-cb-launcher:focus-visible,
.desidea-cb-close:focus-visible,
.desidea-cb-send:focus-visible,
.desidea-cb-chip:focus-visible,
.desidea-cb-contact:focus-visible {
  outline: 3px solid #2f6fed;
  outline-offset: 2px;
}

@keyframes desidea-cb-pulse {
  0% {
    transform: scale(1);
    opacity: 0.7;
  }
  70% {
    transform: scale(1.18);
    opacity: 0;
  }
  100% {
    transform: scale(1.18);
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .desidea-cb-launcher__pulse {
    animation: none;
    opacity: 0;
  }

  .desidea-cb-launcher,
  .desidea-cb-panel.is-open {
    transition: none;
    animation: none;
  }
}

.desidea-cb-panel {
  position: fixed !important;
  right: var(--cb-right) !important;
  bottom: calc(var(--cb-bottom) + 48px + var(--cb-gap) + var(--cb-launcher-size) + var(--cb-gap)) !important;
  width: min(380px, calc(100vw - 32px));
  height: min(560px, calc(100vh - 160px));
  max-height: calc(100dvh - 160px);
  display: none;
  flex-direction: column;
  background: var(--cb-surface);
  border: 1px solid var(--cb-line);
  border-radius: 18px;
  box-shadow: var(--cb-shadow);
  overflow: hidden;
  z-index: var(--cb-z) !important;
}

body.desidea-chat-open .desidea-cb-panel.is-open {
  bottom: var(--cb-bottom) !important;
  height: min(600px, calc(100dvh - 32px));
  max-height: calc(100dvh - 32px);
}

body.desidea-chat-open .desidea-cb-launcher {
  /* While open, move launcher out of the way at bottom corner under panel */
  bottom: var(--cb-bottom) !important;
  visibility: hidden;
  pointer-events: none;
}

.desidea-cb-panel.is-open {
  display: flex;
  animation: desidea-cb-rise 0.22s ease;
}

@keyframes desidea-cb-rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.desidea-cb-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 14px 12px;
  background: linear-gradient(135deg, #6f9d2e, #4f7220);
  color: #fff;
  flex-shrink: 0;
}

.desidea-cb-header-text h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.desidea-cb-header-text p {
  margin: 2px 0 0;
  font-size: 0.85rem;
  opacity: 0.92;
}

.desidea-cb-online {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  font-size: 0.75rem;
}

.desidea-cb-online::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #b8f06a;
  box-shadow: 0 0 0 3px rgba(184, 240, 106, 0.25);
}

.desidea-cb-close {
  border: 0;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  cursor: pointer;
  flex-shrink: 0;
}

.desidea-cb-messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px;
  background:
    linear-gradient(180deg, rgba(111, 157, 46, 0.05), transparent 120px),
    #fbfcfb;
  min-height: 0;
}

.desidea-cb-msg {
  display: flex;
  margin-bottom: 10px;
}

.desidea-cb-msg--user {
  justify-content: flex-end;
}

.desidea-cb-bubble {
  max-width: 85%;
  padding: 10px 12px;
  border-radius: 14px;
  font-size: 0.92rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.desidea-cb-msg--assistant .desidea-cb-bubble {
  background: var(--cb-assistant);
  border: 1px solid var(--cb-line);
  border-bottom-left-radius: 4px;
}

.desidea-cb-msg--user .desidea-cb-bubble {
  background: var(--cb-user);
  border: 1px solid #d5e7b8;
  border-bottom-right-radius: 4px;
}

.desidea-cb-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 4px 0 12px;
}

.desidea-cb-chip {
  border: 1px solid #c9dbad;
  background: #fff;
  color: var(--cb-green-dark);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 0.8rem;
  cursor: pointer;
  min-height: 36px;
}

.desidea-cb-chip:hover:not(:disabled) {
  background: #f3f9ea;
}

.desidea-cb-chip:disabled,
.desidea-cb-send:disabled,
.desidea-cb-contact:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.desidea-cb-typing {
  display: none;
  margin: 0 0 8px;
  padding: 0 14px;
  color: var(--cb-muted);
  font-size: 0.85rem;
  flex-shrink: 0;
}

.desidea-cb-typing.is-visible {
  display: block;
}

.desidea-cb-actions {
  display: flex;
  gap: 8px;
  padding: 0 14px 10px;
  background: #fbfcfb;
  flex-shrink: 0;
}

.desidea-cb-contact {
  flex: 1;
  border: 1px solid var(--cb-green);
  background: var(--cb-green);
  color: #fff;
  border-radius: 10px;
  padding: 12px;
  font-size: 0.85rem;
  cursor: pointer;
  min-height: 44px;
}

.desidea-cb-contact:hover:not(:disabled) {
  background: var(--cb-green-dark);
}

.desidea-cb-composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 12px 14px calc(14px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--cb-line);
  background: #fff;
  flex-shrink: 0;
}

.desidea-cb-composer textarea {
  width: 100%;
  min-height: 44px;
  max-height: 110px;
  resize: none;
  border: 1px solid var(--cb-line);
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--cb-ink);
  background: #fff;
  font-size: 16px; /* prevents iOS zoom on focus */
}

.desidea-cb-composer textarea:focus {
  outline: 2px solid rgba(111, 157, 46, 0.35);
  border-color: var(--cb-green);
}

.desidea-cb-send {
  border: 0;
  border-radius: 12px;
  min-width: 72px;
  min-height: 44px;
  background: var(--cb-green);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.desidea-cb-send:hover:not(:disabled) {
  background: var(--cb-green-dark);
}

.desidea-cb-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;
}

@media (max-width: 900px) {
  #desidea-chatbot-root {
    --cb-launcher-size: 54px;
  }

  .desidea-cb-panel {
    width: min(360px, calc(100vw - 28px));
  }

  body.desidea-chatbot-present #back-to-top,
  body:has(#desidea-chatbot-root) #back-to-top {
    width: 46px !important;
    height: 46px !important;
    line-height: 46px !important;
  }

  .desidea-cb-launcher {
    bottom: calc(var(--cb-bottom) + 46px + var(--cb-gap)) !important;
  }
}

@media (max-width: 640px) {
  #desidea-chatbot-root {
    --cb-right: max(12px, env(safe-area-inset-right, 0px));
    --cb-bottom: max(12px, env(safe-area-inset-bottom, 0px));
    --cb-launcher-size: 54px;
    --cb-gap: 10px;
  }

  body.desidea-chatbot-present #back-to-top,
  body:has(#desidea-chatbot-root) #back-to-top {
    width: 44px !important;
    height: 44px !important;
    line-height: 44px !important;
    font-size: 15px !important;
    bottom: max(12px, env(safe-area-inset-bottom, 0px)) !important;
  }

  .desidea-cb-launcher {
    bottom: calc(var(--cb-bottom) + 44px + var(--cb-gap)) !important;
  }

  .desidea-cb-launcher__badge {
    font-size: 9px;
    padding: 2px 7px;
    top: -5px;
    left: -6px;
  }

  .desidea-cb-launcher__icon svg {
    width: 27px;
    height: 27px;
  }

  .desidea-cb-panel,
  body.desidea-chat-open .desidea-cb-panel.is-open {
    top: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    max-height: 100dvh !important;
    border-radius: 0;
    border: 0;
  }

  .desidea-cb-header {
    padding-top: calc(12px + env(safe-area-inset-top, 0px));
  }
}

@media (max-width: 380px) {
  #desidea-chatbot-root {
    --cb-launcher-size: 48px;
  }

  body.desidea-chatbot-present #back-to-top,
  body:has(#desidea-chatbot-root) #back-to-top {
    width: 42px !important;
    height: 42px !important;
    line-height: 42px !important;
    bottom: max(12px, env(safe-area-inset-bottom, 0px)) !important;
  }

  .desidea-cb-launcher {
    bottom: calc(var(--cb-bottom) + 42px + var(--cb-gap)) !important;
  }

  .desidea-cb-send {
    min-width: 64px;
  }
}
