/**
 * AI Chat Branch - Frontend Styles
 */

/* Main wrapper */
#ai-chat-branch-wrapper {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    max-width: 1200px;
    margin: 20px auto;
    padding: 20px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Controls section */
.ai-chat-branch-controls {
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid #e0e0e0;
}

/* Input group */
.ai-input-group {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    align-items: flex-start;
    flex-wrap: wrap;
}

#ai-prompt {
    flex: 1 1 100%;
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    font-size: 14px;
    resize: vertical;
    min-height: 60px;
    font-family: inherit;
}

#ai-send-btn {
    padding: 12px 24px;
    background: #2271b1;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    flex: 0 1 auto;
    transition: background 0.2s;
}

#ai-send-btn:hover {
    background: #135e96;
}

.main-prompt-dropdown {
    display: flex;
    align-items: center;
    flex: 1 1 auto;
}

.main-prompt-dropdown select {
    padding: 8px 12px;
    border: 1px solid #2271b1;
    border-radius: 4px;
    background: white;
    color: #333;
    cursor: pointer;
    width: 100%;
    min-width: 180px;
}

/* Session controls */
.ai-session-controls {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.ai-session-controls button {
    padding: 8px 16px;
    background: #2271b1;
    color: white;
    border: 1px solid #135e96;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s ease;
}

.ai-session-controls button:hover {
    background: #135e96;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

#node-counter {
    margin-left: auto;
    padding: 8px 16px;
    background: #2271b1;
    color: white;
    border: 1px solid #135e96;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 600;
}

/* Tree container */
#ai-chat-branch-container {
    min-height: 200px;
}

/* Node styles */
.ai-node {
    margin: 20px 0;
    padding: 20px;
    background: #f9f9f9;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    position: relative;
    transition: all 0.3s ease;
}

.ai-node:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    transform: translateY(-2px);
}

.ai-node-branch {
    margin-left: 40px;
    border-left: 3px solid #2271b1;
    padding-left: 20px;
}

/* Depth-based coloring */
.ai-depth-0 { 
    background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%); 
    border-left: 4px solid #2271b1;
}

.ai-depth-1 { 
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%); 
    border-left: 4px solid #5a67d8;
}

