/*
 * Systemake chat UI v2
 * Corporate laser-blue chat with readable formatting and a larger viewport.
 * Load after app.css.
 */

:root {
  --sm-laser-blue: #00d9ff;
  --sm-electric-blue: #1788ff;
  --sm-chat-text: #edf6ff;
  --sm-chat-muted: #9aa8c2;
  --sm-assistant-bg: rgba(10, 17, 31, 0.98);
  --sm-assistant-bg-end: rgba(7, 12, 23, 0.99);
  --sm-assistant-border: rgba(73, 145, 255, 0.34);
  --sm-user-bg: #eaf5ff;
  --sm-user-bg-end: #dcecff;
  --sm-user-text: #071522;
  --sm-error: #ff6b81;
  --sm-error-bg: rgba(79, 20, 32, 0.58);
  --sm-error-border: rgba(255, 107, 129, 0.5);
}

/* The original viewport was too short and clipped the visitor message. */
#conversation {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  box-sizing: border-box;
  width: 100%;
  height: clamp(20rem, 48vh, 32rem);
  min-height: 20rem;
  max-height: 32rem;
  padding: 0.45rem 0.65rem 1rem;
  overflow-x: hidden;
  overflow-y: auto;
  scroll-behavior: auto;
  scroll-padding-block: 1rem;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: rgba(132, 156, 202, 0.55) transparent;
}

#conversation::-webkit-scrollbar {
  width: 0.45rem;
}

#conversation::-webkit-scrollbar-track {
  background: transparent;
}

#conversation::-webkit-scrollbar-thumb {
  background: rgba(132, 156, 202, 0.48);
  border-radius: 999px;
}

/* Shared bubble */
.message {
  position: relative;
  flex: 0 0 auto;
  align-self: flex-start;
  box-sizing: border-box;
  width: fit-content;
  max-width: min(86%, 46rem);
  margin: 0;
  padding: 0.92rem 1.05rem;
  border: 1px solid transparent;
  font-size: clamp(0.98rem, 0.35vw + 0.9rem, 1.06rem);
  font-weight: 400;
  line-height: 1.55;
  letter-spacing: 0.002em;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: normal;
  text-wrap: pretty;
  opacity: 0;
  transform: translateY(0.35rem);
  animation: sm-message-enter 170ms ease-out forwards;
}

/* Assistant */
.message--assistant {
  color: var(--sm-chat-text);
  background:
    linear-gradient(
      145deg,
      var(--sm-assistant-bg),
      var(--sm-assistant-bg-end)
    );
  border-color: var(--sm-assistant-border);
  border-left: 3px solid var(--sm-laser-blue);
  border-radius: 0.5rem 1.15rem 1.15rem 1.15rem;
  box-shadow:
    0 0.7rem 1.8rem rgba(0, 0, 0, 0.23),
    0 0 1rem rgba(0, 217, 255, 0.045),
    inset 0 1px 0 rgba(255, 255, 255, 0.025);
}

/* Visitor */
.message--user {
  align-self: flex-end;
  max-width: min(78%, 42rem);
  color: var(--sm-user-text);
  background:
    linear-gradient(
      135deg,
      var(--sm-user-bg),
      var(--sm-user-bg-end)
    );
  border-color: rgba(0, 191, 255, 0.34);
  border-radius: 1.15rem 0.5rem 1.15rem 1.15rem;
  box-shadow:
    0 0.6rem 1.5rem rgba(0, 0, 0, 0.15),
    0 0 0.9rem rgba(0, 217, 255, 0.055);
}

/* Safe formatted content produced by app.js */
.message--formatted {
  white-space: normal;
}

.message__paragraph {
  margin: 0 0 0.68rem;
}

.message__paragraph:last-child,
.message__list:last-child {
  margin-bottom: 0;
}

.message__paragraph--emphasis {
  color: #ffffff;
  font-weight: 650;
}

.message__list {
  margin: 0.25rem 0 0.75rem;
  padding-left: 1.25rem;
}

.message__list-item {
  margin: 0.28rem 0;
  padding-left: 0.12rem;
}

