/* Root Variables */
:root {
    --primary-color: #7C3AED;
    --bg-color: #F3F4F6;
    --chat-bg: #FFFFFF;
    --text-color: #1F2937;
    --secondary-text: #6B7280;
    --border-color: #E5E7EB;
    --success-color: #10B981;
    --error-color: #EF4444;
    --hover-color: rgba(124, 58, 237, 0.1);
}

/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
        Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    background-color: var(--bg-color);
    min-height: 100vh;
    width: 100vw;
    overflow: hidden;
}

/* Main Container */
.chat-container {
    width: 100vw;
    height: 100vh;
    display: grid;
    grid-template-columns: 290px 1fr;
    background-color: var(--chat-bg);
    overflow: hidden;
}

/* Sidebar */
.conversations {
    height: 100vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    grid-row: 1 / -1;
    border-right: 1px solid var(--border-color);
    background-color: var(--bg-color);
}

.new-chat, .file-upload {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

#new-chat-btn, .upload-btn {
    width: 100%;
    padding: 0.75rem;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    text-align: center;
    transition: background-color 0.2s ease;
}

#new-chat-btn:hover, .upload-btn:hover {
    background-color: #6D28D9;
}

.upload-status {
    margin-top: 0.5rem;
    font-size: 0.9rem;
    color: var(--secondary-text);
    padding: 0.5rem;
    border-radius: 4px;
}

.upload-status.success {
    color: var(--success-color);
    background-color: rgba(16, 185, 129, 0.1);
}

.upload-status.error {
    color: var(--error-color);
    background-color: rgba(239, 68, 68, 0.1);
}

/* Conversation item styling */
.conversation {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: background-color 0.2s;
    color: var(--text-color);
}

.conversation-content {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-right: 8px;
}

/* Three dots menu button */
/* Menu Button Styles */
.menu-btn {
    padding: 4px 8px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--secondary-text);
    border-radius: 4px;
    opacity: 0; /* Changed from display: none */
    transition: opacity 0.2s ease;
}


.conversation:hover .menu-btn {
    display: block; /* Changed from visibility: visible */
}

.conversation:hover .menu-btn,
.conversation.active .menu-btn {
    opacity: 1; /* Show on hover and when conversation is active */
}

.menu-btn:hover {
    background-color: var(--hover-color);
    color: var(--primary-color);
}

/* Dropdown Menu Styles */
.conversation-menu {
    position: absolute;
    top: 0;
    right: 40px;
    background-color: var(--chat-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    display: none;
    min-width: 150px;
}


.conversation-menu.active {
    display: block;
    animation: menuAppear 0.2s ease forwards;
}

/* Menu items styling remains the same */
.menu-item {
    display: block;
    width: 100%;
    padding: 8px 16px;
    border: none;
    background: none;
    text-align: left;
    cursor: pointer;
    color: var(--text-color);
    font-size: 0.9rem;
    transition: background-color 0.2s;
    position: relative;
    z-index: 1001;
}

.menu-item span {
    pointer-events: none;
}

.menu-item:first-child {
    border-top-left-radius: 6px;
    border-top-right-radius: 6px;
}

.menu-item:last-child {
    border-bottom-left-radius: 6px;
    border-bottom-right-radius: 6px;
}


.menu-item:hover {
    background-color: var(--hover-color);
}

.menu-item.delete {
    color: var(--error-color);
}

.menu-item.delete:hover {
    background-color: rgba(239, 68, 68, 0.1);
}


/* Add smooth animation */
.conversation-menu {
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 0.2s, transform 0.2s;
    pointer-events: none;
}


.conversation:hover {
    background-color: var(--hover-color);
}

.conversation.active {
    background-color: var(--hover-color);
    border-right: 3px solid var(--primary-color);
}

/* Main Content Area */
.main-content {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background-color: var(--chat-bg);
    overflow: hidden;
    position: relative;
}

/* Header */
header {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 1rem;
    background-color: var(--chat-bg);
    z-index: 10;
}

.go-back {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
    color: var(--text-color);
}

/* Toggle Graph Button */
.toggle-graph-btn {
    display: none;
    padding: 0.5rem 1rem;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    margin-left: auto;
}

.toggle-graph-btn.visible {
    display: block;
}

/* Content Container */
.content-container {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    overflow: hidden;
    min-height: 0;
    position: relative;
}

.content-container.with-graph {
    grid-template-columns: 1fr 1fr;
}

/* Messages Section */
.messages {
    height: calc(100vh - 130px);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1rem;
    padding-bottom: 80px;
}

.message {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 12px;
    line-height: 1.5;
    font-size: 0.95rem;
}

.user-message {
    align-self: flex-end;
    background-color: var(--primary-color);
    color: white;
}

.assistant-message {
    align-self: flex-start;
    background-color: var(--bg-color);
    color: var(--text-color);
}

/* Graph View */
.graph-view {
    display: none;
    height: calc(100vh - 130px);
    border-left: 1px solid var(--border-color);
    overflow: hidden;
    background-color: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.graph-view.visible {
    display: block;
}

.graph-view iframe {
    width: 100%;
    height: 100%;
    border: none;
}

/* Input Container */
.input-container {
    position: fixed;
    bottom: 0;
    left: 290px;
    right: 0;
    padding: 1rem;
    background-color: var(--chat-bg);
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 0.5rem;
    z-index: 100;
}

#user-input {
    flex: 1;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 1rem;
    transition: border-color 0.2s ease;
    outline: none;
}

#user-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(124, 58, 237, 0.1);
}

