/* Live chat widget */
#chatw { --cw-primary: var(--primary, #7c3aed); --cw-primary2: var(--primary-2, #06b6d4); font-family: 'Inter', 'Cairo', system-ui, sans-serif; }
#chatw, #chatw * { box-sizing: border-box; }
#chatw .cw-fab {
  position: fixed; bottom: 22px; z-index: 1040; width: 60px; height: 60px; border: 0; border-radius: 50%; cursor: pointer;
  background: linear-gradient(135deg, var(--cw-primary), var(--cw-primary2)); color: #fff; font-size: 1.7rem;
  display: flex; align-items: center; justify-content: center; box-shadow: 0 10px 30px rgba(0,0,0,.45); transition: transform .2s;
}
#chatw[data-side="right"] .cw-fab, #chatw[data-side="right"] .cw-teaser, #chatw[data-side="right"] .cw-panel { right: 22px; }
#chatw[data-side="left"]  .cw-fab, #chatw[data-side="left"]  .cw-teaser, #chatw[data-side="left"]  .cw-panel { left: 22px; }
#chatw .cw-fab:hover { transform: scale(1.07); }
#chatw .cw-fab.cw-pulse::after { content: ''; position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--cw-primary2); animation: cw-ring 1.8s infinite; }
@keyframes cw-ring { 0% { transform: scale(1); opacity: .9; } 100% { transform: scale(1.6); opacity: 0; } }
#chatw .cw-badge {
  position: absolute; top: -3px; right: -3px; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 99px; background: #ef4444; color: #fff;
  font-size: .75rem; font-weight: 700; display: none; align-items: center; justify-content: center; border: 2px solid #0a0d18;
}
#chatw .cw-badge.on { display: flex; }

#chatw .cw-teaser {
  position: fixed; bottom: 94px; z-index: 1040; max-width: min(300px, calc(100vw - 44px)); background: #fff; color: #1b1f2e; border-radius: 16px;
  padding: 12px 34px 12px 14px; font-size: .9rem; line-height: 1.45; box-shadow: 0 12px 40px rgba(0,0,0,.45); cursor: pointer; display: none;
  animation: cw-pop .35s ease;
}
#chatw .cw-teaser.on { display: block; }
#chatw .cw-teaser b { display: block; font-size: .78rem; color: var(--cw-primary); margin-bottom: 2px; }
#chatw .cw-teaser .cw-x { position: absolute; top: 6px; right: 8px; border: 0; background: none; color: #8a90a2; font-size: 1.1rem; line-height: 1; cursor: pointer; padding: 2px 4px; }
#chatw[data-dir="rtl"] .cw-teaser { padding: 12px 14px 12px 34px; }
#chatw[data-dir="rtl"] .cw-teaser .cw-x { right: auto; left: 8px; }
@keyframes cw-pop { from { transform: translateY(8px) scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }

#chatw .cw-panel {
  position: fixed; bottom: 94px; z-index: 1041; width: 370px; max-width: calc(100vw - 24px); height: 540px; max-height: calc(100vh - 120px);
  background: #12172a; color: #e8ebf5; border: 1px solid rgba(255,255,255,.1); border-radius: 18px; box-shadow: 0 20px 60px rgba(0,0,0,.6);
  display: none; flex-direction: column; overflow: hidden;
}
#chatw .cw-panel.on { display: flex; animation: cw-pop .25s ease; }
#chatw .cw-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; background: linear-gradient(135deg, var(--cw-primary), var(--cw-primary2)); color: #fff; }
#chatw .cw-av { width: 38px; height: 38px; border-radius: 50%; background: rgba(255,255,255,.22); display: flex; align-items: center; justify-content: center; font-size: 1.2rem; flex-shrink: 0; }
#chatw .cw-ht { flex: 1; min-width: 0; }
#chatw .cw-ht strong { display: block; font-size: .98rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#chatw .cw-ht span { font-size: .78rem; opacity: .92; display: flex; align-items: center; gap: 6px; }
#chatw .cw-dot { width: 8px; height: 8px; border-radius: 50%; background: #9ca3af; display: inline-block; }
#chatw .cw-dot.on { background: #4ade80; box-shadow: 0 0 0 3px rgba(74,222,128,.25); }
#chatw .cw-close { border: 0; background: rgba(255,255,255,.18); color: #fff; width: 32px; height: 32px; border-radius: 50%; cursor: pointer; font-size: 1.1rem; line-height: 1; }
#chatw .cw-close:hover { background: rgba(255,255,255,.3); }

