/* Chat widget (visitor) — bottom-left for RTL, matches the light/violet site style */
.chw { --chw-accent: var(--accent, #263C37); --chw-ink: var(--ink, #15131C); --chw-paper: var(--paper, #FFFCF7); --chw-bg: var(--bg, #F3F0EA); --chw-muted: var(--muted, #5C5866); --chw-gold: var(--gold, #B8964F);
  position: fixed; z-index: 90; left: calc(1.25rem + env(safe-area-inset-left)); bottom: calc(1.25rem + env(safe-area-inset-bottom));
  font-family: Vazirmatn, Tahoma, sans-serif; color: var(--chw-ink); line-height: 1.7; }
.chw *, .chw *::before, .chw *::after { box-sizing: border-box; }
.chw [hidden] { display: none !important; }

.chw-launcher { position: relative; width: 3.75rem; height: 3.75rem; border-radius: 50%; border: 1.5px solid var(--chw-ink); background: var(--chw-accent); color: #fff;
  display: grid; place-items: center; cursor: pointer; box-shadow: 4px 4px 0 var(--chw-gold); transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.25s, background 0.2s; padding: 0; }
.chw-launcher:hover { transform: translate(-2px, -2px); box-shadow: 6px 6px 0 var(--chw-gold); background: var(--accent-hover, #1A2B27); }
.chw-launcher:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--chw-gold); }
.chw-launcher:focus-visible { outline: 3px solid var(--chw-accent); outline-offset: 4px; }
.chw-ico { grid-area: 1 / 1; display: grid; place-items: center; transition: opacity 0.2s, transform 0.25s; }
.chw-ico--close { opacity: 0; transform: rotate(-60deg) scale(0.6); }
.chw.is-open .chw-ico--chat { opacity: 0; transform: rotate(60deg) scale(0.6); }
.chw.is-open .chw-ico--close { opacity: 1; transform: none; }
.chw-dot { position: absolute; top: 0.15rem; right: 0.15rem; width: 0.85rem; height: 0.85rem; border-radius: 50%; border: 2px solid var(--chw-paper); background: #a29fab; }
.chw.is-online .chw-dot { background: #22c55e; }
.chw-badge { position: absolute; top: -0.45rem; left: -0.35rem; min-width: 1.45rem; height: 1.45rem; padding: 0 0.35rem; border-radius: 999px; background: #e5484d; color: #fff;
  font-size: 0.78rem; font-weight: 700; display: grid; place-items: center; border: 2px solid var(--chw-paper); animation: chw-pop 0.35s cubic-bezier(0.22, 1, 0.36, 1); }
@keyframes chw-pop { from { transform: scale(0.3); } to { transform: none; } }

.chw-panel { position: absolute; left: 0; bottom: calc(100% + 1rem); width: min(23.5rem, calc(100vw - 2.5rem)); height: min(36rem, calc(100dvh - 7.5rem));
  display: flex; flex-direction: column; background: var(--chw-paper); border: 1.5px solid var(--chw-ink); border-radius: 1.4rem; box-shadow: 6px 6px 0 var(--tint, #C9D4C7);
  overflow: hidden; transform-origin: bottom left; animation: chw-in 0.3s cubic-bezier(0.22, 1, 0.36, 1); }
@keyframes chw-in { from { opacity: 0; transform: translateY(12px) scale(0.96); } to { opacity: 1; transform: none; } }

.chw-head { display: flex; align-items: center; gap: 0.7rem; padding: 0.85rem 1rem; background: var(--chw-accent); color: #fff; border-bottom: 1.5px solid var(--chw-ink); }
.chw-avatar { position: relative; flex: none; width: 2.5rem; height: 2.5rem; border-radius: 0.8rem; background: #fff; color: var(--chw-accent); display: grid; place-items: center; font-weight: 800; font-size: 1.15rem; border: 1.5px solid var(--chw-ink); }
.chw-avatar::after { content: ""; position: absolute; bottom: -0.2rem; left: -0.2rem; width: 0.75rem; height: 0.75rem; border-radius: 50%; background: #a29fab; border: 2px solid var(--chw-accent); }
.chw.is-online .chw-avatar::after { background: #22c55e; }
.chw-head-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chw-title { font-size: 1rem; }
.chw-status { font-size: 0.78rem; opacity: 0.88; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chw-close { flex: none; width: 2.3rem; height: 2.3rem; border-radius: 50%; border: 1.5px solid rgba(255, 255, 255, 0.55); background: transparent; color: #fff; display: grid; place-items: center; cursor: pointer; padding: 0; }
.chw-close:hover { background: rgba(255, 255, 255, 0.15); }

.chw-body { flex: 1; overflow-y: auto; padding: 1rem; background: var(--chw-bg); overscroll-behavior: contain; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; gap: 0.55rem; }
.chw-thread { display: flex; flex-direction: column; gap: 0.55rem; }
.chw-msg { max-width: 84%; display: flex; flex-direction: column; }
.chw-msg--them { align-self: flex-start; }
.chw-msg--me { align-self: flex-end; align-items: flex-end; }
.chw-bubble { white-space: pre-wrap; overflow-wrap: anywhere; padding: 0.55rem 0.9rem; border-radius: 1.1rem; font-size: 0.95rem; background: var(--chw-paper); border: 1.5px solid var(--chw-ink); }
.chw-msg--them .chw-bubble { border-start-start-radius: 0.3rem; }
.chw-msg--me .chw-bubble { background: var(--chw-accent); border-color: var(--chw-accent); color: #fff; border-start-end-radius: 0.3rem; }
.chw-intro .chw-bubble { background: var(--accent-soft, #E3E9E1); border-color: var(--accent-mid, #3F5E55); }
.chw-msg.is-pending { opacity: 0.6; }
.chw-time { font-size: 0.7rem; color: var(--chw-muted); margin-top: 0.1rem; padding-inline: 0.3rem; }

.chw-form { flex: none; border-top: 1.5px solid var(--chw-ink); background: var(--chw-paper); padding: 0.7rem 0.75rem calc(0.7rem + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 0.5rem; }
.chw-contact { display: grid; grid-template-columns: 1fr 1fr; gap: 0.45rem; }
.chw-note { grid-column: 1 / -1; margin: 0; font-size: 0.78rem; color: var(--chw-muted); line-height: 1.6; }
.chw-input, .chw-text { width: 100%; font: inherit; font-size: 16px; /* ≥16px: no iOS zoom */ color: var(--chw-ink); background: #fff; border: 1.5px solid rgba(21, 19, 28, 0.18); border-radius: 0.8rem; padding: 0.5rem 0.75rem; margin: 0; }
.chw-input { font-size: 15px; }
@supports (-webkit-touch-callout: none) { .chw-input { font-size: 16px; } }
.chw-input:focus, .chw-text:focus { outline: none; border-color: var(--chw-accent); box-shadow: 0 0 0 3px rgba(38, 60, 55, 0.2); }
.chw-compose { display: flex; align-items: flex-end; gap: 0.5rem; }
.chw-text { flex: 1; resize: none; min-height: 2.75rem; max-height: 140px; line-height: 1.6; display: block; }
.chw-send { flex: none; width: 2.75rem; height: 2.75rem; border-radius: 50%; border: 1.5px solid var(--chw-ink); background: var(--chw-accent); color: #fff; display: grid; place-items: center; cursor: pointer; padding: 0; transition: transform 0.15s; }
.chw-send:hover { transform: scale(1.06); }
.chw-send:disabled { opacity: 0.55; cursor: progress; }
.chw-hp { position: absolute !important; left: -9999px !important; width: 1px; height: 1px; opacity: 0; }
.chw-error { margin: 0; font-size: 0.82rem; color: #c53030; }
.chw-counter { font-size: 0.72rem; color: var(--chw-muted); align-self: flex-end; }

body.menu-open .chw { display: none; }

/* Mobile: full-screen sheet, iOS-safe (visualViewport sets --chw-vh / --chw-top) */
@media (max-width: 600px) {
  .chw { left: calc(1rem + env(safe-area-inset-left)); bottom: calc(1rem + env(safe-area-inset-bottom)); }
  .chw-launcher { width: 3.4rem; height: 3.4rem; box-shadow: 3px 3px 0 var(--chw-gold); }
  .chw-panel { position: fixed; left: 0; right: 0; top: var(--chw-top, 0); bottom: auto; width: 100%; height: var(--chw-vh, 100dvh); max-height: none;
    border: 0; border-radius: 0; box-shadow: none; animation: chw-up 0.3s cubic-bezier(0.22, 1, 0.36, 1); }
  .chw-head { padding-top: calc(0.85rem + env(safe-area-inset-top)); }
  .chw.is-open .chw-launcher { display: none; }
  .chw-contact { grid-template-columns: 1fr; }
  @keyframes chw-up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
}
html.chw-lock, html.chw-lock body { overflow: hidden; }
@media (prefers-reduced-motion: reduce) { .chw-panel, .chw-badge { animation: none; } .chw-launcher, .chw-ico { transition: none; } }
@media print { .chw { display: none; } }
