/* ===================================================================
   The Social Edit — AI chat widget
   Self-contained, prefixed (.tse-chat*) so it never collides with the
   site's Tailwind. Brand palette mirrors includes/head.php.
   =================================================================== */
.tse-chat {
  --tse-ink:   #0F0F0F;
  --tse-cream: #F6F2EA;
  --tse-bone:  #FBF9F4;
  --tse-oat:   #EBE3D2;
  --tse-sand:  #D6CFC0;
  --tse-clay:  #B89968;
  --tse-cocoa: #6B5847;
  --tse-line:  rgba(15, 15, 15, 0.10);
  font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.tse-chat *, .tse-chat *::before, .tse-chat *::after { box-sizing: border-box; }

/* ---- Launcher ---------------------------------------------------- */
.tse-chat-launcher {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 9998;
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0;
  height: 60px;
  width: 60px;
  border: none;
  border-radius: 999px;
  background: var(--tse-ink);
  color: var(--tse-cream);
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(15, 15, 15, 0.28);
  transition: transform .25s ease, box-shadow .25s ease, width .25s ease, background .25s ease;
  overflow: hidden;
}
.tse-chat-launcher:hover { transform: translateY(-2px); box-shadow: 0 14px 38px rgba(15, 15, 15, 0.34); }
.tse-chat-launcher:focus-visible { outline: 3px solid var(--tse-clay); outline-offset: 3px; }
.tse-chat-launcher svg { width: 26px; height: 26px; flex: 0 0 auto; margin: 0 17px; transition: margin .25s ease; }
.tse-chat-launcher .tse-chat-launcher-label {
  white-space: nowrap;
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  max-width: 0;
  opacity: 0;
  transition: max-width .3s ease, opacity .2s ease, padding .3s ease;
  padding-right: 0;
}
@media (min-width: 768px) {
  .tse-chat-launcher { width: auto; padding-right: 0; }
  .tse-chat-launcher svg { margin: 0 0 0 17px; }
  .tse-chat-launcher .tse-chat-launcher-label { max-width: 180px; opacity: 1; padding-right: 22px; padding-left: 10px; }
}
.tse-chat-launcher .tse-chat-dot {
  position: absolute; top: 12px; right: 12px;
  width: 10px; height: 10px; border-radius: 999px;
  background: var(--tse-clay); border: 2px solid var(--tse-ink);
}
.tse-chat-launcher.tse-is-open { transform: scale(0.9); opacity: 0; pointer-events: none; }

/* ---- Panel ------------------------------------------------------- */
.tse-chat-panel {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 9999;
  width: 384px;
  max-width: calc(100vw - 2rem);
  height: min(640px, calc(100vh - 2.5rem));
  display: flex;
  flex-direction: column;
  background: var(--tse-bone);
  border: 1px solid var(--tse-line);
  border-radius: 24px;
  box-shadow: 0 28px 80px rgba(15, 15, 15, 0.28);
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(0.98);
  transform-origin: bottom right;
  pointer-events: none;
  transition: opacity .26s ease, transform .26s cubic-bezier(.2,.8,.2,1);
}
.tse-chat-panel.tse-is-open { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }

@media (max-width: 480px) {
  .tse-chat-panel {
    bottom: 0; right: 0; left: 0;
    width: 100%; max-width: 100%;
    height: 100dvh; height: 100vh;
    border-radius: 0;
  }
  .tse-chat-launcher { bottom: 1rem; right: 1rem; }
}

/* ---- Header ------------------------------------------------------ */
.tse-chat-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.1rem;
  background: var(--tse-ink);
  color: var(--tse-cream);
  flex: 0 0 auto;
}
.tse-chat-avatar {
  width: 40px; height: 40px; border-radius: 999px;
  background: var(--tse-clay); color: var(--tse-ink);
  display: grid; place-items: center; flex: 0 0 auto;
  font-weight: 900; font-size: 1rem;
}
.tse-chat-htext { min-width: 0; flex: 1; }
.tse-chat-title { font-weight: 800; font-size: 0.95rem; letter-spacing: -0.01em; line-height: 1.1; }
.tse-chat-sub { font-size: 0.7rem; color: rgba(246,242,234,0.65); margin-top: 2px; display: flex; align-items: center; gap: 6px; }
.tse-chat-sub::before { content: ''; width: 7px; height: 7px; border-radius: 999px; background: #6FCF8E; box-shadow: 0 0 0 0 rgba(111,207,142,0.6); animation: tse-pulse 2s infinite; }
@keyframes tse-pulse { 0% { box-shadow: 0 0 0 0 rgba(111,207,142,0.5);} 70%{box-shadow:0 0 0 6px rgba(111,207,142,0);} 100%{box-shadow:0 0 0 0 rgba(111,207,142,0);} }
.tse-chat-close {
  appearance: none; border: none; background: rgba(246,242,234,0.10); color: var(--tse-cream);
  width: 34px; height: 34px; border-radius: 999px; cursor: pointer; flex: 0 0 auto;
  display: grid; place-items: center; transition: background .2s ease;
}
.tse-chat-close:hover { background: rgba(246,242,234,0.2); }
.tse-chat-close:focus-visible { outline: 2px solid var(--tse-clay); outline-offset: 2px; }

/* ---- Messages ---------------------------------------------------- */
.tse-chat-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  background:
    radial-gradient(120% 60% at 100% 0%, rgba(184,153,104,0.08), transparent 60%),
    var(--tse-bone);
  scroll-behavior: smooth;
}
.tse-msg { display: flex; gap: 0.5rem; max-width: 88%; }
.tse-msg-bubble {
  padding: 0.7rem 0.9rem;
  border-radius: 16px;
  font-size: 0.9rem;
  line-height: 1.55;
  color: var(--tse-ink);
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.tse-msg.tse-bot { align-self: flex-start; }
.tse-msg.tse-bot .tse-msg-bubble { background: var(--tse-oat); border-bottom-left-radius: 5px; }
.tse-msg.tse-user { align-self: flex-end; }
.tse-msg.tse-user .tse-msg-bubble { background: var(--tse-ink); color: var(--tse-cream); border-bottom-right-radius: 5px; }
.tse-msg-bubble a { color: var(--tse-cocoa); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
.tse-msg.tse-user .tse-msg-bubble a { color: var(--tse-cream); }
.tse-msg-bubble p { margin: 0 0 0.5rem; }
.tse-msg-bubble p:last-child { margin-bottom: 0; }
.tse-msg-bubble ul { margin: 0.35rem 0; padding-left: 1.1rem; }
.tse-msg-bubble li { margin: 0.2rem 0; }
.tse-msg-bubble strong { font-weight: 800; }

/* typing indicator */
.tse-typing { display: inline-flex; gap: 4px; align-items: center; padding: 0.85rem 0.95rem; }
.tse-typing span { width: 7px; height: 7px; border-radius: 999px; background: var(--tse-cocoa); opacity: 0.5; animation: tse-bounce 1.2s infinite; }
.tse-typing span:nth-child(2){ animation-delay: .15s; }
.tse-typing span:nth-child(3){ animation-delay: .3s; }
@keyframes tse-bounce { 0%,60%,100%{ transform: translateY(0); opacity:.4;} 30%{ transform: translateY(-4px); opacity:.9;} }

/* suggested chips */
.tse-chat-suggested { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-top: 0.2rem; }
.tse-chip {
  border: 1px solid var(--tse-line);
  background: var(--tse-cream);
  color: var(--tse-ink);
  border-radius: 999px;
  padding: 0.45rem 0.8rem;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .18s ease, transform .18s ease;
  text-align: left;
}
.tse-chip:hover { background: var(--tse-oat); transform: translateY(-1px); }
.tse-chip:focus-visible { outline: 2px solid var(--tse-clay); outline-offset: 2px; }

/* ---- Quick actions + composer ------------------------------------ */
.tse-chat-actions {
  display: flex; gap: 0.4rem; padding: 0.55rem 0.75rem 0; flex: 0 0 auto;
}
.tse-chat-actions button {
  flex: 1; border: 1px solid var(--tse-line); background: var(--tse-cream);
  color: var(--tse-ink); border-radius: 999px; padding: 0.5rem; cursor: pointer;
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.02em;
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  transition: background .18s ease;
}
.tse-chat-actions button:hover { background: var(--tse-oat); }
.tse-chat-actions button.tse-primary { background: var(--tse-clay); color: var(--tse-cream); border-color: var(--tse-clay); }
.tse-chat-actions button.tse-primary:hover { background: var(--tse-cocoa); }
.tse-chat-actions svg { width: 14px; height: 14px; }

.tse-chat-composer {
  display: flex; align-items: flex-end; gap: 0.5rem;
  padding: 0.75rem; flex: 0 0 auto;
  border-top: 1px solid var(--tse-line); background: var(--tse-bone);
}
.tse-chat-composer textarea {
  flex: 1; resize: none; border: 1px solid var(--tse-line); border-radius: 14px;
  padding: 0.6rem 0.75rem; font: inherit; font-size: 0.9rem; line-height: 1.4;
  background: var(--tse-cream); color: var(--tse-ink); max-height: 110px; min-height: 44px;
  outline: none; transition: border-color .18s ease;
}
.tse-chat-composer textarea:focus { border-color: var(--tse-clay); }
.tse-chat-send {
  flex: 0 0 auto; width: 44px; height: 44px; border-radius: 14px; border: none;
  background: var(--tse-ink); color: var(--tse-cream); cursor: pointer;
  display: grid; place-items: center; transition: background .18s ease, transform .18s ease;
}
.tse-chat-send:hover { background: var(--tse-cocoa); }
.tse-chat-send:disabled { opacity: 0.4; cursor: default; }
.tse-chat-send:focus-visible { outline: 2px solid var(--tse-clay); outline-offset: 2px; }
.tse-chat-send svg { width: 18px; height: 18px; }

.tse-chat-foot {
  text-align: center; font-size: 0.62rem; color: rgba(15,15,15,0.45);
  padding: 0.4rem 0.75rem 0.6rem; background: var(--tse-bone); flex: 0 0 auto;
}

/* ---- Enquiry form ------------------------------------------------ */
.tse-form { display: flex; flex-direction: column; gap: 0.6rem; }
.tse-form-intro { font-size: 0.82rem; color: rgba(15,15,15,0.7); line-height: 1.5; margin-bottom: 0.2rem; }
.tse-field label { display: block; font-size: 0.7rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em; color: var(--tse-cocoa); margin-bottom: 0.25rem; }
.tse-field input, .tse-field select, .tse-field textarea {
  width: 100%; border: 1px solid var(--tse-line); border-radius: 12px;
  padding: 0.55rem 0.7rem; font: inherit; font-size: 0.88rem; background: var(--tse-cream);
  color: var(--tse-ink); outline: none; transition: border-color .18s ease;
}
.tse-field input:focus, .tse-field select:focus, .tse-field textarea:focus { border-color: var(--tse-clay); }
.tse-field textarea { resize: vertical; min-height: 76px; }
.tse-field.tse-invalid input, .tse-field.tse-invalid select, .tse-field.tse-invalid textarea { border-color: #C2553C; }
.tse-field-error { color: #C2553C; font-size: 0.72rem; margin-top: 0.2rem; display: none; }
.tse-field.tse-invalid .tse-field-error { display: block; }
.tse-hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.tse-form-submit {
  margin-top: 0.2rem; border: none; border-radius: 999px; background: var(--tse-clay);
  color: var(--tse-cream); font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase;
  font-size: 0.74rem; padding: 0.75rem; cursor: pointer; transition: background .18s ease;
}
.tse-form-submit:hover { background: var(--tse-cocoa); }
.tse-form-submit:disabled { opacity: 0.55; cursor: default; }
.tse-form-note { font-size: 0.72rem; color: rgba(15,15,15,0.55); }
.tse-form-back {
  background: none; border: none; color: var(--tse-cocoa); font-weight: 700; cursor: pointer;
  font-size: 0.78rem; padding: 0; display: inline-flex; align-items: center; gap: 4px;
}
.tse-form-ok {
  background: var(--tse-oat); border-radius: 16px; padding: 1rem; font-size: 0.88rem;
  line-height: 1.5; color: var(--tse-ink);
}

/* scrollbar */
.tse-chat-body::-webkit-scrollbar { width: 8px; }
.tse-chat-body::-webkit-scrollbar-thumb { background: rgba(15,15,15,0.16); border-radius: 999px; }

@media (prefers-reduced-motion: reduce) {
  .tse-chat-panel, .tse-chat-launcher { transition: none; }
  .tse-typing span, .tse-chat-sub::before { animation: none; }
}
