/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 *  Floating WhatsApp Widget — Styles
 *  Shadow DOM scoped
 * ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */

:host {
  --wa-color: #25d366;
  --wa-color-dark: #1a8a44;
  --wa-color-light: #dcf8c6;
  --wa-radius: 18px;
  --wa-radius-sm: 12px;
  --wa-elevation: 0 8px 32px rgba(0, 0, 0, 0.18), 0 2px 8px rgba(0, 0, 0, 0.08);
  --wa-elevation-hover: 0 12px 40px rgba(0, 0, 0, 0.22), 0 4px 12px rgba(0, 0, 0, 0.1);
  --wa-surface: #ffffff;
  --wa-surface-variant: #f5f5f5;
  --wa-on-surface: #1c1c1e;
  --wa-on-surface-variant: #6b6b6b;
  --wa-outline-variant: #e0e0e0;
  --wa-error: #d32f2f;
  --wa-fab-size: 56px;
  --wa-max-width: 360px;
  --wa-max-height: 620px;
  --wa-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
    Ubuntu, Cantarell, sans-serif;

  all: initial;
  display: block;
  font-family: var(--wa-font);
  color: var(--wa-on-surface);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Dark theme ─────────────────────────── */
:host([data-theme='dark']),
:host-context([data-theme='dark']),
:host-context(.dark) {
  --wa-surface: #1e1e1e;
  --wa-surface-variant: #2a2a2a;
  --wa-on-surface: #e0e0e0;
  --wa-on-surface-variant: #aaaaaa;
  --wa-outline-variant: #333333;
}

/* ── FAB ─────────────────────────────────── */
.fab {
  position: fixed;
  bottom: 24px;
  z-index: 2147483000;
  width: var(--wa-fab-size);
  height: var(--wa-fab-size);
  border-radius: 50%;
  border: none;
  background: var(--wa-color);
  color: #fff;
  box-shadow: 0 4px 16px color-mix(in srgb, var(--wa-color) 40%, transparent);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1),
    box-shadow 0.3s ease;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.fab--right {
  right: 24px;
}

.fab--left {
  left: 24px;
}

.fab:hover {
  box-shadow: 0 6px 24px color-mix(in srgb, var(--wa-color) 60%, transparent);
  transform: scale(1.08);
}

.fab:active {
  transform: scale(0.92);
}

/* Pulse ring */
.fab::before {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2.5px solid var(--wa-color);
  opacity: 0.25;
  animation: fab-pulse 2.4s ease-in-out infinite;
  pointer-events: none;
}

.fab--open::before {
  animation: none;
  opacity: 0;
}

@keyframes fab-pulse {
  0%, 100% { transform: scale(1); opacity: 0.25; }
  50% { transform: scale(1.18); opacity: 0.05; }
}

.fab svg {
  position: absolute;
  width: 26px;
  height: 26px;
  transition: opacity 0.25s cubic-bezier(0.4, 0, 0.6, 1),
    transform 0.25s cubic-bezier(0.4, 0, 0.6, 1);
}

.fab .icon-chat {
  opacity: 1;
  transform: rotate(0deg);
}

.fab .icon-close {
  opacity: 0;
  transform: rotate(90deg);
}

.fab--open .icon-chat {
  opacity: 0;
  transform: rotate(-90deg);
}

.fab--open .icon-close {
  opacity: 1;
  transform: rotate(0deg);
}

@media (max-width: 480px) {
  .fab {
    bottom: 16px;
    width: 50px;
    height: 50px;
  }
  .fab--right { right: 16px; }
  .fab--left { left: 16px; }
  .fab svg { width: 22px; height: 22px; }
}

/* ── Card ────────────────────────────────── */
.card {
  position: fixed;
  bottom: 96px;
  z-index: 2147482999;
  width: calc(100vw - 32px);
  max-width: var(--wa-max-width);
  max-height: var(--wa-max-height);
  background: var(--wa-surface);
  border-radius: var(--wa-radius);
  box-shadow: var(--wa-elevation);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transform-origin: bottom right;
  opacity: 0;
  transform: translateY(24px) scale(0.96);
  visibility: hidden;
  transition: opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1),
    transform 0.25s cubic-bezier(0.16, 1, 0.3, 1),
    visibility 0.25s;
}

.card--right {
  right: 24px;
}

.card--left {
  left: 24px;
}

.card--open {
  opacity: 1;
  transform: translateY(0) scale(1);
  visibility: visible;
}

@media (max-width: 420px) {
  .card {
    right: 8px !important;
    left: 8px !important;
    bottom: 78px;
    width: calc(100vw - 16px);
    max-height: calc(100vh - 120px);
    border-radius: var(--wa-radius-sm);
  }
}

/* ── Loader ──────────────────────────────── */
.loader {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  background: var(--wa-surface);
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--wa-outline-variant);
  border-top-color: var(--wa-color);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Header ──────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  background: var(--wa-color-dark);
  color: #fff;
  flex-shrink: 0;
  gap: 8px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}

