/* ============================================
   Tally Chat Widget — TARA design language
   Matches tallysolutions.com chatbot (Orbitel)
   ============================================ */

:root {
  --tara-orange: #e69100;
  --tara-orange-dark: #cc8200;
  --tara-orange-send: #f4d08b;
  --tara-bubble: #f0f2f5;
  --tara-bubble-hover: #e8eaed;
  --tara-text: #231f20;
  --tara-text-muted: #6b6b6b;
  --tara-text-light: #9a9a9a;
  --tara-white: #ffffff;
  --tara-border: #e0e0e0;
  --tara-shadow: 0 4px 24px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.06);
  --tara-radius-window: 18px;
  --tara-radius-bubble: 16px;
  --tara-radius-pill: 999px;
  --tara-font: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --tara-transition: 0.25s ease;
  --widget-offset: 20px;
  --launcher-size: 52px;
}

/* ---- Widget root ---- */
.tally-chat-widget {
  position: fixed;
  bottom: var(--widget-offset);
  right: var(--widget-offset);
  z-index: 9999;
  font-family: var(--tara-font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--tara-text);
  -webkit-font-smoothing: antialiased;
  /* iOS: keep taps targeting the widget, not the page behind */
  -webkit-tap-highlight-color: transparent;
}

/* ---- Prompt window ---- */
.tally-chat-prompt {
  position: absolute;
  bottom: calc(var(--launcher-size) + 14px);
  right: 0;
  width: 340px;
  max-width: calc(100vw - var(--widget-offset) * 2);
  background: var(--tara-white);
  border-radius: var(--tara-radius-window);
  box-shadow: var(--tara-shadow);
  border: none;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px) scale(0.97);
  transform-origin: bottom right;
  transition:
    opacity var(--tara-transition),
    transform var(--tara-transition),
    visibility var(--tara-transition);
}

.tally-chat-prompt.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.tally-chat-prompt.is-minimized {
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px) scale(0.98);
  pointer-events: none;
}

/* ---- Orange header (TARA) ---- */
.tally-chat-prompt__header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--tara-orange);
  border-bottom: none;
}

.tally-chat-prompt__avatar {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--tara-white);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 6px;
}

.tally-chat-prompt__avatar img {
  width: 100%;
  height: auto;
  display: block;
}

.tally-chat-prompt__title-wrap {
  flex: 1;
  min-width: 0;
}

.tally-chat-prompt__title {
  font-size: 15px;
  font-weight: 700;
  color: var(--tara-white);
  margin: 0;
  line-height: 1.3;
}

.tally-chat-prompt__subtitle {
  font-size: 12px;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.92);
  margin: 2px 0 0;
  line-height: 1.3;
}

.tally-chat-prompt__close {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border: none;
  background: transparent;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--tara-white);
  opacity: 0.85;
  transition: opacity var(--tara-transition), background var(--tara-transition);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

.tally-chat-prompt__close > * {
  pointer-events: none;
}

.tally-chat-prompt__close:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.15);
}

.tally-chat-prompt__close svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
}

/* ---- Body ---- */
.tally-chat-prompt__body {
  padding: 16px 14px 10px;
  background: var(--tara-white);
}

/* Bot message bubble */
.tally-chat-prompt__message {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 14px;
}

.tally-chat-prompt__msg-avatar {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--tara-bubble);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 4px;
}

.tally-chat-prompt__msg-avatar img {
  width: 100%;
  height: auto;
  display: block;
}

.tally-chat-prompt__bubble {
  flex: 1;
  min-width: 0;
  background: var(--tara-bubble);
  color: var(--tara-text);
  font-size: 13px;
  line-height: 1.5;
  padding: 10px 14px;
  border-radius: var(--tara-radius-bubble);
  border-top-left-radius: 4px;
  margin: 0;
}

/* ---- Option list ---- */
.tally-chat-prompt__options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 2px;
}

.tally-chat-prompt__option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--tara-border);
  border-radius: var(--tara-radius-bubble);
  background: var(--tara-white);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  /* iOS Safari: ensure taps fire reliably */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  transition:
    background var(--tara-transition),
    border-color var(--tara-transition),
    box-shadow var(--tara-transition);
}

