/* ============================================
   DisparoZap - Template Builder (Editor Visual)
   Replica a experiência do Meta Business Manager
   ============================================ */

/* ── Layout Principal ─────────────────────── */
.template-builder {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 24px;
    min-height: calc(100vh - 140px);
}

@media (max-width: 992px) {
    .template-builder {
        grid-template-columns: 1fr;
    }
}

/* ── Painel do Formulário (Esquerda) ──────── */
.tb-editor {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
    padding: 28px 32px;
    overflow-y: auto;
    max-height: calc(100vh - 140px);
}

.tb-editor::-webkit-scrollbar {
    width: 6px;
}

.tb-editor::-webkit-scrollbar-thumb {
    background: #c4c4c4;
    border-radius: 3px;
}

.tb-section {
    margin-bottom: 28px;
    padding-bottom: 24px;
    border-bottom: 1px solid #e9ecef;
}

.tb-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.tb-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.tb-section-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: #1a1a2e;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.tb-section-title .badge-optional {
    font-size: 0.65rem;
    font-weight: 500;
    background: #e9ecef;
    color: #6c757d;
    padding: 2px 8px;
    border-radius: 10px;
    text-transform: none;
    letter-spacing: 0;
}

.tb-section-hint {
    font-size: 0.8rem;
    color: #6c757d;
    margin-bottom: 12px;
    line-height: 1.4;
}

/* ── Campos de Formulário ─────────────────── */
.tb-label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: #495057;
    margin-bottom: 6px;
}

.tb-input,
.tb-select,
.tb-textarea {
    width: 100%;
    border: 1.5px solid #dee2e6;
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 0.9rem;
    color: #212529;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: #fff;
}

.tb-input:focus,
.tb-select:focus,
.tb-textarea:focus {
    outline: none;
    border-color: #25D366;
    box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.15);
}

.tb-input.is-invalid,
.tb-textarea.is-invalid {
    border-color: #dc3545;
    box-shadow: 0 0 0 3px rgba(220, 53, 69, 0.1);
}

.tb-input.is-valid,
.tb-textarea.is-valid {
    border-color: #25D366;
}

.tb-textarea {
    resize: vertical;
    min-height: 100px;
    line-height: 1.5;
    font-family: inherit;
}

.tb-select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23495057' d='M6 8.5L1 3.5h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

/* ── Contador de caracteres ───────────────── */
.tb-char-count {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    font-size: 0.75rem;
    color: #6c757d;
}

.tb-char-count.warning {
    color: #e67e22;
    font-weight: 600;
}

.tb-char-count.danger {
    color: #dc3545;
    font-weight: 700;
}

.tb-char-bar {
    flex: 1;
    height: 3px;
    background: #e9ecef;
    border-radius: 2px;
    overflow: hidden;
}

.tb-char-bar-fill {
    height: 100%;
    background: #25D366;
    border-radius: 2px;
    transition: width 0.2s, background 0.2s;
}

.tb-char-bar-fill.warning {
    background: #e67e22;
}

.tb-char-bar-fill.danger {
    background: #dc3545;
}

/* ── Validação / Alertas ──────────────────── */
.tb-validation {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 0.8rem;
    line-height: 1.4;
    margin-top: 8px;
    animation: tb-slideIn 0.2s ease;
}

@keyframes tb-slideIn {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

.tb-validation.error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
}

.tb-validation.warning {
    background: #fffbeb;
    border: 1px solid #fde68a;
    color: #92400e;
}

.tb-validation.info {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    color: #1e40af;
}

.tb-validation.success {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #166534;
}

.tb-validation-icon {
    flex-shrink: 0;
    font-size: 1rem;
    line-height: 1;
}

