/* Modern CSS Variables */
:root {
    --primary-color: #2563eb;
    --primary-dark: #1d4ed8;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --error-color: #ef4444;
    
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #e2e8f0;
    --bg-dark: #1e293b;
    
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-light: #94a3b8;
    
    --border-color: #e2e8f0;
    --border-radius: 8px;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
    font-size: 16px;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-secondary);
}

/* Login Page Styles */
.login-page {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.background-pattern {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        radial-gradient(circle at 25% 25%, rgba(255,255,255,0.1) 2px, transparent 2px),
        radial-gradient(circle at 75% 75%, rgba(255,255,255,0.1) 2px, transparent 2px);
    background-size: 50px 50px;
    z-index: 1;
}

.login-container {
    position: relative;
    z-index: 2;
    width: 100%;
    max-width: 400px;
    padding: 2rem;
}

.login-card {
    background: var(--bg-primary);
    padding: 3rem 2rem;
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.logo h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    color: var(--primary-color);
}

.tagline {
    color: var(--text-secondary);
    margin-bottom: 2rem;
    font-size: 1.1rem;
}

.login-form {
    text-align: left;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-primary);
}

.form-group input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.login-btn {
    width: 100%;
    padding: 0.875rem 1.5rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
}

.login-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.error-message {
    background: #fef2f2;
    color: var(--error-color);
    padding: 0.75rem;
    border-radius: var(--border-radius);
    margin-bottom: 1rem;
    border: 1px solid #fecaca;
}

.success-message {
    background: #f0fdf4;
    color: var(--success-color);
    padding: 0.75rem;
    border-radius: var(--border-radius);
    margin-bottom: 1rem;
    border: 1px solid #bbf7d0;
}

.demo-info {
    margin-top: 1.5rem;
    color: var(--text-light);
}

/* Chat Page Styles */
.chat-page {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.chat-container {
    height: 100vh;
    display: flex;
    flex-direction: row;
    max-width: 1400px;
    margin: 0 auto;
    background: var(--bg-primary);
    box-shadow: var(--shadow-md);
}

/* Conversation Sidebar */
.conversation-sidebar {
    width: 300px;
    min-width: 300px;
    background: var(--bg-secondary);
    border-right: 2px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 100vh;
    transition: margin-left 0.3s ease;
}

.conversation-sidebar.hidden {
    margin-left: -300px;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-primary);
}

.sidebar-header h3 {
    font-size: 1.1rem;
    color: var(--text-primary);
    margin: 0;
}

.new-conversation-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: background-color 0.2s;
}

.new-conversation-btn:hover {
    background: var(--primary-dark);
}

.conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.conversation-item {
    padding: 0.75rem;
    margin: 0.25rem 0;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: background-color 0.2s;
    border: 1px solid transparent;
}

.conversation-item:hover {
    background: var(--bg-tertiary);
}

.conversation-item.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-dark);
}

.conversation-title {
    font-weight: 500;
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    opacity: 0.8;
}

.message-count {
    color: var(--text-light);
}

.conversation-item.active .message-count {
    color: rgba(255, 255, 255, 0.8);
}

.delete-conversation-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
    font-size: 0.8rem;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.delete-conversation-btn:hover {
    opacity: 1;
    background: rgba(239, 68, 68, 0.1);
}