.ai-depth-2 { 
    background: linear-gradient(135deg, #e9ecef 0%, #dee2e6 100%); 
    border-left: 4px solid #9f7aea;
}

.ai-depth-3 { 
    background: linear-gradient(135deg, #dee2e6 0%, #ced4da 100%); 
    border-left: 4px solid #ed8936;
}

.ai-depth-4 { 
    background: linear-gradient(135deg, #ced4da 0%, #adb5bd 100%); 
    border-left: 4px solid #f56565;
}

/* Alternating colors for siblings */
.ai-node:nth-child(even) {
    background: linear-gradient(135deg, #f0f8ff 0%, #e6f3ff 100%);
}

/* Node header */
.ai-node-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 10px;
}

.ai-collapse-btn {
    background: none;
    border: 1px solid #ddd;
    border-radius: 3px;
    padding: 2px 8px;
    cursor: pointer;
    font-size: 12px;
    color: #666;
    margin-left: 10px;
    flex-shrink: 0;
}

.ai-collapse-btn:hover {
    background: #f0f0f1;
}

/* Collapsed state */
.ai-node-collapsed .ai-children {
    display: none;
}

/* Text content */
.ai-prompt-text, .ai-response-text {
    margin: 10px 0;
    line-height: 1.6;
}

.ai-prompt-text {
    font-weight: 600;
    color: #2271b1;
    flex: 1;
    white-space: pre-line;
    word-wrap: break-word;
}

.ai-response-text {
    color: #333;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Text truncation */
.ai-prompt-text.truncated,
.ai-response-text.truncated {
    max-height: 4.5em;
    overflow: hidden;
    position: relative;
    cursor: pointer;
}

.ai-prompt-text.truncated::after,
.ai-response-text.truncated::after {
    content: "... (click to expand)";
    position: absolute;
    bottom: 0;
    right: 0;
    background: linear-gradient(to right, transparent, #f9f9f9 50%);
    padding-left: 20px;
    color: #666;
    font-size: 12px;
    font-weight: normal;
}

/* Node actions */
.ai-node-actions {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #e0e0e0;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.ai-node-actions button {
    padding: 6px 12px;
    background: white;
    border: 1px solid #2271b1;
    color: #2271b1;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}

.ai-node-actions button:hover {
    background: #2271b1;
    color: white;
}

/* Branch input */
.ai-branch-input {
    display: none;
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #e0e0e0;
}

.ai-branch-input.active {
    display: block;
}

.ai-branch-input textarea {
    width: 100%;
    padding: 10px;
    border: 2px solid #2271b1;
    border-radius: 4px;
    resize: vertical;
    min-height: 60px;
    font-family: inherit;
    margin-bottom: 10px;
}

.ai-branch-input button {
    margin-right: 5px;
    padding: 8px 16px;
    background: #2271b1;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.ai-branch-input button:hover {
    background: #135e96;
}

.prompt-dropdown {
    margin-top: 10px;
}

.prompt-dropdown select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #2271b1;
    border-radius: 4px;
    background: white;
    color: #333;
    cursor: pointer;
}

/* Loading state */
.ai-loading {
    display: inline-block;
    padding: 10px;
    color: #666;
    font-style: italic;
}

.ai-loading::after {
    content: '...';
    animation: dots 1.5s infinite;
}

@keyframes dots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 100% { content: '...'; }
}

/* Modals */
.ai-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.ai-modal-content {
    background: white;
    padding: 30px;
    border-radius: 8px;
    max-width: 900px;
    max-height: 80vh;
    overflow-y: auto;
    width: 90%;
}

.ai-modal-content h3 {
    margin-top: 0;
    color: #333;
    border-bottom: 2px solid #e0e0e0;
    padding-bottom: 10px;
}

.ai-modal-close {
    margin-top: 20px;
    padding: 10px 20px;
    background: #2271b1;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.ai-modal-close:hover {
    background: #135e96;
}

/* Session items */
.session-item {
    padding: 15px;
    margin: 10px 0;
    background: #f0f0f1;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.session-item:hover {
    background: #2271b1;
    color: white;
}

.session-item strong {
    display: block;
    margin-bottom: 5px;
}

.session-item small {
    opacity: 0.8;
}

.session-actions {
    display: flex;
    gap: 5px;
    flex-shrink: 0;
}

.session-actions button {
    padding: 5px 10px;
    color: white;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
}

.session-export-btn {
    background: #2271b1;
}

.session-export-btn:hover {
    background: #135e96;
}

.session-delete-btn {
    background: #d63638;
}

.session-delete-btn:hover {
    background: #b32d2e;
}

/* Prompt manager */
.prompt-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    border-bottom: 2px solid #e0e0e0;
}

.prompt-tab {
    padding: 10px 20px;
    background: none;
    border: none;
    cursor: pointer;
    color: #666;
    font-size: 14px;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
}

.prompt-tab.active {
    color: #2271b1;
    border-bottom-color: #2271b1;
}

.prompt-filters {
    display: flex;
    gap: 15px;
    margin-bottom: 15px;
    align-items: center;
}

.prompt-filters select {
    padding: 5px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.prompt-item {
    padding: 15px;
    margin: 10px 0;
    background: #f9f9f9;
    border-radius: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.prompt-item:hover {
    background: #e0e0e0;
}

.prompt-item-content {
    flex: 1;
}

.prompt-item-name {
    font-weight: 600;
    margin-bottom: 5px;
}

.prompt-item-text {
    color: #666;
    font-size: 13px;
}

.prompt-item-meta {
    display: flex;
    gap: 10px;
    margin-top: 5px;
    font-size: 12px;
    color: #999;
}

.filter-info {
    background: #e7f3ff;
    border: 1px solid #b8daff;
    border-radius: 4px;
    padding: 8px 12px;
    margin-bottom: 15px;
    font-size: 13px;
    color: #0c5aa6;
    text-align: center;
}

.prompt-item-actions {
    display: flex;
    gap: 5px;
}

.prompt-item-actions button {
    padding: 5px 10px;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    font-size: 12px;
}

.btn-favorite {
    background: #f0f0f0;
    color: #999;
    border: 1px solid #ddd;
    font-size: 14px;
    font-weight: bold;
}

.btn-favorite:hover {
    background: #e8e8e8;
    color: #666;
}

.btn-favorite.active {
    background: #ff6b35;
    color: white;
    border-color: #ff6b35;
    box-shadow: 0 0 8px rgba(255, 107, 53, 0.3);
}

.btn-favorite.active:hover {
    background: #e55a2b;
    border-color: #e55a2b;
}

.btn-use {
    background: #2271b1;
    color: white;
}

.btn-edit {
    background: #666;
    color: white;
}

.btn-copy {
    background: #6c5ce7;
    color: white;
}

.btn-copy:hover {
    background: #5f4de0;
}

.btn-copy-success {
    background: #28a745 !important;
    color: white !important;
}

.btn-copy-error {
    background: #dc3545 !important;
    color: white !important;
}

.btn-delete {
    background: #d63638;
    color: white;
}

/* Add prompt form */
.add-prompt-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.add-prompt-form input,
.add-prompt-form textarea,
.add-prompt-form select {
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-family: inherit;
}

.add-prompt-form button {
    padding: 10px 20px;
    background: #2271b1;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.add-prompt-form button:hover {
    background: #135e96;
}

/* Import/Export section */
.import-export-section h4 {
    margin-top: 20px;
    margin-bottom: 10px;
    color: #333;
}

.import-export-section p {
    color: #666;
    margin-bottom: 10px;
}

.import-export-section textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-family: monospace;
    font-size: 12px;
}

/* Export and import button containers */
.export-buttons,
.import-buttons {
    display: flex;
    gap: 10px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.import-export-section button {
    padding: 10px 20px;
    background: #2271b1;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.import-export-section button:hover {
    background: #135e96;
}

/* Warning and danger button styles */
.button-warning {
    background: #ff8c00 !important;
}

.button-warning:hover {
    background: #ff7700 !important;
}

.button-danger {
    background: #dc3545 !important;
}

.button-danger:hover {
    background: #c82333 !important;
}

.button-secondary {
    background: #6c757d !important;
    color: white !important;
}

.button-secondary:hover {
    background: #5a6268 !important;
    color: white !important;
}

/* Warning modal styles */
#replace-warning-modal .ai-modal-content {
    max-width: 500px;
}

#replace-warning-modal h3 {
    color: #dc3545;
    margin-bottom: 15px;
}

#replace-warning-modal p {
    margin-bottom: 15px;
    line-height: 1.5;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}

/* Manage Prompts buttons */
.manage-prompts-btn {
    background: #6c5ce7 !important;
    color: white !important;
    border: none !important;
    padding: 8px 12px !important;
    border-radius: 4px !important;
    cursor: pointer !important;
    font-size: 12px !important;
}

.manage-prompts-btn:hover {
    background: #5f4de0 !important;
}

/* Main interface manage prompts button */
#main-manage-prompts-btn {
    margin-left: 8px;
}

/* Branch and continue area manage prompts buttons */
.ai-branch-input .manage-prompts-btn {
    margin-left: 8px;
}

/* Sticky filter header for long prompt lists */
.prompt-filters-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 12px 15px;
    margin-bottom: 15px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.prompt-filters {
    display: flex;
    align-items: center;
    gap: 15px;
    flex: 1;
}

/* Mobile responsiveness for filter header */
@media (max-width: 768px) {
    .prompt-filters-header {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        padding: 10px;
    }
    
    .prompt-filters {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    
    .prompt-filters select {
        width: 100%;
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    .prompt-filters label {
        display: flex;
        align-items: center;
        gap: 8px;
        font-size: 14px;
    }
}

/* Top close button styling */
.ai-modal-close-top {
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 18px;
    font-weight: bold;
    transition: all 0.2s ease;
    flex-shrink: 0;
    min-width: 32px; /* Prevents compression */
}

.ai-modal-close-top:hover {
    background: #c82333;
    transform: scale(1.1);
}

.ai-modal-close-top .close-icon {
    line-height: 1;
    font-family: Arial, sans-serif;
}

/* Mobile optimization for close button */
@media (max-width: 768px) {
    .ai-modal-close-top {
        width: 44px;
        height: 44px;
        font-size: 20px;
        min-width: 44px;
        align-self: flex-end; /* Align to right when header stacks */
    }
}

/* Ensure modal content has proper scrolling */
.ai-modal-content {
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
}

/* Back to top button */
.back-to-top-btn {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background: #6c5ce7;
    color: white;
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(108, 92, 231, 0.3);
    transition: all 0.3s ease;
}

.back-to-top-btn:hover {
    background: #5f4de0;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(108, 92, 231, 0.4);
}

.back-to-top-btn span {
    display: block;
    line-height: 1;
}

/* Mobile optimization for back to top button */
@media (max-width: 768px) {
    .back-to-top-btn {
        width: 44px;
        height: 44px;
        bottom: 20px;
        right: 20px;
        font-size: 18px;
    }
}

/* Enhanced filter info styling */
.filter-info {
    background: #e3f2fd;
    border: 1px solid #2196f3;
    border-radius: 4px;
    padding: 8px 12px;
    margin-bottom: 15px;
    font-size: 14px;
    color: #1976d2;
}

/* Smooth scrolling for better UX */
.ai-modal-content {
    scroll-behavior: smooth;
}

/* Mobile modal optimizations */
@media (max-width: 768px) {
    .ai-modal-content {
        width: 95%;
        max-width: none;
        margin: 20px auto;
        max-height: 85vh;
        border-radius: 8px;
    }
    
    .ai-modal {
        padding: 10px;
    }
    
    /* Better tap targets for mobile */
    .prompt-item {
        padding: 15px 12px;
        margin-bottom: 8px;
    }
    
    .prompt-item-actions {
        gap: 8px;
    }
    
    .prompt-item-actions button {
        padding: 8px 12px;
        font-size: 14px;
        min-height: 44px; /* Apple's recommended minimum tap target */
    }
    
    /* Manage prompts buttons mobile optimization */
    .manage-prompts-btn {
        padding: 10px 14px !important;
        font-size: 14px !important;
        min-height: 44px;
    }
    
    #main-manage-prompts-btn {
        margin-left: 6px;
        margin-top: 8px;
    }
    
    /* Textarea improvements for mobile */
    .ai-branch-input textarea,
    #ai-prompt {
        font-size: 16px; /* Prevents zoom on iOS */
        min-height: 44px;
    }
}

/* Comprehensive export sections */
.comprehensive-export-section,
.sessions-export-section {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    padding: 15px;
    margin: 15px 0;
}

.comprehensive-export-section h4,
.sessions-export-section h4 {
    margin-top: 0;
    margin-bottom: 10px;
    color: #0073aa;
    font-size: 16px;
}

.comprehensive-export-section p,
.sessions-export-section p {
    margin: 0 0 12px 0;
    font-size: 14px;
    color: #555;
}

.comprehensive-export-section .button-secondary,
.sessions-export-section .button-secondary {
    display: inline-block;
    padding: 8px 16px;
    background: #0073aa;
    color: white;
    text-decoration: none;
    border-radius: 4px;
    font-size: 14px;
    transition: background-color 0.2s;
}

.comprehensive-export-section .button-secondary:hover,
.sessions-export-section .button-secondary:hover {
    background: #005a87;
    color: white;
}

/* Notice for non-admin users */
.ai-chat-branch-notice {
    padding: 20px;
    background: #f0f0f1;
    border-left: 4px solid #d63638;
    margin: 20px 0;
}

.ai-chat-branch-notice strong {
    color: #d63638;
}

.ai-chat-branch-notice a {
    color: #2271b1;
    text-decoration: none;
}

.ai-chat-branch-notice a:hover {
    text-decoration: underline;
}

/* Edit Prompt Modal Styles */
.edit-prompt-form {
    max-width: 600px;
}

.edit-prompt-form .form-group {
    margin-bottom: 15px;
}

.edit-prompt-form label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: #333;
}

