/* ============================================================================
   DoTiap website AI assistant — widget styles
   Matches the dotiap.world aesthetic: deep ink background, champagne gold,
   Playfair Display serif headings, Inter body. No frameworks.
   ============================================================================ */

:root {
  /* Site tokens (mirrored from styles.css so the widget can live standalone) */
  --da-bg: #0a0e17;
  --da-bg-soft: #0d1322;
  --da-bg-card: #101828;
  --da-gold: #C6A15B;
  --da-gold-2: #D9BC7E;
  --da-gold-deep: #9a7a3e;
  --da-ink: #f3efe6;
  --da-ink-dim: rgba(243, 239, 230, 0.72);
  --da-ink-faint: rgba(243, 239, 230, 0.5);
  --da-line: rgba(198, 161, 91, 0.22);
  --da-line-soft: rgba(243, 239, 230, 0.1);
  --da-serif: "Playfair Display", Georgia, "Times New Roman", serif;
  --da-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* ---------- Floating launcher button ---------- */
.da-launcher {
  position: fixed;
  z-index: 2147483000;
  right: calc(env(safe-area-inset-right, 0px) + 1.25rem);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 1.25rem);
  width: 60px;
  height: 60px;
  box-sizing: border-box;
  overflow: hidden;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--da-gold-deep);
  background: linear-gradient(135deg, var(--da-bg-card), var(--da-bg-soft));
  color: var(--da-gold-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55), 0 0 0 4px rgba(198, 161, 91, 0.08);
  transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
  font-family: var(--da-sans);
  -webkit-tap-highlight-color: transparent;
}

.da-launcher:hover,
.da-launcher:focus-visible {
  transform: translateY(-3px);
  border-color: var(--da-gold);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.6), 0 0 0 6px rgba(198, 161, 91, 0.12);
  outline: none;
}

.da-launcher svg {
  width: 26px;
  height: 26px;
  flex: 0 0 auto;
  display: block;
}

/* Pulsing halo — subtle, stops once opened. D5 fix (2026-10-21): the halo is
   the launcher's own box-shadow, not a scaled ::after ring — the ring's
   transform inflated the button's scrollWidth (59-62px in a 54px box);
   box-shadow never counts toward scrollable overflow, so
   scrollWidth == clientWidth again. */
.da-launcher:not([data-open="true"]) {
  animation: da-ping 2.8s ease-out infinite;
}

@keyframes da-ping {
  0%   { box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55), 0 0 0 0 rgba(198, 161, 91, 0.45); }
  70%  { box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55), 0 0 0 15px rgba(198, 161, 91, 0); }
  100% { box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55), 0 0 0 0 rgba(198, 161, 91, 0); }
}

/* ---------- Chat panel ---------- */
.da-panel {
  position: fixed;
  z-index: 2147483001;
  right: calc(env(safe-area-inset-right, 0px) + 1.25rem);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 5.6rem);
  width: min(392px, calc(100vw - 2rem));
  max-height: min(600px, calc(100dvh - 9rem));
  display: flex;
  flex-direction: column;
  background: linear-gradient(165deg, rgba(198, 161, 91, 0.07), rgba(198, 161, 91, 0.015)), var(--da-bg-card);
  border: 1px solid var(--da-line);
  border-radius: 18px;
  box-shadow: 0 32px 80px rgba(0, 0, 0, 0.65);
  overflow: hidden;
  font-family: var(--da-sans);
  color: var(--da-ink);
  opacity: 0;
  transform: translateY(14px) scale(0.98);
  transform-origin: bottom right;
  pointer-events: none;
  transition: opacity 0.28s ease, transform 0.28s ease;
}

.da-panel[data-open="true"] {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.da-panel[dir="rtl"] {
  transform-origin: bottom left;
}

/* ---------- Header ---------- */
.da-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.1rem 0.85rem;
  border-bottom: 1px solid var(--da-line-soft);
  background: rgba(10, 14, 23, 0.45);
}

.da-avatar {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--da-gold-deep);
  background: linear-gradient(135deg, rgba(198, 161, 91, 0.25), rgba(198, 161, 91, 0.06));
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--da-gold-2);
  font-family: var(--da-serif);
  font-size: 1.25rem;
  font-weight: 600;
  overflow: hidden;
  padding: 0;
}

.da-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: 50%;
}

.da-title-wrap {
  flex: 1 1 auto;
  min-width: 0;
}

