#cw-root, #cw-root * {
  box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --cw-primary: #144A7C;
  --cw-secondary: #3BB99F;
  --cw-gradient: linear-gradient(135deg, var(--cw-primary) 0%, var(--cw-secondary) 100%);
}
#cw-root { position: fixed; bottom: 20px; right: 20px; z-index: 999999; }

#cw-bubble {
  width: 58px; height: 58px; border-radius: 50%;
  background: var(--cw-gradient); color: #fff; border: none; cursor: pointer;
  box-shadow: 0 6px 18px rgba(20,74,124,0.35);
  display: flex; align-items: center; justify-content: center;
  position: relative;
}
#cw-bubble svg { width: 26px; height: 26px; }
#cw-badge {
  position: absolute; top: -4px; right: -4px;
  background: #ff4b4b; color: #fff; border-radius: 999px;
  font-size: 11px; min-width: 18px; height: 18px; padding: 0 4px;
  display: none; align-items: center; justify-content: center;
}

#cw-panel {
  display: none;
  position: absolute; bottom: 72px; right: 0;
  width: 340px; max-width: calc(100vw - 40px);
  height: 460px; max-height: 70vh;
  background: #fff; border-radius: 14px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.18);
  overflow: hidden; flex-direction: column;
}
#cw-panel.open { display: flex; }

#cw-header {
  background: var(--cw-gradient); color: #fff; padding: 14px 16px;
  display: flex; align-items: center; justify-content: space-between;
}
#cw-header .cw-title { font-weight: 600; font-size: 0.95rem; }
#cw-header .cw-sub { font-size: 0.72rem; opacity: 0.85; }
#cw-header-actions { display: flex; align-items: center; gap: 10px; }
#cw-newchat, #cw-close, #cw-faq-toggle { background: none; border: none; color: #fff; cursor: pointer; line-height: 1; }
#cw-newchat { font-size: 1rem; opacity: 0.9; }
#cw-newchat:hover { opacity: 1; }
#cw-close { font-size: 1.1rem; }
#cw-faq-toggle {
  width: 20px; height: 20px; border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,0.65);
  font-size: 0.78rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  opacity: 0.9; padding: 0;
}
#cw-faq-toggle:hover { opacity: 1; border-color: #fff; }

#cw-body { flex: 1; overflow-y: auto; padding: 12px 14px; background: #f7f7fb; }

#cw-prechat { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
#cw-prechat p { margin: 0 0 4px; font-size: 0.85rem; color: #555; }
#cw-prechat input {
  padding: 9px 10px; border: 1px solid #dcdde5; border-radius: 8px; font-size: 0.88rem;
}
#cw-prechat button {
  padding: 10px; background: var(--cw-gradient); color: #fff; border: none; border-radius: 8px;
  font-size: 0.9rem; cursor: pointer;
}
#cw-prechat button:disabled { opacity: 0.7; cursor: default; }
.cw-prechat-error {
  display: none; margin: -4px 0 0; font-size: 0.78rem; color: #c0392b; line-height: 1.35;
}
.cw-prechat-error.show { display: block; }

.cw-msg { max-width: 80%; margin-bottom: 8px; padding: 8px 11px; border-radius: 10px; font-size: 0.86rem; line-height: 1.35; white-space: pre-wrap; word-wrap: break-word; }
.cw-msg-visitor { margin-left: auto; background: var(--cw-gradient); color: #fff; }
.cw-msg-admin { margin-right: auto; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.08); color: #222; }

#cw-quick-replies {
  max-height: 0; overflow: hidden;
  border-top: 1px solid #eceef3; background: #fbfbfd;
  transition: max-height 0.2s ease;
  flex-shrink: 0;
}
#cw-quick-replies.open { max-height: 160px; overflow-y: auto; padding: 10px 10px 4px; }
.cw-qr-chip {
  display: inline-block; margin: 0 6px 6px 0;
  padding: 7px 12px; border-radius: 999px;
  border: 1px solid var(--cw-primary); background: #fff; color: var(--cw-primary);
  font-size: 0.78rem; cursor: pointer; text-align: left;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.cw-qr-chip:hover { background: var(--cw-gradient); color: #fff; border-color: transparent; }

.cw-followup { display: flex; flex-wrap: wrap; margin: 2px 0 10px; }
.cw-followup .cw-qr-chip { font-size: 0.74rem; padding: 6px 11px; }

#cw-input-row { display: none; border-top: 1px solid #eceef3; padding: 10px; gap: 8px; }
#cw-input-row.show { display: flex; }
#cw-input { flex: 1; resize: none; border: 1px solid #dcdde5; border-radius: 8px; padding: 8px 10px; font-size: 0.86rem; height: 40px; }
#cw-send { background: var(--cw-gradient); color: #fff; border: none; border-radius: 8px; padding: 0 14px; cursor: pointer; font-size: 0.86rem; }

@media (max-width: 420px) {
  #cw-panel { width: calc(100vw - 24px); right: -8px; }
}

#cw-confirm-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(20,24,35,0.45);
  align-items: center; justify-content: center;
  z-index: 1000000;
}
#cw-confirm-overlay.show { display: flex; }
#cw-confirm-box {
  background: #fff; border-radius: 12px; padding: 20px;
  width: 280px; max-width: calc(100vw - 48px);
  box-shadow: 0 12px 32px rgba(0,0,0,0.25);
  text-align: center;
}
#cw-confirm-text { margin: 0 0 16px; font-size: 0.88rem; color: #333; line-height: 1.4; }
#cw-confirm-actions { display: flex; gap: 10px; }
#cw-confirm-actions button {
  flex: 1; padding: 9px 0; border-radius: 8px; font-size: 0.85rem;
  cursor: pointer; border: none;
}
#cw-confirm-cancel { background: #eef0f4; color: #444; }
#cw-confirm-ok { background: var(--cw-gradient); color: #fff; }
