/* ============================================================
   Erbila — chat widget
   A premium, on-brand assistant. Matches the Operator aesthetic.
   ============================================================ */

/* ---------- Launcher (floating button) ---------- */
.cw-launcher {
  position: fixed;
  right: clamp(1rem, 3vw, 1.75rem);
  bottom: clamp(1rem, 3vw, 1.75rem);
  z-index: 90;

  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.7rem 1rem 0.7rem 0.85rem;

  background: linear-gradient(135deg, var(--bg-2) 0%, var(--bg-3) 100%);
  border: 1px solid var(--rule-2);
  border-radius: 999px;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 500;

  box-shadow:
    0 14px 40px -14px rgba(0,0,0,0.65),
    0 0 0 1px var(--rule),
    inset 0 1px 0 rgba(255,255,255,0.05);

  transition: transform 240ms cubic-bezier(.2,.8,.2,1),
              box-shadow 240ms ease,
              border-color 240ms ease;
  -webkit-tap-highlight-color: transparent;
}
/* RTL: flip the floating launcher to the bottom-left corner. */
[dir="rtl"] .cw-launcher {
  right: auto;
  left: clamp(1rem, 3vw, 1.75rem);
}
.cw-launcher:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow:
    0 18px 50px -18px var(--accent),
    0 0 0 1px var(--accent-soft);
}
.cw-launcher__avatar {
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--bg-deep);
  flex-shrink: 0;
  position: relative;
}
.cw-launcher__avatar::after {
  content: "";
  position: absolute;
  bottom: -1px; right: -1px;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--green);
  border: 2px solid var(--bg-2);
  box-shadow: 0 0 6px var(--green);
}
.cw-launcher__label { white-space: nowrap; }
.cw-launcher__close-icon { display: none; }

.cw-launcher.is-open .cw-launcher__avatar,
.cw-launcher.is-open .cw-launcher__label {
  display: none;
}
.cw-launcher.is-open .cw-launcher__close-icon {
  display: grid;
  place-items: center;
  width: 26px; height: 26px;
  color: var(--ink-2);
}

@media (max-width: 480px) {
  .cw-launcher__label { display: none; }
  .cw-launcher { padding: 0.85rem; }
}
/* Whenever the chat panel takes over the full viewport (≤ 768px), hide the
   floating launcher entirely — the header's X button is the close target.
   Otherwise the launcher's X-state floats above the send button. */
@media (max-width: 768px) {
  .cw-launcher.is-open { display: none; }
}

/* ---------- Panel ---------- */
.cw-panel {
  position: fixed;
  right: clamp(1rem, 3vw, 1.75rem);
  bottom: calc(clamp(1rem, 3vw, 1.75rem) + 64px);
  width: min(380px, calc(100vw - 2rem));
  height: min(580px, calc(100vh - 6rem));
  z-index: 89;

  display: flex;
  flex-direction: column;
  /* Warm grey @ 80% opacity, with frosted glass blur. */
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: saturate(160%) blur(20px);
  -webkit-backdrop-filter: saturate(160%) blur(20px);
  border: 1px solid var(--rule-2);
  border-radius: 16px;
  overflow: hidden;

  box-shadow:
    0 30px 80px -30px rgba(0,0,0,0.55),
    0 10px 30px -10px rgba(0,0,0,0.3),
    0 0 0 1px var(--rule),
    inset 0 1px 0 rgba(255,255,255,0.08);

  opacity: 0;
  transform: translateY(12px) scale(0.985);
  pointer-events: none;
  transition: opacity 240ms ease,
              transform 280ms cubic-bezier(.2,.8,.2,1);
}
[dir="rtl"] .cw-panel {
  right: auto;
  left: clamp(1rem, 3vw, 1.75rem);
}
.cw-panel.is-open {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

/* Full-screen takeover on phones, phablets, and small tablets.
   Below 768px the floating-panel form factor competes with the hero
   pill / eyebrow text — taking over the whole viewport is cleaner. */
@media (max-width: 768px) {
  .cw-panel {
    right: 0; bottom: 0; left: 0;
    width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    border-left: 0; border-right: 0; border-bottom: 0;
  }
}

/* ---------- Panel header ---------- */
.cw-head {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--rule);
  /* Subtle orange wash at top — panel's warm-grey glass shows through. */
  background: linear-gradient(180deg, rgba(228,113,72,0.10), transparent 60%);
  flex-shrink: 0;
}
.cw-head__avatar {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--bg-deep);
  box-shadow: 0 6px 18px -8px var(--accent);
  flex-shrink: 0;
}
.cw-head__title {
  flex: 1;
  display: flex; flex-direction: column;
  line-height: 1.2;
}
.cw-head__name {
  font-weight: 600;
  font-size: 0.94rem;
  color: var(--ink);
}
.cw-head__sub {
  font-size: 0.74rem;
  color: var(--muted);
  display: inline-flex; align-items: center; gap: 0.4rem;
}
.cw-head__dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
}
.cw-head__close {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  width: 32px; height: 32px;
  border-radius: 8px;
  display: grid; place-items: center;
  cursor: pointer;
  transition: all 180ms ease;
}
.cw-head__close:hover {
  border-color: var(--rule-2);
  color: var(--ink);
  background: var(--bg-3);
}

/* ---------- Messages ---------- */
.cw-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 1rem;
  display: flex; flex-direction: column; gap: 0.7rem;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--rule-2) transparent;
}
.cw-body::-webkit-scrollbar { width: 6px; }
.cw-body::-webkit-scrollbar-thumb { background: var(--rule-2); border-radius: 3px; }