/* ── Header Type Selector ─────────────────── */
.tb-type-selector {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.tb-type-btn {
    flex: 1;
    min-width: 70px;
    padding: 10px 8px;
    border: 1.5px solid #dee2e6;
    border-radius: 10px;
    background: #fff;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.78rem;
    font-weight: 600;
    color: #495057;
}

.tb-type-btn:hover {
    border-color: #25D366;
    background: #f0fdf4;
}

.tb-type-btn.active {
    border-color: #25D366;
    background: #dcfce7;
    color: #166534;
}

.tb-type-btn-icon {
    display: block;
    font-size: 1.3rem;
    margin-bottom: 4px;
}

/* ── Upload Area ──────────────────────────── */
.tb-upload-area {
    border: 2px dashed #dee2e6;
    border-radius: 10px;
    padding: 28px 16px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: #fafafa;
    margin-top: 12px;
}

.tb-upload-area:hover {
    border-color: #25D366;
    background: #f0fdf4;
}

.tb-upload-area.has-file {
    border-color: #25D366;
    border-style: solid;
    background: #f0fdf4;
}

.tb-upload-icon {
    font-size: 2rem;
    color: #adb5bd;
    margin-bottom: 8px;
}

.tb-upload-text {
    font-size: 0.82rem;
    color: #6c757d;
}

.tb-upload-text strong {
    color: #25D366;
}

.tb-upload-preview {
    max-width: 100%;
    max-height: 180px;
    border-radius: 8px;
    margin-top: 8px;
}

/* ── Botões do Template ───────────────────── */
.tb-buttons-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.tb-button-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 14px;
    border: 1.5px solid #dee2e6;
    border-radius: 10px;
    background: #fafafa;
    position: relative;
    transition: border-color 0.2s;
}

.tb-button-item:hover {
    border-color: #25D366;
}

.tb-button-item-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.tb-button-item-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.tb-button-item-row .tb-select {
    width: 160px;
    flex-shrink: 0;
}

.tb-button-item-row .tb-input {
    flex: 1;
}

.tb-btn-remove {
    width: 28px;
    height: 28px;
    border: none;
    background: #fee2e2;
    color: #dc3545;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: background 0.2s;
    flex-shrink: 0;
    margin-top: 2px;
}

.tb-btn-remove:hover {
    background: #fecaca;
}

.tb-add-button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px;
    border: 1.5px dashed #adb5bd;
    border-radius: 10px;
    background: transparent;
    color: #495057;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    transition: all 0.2s;
}

.tb-add-button:hover {
    border-color: #25D366;
    color: #25D366;
    background: #f0fdf4;
}

.tb-add-button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ── Ações do formulário ──────────────────── */
.tb-actions {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-top: 28px;
    padding-top: 20px;
    border-top: 1px solid #e9ecef;
}

.tb-btn-submit {
    padding: 12px 28px;
    background: #25D366;
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.tb-btn-submit:hover {
    background: #1fb855;
    transform: translateY(-1px);
}

.tb-btn-submit:active {
    transform: translateY(0);
}

.tb-btn-submit:disabled {
    background: #adb5bd;
    cursor: not-allowed;
    transform: none;
}

.tb-btn-submit .spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: tb-spin 0.6s linear infinite;
}

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

.tb-btn-cancel {
    padding: 12px 24px;
    background: transparent;
    color: #6c757d;
    border: 1.5px solid #dee2e6;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.tb-btn-cancel:hover {
    background: #f8f9fa;
    color: #495057;
    text-decoration: none;
}

/* ── Painel de Preview (Direita) ──────────── */
.tb-preview-panel {
    position: sticky;
    top: 80px;
    align-self: flex-start;
}

.tb-preview-label {
    font-size: 0.82rem;
    font-weight: 700;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
    text-align: center;
}

/* ── Moldura do Celular ───────────────────── */
.tb-phone-frame {
    width: 340px;
    background: #0b141a;
    border-radius: 36px;
    padding: 12px;
    box-shadow:
        0 20px 60px rgba(0, 0, 0, 0.15),
        0 0 0 2px rgba(0, 0, 0, 0.05);
    margin: 0 auto;
}

.tb-phone-notch {
    width: 120px;
    height: 24px;
    background: #0b141a;
    border-radius: 0 0 16px 16px;
    margin: 0 auto 0;
    position: relative;
    z-index: 2;
}

.tb-phone-screen {
    background: #e5ddd5;
    border-radius: 24px;
    overflow: hidden;
    position: relative;
    min-height: 520px;
    display: flex;
    flex-direction: column;
}

