/* ==========================================================
   Tracy Lowery LLC — floating chat widget
   Loaded on every page. Bottom-right bubble opens a panel.
   ========================================================== */

.tl-chat {
  --tl-chat-bg: #12100c;
  --tl-chat-surface: #1c1815;
  --tl-chat-border: rgba(212, 169, 74, 0.24);
  --tl-chat-text: #f4ecd8;
  --tl-chat-muted: rgba(244, 236, 216, 0.62);
  --tl-chat-accent: #d4a94a;
  --tl-chat-accent-dark: #8a6a1f;
  --tl-chat-user-bubble: #2a2118;
  --tl-chat-assistant-bubble: rgba(212, 169, 74, 0.09);
  --tl-chat-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);

  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 2147483000;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* Toggle bubble */
.tl-chat__toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px 12px 14px;
  border-radius: 999px;
  background: var(--tl-chat-accent);
  color: #1a140b;
  border: none;
  cursor: pointer;
  box-shadow: var(--tl-chat-shadow);
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: 0.01em;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.tl-chat__toggle:hover { transform: translateY(-2px); box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55); }
.tl-chat__toggle:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }
.tl-chat__toggle svg { display: block; }
.tl-chat__toggle-label { display: inline; }

.tl-chat[data-open="true"] .tl-chat__toggle {
  padding: 12px;
  border-radius: 50%;
}
.tl-chat[data-open="true"] .tl-chat__toggle-label { display: none; }

/* Panel */
.tl-chat__panel {
  position: absolute;
  right: 0;
  bottom: calc(100% + 14px);
  width: min(380px, calc(100vw - 40px));
  height: min(560px, calc(100vh - 120px));
  background: var(--tl-chat-bg);
  border: 1px solid var(--tl-chat-border);
  border-radius: 18px;
  box-shadow: var(--tl-chat-shadow);
  display: none;
  flex-direction: column;
  overflow: hidden;
  color: var(--tl-chat-text);
}
.tl-chat[data-open="true"] .tl-chat__panel { display: flex; }

.tl-chat__header {
  padding: 14px 18px;
  background: linear-gradient(135deg, #1a140b 0%, #241a0f 100%);
  border-bottom: 1px solid var(--tl-chat-border);
  display: flex;
  align-items: center;
  gap: 12px;
}
.tl-chat__avatar {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  background: var(--tl-chat-accent);
  color: #1a140b;
  display: grid;
  place-items: center;
  font-family: "Cormorant Garamond", serif;
  font-size: 1.15rem;
  font-weight: 600;
  flex: none;
}
.tl-chat__titles { line-height: 1.2; }
.tl-chat__title { font-family: "Cormorant Garamond", serif; font-size: 1.15rem; }
.tl-chat__subtitle { font-size: 0.75rem; color: var(--tl-chat-muted); }
.tl-chat__close {
  margin-left: auto;
  background: transparent;
  border: none;
  color: var(--tl-chat-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
}
.tl-chat__close:hover { color: var(--tl-chat-text); background: rgba(255, 255, 255, 0.05); }

.tl-chat__log {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.14) transparent;
}
.tl-chat__log::-webkit-scrollbar { width: 6px; }
.tl-chat__log::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.14); border-radius: 3px; }

