/* Customer chat + voice widget. Each site sets the --cw-* tokens on .cw (or :root). */
.cw {
  --cw-primary: #1d3b33; --cw-on-primary: #fff; --cw-accent: #b08d57;
  --cw-surface: #fff; --cw-raised: #f4f4f6; --cw-ink: #1c1a24; --cw-muted: #5d5a66; --cw-line: #dcdae2;
  --cw-user: var(--cw-primary); --cw-on-user: var(--cw-on-primary); --cw-bot: var(--cw-raised);
  --cw-font: system-ui, sans-serif; --cw-radius: 18px; --cw-bubble: 16px; --cw-shadow: 0 24px 60px -20px rgba(20, 16, 30, .45);
  position: fixed; inset-inline-end: 24px; inset-block-end: 24px; z-index: 50;
  display: flex; flex-direction: column; align-items: flex-end; gap: 14px;
  font-family: var(--cw-font); color: var(--cw-ink); font-size: 15px; line-height: 1.45;
}
.cw *, .cw *::before, .cw *::after { box-sizing: border-box; }
.cw svg { width: 20px; height: 20px; flex: none; }
.cw :where(button) { font: inherit; color: inherit; cursor: pointer; }
.cw :focus-visible { outline: 2px solid var(--cw-accent); outline-offset: 2px; }
.cw [hidden] { display: none !important; }
.cw-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* launcher */
.cw-launcher {
  display: inline-flex; align-items: center; gap: 10px; border: 0; border-radius: 999px;
  padding: 14px 22px 14px 18px; background: var(--cw-primary); color: var(--cw-on-primary);
  font-weight: 600; letter-spacing: .01em; box-shadow: var(--cw-shadow);
  transition: transform .18s ease;
}
.cw-launcher:hover { transform: translateY(-2px); }
.cw.is-open .cw-launcher { padding: 14px; }
.cw.is-open .cw-launcher span { display: none; }

