/* ==========================================================================
   Automation Editor - Flow builder + Phone Preview
   ========================================================================== */

/* Remove main padding on editor page */
.app-content:has(.ae) > .main {
    padding: 0;
}

.ae {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* ── Activate button (inside preview topbar) ── */
.ae__activate-btn {
    padding: 8px 20px;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.ae__activate-btn:hover {
    background: var(--color-surface-hover);
    border-color: var(--color-text-muted);
}

/* ── Body (two panels) ── */
.ae__body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ── Left sidebar ── */
.ae__sidebar {
    width: 376px;
    flex-shrink: 0;
    padding: var(--spacing-xl);
    background: var(--color-bg-elevated);
    border-left: 1px solid var(--color-border);
    overflow-y: auto;
}

.ae__trigger-title {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-bold);
    color: var(--color-text);
    line-height: 1.3;
    margin-bottom: var(--spacing-md);
}

/* ── Delay divider ── */
.ae__delay {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-xl);
}

.ae__delay-line {
    flex: 1;
    height: 1px;
    background: var(--color-border);
}

.ae__delay-label {
    font-size: var(--font-size-sm);
    color: var(--color-primary);
    font-weight: var(--font-weight-medium);
    white-space: nowrap;
    margin-right: 2px;
}

.ae__delay-edit {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: var(--color-primary-subtle);
    border: none;
    border-radius: var(--radius-sm);
    color: var(--color-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.ae__delay-edit:hover {
    background: rgba(254, 6, 189, 0.18);
}

/* ── Next step button ── */
.ae__next-btn {
    display: inline-flex;
    align-items: center;
    padding: 10px 20px;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text);
    background: none;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.ae__next-btn:hover {
    background: var(--alpha-white-3);
    border-color: var(--color-text-muted);
}

/* ── Right preview panel ── */
.ae__preview {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.ae__preview-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-xl);
    flex-shrink: 0;
}

.ae__preview-label {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    font-weight: var(--font-weight-medium);
}

.ae__preview-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-md);
    padding: 0 var(--spacing-xl) var(--spacing-xl);
}

/* ── Phone mockup ── */
.ae__phone {
    width: 340px;
}

.ae__phone-frame {
    background: var(--color-bg);
    border-radius: 42px;
    border: 7px solid var(--color-surface);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: 680px;
}

/* Status bar */
.ae__phone-status {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px 6px;
    flex-shrink: 0;
}

.ae__phone-time {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text);
}

.ae__phone-notch {
    width: 80px;
    height: 24px;
    background: var(--color-surface-light);
    border-radius: var(--radius-lg);
}

.ae__phone-icons {
    display: flex;
    align-items: center;
    gap: 4px;
    color: var(--color-text);
}

/* Instagram DM header */
.ae__phone-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    flex-shrink: 0;
    border-bottom: 1px solid var(--color-border);
}

.ae__phone-user {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}

.ae__phone-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, #f09433, #e6683c, #dc2743, #cc2366, #bc1888);
    object-fit: cover;
    flex-shrink: 0;
}

.ae__phone-username {
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text);
}

.ae__phone-header-actions {
    display: flex;
    align-items: center;
    gap: 14px;
}

/* Chat body */
.ae__phone-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: var(--spacing-md) var(--spacing-md);
}

.ae__phone-system-msg {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    text-align: center;
}

/* Message input */
.ae__phone-input {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    margin: 0 18px 18px;
    background: var(--color-bg-elevated);
    border-radius: var(--radius-xl);
    flex-shrink: 0;
}

.ae__phone-placeholder {
    flex: 1;
    font-size: var(--font-size-base);
    color: var(--color-text-muted);
}

.ae__phone-camera {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #0095f6;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ae__phone-input-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Channel badge */
.ae__channel-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 16px;
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-secondary);
    background: var(--color-surface);
    border: 3px solid var(--color-border);
    border-radius: var(--radius-full);
}

/* ── Steps ── */
.ae__step--hidden {
    display: none;
}

/* ── Message card ── */
.ae__msg-card {
    background: var(--color-surface);
    border: none;
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    margin-bottom: var(--spacing-md);
}

.ae__msg-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--spacing-md);
}

.ae__msg-card-label {
    font-size: var(--font-size-sm);
    color: var(--color-text);
    font-weight: var(--font-weight-medium);
}

