/**
 * SPL Agents CSS - Shared styles for agent chat windows and avatars
 * Universal styles for both curriculum and competency SPL interfaces
 */

/* Floating Agent Chat Windows */
.agent-chat-window {
    position: fixed;
    width: 350px;
    min-width: 280px;
    max-width: 600px;
    min-height: 300px;
    max-height: 80vh;
    background: rgba(255, 255, 255, 0.75);
    border-radius: 16px;
    box-shadow: 0 15px 40px rgba(0,0,0,0.2);
    z-index: 1000;
    display: none;
    flex-direction: column;
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255,255,255,0.3);
    animation: slideIn 0.3s ease-out;
    transition: all 0.3s ease;
    opacity: 0.7;
    overflow: hidden;
    resize: both;
}

/* Custom resize handle */
.agent-chat-window::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: 0;
    width: 20px;
    height: 20px;
    background: linear-gradient(-45deg, 
        transparent 0%, 
        transparent 40%, 
        rgba(102, 126, 234, 0.3) 40%, 
        rgba(102, 126, 234, 0.3) 45%, 
        transparent 45%, 
        transparent 55%, 
        rgba(102, 126, 234, 0.3) 55%, 
        rgba(102, 126, 234, 0.3) 60%, 
        transparent 60%
    );
    cursor: nw-resize;
    border-radius: 0 0 16px 0;
    pointer-events: none; /* Let the browser handle resize */
}

.agent-chat-window.focused {
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 25px 60px rgba(0,0,0,0.35);
    backdrop-filter: blur(15px);
    opacity: 1;
    transform: scale(1.02);
}

.agent-chat-window:hover {
    background: rgba(255, 255, 255, 0.85);
    box-shadow: 0 20px 50px rgba(0,0,0,0.25);
    opacity: 0.9;
}

.agent-chat-window.dragging {
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 30px 80px rgba(0,0,0,0.4);
    transform: scale(1.01);
    z-index: 1002 !important;
}

@keyframes slideIn {
    from { 
        opacity: 0; 
        transform: translateY(-20px) scale(0.95); 
    }
    to { 
        opacity: 0.7; 
        transform: translateY(0) scale(1); 
    }
}

.agent-chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px 10px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.5);
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1), rgba(118, 75, 162, 0.1));
}

.agent-chat-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.agent-close-btn {
    background: none;
    border: none;
    font-size: 20px;
    font-weight: bold;
    color: #666;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: background 0.2s ease;
}

.agent-close-btn:hover {
    background: rgba(255,255,255,0.2);
}

.agent-chat-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0;
    min-height: 0; /* Important for flexbox to work properly */
}

.agent-chat-history {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 15px;
    background: #fafafa;
    min-height: 0; /* Allow shrinking */
    scroll-behavior: smooth;
}

.agent-input-area {
    display: flex;
    gap: 8px;
    align-items: stretch;
    padding: 15px;
    background: white;
    border-top: 1px solid #e0e0e0;
    border-radius: 0 0 16px 16px;
    flex-shrink: 0; /* Never shrink the input area */
}

.agent-input-area input {
    flex: 1;
    padding: 12px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s ease;
}

.agent-input-area input:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.1);
}

.agent-send-btn {
    padding: 12px 20px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    white-space: nowrap;
    flex-shrink: 0;
}

.agent-send-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, #5a6fd8, #6a4190);
    transform: translateY(-1px);
}

.agent-send-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Agent Messages */
.agent-message {
    margin-bottom: 16px;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    animation: agentFadeIn 0.3s ease;
    max-width: 85%;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

@keyframes agentFadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

.agent-user-message {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    margin-left: auto;
    margin-right: 0;
    border-radius: 12px 12px 4px 12px;
}

.agent-bot-message {
    background: #f0f0f0;
    color: #333;
    margin-left: 0;
    margin-right: auto;
    border-radius: 12px 12px 12px 4px;
    border-left: 3px solid rgb(var(--agent-color-rgb, 102, 126, 234));
}

/* Agent-specific colors */
.hint-agent .agent-bot-message {
    --agent-color-rgb: 66, 165, 245;
}

.answer-help-agent .agent-bot-message {
    --agent-color-rgb: 255, 152, 0;
}

/* Floating Agent Avatars */
.agent-avatar {
    position: fixed;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    cursor: pointer;
    z-index: 999;
    transition: all 0.3s ease;
    box-shadow: 0 8px 25px rgba(0,0,0,0.15);
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255,255,255,0.3);
    animation: avatarFloat 3s ease-in-out infinite;
}

@keyframes avatarFloat {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-5px); }
}

.agent-avatar:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 12px 35px rgba(0,0,0,0.25);
}

.agent-avatar:active {
    transform: translateY(-1px) scale(0.98);
}

/* Avatar positioning */
.hint-avatar {
    background: linear-gradient(135deg, #42a5f5, #1e88e5);
    bottom: 200px;
    right: 30px;
    animation-delay: 0s;
}

.answer-avatar {
    background: linear-gradient(135deg, #ff9800, #f57c00);
    bottom: 300px;
    right: 30px;
    animation-delay: 1s;
}

/* Study Mate specific styles */
.study-mate-message {
    background: linear-gradient(135deg, #e8f5e9, #c8e6c9);
    border-left: 4px solid #4caf50;
    margin: 0 10px;
    position: relative;
}

.study-mate-message::before {
    content: "🎓 Study Mate";
    position: absolute;
    top: -8px;
    left: 8px;
    background: #4caf50;
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 10px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Responsive design */
@media (max-width: 768px) {
    .agent-chat-window {
        width: 300px;
        min-width: 250px;
        max-width: calc(100vw - 40px);
        max-height: 70vh;
        min-height: 250px;
        right: 10px;
        left: auto;
    }
    
    .agent-avatar {
        width: 60px;
        height: 60px;
        font-size: 24px;
        right: 15px;
    }
    
    .hint-avatar {
        bottom: 150px;
    }
    
    .answer-avatar {
        bottom: 220px;
    }
    
    .agent-message {
        max-width: 90%;
        font-size: 13px;
    }
    
    .agent-input-area {
        padding: 12px;
    }
    
    .agent-input-area input {
        padding: 10px;
        font-size: 13px;
    }
    
    .agent-send-btn {
        padding: 10px 16px;
        font-size: 13px;
    }
}

@media (max-width: 480px) {
    .agent-chat-window {
        width: calc(100vw - 20px);
        min-width: calc(100vw - 20px);
        max-width: calc(100vw - 20px);
        max-height: 60vh;
        min-height: 200px;
        left: 10px;
        right: 10px;
    }
    
    .agent-avatar {
        width: 50px;
        height: 50px;
        font-size: 20px;
        right: 10px;
    }
    
    .agent-message {
        max-width: 95%;
        font-size: 12px;
        padding: 10px 12px;
    }
    
    .agent-input-area {
        padding: 10px;
    }
    
    .agent-input-area input {
        padding: 8px;
        font-size: 12px;
    }
    
    .agent-send-btn {
        padding: 8px 12px;
        font-size: 12px;
    }
}