/* iOS: route taps to the button, not SVG/text children */
.tally-chat-prompt__option > * {
  pointer-events: none;
}

.tally-chat-prompt__option:hover {
  background: var(--tara-bubble);
  border-color: var(--tara-orange);
  box-shadow: 0 2px 8px rgba(230, 145, 0, 0.12);
}

.tally-chat-prompt__option:focus-visible {
  outline: 2px solid var(--tara-orange);
  outline-offset: 2px;
}

.tally-chat-prompt__option-icon {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--tara-bubble);
  color: var(--tara-orange);
}

.tally-chat-prompt__option-icon svg {
  width: 16px;
  height: 16px;
}

.tally-chat-prompt__option--video .tally-chat-prompt__option-icon {
  color: var(--tara-orange-dark);
}

.tally-chat-prompt__option--expert .tally-chat-prompt__option-icon {
  color: var(--tara-orange);
}

.tally-chat-prompt__option--ai .tally-chat-prompt__option-icon {
  color: #8a6914;
}

.tally-chat-prompt__option-text {
  flex: 1;
  min-width: 0;
}

.tally-chat-prompt__option-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--tara-text);
  margin-bottom: 1px;
}

.tally-chat-prompt__option-desc {
  display: block;
  font-size: 11px;
  color: var(--tara-text-muted);
  line-height: 1.35;
}

.tally-chat-prompt__option-arrow {
  flex-shrink: 0;
  color: var(--tara-text-light);
  opacity: 0;
  transition: opacity var(--tara-transition);
}

.tally-chat-prompt__option:hover .tally-chat-prompt__option-arrow {
  opacity: 1;
}

.tally-chat-prompt__option-arrow svg {
  width: 14px;
  height: 14px;
}

/* ---- Footer ---- */
.tally-chat-prompt__footer {
  padding: 8px 14px 14px;
  text-align: center;
  background: var(--tara-white);
}

.tally-chat-prompt__footer-text {
  font-size: 11px;
  color: var(--tara-text-light);
  margin: 0;
}

.tally-chat-prompt__footer-text strong {
  font-weight: 600;
  color: var(--tara-text-muted);
}

