/* 
 * Interactive AST Remediation Engine — UI Styles (Phase 4)
 * Scope: .remediation-engine namespace only.
 */

.remediation-engine {
    background: #0F1115;
    /* Deep technical background */
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    font-family: var(--font-body, 'Inter', sans-serif);
    color: #E2E8F0;
    min-height: 640px;
    /* Increased vertical presence */
    width: min(100%, 1180px);
    /* Substantial width */
    margin: 0 auto;
    position: relative;
    /* Clean, non-distracting aesthetic */
}

/* Header */
.remediation-engine .engine-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background: rgba(255, 255, 255, 0.03);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.5px;
}

.remediation-engine .engine-title {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #94A3B8;
}

.remediation-engine .engine-title strong {
    color: #F8FAFC;
    font-weight: 600;
}

.remediation-engine .engine-status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--font-mono, 'JetBrains Mono', monospace);
    font-size: 12px;
    text-transform: uppercase;
    color: #94A3B8;
}

.remediation-engine .status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #475569;
}

.remediation-engine[data-state="IDLE"] .status-dot {
    background: #475569;
}

.remediation-engine[data-state="ANALYZING"] .status-dot {
    background: #3B82F6;
    box-shadow: 0 0 8px rgba(59, 130, 246, 0.6);
}

.remediation-engine[data-state="VERIFIED"] .status-dot {
    background: #10B981;
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.6);
}

.remediation-engine[data-state="FAILED"] .status-dot {
    background: #EF4444;
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.6);
}

/* Main Split Pane */
.remediation-engine .engine-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.remediation-engine .engine-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.remediation-engine .engine-pane-left {
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    position: relative;
    flex: 0 0 42%;
    /* Adjusted proportion per spec */
}

/* Panel Headers */
.remediation-engine .panel-header {
    padding: 8px 16px;
    font-size: 11px;
    text-transform: uppercase;
    color: #64748B;
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-family: var(--font-mono, 'JetBrains Mono', monospace);
    display: flex;
    justify-content: space-between;
    flex-shrink: 0;
}

/* Diagnostic Box */
.remediation-engine .engine-diagnostic {
    margin: 16px;
    padding: 12px 16px;
    background: rgba(239, 68, 68, 0.1);
    border-left: 3px solid #EF4444;
    border-radius: 4px;
    font-family: var(--font-mono, 'JetBrains Mono', monospace);
    font-size: 13px;
    flex-shrink: 0;
}

.remediation-engine .diagnostic-code {
    color: #FCA5A5;
    font-weight: 600;
    margin-bottom: 4px;
}

.remediation-engine .diagnostic-message {
    color: #E2E8F0;
    line-height: 1.5;
    white-space: pre-wrap;
    /* allow better wrapping */
}

.remediation-engine .diagnostic-loc {
    margin-top: 8px;
    font-size: 11px;
    color: #94A3B8;
}

/* Code Area (Placeholder for Monaco) */
.remediation-engine .engine-code-container {
    flex: 1 1 auto;
    position: relative;
    padding: 0;
    /* Monaco handles its own padding */
    min-height: 0;
    /* Important for flex-child scrolling */
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.4s ease;
}

.monaco-ast-highlight {
    background: rgba(59, 130, 246, 0.25);
    border: 1px solid rgba(59, 130, 246, 0.5);
    border-radius: 2px;
}

/* AST Graph */
.remediation-engine .engine-ast-container {
    flex: 1;
    position: relative;
    padding: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    font-family: var(--font-mono, 'JetBrains Mono', monospace);
    font-size: 12px;
    color: #64748B;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.4s ease 0.2s;
}

/* Progressive Disclosure Reveal */
.remediation-engine .is-revealed {
    opacity: 1 !important;
    transform: translateY(0) !important;
}

/* AST Node Animations */
@keyframes fault-pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
        stroke: rgba(239, 68, 68, 1);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(239, 68, 68, 0);
        stroke: rgba(239, 68, 68, 0.5);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
        stroke: rgba(239, 68, 68, 1);
    }
}

/* Node positioning lives on the .ast-node-anchor wrapper as an SVG
   transform attribute; the hover scale lives here on the inner group.
   They MUST stay on separate elements: a CSS `transform` overrides an
   SVG transform presentation attribute outright, so when both were on
   one <g>, `scale(1.05)` replaced `translate(x,y)` and the node
   teleported to the SVG origin. It then left the pointer, :hover stopped
   matching, it sprang back under the pointer, and the cycle repeated —
   an endless vibration. Do not merge these two rules onto one element.

   transform-box/transform-origin make the scale happen about the node's
   own centre; without them scale() is relative to the SVG user-space
   origin and the node would still drift on hover. */
