/* ===== DECISION TREE AI INTERFACE STYLES ===== */

/* AI Action Buttons */
.tree-ai-actions {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.tree-build-btn {
    flex: 1;
    font-weight: 600;
}

@media (max-width: 768px) {
    .tree-ai-actions {
        flex-direction: column;
    }
}

/* AI Interface Container - Floating Modal */
.tree-ai-interface {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2001;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.tree-ai-interface.active {
    display: flex;
    opacity: 1;
}

.tree-ai-interface.hidden {
    display: none;
}

/* Modal Dialog */
.tree-ai-dialog {
    background: var(--bg-secondary);
    border-radius: 0.75rem;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    width: 90%;
    max-width: 900px;
    max-height: 90vh;
    height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.tree-ai-interface.active .tree-ai-dialog {
    transform: scale(1);
}

/* Mobile: Match modal-content.large behavior */
@media (max-width: 768px) {
    .tree-ai-interface {
        align-items: flex-end;
    }

    .tree-ai-dialog {
        width: 90%;
        max-width: 500px;
        max-height: 90vh;
        border-radius: 20px 20px 0 0;
        animation: slideUp 0.3s ease-out;
    }

    .tree-ai-interface.active .tree-ai-dialog {
        transform: scale(1) translateY(0);
    }
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

/* AI Header */
.tree-ai-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: linear-gradient(135deg, rgba(212, 175, 55, 0.1), rgba(255, 215, 0, 0.1));
    border-bottom: 1px solid var(--border-color);
}

.tree-ai-header h4 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--text-primary);
}

.tree-ai-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.25rem;
    transition: all 0.2s;
}

/* Wizard Stepper */
.tree-ai-stepper {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1.5rem 1rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-primary);
}

/* Desktop: Stepper inline with header */
@media (min-width: 769px) {
    .tree-ai-header {
        padding: 1rem 1.5rem;
    }

    .tree-ai-stepper {
        border-bottom: none;
        background: transparent;
        padding: 0;
        flex: 1;
        justify-content: flex-end;
        gap: 1rem;
    }
}

/* Mobile: Show stepper separately below header */
@media (max-width: 768px) {
    .tree-ai-header {
        flex-wrap: wrap;
    }

    .tree-ai-header h4 {
        display: none;
    }

    .tree-ai-stepper {
        order: 3;
        width: 100%;
        border-top: 1px solid var(--border-color);
        padding: 1rem;
        background: var(--bg-primary);
        justify-content: center;
    }

    .tree-ai-close {
        order: 2;
    }
}

.tree-ai-step {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.tree-ai-step-number {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #e0e0e0;
    color: #666;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.3s;
}

.tree-ai-step.active .tree-ai-step-number {
    background: linear-gradient(135deg, var(--gold-start), var(--gold-end));
    color: white;
    box-shadow: 0 2px 8px rgba(212, 175, 55, 0.3);
}

.tree-ai-step.completed .tree-ai-step-number {
    background: linear-gradient(135deg, var(--gold-start), var(--gold-end));
    color: white;
}

.tree-ai-step-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.tree-ai-step.active .tree-ai-step-label {
    color: var(--text-primary);
    font-weight: 600;
}

.tree-ai-step-connector {
    width: 40px;
    height: 2px;
    background: #e0e0e0;
    margin: 0 0.5rem;
}

.tree-ai-step.completed ~ .tree-ai-step .tree-ai-step-connector {
    background: linear-gradient(135deg, var(--gold-start), var(--gold-end));
}

.tree-ai-close:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-primary);
}

/* Messages Container */
.tree-ai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background: var(--bg-primary);
    min-height: 0;
}

.tree-ai-message {
    margin-bottom: 1rem;
    display: flex;
    gap: 0.5rem;
}

.tree-ai-message.user {
    flex-direction: row-reverse;
}

.tree-ai-message-bubble {
    max-width: 75%;
    padding: 0.75rem 1rem;
    border-radius: 1rem;
    line-height: 1.5;
    word-wrap: break-word;
}

.tree-ai-message.user .tree-ai-message-bubble {
    background: linear-gradient(135deg, var(--gold-start), var(--gold-end));
    color: white;
    border-bottom-right-radius: 0.25rem;
}

.tree-ai-message.assistant .tree-ai-message-bubble {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-bottom-left-radius: 0.25rem;
}

.tree-ai-message.error .tree-ai-message-bubble {
    background: rgba(244, 67, 54, 0.1);
    border: 1px solid #F44336;
    color: #F44336;
}

/* Loading Spinner Animation - kb-spinner style */
.tree-ai-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top-color: var(--gold-start);
    border-radius: 50%;
    animation: tree-ai-spin 0.8s linear infinite;
    flex-shrink: 0;
}

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

