/* 
 * AI Content Popup - Optimized Styles
 * Structure: Split Pane (Desktop) / Stacked (Mobile)
 */



.ea4v-texteditor-ai-popup .ts-popup-content-wrapper {
    max-height: 56vh !important
}

.ea4v-popup-expanded .ts-popup-content-wrapper {
    height: 100vh !important;
}

.ea4v-popup-expanded .ts-popup-content-wrapper {
    max-height: 100vh !important;
    height: 100vh !important;
}

.ts-popup-content-wrapper {

    display: flex;
    flex-direction: column;
}

.ea4v-ai-content-editor {
    height: 300px;
    max-height: 80vh;
}

/* --- 1. Base Reset & Utilities --- */
.ea4v-texteditor-ai-popup,
.ea4v-texteditor-ai-popup * {
    box-sizing: border-box;
}

/* --- 2. Components --- */

/* Field Tags (Buttons) */
.ea4v-field-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    margin-bottom: 12px;
}

.ea4v-field-tag {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    font-size: 13px;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    color: #4a4a4a;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
}

.ea4v-field-tag:hover:not(:disabled) {
    border-color: #3378ff;
    color: #3378ff;
    background: #f0f7ff;
    transform: translateY(-1px);
}

.ea4v-field-tag:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Prompt Editor Input */
.ea4v-prompt-editor {
    min-height: 150px;
    padding: 16px;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    font-size: 14px;
    line-height: 1.6;
    background: #fff;
    color: #2d2d2d;
    cursor: text;
    white-space: pre-wrap;
    word-wrap: break-word;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.ea4v-prompt-editor:focus {
    outline: none;
    border-color: #3378ff;
    box-shadow: 0 0 0 3px rgba(51, 120, 255, 0.1);
}

.ea4v-prompt-editor:empty:before {
    content: attr(data-placeholder);
    color: #9ca3af;
}

/* Field Tags inside Prompt Editor */
.ea4v-prompt-editor .ea4v-prompt-tag {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    margin: 0 3px;
    font-size: 12px;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 4px;
    color: #1d4ed8;
    font-weight: 600;
    user-select: none;
    line-height: 1.4;
    vertical-align: middle;
}

/* AI Preview Box */
.ea4v-ai-preview {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 20px;
    font-size: 14px;
    line-height: 1.7;
    color: #374151;
    min-height: 200px;
}

.ea4v-ai-preview p {
    margin-bottom: 1em;
}

.ea4v-ai-preview p:last-child {
    margin-bottom: 0;
}

/* Loading State */
.ea4v-ai-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #6b7280;
    font-style: italic;
    min-height: 100px;
}

.ea4v-ai-loading i {
    margin-right: 8px;
    animation: ea4v-spin 1s linear infinite;
}

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

/* Inline Notification */
.ea4v-inline-notification {
    padding: 12px;
    border-radius: 6px;
    margin-bottom: 15px;
    font-size: 13px;
    background: #fefff5;
    border: 1px solid #e0e0e0;
    color: #333;
}

/* --- 3. Desktop Layout (Split Pane) --- */
@media (min-width: 960px) {

    /* 
     * Override Voxel's default scroll container to enable split-pane layout.
     * We disable scroll on the parent and move scrolling to individual columns.
     */
    .ea4v-texteditor-ai-popup .ts-form-group.min-scroll {
        overflow: hidden !important;
        display: flex;
        flex-direction: column;
        padding-bottom: 0 !important;
        /* Ensure it fills height if expanded, or respects max-height */
        height: 80vh;
        max-height: 80vh !important;
    }

    .ea4v-popup-expanded .ts-form-group.min-scroll {
        height: calc(100vh - 60px) !important;
        /* Adjust for header */
        max-height: none !important;
    }

    /* The Main Grid/Flex Container */
    .ea4v-ai-content-editor {
        display: flex;
        flex: 1;
        /* Fill remaining space */
        width: 100%;
        overflow: hidden;
    }

    /* Left Column: Settings & Prompt */
    .ea4v-ai-content-editor>.vx-1-2 {
        width: 50% !important;
        overflow-y: auto;
        /* Independent Scroll */
        padding: 20px;
        /* Space for hidden sticky footer if consistent */
        border-right: 1px solid #f0f0f0;
        margin: 0 !important;
    }

    /* Right Column: Generated Content (Sticky Feel) */
    /* Target specifically the second column or by class flexify if unique */
    .ea4v-ai-content-editor>.vx-1-2:nth-child(2) {
        background-color: #fcfcfc;
    }

    /* Make the preview container fill the column height */
    .ea4v-ai-preview {
        flex: 1;
        border: none;
        background: transparent;
        border-radius: 0;
        overflow-y: auto;
        /* Internal scroll for preview text */
        height: 100%;
        padding: 0;
        /* Removing padding from box, rely on column padding? */
        /* Actually, keep standard box but make it fill */
    }
}

/* --- 4. Mobile Layout --- */
@media (max-width: 959px) {
    .ea4v-ai-content-editor {
        display: block;
    }

    .ea4v-ai-content-editor>.vx-1-2 {
        width: 100% !important;
        padding: 20px;
    }

    /* On mobile, let simple flow handle height */
    .ea4v-ai-preview {
        max-height: 400px;
        overflow-y: auto;
    }

    /* Hide Fullscreen toggles on mobile */
    .ea4v-ai-toggle-fullscreen {
        display: none !important;
    }

    .ea4v-texteditor-ai-popup .ts-popup-content-wrapper {
        height: 90vh !important;
    }
}

/* Fullscreen Mode Overrides */
.ea4v-popup-expanded .ts-field-popup.triggers-blur {
    position: fixed !important;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100% !important;
    height: 100% !important;
    margin: 0 !important;
    border-radius: 0 !important;
    max-width: none !important;
    z-index: 999999 !important;
}

.ea4v-popup-expanded .ts-form {
    display: flex !important;
    flex-direction: column !important;
    height: 100% !important;
}

.ea4v-popup-expanded .ts-form-group.min-scroll {
    flex: 1 !important;
    height: auto !important;
    max-height: none !important;
    padding-bottom: 0 !important;
    overflow: hidden !important;
}

.ea4v-popup-expanded .ea4v-ai-content-editor {
    height: 100% !important;
    max-height: none !important;
}

.ea4v-ai-error {
    color: #c05621;
    background-color: #fff9f0;
    border: 1px solid #ffe6cc;
    font-size: 13px;
    border-radius: 6px;
    padding: 10px 13px;
    line-height: 1.5;
    font-weight: 500;
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.ea4v-ai-error:before {
    content: "!";
    display: inline-flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
    width: 13px;
    height: 13px;
    background: #ed8936;
    color: #fff;
    border-radius: 50%;
    font-size: 11px;
    font-weight: 700;
    margin-top: 2px;
}

/* History List */
.ea4v-history-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
    margin-top: 8px;
}

.ea4v-history-tag {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 10px;
    font-size: 12px;
    background: #f5f5f5;
    border: 1px solid #ddd;
    border-radius: 4px;
    color: #666;
    cursor: pointer;
    transition: all 0.2s ease;
}

.ea4v-history-tag:hover {
    background: #e6e6e6;
    color: #333;
}

.ea4v-history-tag.active {
    background: white;
    border-color: #3c3c3c;
    color: black;
    box-shadow: 0 1px 2px rgba(51, 120, 255, 0.2);
}