.message--assistant strong {
  color: #ffffff;
  font-weight: 650;
}

.message--assistant code {
  padding: 0.08rem 0.28rem;
  color: #bfeeff;
  background: rgba(0, 217, 255, 0.09);
  border: 1px solid rgba(0, 217, 255, 0.16);
  border-radius: 0.3rem;
  font: 0.92em/1.35 ui-monospace, SFMono-Regular, Consolas, monospace;
}

/* Streaming caret */
.message--assistant.message--streaming::after {
  display: inline-block;
  width: 0.42rem;
  height: 1em;
  margin-left: 0.24rem;
  vertical-align: -0.15em;
  content: "";
  background: var(--sm-laser-blue);
  border-radius: 0.12rem;
  box-shadow: 0 0 0.55rem rgba(0, 217, 255, 0.72);
  animation: sm-stream-caret 850ms steps(1, end) infinite;
}

/* Errors */
.message--assistant.message--error {
  color: #ffe8ed;
  background: var(--sm-error-bg);
  border-color: var(--sm-error-border);
  border-left-color: var(--sm-error);
}

/* Typing indicator */
#typing {
  flex: 0 0 auto;
  align-self: flex-start;
  box-sizing: border-box;
  width: fit-content;
  min-width: 4rem;
  min-height: 2.6rem;
  margin: 0;
  padding: 0.65rem 0.9rem;
  color: var(--sm-chat-muted);
  background:
    linear-gradient(
      145deg,
      var(--sm-assistant-bg),
      var(--sm-assistant-bg-end)
    );
  border: 1px solid var(--sm-assistant-border);
  border-left: 3px solid var(--sm-laser-blue);
  border-radius: 0.5rem 1.05rem 1.05rem 1.05rem;
  box-shadow: 0 0.65rem 1.6rem rgba(0, 0, 0, 0.19);
}

#typing[hidden] {
  display: none !important;
}

#typing span,
#typing i,
#typing b {
  background-color: currentColor;
}

/* The composer was visually dominating the chat. */
#chat-form {
  box-sizing: border-box;
  margin-top: 0.75rem;
}

#message {
  box-sizing: border-box;
  width: 100%;
  min-height: 4.8rem !important;
  max-height: 8rem;
  line-height: 1.5;
  resize: vertical;
}

.message::selection {
  color: #031019;
  background: rgba(0, 217, 255, 0.82);
}

@keyframes sm-message-enter {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes sm-stream-caret {
  0%,
  45% {
    opacity: 1;
  }

  46%,
  100% {
    opacity: 0.18;
  }
}

/* Short desktop windows: preserve more room for the conversation. */
@media (min-width: 641px) and (max-height: 720px) {
  #conversation {
    height: 18rem;
    min-height: 18rem;
  }

  #message {
    min-height: 4.25rem !important;
  }
}

/* Mobile */
@media (max-width: 640px) {
  #conversation {
    gap: 0.72rem;
    height: clamp(22rem, 54svh, 34rem);
    min-height: 22rem;
    padding: 0.4rem 0.25rem 0.9rem;
    scrollbar-gutter: auto;
  }

  .message {
    max-width: 92%;
    padding: 0.82rem 0.92rem;
    font-size: 1rem;
    line-height: 1.52;
  }

  .message--user {
    max-width: 90%;
  }

  #message {
    min-height: 4.5rem !important;
    max-height: 7rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .message {
    opacity: 1;
    transform: none;
    animation: none;
  }

  .message--assistant.message--streaming::after {
    animation: none;
    opacity: 0.8;
  }
}

/* Lead capture */
.lead-trigger {
  display: block;
  width: fit-content;
  margin: 0.85rem auto 0;
  padding: 0.68rem 1.05rem;
  color: #dff8ff;
  background: rgba(9, 18, 34, 0.9);
  border: 1px solid rgba(0, 217, 255, 0.38);
  border-radius: 999px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 0 1rem rgba(0, 217, 255, 0.06);
  transition: border-color 150ms ease, background 150ms ease, transform 150ms ease;
}

