/* ==========================================================================
   ChatWidget styles
   Theme per-client by setting --cw-accent (done automatically from config),
   or override any variable below on .cw-root for a specific instance.
   ========================================================================== */

.cw-root {
  --cw-accent: #4A6CF7;
  --cw-bg: #EEF0F4;
  --cw-panel: #FFFFFF;
  --cw-bot-bubble: #E4E6EB;
  --cw-bot-text: #1C1E21;
  --cw-user-text: #FFFFFF;
  --cw-time: #8A8D91;
  --cw-exit-bg: #C0392B;
  --cw-exit-text: #FFFFFF;
  --cw-radius: 16px;
  --cw-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  font-family: var(--cw-font);
  box-sizing: border-box;
}
.cw-root *, .cw-root *::before, .cw-root *::after {
  box-sizing: inherit;
}

.cw-window {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 480px;
  max-height: 720px;
  background: var(--cw-bg);
  border-radius: var(--cw-radius);
  overflow: hidden;
  border: 1px solid rgba(0,0,0,0.06);
}

/* -------------------------------------------------------------------- header */
.cw-header {
  padding: 22px 20px 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  position: relative;
}

.cw-header-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: #6b6f76;
}

.cw-lang-toggle {
  border: 1.5px solid #d0d3d8;
  background: transparent;
  color: #6b6f76;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  border-radius: 20px;
  padding: 4px 10px;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}
.cw-lang-toggle:hover {
  border-color: var(--cw-accent);
  color: var(--cw-accent);
}
.cw-lang-toggle.cw-active {
  background: var(--cw-accent);
  border-color: var(--cw-accent);
  color: #fff;
}

.cw-header-toggles {
  position: absolute;
  right: 20px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.cw-voice-toggle {
  border: 1.5px solid #d0d3d8;
  background: transparent;
  color: #9aa0a6;
  border-radius: 50%;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}
.cw-voice-toggle svg {
  width: 14px;
  height: 14px;
}
.cw-voice-toggle:hover {
  border-color: var(--cw-accent);
  color: var(--cw-accent);
}
.cw-voice-toggle.cw-active {
  background: var(--cw-accent);
  border-color: var(--cw-accent);
  color: #fff;
}

/* ---------------------------------------------------------------- messages */
.cw-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 20px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.cw-row {
  display: flex;
  width: 100%;
}
.cw-row-bot { justify-content: flex-start; }
.cw-row-user { justify-content: flex-end; }

.cw-bubble {
  max-width: 78%;
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.4;
  position: relative;
  animation: cw-pop 160ms ease-out;
}

@keyframes cw-pop {
  from { opacity: 0; transform: translateY(4px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.cw-bubble-bot {
  background: var(--cw-bot-bubble);
  color: var(--cw-bot-text);
  border-bottom-left-radius: 4px;
}

.cw-bubble-user {
  background: var(--cw-accent);
  color: var(--cw-user-text);
  border-bottom-right-radius: 4px;
}

.cw-text {
  white-space: pre-wrap;
  word-break: break-word;
}

.cw-time {
  margin-top: 4px;
  font-size: 11px;
  color: var(--cw-time);
}
.cw-bubble-user .cw-time {
  color: rgba(255,255,255,0.75);
}

/* ------------------------------------------------------------------ typing */
.cw-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 14px 16px;
}
.cw-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cw-time);
  display: inline-block;
  animation: cw-bounce 1.1s infinite ease-in-out;
}
.cw-typing span:nth-child(2) { animation-delay: 0.15s; }
.cw-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes cw-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ----------------------------------------------------------------- composer */
.cw-composer {
  padding: 10px 16px 14px;
  background: var(--cw-bg);
}

.cw-inputwrap {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  background: var(--cw-panel);
  border: 1.5px solid transparent;
  border-radius: 22px;
  padding: 6px 8px 6px 16px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  transition: border-color 120ms ease;
}
.cw-inputwrap:focus-within {
  border-color: var(--cw-accent);
}

.cw-input {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  font: inherit;
  font-size: 15px;
  line-height: 1.4;
  max-height: 120px;
  padding: 8px 0;
  color: var(--cw-bot-text);
  font-family: var(--cw-font);
}
.cw-input::placeholder {
  color: #9AA0A6;
}

.cw-icon-btn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: #55585C;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, transform 80ms ease;
}
.cw-icon-btn svg {
  width: 18px;
  height: 18px;
}
.cw-icon-btn:hover {
  background: rgba(0,0,0,0.06);
}
.cw-icon-btn:active {
  transform: scale(0.92);
}
.cw-icon-btn:focus-visible {
  outline: 2px solid var(--cw-accent);
  outline-offset: 2px;
}

.cw-send {
  background: #E4E6EB;
  color: var(--cw-accent);
}
.cw-send.cw-send-active {
  background: var(--cw-accent);
  color: #fff;
}
.cw-send.cw-send-active:hover {
  filter: brightness(1.08);
}

.cw-mic.cw-listening {
  background: #34A853;
  color: #fff;
  animation: cw-pulse 1s infinite;
}
@keyframes cw-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(52, 168, 83, 0.45); }
  70%  { box-shadow: 0 0 0 8px rgba(52, 168, 83, 0); }
  100% { box-shadow: 0 0 0 0 rgba(52, 168, 83, 0); }
}

.cw-mode.cw-active {
  background: rgba(0,0,0,0.08);
  color: var(--cw-accent);
}

/* -------------------------------------------------------------------- exit */
.cw-exit {
  border: none;
  background: var(--cw-exit-bg);
  color: var(--cw-exit-text);
  padding: 14px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: filter 120ms ease;
}
.cw-exit:hover {
  filter: brightness(1.08);
}
.cw-exit:focus-visible {
  outline: 2px solid #fff;
  outline-offset: -4px;
}

/* -------------------------------------------------------------- responsive */
@media (max-width: 480px) {
  .cw-window {
    min-height: 100vh;
    min-height: 100dvh; /* dvh accounts for mobile browser chrome (address bar); vh above is a fallback for older browsers */
    max-height: 100vh;
    max-height: 100dvh;
    border-radius: 0;
  }
  .cw-bubble {
    max-width: 86%;
  }
}

/* -------------------------------------------------------- reduced motion */
@media (prefers-reduced-motion: reduce) {
  .cw-bubble, .cw-mic.cw-listening, .cw-typing span {
    animation: none;
  }
}