/* panel */
.cw-panel {
  width: min(400px, calc(100vw - 32px)); height: min(640px, calc(100vh - 120px));
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--cw-surface); border-radius: var(--cw-radius); box-shadow: var(--cw-shadow);
  border: 1px solid var(--cw-line);
  transform-origin: bottom right; animation: cw-in .22s cubic-bezier(.2, .8, .2, 1);
}
.cw[dir=rtl] .cw-panel { transform-origin: bottom left; }
@keyframes cw-in { from { opacity: 0; transform: translateY(12px) scale(.98); } }
.cw-head { display: flex; align-items: center; gap: 12px; padding: 16px 16px 12px 18px; background: var(--cw-primary); color: var(--cw-on-primary); }
.cw-avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--cw-accent); color: var(--cw-primary); font-weight: 700; font-size: 17px; flex: none; }
.cw-id { flex: 1; min-width: 0; }
.cw-id h2 { margin: 0; font-size: 16px; font-weight: 650; line-height: 1.2; }
.cw-status { margin: 2px 0 0; font-size: 13px; opacity: .82; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cw-status::before { content: ''; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #6fd39b; margin-inline-end: 6px; vertical-align: 1px; }
.cw-status[data-state=connecting]::before, .cw-status[data-state=transfer]::before { background: #f2c14e; }
.cw-status[data-state=ended]::before, .cw-status[data-state=error]::before { background: #c9c4cf; }
.cw-icon-btn { border: 0; background: transparent; color: inherit; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; }
.cw-icon-btn:hover { background: rgba(255, 255, 255, .14); }

.cw-tabs { display: flex; gap: 4px; padding: 0 14px; background: var(--cw-primary); }
.cw-tab { flex: 1; display: inline-flex; justify-content: center; align-items: center; gap: 8px; border: 0; background: transparent; color: var(--cw-on-primary); opacity: .7; padding: 10px 8px 12px; border-bottom: 2px solid transparent; font-weight: 600; font-size: 14px; }
.cw-tab[aria-selected=true] { opacity: 1; border-bottom-color: var(--cw-accent); }
.cw-tab svg { width: 18px; height: 18px; }

.cw-view { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* chat */
.cw-log { flex: 1; overflow-y: auto; padding: 18px 16px 8px; display: flex; flex-direction: column; gap: 8px; scroll-behavior: smooth; }
.cw-msg { max-width: 84%; padding: 10px 14px; border-radius: var(--cw-bubble); overflow-wrap: anywhere; }
.cw-bot { align-self: flex-start; background: var(--cw-bot); border-end-start-radius: 4px; }
.cw-user { align-self: flex-end; background: var(--cw-user); color: var(--cw-on-user); border-end-end-radius: 4px; }
.cw-sys { align-self: center; max-width: 92%; text-align: center; font-size: 13px; color: var(--cw-muted); padding: 6px 10px; }
.cw-msg a { color: inherit; }
.cw-typing { align-self: flex-start; display: inline-flex; gap: 4px; padding: 12px 14px; background: var(--cw-bot); border-radius: var(--cw-bubble); border-end-start-radius: 4px; }
.cw-typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--cw-muted); animation: cw-dot 1.2s infinite ease-in-out; }
.cw-typing i:nth-child(2) { animation-delay: .15s; } .cw-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes cw-dot { 0%, 60%, 100% { opacity: .3; transform: none; } 30% { opacity: 1; transform: translateY(-3px); } }
.cw-chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 4px 16px 10px; }
.cw-chips:empty { display: none; }
.cw-chip { border: 1px solid var(--cw-line); background: var(--cw-surface); border-radius: 999px; padding: 7px 13px; font-size: 13.5px; text-align: start; }
.cw-chip:hover { border-color: var(--cw-primary); }
.cw-after { padding: 8px 16px 16px; display: flex; justify-content: center; }
.cw-form { display: flex; align-items: flex-end; gap: 8px; margin: 0 12px 12px; padding: 6px 6px 6px 14px; border: 1px solid var(--cw-line); border-radius: 22px; background: var(--cw-surface); }
.cw-form:focus-within { border-color: var(--cw-primary); }
.cw-form textarea { flex: 1; border: 0; outline: 0; resize: none; font: inherit; color: inherit; background: transparent; padding: 7px 0; max-height: 120px; }
.cw-send { width: 38px; height: 38px; border: 0; border-radius: 50%; background: var(--cw-primary); color: var(--cw-on-primary); display: grid; place-items: center; flex: none; }
.cw-send:disabled { opacity: .4; cursor: default; }
.cw[dir=rtl] .cw-send svg { transform: scaleX(-1); }

/* buttons */
.cw-btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border-radius: 999px; padding: 11px 18px; font-weight: 600; border: 1px solid transparent; }
.cw-btn-primary { background: var(--cw-primary); color: var(--cw-on-primary); }
.cw-btn-ghost { background: transparent; border-color: var(--cw-line); }
.cw-btn-danger { background: #b3261e; color: #fff; }
.cw-btn-wide { min-width: 200px; }

/* call */
.cw-call { align-items: center; padding: 26px 20px 18px; text-align: center; }
.cw-orb-wrap { width: 132px; height: 132px; display: grid; place-items: center; margin-bottom: 14px; }
.cw-orb {
  --level: 0; width: 96px; height: 96px; border-radius: 50%; display: grid; place-items: center;
  background: var(--cw-raised); color: var(--cw-primary);
  box-shadow: 0 0 0 calc(var(--level) * 18px) color-mix(in srgb, var(--cw-accent) 35%, transparent);
  transition: box-shadow .08s linear, background .2s;
}
.cw-orb svg { width: 34px; height: 34px; }
.cw-call[data-state=live] .cw-orb, .cw-call[data-state=connecting] .cw-orb { background: var(--cw-primary); color: var(--cw-on-primary); }
.cw-orb.is-speaking { animation: cw-speak 1.4s ease-in-out infinite; }
@keyframes cw-speak { 50% { box-shadow: 0 0 0 14px color-mix(in srgb, var(--cw-primary) 18%, transparent); } }
.cw-call-state { margin: 0; font-weight: 600; font-size: 16px; max-width: 30ch; }
.cw-call-timer { margin: 4px 0 0; color: var(--cw-muted); font-variant-numeric: tabular-nums; min-height: 1.4em; }
.cw-call:not([data-state=live]) .cw-call-timer { visibility: hidden; }
.cw-captions { flex: 1; width: 100%; overflow-y: auto; margin: 16px 0; padding: 12px 14px; border-radius: 12px; background: var(--cw-raised); text-align: start; font-size: 14px; }
.cw-cap { margin: 0 0 8px; }
.cw-cap span { display: block; font-size: 12px; font-weight: 650; color: var(--cw-muted); }
.cw-cap-sys { color: var(--cw-muted); font-style: italic; }
.cw-cap-empty { margin: 0; color: var(--cw-muted); }
.cw-call-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

/* incoming call */
.cw-ring {
  display: flex; align-items: center; gap: 12px; width: min(400px, calc(100vw - 32px)); padding: 14px 14px 14px 16px;
  background: var(--cw-surface); border: 1px solid var(--cw-line); border-radius: var(--cw-radius); box-shadow: var(--cw-shadow);
  animation: cw-in .25s ease;
}
.cw-ring-icon { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: var(--cw-primary); color: var(--cw-on-primary); animation: cw-ring 1.6s ease-in-out infinite; flex: none; }
@keyframes cw-ring { 0%, 100% { transform: rotate(0); } 10%, 30% { transform: rotate(-12deg); } 20%, 40% { transform: rotate(12deg); } 50% { transform: rotate(0); } }
.cw-ring-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.cw-ring-sub { color: var(--cw-muted); font-size: 13px; }
.cw-ring .cw-btn { padding: 9px 14px; }

@media (max-width: 520px) {
  .cw { inset-inline-end: 12px; inset-block-end: 12px; }
  .cw.is-open { inset: 0; align-items: stretch; gap: 0; }
  .cw.is-open .cw-panel { width: 100%; height: 100%; border-radius: 0; border: 0; }
  .cw.is-open .cw-launcher { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .cw *, .cw *::before, .cw *::after { animation: none !important; transition: none !important; }
}

/* specialist (human rep) messages after handoff */
.cw-rep { align-self: flex-start; background: var(--cw-surface); border: 1.5px solid var(--cw-accent); border-end-start-radius: 4px; }
.cw-who { display: block; font-size: 12px; font-weight: 700; color: var(--cw-muted); margin-bottom: 2px; }
.cw-launcher.has-new::after { content: ''; position: absolute; top: 6px; inset-inline-end: 6px; width: 12px; height: 12px; border-radius: 50%; background: var(--cw-accent); border: 2px solid var(--cw-surface); }
.cw-launcher { position: relative; }

/* typing indicator with an optional passing status line ("Checking your order…") */
.cw-typing-wrap { align-self: flex-start; display: flex; flex-direction: column; gap: 4px; max-width: 84%; }
.cw-typing-wrap .cw-typing { align-self: flex-start; }
.cw-typing-status { font-size: 12.5px; color: var(--cw-muted); padding-inline-start: 4px; animation: cw-fade .25s ease; }
@keyframes cw-fade { from { opacity: 0; } }