#chatw .cw-msgs { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; background: #0d1122; scroll-behavior: smooth; }
#chatw .cw-row { display: flex; flex-direction: column; max-width: 84%; }
#chatw .cw-row.me { align-self: flex-end; align-items: flex-end; }
#chatw .cw-row.them { align-self: flex-start; align-items: flex-start; }
#chatw .cw-who { font-size: .7rem; color: #8f98b3; margin: 0 6px 2px; }
#chatw .cw-b { padding: 9px 13px; border-radius: 16px; font-size: .92rem; line-height: 1.45; white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere; }
#chatw .cw-row.me .cw-b { background: linear-gradient(135deg, var(--cw-primary), color-mix(in srgb, var(--cw-primary) 60%, var(--cw-primary2))); color: #fff; border-end-end-radius: 4px; }
#chatw .cw-row.them .cw-b { background: #1c2340; color: #e8ebf5; border-end-start-radius: 4px; }
#chatw .cw-b a { color: inherit; text-decoration: underline; }
#chatw .cw-time { font-size: .66rem; color: #6f7893; margin: 2px 6px 0; }

#chatw .cw-event { align-self: center; max-width: 90%; text-align: center; font-size: .75rem; color: #9aa4c2; background: rgba(255,255,255,.06); padding: 4px 12px; border-radius: 99px; margin: 2px 0; }
#chatw .cw-tick { color: #7b84a3; font-size: .72rem; letter-spacing: -2px; }
#chatw .cw-tick.seen { color: #38bdf8; }
#chatw .cw-name { background: #161d38; border: 1px solid rgba(255,255,255,.08); border-radius: 14px; padding: 10px 12px; font-size: .85rem; }
#chatw .cw-name p { margin: 0 0 8px; color: #c8cee2; }
#chatw .cw-name .cw-nr { display: flex; gap: 6px; }
#chatw .cw-name input { flex: 1; min-width: 0; background: #0d1122; border: 1px solid rgba(255,255,255,.12); color: #fff; border-radius: 10px; padding: 7px 10px; font-size: .88rem; }
#chatw .cw-name input:focus, #chatw .cw-in textarea:focus { outline: 2px solid var(--cw-primary2); outline-offset: 0; }
#chatw .cw-btn { border: 0; border-radius: 10px; padding: 7px 12px; font-size: .82rem; font-weight: 600; cursor: pointer; background: linear-gradient(135deg, var(--cw-primary), var(--cw-primary2)); color: #fff; }
#chatw .cw-btn.ghost { background: transparent; color: #9aa4c2; border: 1px solid rgba(255,255,255,.12); }

#chatw .cw-in { display: flex; align-items: flex-end; gap: 8px; padding: 10px; border-top: 1px solid rgba(255,255,255,.08); background: #12172a; }
#chatw .cw-in textarea {
  flex: 1; resize: none; max-height: 110px; min-height: 42px; background: #0d1122; color: #fff; border: 1px solid rgba(255,255,255,.12);
  border-radius: 14px; padding: 10px 12px; font: inherit; font-size: .92rem; line-height: 1.35;
}
#chatw .cw-send { width: 42px; height: 42px; flex-shrink: 0; border: 0; border-radius: 50%; cursor: pointer; background: linear-gradient(135deg, var(--cw-primary), var(--cw-primary2)); color: #fff; font-size: 1.05rem; display: flex; align-items: center; justify-content: center; }
#chatw .cw-send:disabled { opacity: .5; cursor: default; }
#chatw[data-dir="rtl"] .cw-send i { transform: scaleX(-1); }
#chatw .cw-err { color: #fca5a5; font-size: .75rem; padding: 0 14px 6px; display: none; background: #12172a; }
#chatw .cw-err.on { display: block; }