/* Toggle switch */
.ae__toggle {
    position: relative;
    display: inline-flex;
    cursor: pointer;
}

.ae__toggle input {
    display: none;
}

.ae__toggle-track {
    width: 34px;
    height: 18px;
    background: var(--color-border);
    border-radius: var(--radius-full);
    position: relative;
    transition: background 0.2s;
}

.ae__toggle-track::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 14px;
    height: 14px;
    background: var(--color-text);
    border-radius: 50%;
    transition: transform 0.2s;
}

.ae__toggle input:checked + .ae__toggle-track {
    background: var(--color-primary);
}

.ae__toggle input:checked + .ae__toggle-track::after {
    transform: translateX(16px);
}

/* Message body */
.ae__msg-card-body {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.ae__msg-textarea {
    width: 100%;
    min-height: 160px;
    padding: var(--spacing-md);
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    color: var(--color-text);
    font-size: var(--font-size-sm);
    font-family: inherit;
    line-height: 1.5;
    resize: none;
    outline: none;
    transition: border-color 0.2s;
}

.ae__msg-textarea:focus {
    border-color: var(--color-text-muted);
}

.ae__msg-quick-reply {
    width: 100%;
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    color: var(--color-text);
    font-size: var(--font-size-sm);
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}

.ae__msg-quick-reply:focus {
    border-color: var(--color-text-muted);
}

.ae__msg-card-info {
    display: flex;
    align-items: flex-start;
    gap: var(--spacing-xs);
    margin-top: var(--spacing-md);
    color: var(--color-info);
    font-size: var(--font-size-xs);
    cursor: pointer;
}

.ae__msg-card-info span {
    line-height: 1.4;
}

.ae__msg-card-info:hover {
    text-decoration: underline;
}

/* ── Phone chat bubbles ── */
.ae__phone-chat {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    margin-top: 8px;
}

.ae__phone-chat--hidden {
    display: none;
}

.ae__phone-bubble-row {
    display: flex;
    align-items: flex-end;
    gap: 6px;
}

.ae__phone-bubble-row--left {
    justify-content: flex-start;
}

.ae__phone-bubble-row--right {
    justify-content: flex-end;
}

.ae__phone-bubble-avatar {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: linear-gradient(135deg, #f09433, #e6683c, #dc2743, #cc2366, #bc1888);
    object-fit: cover;
    flex-shrink: 0;
}

.ae__phone-bubble {
    max-width: 75%;
    padding: 10px;
    font-size: var(--font-size-sm);
    line-height: 1.4;
    border-radius: var(--radius-xl);
    word-break: break-word;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.ae__phone-bubble #previewBubble {
    display: block;
    white-space: pre-wrap;
}

.ae__phone-bubble--has-btn {
    width: 75%;
    max-width: 75%;
}

.ae__phone-bubble--received {
    background: var(--color-surface-light);
    color: var(--color-text);
    border-bottom-left-radius: 4px;
}


.ae__phone-bubble--sent {
    background: #7c3aed;
    color: var(--color-text);
    border-bottom-right-radius: 4px;
}

/* ── Add link button ── */
.ae__add-link-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    width: 100%;
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    font-family: inherit;
    color: var(--color-text);
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.ae__add-link-btn:hover {
    background: var(--color-surface-hover);
    border-color: var(--color-text-muted);
}


/* ── PRO badge ── */
.ae__pro-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-bold);
    color: var(--color-info);
    background: rgba(59, 130, 246, 0.12);
    border-radius: var(--radius-sm);
    letter-spacing: 0.02em;
}

.ae__msg-card-header-right {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    flex-shrink: 0;
}

.ae__phone-quick-reply {
    display: block;
    margin-top: 2px;
    padding: 7px 12px;
    font-size: var(--font-size-sm);
    color: var(--color-text);
    background: var(--color-surface-active);
    border: none;
    border-radius: var(--radius-md);
    text-align: center;
}

/* ── Delay Modal ── */
.ae-modal {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
}

.ae-modal.open {
    opacity: 1;
    visibility: visible;
}