.cw-msg {
  display: flex;
  flex-direction: column;
  max-width: 88%;
  animation: cw-in 320ms cubic-bezier(.2,.8,.2,1);
}
@keyframes cw-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

.cw-msg__label {
  font-size: 0.66rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
  margin: 0 0.35rem 0.2rem;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

.cw-msg__bubble {
  padding: 0.65rem 0.85rem;
  border-radius: 14px;
  font-size: 0.93rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.cw-msg--ai,
.cw-msg--team {
  align-items: flex-start;
}
.cw-msg--ai .cw-msg__bubble {
  background: var(--bg-3);
  border: 1px solid var(--rule);
  color: var(--ink);
  border-top-left-radius: 4px;
}
.cw-msg--team .cw-msg__bubble {
  background: var(--bg-3);
  border: 1px solid var(--rule);
  border-left: 2px solid var(--accent);
  color: var(--ink);
  border-top-left-radius: 4px;
}
.cw-msg--team .cw-msg__label {
  color: var(--accent);
}
.cw-msg--user {
  align-self: flex-end;
  align-items: flex-end;
}
.cw-msg--user .cw-msg__bubble {
  background: linear-gradient(135deg, var(--accent), var(--accent-deep, #C95E36));
  color: var(--bg-deep);
  font-weight: 500;
  border-top-right-radius: 4px;
}

/* System notice — inline divider for takeover/handback events. */
.cw-msg--system {
  align-self: center;
  align-items: center;
  max-width: 92%;
}
.cw-msg--system .cw-msg__bubble {
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-style: italic;
  padding: 0.35rem 0.7rem;
  text-align: center;
}

/* Typing indicator */
.cw-typing {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 0.7rem 0.85rem;
  background: var(--bg-3);
  border: 1px solid var(--rule);
  border-radius: 14px;
  border-top-left-radius: 4px;
}
.cw-typing__dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: cw-bounce 1.2s infinite;
}
.cw-typing__dot:nth-child(2) { animation-delay: 0.15s; }
.cw-typing__dot:nth-child(3) { animation-delay: 0.30s; }
@keyframes cw-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30%           { transform: translateY(-3px); opacity: 1; }
}

/* ---------- Suggestion chips ---------- */
.cw-suggest {
  display: flex; flex-wrap: wrap; gap: 0.4rem;
  margin-top: 0.4rem;
}
.cw-chip {
  background: var(--bg-3);
  border: 1px solid var(--rule-2);
  color: var(--ink-2);
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  font-size: 0.83rem;
  cursor: pointer;
  transition: all 180ms ease;
}
.cw-chip:hover {
  border-color: var(--accent);
  color: var(--ink);
  background: var(--accent-soft);
}

/* ---------- Live-handoff CTA ---------- */
.cw-handoff {
  margin: 0.4rem 0;
  padding: 0.85rem 0.95rem;
  background: linear-gradient(135deg, rgba(228,113,72,0.12), rgba(228,113,72,0.04));
  border: 1px solid rgba(228,113,72,0.4);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.75rem;
  animation: cw-in 320ms cubic-bezier(.2,.8,.2,1);
}
.cw-handoff__text {
  font-size: 0.86rem;
  color: var(--ink);
  line-height: 1.35;
}
.cw-handoff__text small {
  display: block;
  font-size: 0.74rem;
  color: var(--ink-2);
  margin-top: 0.15rem;
}
.cw-handoff__btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.6rem 0.9rem;
  background: var(--accent);
  color: var(--bg-deep);
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.85rem;
  white-space: nowrap;
  transition: all 200ms ease;
  border: 0;
  cursor: pointer;
}
.cw-handoff__btn:hover {
  background: var(--accent-2);
  transform: translateY(-1px);
  box-shadow: 0 8px 20px -8px var(--accent);
}

/* ---------- Footer / input ---------- */
.cw-foot {
  border-top: 1px solid var(--rule);
  padding: 0.75rem 0.85rem 0.85rem;
  /* Transparent — panel's warm-grey glass shows through. */
  background: transparent;
  flex-shrink: 0;
}
.cw-form {
  display: flex; align-items: flex-end; gap: 0.5rem;
  background: var(--bg-3);
  border: 1px solid var(--rule-2);
  border-radius: 12px;
  padding: 0.4rem 0.4rem 0.4rem 0.75rem;
  transition: border-color 180ms ease, box-shadow 180ms ease;
}
.cw-form:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.cw-input {
  flex: 1;
  background: transparent;
  border: 0;
  outline: 0;
  color: var(--ink);
  font-family: inherit;
  font-size: 0.94rem;
  line-height: 1.45;
  resize: none;
  padding: 0.45rem 0;
  max-height: 110px;
  min-height: 1.6rem;
}
.cw-input::placeholder { color: var(--muted-2); }

.cw-send {
  width: 34px; height: 34px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--bg-deep);
  border: 0;
  display: grid; place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 200ms cubic-bezier(.2,.8,.2,1);
}
.cw-send:hover:not(:disabled) {
  background: var(--accent);
  transform: translateY(-1px);
}
.cw-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.cw-tag {
  display: block;
  text-align: center;
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--muted-2);
  margin-top: 0.5rem;
  letter-spacing: 0.04em;
}
.cw-tag .accent { color: var(--accent); }

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .cw-msg, .cw-handoff { animation: none; }
  .cw-panel { transition: opacity 0.001ms ease; }
}