/* Legacy Loading Dots Animation - kept for backwards compatibility */
.loading-dots {
    display: inline-flex;
    gap: 0.25rem;
}

.loading-dots span {
    animation: loadingDot 1.4s infinite;
    font-size: 1.5rem;
}

.loading-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.loading-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes loadingDot {
    0%, 80%, 100% { opacity: 0.3; }
    40% { opacity: 1; }
}

/* Wizard Footer/Actions */
.tree-ai-wizard-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-top: 1px solid var(--border-color);
    background: var(--bg-primary);
    flex-shrink: 0;
}

.tree-ai-wizard-actions {
    display: flex;
    gap: 0.75rem;
}

.tree-ai-wizard-actions button {
    padding: 0.75rem 1.5rem;
    border-radius: 0.5rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.tree-ai-wizard-actions .btn-back {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.tree-ai-wizard-actions .btn-back:hover:not(:disabled) {
    background: var(--bg-primary);
}

.tree-ai-wizard-actions .btn-skip {
    background: var(--bg-secondary);
    border: 1px solid var(--gold-start);
    color: var(--gold-start);
}

.tree-ai-wizard-actions .btn-skip:hover:not(:disabled) {
    background: rgba(212, 175, 55, 0.1);
}

.tree-ai-wizard-actions button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Back Button (outside wizard-actions) */
.btn-back {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.75rem 1.5rem;
    border-radius: 0.5rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-back:hover:not(:disabled) {
    background: var(--bg-primary);
}

.btn-back:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Prompt Templates */
.tree-ai-templates {
    position: absolute;
    right: 1rem;
    bottom: 8rem;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.5rem;
    z-index: 100;
    pointer-events: none;
}

.tree-ai-templates.hidden {
    display: none;
}

.tree-ai-templates-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
    margin-bottom: 0.25rem;
    pointer-events: auto;
}

.tree-ai-template-btn {
    padding: 0.5rem 1rem;
    background: var(--bg-secondary);
    border: 2px solid var(--gold-start);
    border-radius: 20px;
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    pointer-events: auto;
}

.tree-ai-template-btn:hover {
    background: var(--gold-start);
    color: white;
    border-color: var(--gold-end);
    transform: translateX(-4px);
    box-shadow: 0 4px 12px rgba(212, 175, 55, 0.3);
}

.tree-ai-template-btn:active {
    transform: translateX(-2px);
}

/* Mobile: Adjust template position */
@media (max-width: 768px) {
    .tree-ai-templates {
        right: 0.5rem;
        bottom: 5rem;
    }

    .tree-ai-template-btn {
        font-size: 0.8rem;
        padding: 0.4rem 0.85rem;
    }
}

/* Input Container */
/* Input Pill (matches chat-input-pill from ai-styles.css) */
.tree-ai-input-pill {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    background: var(--bg-secondary);
    border-radius: 30px;
    padding: 0.5rem;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    transition: all 0.3s ease;
    border: 2px solid var(--gold-start);
    margin: 0 1rem 1rem 1rem;
    flex-shrink: 0;
}

.tree-ai-input-pill:focus-within {
    box-shadow: 0 4px 20px rgba(212, 175, 55, 0.3);
    border-color: var(--gold-end);
}

.tree-ai-input {
    flex: 1;
    padding: 0.75rem;
    padding-left: 1rem;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9375rem;
    resize: none;
    max-height: 120px;
    overflow-y: auto;
    line-height: 1.5;
    min-height: 20px;
}

.tree-ai-input:focus {
    outline: none;
}

.tree-ai-input::placeholder {
    color: var(--text-secondary);
}

.tree-ai-send-btn {
    width: 38px;
    height: 38px;
    min-width: 38px;
    padding: 0;
    background: var(--gold-start);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.tree-ai-send-btn:hover {
    background: var(--gold-end);
    transform: scale(1.05);
}

.tree-ai-send-btn:active {
    transform: scale(0.95);
}

.tree-ai-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: scale(1);
}

.tree-ai-send-btn svg {
    display: block;
}

/* Preview Container */
.tree-ai-preview-container {
    border-top: 1px solid var(--border-color);
    background: var(--bg-primary);
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.tree-ai-preview-container:not(.hidden) {
    max-height: 500px;
}

.tree-ai-preview {
    padding: 1rem;
}

.tree-ai-preview-header {
    margin-bottom: 1rem;
}

.tree-ai-preview-header h5 {
    margin: 0;
    color: var(--text-primary);
    font-size: 1rem;
}

.tree-ai-preview-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    padding: 1rem;
    margin-bottom: 1rem;
    max-height: 300px;
    overflow-y: auto;
}

.tree-ai-preview-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
}

/* Diff Display */
.tree-ai-diff {
    padding: 1rem;
}

.tree-ai-diff-header {
    background: rgba(212, 175, 55, 0.1);
    padding: 1rem;
    border-radius: 0.5rem 0.5rem 0 0;
    border-bottom: 2px solid var(--gold-start);
    margin: -1rem -1rem 1rem -1rem;
}

.tree-ai-diff-header h5 {
    margin: 0;
    font-size: 1rem;
}

.tree-ai-diff-summary {
    background: var(--bg-primary);
    padding: 1rem;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
}

.diff-item {
    padding: 0.5rem;
    margin: 0.5rem 0;
    border-radius: 0.25rem;
    font-size: 0.9rem;
}

.diff-item strong {
    display: block;
    margin-bottom: 0.25rem;
}

.diff-added {
    background: rgba(76, 175, 80, 0.1);
    border-left: 3px solid #4CAF50;
}

.diff-removed {
    background: rgba(244, 67, 54, 0.1);
    border-left: 3px solid #F44336;
}

.diff-modified {
    background: rgba(255, 152, 0, 0.1);
    border-left: 3px solid #FF9800;
}

.tree-ai-diff-visual {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}

.tree-ai-diff-side {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    padding: 1rem;
    max-height: 300px;
    overflow-y: auto;
}

.tree-ai-diff-side h6 {
    margin: 0 0 0.5rem 0;
    color: var(--text-secondary);
    font-size: 0.85rem;
    text-transform: uppercase;
}

.tree-ai-diff-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

@media (max-width: 768px) {
    .tree-ai-diff-visual {
        grid-template-columns: 1fr;
    }

    .tree-ai-messages {
        max-height: 250px;
    }

    .tree-ai-interface.active {
        max-height: 500px;
    }
}

/* Direct Code Editor */
.tree-code-editor-section {
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
    padding: 1rem;
}

.tree-code-editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.tree-code-editor-header h5 {
    margin: 0;
    color: var(--text-primary);
    font-size: 0.95rem;
}

.btn-toggle {
    background: var(--bg-secondary);
    border: 1px solid var(--gold-start);
    color: var(--gold-start);
    padding: 0.5rem 1rem;
    border-radius: 0.375rem;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 600;
    transition: all 0.2s;
}

.btn-toggle:hover {
    background: rgba(212, 175, 55, 0.1);
}

.tree-code-editor-content {
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.tree-mermaid-code-textarea {
    width: 100%;
    min-height: 300px;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    padding: 0.75rem;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.875rem;
    line-height: 1.5;
    resize: vertical;
    background: var(--bg-primary);
    color: var(--text-primary);
}

.tree-mermaid-code-textarea:focus {
    outline: none;
    border-color: var(--gold-start);
    box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.1);
    background: var(--bg-secondary);
}

.tree-code-editor-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 0.75rem;
}