.edit-prompt-form .full-width {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    font-family: inherit;
}

.edit-prompt-form textarea.full-width {
    resize: vertical;
    min-height: 120px;
    font-family: inherit;
}

.category-selector {
    display: flex;
    gap: 10px;
    align-items: center;
}

.category-dropdown {
    flex: 1;
}

.form-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid #eee;
}

.button-primary {
    background: #2271b1;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
}

.button-primary:hover {
    background: #135e96;
}

.button-secondary {
    background: #f7f7f7;
    color: #333;
    border: 1px solid #ccd0d4;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
}

.button-secondary:hover {
    background: #fafafa;
    border-color: #999;
}

/* Category Management Modal Styles */
.category-tabs {
    display: flex;
    margin-bottom: 20px;
    border-bottom: 1px solid #ddd;
}

.category-tab {
    padding: 10px 20px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    border-bottom: 2px solid transparent;
}

.category-tab.active {
    border-bottom-color: #2271b1;
    color: #2271b1;
    font-weight: 500;
}

.category-tab:hover {
    background: #f5f5f5;
}

.category-tab-content {
    min-height: 300px;
}

.help-text {
    color: #666;
    font-style: italic;
    margin-bottom: 15px;
}

.category-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    border: 1px solid #ddd;
    border-radius: 4px;
    margin-bottom: 10px;
    background: #fafafa;
}

