/* ============================================
   Top Web Telecom — Widget Conversacional
   styles.css v1.0.0
   Prefixo: .tw- (isolamento total)
   Mobile-first
   ============================================ */

/* ---- Reset & Variables ---- */
.tw-widget-root,
.tw-widget-root *,
.tw-widget-root *::before,
.tw-widget-root *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.tw-widget-root {
  --tw-primary: #00b956;
  --tw-primary-dark: #009645;
  --tw-primary-light: #e6f9ef;
  --tw-secondary: #075e54;
  --tw-bg-chat: #e5ddd5;
  --tw-bg-header: #075e54;
  --tw-bg-bubble-bot: #ffffff;
  --tw-bg-bubble-user: #dcf8c6;
  --tw-bg-modal: #ffffff;
  --tw-text-primary: #111b21;
  --tw-text-secondary: #667781;
  --tw-text-light: #ffffff;
  --tw-border: #e0e0e0;
  --tw-shadow: 0 2px 16px rgba(0, 0, 0, 0.15);
  --tw-shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.25);
  --tw-radius: 12px;
  --tw-radius-sm: 8px;
  --tw-font: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --tw-z-launcher: 999998;
  --tw-z-modal: 999999;
  --tw-z-overlay: 999997;
  --tw-safe-bottom: env(safe-area-inset-bottom, 0px);
  --tw-safe-top: env(safe-area-inset-top, 0px);

  font-family: var(--tw-font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--tw-text-primary);
}

/* ---- Launcher Button ---- */
.tw-launcher {
  position: fixed;
  bottom: calc(20px + var(--tw-safe-bottom));
  right: 20px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--tw-primary);
  border: none;
  cursor: pointer;
  z-index: var(--tw-z-launcher);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--tw-shadow-lg);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
              background-color 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}

.tw-launcher:hover {
  transform: scale(1.08);
  background: var(--tw-primary-dark);
}

.tw-launcher:active {
  transform: scale(0.95);
}

.tw-launcher:focus-visible {
  outline: 3px solid var(--tw-primary);
  outline-offset: 3px;
}

.tw-launcher__icon {
  width: 32px;
  height: 32px;
  fill: #ffffff;
  transition: transform 0.3s ease;
}

.tw-launcher--open .tw-launcher__icon--chat {
  display: none;
}
.tw-launcher--open .tw-launcher__icon--close {
  display: block;
}
.tw-launcher:not(.tw-launcher--open) .tw-launcher__icon--close {
  display: none;
}

/* Pulse animation */
.tw-launcher::after {
  content: '';
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--tw-primary);
  opacity: 0;
  animation: tw-pulse 2s ease-out infinite;
}

.tw-launcher--open::after {
  animation: none;
  opacity: 0;
}

@keyframes tw-pulse {
  0% { transform: scale(1); opacity: 0.4; }
  100% { transform: scale(1.6); opacity: 0; }
}

/* Badge */
.tw-launcher__badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ff4444;
  color: white;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid white;
}

/* ---- Overlay ---- */
.tw-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: var(--tw-z-overlay);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

.tw-overlay--visible {
  opacity: 1;
  visibility: visible;
}

/* Desktop: no overlay */
@media (min-width: 769px) {
  .tw-overlay { display: none; }
}

/* ---- Modal ---- */
.tw-modal {
  position: fixed;
  z-index: var(--tw-z-modal);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* Mobile: fullscreen */
  inset: 0;
  border-radius: 0;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.tw-modal--open {
  transform: translateY(0);
}

/* Desktop: card layout */
@media (min-width: 769px) {
  .tw-modal {
    inset: auto;
    bottom: 100px;
    right: 20px;
    width: 400px;
    height: 600px;
    max-height: calc(100vh - 120px);
    border-radius: var(--tw-radius);
    box-shadow: var(--tw-shadow-lg);
    transform: scale(0) translateY(20px);
    transform-origin: bottom right;
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1),
                opacity 0.2s ease;
    opacity: 0;
  }

  .tw-modal--open {
    transform: scale(1) translateY(0);
    opacity: 1;
  }
}

/* ---- Header ---- */
.tw-header {
  background: var(--tw-bg-header);
  color: var(--tw-text-light);
  padding: 12px 16px;
  padding-top: calc(12px + var(--tw-safe-top));
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  flex-shrink: 0;
}

.tw-header__avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--tw-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  color: white;
  flex-shrink: 0;
}

.tw-header__info {
  flex: 1;
  min-width: 0;
}