.tl-chat__msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.tl-chat__msg--assistant {
  background: var(--tl-chat-assistant-bubble);
  border: 1px solid var(--tl-chat-border);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.tl-chat__msg--user {
  background: var(--tl-chat-user-bubble);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.tl-chat__msg--system {
  background: transparent;
  color: var(--tl-chat-muted);
  font-size: 0.8rem;
  text-align: center;
  align-self: center;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px dashed var(--tl-chat-border);
}
.tl-chat__msg--admin {
  background: rgba(212, 169, 74, 0.14);
  border: 1px solid rgba(212, 169, 74, 0.45);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  padding: 8px 14px 10px;
}
.tl-chat__msg--admin .tl-chat__msg-from {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #d4a94a;
  margin-bottom: 2px;
}
.tl-chat__typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 8px 12px;
}
.tl-chat__typing span {
  width: 6px;
  height: 6px;
  background: var(--tl-chat-accent);
  border-radius: 50%;
  animation: tl-chat-bounce 1.2s infinite;
}
.tl-chat__typing span:nth-child(2) { animation-delay: 0.15s; }
.tl-chat__typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes tl-chat-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* Handoff card */
.tl-chat__handoff {
  margin: 4px 0 2px;
  padding: 12px;
  background: rgba(212, 169, 74, 0.06);
  border: 1px solid var(--tl-chat-border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.tl-chat__handoff-title { font-size: 0.85rem; font-weight: 600; color: var(--tl-chat-accent); }
.tl-chat__handoff-desc { font-size: 0.8rem; color: var(--tl-chat-muted); line-height: 1.4; }
.tl-chat__handoff input {
  background: #0a0906;
  border: 1px solid var(--tl-chat-border);
  color: var(--tl-chat-text);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.85rem;
  font-family: inherit;
  width: 100%;
  box-sizing: border-box;
}
.tl-chat__handoff input:focus { outline: 2px solid var(--tl-chat-accent); outline-offset: 1px; }
.tl-chat__handoff-actions { display: flex; gap: 8px; }
.tl-chat__handoff button {
  flex: 1;
  padding: 8px 10px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
}
.tl-chat__handoff-submit { background: var(--tl-chat-accent); color: #1a140b; }
.tl-chat__handoff-submit:disabled { opacity: 0.5; cursor: default; }
.tl-chat__handoff-skip { background: transparent; color: var(--tl-chat-muted); border: 1px solid var(--tl-chat-border) !important; }

/* Composer */
.tl-chat__composer {
  padding: 12px;
  border-top: 1px solid var(--tl-chat-border);
  background: var(--tl-chat-surface);
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.tl-chat__input {
  flex: 1;
  background: #0a0906;
  border: 1px solid var(--tl-chat-border);
  color: var(--tl-chat-text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.9rem;
  font-family: inherit;
  resize: none;
  line-height: 1.4;
  max-height: 120px;
}
.tl-chat__input:focus { outline: 2px solid var(--tl-chat-accent); outline-offset: 1px; }
.tl-chat__send {
  padding: 10px 14px;
  border-radius: 10px;
  border: none;
  background: var(--tl-chat-accent);
  color: #1a140b;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  font-family: inherit;
  display: flex;
  align-items: center;
  gap: 6px;
}
.tl-chat__send:disabled { opacity: 0.5; cursor: default; }
.tl-chat__send:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

.tl-chat__disclaimer {
  padding: 0 12px 10px;
  font-size: 0.7rem;
  color: var(--tl-chat-muted);
  text-align: center;
  background: var(--tl-chat-surface);
}

/* Light theme support (uses the page's data-theme) */
html[data-theme="light"] .tl-chat {
  --tl-chat-bg: #fbf8f1;
  --tl-chat-surface: #ffffff;
  --tl-chat-border: rgba(138, 106, 31, 0.28);
  --tl-chat-text: #1a140b;
  --tl-chat-muted: rgba(26, 20, 11, 0.6);
  --tl-chat-user-bubble: #ede6d3;
  --tl-chat-assistant-bubble: rgba(212, 169, 74, 0.12);
  --tl-chat-shadow: 0 20px 60px rgba(26, 20, 11, 0.18);
}
html[data-theme="light"] .tl-chat__header {
  background: linear-gradient(135deg, #f4ecd8 0%, #ede6d3 100%);
}
html[data-theme="light"] .tl-chat__input,
html[data-theme="light"] .tl-chat__handoff input {
  background: #fff;
  color: #1a140b;
}

/* Mobile */
@media (max-width: 480px) {
  .tl-chat { right: 12px; bottom: 12px; }
  .tl-chat__panel {
    width: calc(100vw - 24px);
    height: calc(100vh - 80px);
    bottom: calc(100% + 10px);
  }
  .tl-chat__toggle-label { display: none; }
  .tl-chat__toggle { padding: 12px; border-radius: 50%; }
}

/* Print / reduced motion */
@media print { .tl-chat { display: none !important; } }
@media (prefers-reduced-motion: reduce) {
  .tl-chat__typing span { animation: none; opacity: 0.7; }
  .tl-chat__toggle { transition: none; }
}
