/* Main Layout */
.main-layout {
    display: flex;
    min-height: calc(100vh - 76px); /* Subtract navbar height */
    position: relative;
}

/* Main Content Area */
.main-content {
    flex: 1;
    transition: margin-right 0.3s ease;
    min-height: calc(100vh - 76px);
    margin-right: 0; /* No margin by default (chat closed) */
}

.main-content.chat-open {
    margin-right: 350px;
}

/* Chat Sidebar */
.chat-sidebar {
    position: fixed;
    top: 76px; /* Below navbar */
    right: 0;
    width: 350px;
    height: calc(100vh - 76px);
    background: #ffffff;
    border-left: 1px solid #e0e0e0;
    box-shadow: -2px 0 10px rgba(0, 0, 0, 0.1);
    transform: translateX(100%); /* Closed by default */
    transition: transform 0.3s ease;
    z-index: 1000;
    display: flex;
    flex-direction: column;
}

.chat-sidebar.open {
    transform: translateX(0);
}

/* Chat Sidebar Header */
.chat-sidebar-header {
    background: linear-gradient(135deg, #007bff, #0056b3);
    color: white;
    padding: 15px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

.chat-sidebar-header h5 {
    font-weight: 600;
}

#toggle-chat {
    border-color: rgba(255, 255, 255, 0.3);
    color: white;
    transition: all 0.2s ease;
}

#toggle-chat:hover {
    background-color: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.5);
    color: white;
}

/* Chat Sidebar Content */
.chat-sidebar-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

/* Chat Messages Area */
.chat-messages {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Custom scrollbar for chat messages */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Message Bubbles */
.user-message, .assistant-message {
    display: flex;
    flex-direction: column;
    margin-bottom: 10px;
}

.user-message {
    align-items: flex-end;
}

.assistant-message {
    align-items: flex-start;
}

.message-bubble {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 18px;
    word-wrap: break-word;
    font-size: 14px;
    line-height: 1.4;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.user-message .message-bubble {
    background: #007bff;
    color: white;
    border-bottom-right-radius: 5px;
}

.assistant-message .message-bubble {
    background: #e9ecef;
    color: #333;
    border-bottom-left-radius: 5px;
}

.chat-timestamp {
    font-size: 11px;
    color: #6c757d;
    margin-top: 5px;
    padding: 0 5px;
}

/* Chat Input Area */
.chat-input-area {
    padding: 15px;
    border-top: 1px solid #e0e0e0;
    background: white;
    flex-shrink: 0;
}

.chat-input-area textarea {
    resize: none;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 14px;
    transition: border-color 0.2s ease;
}

.chat-input-area textarea:focus {
    border-color: #007bff;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
    outline: none;
}

/* Toggle Button Icon Animation */
#chat-toggle-icon {
    transition: transform 0.3s ease;
}

.chat-sidebar.open #chat-toggle-icon {
    transform: rotate(180deg);
}

