/* ============================================================
   ЧАТ-ВИДЖЕТ — self-contained, portable to other sites.
   Root tokens below are aliases onto this site's css/tokens.css
   (--cw-accent → --accent, etc). To reuse the widget elsewhere,
   copy this file + the HTML block + the <script> and either keep
   these aliases pointed at that site's tokens, or replace the
   :root block with literal values.
   ============================================================ */
:root {
  --cw-accent: var(--accent);
  --cw-bg: var(--bg-raised);
  --cw-bg-panel: var(--bg);
  --cw-border: var(--border);
  --cw-text: var(--text-dim);
  --cw-text-dim: var(--text-xs);
}

#cw-launcher {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--cw-accent);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(224, 25, 107, 0.35);
  z-index: 9998;
  transition: transform 0.2s ease;
}
#cw-launcher:hover { transform: scale(1.06); }
#cw-launcher svg { width: 26px; height: 26px; fill: #fff; }

#cw-panel {
  position: fixed;
  bottom: 92px;
  right: 24px;
  width: 340px;
  max-width: calc(100vw - 32px);
  height: 460px;
  max-height: calc(100vh - 140px);
  background: var(--cw-bg-panel);
  border: 1px solid var(--cw-border);
  border-radius: 12px;
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 9999;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
  font-family: inherit;
}
#cw-panel.cw-open { display: flex; }

#cw-header {
  padding: 14px 16px;
  background: var(--cw-bg);
  border-bottom: 1px solid var(--cw-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
#cw-header-title { color: var(--cw-text); font-size: 14px; font-weight: 600; }
#cw-header-sub { color: var(--cw-text-dim); font-size: 12px; margin-top: 2px; }
#cw-close { background: none; border: none; color: var(--cw-text-dim); cursor: pointer; font-size: 18px; line-height: 1; padding: 4px; }
#cw-close:hover { color: var(--cw-text); }

#cw-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.cw-msg { max-width: 85%; padding: 10px 13px; border-radius: 10px; font-size: 13.5px; line-height: 1.45; }
.cw-msg-bot { align-self: flex-start; background: var(--cw-bg); color: var(--cw-text); border: 1px solid var(--cw-border); }
.cw-msg-bot a { color: var(--cw-accent); text-decoration: underline; word-break: break-all; }
.cw-msg-bot a:hover { opacity: 0.85; }
.cw-msg-user { align-self: flex-end; background: var(--cw-accent); color: #fff; }
.cw-msg-typing { align-self: flex-start; color: var(--cw-text-dim); font-size: 13px; font-style: italic; }

#cw-input-row {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--cw-border);
  background: var(--cw-bg);
}
#cw-input {
  flex: 1;
  background: var(--cw-bg-panel);
  border: 1px solid var(--cw-border);
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--cw-text);
  font-size: 13.5px;
  outline: none;
}
#cw-input:focus { border-color: var(--cw-accent); }
#cw-send {
  background: var(--cw-accent);
  border: none;
  border-radius: 8px;
  width: 38px;
  color: #fff;
  cursor: pointer;
  font-size: 15px;
}
#cw-send:disabled { opacity: 0.5; cursor: default; }

/* Mobile: the small floating panel doesn't work well on a phone screen
   (cramped, and the on-screen keyboard can cover the input) — go
   near-full-screen instead, like most mobile chat widgets.

   `top`/`height` here are a CSS-only fallback (16px margin, matching
   the JS-driven sizing below) for browsers without window.visualViewport.
   Everywhere that matters, js/index.html's syncPanelToVisualViewport()
   overrides these as inline styles, pinned to the actual visible
   viewport — plain `dvh` alone isn't reliable enough against real
   on-screen keyboards (confirmed on real Android/Chrome: the header
   ended up scrolled out of view under the keyboard). */
@media (max-width: 640px) {
  #cw-panel {
    top: 16px;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    height: auto;
    max-height: calc(100dvh - 16px);
    border-radius: 16px 16px 0 0;
    border: none;
    border-top: 1px solid var(--cw-border);
  }
  #cw-header { padding-top: max(14px, env(safe-area-inset-top)); }
  #cw-input-row { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
}