#send-button {
    padding: 0.75rem 1.5rem;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    font-weight: 500;
}

#send-button:hover {
    background-color: #6D28D9;
}

#send-button:disabled {
    background-color: var(--secondary-text);
    cursor: not-allowed;
}

/* Loading States */
.loading {
    opacity: 0.7;
    pointer-events: none;
}

.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s ease-in-out infinite;
}

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

/* Animation */
@keyframes menuAppear {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(-10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* Mobile Styles */
@media (max-width: 768px) {
    .conversations {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 1000;
    }

    .conversations.active {
        transform: translateX(0);
    }

    .conversations.active .file-upload {
        transform: translateX(0);
    }

    .file-upload {
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 1001;
    }
}


/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-color);
}

::-webkit-scrollbar-thumb {
    background: #CBD5E1;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94A3B8;
}

/* Helper Classes */
.hidden {
    display: none !important;
}

.visible {
    display: block !important;
}

/* Mobile Styles */
@media (max-width: 768px) {
    .chat-container {
        grid-template-columns: 1fr;
    }

    .conversations {
        position: fixed;
        left: 0;
        top: 0;
        width: 100%;
        z-index: 20;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }

    .conversations.active {
        transform: translateX(0);
    }

    .go-back {
        display: block;
    }

    /* Update content container for mobile */
    .content-container {
        display: flex;
        flex-direction: row;
        overflow-x: hidden;
        width: 100%;
        position: relative;
    }

    /* Update messages container for mobile */
    .messages {
        height: calc(100vh - 120px);
        width: 100%;
        flex-shrink: 0;
        transition: width 0.3s ease;
        padding: 1rem;
        padding-bottom: 80px;
    }

    .content-container.with-graph .messages {
        width: 50%;
    }

    /* Update graph view for mobile */
    .graph-view {
        height: calc(100vh - 120px);
        width: 50%;
        position: relative;
        flex-shrink: 0;
        transform: none;
        border-left: 1px solid var(--border-color);
        transition: width 0.3s ease;
    }

    .message {
        max-width: 90%;
    }

    /* Update input container for mobile */
    .input-container {
        left: 0;
        width: 100%;
        transition: width 0.3s ease;
    }

    .content-container.with-graph ~ .input-container {
        width: 50%;
    }
}


/* Add smaller screen breakpoint for very small devices */
@media (max-width: 480px) {
    .content-container.with-graph .messages {
        width: 100%;
    }

    .graph-view {
        position: fixed;
        top: 60px;
        right: 0;
        width: 100%;
        z-index: 15;
        transform: translateX(100%);
        transition: transform 0.3s ease;
    }

    .graph-view.visible {
        transform: translateX(0);
    }

    .content-container.with-graph ~ .input-container {
        width: 100%;
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #1F2937;
        --chat-bg: #374151;
        --text-color: #F9FAFB;
        --secondary-text: #9CA3AF;
        --border-color: #4B5563;
    }

    .message.assistant-message {
        background-color: #4B5563;
    }

    #user-input {
        background-color: #4B5563;
        color: var(--text-color);
    }
}

#conversation-list {
    flex: 1;
    overflow-y: auto;
    min-height: 0; /* Add this */
}


.new-chat {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.file-upload {
    padding: 1rem;
    border-top: 1px solid var(--border-color);
    background-color: var(--bg-color);
    z-index: 2; /* Ensure it stays above other content */
}