/*
 * Ask Turleno: the chat panel, its floating button and the demo form inside it.
 * It uses the page's identity tokens (ink blue actions with a white label, cool neutral surfaces,
 * navy text and focus ring) and falls back to the same values when they are missing. Every rule is
 * scoped under .tla so nothing here restyles the page, except the one that stops the page scrolling
 * behind the open panel on a phone.
 */

.tla {
  --tla-text: var(--text, #0b1f3a);
  --tla-muted: var(--muted, #4a5a73);
  --tla-surface: var(--surface, #ffffff);
  --tla-surface-2: var(--surface-2, #eef1f5);
  --tla-rule: var(--rule, #e2e6ec);
  --tla-line: var(--line, #8590a3);
  --tla-primary: var(--primary, #2a5bc8);
  --tla-primary-hover: var(--primary-hover, #234fb0);
  --tla-primary-fg: var(--primary-fg, #ffffff);
  --tla-primary-soft: var(--primary-soft, #e8eefb);
  --tla-link: var(--link, #2a5bc8);
  --tla-navy: var(--navy, #0b1f3a);
  font-family: inherit;
  color: var(--tla-text);
}

.tla [hidden] {
  display: none !important;
}

.tla-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.tla :focus-visible {
  outline: 2px solid var(--tla-navy);
  outline-offset: 2px;
}

/* ---------- Floating button ---------- */

.tla-fab {
  position: fixed;
  right: max(16px, env(safe-area-inset-right, 0px));
  bottom: max(16px, env(safe-area-inset-bottom, 0px));
  z-index: 900;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 8px 18px 8px 8px;
  border: 1px solid var(--tla-primary);
  border-radius: 999px;
  background: var(--tla-primary);
  color: var(--tla-primary-fg);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(11, 31, 58, 0.2);
  transition: background-color 0.15s ease;
}

.tla-fab:hover {
  background: var(--tla-primary-hover);
  border-color: var(--tla-primary-hover);
}

.tla-fab-icon {
  width: 36px;
  height: 36px;
  flex: none;
  border-radius: 9px;
}

/* ---------- Panel ---------- */

.tla-backdrop {
  position: fixed;
  inset: 0;
  z-index: 950;
  background: rgba(11, 31, 58, 0.32);
}

.tla-panel {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  width: min(400px, calc(100vw - 48px));
  height: min(680px, calc(100vh - 48px));
  height: min(680px, calc(100dvh - 48px));
  overflow: hidden;
  border: 1px solid var(--tla-rule);
  border-radius: 16px;
  background: var(--tla-surface);
  box-shadow: 0 16px 40px rgba(11, 31, 58, 0.24);
  font-size: 15px;
  line-height: 1.5;
}

.tla-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 8px 12px 16px;
  border-bottom: 1px solid var(--tla-rule);
}

.tla-head-icon {
  width: 32px;
  height: 32px;
  flex: none;
  border-radius: 8px;
}

.tla .tla-title {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: 0;
}

.tla-title:focus {
  outline: none;
}

.tla-title:focus-visible {
  outline: 2px solid var(--tla-navy);
}

.tla-close {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: none;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--tla-text);
  cursor: pointer;
}

.tla-close:hover {
  background: var(--tla-surface-2);
}

.tla-close-icon,
.tla-send-icon,
.tla-back-icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* The AI label: always on screen while the panel is open. */
.tla-label {
  margin: 0;
  padding: 8px 16px;
  border-bottom: 1px solid var(--tla-rule);
  background: var(--tla-surface-2);
  color: var(--tla-muted);
  font-size: 12.5px;
  line-height: 1.45;
}

.tla-label-link {
  color: var(--tla-link);
  font-weight: 600;
}

.tla-view {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

/* ---------- Conversation ---------- */

.tla-log {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  padding: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.tla-msg {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 12px;
  overflow-wrap: anywhere;
}

.tla-msg p {
  margin: 0;
  white-space: pre-line;
}

.tla-msg-bot {
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  background: var(--tla-surface-2);
  color: var(--tla-text);
}

.tla-msg-note {
  border: 1px solid var(--tla-rule);
  background: var(--tla-surface);
}

.tla-msg-me {
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  background: var(--tla-primary);
  color: var(--tla-primary-fg);
}

.tla-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.tla-act {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid var(--tla-line);
  border-radius: 8px;
  background: var(--tla-surface);
  color: var(--tla-text);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.25;
  text-decoration: none;
  cursor: pointer;
}

.tla-act:hover {
  border-color: var(--tla-text);
}

.tla-act-primary {
  border-color: var(--tla-primary);
  background: var(--tla-primary);
  color: var(--tla-primary-fg);
}

.tla-act-primary:hover {
  border-color: var(--tla-primary-hover);
  background: var(--tla-primary-hover);
}

.tla-typing {
  padding: 0 16px 8px;
}

.tla-dots {
  display: inline-flex;
  gap: 4px;
  padding: 10px 14px;
  border-radius: 12px;
  border-bottom-left-radius: 4px;
  background: var(--tla-surface-2);
}

.tla-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--tla-muted);
  animation: tla-dot 1.2s ease-in-out infinite;
}

.tla-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.tla-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes tla-dot {
  0%,
  60%,
  100% {
    opacity: 0.35;
  }
  30% {
    opacity: 1;
  }
}

.tla-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 16px;
  border-top: 1px solid var(--tla-rule);
}

.tla-chips:empty {
  display: none;
}

.tla-chip {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 6px 14px;
  border: 1px solid var(--tla-line);
  border-radius: 999px;
  background: var(--tla-surface);
  color: var(--tla-text);
  font: inherit;
  font-size: 14px;
  line-height: 1.25;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.tla-chip:hover:not(:disabled) {
  border-color: var(--tla-primary);
  color: var(--tla-primary);
}

.tla-chip:disabled {
  cursor: default;
  opacity: 0.55;
}

.tla .tla-compose {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin: 0;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  border: 0;
  border-top: 1px solid var(--tla-rule);
  border-radius: 0;
  background: var(--tla-surface);
}

.tla-input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  max-height: 120px;
  padding: 10px 12px;
  border: 1px solid var(--tla-line);
  border-radius: 8px;
  background: var(--tla-surface);
  color: var(--tla-text);
  font: inherit;
  font-size: 16px;
  line-height: 1.4;
  resize: none;
}

.tla-input::placeholder {
  color: var(--tla-muted);
  opacity: 1;
}

.tla-input:focus-visible {
  outline: none;
  border-color: var(--tla-primary);
  box-shadow: 0 0 0 3px rgba(42, 91, 200, 0.2);
}

.tla-input:disabled {
  background: var(--tla-surface-2);
}

.tla-send {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: none;
  border: 1px solid var(--tla-primary);
  border-radius: 8px;
  background: var(--tla-primary);
  color: var(--tla-primary-fg);
  cursor: pointer;
}

.tla-send:hover:not(:disabled) {
  background: var(--tla-primary-hover);
}

.tla-send:disabled {
  cursor: default;
  opacity: 0.55;
}

/* ---------- Demo form ---------- */

.tla-form-head {
  padding: 8px 12px;
  border-bottom: 1px solid var(--tla-rule);
}

.tla-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--tla-link);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.tla-back:hover {
  background: var(--tla-surface-2);
}

.tla-form-body {
  flex: 1;
  min-height: 0;
  padding: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.tla .tla-form-title {
  margin: 0 0 16px;
  font-size: 20px;
  font-weight: 600;
}

.tla-form-title:focus {
  outline: none;
}

.tla .tla-demo-form {
  display: grid;
  gap: 16px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.tla .tla-demo-form .two {
  grid-template-columns: 1fr;
  gap: 16px;
}

.tla .tla-demo-form .btn {
  justify-self: start;
}

.tla-summary {
  display: grid;
  gap: 6px;
  padding: 12px 14px;
  border: 1px solid var(--tla-rule);
  border-radius: 12px;
  background: var(--tla-surface-2);
}

.tla-summary h4 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

.tla-summary p {
  margin: 0;
}

.tla-summary-help,
.tla-summary-loading {
  color: var(--tla-muted);
  font-size: 13px;
}

.tla-summary-text {
  padding: 8px 10px;
  border: 1px solid var(--tla-rule);
  border-radius: 8px;
  background: var(--tla-surface);
  font-size: 14px;
  overflow-wrap: anywhere;
  white-space: pre-line;
}

.tla-summary-choice {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  cursor: pointer;
}

.tla-summary-choice input {
  width: 18px;
  height: 18px;
  margin: 0;
  flex: none;
  accent-color: var(--tla-link);
}

.tla .success {
  padding: 20px;
}

/* ---------- Phone: a full-screen sheet ---------- */

@media (max-width: 639px) {
  .tla-panel {
    inset: 0;
    width: 100%;
    height: 100%;
    max-height: none;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    padding-top: env(safe-area-inset-top, 0px);
  }

  .tla-chip {
    min-height: 44px;
  }

  .tla-act {
    min-height: 44px;
  }
}

/* The page behind an open phone sheet does not scroll. */
@media (max-width: 639px) {
  html.tla-open,
  html.tla-open body {
    overflow: hidden;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tla-dots span {
    animation: none;
    opacity: 0.7;
  }

  .tla-fab {
    transition: none;
  }
}