.category-info h4 {
    margin: 0 0 5px 0;
    font-size: 16px;
    color: #333;
}

.category-info p {
    margin: 0;
    font-size: 13px;
    color: #666;
}

.category-actions {
    display: flex;
    gap: 8px;
}

.category-actions button {
    padding: 6px 12px;
    font-size: 12px;
}

.category-delete {
    background: #dc3545 !important;
    color: white !important;
    border-color: #dc3545 !important;
}

.category-delete:hover {
    background: #c82333 !important;
    color: white !important;
    border-color: #c82333 !important;
}

.add-category-form {
    max-width: 500px;
}

/* Responsive adjustments for new modals */
@media (max-width: 768px) {
    .edit-prompt-form,
    .add-category-form {
        max-width: none;
    }
    
    .category-selector {
        flex-direction: column;
        align-items: stretch;
    }
    
    .form-actions {
        flex-direction: column;
    }
    
    .category-item {
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
    }
    
    .category-actions {
        justify-content: center;
    }
}

/* Inline Category Management in Main Modal */
.category-management {
    max-width: 600px;
}

.category-actions-bar {
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid #ddd;
}

.add-category-inline {
    padding: 15px;
    background: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 4px;
    margin-bottom: 20px;
}

.category-item-simple {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    margin-bottom: 8px;
    background: #fafafa;
}

.category-actions-simple {
    display: flex;
    gap: 6px;
}

.btn-small {
    padding: 4px 8px !important;
    font-size: 11px !important;
}