.tw-header__name {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tw-header__status {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.8);
  display: flex;
  align-items: center;
  gap: 4px;
}

.tw-header__status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
  display: inline-block;
}

.tw-header__close {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  transition: background 0.2s;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}

.tw-header__close:hover {
  background: rgba(255, 255, 255, 0.15);
}

.tw-header__close:focus-visible {
  outline: 2px solid white;
  outline-offset: 2px;
}

.tw-header__close svg {
  width: 20px;
  height: 20px;
}

/* ---- Chat Body ---- */
.tw-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--tw-bg-chat);
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23d4cfc6' fill-opacity='0.15'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  padding: 16px 12px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}

/* Prevent body scroll when modal open */
body.tw-modal-active {
  overflow: hidden !important;
  position: fixed !important;
  width: 100% !important;
  height: 100% !important;
}

@media (min-width: 769px) {
  body.tw-modal-active {
    overflow: unset !important;
    position: unset !important;
    width: unset !important;
    height: unset !important;
  }
}

/* ---- Chat Bubbles ---- */
.tw-msg {
  display: flex;
  margin-bottom: 8px;
  animation: tw-fadeInUp 0.3s ease;
}

.tw-msg--bot {
  justify-content: flex-start;
}

.tw-msg--user {
  justify-content: flex-end;
}

.tw-bubble {
  max-width: 85%;
  padding: 8px 12px;
  border-radius: var(--tw-radius-sm);
  font-size: 14px;
  line-height: 1.45;
  word-break: break-word;
  position: relative;
}

.tw-bubble--bot {
  background: var(--tw-bg-bubble-bot);
  color: var(--tw-text-primary);
  border-top-left-radius: 2px;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.06);
}

.tw-bubble--user {
  background: var(--tw-bg-bubble-user);
  color: var(--tw-text-primary);
  border-top-right-radius: 2px;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.06);
}

.tw-bubble__time {
  font-size: 11px;
  color: var(--tw-text-secondary);
  text-align: right;
  margin-top: 2px;
}

@keyframes tw-fadeInUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---- Typing Indicator ---- */
.tw-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
  background: var(--tw-bg-bubble-bot);
  border-radius: var(--tw-radius-sm);
  border-top-left-radius: 2px;
  width: fit-content;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.06);
  margin-bottom: 8px;
}

.tw-typing__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--tw-text-secondary);
  animation: tw-typingBounce 1.4s ease-in-out infinite;
}

.tw-typing__dot:nth-child(2) { animation-delay: 0.2s; }
.tw-typing__dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes tw-typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ---- Quick Replies ---- */
.tw-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 0;
  animation: tw-fadeInUp 0.3s ease 0.15s both;
}

.tw-quick-reply {
  background: transparent;
  border: 1.5px solid var(--tw-primary);
  color: var(--tw-primary);
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  font-family: var(--tw-font);
  cursor: pointer;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
  outline: none;
}

.tw-quick-reply:hover {
  background: var(--tw-primary);
  color: white;
}

.tw-quick-reply:focus-visible {
  background: var(--tw-primary);
  color: white;
  box-shadow: 0 0 0 3px rgba(0, 185, 86, 0.3);
}

.tw-quick-reply:active {
  transform: scale(0.96);
}

.tw-quick-reply--selected {
  background: var(--tw-primary);
  color: white;
  pointer-events: none;
}

/* ---- Input Area ---- */
.tw-input-area {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  padding-bottom: calc(8px + var(--tw-safe-bottom));
  background: var(--tw-bg-modal);
  border-top: 1px solid var(--tw-border);
  flex-shrink: 0;
}

.tw-input {
  flex: 1;
  border: 1px solid var(--tw-border);
  border-radius: 24px;
  padding: 10px 16px;
  font-size: 14px;
  font-family: var(--tw-font);
  outline: none;
  transition: border-color 0.2s;
  background: #f0f2f5;
  color: var(--tw-text-primary);
  -webkit-appearance: none;
}

.tw-input:focus {
  border-color: var(--tw-primary);
  background: #ffffff;
}

.tw-input::placeholder {
  color: var(--tw-text-secondary);
}

.tw-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--tw-primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  transition: background 0.2s, transform 0.15s;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}

.tw-send-btn:hover {
  background: var(--tw-primary-dark);
}

.tw-send-btn:active {
  transform: scale(0.92);
}

.tw-send-btn:disabled {
  background: #ccc;
  cursor: not-allowed;
}

