/* Rule Chain Styles */

.rule-chain-container {
    border: 1px solid #e1e5e9;
    border-radius: 8px;
    background: #f8f9fa;
    padding: 16px;
}

/* Rule Selection Modal Styles */
.rule-selection-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    margin-bottom: 12px;
    border-bottom: 1px solid #e1e5e9;
    font-size: 0.9rem;
    color: #6c757d;
}

.available-rules-list {
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid #e1e5e9;
    border-radius: 8px;
    background: #ffffff;
}

.available-rule-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid #f1f3f4;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

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

.available-rule-item:hover {
    background-color: #f8f9fa;
}

.available-rule-item.selected {
    background-color: #e3f2fd;
    border-left: 4px solid #2196f3;
}

.available-rule-item.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.available-rule-item-checkbox {
    margin-right: 12px;
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.available-rule-item-content {
    flex: 1;
    min-width: 0;
}

.available-rule-item-name {
    font-weight: 500;
    color: #212529;
    margin-bottom: 4px;
}

.available-rule-item-description {
    font-size: 0.85rem;
    color: #6c757d;
    margin: 0;
}

.available-rule-item-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
    font-size: 0.8rem;
    color: #6c757d;
}

.available-rule-item-tags {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.available-rule-item-tag {
    background: #e9ecef;
    color: #495057;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.75rem;
}

.rule-chain-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    font-weight: 500;
    color: #495057;
}

.rule-chain-list {
    min-height: 60px;
    max-height: 300px;
    overflow-y: auto;
}

.rule-chain-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    color: #6c757d;
    background: #ffffff;
    border: 2px dashed #dee2e6;
    border-radius: 8px;
}

.rule-chain-empty i {
    font-size: 2rem;
    margin-bottom: 12px;
    opacity: 0.5;
}

.rule-chain-empty p {
    margin: 0;
    font-size: 0.9rem;
}

.rule-chain-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    margin-bottom: 8px;
    background: #ffffff;
    border: 1px solid #e1e5e9;
    border-radius: 6px;
    cursor: move;
    transition: all 0.2s ease;
    position: relative;
}

.rule-chain-item:hover {
    border-color: #007bff;
    box-shadow: 0 2px 4px rgba(0, 123, 255, 0.1);
}

.rule-chain-item.dragging {
    opacity: 0.5;
    transform: rotate(2deg);
}

.rule-chain-item.drag-over {
    border-color: #007bff;
    background: #f8f9ff;
}

.rule-chain-item-handle {
    display: flex;
    align-items: center;
    margin-right: 12px;
    color: #6c757d;
    cursor: grab;
}

.rule-chain-item-handle:active {
    cursor: grabbing;
}

.rule-chain-item-order {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: #007bff;
    color: white;
    border-radius: 50%;
    font-size: 0.8rem;
    font-weight: 600;
    margin-right: 12px;
}

.rule-chain-item-content {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.rule-chain-item-name {
    font-weight: 500;
    color: #212529;
    margin-bottom: 2px;
}

.rule-chain-item-description {
    font-size: 0.85rem;
    color: #6c757d;
}

.rule-chain-item-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.rule-chain-item-remove {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.rule-chain-item-remove:hover {
    background: #c82333;
}

.rule-chain-item-remove i {
    font-size: 0.8rem;
}

/* Rule Selection Modal Styles */
.rule-selection-container {
    max-height: 500px;
    display: flex;
    flex-direction: column;
}

.rule-search {
    margin-bottom: 16px;
}

.available-rules-list {
    flex: 1;
    overflow-y: auto;
    max-height: 400px;
}

.available-rule-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border: 1px solid #e1e5e9;
    border-radius: 6px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: #ffffff;
}

.available-rule-item:hover {
    border-color: #007bff;
    background: #f8f9ff;
}

.available-rule-item.selected {
    border-color: #007bff;
    background: #e3f2fd;
}

.available-rule-item.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #f8f9fa;
}