/* Chat Toggle Tab (when collapsed) */
.chat-toggle-tab {
    position: fixed;
    top: 50%;
    right: 0;
    transform: translateY(-50%);
    background: linear-gradient(135deg, #007bff, #0056b3);
    color: white;
    border: none;
    border-radius: 8px 0 0 8px;
    padding: 12px 8px;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    z-index: 999;
    box-shadow: -2px 0 10px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    display: block; /* Show by default since chat is closed */
}

.chat-toggle-tab:hover {
    background: linear-gradient(135deg, #0056b3, #004085);
    transform: translateY(-50%) translateX(-5px);
}

.chat-toggle-tab.hidden {
    display: none;
}

/* Responsive Design */
@media (max-width: 1200px) {
    .chat-sidebar {
        width: 300px;
    }
    
    .main-content {
        margin-right: 0; /* No margin by default */
    }

    .main-content.chat-open {
        margin-right: 300px;
    }
}

@media (max-width: 768px) {
    .chat-sidebar {
        width: 100%;
        transform: translateX(100%); /* Closed by default on mobile */
    }
    
    .main-content {
        margin-right: 0; /* No margin on mobile by default */
    }
    
    .main-content.chat-open {
        margin-right: 0;
    }
    
    .chat-toggle-tab {
        display: block; /* Show toggle tab on mobile */
    }
}

/* Loading states */
.chat-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
}

.chat-loading::after {
    content: '';
    width: 20px;
    height: 20px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Notification styles for chat */
.chat-notification {
    position: absolute;
    top: 10px;
    right: 10px;
    background: #dc3545;
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
    }
}

/* System messages */
.system-message {
    text-align: center;
    background-color: #fff3cd;
    color: #856404;
    padding: 8px 12px;
    border-radius: 4px;
    margin: 10px auto;
    max-width: 80%;
    font-size: 0.9rem;
}

/* Error message */
.error-message {
    text-align: center;
    background-color: #f8d7da;
    color: #721c24;
    padding: 8px 12px;
    border-radius: 4px;
    margin: 10px auto;
    max-width: 80%;
    font-size: 0.9rem;
}

/* Processing indicator */
.processing-indicator {
    padding: 15px;
    margin: 10px 0;
    display: flex;
    justify-content: flex-start;
    align-items: center;
}

.processing-dots {
    display: flex;
    gap: 4px;
    align-items: center;
}

.processing-dots span {
    width: 8px;
    height: 8px;
    background-color: #007bff;
    border-radius: 50%;
    animation: wave 1.4s ease-in-out infinite;
}

.processing-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.processing-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

.processing-dots span:nth-child(3) {
    animation-delay: 0s;
}

@keyframes wave {
    0%, 60%, 100% {
        transform: initial;
        opacity: 0.6;
    }
    30% {
        transform: translateY(-3px);
        opacity: 1;
    }
}

/* Alternative processing indicator - bars */
.processing-bars {
    display: flex;
    gap: 3px;
    align-items: flex-end;
    height: 20px;
}

.processing-bars span {
    width: 3px;
    background-color: #007bff;
    border-radius: 1px;
    animation: bars 1.2s ease-in-out infinite;
}

.processing-bars span:nth-child(1) {
    height: 10px;
    animation-delay: -0.8s;
}

.processing-bars span:nth-child(2) {
    height: 16px;
    animation-delay: -0.6s;
}

.processing-bars span:nth-child(3) {
    height: 12px;
    animation-delay: -0.4s;
}

.processing-bars span:nth-child(4) {
    height: 18px;
    animation-delay: -0.2s;
}

@keyframes bars {
    0%, 40%, 100% {
        transform: scaleY(0.4);
        opacity: 0.6;
    }
    20% {
        transform: scaleY(1);
        opacity: 1;
    }
}

/* Alternative processing indicator - pulsing ellipsis */
.processing-ellipsis {
    display: flex;
    align-items: center;
    gap: 2px;
    height: 20px;
}

.processing-ellipsis span {
    width: 6px;
    height: 6px;
    background-color: #6c757d;
    border-radius: 50%;
    animation: pulse-ellipsis 1.4s ease-in-out infinite;
}

.processing-ellipsis span:nth-child(1) {
    animation-delay: -0.32s;
}

.processing-ellipsis span:nth-child(2) {
    animation-delay: -0.16s;
}

.processing-ellipsis span:nth-child(3) {
    animation-delay: 0s;
}

@keyframes pulse-ellipsis {
    0%, 80%, 100% {
        transform: scale(0);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Progress message styling */
.progress-message {
    opacity: 0.8;
}

.progress-bubble {
    background-color: #e3f2fd !important;
    border: 1px solid #bbdefb;
    font-style: italic;
    color: #1976d2;
    position: relative;
}

.progress-bubble::before {
    content: "⏳";
    margin-right: 6px;
    animation: progress-pulse 1.5s ease-in-out infinite;
}

@keyframes progress-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Mobile responsiveness */
@media (max-width: 576px) {
    #chat-panel {
        width: 100%;
        height: 100%;
        border-radius: 0;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
    }
}
