/**
 * Cognitive Studio Blocks CSS
 * Core styling for intent blocks in both editor and viewer modes
 * Iteration 118
 */

/* ===================================
   BASE INTENT BLOCK STRUCTURE
   =================================== */

/* Base intent block styling */
.intent-block-instance {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    margin-bottom: 8px;
    background: #2a2a2a;
    border: 1px solid #444;
    border-radius: 8px;
    transition: all 0.2s ease;
    min-height: 60px;
    color: #e0e0e0;
}

/* Hover state */
.intent-block-instance:hover {
    background: #333;
    border-color: #555;
    transform: translateX(2px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* Line numbers (QBasic style) */
.intent-line-number {
    position: absolute;
    left: -45px;
    top: 50%;
    transform: translateY(-50%);
    color: #666;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    font-weight: bold;
    user-select: none;
}

/* Icon container */
.intent-icon-container {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(102, 126, 234, 0.1);
    border: 1px solid rgba(102, 126, 234, 0.3);
    border-radius: 8px;
}

.intent-icon {
    font-size: 20px;
    line-height: 1;
}

/* Content area */
.intent-content {
    flex: 1;
    min-width: 0;
}

.intent-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.intent-type {
    font-weight: 600;
    font-size: 14px;
    color: #fff;
    text-transform: capitalize;
}

.intent-summary {
    font-size: 12px;
    color: #999;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Remove button */
.intent-remove-container {
    flex-shrink: 0;
    opacity: 0;
    transition: opacity 0.2s;
}

.intent-block-instance:hover .intent-remove-container {
    opacity: 1;
}

/* Remove button - Iteration 127 Enhanced */
.intent-remove {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 30px; /* Increased from 24px */
    height: 30px; /* Increased from 24px */ 
    border: none;
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border-radius: 4px;
    font-size: 22px; /* Increased from 18px */
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    z-index: 100; /* Added for consistency */
}

.intent-remove:hover {
    background: rgba(239, 68, 68, 0.2);
    transform: scale(1.1); /* Reduced from 1.3 since button is already bigger */
}

/* ===================================
   CONTAINER BLOCK STYLES
   =================================== */

.intent-block-instance.container-type {
    background: linear-gradient(135deg, #2a2a2a 0%, rgba(168, 85, 247, 0.05) 100%);
    border-color: rgba(168, 85, 247, 0.3);
    border-bottom-width: 3px;
}

.intent-block-instance.container-type .intent-icon-container {
    background: rgba(168, 85, 247, 0.1);
    border-color: rgba(168, 85, 247, 0.3);
}

/* Container indicator */
.intent-block-instance.container-type::after {
    content: '{ }';
    position: absolute;
    right: 60px;
    top: 50%;
    transform: translateY(-50%);
    font-family: 'Courier New', monospace;
    font-size: 14px;
    font-weight: bold;
    color: rgba(168, 85, 247, 0.5);
    pointer-events: none;
}

/* ===================================
   DRAG STATES
   =================================== */

.intent-block-instance.dragging,
.intent-block-instance.dragging-internal {
    opacity: 0.5;
    cursor: grabbing !important;
}

.intent-block-instance.drag-over {
    background: rgba(59, 130, 246, 0.1);
    border-color: rgba(59, 130, 246, 0.5);
}

/* ===================================
   SELECTION STATE
   =================================== */

.intent-block-instance.selected {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, #2a2a2a 100%);
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.3);
}

/* ===================================
   EXECUTION STATES (for agent view)
   =================================== */

.agent-intent-block {
    /* Same base styles as intent-block-instance */
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    margin-bottom: 8px;
    background: #2a2a2a;
    border: 1px solid #444;
    border-radius: 8px;
    min-height: 60px;
    color: #e0e0e0;
}

.agent-intent-block.pending {
    opacity: 0.6;
}

.agent-intent-block.executing {
    background: linear-gradient(135deg, #2a2a2a 0%, rgba(59, 130, 246, 0.1) 100%);
    border-color: rgba(59, 130, 246, 0.5);
    animation: executingPulse 2s ease-in-out infinite;
}

.agent-intent-block.completed {
    background: linear-gradient(135deg, #2a2a2a 0%, rgba(16, 185, 129, 0.1) 100%);
    border-color: rgba(16, 185, 129, 0.5);
}

.agent-intent-block.error {
    background: linear-gradient(135deg, #2a2a2a 0%, rgba(239, 68, 68, 0.1) 100%);
    border-color: rgba(239, 68, 68, 0.5);
}

/* ===================================
   NESTED CONTENT
   =================================== */

.nested-content {
    position: relative;
    margin-top: 8px;
    margin-left: 40px;
    padding-left: 20px;
    min-height: 40px;
    border-left: 2px solid rgba(168, 85, 247, 0.2);
}

.nested-content::before {
    content: '';
    position: absolute;
    left: -2px;
    top: -8px;
    width: 20px;
    height: 20px;
    border-left: 2px solid rgba(168, 85, 247, 0.2);
    border-bottom: 2px solid rgba(168, 85, 247, 0.2);
    border-bottom-left-radius: 10px;
}

/* ===================================
   ANIMATIONS
   =================================== */

@keyframes executingPulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(59, 130, 246, 0);
    }
    50% {
        box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.2);
    }
}

/* ===================================
   EMPTY STATE
   =================================== */

.empty-program {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 400px;
    color: #666;
    text-align: center;
    padding: 40px;
}

.empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-program p {
    margin: 8px 0;
}

.empty-subtitle {
    font-size: 14px;
    color: #555;
}

/* ===================================
   INTENT PARAMETER MENU - Iteration 127
   =================================== */

/* Menu button */
.intent-menu-button {
    position: absolute;
    top: 8px;
    right: 60px; /* Positioned left of the X button */
    width: 30px;
    height: 30px;
    border: none;
    background: transparent;
    color: #999;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    opacity: 0;
    z-index: 100; /* Increased from 10 - Iteration 127 */
}

/* Show menu button on block hover */
.intent-block-instance:hover .intent-menu-button {
    opacity: 1;
}

.intent-menu-button:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

/* Parameter menu : iteration 127*/
.intent-parameter-menu {
    position: fixed;
    background: #1a1a1a;
    border: 1px solid #444;
    border-radius: 8px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
    min-width: 280px;
    max-width: 400px;
    max-height: 500px;
    overflow-y: auto;
    z-index: 999999; /* Changed from 10000 to match studio's z-index - Iteration 127 */
    opacity: 0;
    transform: scale(0.95);
    transition: all 0.2s ease;
}

.intent-parameter-menu.active {
    opacity: 1;
    transform: scale(1);
}

/* Menu content */
.intent-menu-content {
    padding: 8px 0;
}

/* Menu sections */
.menu-section {
    border-bottom: 1px solid #333;
    padding-bottom: 8px;
    margin-bottom: 8px;
}

.menu-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.menu-section-header {
    padding: 8px 16px;
    font-size: 12px;
    font-weight: 600;
    color: #999;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Parameter items */
.parameter-item {
    padding: 8px 16px;
    cursor: pointer;
    transition: all 0.15s ease;
    position: relative;
}

.parameter-item:hover {
    background: rgba(102, 126, 234, 0.1);
    color: #fff;
}

.parameter-item.configured {
    opacity: 0.6;
    cursor: default;
}

.parameter-item.configured:hover {
    background: transparent;
}

/* Parameter name and description */
.parameter-name {
    font-size: 14px;
    font-weight: 500;
    color: #e0e0e0;
    margin-bottom: 2px;
}

.parameter-description {
    font-size: 12px;
    color: #999;
    line-height: 1.4;
}

/* Default value indicator */
.parameter-item .parameter-name::after {
    content: attr(data-default);
    margin-left: 8px;
    font-size: 11px;
    color: #666;
    font-weight: normal;
}

/* Required parameter indicator */
.menu-section-header::before {
    content: attr(data-icon);
    margin-right: 6px;
    font-size: 14px;
}

/* ===================================
   PARAMETER ADDITION ANIMATION
   =================================== */

/* Animation for newly added parameters in JSON editor */
@keyframes parameterBlink {
    0% { 
        background-color: transparent; 
        transform: translateX(0);
    }
    25% { 
        background-color: rgba(74, 222, 128, 0.2);
        transform: translateX(3px);
    }
    50% { 
        background-color: rgba(74, 222, 128, 0.3);
        transform: translateX(0);
    }
    75% {
        background-color: rgba(74, 222, 128, 0.2);
        transform: translateX(-3px);
    }
    100% { 
        background-color: transparent;
        transform: translateX(0);
    }
}

.parameter-added {
    animation: parameterBlink 1.5s ease-in-out 2;
    position: relative;
}

/* Green highlight bar */
.parameter-added::before {
    content: '';
    position: absolute;
    left: -4px;
    top: 0;
    bottom: 0;
    width: 3px;
    background: #4ade80;
    animation: fadeOut 3s ease-out forwards;
}

@keyframes fadeOut {
    0% { opacity: 1; }
    70% { opacity: 1; }
    100% { opacity: 0; }
}

/* Scrollbar styling for menu */
.intent-parameter-menu::-webkit-scrollbar {
    width: 6px;
}

.intent-parameter-menu::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

.intent-parameter-menu::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.intent-parameter-menu::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Empty state for sections */
.menu-section-empty {
    padding: 16px;
    text-align: center;
    color: #666;
    font-size: 12px;
    font-style: italic;
}

/* ITERATION 182: Fix hamburger vertical position */
.intent-menu-button {
    position: absolute;
    top: 8px;      /* Same as remove button */
    right: 45px;   /* Left of the X button */
    width: 30px;
    height: 30px;
    border: none;
    background: transparent;
    color: #999;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    opacity: 0;
    z-index: 100;
    transform: translateY(0); /* Reset any transforms */
}

/* ITERATION 182: Show on parent OR self hover */
.intent-block-instance:hover .intent-menu-button,
.intent-menu-button:hover {
    opacity: 1;
}

/* ITERATION 182: Keep parent hover state when hovering nested */
.intent-block-wrapper:hover .intent-menu-button {
    opacity: 1;
}

/* For nested intents, maintain visibility */
.nested-content:hover .intent-menu-button,
.branch-content:hover .intent-menu-button,
.container-content:hover .intent-menu-button {
    opacity: 1;
}

/* ITERATION 182: Ensure nested blocks don't hide parent buttons */
.intent-block-instance {
    position: relative; /* Ensure positioning context */
}

/* Make the whole intent block area maintain hover */
.intent-block-instance::before {
    content: '';
    position: absolute;
    top: -5px;
    left: -5px;
    right: -5px;
    bottom: -5px;
    z-index: -1;
}

/* For table-based layouts, ensure button stays at top */
.intent-table {
    position: relative;
}

.intent-block-instance .intent-menu-button {
    top: 8px !important; /* Force top position */
}