:root {
  --wa-header: #0f172a;
  --wa-header-soft: #1e293b;
  --wa-accent: #10b981;
  --wa-accent2: #059669;
  --wa-bg: #f1f5f9;
  --wa-out: #e0e7ff;
  --wa-in: #ffffff;
  --wa-text: #0f172a;
  --wa-muted: #64748b;
}

.wa-chat-launcher,
.wa-chat-widget,
.wa-chat-widget * {
  box-sizing: border-box;
  font-family: 'Inter', Arial, Helvetica, sans-serif;
}

.wa-chat-launcher {
  position: fixed;
  right: 22px;
  bottom: 24px;
  z-index: 99999;
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--wa-accent), var(--wa-accent2));
  color: #fff;
  box-shadow: 0 10px 25px rgba(16,185,129,.4), 0 4px 10px rgba(0,0,0,.1);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 2px;
  transition: transform 0.3s cubic-bezier(0.34,1.56,0.64,1), box-shadow 0.3s;
}

.wa-chat-launcher:hover {
  transform: scale(1.08);
  box-shadow: 0 12px 36px rgba(16,185,129,.5), 0 6px 16px rgba(0,0,0,.15);
}

.wa-chat-launcher::after {
  content: 'Support';
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.85);
  line-height: 1;
}

/* Ping animation ring */
.wa-chat-launcher::before {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 24px;
  border: 2px solid rgba(16,185,129,0.4);
  animation: wa-ping 2s ease-out infinite;
}

@keyframes wa-ping {
  0%   { opacity: 1; transform: scale(1); }
  80%  { opacity: 0; transform: scale(1.28); }
  100% { opacity: 0; }
}

.wa-chat-launcher svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
  flex-shrink: 0;
}

.wa-chat-tooltip {
  position: absolute;
  right: -5px;
  bottom: calc(100% + 20px);
  margin-right: 0;
  transform: translateY(15px);
  background: #ffffff;
  color: #1e293b;
  padding: 16px 20px;
  border-radius: 16px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.12), 0 4px 10px rgba(0,0,0,0.06);
  font-size: 14px;
  font-weight: 500;
  width: 250px;
  line-height: 1.5;
  opacity: 0;
  visibility: hidden;
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  transform-origin: bottom right;
}

.wa-chat-tooltip::after {
  content: '';
  position: absolute;
  bottom: -6px;
  right: 28px;
  width: 12px;
  height: 12px;
  background: #ffffff;
  transform: rotate(45deg);
  box-shadow: 4px 4px 5px rgba(0,0,0,0.04);
}

.wa-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  background: #ef4444; 
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 8px rgba(239, 68, 68, 0.4);
  border: 2px solid #fff;
  opacity: 0;
  transform: scale(0);
  transition: all 0.3s cubic-bezier(0.34,1.56,0.64,1);
  z-index: 2;
}

.wa-badge.show {
  opacity: 1;
  transform: scale(1);
}

.wa-chat-tooltip.show {
  opacity: 1;
  visibility: visible;
}

.wa-chat-tooltip .wa-tooltip-close {
  position: absolute;
  top: 4px;
  right: 4px;
  background: none;
  border: none;
  color: #94a3b8;
  font-size: 16px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

.wa-chat-tooltip .wa-tooltip-close:hover {
  color: #475569;
}

.wa-chat-widget {
  position: fixed;
  right: 20px;
  bottom: 92px;
  z-index: 99999;
  width: min(370px, calc(100vw - 24px));
  height: min(620px, calc(100vh - 120px));
  background: var(--wa-bg);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 16px 50px rgba(0, 0, 0, .28);
  display: none;
  flex-direction: column;
}

.wa-chat-widget.is-open {
  display: flex;
}

.wa-chat-header {
  min-height: 64px;
  background: linear-gradient(135deg, var(--wa-header), var(--wa-header-soft));
  color: #fff;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 14px;
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
}

.wa-chat-avatar {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex: 0 0 auto;
}

.wa-chat-title {
  min-width: 0;
  flex: 1;
}

.wa-chat-title strong {
  display: block;
  font-size: 15px;
  line-height: 20px;
}

.wa-chat-title span {
  display: block;
  font-size: 12px;
  opacity: .86;
}

.wa-chat-close {
  border: 0;
  background: transparent;
  color: #fff;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
}

.wa-chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
  background-color: var(--wa-bg);
  background-image:
    radial-gradient(rgba(0, 0, 0, .035) 1px, transparent 1px),
    radial-gradient(rgba(255, 255, 255, .28) 1px, transparent 1px);
  background-position: 0 0, 8px 8px;
  background-size: 16px 16px;
}