.da-title {
  font-family: var(--da-serif);
  font-size: 1.06rem;
  font-weight: 600;
  color: var(--da-ink);
  margin: 0;
  line-height: 1.3;
}

.da-status {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--da-ink-faint);
  margin-top: 0.15rem;
}

.da-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #7ee2a8;
  box-shadow: 0 0 6px rgba(126, 226, 168, 0.8);
}

/* Demo badge — always honest about demo mode */
.da-demo-badge {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #14100a;
  background: linear-gradient(100deg, var(--da-gold-2), var(--da-gold));
  border-radius: 999px;
  padding: 0.28rem 0.6rem;
}

.da-demo-badge[hidden] { display: none; }

.da-close {
  flex: 0 0 auto;
  background: transparent;
  border: 1px solid transparent;
  color: var(--da-ink-faint);
  width: 46px;
  height: 46px;
  min-width: 46px;
  min-height: 46px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.15rem;
  line-height: 1;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.da-close:hover,
.da-close:focus-visible {
  color: var(--da-gold-2);
  border-color: var(--da-line);
  outline: none;
}

/* ---------- Message list ---------- */
.da-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 1.1rem 1.1rem 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  min-height: 180px;
  scrollbar-width: thin;
  scrollbar-color: var(--da-gold-deep) transparent;
}

.da-messages::-webkit-scrollbar { width: 6px; }
.da-messages::-webkit-scrollbar-thumb { background: var(--da-gold-deep); border-radius: 3px; }

.da-msg {
  max-width: 86%;
  padding: 0.65rem 0.85rem;
  border-radius: 14px;
  font-size: 0.93rem;
  line-height: 1.55;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.da-msg-bot {
  align-self: flex-start;
  background: rgba(243, 239, 230, 0.06);
  border: 1px solid var(--da-line-soft);
  border-start-start-radius: 4px;
  color: var(--da-ink);
}

.da-msg-user {
  align-self: flex-end;
  background: linear-gradient(100deg, rgba(198, 161, 91, 0.9), rgba(198, 161, 91, 0.78));
  color: #14100a;
  border-end-end-radius: 4px;
}

.da-panel[dir="rtl"] .da-msg-bot { align-self: flex-end; }
.da-panel[dir="rtl"] .da-msg-user { align-self: flex-start; }

.da-msg a {
  color: var(--da-gold-2);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.da-msg-user a { color: #14100a; }

/* Typing indicator */
.da-typing {
  display: inline-flex;
  gap: 0.3rem;
  padding: 0.35rem 0.2rem;
}
.da-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--da-gold);
  opacity: 0.5;
  animation: da-blink 1.2s ease-in-out infinite;
}
.da-typing span:nth-child(2) { animation-delay: 0.2s; }
.da-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes da-blink {
  0%, 100% { opacity: 0.25; transform: translateY(0); }
  50%      { opacity: 0.9; transform: translateY(-3px); }
}

/* ---------- Lead capture card ---------- */
.da-lead {
  align-self: stretch;
  max-width: none;
  background: linear-gradient(165deg, rgba(198, 161, 91, 0.12), rgba(198, 161, 91, 0.03));
  border: 1px solid var(--da-line);
  border-radius: 14px;
  padding: 0.9rem 1rem;
  font-size: 0.9rem;
}

.da-lead h4 {
  font-family: var(--da-serif);
  font-size: 1rem;
  font-weight: 600;
  color: var(--da-gold-2);
  margin: 0 0 0.15rem;
}

.da-lead p {
  margin: 0 0 0.7rem;
  color: var(--da-ink-dim);
  font-size: 0.85rem;
  line-height: 1.5;
}

.da-lead label {
  display: block;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  color: var(--da-ink-faint);
  margin: 0.55rem 0 0.25rem;
}

.da-lead input,
.da-lead select {
  width: 100%;
  box-sizing: border-box;
  background: rgba(10, 14, 23, 0.6);
  border: 1px solid var(--da-line-soft);
  border-radius: 9px;
  color: var(--da-ink);
  padding: 0.55rem 0.7rem;
  font-family: var(--da-sans);
  font-size: 0.9rem;
}

.da-lead input:focus,
.da-lead select:focus {
  outline: none;
  border-color: var(--da-gold);
}

.da-lead-actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 0.85rem;
}

.da-lead-note {
  margin-top: 0.7rem;
  font-size: 0.75rem;
  color: var(--da-ink-faint);
  font-style: italic;
}