.avatar svg {
  width: 22px;
  height: 22px;
  color: #fff;
}

.header-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.company-name {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  opacity: 0.85;
  font-weight: 400;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4caf50;
  display: inline-block;
  animation: status-blink 2s ease-in-out infinite;
}

@keyframes status-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.btn-minimize {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  flex-shrink: 0;
  padding: 0;
  outline: none;
}

.btn-minimize:hover {
  background: rgba(255, 255, 255, 0.25);
}

.btn-minimize svg {
  width: 18px;
  height: 18px;
}

/* ── Body ────────────────────────────────── */
.body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 18px 20px 14px;
  background: var(--wa-surface);
}

.body::-webkit-scrollbar {
  width: 4px;
}

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

.body::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--wa-on-surface-variant) 25%, transparent);
  border-radius: 4px;
}

.welcome {
  font-size: 14px;
  color: var(--wa-on-surface-variant);
  line-height: 1.55;
  margin: 0 0 16px;
}

/* ── Form ────────────────────────────────── */
.form {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.form-group {
  position: relative;
  margin-bottom: 6px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--wa-on-surface-variant);
  margin-bottom: 4px;
  transition: color 0.2s;
}

.form-group:focus-within label {
  color: var(--wa-color);
}

.form-input {
  width: 100%;
  padding: 10px 14px;
  font-size: 14px;
  font-family: var(--wa-font);
  color: var(--wa-on-surface);
  background: var(--wa-surface);
  border: 1.5px solid var(--wa-outline-variant);
  border-radius: 10px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-sizing: border-box;
  line-height: 1.4;
}

.form-input:hover {
  border-color: color-mix(in srgb, var(--wa-color) 50%, var(--wa-on-surface-variant));
}

.form-input:focus {
  border-color: var(--wa-color);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--wa-color) 15%, transparent);
}

.form-input.error {
  border-color: var(--wa-error);
}

.form-input::placeholder {
  color: color-mix(in srgb, var(--wa-on-surface-variant) 50%, transparent);
}

textarea.form-input {
  resize: vertical;
  min-height: 60px;
  max-height: 120px;
}

.form-error {
  font-size: 11px;
  color: var(--wa-error);
  margin-top: 3px;
  display: none;
}

.form-error--visible {
  display: block;
}

/* ── Checkbox ────────────────────────────── */
.checkbox-group {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 8px 0 2px;
}

.checkbox-group input[type='checkbox'] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border: 2px solid var(--wa-outline-variant);
  border-radius: 4px;
  background: var(--wa-surface);
  cursor: pointer;
  flex-shrink: 0;
  margin-top: 1px;
  position: relative;
  transition: border-color 0.2s, background 0.2s;
}

.checkbox-group input[type='checkbox']:checked {
  background: var(--wa-color);
  border-color: var(--wa-color);
}

.checkbox-group input[type='checkbox']:checked::after {
  content: '';
  position: absolute;
  left: 5px;
  top: 1px;
  width: 5px;
  height: 9px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.checkbox-group input[type='checkbox']:focus-visible {
  outline: 2px solid var(--wa-color);
  outline-offset: 2px;
}

.checkbox-group label {
  font-size: 13px;
  color: var(--wa-on-surface-variant);
  cursor: pointer;
  line-height: 1.4;
  user-select: none;
  display: inline;
}

.checkbox-label-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.checkbox-group a {
  color: var(--wa-color);
  text-decoration: underline;
}

.privacy-link {
  font-size: 11px;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.privacy-link:hover {
  opacity: 1;
}

.checkbox-error {
  font-size: 11px;
  color: var(--wa-error);
  margin: 0 0 4px;
  display: none;
}

.checkbox-error--visible {
  display: block;
}

/* ── Submit ──────────────────────────────── */
.btn-submit {
  width: 100%;
  margin-top: 14px;
  padding: 12px 24px;
  border: none;
  border-radius: 24px;
  background: var(--wa-color);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  font-family: var(--wa-font);
  letter-spacing: 0.01em;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: box-shadow 0.2s, transform 0.2s, opacity 0.2s;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.btn-submit:hover:not(:disabled) {
  box-shadow: 0 4px 16px color-mix(in srgb, var(--wa-color) 40%, transparent);
}

.btn-submit:active:not(:disabled) {
  transform: scale(0.98);
}

.btn-submit:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-submit svg {
  width: 16px;
  height: 16px;
}

/* ── Footer ──────────────────────────────── */
.footer {
  flex-shrink: 0;
  padding: 8px 18px;
  background: var(--wa-surface-variant);
  color: var(--wa-on-surface-variant);
  font-size: 11px;
  text-align: center;
  border-top: 1px solid var(--wa-outline-variant);
}

/* ── Reduced motion ──────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .fab { transition: none; }
  .fab::before { animation: none; }
  .card { transition: none; }
  .status-dot { animation: none; }
}