.lead-trigger:hover,
.lead-trigger:focus-visible {
  background: rgba(10, 31, 54, 0.98);
  border-color: rgba(0, 217, 255, 0.75);
  outline: none;
  transform: translateY(-1px);
}

.lead-card {
  position: relative;
  flex: 0 0 auto;
  align-self: stretch;
  box-sizing: border-box;
  width: min(100%, 44rem);
  margin: 0.15rem auto 0.35rem;
  padding: 1rem;
  color: var(--sm-chat-text);
  background: linear-gradient(145deg, rgba(10, 18, 34, 0.99), rgba(6, 12, 23, 0.99));
  border: 1px solid rgba(0, 217, 255, 0.32);
  border-radius: 1.15rem;
  box-shadow: 0 0.8rem 2rem rgba(0, 0, 0, 0.25), 0 0 1.2rem rgba(0, 217, 255, 0.05);
}

.lead-card__title {
  margin: 0 2rem 0.85rem 0;
  color: #fff;
  font-size: 1.05rem;
  line-height: 1.3;
}

.lead-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem;
}

.lead-field {
  display: grid;
  gap: 0.35rem;
  min-width: 0;
}

.lead-field:has(textarea),
.lead-consent,
.lead-form__error,
.lead-form__actions {
  grid-column: 1 / -1;
}

.lead-field__label {
  color: #b9c7df;
  font-size: 0.82rem;
  font-weight: 600;
}

.lead-field__control {
  box-sizing: border-box;
  width: 100%;
  min-height: 2.7rem;
  padding: 0.68rem 0.75rem;
  color: #eef8ff;
  background: rgba(4, 10, 21, 0.9);
  border: 1px solid rgba(120, 151, 205, 0.32);
  border-radius: 0.7rem;
  font: inherit;
  line-height: 1.35;
}

textarea.lead-field__control {
  min-height: 6.2rem;
  resize: vertical;
}

.lead-field__control:focus {
  border-color: var(--sm-laser-blue);
  outline: 2px solid rgba(0, 217, 255, 0.13);
  outline-offset: 1px;
}

.lead-consent {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.55rem;
  align-items: start;
  color: #bdc9dc;
  font-size: 0.82rem;
  line-height: 1.45;
}

.lead-consent input {
  width: 1rem;
  height: 1rem;
  margin-top: 0.15rem;
  accent-color: var(--sm-laser-blue);
}

.lead-form__actions {
  display: flex;
  justify-content: flex-end;
}

.lead-form__submit {
  min-height: 2.75rem;
  padding: 0.68rem 1rem;
  color: #021018;
  background: linear-gradient(135deg, #58e9ff, var(--sm-laser-blue));
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-weight: 750;
  cursor: pointer;
  box-shadow: 0 0 1rem rgba(0, 217, 255, 0.16);
}

.lead-form__submit:disabled {
  cursor: wait;
  opacity: 0.62;
}

.lead-form__cancel {
  position: absolute;
  top: 0.7rem;
  right: 0.75rem;
  width: 2rem;
  height: 2rem;
  padding: 0;
  color: #aebbd0;
  background: transparent;
  border: 1px solid rgba(130, 154, 198, 0.25);
  border-radius: 999px;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}

.lead-form__error {
  margin: 0;
  padding: 0.6rem 0.75rem;
  color: #ffe6ec;
  background: rgba(111, 26, 45, 0.42);
  border: 1px solid rgba(255, 107, 129, 0.38);
  border-radius: 0.65rem;
  font-size: 0.85rem;
}

.lead-honeypot {
  position: absolute !important;
  left: -10000px !important;
  width: 1px !important;
  height: 1px !important;
  overflow: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

@media (max-width: 640px) {
  .lead-card {
    width: 100%;
    padding: 0.9rem;
    border-radius: 1rem;
  }

  .lead-form {
    grid-template-columns: 1fr;
    gap: 0.72rem;
  }

  .lead-field:has(textarea),
  .lead-consent,
  .lead-form__error,
  .lead-form__actions {
    grid-column: auto;
  }

  .lead-form__submit {
    width: 100%;
  }
}