.ae-modal__backdrop {
    position: absolute;
    inset: 0;
    background: var(--alpha-black-60);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.ae-modal__dialog {
    position: relative;
    width: 480px;
    max-width: 90vw;
    background: var(--color-surface);
    border: none;
    border-radius: var(--radius-xl);
    padding: var(--spacing-xl);
    box-shadow: 0 16px 48px var(--alpha-black-50);
    transform: scale(0.96) translateY(8px);
    transition: transform 0.2s;
}

.ae-modal.open .ae-modal__dialog {
    transform: scale(1) translateY(0);
}

.ae-modal__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: var(--spacing-sm);
}

.ae-modal__title {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-bold);
    color: var(--color-text);
}

.ae-modal__close {
    position: absolute;
    top: var(--spacing-md);
    right: var(--spacing-md);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: none;
    border: none;
    border-radius: var(--radius-md);
    color: var(--color-text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.ae-modal__close:hover {
    background: var(--color-border);
    color: var(--color-text);
}

.ae-modal__desc {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    line-height: 1.5;
    margin-bottom: var(--spacing-xl);
}

.ae-modal__options {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-xl);
}

.ae-modal__option {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    cursor: pointer;
    padding: 2px 0;
}

.ae-modal__option input[type="radio"] {
    display: none;
}

.ae-modal__radio {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid var(--color-text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all var(--transition-fast);
}

.ae-modal__radio::after {
    content: '';
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--color-primary);
    transform: scale(0);
    transition: transform 0.15s;
}

.ae-modal__option input[type="radio"]:checked ~ .ae-modal__radio {
    border-color: var(--color-primary);
}

.ae-modal__option input[type="radio"]:checked ~ .ae-modal__radio::after {
    transform: scale(1);
}

.ae-modal__option-text {
    font-size: var(--font-size-base);
    color: var(--color-text);
    font-weight: var(--font-weight-medium);
}

.ae-modal__footer {
    display: flex;
    justify-content: flex-end;
}

.ae-modal__save {
    padding: 10px 28px;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--color-bg);
    background: var(--color-text);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-family: inherit;
    transition: all var(--transition-fast);
}

.ae-modal__save:hover {
    background: var(--alpha-white-90);
}

.ae-modal__cancel {
    padding: 10px 28px;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text);
    background: none;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-family: inherit;
    transition: all var(--transition-fast);
}

.ae-modal__cancel:hover {
    background: var(--alpha-white-3);
    border-color: var(--color-text-muted);
}

.ae-modal__footer--between {
    justify-content: space-between;
}

.ae-modal__fields {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-lg);
    margin-bottom: var(--spacing-xl);
}

.ae-modal__field {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
}

.ae-modal__label {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--color-text);
}

.ae-modal__input {
    width: 100%;
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    color: var(--color-text);
    font-size: var(--font-size-sm);
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}

.ae-modal__input:focus {
    border-color: var(--color-text-muted);
}

/* Make delay label clickable */
.ae__delay-label {
    cursor: pointer;
}

/* ── Responsive ── */
@media (max-width: 768px) {
    .ae__body {
        flex-direction: column;
    }

    .ae__sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--color-border);
        max-height: 40vh;
    }

    .ae__phone-frame {
        height: 480px;
    }
}

/* ── Light theme overrides ── */
[data-theme="light"] .ae__next-btn:hover {
    background: var(--alpha-black-10);
}

/* Phone mockup: always dark (simulates Instagram DM) */
[data-theme="light"] .ae__phone-frame {
    background: #000;
    border-color: var(--color-surface);
}

[data-theme="light"] .ae__phone-notch {
    background: var(--color-surface-light);
}

[data-theme="light"] .ae__phone-header {
    border-bottom-color: var(--color-border);
}

[data-theme="light"] .ae__phone-input {
    background: var(--color-bg-elevated);
}

[data-theme="light"] .ae__phone-system-msg {
    color: #666;
}

[data-theme="light"] .ae__phone-placeholder {
    color: #666;
}

[data-theme="light"] .ae__phone-bubble--received {
    background: var(--color-surface-light);
}

[data-theme="light"] .ae__phone-quick-reply {
    background: #262626;
}

/* Modal overrides */
[data-theme="light"] .ae-modal__close:hover {
    background: var(--alpha-black-10);
}

[data-theme="light"] .ae-modal__save {
    color: var(--color-text);
    background: var(--color-surface-light);
}

[data-theme="light"] .ae-modal__save:hover {
    background: var(--alpha-black-80);
}

[data-theme="light"] .ae-modal__cancel:hover {
    background: var(--alpha-black-10);
}