/* Update existing category tab content to have more space */
#prompt-tab-categories {
    min-height: 400px;
    padding: 10px 0;
}

/* Emergency CSS to hide any empty shortcode containers that might be created by page builders */
div:empty {
    /* Only target divs that might be shortcode containers */
}

/* Specific targeting for potential Elementor shortcode containers */
.elementor-shortcode:empty,
.elementor-widget-shortcode:empty,
div[data-id*="ai_tree"]:empty,
.wp-block-shortcode:empty {
    display: none !important;
    height: 0 !important;
    width: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    background: none !important;
    min-height: 0 !important;
    line-height: 0 !important;
}

/* Target any container that only contains whitespace or empty ai_tree shortcode */
*:only-child:empty {
    /* Only apply if it's the only child and empty - be very specific */
}

/* Healthcare Variables Tab Styles */
.healthcare-variables-section {
    padding: 0;
}

.healthcare-intro {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    padding: 20px;
    margin-bottom: 25px;
}

.healthcare-intro h4 {
    color: #0073aa;
    margin-top: 0;
    margin-bottom: 12px;
    font-size: 18px;
}

.healthcare-intro > p {
    color: #555;
    font-size: 14px;
    line-height: 1.5;
    margin-bottom: 20px;
}

.available-placeholders {
    margin-bottom: 20px;
}

.available-placeholders h5 {
    color: #333;
    margin-bottom: 10px;
    font-size: 14px;
    font-weight: 600;
}

.placeholder-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.placeholder-tag {
    background: #e3f2fd;
    color: #1565c0;
    padding: 4px 8px;
    border-radius: 12px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    font-weight: 500;
    border: 1px solid #bbdefb;
}

/* Content placeholders info section */
.content-placeholders-info {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    padding: 12px;
    margin: 10px 0 15px 0;
}

.content-placeholders-info p {
    margin: 0 0 8px 0;
    color: #6c757d;
}

.content-placeholders-info .placeholder-tags.small {
    gap: 6px;
}

.content-placeholders-info .placeholder-tags.small .placeholder-tag {
    font-size: 11px;
    padding: 3px 6px;
}

/* Enhanced posts styling */
.post-item.post-enhanced {
    opacity: 0.6;
    background-color: #f8f9fa;
    border-left: 3px solid #28a745;
}

.post-item.post-enhanced input[type="checkbox"] {
    opacity: 0.5;
}

.enhanced-indicator {
    color: #28a745;
    font-size: 12px;
    font-weight: 500;
    margin-left: 8px;
}

/* Post status badges */
.post-status-badge {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 600;
    margin-left: 8px;
    text-transform: uppercase;
}

.post-status-badge.status-publish {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.post-status-badge.status-draft {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffeaa7;
}

.post-status-badge.status-future {
    background: #cfe2ff;
    color: #084298;
    border: 1px solid #b6d4fe;
}

.post-status-badge.status-pending {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

/* Enhancement history clickable links */
.history-post-link {
    color: #0073aa;
    text-decoration: none;
}

.history-post-link:hover {
    color: #005a87;
    text-decoration: underline;
}

.external-link {
    font-size: 12px;
    margin-left: 4px;
    opacity: 0.7;
}

.healthcare-notice {
    background: #fff3cd;
    border: 1px solid #ffeaa7;
    border-radius: 4px;
    padding: 12px;
    color: #856404;
    font-size: 14px;
    margin: 0;
}

.healthcare-variables-form {
    margin-top: 0;
}

.variables-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 25px;
}

.variable-group {
    display: flex;
    flex-direction: column;
}

.variable-group.full-width {
    grid-column: 1 / -1;
}

.variable-group.age-range-group {
    grid-column: 1 / -1;
    background: #f8f9fa;
    padding: 15px;
    border-radius: 6px;
    border: 1px solid #dee2e6;
}

.variable-group label {
    display: block;
    font-weight: 600;
    color: #333;
    margin-bottom: 8px;
    font-size: 14px;
}

.variable-counter {
    font-weight: normal;
    color: #666;
    font-size: 12px;
}

.variable-group textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
    font-family: inherit;
    resize: vertical;
    line-height: 1.4;
    box-sizing: border-box;
}

.variable-group textarea:focus {
    border-color: #0073aa;
    outline: none;
    box-shadow: 0 0 0 2px rgba(0, 115, 170, 0.2);
}

.age-range-inputs {
    display: flex;
    gap: 20px;
    align-items: center;
}

.age-input-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.age-input-group label {
    margin-bottom: 0;
    font-size: 13px;
    white-space: nowrap;
}

.age-input-group input {
    width: 80px;
    padding: 6px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    text-align: center;
}

.age-input-group input:focus {
    border-color: #0073aa;
    outline: none;
    box-shadow: 0 0 0 2px rgba(0, 115, 170, 0.2);
}

