
.agent-instructions-btn {
    position: absolute;
    right: 0;
    bottom: -18px; /* Position below the tool-start line */
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px 6px; /* Tighter padding */
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 3px;
    font-size: 10px; /* Smaller font */
    color: var(--text-tertiary);
    cursor: pointer;
    transition: all 0.2s;
    z-index: 10;
    font-family: inherit;
    line-height: 1;
    height: 20px; /* Fixed small height */
    margin-bottom: 8px; /* Small margin below the button */
}

.agent-instructions-btn:hover {
    color: var(--accent-color);
    border-color: var(--accent-color);
    background: rgba(var(--accent-bg), 0.1);
}

.agent-instructions-btn svg {
    flex-shrink: 0;
    width: 12px; /* Smaller icon */
    height: 12px;
}

.agent-instructions-btn span {
    white-space: nowrap;
    font-size: 10px;
}

/* Dark theme specific */
[data-theme="dark"] .agent-instructions-btn {
    background: rgba(42, 42, 42, 0.8);
    border-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .agent-instructions-btn:hover {
    background: rgba(var(--accent-bg), 0.15);
}

/* Modal Container */
.agent-instructions-modal-container {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    z-index: 99999;
    justify-content: center;
    align-items: center; /* Center vertically */
    padding: 20px;
}

/* Adjust modal content height to fill more space */
.agent-instructions-modal-content {
    width: 90%;
    max-width: 1200px;
    height: auto; /* Adapt to content */
    min-height: 300px; /* Minimum reasonable height */
    max-height: 90vh; /* Maximum height */
    background: var(--bg-primary);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    position: relative;
    z-index: 100000;
}

/* Modal Header */
.agent-instructions-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px; /* Reduced from 20px 24px */
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
    flex-shrink: 0; /* Prevent shrinking */
}

.agent-instructions-header h3 {
    color: var(--accent-color);
    margin: 0;
    font-size: 20px;
    font-weight: 600;
}

.agent-instructions-close {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.agent-instructions-close:hover {
    background: rgba(var(--accent-bg), 0.2);
    border-color: var(--accent-color);
}

/* Modal Body */
.agent-instructions-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px; /* Reduced from 20px */
    display: flex;
    flex-direction: column;
    gap: 12px; /* Reduced gap between sections */
}

/* Make sections fill available space better */
.instructions-section {
    margin-bottom: 12px; /* Reduced from 20px */
    background: var(--bg-secondary);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.section-header {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg-primary);
    cursor: pointer;
    user-select: none;
    transition: background 0.2s;
}

.section-header:hover {
    background: rgba(var(--accent-bg), 0.05);
}

.expand-icon {
    margin-right: 8px;
    transition: transform 0.3s;
    color: var(--text-secondary);
}

.instructions-section.collapsed .expand-icon {
    transform: rotate(-90deg);
}

.section-header span {
    flex: 1;
    font-weight: 600;
    color: var(--text-primary);
}

.copy-btn {
    padding: 4px 8px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-tertiary);
    cursor: pointer;
    transition: all 0.2s;
}

.copy-btn:hover {
    color: var(--accent-color);
    border-color: var(--accent-color);
    background: rgba(var(--accent-bg), 0.1);
}

/* Section Content */
.section-content {
    padding: 12px;
    max-height: 50vh;
    overflow-y: auto;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 12px;
    line-height: 1.4; /* Compact line height */
}

.instructions-section.collapsed .section-content {
    display: none;
}

.instructions-section.collapsed {
    flex: none;
    margin-bottom: 12px; /* Maintain consistent spacing */
}

/* For very short content, ensure readable minimum */
.agent-instructions-modal-container .section-content:not(:empty) {
    min-height: 40px; /* Minimum height for single line content */
}

/* Content Formatting */
.instruction-content {
    color: var(--text-primary);
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 12px;
    line-height: 1.4; /* Compact line height */
    white-space: pre-wrap; /* Preserve spacing */
    word-break: break-word;
}

/* XML Tags Highlighting */
.xml-tag {
    color: var(--accent-color);
    background: rgba(var(--accent-bg), 0.1);
    padding: 1px 3px;
    border-radius: 2px;
    font-weight: 500;
}

.instruction-content br {
    line-height: 1.4;
}

/* Loading and Error States */
.agent-instructions-modal-container .loading,
.agent-instructions-modal-container .error,
.agent-instructions-modal-container .empty {
    text-align: center;
    padding: 40px;
    color: var(--text-tertiary);
    font-style: italic;
}

.agent-instructions-modal-container .error {
    color: var(--error-color);
}

/* Scrollbar styling */
.section-content::-webkit-scrollbar,
.agent-instructions-body::-webkit-scrollbar {
    width: 8px;
}

.section-content::-webkit-scrollbar-track,
.agent-instructions-body::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

.section-content::-webkit-scrollbar-thumb,
.agent-instructions-body::-webkit-scrollbar-thumb {
    background: var(--text-tertiary);
    border-radius: 4px;
}

.section-content::-webkit-scrollbar-thumb:hover,
.agent-instructions-body::-webkit-scrollbar-thumb:hover {
    background: var(--accent-color);
}

/* Dark theme adjustments */
[data-theme="dark"] .xml-tag {
    background: rgba(var(--accent-bg), 0.2);
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .agent-instructions-modal-content {
        width: 95%;
        height: 90vh;
    }
    
    .section-content {
        max-height: 300px;
    }
}