.ast-node {
    transform-box: fill-box;
    transform-origin: center;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.ast-node.is-fault rect {
    animation: fault-pulse 2s infinite;
}

.ast-node:hover {
    transform: scale(1.05);
}

/* Pipeline Status Bar */
.remediation-engine .engine-pipeline {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 12px 20px;
    background: rgba(0, 0, 0, 0.3);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-family: var(--font-mono, 'JetBrains Mono', monospace);
    font-size: 11px;
    color: #64748B;
}

.remediation-engine .pipeline-step {
    display: flex;
    align-items: center;
    gap: 6px;
}

.remediation-engine .pipeline-step.active {
    color: #3B82F6;
}

.remediation-engine .pipeline-step.done {
    color: #10B981;
}

.remediation-engine .pipeline-separator {
    color: #334155;
}

/* Telemetry Bar */
.remediation-engine .engine-telemetry {
    display: flex;
    align-items: center;
    background: rgba(0, 0, 0, 0.4);
    font-family: var(--font-mono, 'JetBrains Mono', monospace);
    font-size: 13px;
    color: #94A3B8;
}

.remediation-engine .telemetry-item {
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 12px 24px;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.remediation-engine .telemetry-label {
    font-size: 10px;
    text-transform: uppercase;
    color: #64748B;
    margin-bottom: 4px;
}

.remediation-engine .telemetry-value {
    color: #F8FAFC;
    font-weight: 500;
}

.monaco-ast-highlight {
    background-color: rgba(59, 130, 246, 0.3);
    border-radius: 2px;
}

/* Engine Controls */
.remediation-engine .engine-controls {
    margin-left: auto;
    padding-right: 20px;
}

.remediation-engine .engine-button {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #E2E8F0;
    padding: 4px 12px;
    border-radius: 4px;
    font-size: 11px;
    font-family: var(--font-mono, 'JetBrains Mono', monospace);
    cursor: pointer;
    transition: all 0.2s;
}

.remediation-engine .engine-button:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #FFF;
}

/* Mobile Responsive */
@media (max-width: 1024px) {
    .remediation-engine {
        width: 100%;
        min-height: auto;
    }

    .remediation-engine .engine-body {
        flex-direction: column;
    }

    .remediation-engine .engine-pane-left {
        border-right: none;
        border-bottom: 1px solid rgba(255, 255, 255, 0.08);
        min-height: 250px;
        max-width: 100%;
        flex: 1 1 auto;
    }

    .remediation-engine .engine-telemetry {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        width: 100%;
    }

    .remediation-engine .telemetry-item {
        border-right: 1px solid rgba(255, 255, 255, 0.08);
        padding: 10px 16px;
    }
}

@media (max-width: 768px) {
    .remediation-engine {
        border-radius: 8px;
        margin: 0;
    }

    .remediation-engine .engine-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        padding: 10px 14px;
    }

    .remediation-engine .engine-pipeline {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        justify-content: flex-start;
        width: 100%;
        white-space: nowrap;
        padding: 10px 14px;
        scrollbar-width: none;
        gap: 12px;
    }

    .remediation-engine .engine-pipeline::-webkit-scrollbar {
        display: none;
    }

    .remediation-engine .engine-telemetry {
        grid-template-columns: repeat(2, 1fr);
    }

    .remediation-engine .telemetry-item {
        border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    }

    .remediation-engine .engine-pane-left {
        min-height: 200px;
    }

    .remediation-engine .engine-ast-container {
        min-height: 220px;
        padding: 14px;
    }

    .slack-card-container {
        width: calc(100vw - 32px) !important;
        max-width: 400px !important;
        left: 16px !important;
        right: 16px !important;
    }
}

@media (max-width: 480px) {
    .remediation-engine .engine-telemetry {
        grid-template-columns: 1fr;
    }

    .remediation-engine .engine-diagnostic {
        margin: 10px;
        padding: 10px 12px;
        font-size: 12px;
    }

    .remediation-engine .panel-header {
        padding: 6px 12px;
        font-size: 10px;
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {

    .remediation-engine .ast-node,
    .remediation-engine .ast-node rect,
    .remediation-engine .ast-node text,
    .remediation-engine .pipeline-step {
        transition: none !important;
        animation: none !important;
    }
}