.tw-send-btn svg {
  width: 20px;
  height: 20px;
}

/* ---- Recommendation Card ---- */
.tw-rec-card {
  background: white;
  border-radius: var(--tw-radius);
  padding: 16px;
  margin: 8px 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  animation: tw-fadeInUp 0.4s ease;
}

.tw-rec-card__badge {
  display: inline-block;
  background: var(--tw-primary-light);
  color: var(--tw-primary-dark);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 12px;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.tw-rec-card__plan {
  font-size: 22px;
  font-weight: 700;
  color: var(--tw-text-primary);
  margin-bottom: 2px;
}

.tw-rec-card__speed {
  font-size: 14px;
  color: var(--tw-text-secondary);
  margin-bottom: 12px;
}

.tw-rec-card__price {
  font-size: 28px;
  font-weight: 800;
  color: var(--tw-primary);
  margin-bottom: 4px;
}

.tw-rec-card__price-note {
  font-size: 12px;
  color: var(--tw-text-secondary);
  margin-bottom: 12px;
}

.tw-rec-card__reasons {
  list-style: none;
  padding: 0;
  margin: 0 0 16px;
}

.tw-rec-card__reasons li {
  font-size: 13px;
  color: var(--tw-text-primary);
  padding: 4px 0;
  display: flex;
  align-items: flex-start;
  gap: 6px;
}

.tw-rec-card__reasons li::before {
  content: '✓';
  color: var(--tw-primary);
  font-weight: 700;
  flex-shrink: 0;
}

.tw-rec-card__cta {
  display: flex;
  width: 100%;
  padding: 14px;
  background: var(--tw-primary);
  color: white;
  border: none;
  border-radius: var(--tw-radius-sm);
  font-size: 15px;
  font-weight: 600;
  font-family: var(--tw-font);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.2s, transform 0.15s;
  -webkit-tap-highlight-color: transparent;
  text-decoration: none;
}

.tw-rec-card__cta:hover {
  background: var(--tw-primary-dark);
}

.tw-rec-card__cta:active {
  transform: scale(0.98);
}

.tw-rec-card__cta svg {
  width: 20px;
  height: 20px;
  fill: white;
}

.tw-rec-card__alt {
  text-align: center;
  margin-top: 10px;
}

.tw-rec-card__alt-link {
  font-size: 12px;
  color: var(--tw-text-secondary);
  text-decoration: underline;
  cursor: pointer;
  background: none;
  border: none;
  font-family: var(--tw-font);
}

/* ---- Consent ---- */
.tw-consent {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  background: var(--tw-primary-light);
  border-radius: var(--tw-radius-sm);
  margin: 8px 0;
  animation: tw-fadeInUp 0.3s ease;
}

.tw-consent__checkbox {
  width: 18px;
  height: 18px;
  accent-color: var(--tw-primary);
  flex-shrink: 0;
  margin-top: 2px;
  cursor: pointer;
}

.tw-consent__text {
  font-size: 12px;
  color: var(--tw-text-primary);
  line-height: 1.4;
}

.tw-consent__link {
  color: var(--tw-primary);
  text-decoration: underline;
}

/* ---- Fallback Buttons ---- */
.tw-fallback {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.tw-fallback__btn {
  padding: 10px 16px;
  border-radius: var(--tw-radius-sm);
  font-size: 13px;
  font-weight: 500;
  font-family: var(--tw-font);
  cursor: pointer;
  text-align: center;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
  text-decoration: none;
  display: block;
}

.tw-fallback__btn--primary {
  background: var(--tw-primary);
  color: white;
  border: none;
}

.tw-fallback__btn--secondary {
  background: transparent;
  color: var(--tw-text-secondary);
  border: 1px solid var(--tw-border);
}

/* ---- Reduced Motion ---- */
@media (prefers-reduced-motion: reduce) {
  .tw-modal,
  .tw-launcher,
  .tw-msg,
  .tw-quick-replies,
  .tw-rec-card,
  .tw-typing__dot {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }

  .tw-launcher::after {
    animation: none;
  }
}

/* ---- iOS Keyboard Fix ---- */
@supports (-webkit-touch-callout: none) {
  .tw-modal {
    height: -webkit-fill-available;
  }

  .tw-input-area {
    position: sticky;
    bottom: 0;
  }
}

/* ---- Scrollbar ---- */
.tw-body::-webkit-scrollbar {
  width: 4px;
}

.tw-body::-webkit-scrollbar-track {
  background: transparent;
}

.tw-body::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 4px;
}