/* Fundo tipo WhatsApp */
.tb-phone-screen::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M30 5c1.5 0 2.7 1.2 2.7 2.7S31.5 10.4 30 10.4s-2.7-1.2-2.7-2.7S28.5 5 30 5zm-15 15c1.5 0 2.7 1.2 2.7 2.7s-1.2 2.7-2.7 2.7-2.7-1.2-2.7-2.7 1.2-2.7 2.7-2.7zm30 0c1.5 0 2.7 1.2 2.7 2.7s-1.2 2.7-2.7 2.7-2.7-1.2-2.7-2.7 1.2-2.7 2.7-2.7zm-15 15c1.5 0 2.7 1.2 2.7 2.7s-1.2 2.7-2.7 2.7-2.7-1.2-2.7-2.7 1.2-2.7 2.7-2.7z' fill='%23d4ccb9' fill-opacity='0.3'/%3E%3C/svg%3E");
    opacity: 0.5;
    z-index: 0;
}

/* Header bar do WhatsApp */
.tb-wa-header-bar {
    background: #075e54;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    position: relative;
    z-index: 1;
}

.tb-wa-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #128c7e;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1rem;
    font-weight: 700;
}

.tb-wa-contact-name {
    color: #fff;
    font-size: 0.9rem;
    font-weight: 600;
}

.tb-wa-contact-status {
    color: rgba(255,255,255,0.7);
    font-size: 0.7rem;
}

/* Área de mensagens */
.tb-wa-messages {
    flex: 1;
    padding: 16px;
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

/* Bolha da mensagem */
.tb-wa-bubble {
    background: #fff;
    border-radius: 0 8px 8px 8px;
    padding: 0;
    max-width: 95%;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    position: relative;
    overflow: hidden;
}

/* Seta da bolha */
.tb-wa-bubble::before {
    content: '';
    position: absolute;
    top: 0;
    left: -8px;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 0 8px 8px 0;
    border-color: transparent #fff transparent transparent;
}

/* Header da bolha (imagem) */
.tb-wa-bubble-header {
    width: 100%;
    overflow: hidden;
}

.tb-wa-bubble-header img {
    width: 100%;
    display: block;
    object-fit: cover;
    max-height: 160px;
}

.tb-wa-bubble-header-text {
    padding: 10px 12px 0;
    font-weight: 700;
    font-size: 0.88rem;
    color: #111;
}

.tb-wa-bubble-header-media-placeholder {
    width: 100%;
    height: 130px;
    background: #e9ecef;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #adb5bd;
    font-size: 2.5rem;
}

/* Body da bolha */
.tb-wa-bubble-body {
    padding: 10px 12px;
    font-size: 0.84rem;
    line-height: 1.45;
    color: #111;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.tb-wa-bubble-body .variable {
    background: #dcfce7;
    color: #166534;
    padding: 1px 5px;
    border-radius: 4px;
    font-weight: 600;
    font-size: 0.82rem;
}

/* Footer da bolha */
.tb-wa-bubble-footer {
    padding: 0 12px 8px;
    font-size: 0.72rem;
    color: #8696a0;
}

/* Timestamp */
.tb-wa-bubble-time {
    text-align: right;
    padding: 0 10px 6px;
    font-size: 0.65rem;
    color: #8696a0;
}

/* Botões da mensagem */
.tb-wa-bubble-buttons {
    border-top: 1px solid #e9ecef;
}

.tb-wa-bubble-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px;
    border-bottom: 1px solid #e9ecef;
    color: #00a5f4;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: default;
    text-align: center;
}

.tb-wa-bubble-btn:last-child {
    border-bottom: none;
}

.tb-wa-bubble-btn-icon {
    font-size: 0.9rem;
}

/* Preview vazio */
.tb-preview-empty {
    padding: 20px;
    text-align: center;
    color: #8696a0;
    font-size: 0.8rem;
    position: relative;
    z-index: 1;
}

/* ── Formulário Inline Row ────────────────── */
.tb-row {
    display: flex;
    gap: 12px;
}

.tb-row > * {
    flex: 1;
}

.tb-field {
    margin-bottom: 14px;
}

/* ── Toggle Switch ────────────────────────── */
.tb-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 0.82rem;
    color: #495057;
}

.tb-toggle input {
    display: none;
}