.healthcare-actions {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 25px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 6px;
    border: 1px solid #dee2e6;
}

.healthcare-actions button {
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.healthcare-actions .button-primary {
    background: #0073aa;
    color: white;
}

.healthcare-actions .button-primary:hover {
    background: #005a87;
}

.healthcare-actions .button-secondary {
    background: #6c757d;
    color: white;
    border: 1px solid #6c757d;
}

.healthcare-actions .button-secondary:hover {
    background: #5a6268;
    border-color: #5a6268;
}

.save-status {
    font-size: 13px;
    font-weight: 500;
    margin-left: 10px;
}

.healthcare-test-section {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    padding: 20px;
    margin-top: 15px;
}

.healthcare-test-section h5 {
    color: #0073aa;
    margin-top: 0;
    margin-bottom: 10px;
    font-size: 16px;
}

.healthcare-test-section p {
    color: #555;
    font-size: 14px;
    margin-bottom: 15px;
}

.healthcare-test-section textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    font-family: inherit;
    margin-bottom: 15px;
    resize: vertical;
    box-sizing: border-box;
}

.healthcare-test-section textarea:focus {
    border-color: #0073aa;
    outline: none;
    box-shadow: 0 0 0 2px rgba(0, 115, 170, 0.2);
}

.healthcare-test-section button {
    padding: 8px 16px;
    background: #0073aa;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 15px;
}

.healthcare-test-section button:hover {
    background: #005a87;
}

.test-result {
    margin-top: 15px;
}

.test-success {
    background: #d4edda;
    border: 1px solid #c3e6cb;
    border-radius: 4px;
    padding: 15px;
    color: #155724;
}

.test-success h6 {
    margin: 0 0 10px 0;
    font-size: 14px;
    font-weight: 600;
    color: #0f5132;
}

