'use strict';

// Auditable accessibility layer for the licensed UI from the minified bundle.
(() => {
  function appendWhenDocumentReady(node) {
    const target = document.head || document.documentElement;
    if (target) {
      target.appendChild(node);
      return;
    }
    document.addEventListener('DOMContentLoaded', () => {
      const readyTarget = document.head || document.documentElement;
      if (readyTarget && !node.isConnected) readyTarget.appendChild(node);
    }, { once: true });
  }

  const STYLE_ID = 'flowhatsapp-accessibility-ui';
  if (document.getElementById(STYLE_ID)) return;
  const style = document.createElement('style');
  style.id = STYLE_ID;
  style.textContent = `
    #wa-extension-header-root {
      --wf-text: #ffffff;
      --wf-text-soft: #f1f5f9;
      --wf-text-muted: #e2e8f0;
      --wf-focus: #a78bfa;
    }
    #wa-extension-header-root .wa-brand-version,
    #wa-extension-header-root .wa-pinned-action,
    #wa-extension-header-root .wa-pinned-action-label,
    #wa-extension-header-root .wa-info-label,
    #wa-extension-header-root .wa-section-label,
    #wa-extension-header-root .tab-item-v2:not(.active),
    #wa-extension-header-root .tab-item-v2:not(.active) .tab-title-v2 {
      color: var(--wf-text-soft) !important;
      opacity: 1 !important;
      text-shadow: none !important;
    }
    #wa-extension-header-root .wa-brand-version {
      font-size: 11px !important;
      font-weight: 700 !important;
    }
    #wa-extension-header-root .wa-pinned-action,
    #wa-extension-header-root .wa-pinned-action-label { font-weight: 650 !important; }
    #wa-extension-header-root .wa-pinned-action svg,
    #wa-extension-header-root .wa-close-btn,
    #wa-extension-header-root .wa-menu-item svg {
      color: var(--wf-text-soft) !important;
      opacity: 1 !important;
    }
    #wa-extension-header-root .wa-info-label,
    #wa-extension-header-root .wa-section-label {
      font-weight: 700 !important;
      letter-spacing: .02em !important;
    }
    #wa-extension-header-root .wa-profile-dropdown-header {
      background: linear-gradient(135deg, #4c1d95 0%, #1d4ed8 100%) !important;
      border-bottom-color: rgba(255,255,255,.28) !important;
    }
    #wa-extension-header-root .wa-profile-dropdown-header,
    #wa-extension-header-root .wa-profile-dropdown-header * {
      color: #ffffff !important;
      opacity: 1 !important;
      text-shadow: 0 1px 2px rgba(0,0,0,.35) !important;
    }
    #wa-extension-header-root .wa-menu-item {
      color: var(--wf-text) !important;
      font-weight: 650 !important;
    }
    #wa-extension-header-root .wa-info-grid {
      display: grid !important;
      grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
      gap: 12px !important;
      align-items: stretch !important;
    }
    #wa-extension-header-root .wa-info-grid > .wa-info-card { min-width: 0 !important; }
    #wa-extension-header-root .wa-info-grid > .wa-info-card:nth-child(3) {
      order: 4 !important;
      grid-column: 1 / -1 !important;
    }
    #wa-extension-header-root #wf-buy-license-card {
      order: 3 !important;
      background: linear-gradient(135deg, #5b21b6, #2563eb) !important;
      border-color: #8b5cf6 !important;
    }
    #wa-extension-header-root #wf-buy-license-card,
    #wa-extension-header-root #wf-buy-license-card * {
      color: #ffffff !important;
      opacity: 1 !important;
    }
    #wa-extension-header-root #wf-buy-license-card .wa-value-highlight {
      color: #ffffff !important;
      font-weight: 750 !important;
      text-decoration-color: rgba(255,255,255,.7) !important;
    }
    #wa-extension-header-root button:focus-visible,
    #wa-extension-header-root a:focus-visible,
    #wa-extension-header-root input:focus-visible,
    #wa-extension-header-root select:focus-visible,
    #wa-extension-header-root textarea:focus-visible {
      outline: 3px solid var(--wf-focus) !important;
      outline-offset: 2px !important;
    }
    @media (max-width: 900px) {
      #wa-extension-header-root .wa-info-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
      #wa-extension-header-root #wf-buy-license-card { grid-column: 1 / -1 !important; }
    }
    @media (max-width: 560px) {
      #wa-extension-header-root .wa-info-grid { grid-template-columns: minmax(0, 1fr) !important; }
      #wa-extension-header-root .wa-info-grid > .wa-info-card { grid-column: 1 !important; }
      #wa-extension-header-root .wa-pinned-action-label { font-size: 12px !important; }
    }

    /* --- PROFILE TAB OVERRIDES (Detalhes do Usuário) --- */
    #wa-extension-header-root .crm-profile-tab {
      background: #0f172a !important;
      color: #f8fafc !important;
      padding: 20px !important;
      border-radius: 12px !important;
    }
    #wa-extension-header-root .crm-profile-tab .crm-section-title {
      color: #ffffff !important;
      font-size: 1.1rem !important;
      font-weight: 700 !important;
    }
    #wa-extension-header-root .crm-profile-tab .crm-profile-field-label {
      color: #e2e8f0 !important;
      font-size: 11px !important;
      text-transform: uppercase !important;
      letter-spacing: 0.5px !important;
      margin-bottom: 4px !important;
    }
    #wa-extension-header-root .crm-profile-tab .crm-profile-field-value {
      color: #e2e8f0 !important;
      font-size: 14px !important;
      font-weight: 600 !important;
    }
    #wa-extension-header-root .crm-profile-tab .crm-profile-field-row {
      border-bottom: 1px solid rgba(255, 255, 255, 0.05) !important;
      padding: 12px 0 !important;
    }

    /* --- DELETED MESSAGES & ANTI-REVOKE TAB --- */
    #wa-extension-header-root .crm-deleted-tab {
      background: #0f172a !important;
      color: #cbd5e1 !important;
      padding: 20px !important;
    }
    #wa-extension-header-root .crm-deleted-tab .dm-banner {
      border-radius: 12px !important;
      padding: 16px !important;
      display: flex !important;
      align-items: center !important;
      justify-content: space-between !important;
      gap: 14px !important;
      margin-bottom: 20px !important;
      background: #1e293b !important;
    }
    #wa-extension-header-root .crm-deleted-tab .dm-banner.off {
      border: 1px solid rgba(239, 68, 68, 0.2) !important;
    }
    #wa-extension-header-root .crm-deleted-tab .dm-banner.off strong {
      color: #ef4444 !important;
    }
    #wa-extension-header-root .crm-deleted-tab .dm-banner.on {
      border: 1px solid rgba(16, 185, 129, 0.2) !important;
    }
    #wa-extension-header-root .crm-deleted-tab .dm-banner.on strong {
      color: #10b981 !important;
    }
    #wa-extension-header-root .crm-deleted-tab .dm-banner .desc div {
      color: #e2e8f0 !important;
    }
    #wa-extension-header-root .crm-deleted-tab .dm-toggle-btn {
      background: #7c3aed !important;
      color: #ffffff !important;
      border: none !important;
      border-radius: 8px !important;
      padding: 8px 16px !important;
      font-weight: 700 !important;
      cursor: pointer !important;
      transition: all 0.2s ease !important;
    }
    #wa-extension-header-root .crm-deleted-tab .dm-toggle-btn:hover {
      background: #6d28d9 !important;
    }
    #wa-extension-header-root .crm-deleted-tab .dm-toggle-btn.off {
      background: rgba(255, 255, 255, 0.08) !important;
      border: 1px solid rgba(255, 255, 255, 0.1) !important;
      color: #cbd5e1 !important;
      font-weight: 700 !important;
    }
    #wa-extension-header-root .crm-deleted-tab .dm-toggle-btn.off:hover {
      background: rgba(255, 255, 255, 0.15) !important;
    }
    #wa-extension-header-root .crm-deleted-tab .dm-chat-tip {
      background: rgba(30, 41, 59, 0.25) !important;
      border: 1px dashed rgba(255, 255, 255, 0.1) !important;
      border-radius: 12px !important;
      padding: 20px !important;
      color: #e2e8f0 !important;
      text-align: center !important;
      display: flex !important;
      flex-direction: column !important;
      align-items: center !important;
      gap: 12px !important;
    }
    #wa-extension-header-root .crm-deleted-tab .dm-chat-tip svg {
      color: #a78bfa !important;
      width: 32px !important;
      height: 32px !important;
    }

    /* --- OTHER DIALOGS/BUTTON OVERRIDES FOR PREMIUM LOOK --- */
    #wa-extension-header-root .crm-btn {
      border-radius: 8px !important;
      font-weight: 600 !important;
      font-family: 'Montserrat', sans-serif !important;
      transition: all 0.2s ease !important;
      padding: 8px 16px !important;
      cursor: pointer !important;
    }
    #wa-extension-header-root .crm-btn-link {
      color: #a78bfa !important;
      border: 1px solid rgba(167, 139, 250, 0.2) !important;
      background: rgba(167, 139, 250, 0.05) !important;
      padding: 6px 12px !important;
    }
    #wa-extension-header-root .crm-btn-link:hover {
      background: rgba(167, 139, 250, 0.15) !important;
      border-color: #a78bfa !important;
    }
    #wa-extension-header-root .crm-btn-primary {
      background: #7c3aed !important;
      color: #ffffff !important;
      border: none !important;
    }
    #wa-extension-header-root .crm-btn-primary:hover {
      background: #6d28d9 !important;
    }
    #wa-extension-header-root .crm-btn-secondary {
      background: rgba(255, 255, 255, 0.08) !important;
      color: #e2e8f0 !important;
      border: 1px solid rgba(255, 255, 255, 0.1) !important;
    }
    #wa-extension-header-root .crm-btn-secondary:hover {
      background: rgba(255, 255, 255, 0.15) !important;
    }

    @media (prefers-reduced-motion: reduce) {
      #wa-extension-header-root *, #wa-extension-header-root *::before, #wa-extension-header-root *::after {
        scroll-behavior: auto !important;
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
      }
    }
  `;
  appendWhenDocumentReady(style);
})();