.tb-toggle-track {
    width: 38px;
    height: 20px;
    background: #dee2e6;
    border-radius: 10px;
    position: relative;
    transition: background 0.2s;
    flex-shrink: 0;
}

.tb-toggle-track::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: transform 0.2s;
    box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}

.tb-toggle input:checked + .tb-toggle-track {
    background: #25D366;
}

.tb-toggle input:checked + .tb-toggle-track::after {
    transform: translateX(18px);
}

/* ── Status Badges ────────────────────────── */
.tb-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.tb-status.pending {
    background: #fff3cd;
    color: #856404;
}

.tb-status.approved {
    background: #d4edda;
    color: #155724;
}

.tb-status.rejected {
    background: #f8d7da;
    color: #721c24;
}

/* ── Validação Summary ────────────────────── */
.tb-validation-summary {
    background: #fff;
    border-radius: 10px;
    border: 1.5px solid #dee2e6;
    padding: 16px;
    margin-top: 16px;
}

.tb-validation-summary-title {
    font-size: 0.82rem;
    font-weight: 700;
    color: #495057;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.tb-validation-summary-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.tb-validation-summary-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    padding: 6px 10px;
    border-radius: 6px;
}

.tb-validation-summary-item.pass {
    color: #166534;
    background: #f0fdf4;
}

.tb-validation-summary-item.fail {
    color: #991b1b;
    background: #fef2f2;
}

/* ── Page Title ───────────────────────────── */
.tb-page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.tb-page-title {
    font-size: 1.35rem;
    font-weight: 800;
    color: #1a1a2e;
    display: flex;
    align-items: center;
    gap: 10px;
}

.tb-page-title-icon {
    font-size: 1.5rem;
}

/* ── Variables highlight in textarea ──────── */
.tb-body-overlay {
    position: relative;
}

/* ── Result Modal ─────────────────────────── */
.tb-result-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: tb-fadeIn 0.2s ease;
}

@keyframes tb-fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.tb-result-modal {
    background: #fff;
    border-radius: 16px;
    padding: 32px;
    max-width: 480px;
    width: 90%;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    animation: tb-scaleIn 0.25s ease;
}

@keyframes tb-scaleIn {
    from { transform: scale(0.9); opacity: 0; }
    to   { transform: scale(1); opacity: 1; }
}

.tb-result-icon {
    font-size: 3.5rem;
    margin-bottom: 12px;
}

.tb-result-title {
    font-size: 1.2rem;
    font-weight: 800;
    color: #1a1a2e;
    margin-bottom: 8px;
}

.tb-result-message {
    font-size: 0.88rem;
    color: #6c757d;
    line-height: 1.5;
    margin-bottom: 20px;
}

.tb-result-details {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 12px 16px;
    font-size: 0.78rem;
    color: #495057;
    text-align: left;
    margin-bottom: 20px;
    max-height: 180px;
    overflow-y: auto;
    word-break: break-word;
}

.tb-result-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

/* ── Tooltip ──────────────────────────────── */
.tb-tooltip {
    position: relative;
    display: inline-flex;
    align-items: center;
    cursor: help;
}

.tb-tooltip::after {
    content: attr(data-tip);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: #1a1a2e;
    color: #fff;
    font-size: 0.72rem;
    font-weight: 500;
    padding: 6px 10px;
    border-radius: 6px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
    z-index: 10;
}

.tb-tooltip:hover::after {
    opacity: 1;
}

/* ── Variáveis Header/Body textarea highlight ─── */
.tb-var-badge {
    display: inline-block;
    background: #dcfce7;
    color: #166534;
    font-size: 0.72rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 10px;
    margin: 2px;
    cursor: default;
}

/* ── Responsivo ───────────────────────────── */
@media (max-width: 992px) {
    .tb-preview-panel {
        position: static;
        order: -1;
    }

    .tb-phone-frame {
        width: 300px;
    }

    .tb-editor {
        max-height: none;
    }
}

@media (max-width: 576px) {
    .tb-editor {
        padding: 20px 16px;
    }

    .tb-row {
        flex-direction: column;
    }

    .tb-button-item-row {
        flex-direction: column;
    }

    .tb-button-item-row .tb-select {
        width: 100%;
    }

    .tb-phone-frame {
        width: 100%;
        max-width: 300px;
    }
}
