/* ============================================================
   TALI v2 — UseTalos agentic customer-service widget
   Self-contained, zero-dependency, theme-adaptive.
   All selectors namespaced under #tali-root to prevent leaks.
   v2 (2026-07-10): UseTalos blue/red palette fallbacks, true
   dark-mode (system + data-theme hook for V2 toggle), iOS-safe
   panel height (dvh + safe-area), fake launcher badge removed.
   ============================================================ */

#tali-root {
  /* Local aliases: use host vars if present, else UseTalos brand fallbacks */
  --tali-navy: var(--navy, #16244a);
  --tali-blue: var(--accent-blue, #2563eb);
  --tali-red: var(--accent-red, #ef4444);
  --tali-green: var(--green, #1a9d3a);
  --tali-bg: var(--card, #ffffff);
  --tali-page: var(--bg, #f6f9ff);
  --tali-surface: var(--surface, #eef4ff);
  --tali-border: var(--border, #dbe4f3);
  --tali-text: var(--text, #0f172a);
  --tali-muted: var(--muted, #5b6b85);
  --tali-shadow: 0 12px 48px rgba(15, 32, 84, 0.20);
  --tali-radius: 18px;
  --tali-font: var(--sans, 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif);
  --tali-display: var(--display, 'Space Grotesk', 'Inter', system-ui, sans-serif);
  --tali-mono: var(--mono, ui-monospace, 'Cascadia Mono', 'JetBrains Mono', Consolas, monospace);

  position: fixed;
  z-index: 2147483000; /* above almost everything */
  bottom: 0;
  right: 0;
  font-family: var(--tali-font);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}
#tali-root *, #tali-root *::before, #tali-root *::after { box-sizing: border-box; }

/* True dark mode: system preference, plus data-theme hook for the V2 toggle */
@media (prefers-color-scheme: dark) {
  #tali-root {
    --tali-navy: var(--navy, #0d1830);
    --tali-blue: var(--accent-blue, #3b82f6);
    --tali-red: var(--accent-red, #ff5d6c);
    --tali-bg: var(--card, #101827);
    --tali-page: var(--bg, #0a0e16);
    --tali-surface: var(--surface, #16203a);
    --tali-border: var(--border, #26334f);
    --tali-text: var(--text, #e7eefc);
    --tali-muted: var(--muted, #9db0cf);
    --tali-shadow: 0 12px 48px rgba(0, 0, 0, 0.55);
  }
}
:root[data-theme="light"] #tali-root {
  --tali-navy: var(--navy, #16244a);
  --tali-blue: var(--accent-blue, #2563eb);
  --tali-red: var(--accent-red, #ef4444);
  --tali-bg: var(--card, #ffffff);
  --tali-page: var(--bg, #f6f9ff);
  --tali-surface: var(--surface, #eef4ff);
  --tali-border: var(--border, #dbe4f3);
  --tali-text: var(--text, #0f172a);
  --tali-muted: var(--muted, #5b6b85);
  --tali-shadow: 0 12px 48px rgba(15, 32, 84, 0.20);
}
:root[data-theme="dark"] #tali-root {
  --tali-navy: var(--navy, #0d1830);
  --tali-blue: var(--accent-blue, #3b82f6);
  --tali-red: var(--accent-red, #ff5d6c);
  --tali-bg: var(--card, #101827);
  --tali-page: var(--bg, #0a0e16);
  --tali-surface: var(--surface, #16203a);
  --tali-border: var(--border, #26334f);
  --tali-text: var(--text, #e7eefc);
  --tali-muted: var(--muted, #9db0cf);
  --tali-shadow: 0 12px 48px rgba(0, 0, 0, 0.55);
}

/* ---------- Launcher button ---------- */
#tali-launch {
  position: fixed;
  bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  right: 22px;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, var(--tali-blue) 0%, var(--tali-navy) 100%);
  color: #fff;
  box-shadow: var(--tali-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .25s cubic-bezier(.34,1.56,.64,1), filter .2s;
  overflow: visible;
}
#tali-launch:hover { transform: scale(1.07); filter: brightness(1.12); }
#tali-launch:active { transform: scale(.96); }
#tali-launch svg { width: 28px; height: 28px; }
/* Gentle attention pulse (respects reduced-motion below) */
#tali-launch::after {
  content: '';
  position: absolute; inset: 0;
  border-radius: 50%;
  box-shadow: 0 0 0 0 rgba(37,99,235,0.5);
  animation: tali-pulse 2.6s infinite;
}
@keyframes tali-pulse {
  0% { box-shadow: 0 0 0 0 rgba(37,99,235,0.45); }
  70% { box-shadow: 0 0 0 16px rgba(37,99,235,0); }
  100% { box-shadow: 0 0 0 0 rgba(37,99,235,0); }
}
#tali-root.tali-open #tali-launch { transform: scale(0); pointer-events: none; }

/* ---------- Panel ---------- */
#tali-panel {
  position: fixed;
  bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  right: 22px;
  width: 384px;
  max-width: calc(100vw - 24px);
  height: 620px;
  max-height: calc(100vh - 44px);
  max-height: calc(100dvh - 44px);
  background: var(--tali-bg);
  border: 1px solid var(--tali-border);
  border-radius: var(--tali-radius);
  box-shadow: var(--tali-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(24px) scale(.96);
  transform-origin: bottom right;
  pointer-events: none;
  transition: opacity .28s ease, transform .28s cubic-bezier(.34,1.4,.64,1);
}
#tali-root.tali-open #tali-panel {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* ---------- Header ---------- */
#tali-header {
  position: relative;
  padding: 16px 16px 14px;
  background: linear-gradient(135deg, var(--tali-navy) 0%, var(--tali-blue) 130%);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
#tali-header .tali-avatar {
  width: 42px; height: 42px; border-radius: 50%;
  background: #fff;
  color: var(--tali-blue);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 800; flex-shrink: 0;
  box-shadow: 0 2px 10px rgba(0,0,0,.25);
}
#tali-header .tali-id { flex: 1; min-width: 0; }
#tali-header .tali-id h4 { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: -.01em; font-family: var(--tali-display); }
#tali-header .tali-id .tali-status {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: #c8d6f2; margin-top: 2px;
}
#tali-header .tali-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #35d07f; box-shadow: 0 0 0 0 rgba(53,208,127,.6);
  animation: tali-live 2s infinite;
}
@keyframes tali-live {
  0% { box-shadow: 0 0 0 0 rgba(53,208,127,.6); }
  70% { box-shadow: 0 0 0 6px rgba(53,208,127,0); }
  100% { box-shadow: 0 0 0 0 rgba(53,208,127,0); }
}
#tali-close {
  background: rgba(255,255,255,.12);
  border: none; color: #fff; cursor: pointer;
  width: 32px; height: 32px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; line-height: 1; transition: background .15s; flex-shrink: 0;
}
#tali-close:hover { background: rgba(255,255,255,.24); }

/* ---------- Messages ---------- */
#tali-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px 8px;
  background: var(--tali-page);
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}
#tali-messages::-webkit-scrollbar { width: 7px; }
#tali-messages::-webkit-scrollbar-thumb { background: var(--tali-border); border-radius: 4px; }

.tali-msg { display: flex; gap: 9px; max-width: 100%; animation: tali-in .32s ease both; }
@keyframes tali-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.tali-msg.tali-user { flex-direction: row-reverse; }
.tali-msg .tali-msg-av {
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 800;
}
.tali-msg.tali-bot .tali-msg-av { background: var(--tali-blue); color: #fff; }
.tali-msg.tali-user .tali-msg-av { background: var(--tali-navy); color: #fff; }
.tali-msg .tali-msg-av svg { width: 15px; height: 15px; }
.tali-bubble {
  padding: 10px 13px; border-radius: 14px; font-size: 14px;
  max-width: 260px; word-wrap: break-word; white-space: pre-wrap;
}
.tali-bot .tali-bubble {
  background: var(--tali-bg); border: 1px solid var(--tali-border);
  color: var(--tali-text); border-top-left-radius: 4px;
}
.tali-user .tali-bubble {
  background: var(--tali-navy); color: #fff; border-top-right-radius: 4px;
}
.tali-bubble a { color: var(--tali-blue); font-weight: 600; }
.tali-user .tali-bubble a { color: #bcd2ff; }

/* ---------- Reasoning engine trace ---------- */
.tali-reason {
  align-self: flex-start;
  width: 100%;
  max-width: 300px;
  background: var(--tali-surface);
  border: 1px solid var(--tali-border);
  border-radius: 12px;
  padding: 10px 12px;
  font-family: var(--tali-mono);
  font-size: 11.5px;
  color: var(--tali-muted);
  animation: tali-in .3s ease both;
}
.tali-reason .tali-reason-title {
  display: flex; align-items: center; gap: 6px;
  font-family: var(--tali-font); font-weight: 700; font-size: 11px;
  text-transform: uppercase; letter-spacing: .05em;
  color: var(--tali-blue); margin-bottom: 7px;
}
.tali-reason .tali-cog {
  width: 13px; height: 13px; display: inline-block;
  animation: tali-spin 1.6s linear infinite;
}
.tali-reason.tali-done .tali-cog { animation: none; }
@keyframes tali-spin { to { transform: rotate(360deg); } }
.tali-step {
  display: flex; gap: 7px; align-items: flex-start;
  padding: 2px 0; opacity: 0;
  animation: tali-step-in .25s ease forwards;
}
@keyframes tali-step-in { to { opacity: 1; } }
.tali-step .tali-step-tag {
  color: var(--tali-blue); font-weight: 700; flex-shrink: 0;
}
.tali-step.tali-exec .tali-step-tag { color: var(--tali-green); }
.tali-step code { color: var(--tali-text); }

/* ---------- Typing dots ---------- */
.tali-typing { display: flex; gap: 4px; padding: 12px 14px; }
.tali-typing span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--tali-muted);
  animation: tali-bounce 1.3s infinite;
}
.tali-typing span:nth-child(2) { animation-delay: .18s; }
.tali-typing span:nth-child(3) { animation-delay: .36s; }
@keyframes tali-bounce { 0%,60%,100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-5px); opacity: 1; } }

/* ---------- Rich result cards ---------- */
.tali-card {
  width: 100%; max-width: 300px;
  background: var(--tali-bg); border: 1px solid var(--tali-border);
  border-radius: 14px; overflow: hidden; animation: tali-in .34s ease both;
}
.tali-card .tali-card-head {
  padding: 11px 14px; background: var(--tali-surface);
  border-bottom: 1px solid var(--tali-border);
  font-weight: 700; font-size: 13px; color: var(--tali-text);
  display: flex; align-items: center; gap: 7px;
  font-family: var(--tali-display);
}
.tali-card .tali-card-body { padding: 13px 14px; }

/* product / service card rows */
.tali-prod { display: flex; flex-direction: column; gap: 4px; }
.tali-prod .tali-prod-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.tali-prod h5 { margin: 0; font-size: 14px; font-weight: 700; color: var(--tali-text); font-family: var(--tali-display); }
.tali-prod .tali-price { font-size: 15px; font-weight: 800; color: var(--tali-blue); white-space: nowrap; }
.tali-prod p { margin: 3px 0 0; font-size: 12.5px; color: var(--tali-muted); }
.tali-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.tali-tag { font-size: 10.5px; background: var(--tali-surface); color: var(--tali-muted); padding: 3px 8px; border-radius: 20px; }

/* ROI / stat card */
.tali-stat { text-align: center; padding: 4px 0; }
.tali-stat .tali-big { font-size: 32px; font-weight: 800; color: var(--tali-blue); line-height: 1.1; font-family: var(--tali-display); }
.tali-stat .tali-big small { font-size: 15px; color: var(--tali-muted); font-weight: 600; }
.tali-stat .tali-sub { font-size: 12.5px; color: var(--tali-muted); margin-top: 4px; }

/* slot picker (booking) */
.tali-slots { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.tali-slot {
  padding: 9px 6px; border: 1px solid var(--tali-border); border-radius: 10px;
  background: var(--tali-page); cursor: pointer; text-align: center;
  font-size: 12.5px; font-weight: 600; color: var(--tali-text); transition: all .15s;
}
.tali-slot:hover { border-color: var(--tali-blue); background: var(--tali-surface); }
.tali-slot.tali-sel { background: var(--tali-navy); color: #fff; border-color: var(--tali-navy); }
.tali-slot small { display: block; font-weight: 400; opacity: .7; font-size: 10.5px; }

/* mini form */
.tali-form label { display: block; font-size: 12px; font-weight: 600; margin: 8px 0 3px; color: var(--tali-text); }
.tali-form input, .tali-form textarea, .tali-form select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--tali-border);
  border-radius: 9px; font-size: 13px; font-family: inherit;
  background: var(--tali-page); color: var(--tali-text);
}
.tali-form textarea { min-height: 62px; resize: vertical; }

/* buttons in cards / actions */
.tali-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; border-radius: 100px; border: none; cursor: pointer;
  font-weight: 700; font-size: 13px; font-family: inherit;
  background: var(--tali-blue); color: #fff; text-decoration: none;
  transition: all .18s; width: 100%; margin-top: 12px;
}
.tali-btn:hover { filter: brightness(1.12); transform: translateY(-1px); }
.tali-btn.tali-btn-gold { background: linear-gradient(135deg, var(--tali-red) 0%, #c81e2e 100%); color: #fff; }
.tali-btn.tali-btn-gold:hover { filter: brightness(1.1); }
.tali-btn.tali-btn-ghost { background: transparent; border: 1.5px solid var(--tali-border); color: var(--tali-text); }
.tali-btn.tali-btn-ghost:hover { border-color: var(--tali-blue); background: var(--tali-surface); transform: none; filter: none; }

.tali-confirm-badge {
  display: flex; align-items: center; gap: 8px; justify-content: center;
  padding: 10px; color: var(--tali-green); font-weight: 700; font-size: 14px;
}

/* ---------- Quick-reply chips ---------- */
#tali-chips {
  display: flex; flex-wrap: wrap; gap: 7px;
  padding: 8px 16px 4px; background: var(--tali-page);
  flex-shrink: 0;
}
.tali-chip {
  padding: 8px 13px; border: 1px solid var(--tali-border);
  background: var(--tali-bg); color: var(--tali-blue);
  border-radius: 100px; font-size: 12.5px; font-weight: 600;
  cursor: pointer; transition: all .15s; white-space: nowrap;
}
.tali-chip:hover { border-color: var(--tali-blue); background: var(--tali-surface); transform: translateY(-1px); }

/* ---------- Composer ---------- */
#tali-composer {
  display: flex; gap: 8px; align-items: flex-end;
  padding: 12px 14px 14px; background: var(--tali-page);
  border-top: 1px solid var(--tali-border); flex-shrink: 0;
}
#tali-input {
  flex: 1; resize: none; max-height: 100px;
  padding: 11px 13px; border: 1px solid var(--tali-border);
  border-radius: 22px; font-size: 14px; font-family: inherit;
  background: var(--tali-bg); color: var(--tali-text); line-height: 1.4;
}
#tali-input:focus { outline: none; border-color: var(--tali-blue); }
#tali-send {
  width: 42px; height: 42px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--tali-blue); color: #fff; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; transition: all .18s;
}
#tali-send:hover { filter: brightness(1.12); }
#tali-send:disabled { opacity: .4; cursor: default; }
#tali-poweredby {
  text-align: center; font-size: 10.5px; color: var(--tali-muted);
  padding: 0 0 8px; background: var(--tali-page); flex-shrink: 0;
}
#tali-poweredby strong { color: var(--tali-blue); }

/* ---------- Mobile ---------- */
@media (max-width: 480px) {
  #tali-panel {
    width: 100vw; height: 100vh; max-height: 100vh;
    height: 100dvh; max-height: 100dvh;
    bottom: 0; right: 0; border-radius: 0; border: none;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  #tali-launch { bottom: calc(16px + env(safe-area-inset-bottom, 0px)); right: 16px; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  #tali-root *, #tali-root *::before, #tali-root *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .05ms !important;
  }
}