.available-rule-item-content {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.available-rule-item-name {
    font-weight: 500;
    color: #212529;
    margin-bottom: 2px;
}

.available-rule-item-description {
    font-size: 0.85rem;
    color: #6c757d;
}

.available-rule-item-status {
    display: flex;
    align-items: center;
    margin-left: 12px;
}

.available-rule-item-status .badge {
    font-size: 0.75rem;
    padding: 4px 8px;
}

/* Drag and Drop Visual Feedback */
.rule-chain-drop-zone {
    border: 2px dashed #007bff;
    background: #f8f9ff;
    border-radius: 6px;
    padding: 20px;
    text-align: center;
    color: #007bff;
    font-weight: 500;
    margin: 8px 0;
    transition: all 0.2s ease;
}

.rule-chain-drop-zone.active {
    background: #e3f2fd;
    border-color: #1976d2;
}

/* Responsive Design */
@media (max-width: 768px) {
    .rule-chain-item {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .rule-chain-item-handle {
        margin-right: 0;
        margin-bottom: 8px;
    }
    
    .rule-chain-item-actions {
        margin-top: 8px;
        align-self: flex-end;
    }
}

/* Animation for rule chain items */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.rule-chain-item {
    animation: slideIn 0.3s ease;
}

/* Loading state for rule chain */
.rule-chain-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    color: #6c757d;
}

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

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Rule Chain Mapping Styles */

.rule-chain-mapping-container {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.rule-chain-mapping-section {
    border: 1px solid #e1e5e9;
    border-radius: 8px;
    background: #ffffff;
    padding: 20px;
}

.rule-chain-mapping-header {
    display: flex;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid #e1e5e9;
}

.rule-chain-mapping-order {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: #007bff;
    color: white;
    border-radius: 50%;
    font-weight: 600;
    margin-right: 12px;
}

.rule-chain-mapping-title {
    flex: 1;
}

.rule-chain-mapping-name {
    font-weight: 600;
    color: #212529;
    margin-bottom: 2px;
}

.rule-chain-mapping-description {
    font-size: 0.9rem;
    color: #6c757d;
}

.rule-chain-mapping-variables {
    display: grid;
    gap: 12px;
}

.rule-variable-mapping {
    display: flex;
    align-items: center;
    padding: 12px;
    border: 1px solid #e1e5e9;
    border-radius: 6px;
    background: #f8f9fa;
    transition: all 0.2s ease;
}

.rule-variable-mapping:hover {
    border-color: #007bff;
    background: #f8f9ff;
}

.rule-variable-mapping.mapped {
    border-color: #28a745;
    background: #f8fff9;
}

.rule-variable-info {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.rule-variable-name {
    font-weight: 500;
    color: #212529;
    margin-bottom: 2px;
}

.rule-variable-type {
    font-size: 0.8rem;
    color: #6c757d;
    text-transform: uppercase;
    font-weight: 500;
}

.rule-variable-required {
    color: #dc3545;
    font-weight: 600;
}

.rule-variable-mapping-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.rule-variable-source {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: #e9ecef;
    border-radius: 4px;
    font-size: 0.85rem;
    color: #495057;
}

.rule-variable-source.token {
    background: #d1ecf1;
    color: #0c5460;
}

.rule-variable-source.previous-rule {
    background: #f8d7da;
    color: #721c24;
}

.rule-variable-remove {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.rule-variable-remove:hover {
    background: #c82333;
}

.rule-variable-remove i {
    font-size: 0.7rem;
}

/* Token Library for Mapping */
.token-library-mapping {
    border-top: 1px solid #e1e5e9;
    padding-top: 20px;
}

.token-library-mapping h4 {
    margin: 0 0 12px 0;
    color: #495057;
    font-size: 1rem;
}

.mapping-token-library {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 8px;
    max-height: 200px;
    overflow-y: auto;
    padding: 8px;
    border: 1px solid #e1e5e9;
    border-radius: 6px;
    background: #f8f9fa;
}

.mapping-token-item {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    background: #ffffff;
    border: 1px solid #e1e5e9;
    border-radius: 4px;
    cursor: grab;
    transition: all 0.2s ease;
    font-size: 0.85rem;
}

.mapping-token-item:hover {
    border-color: #007bff;
    background: #f8f9ff;
}

.mapping-token-item:active {
    cursor: grabbing;
}

.mapping-token-item i {
    margin-right: 6px;
    color: #6c757d;
}

.mapping-token-item-name {
    font-weight: 500;
    color: #212529;
}

/* Previous Rule Outputs */
.previous-rule-outputs {
    margin-top: 12px;
    padding: 12px;
    background: #fff3cd;
    border: 1px solid #ffeaa7;
    border-radius: 6px;
}

.previous-rule-outputs h5 {
    margin: 0 0 8px 0;
    color: #856404;
    font-size: 0.9rem;
}

.previous-rule-output-item {
    display: flex;
    align-items: center;
    padding: 6px 8px;
    background: #ffffff;
    border: 1px solid #ffeaa7;
    border-radius: 4px;
    cursor: grab;
    transition: all 0.2s ease;
    font-size: 0.8rem;
    margin-bottom: 4px;
}

.previous-rule-output-item:hover {
    border-color: #f39c12;
    background: #fef9e7;
}

.previous-rule-output-item:active {
    cursor: grabbing;
}

.previous-rule-output-item i {
    margin-right: 6px;
    color: #f39c12;
}

.previous-rule-output-name {
    font-weight: 500;
    color: #856404;
}

/* Drag and Drop Visual Feedback for Mapping */
.rule-variable-mapping.drag-over {
    border-color: #007bff;
    background: #e3f2fd;
    transform: scale(1.02);
}

.mapping-drop-zone {
    border: 2px dashed #007bff;
    background: #f8f9ff;
    border-radius: 6px;
    padding: 20px;
    text-align: center;
    color: #007bff;
    font-weight: 500;
    margin: 8px 0;
    transition: all 0.2s ease;
}

.mapping-drop-zone.active {
    background: #e3f2fd;
    border-color: #1976d2;
}

/* Responsive Design for Mapping */
@media (max-width: 768px) {
    .rule-variable-mapping {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .rule-variable-mapping-controls {
        margin-top: 8px;
        align-self: flex-end;
    }
    
    .mapping-token-library {
        grid-template-columns: 1fr;
    }
}

/* Rule Chain Results Styles */

.rule-chain-header {
    background: #f8f9fa;
    font-weight: 600;
    color: #495057;
    text-align: center;
    padding: 12px 8px;
    border-left: 1px solid #e1e5e9;
    border-right: 1px solid #e1e5e9;
}

.rule-chain-result-cell {
    padding: 8px;
    border-left: 1px solid #e1e5e9;
    border-right: 1px solid #e1e5e9;
    vertical-align: top;
}

.rule-chain-result {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 60px;
}

.rule-chain-result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.rule-chain-result-name {
    font-weight: 500;
    color: #212529;
    font-size: 0.85rem;
}

.rule-chain-result-status {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    padding: 2px 6px;
    border-radius: 3px;
    font-weight: 500;
}

.rule-chain-result-status.success {
    background: #d4edda;
    color: #155724;
}

.rule-chain-result-status.failure {
    background: #f8d7da;
    color: #721c24;
}

.rule-chain-result-status.warning {
    background: #fff3cd;
    color: #856404;
}

.rule-chain-result-value {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 24px;
}

.rule-chain-result-time {
    font-size: 0.7rem;
    color: #6c757d;
    text-align: center;
}

.rule-chain-result-error {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.7rem;
    color: #dc3545;
    background: #f8d7da;
    padding: 4px 6px;
    border-radius: 3px;
    margin-top: 4px;
}

/* Rule Chain Outcome Styles */
.rule-chain-outcome-boolean {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border-radius: 4px;
    font-weight: 500;
    font-size: 0.8rem;
}

.rule-chain-outcome-boolean.true {
    background: #d4edda;
    color: #155724;
}

.rule-chain-outcome-boolean.false {
    background: #f8d7da;
    color: #721c24;
}

.rule-chain-outcome-number {
    background: #e3f2fd;
    color: #0d47a1;
    padding: 4px 8px;
    border-radius: 4px;
    font-weight: 500;
    font-size: 0.8rem;
    text-align: center;
}

.rule-chain-outcome-string {
    background: #f3e5f5;
    color: #4a148c;
    padding: 4px 8px;
    border-radius: 4px;
    font-weight: 500;
    font-size: 0.8rem;
    text-align: center;
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rule-chain-outcome-failed {
    background: #f8d7da;
    color: #721c24;
    padding: 4px 8px;
    border-radius: 4px;
    font-weight: 500;
    font-size: 0.8rem;
    text-align: center;
}

.rule-chain-outcome-skipped {
    background: #fff3cd;
    color: #856404;
    padding: 4px 8px;
    border-radius: 4px;
    font-weight: 500;
    font-size: 0.8rem;
    text-align: center;
}

.rule-chain-outcome-null {
    background: #e9ecef;
    color: #6c757d;
    padding: 4px 8px;
    border-radius: 4px;
    font-weight: 500;
    font-size: 0.8rem;
    text-align: center;
}

/* Rule Chain Result Row Styles */
.rule-chain-result-row {
    background: #f8f9fa;
}

.rule-chain-result-row:hover {
    background: #e9ecef;
}

/* Responsive Design for Results */
@media (max-width: 1200px) {
    .rule-chain-result {
        min-height: 80px;
    }
    
    .rule-chain-result-name {
        font-size: 0.8rem;
    }
    
    .rule-chain-result-status {
        font-size: 0.7rem;
    }
}

@media (max-width: 768px) {
    .rule-chain-result-cell {
        padding: 4px;
    }
    
    .rule-chain-result {
        min-height: 100px;
    }
    
    .rule-chain-result-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }
    
    .rule-chain-result-name {
        font-size: 0.75rem;
    }
    
    .rule-chain-result-status {
        font-size: 0.65rem;
    }
}

/* Rule Variables Styles */
.rule-variables-list {
    margin-top: 12px;
}

.rule-variables-list h6 {
    margin: 0 0 12px 0;
    font-size: 0.9rem;
    font-weight: 600;
    color: #495057;
    display: flex;
    align-items: center;
    gap: 8px;
}

.rule-variable-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    margin-bottom: 8px;
    background: #ffffff;
    border: 1px solid #e1e5e9;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.rule-variable-item:hover {
    border-color: #2196f3;
    box-shadow: 0 2px 4px rgba(33, 150, 243, 0.1);
}

.rule-variable-info {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}

.rule-variable-name {
    font-weight: 500;
    color: #212529;
}

.rule-variable-type {
    font-size: 0.8rem;
    color: #6c757d;
    background: #f8f9fa;
    padding: 2px 6px;
    border-radius: 4px;
}

.rule-variable-mapping {
    flex: 1;
    margin-left: 16px;
}

.mapping-drop-zone {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    border: 2px dashed #dee2e6;
    border-radius: 6px;
    background: #f8f9fa;
    color: #6c757d;
    font-size: 0.9rem;
    transition: all 0.2s ease;
    cursor: pointer;
    min-height: 40px;
}

.mapping-drop-zone:hover {
    border-color: #2196f3;
    background: #e3f2fd;
    color: #1976d2;
}

.mapping-drop-zone.drag-over {
    border-color: #4caf50;
    background: #e8f5e8;
    color: #2e7d32;
}

.mapping-info.error {
    color: #dc3545;
}

.mapping-info.error i {
    color: #dc3545;
}