/* ---- Launcher (TARA orange circle) ---- */
.tally-chat-launcher {
  width: var(--launcher-size);
  height: var(--launcher-size);
  border-radius: 50%;
  border: none;
  background: var(--tara-orange);
  color: var(--tara-white);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(230, 145, 0, 0.45);
  transition: background var(--tara-transition), transform var(--tara-transition);
  position: relative;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

.tally-chat-launcher > * {
  pointer-events: none;
}

.tally-chat-launcher:hover {
  background: var(--tara-orange-dark);
  transform: scale(1.04);
}

.tally-chat-launcher:focus-visible {
  outline: 2px solid var(--tara-orange);
  outline-offset: 3px;
}

.tally-chat-launcher svg {
  width: 24px;
  height: 24px;
  stroke: var(--tara-white);
}

.tally-chat-launcher.has-pulse::before {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 2px solid var(--tara-orange);
  animation: tara-pulse 2s ease-out infinite;
  pointer-events: none;
}

@keyframes tara-pulse {
  0% { transform: scale(1); opacity: 0.5; }
  100% { transform: scale(1.3); opacity: 0; }
}

/* Show X when prompt open */
.tally-chat-widget.is-open .tally-chat-launcher__icon-chat {
  display: none;
}

.tally-chat-widget.is-open .tally-chat-launcher__icon-close {
  display: block;
}

.tally-chat-launcher__icon-close {
  display: none;
}

/* ---- Mobile ---- */
@media (max-width: 480px) {
  :root {
    --widget-offset: 14px;
    --launcher-size: 48px;
  }

  .tally-chat-prompt {
    width: calc(100vw - var(--widget-offset) * 2);
  }

  .tally-chat-prompt__body {
    padding: 14px 12px 8px;
  }

  .tally-chat-prompt__option-desc {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tally-chat-prompt,
  .tally-chat-prompt__option,
  .tally-chat-launcher {
    transition: none;
  }

  .tally-chat-launcher.has-pulse::before {
    animation: none;
  }
}

/* ============================================================
   Variant: Options only — 3 floating pills, no chat window
   (default experience)
   ============================================================ */

.tally-chat-widget--options-only .tally-chat-prompt {
  width: auto;
  max-width: none;
  background: transparent;
  box-shadow: none;
  border: none;
  overflow: visible;
  bottom: calc(var(--launcher-size) + 12px);
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.tally-chat-widget--options-only .tally-chat-prompt__footer {
  display: none;
}

.tally-chat-widget--options-only .tally-chat-prompt__header {
  order: -1;
  width: auto;
  padding: 0;
  background: transparent;
  gap: 0;
}

.tally-chat-widget--options-only .tally-chat-prompt__avatar,
.tally-chat-widget--options-only .tally-chat-prompt__title-wrap {
  display: none;
}

.tally-chat-widget--options-only .tally-chat-prompt__close {
  width: 28px;
  height: 28px;
  background: var(--tara-white);
  color: var(--tara-text-muted);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  opacity: 1;
}

.tally-chat-widget--options-only .tally-chat-prompt__close:hover {
  background: var(--tara-bubble);
  color: var(--tara-text);
}

.tally-chat-widget--options-only .tally-chat-prompt__body {
  padding: 0;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.tally-chat-widget--options-only .tally-chat-prompt__message {
  display: none;
}

.tally-chat-widget--options-only .tally-chat-prompt__options {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  padding: 0;
}

.tally-chat-widget--options-only .tally-chat-prompt__option {
  width: auto;
  min-width: 240px;
  max-width: 280px;
  padding: 12px 18px;
  background: var(--tara-white);
  border: none;
  border-radius: var(--tara-radius-pill);
  box-shadow:
    0 4px 16px rgba(0, 0, 0, 0.1),
    0 2px 6px rgba(0, 0, 0, 0.05);
  opacity: 0;
  transform: translateY(16px) scale(0.94);
}

.tally-chat-widget--options-only .tally-chat-prompt__option:hover {
  background: var(--tara-orange);
  box-shadow:
    0 6px 20px rgba(230, 145, 0, 0.35),
    0 2px 8px rgba(0, 0, 0, 0.08);
  transform: translateY(-2px) scale(1);
}

.tally-chat-widget--options-only .tally-chat-prompt__option:hover .tally-chat-prompt__option-label,
.tally-chat-widget--options-only .tally-chat-prompt__option:hover .tally-chat-prompt__option-desc {
  color: var(--tara-white);
}

.tally-chat-widget--options-only .tally-chat-prompt__option:hover .tally-chat-prompt__option-icon {
  background: rgba(255, 255, 255, 0.25);
  color: var(--tara-white);
}

.tally-chat-widget--options-only .tally-chat-prompt__option-icon {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--tara-bubble);
  color: var(--tara-orange);
}

.tally-chat-widget--options-only .tally-chat-prompt__option-label {
  font-size: 13px;
  font-weight: 500;
}

.tally-chat-widget--options-only .tally-chat-prompt__option-desc {
  font-size: 11px;
}

.tally-chat-widget--options-only .tally-chat-prompt__option-arrow {
  display: none;
}

.tally-chat-widget--options-only .tally-chat-prompt.is-visible .tally-chat-prompt__option:nth-child(3) {
  animation: options-flow-in 0.4s cubic-bezier(0.34, 1.2, 0.64, 1) 0.05s forwards;
}

.tally-chat-widget--options-only .tally-chat-prompt.is-visible .tally-chat-prompt__option:nth-child(2) {
  animation: options-flow-in 0.4s cubic-bezier(0.34, 1.2, 0.64, 1) 0.15s forwards;
}

.tally-chat-widget--options-only .tally-chat-prompt.is-visible .tally-chat-prompt__option:nth-child(1) {
  animation: options-flow-in 0.4s cubic-bezier(0.34, 1.2, 0.64, 1) 0.25s forwards;
}

@keyframes options-flow-in {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.9);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 480px) {
  .tally-chat-widget--options-only .tally-chat-prompt__option {
    min-width: 200px;
    max-width: calc(100vw - var(--widget-offset) * 2 - 60px);
  }

  .tally-chat-widget--options-only .tally-chat-prompt__option-desc {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tally-chat-widget--options-only .tally-chat-prompt.is-visible .tally-chat-prompt__option {
    animation: none;
    opacity: 1;
    transform: none;
  }
}