@media (max-width: 575px) {
  #chatw .cw-panel { right: 12px !important; left: 12px !important; width: auto; bottom: 90px; height: min(560px, calc(100vh - 110px)); }
  #chatw .cw-fab { bottom: 16px; }
  #chatw[data-side="right"] .cw-fab, #chatw[data-side="right"] .cw-teaser { right: 16px; }
  #chatw[data-side="left"] .cw-fab, #chatw[data-side="left"] .cw-teaser { left: 16px; }
  #chatw .cw-teaser { bottom: 86px; }
}
@media (prefers-reduced-motion: reduce) { #chatw * { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }

/* ---- offline mode: banner + e-mail card ---- */
#chatw .cw-offbar { display: none; padding: 8px 14px; font-size: .78rem; line-height: 1.4; color: #f6d89a; background: rgba(245, 158, 11, .12); border-bottom: 1px solid rgba(245, 158, 11, .25); }
#chatw .cw-offbar.on { display: block; }
#chatw .cw-name.cw-off .cw-nr { flex-direction: column; }
#chatw .cw-name .cw-ph { display: flex; gap: 6px; width: 100%; }
#chatw .cw-name select { flex: 0 0 112px; min-width: 0; max-width: 40%; background: #0d1122; border: 1px solid rgba(255,255,255,.12); color: #fff; border-radius: 10px; padding: 7px 4px; font-size: .85rem; }
#chatw .cw-name select:focus { outline: 2px solid var(--cw-primary2); outline-offset: 0; }
#chatw .cw-name.cw-off .cw-btn { width: 100%; padding: 9px 12px; }
#chatw .cw-nerr { display: none; margin-top: 6px; font-size: .78rem; color: #ff8a8a; }
#chatw .cw-nerr.on { display: block; }

/* ---- quick questions (chips) + typing bubble ---- */
#chatw .cw-chips { margin-top: 6px; padding: 10px; border-radius: 14px; background: rgba(255,255,255,.035); border: 1px dashed rgba(255,255,255,.12); animation: cw-pop .25s ease; }
#chatw .cw-chips-t { font-size: .7rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: #8f98b3; margin: 0 2px 8px; }
#chatw .cw-chips-l { display: flex; flex-wrap: wrap; gap: 6px; }
#chatw .cw-chip {
  max-width: 100%; text-align: start; border: 1px solid color-mix(in srgb, var(--cw-primary2) 45%, transparent); background: transparent; color: #dfe4f5; border-radius: 99px;
  padding: 6px 12px; font: inherit; font-size: .82rem; line-height: 1.3; cursor: pointer; transition: background .15s, border-color .15s, color .15s;
}
#chatw .cw-chip:hover { background: color-mix(in srgb, var(--cw-primary2) 18%, transparent); border-color: var(--cw-primary2); color: #fff; }
#chatw .cw-chip:focus-visible { outline: 2px solid var(--cw-primary2); outline-offset: 1px; }
#chatw .cw-chip.agent { display: block; width: 100%; margin-top: 8px; padding: 9px 13px; border-radius: 12px; background: linear-gradient(135deg, var(--cw-primary), var(--cw-primary2)); border-color: transparent; color: #fff; font-weight: 600; text-align: center; }
#chatw .cw-chip.agent:hover { filter: brightness(1.1); }
#chatw .cw-dots { display: flex; align-items: center; gap: 4px; padding: 12px 14px; }
#chatw .cw-dots i { width: 7px; height: 7px; border-radius: 50%; background: #8f98b3; display: block; animation: cw-bounce 1.3s infinite; }
#chatw .cw-dots i:nth-child(2) { animation-delay: .18s; }
#chatw .cw-dots i:nth-child(3) { animation-delay: .36s; }
@keyframes cw-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-5px); opacity: 1; } }

/* v6: file messages, attach button, drag & drop */
#chatw .cw-attach { width: 38px; height: 42px; flex-shrink: 0; border: 0; background: transparent; color: #aeb6cf; font-size: 1.25rem; cursor: pointer; border-radius: 50%; }
#chatw .cw-attach:hover { color: #fff; }
#chatw .cw-attach:disabled { opacity: .5; cursor: default; }
#chatw .cw-b.has-file { padding: 6px; }
#chatw .cw-img img { display: block; max-width: 220px; max-height: 220px; border-radius: 12px; object-fit: cover; }
#chatw .cw-file { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none !important; padding: 6px 8px; }
#chatw .cw-file i { font-size: 1.7rem; }
#chatw .cw-file b { display: block; font-weight: 600; font-size: .88rem; word-break: break-all; }
#chatw .cw-file small { opacity: .75; }
#chatw .cw-cap { padding: 6px 8px 2px; white-space: pre-wrap; }
#chatw .cw-drop { display: none; position: absolute; inset: 0; z-index: 5; background: rgba(13,17,34,.93); border: 2px dashed var(--cw-primary2); color: #fff; align-items: center; justify-content: center; font-weight: 600; border-radius: inherit; }
#chatw .cw-panel.drag .cw-drop { display: flex; }

/* WhatsApp fallback (no answer after 5 minutes) */
#chatw .cw-wa { margin: 6px 4px; padding: 12px 14px; border-radius: 14px; background: rgba(37, 211, 102, .1); border: 1px solid rgba(37, 211, 102, .35); color: #e8ebf5; font-size: .88rem; line-height: 1.45; text-align: center; }
#chatw .cw-wa p { margin: 0 0 10px; }
#chatw .cw-wa-btn { display: inline-flex; align-items: center; gap: 6px; background: #25d366; color: #052e16 !important; font-weight: 700; padding: 8px 16px; border-radius: 999px; text-decoration: none !important; }
#chatw .cw-wa-btn:hover { filter: brightness(1.08); }