.conversation-item.active .delete-conversation-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Main Chat Area */
.main-chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.sidebar-toggle {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.5rem;
    margin-right: 1rem;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.sidebar-toggle:hover {
    background: var(--bg-secondary);
}

.conversation-title-display {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-left: 1rem;
    font-style: italic;
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background: var(--bg-primary);
    border-bottom: 2px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

.header-left h1 {
    font-size: 1.5rem;
    color: var(--primary-color);
    margin-bottom: 0.25rem;
}

.user-info {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.logout-btn {
    padding: 0.5rem 1rem;
    background: var(--error-color);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 0.9rem;
    transition: background-color 0.2s;
}

.logout-btn:hover {
    background: #dc2626;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    background: var(--bg-secondary);
}

.welcome-message {
    text-align: center;
    max-width: 600px;
    margin: 2rem auto;
    padding: 2rem;
    background: var(--bg-primary);
    border-radius: 12px;
    box-shadow: var(--shadow-md);
}

.butler-avatar {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.welcome-message h2 {
    color: var(--primary-color);
    margin-bottom: 1rem;
}

.example-prompts {
    margin-top: 1.5rem;
    text-align: left;
}

.example-prompts ul {
    list-style: none;
    padding-left: 0;
}

.example-prompts li {
    padding: 0.5rem 0;
    color: var(--text-secondary);
    font-style: italic;
}

.message {
    margin-bottom: 1.5rem;
    animation: fadeIn 0.3s ease-in;
}

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

.message.user {
    display: flex;
    justify-content: flex-end;
}

.message.assistant {
    display: flex;
    justify-content: flex-start;
}

.message-content {
    max-width: 70%;
    padding: 1rem 1.5rem;
    border-radius: 18px;
    box-shadow: var(--shadow-sm);
}

.message.user .message-content {
    background: var(--primary-color);
    color: white;
    border-bottom-right-radius: 6px;
}

.message.assistant .message-content {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 6px;
}

.message-content strong {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    opacity: 0.8;
}

.message-content p {
    margin: 0;
    line-height: 1.5;
}

.api-debug {
    margin-top: 1rem;
    font-size: 0.8rem;
}

.api-debug summary {
    cursor: pointer;
    color: var(--text-light);
    margin-bottom: 0.5rem;
}

.api-debug pre {
    background: var(--bg-tertiary);
    padding: 0.5rem;
    border-radius: 4px;
    overflow-x: auto;
    white-space: pre-wrap;
    font-size: 0.75rem;
}

.chat-input-container {
    padding: 1.5rem 2rem;
    background: var(--bg-primary);
    border-top: 2px solid var(--border-color);
}

.input-group {
    display: flex;
    gap: 0.5rem;
    max-width: 800px;
    margin: 0 auto;
}

.chat-form input {
    flex: 1;
    padding: 0.875rem 1.25rem;
    border: 2px solid var(--border-color);
    border-radius: 25px;
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-form input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.chat-form button {
    padding: 0.875rem 1.25rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, transform 0.1s;
    min-width: 48px;
    height: 48px;
}

.chat-form button:hover:not(:disabled) {
    background: var(--primary-dark);
    transform: scale(1.05);
}

.chat-form button:disabled {
    background: var(--text-light);
    cursor: not-allowed;
}

.send-icon {
    font-size: 1.2rem;
}

.loading-indicator {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-primary);
    padding: 1rem 2rem;
    border-radius: 25px;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    z-index: 1000;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top: 2px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Responsive Design */
@media (max-width: 768px) {
    .chat-header {
        padding: 1rem;
    }
    
    .chat-messages {
        padding: 1rem;
    }
    
    .message-content {
        max-width: 90%;
    }
    
    .chat-input-container {
        padding: 1rem;
    }
    
    .login-container {
        padding: 1rem;
    }
    
    .login-card {
        padding: 2rem 1rem;
    }
}

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

.chat-messages::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--text-light);
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* GitHub Integration Styles */
.admin-btn {
    padding: 0.5rem 1rem;
    background: var(--warning-color);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 0.9rem;
    transition: background-color 0.2s;
    margin-right: 0.5rem;
    text-decoration: none;
    display: inline-block;
}

.admin-btn:hover {
    background: #d97706;
    color: white;
}

.github-btn {
    padding: 0.5rem 1rem;
    background: #24292e;
    color: white;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 0.9rem;
    transition: background-color 0.2s;
    margin-right: 0.5rem;
}

.github-btn:hover {
    background: #1b1f23;
}

.graph-btn {
    padding: 0.5rem 1rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 0.9rem;
    transition: background-color 0.2s;
    margin-right: 0.5rem;
    text-decoration: none;
    display: inline-block;
}

.graph-btn:hover {
    background: var(--primary-dark);
    color: white;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.modal-content {
    background: var(--bg-primary);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    color: var(--text-primary);
    margin: 0;
}

.modal-close {
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-light);
    transition: color 0.2s;
}

.modal-close:hover {
    color: var(--text-primary);
}

/* GitHub Form Styles */
.github-form {
    padding: 1.5rem;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-primary);
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 1rem;
    transition: border-color 0.2s;
    font-family: inherit;
    resize: vertical;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-group small {
    display: block;
    margin-top: 0.25rem;
    color: var(--text-light);
    font-size: 0.875rem;
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.btn-primary,
.btn-secondary {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    transition: background-color 0.2s, transform 0.1s;
}

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

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--text-light);
}

/* Success/Error Messages */
.message-alert {
    padding: 1rem;
    border-radius: var(--border-radius);
    margin-bottom: 1rem;
    font-weight: 500;
}

.message-alert.success {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #10b981;
}

.message-alert.error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #ef4444;
}

/* Responsive adjustments for mobile */
@media (max-width: 768px) {
    .modal-content {
        width: 95%;
        margin: 1rem;
    }
    
    .github-form {
        padding: 1rem;
    }
    
    .form-actions {
        flex-direction: column;
    }
    
    .btn-primary,
    .btn-secondary {
        width: 100%;
    }
    
    .github-btn {
        font-size: 0.8rem;
        padding: 0.4rem 0.8rem;
    }
    
    /* Conversation sidebar mobile styles */
    .chat-container {
        flex-direction: column;
    }
    
    .conversation-sidebar {
        width: 100%;
        min-width: unset;
        height: auto;
        max-height: 200px;
        border-right: none;
        border-bottom: 2px solid var(--border-color);
    }
    
    .conversation-sidebar.hidden {
        margin-left: 0;
        margin-top: -200px;
    }
    
    .main-chat-area {
        height: calc(100vh - 200px);
    }
    
    .sidebar-toggle {
        display: block;
    }
    
    .conversation-title-display {
        display: none;
    }
}

/* Desktop styles */
@media (min-width: 769px) {
    .sidebar-toggle {
        display: none;
    }
}