#tw-chat-root { all: initial; }
.tw-chat-bubble {
  position: fixed;
  width: 60px; height: 60px;
  border-radius: 50%;
  background: var(--tw-primary, #9E181B);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(0,0,0,.25);
  z-index: 99999;
  transition: transform .15s ease;
  font-family: system-ui, -apple-system, sans-serif;
}
.tw-chat-bubble:hover { transform: scale(1.05); }
.tw-chat-bubble svg { width: 28px; height: 28px; }
.tw-chat-bubble .tw-unread {
  position: absolute; top: -4px; right: -4px;
  background: #e53935; color: #fff; border-radius: 999px;
  font-size: 11px; font-weight: 700; padding: 2px 6px; min-width: 18px; text-align: center;
}
.tw-chat-panel {
  position: fixed;
  width: 360px; max-width: calc(100vw - 24px);
  height: 520px; max-height: calc(100vh - 100px);
  background: #fff; border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0,0,0,.25);
  display: flex; flex-direction: column; overflow: hidden;
  z-index: 99999; font-family: system-ui, -apple-system, sans-serif;
  border: 1px solid rgba(0,0,0,.08);
}
.tw-chat-header {
  padding: 14px 16px; color: #fff; font-weight: 600;
  background: var(--tw-primary, #9E181B);
  display: flex; align-items: center; justify-content: space-between;
}
.tw-chat-header .tw-close { cursor: pointer; font-size: 20px; line-height: 1; opacity: .85; }
.tw-chat-body { flex: 1; overflow-y: auto; padding: 12px; background: var(--tw-secondary, #F2F2F2); }
.tw-chat-msg { margin-bottom: 10px; display: flex; }
.tw-chat-msg.visitor { justify-content: flex-end; }
.tw-chat-msg.agent { justify-content: flex-start; }
.tw-chat-msg.system { justify-content: center; }
.tw-chat-bubble-msg {
  max-width: 78%; padding: 8px 12px; border-radius: 14px;
  font-size: 14px; line-height: 1.4; word-wrap: break-word;
  background: #fff; color: var(--tw-text, #1a1a1a);
}
.tw-chat-msg.visitor .tw-chat-bubble-msg { background: var(--tw-primary, #9E181B); color: #fff; }
.tw-chat-msg.system .tw-chat-bubble-msg { background: transparent; color: #666; font-style: italic; font-size: 12px; }
.tw-chat-msg-meta { font-size: 10px; color: #888; margin-top: 2px; }
.tw-chat-footer { padding: 10px; border-top: 1px solid rgba(0,0,0,.08); background: #fff; }
.tw-chat-input { display: flex; gap: 8px; }
.tw-chat-input textarea { flex: 1; resize: none; border: 1px solid #ddd; border-radius: 10px; padding: 8px; font-size: 14px; font-family: inherit; }
.tw-chat-input button { background: var(--tw-primary, #9E181B); color: #fff; border: none; border-radius: 10px; padding: 0 14px; cursor: pointer; font-weight: 600; }
.tw-chat-prechat { padding: 16px; }
.tw-chat-prechat h3 { margin: 0 0 10px; font-size: 16px; }
.tw-chat-prechat label { display: block; margin-bottom: 8px; font-size: 13px; }
.tw-chat-prechat input { width: 100%; padding: 8px; border: 1px solid #ddd; border-radius: 8px; box-sizing: border-box; }
.tw-chat-prechat button { margin-top: 10px; width: 100%; padding: 10px; background: var(--tw-primary, #9E181B); color: #fff; border: none; border-radius: 10px; cursor: pointer; font-weight: 600; }
.tw-chat-offline { padding: 20px; text-align: center; color: #666; }
.tw-chat-hidden { display: none !important; }

/* Spinner */
.tw-spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  vertical-align: middle;
  margin-right: 6px;
  animation: tw-spin 0.8s linear infinite;
}
@keyframes tw-spin { to { transform: rotate(360deg); } }
.tw-chat-prechat button:disabled { opacity: .7; cursor: default; }

/* Typing indicator (3 dots) */
.tw-typing .tw-chat-bubble-msg { display: inline-flex; gap: 4px; align-items: center; padding: 10px 14px; }
.tw-dot { width: 7px; height: 7px; border-radius: 50%; background: #888; display: inline-block; animation: tw-bounce 1.2s infinite ease-in-out; }
.tw-dot:nth-child(2) { animation-delay: 0.2s; }
.tw-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes tw-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .4; }
  30% { transform: translateY(-5px); opacity: 1; }
}
.tw-chat-msg.visitor.tw-typing .tw-dot { background: #fff; }

/* Mobile */
@media (max-width: 600px) {
  .tw-chat-panel {
    width: 100vw; height: 100vh; max-width: 100vw; max-height: 100vh;
    bottom: 0 !important; right: 0 !important; left: 0 !important; top: 0 !important;
    border-radius: 0;
  }
  .tw-chat-bubble { width: 56px; height: 56px; }
}