.tree-code-editor-actions button {
    padding: 0.625rem 1.25rem;
    border-radius: 0.375rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-secondary {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--bg-primary);
}

/* Scrollbar Styling */
.tree-ai-messages::-webkit-scrollbar,
.tree-ai-preview-content::-webkit-scrollbar,
.tree-ai-diff-side::-webkit-scrollbar,
.tree-mermaid-code-textarea::-webkit-scrollbar {
    width: 8px;
}

.tree-ai-messages::-webkit-scrollbar-track,
.tree-ai-preview-content::-webkit-scrollbar-track,
.tree-ai-diff-side::-webkit-scrollbar-track,
.tree-mermaid-code-textarea::-webkit-scrollbar-track {
    background: var(--border-color);
    border-radius: 4px;
}

.tree-ai-messages::-webkit-scrollbar-thumb,
.tree-ai-preview-content::-webkit-scrollbar-thumb,
.tree-ai-diff-side::-webkit-scrollbar-thumb,
.tree-mermaid-code-textarea::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.tree-ai-messages::-webkit-scrollbar-thumb:hover,
.tree-ai-preview-content::-webkit-scrollbar-thumb:hover,
.tree-ai-diff-side::-webkit-scrollbar-thumb:hover,
.tree-mermaid-code-textarea::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Tree Building Spinner - Uses hourglass icon */
.tree-spinner {
    width: 60px;
    height: 60px;
    animation: tree-spin 1.5s linear infinite;
    opacity: 0.7;
}

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

/* Quick AI Action Buttons */
.quick-ai-action-btn:hover {
    border-color: var(--gold-start) !important;
    background: var(--bg-primary) !important;
    transform: translateX(4px);
}

.quick-ai-action-btn:active {
    transform: translateX(2px);
}