.processed-text {
    background: #fff;
    border: 1px solid #c3e6cb;
    border-radius: 4px;
    padding: 12px;
    margin-bottom: 15px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.replacements-list {
    margin: 0;
    padding-left: 20px;
}

.replacements-list li {
    margin-bottom: 5px;
    font-size: 13px;
}

.replacements-list code {
    background: #e9ecef;
    padding: 2px 4px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
}

.test-error {
    background: #f8d7da;
    border: 1px solid #f5c6cb;
    border-radius: 4px;
    padding: 15px;
    color: #721c24;
}

.test-error h6 {
    margin: 0 0 10px 0;
    font-size: 14px;
    font-weight: 600;
    color: #5a1a1a;
}

.test-error p {
    margin-bottom: 10px;
    font-size: 14px;
}

.test-error ul {
    margin: 0 0 10px 0;
    padding-left: 20px;
}

.test-error li {
    margin-bottom: 3px;
    font-size: 13px;
}

.loading {
    color: #666;
    font-style: italic;
    padding: 10px;
    text-align: center;
}

.error {
    color: #dc3545;
    font-weight: 500;
    padding: 10px;
    text-align: center;
}

/* Mobile Responsiveness for Healthcare Variables */
@media (max-width: 768px) {
    .variables-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .variable-group.full-width,
    .variable-group.age-range-group {
        grid-column: 1;
    }
    
    .placeholder-tags {
        gap: 6px;
    }
    
    .placeholder-tag {
        font-size: 11px;
        padding: 3px 6px;
    }
    
    .age-range-inputs {
        flex-direction: column;
        align-items: stretch;
        gap: 15px;
    }
    
    .age-input-group {
        justify-content: space-between;
    }
    
    .age-input-group input {
        width: 100px;
    }
    
    .healthcare-actions {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    
    .healthcare-actions button {
        margin: 0;
    }
    
    .save-status {
        margin-left: 0;
        text-align: center;
    }
    
    .healthcare-intro,
    .healthcare-test-section,
    .variable-group.age-range-group {
        padding: 15px;
    }
    
    /* Larger tap targets for mobile */
    .variable-group textarea {
        font-size: 16px; /* Prevents zoom on iOS */
        min-height: 100px;
    }
    
    .healthcare-test-section textarea {
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    .age-input-group input {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 10px;
        min-height: 44px; /* Apple's recommended minimum */
    }
    
    .healthcare-actions button,
    .healthcare-test-section button {
        min-height: 44px; /* Apple's recommended minimum */
        padding: 12px 20px;
    }
}

/* Extra small screens */
@media (max-width: 480px) {
    .healthcare-intro,
    .healthcare-test-section,
    .variable-group.age-range-group,
    .healthcare-actions {
        padding: 12px;
    }
    
    .healthcare-intro h4 {
        font-size: 16px;
    }
    
    .available-placeholders h5 {
        font-size: 13px;
    }
    
    .placeholder-tag {
        font-size: 10px;
        padding: 2px 5px;
    }
    
    .variable-group label {
        font-size: 13px;
    }
    
    .variable-counter {
        font-size: 11px;
    }
}

/* Healthcare processed indicator */
.healthcare-processed-indicator {
    background: #e3f2fd;
    color: #1565c0;
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 12px;
    margin-left: 8px;
    cursor: help;
    display: inline-block;
    font-style: normal;
    border: 1px solid #bbdefb;
}

.healthcare-processed-indicator:hover {
    background: #bbdefb;
}

/* Placeholder Preview Modal Styles */
.placeholder-preview-intro {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    padding: 12px;
    margin-bottom: 20px;
    color: #555;
    font-size: 14px;
}

.placeholder-preview-form {
    margin-bottom: 25px;
}

.placeholder-field {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    padding: 8px;
    background: #f9f9f9;
    border-radius: 4px;
    border: 1px solid #e0e0e0;
}

.placeholder-field-label {
    font-weight: 600;
    color: #333;
    min-width: 80px;
    font-size: 13px;
    text-align: right;
}

.placeholder-field-input {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid #ddd;
    border-radius: 3px;
    font-size: 14px;
    background: #fff;
}

.placeholder-field-input:focus {
    border-color: #0073aa;
    outline: none;
    box-shadow: 0 0 0 2px rgba(0, 115, 170, 0.2);
}

.placeholder-reroll-btn {
    background: #e3f2fd;
    color: #1565c0;
    border: 1px solid #bbdefb;
    border-radius: 3px;
    padding: 4px 8px;
    cursor: pointer;
    font-size: 12px;
    min-width: 32px;
    text-align: center;
    transition: all 0.2s ease;
}

.placeholder-reroll-btn:hover {
    background: #bbdefb;
    transform: scale(1.1);
}

.placeholder-preview-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    padding-top: 15px;
    border-top: 1px solid #eee;
}

.placeholder-preview-actions button {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.placeholder-preview-actions .button-primary {
    background: #0073aa;
    color: white;
}

.placeholder-preview-actions .button-primary:hover {
    background: #005a87;
}

.placeholder-preview-actions .button-secondary {
    background: #6c757d;
    color: white;
    border: 1px solid #6c757d;
}

.placeholder-preview-actions .button-secondary:hover {
    background: #5a6268;
    border-color: #5a6268;
}

/* Mobile responsiveness for placeholder preview */
@media (max-width: 768px) {
    .placeholder-field {
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
    }
    
    .placeholder-field-label {
        text-align: left;
        min-width: auto;
        font-weight: 600;
    }
    
    .placeholder-preview-actions {
        flex-direction: column;
        gap: 8px;
    }
    
    .placeholder-preview-actions button {
        padding: 12px 16px;
        font-size: 14px;
    }
}

/* Content Enhancement Styles */
.content-enhancement-section {
    padding: 15px;
}

.enhancement-intro {
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 1px solid #eee;
}

.enhancement-intro h4 {
    margin: 0 0 10px 0;
    color: #333;
}

.enhancement-intro p {
    margin: 0;
    color: #666;
    font-size: 14px;
}

.enhancement-workflow {
    margin-bottom: 30px;
}

.workflow-step {
    margin-bottom: 25px;
    padding: 20px;
    background: #f9f9f9;
    border-radius: 6px;
    border-left: 4px solid #0073aa;
}

.workflow-step h5 {
    margin: 0 0 15px 0;
    color: #0073aa;
    font-size: 16px;
}

.post-selection {
    margin-bottom: 15px;
}

.post-search {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
    align-items: center;
}

.post-search .search-input-wrapper {
    flex: 1;
}

.post-status-filters {
    display: flex;
    gap: 15px;
    align-items: center;
    padding: 10px 12px;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.post-status-filters > label:first-child {
    font-weight: 600;
    color: #333;
    margin-right: 5px;
}

.post-status-filters label {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 14px;
    color: #555;
    cursor: pointer;
    user-select: none;
}

.post-status-filters input[type="checkbox"] {
    cursor: pointer;
    width: 16px;
    height: 16px;
}

.post-search input {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.post-search select {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    min-width: 120px;
}

.posts-list {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
}

.post-item {
    display: flex;
    align-items: center;
    padding: 12px;
    border-bottom: 1px solid #eee;
    transition: background-color 0.2s;
}

.post-item:hover {
    background-color: #f5f5f5;
}

.post-item:last-child {
    border-bottom: none;
}

.post-item input[type="checkbox"] {
    margin-right: 12px;
}

.post-info {
    flex: 1;
}

.post-title {
    font-weight: 600;
    color: #333;
    margin-bottom: 4px;
}

.post-excerpt {
    color: #666;
    font-size: 13px;
    margin-bottom: 4px;
}

.post-meta {
    color: #999;
    font-size: 12px;
}

.post-slug {
    color: #666;
    font-family: monospace;
    background: #f0f0f0;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 11px;
}

.post-link {
    color: #0073aa;
    text-decoration: none;
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 3px;
    transition: background-color 0.2s;
}

.post-link:hover {
    background-color: #f0f0f0;
    text-decoration: none;
}

.search-input-wrapper {
    position: relative;
    display: inline-block;
    flex: 1;
}

.search-input-wrapper input {
    width: 100%;
    padding-right: 35px;
}

.clear-search-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: #999;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
}

.clear-search-btn:hover {
    color: #333;
}

.clear-search-btn:focus {
    outline: 2px solid #0073aa;
    outline-offset: 2px;
}

.no-posts {
    padding: 40px;
    text-align: center;
    color: #666;
    font-style: italic;
}

.selected-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px;
    background: #e3f2fd;
    border-radius: 4px;
    margin-top: 10px;
}

.selected-summary strong {
    color: #0073aa;
}

.button-small {
    padding: 4px 8px;
    font-size: 12px;
    background: #666;
    color: white;
    border: none;
    border-radius: 3px;
    cursor: pointer;
}

.button-small:hover {
    background: #555;
}

.enhancement-settings {
    display: grid;
    gap: 20px;
}

.setting-group label {
    display: block;
    margin-bottom: 8px;
    color: #333;
}

.setting-group select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.prompt-preview {
    margin-top: 15px;
    padding: 15px;
    background: #f0f8ff;
    border-radius: 4px;
    border: 1px solid #b3d9ff;
}

.prompt-preview h6 {
    margin: 0 0 10px 0;
    color: #0073aa;
}

.prompt-preview-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
}

.prompt-preview-toggle:hover {
    background-color: rgba(0, 115, 170, 0.1);
    padding: 5px;
    border-radius: 3px;
}

.toggle-icon {
    transition: transform 0.3s ease;
    font-size: 12px;
}

.toggle-icon.expanded {
    transform: rotate(180deg);
}

.collapsible-content {
    max-height: 150px;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.collapsible-content.expanded {
    max-height: none;
}

.prompt-preview-text {
    background: white;
    padding: 10px;
    border-radius: 3px;
    border: 1px solid #ddd;
    font-family: monospace;
    font-size: 13px;
    line-height: 1.4;
    white-space: pre-wrap;
}

.placeholder-info {
    margin-top: 10px;
    font-size: 12px;
    color: #666;
}

.enhancement-actions {
    display: flex;
    gap: 10px;
}

.enhancement-actions button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.enhancement-preview {
    margin-top: 20px;
    padding: 15px;
    background: #f9f9f9;
    border-radius: 4px;
    border: 1px solid #ddd;
}

.enhancement-preview h6 {
    margin: 0 0 15px 0;
    color: #333;
}

.preview-content {
    display: grid;
    gap: 15px;
}

.preview-section strong {
    display: block;
    margin-bottom: 8px;
    color: #333;
}

.content-preview {
    background: white;
    padding: 15px;
    border-radius: 4px;
    border: 1px solid #ddd;
    max-height: 200px;
    overflow-y: auto;
    font-size: 14px;
    line-height: 1.5;
}

.progress-section {
    margin-top: 20px;
    padding: 20px;
    background: #f0f8ff;
    border-radius: 4px;
    border: 1px solid #b3d9ff;
}

.progress-section h6 {
    margin: 0 0 15px 0;
    color: #0073aa;
}

.progress-bar {
    width: 100%;
    height: 20px;
    background: #e0e0e0;
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 10px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #0073aa, #005177);
    border-radius: 10px;
    width: 0%;
    transition: width 0.3s ease;
}

.progress-text {
    text-align: center;
    color: #333;
    font-weight: 500;
    margin-bottom: 10px;
}

.progress-results {
    font-size: 13px;
    color: #666;
}

.enhancement-history {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid #eee;
}

.enhancement-history h5 {
    margin: 0 0 15px 0;
    color: #333;
}

.history-list {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
}

.history-item {
    padding: 12px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.history-item:last-child {
    border-bottom: none;
}

.history-info {
    flex: 1;
}

.history-post-title {
    font-weight: 600;
    color: #333;
    margin-bottom: 4px;
}

.history-details {
    font-size: 13px;
    color: #666;
}

.history-date {
    font-size: 12px;
    color: #999;
    white-space: nowrap;
}

.loading-history {
    padding: 40px;
    text-align: center;
    color: #666;
    font-style: italic;
}

@media (max-width: 768px) {
    .post-search {
        flex-direction: column;
        align-items: stretch;
    }
    
    .enhancement-actions {
        flex-direction: column;
    }
    
    .selected-summary {
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
    }
    
    .preview-content {
        grid-template-columns: 1fr;
    }
}