.wa-message-row {
  display: flex;
  margin: 8px 0;
  align-items: flex-end;
}

.wa-agent-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  margin-right: 8px;
  margin-bottom: 2px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
  border: 1.5px solid #ffffff;
}

.wa-agent-name {
  font-size: 11px;
  font-weight: 700;
  color: #2563eb;
  margin-bottom: 4px;
  display: block;
}

.wa-message-row.out {
  justify-content: flex-end;
}

.wa-bubble {
  position: relative;
  max-width: 82%;
  min-width: 74px;
  padding: 8px 8px 18px;
  border-radius: 7px;
  color: var(--wa-text);
  font-size: 14px;
  line-height: 19px;
  box-shadow: 0 1px 1px rgba(0, 0, 0, .08);
  word-wrap: break-word;
}

.wa-message-row.in .wa-bubble {
  background: var(--wa-in);
  border-top-left-radius: 0;
}

.wa-message-row.out .wa-bubble {
  background: var(--wa-out);
  border-top-right-radius: 0;
}

.wa-message-row.in .wa-bubble::before,
.wa-message-row.out .wa-bubble::before {
  content: "";
  position: absolute;
  top: 0;
  width: 0;
  height: 0;
  border-top: 8px solid transparent;
}

.wa-message-row.in .wa-bubble::before {
  left: -7px;
  border-right: 8px solid var(--wa-in);
}

.wa-message-row.out .wa-bubble::before {
  right: -7px;
  border-left: 8px solid var(--wa-out);
}

.wa-bubble img {
  display: block;
  max-width: 100%;
  border-radius: 6px;
}

.wa-time {
  position: absolute;
  right: 8px;
  bottom: 4px;
  color: var(--wa-muted);
  font-size: 10px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.wa-ticks {
  font-size: 12px;
  color: var(--wa-muted);
  letter-spacing: -2px;
  margin-right: 2px;
}

.wa-ticks.is-read {
  color: #34b7f1;
}

.wa-chat-auth {
  padding: 14px;
  background: rgba(255,255,255,.88);
  border-bottom: 1px solid rgba(0,0,0,.08);
}

.wa-chat-auth input,
.wa-chat-input input {
  width: 100%;
  border: 0;
  outline: 0;
  border-radius: 22px;
  padding: 12px 14px;
  background: #fff;
  color: var(--wa-text);
}

.wa-chat-auth button,
.wa-chat-send,
.wa-chat-file-label {
  border: 0;
  background: var(--wa-accent);
  color: #fff;
  border-radius: 22px;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 700;
}

.wa-chat-auth button {
  width: 100%;
  margin-top: 8px;
}

.wa-chat-input {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px;
  background: #f0f2f5;
}

.wa-chat-input input[type="file"] {
  display: none;
}

.wa-chat-file-label {
  width: 42px;
  height: 42px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

.wa-chat-send {
  width: 46px;
  height: 42px;
  padding: 0;
  flex: 0 0 auto;
}

.wa-chat-notice {
  margin: 10px auto;
  max-width: 88%;
  border-radius: 8px;
  background: rgba(255, 255, 255, .8);
  color: var(--wa-muted);
  text-align: center;
  font-size: 12px;
  padding: 8px 10px;
}

.wa-chat-error {
  color: #b42318;
  font-size: 12px;
  margin-top: 8px;
  min-height: 16px;
}

@media (max-width: 520px) {
  .wa-chat-widget {
    right: 12px;
    left: 12px;
    bottom: calc(80px + env(safe-area-inset-bottom, 0px));
    width: auto;
    height: calc(70vh - env(safe-area-inset-top, 0px));
    border-radius: 16px;
  }

  .wa-chat-launcher {
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }
}