/* ---------- Lead send-failure (F-19: honest, never a fake thank-you) ---------- */
.da-lead-failed {
  align-self: stretch;
  max-width: none;
  background: rgba(198, 40, 40, 0.08);
  border: 1px solid rgba(198, 40, 40, 0.35);
  border-radius: 14px;
  padding: 0.9rem 1rem;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--da-ink);
}

.da-lead-failed p { margin: 0 0 0.7rem; }

.da-lead-failed a { color: var(--da-gold-2); }

/* ---------- Composer ---------- */
.da-composer {
  display: flex;
  gap: 0.6rem;
  padding: 0.85rem 1.1rem 1rem;
  border-top: 1px solid var(--da-line-soft);
  background: rgba(10, 14, 23, 0.45);
}

.da-input {
  flex: 1 1 auto;
  min-width: 0;
  background: rgba(243, 239, 230, 0.05);
  border: 1px solid var(--da-line-soft);
  border-radius: 12px;
  color: var(--da-ink);
  padding: 0.7rem 0.85rem;
  min-height: 46px;
  box-sizing: border-box;
  font-family: var(--da-sans);
  font-size: 0.93rem;
  resize: none;
}

.da-input::placeholder { color: var(--da-ink-faint); }
.da-input:focus { outline: none; border-color: var(--da-gold); }

/* ---------- Buttons ---------- */
.da-btn {
  font-family: var(--da-sans);
  font-weight: 600;
  font-size: 0.9rem;
  border-radius: 12px;
  border: 1px solid var(--da-gold);
  background: linear-gradient(100deg, var(--da-gold-2), var(--da-gold));
  color: #14100a;
  padding: 0.7rem 1.05rem;
  min-height: 46px;
  box-sizing: border-box;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  white-space: nowrap;
}

.da-btn:hover,
.da-btn:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(198, 161, 91, 0.25);
  outline: none;
}

.da-btn:disabled {
  opacity: 0.55;
  cursor: wait;
  transform: none;
  box-shadow: none;
}

.da-btn-ghost {
  background: transparent;
  color: var(--da-ink-dim);
  border: 1px solid var(--da-line-soft);
}

.da-btn-ghost:hover,
.da-btn-ghost:focus-visible {
  color: var(--da-gold-2);
  border-color: var(--da-gold);
  box-shadow: none;
}

/* ---------- Footer disclaimer ---------- */
.da-footer {
  padding: 0.55rem 1.1rem calc(0.7rem + env(safe-area-inset-bottom, 0px));
  font-size: 0.7rem;
  color: var(--da-ink-faint);
  text-align: center;
  border-top: 1px solid var(--da-line-soft);
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .da-launcher, .da-panel, .da-btn { transition: none; }
  .da-launcher:not([data-open="true"]) { animation: none; }
  .da-typing span { animation: none; opacity: 0.6; }
}

/* ---------- SF-9 fix (2026-10-26), REVISED by centering pass 2026-10-26:
   keep body/footer text out of the launcher's bottom-right lane WITHOUT
   breaking centering ---------- */
/* The original SF-9 rule put padding-right: 4.9rem on EVERY main/footer
   .container under 860px. That shrank every content box asymmetrically and
   shifted the whole page ~39px left of center on phones — the exact defect
   the founder reported ("the main page isn't centered"). A fixed chat
   bubble transiently overlaying the bottom-right corner while scrolling is
   standard chat-widget behavior; permanently off-centering the whole site
   to prevent it is not. So: no container gutter anymore. Bubble clearance
   is kept exactly where it matters — the hero CTA row at load, via its own
   SYMMETRIC gutter in styles.css (buttons stay centered and clear of the
   lane). The launcher itself is untouched and stays on screen. */

/* Fix 6b (2026-11-04): phone clearance - launcher rides higher above the
   viewport bottom (+ safe area) so full-width content scrolls clear of its
   lane; the panel rises by the same delta so the launcher/panel gap is
   unchanged. Desktop rules above are untouched. */
/* ---------- Small screens ---------- */
@media (max-width: 480px) {
  .da-panel {
    right: 0.75rem;
    left: 0.75rem;
    width: auto;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 6.1rem);
  }
  .da-launcher {
    width: 56px;
    height: 56px;
    right: calc(env(safe-area-inset-right, 0px) + 0.9rem);
    bottom: calc(env(safe-area-inset-bottom, 0px) + 1.75rem);
  }
}
