/* CSS Reset and Variables */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #10a37f;
    --primary-hover: #0d8f73;
    --bg-dark: #343541;
    --bg-darker: #202123;
    --bg-light: #444654;
    --text-primary: #ececf1;
    --text-secondary: #acacbe;
    --border: #565869;
    --error: #ef4444;
    --success: #22c55e;
    --warning: #f59e0b;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --border-radius: 8px;
    --transition: all 0.2s ease;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-primary);
    line-height: 1.6;
    overflow: hidden;
}

/* Utility Classes */
.hidden { display: none !important; }
.flex { display: flex; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }

/* Loading Screen */
.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-content {
    text-align: center;
}

.loading-logo {
    width: 64px;
    height: 64px;
    margin-bottom: 1rem;
    border-radius: 50%;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top: 3px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

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

/* Authentication Styles */
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: linear-gradient(135deg, var(--bg-darker) 0%, var(--bg-dark) 100%);
}

.auth-box {
    background: var(--bg-light);
    padding: 2rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 400px;
    border: 1px solid var(--border);
}

.auth-header {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-logo {
    width: 48px;
    height: 48px;
    margin-bottom: 1rem;
    border-radius: 50%;
}

.auth-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

.auth-form h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    text-align: center;
    color: var(--text-primary);
}

.input-group {
    margin-bottom: 1rem;
}

.input-group input,
.input-group select {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg-darker);
    border: 1px solid var(--border);
    border-radius: var(--border-radius);
    color: var(--text-primary);
    font-size: 0.875rem;
    transition: var(--transition);
}

.input-group input:focus,
.input-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(16, 163, 127, 0.1);
}

.btn-primary {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

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

.btn-primary:active {
    transform: translateY(1px);
}

.auth-switch {
    text-align: center;
    margin-top: 1.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.auth-switch a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

.auth-switch a:hover {
    text-decoration: underline;
}

/* Main App Container */
.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar Styles */
.sidebar {
    width: 260px;
    background: var(--bg-darker);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo {
    width: 32px;
    height: 32px;
    border-radius: 50%;
}

.sidebar-header h1 {
    font-size: 1.125rem;
    font-weight: 600;
}

/* New Chat Button */
.btn-new-chat {
    width: calc(100% - 2rem);
    margin: 1rem;
    padding: 0.75rem 1rem;
    background: var(--primary);
    border: none;
    border-radius: var(--border-radius);
    color: white;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-new-chat:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(16, 163, 127, 0.3);
}

/* Chat History */
.chat-history {
    flex: 1;
    overflow-y: auto;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

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

.history-header span {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.btn-clear-history {
    padding: 0.25rem 0.5rem;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
    border-radius: 4px;
}

.btn-clear-history:hover {
    background: var(--error);
    color: white;
}

/* Chat List */
.chat-list {
    max-height: calc(100vh - 400px);
    overflow-y: auto;
}

.chat-item {
    padding: 0.75rem 1rem;
    cursor: pointer;
    transition: var(--transition);
    border-bottom: 1px solid var(--border);
    position: relative;
}

.chat-item:hover {
    background: var(--bg-light);
}

.chat-item.active {
    background: var(--bg-light);
    border-left: 3px solid var(--primary);
}

.chat-item-title {
    font-size: 0.875rem;
    color: var(--text-primary);
    font-weight: 500;
    margin-bottom: 0.25rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-item-preview {
    font-size: 0.75rem;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-item-date {
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.chat-item-delete {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    padding: 0.25rem;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    opacity: 0;
    transition: var(--transition);
    border-radius: 4px;
}

.chat-item:hover .chat-item-delete {
    opacity: 1;
}

.chat-item-delete:hover {
    background: var(--error);
    color: white;
}

.empty-history {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.user-info {
    margin-top: auto;
    padding: 1rem;
    border-top: 1px solid var(--border);
}

.user-details {
    margin-bottom: 1rem;
}

.user-details span {
    display: block;
    font-size: 0.875rem;
}

#user-email {
    color: var(--text-primary);
    font-weight: 500;
}

#user-role {
    color: var(--text-secondary);
    text-transform: capitalize;
}

.btn-logout {
    width: 100%;
    padding: 0.5rem 1rem;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--border-radius);
    color: var(--text-secondary);
    font-size: 0.875rem;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-logout:hover {
    background: var(--error);
    border-color: var(--error);
    color: white;
}

/* Chat Interface */
.chat-interface {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.chat-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg-dark);
}

.chat-header h2 {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-primary);
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0;
}

.message {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
    animation: fadeIn 0.3s ease-out;
}

.message.user {
    background: var(--bg-dark);
}

.message.bot {
    background: var(--bg-light);
}

.message-content {
    max-width: 48rem;
    margin: 0 auto;
}

.message-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

.message-text {
    color: var(--text-primary);
    line-height: 1.8;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: 0.95rem;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* Enhanced message styling */
.message.bot .message-content {
    background: rgba(16, 163, 127, 0.05);
    padding: 1.5rem;
    border-radius: 12px;
    border-left: 4px solid var(--primary);
}

.message.user .message-content {
    background: rgba(68, 70, 84, 0.3);
    padding: 1.5rem;
    border-radius: 12px;
    border-left: 4px solid var(--text-secondary);
}

/* Section headers in responses */
.message-text .section-header {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--primary);
    margin-top: 1.75rem;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--primary);
    display: block;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

/* First section header needs less top margin */
.message-text .content-section:first-child .section-header {
    margin-top: 0.5rem;
}

/* Content sections with subtle backgrounds */
.message-text .content-section {
    margin: 1.5rem 0;
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 8px;
    border-left: 3px solid transparent;
    transition: all 0.3s ease;
}

.message-text .content-section:first-child {
    margin-top: 0;
}

.message-text .content-section:last-child {
    margin-bottom: 0;
}

.message-text .content-section:hover {
    border-left-color: var(--primary);
    background: rgba(255, 255, 255, 0.04);
}

/* Better numbered lists */
.message-text .numbered-list {
    margin: 1rem 0;
    padding-left: 0;
}

.message-text .numbered-item {
    margin: 0.75rem 0;
    padding: 0.75rem;
    padding-left: 2.5rem;
    background: rgba(16, 163, 127, 0.03);
    border-radius: 6px;
    line-height: 1.8;
    position: relative;
    transition: all 0.2s ease;
}

.message-text .numbered-item:hover {
    background: rgba(16, 163, 127, 0.08);
    transform: translateX(4px);
}

/* Style the numbers differently */
.message-text .numbered-item::before {
    content: attr(data-number);
    position: absolute;
    left: 0.75rem;
    top: 0.75rem;
    width: 1.5rem;
    height: 1.5rem;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.8rem;
}

/* Improved paragraphs */
.message-text .paragraph {
    margin: 1rem 0;
    line-height: 1.9;
    color: var(--text-primary);
}

/* Add subtle animation */
.message-text .content-section,
.message-text .numbered-item,
.message-text .paragraph {
    animation: fadeInUp 0.4s ease-out;
}

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

/* Responsive improvements */
@media (max-width: 768px) {
    .message.bot .message-content,
    .message.user .message-content {
        padding: 1rem;
    }
    
    .message-text .content-section {
        padding: 0.5rem;
    }
    
    .message-text .numbered-item {
        padding-left: 2rem;
    }
}

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

.input-container {
    padding: 1.5rem;
    background: var(--bg-dark);
    border-top: 1px solid var(--border);
}

.input-wrapper {
    display: flex;
    max-width: 48rem;
    margin: 0 auto;
    position: relative;
}

#message-input {
    flex: 1;
    padding: 0.875rem 3rem 0.875rem 1rem;
    background: var(--bg-light);
    border: 1px solid var(--border);
    border-radius: var(--border-radius);
    color: var(--text-primary);
    font-size: 0.875rem;
    transition: var(--transition);
}

#message-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(16, 163, 127, 0.1);
}

.btn-send {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    padding: 0.5rem;
    background: var(--primary);
    border: none;
    border-radius: var(--border-radius);
    color: white;
    cursor: pointer;
    transition: var(--transition);
}

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

.btn-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Admin Dashboard */
.admin-dashboard {
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg-dark);
}

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

.admin-title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.admin-logo {
    width: 32px;
    height: 32px;
    border-radius: 50%;
}

.admin-title h1 {
    font-size: 1.25rem;
    font-weight: 600;
}

.admin-user {
    display: flex;
    align-items: center;
    gap: 1rem;
}

#admin-email {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.admin-nav {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: 0.5rem;
}

.nav-btn {
    padding: 0.5rem 1rem;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--border-radius);
    color: var(--text-secondary);
    font-size: 0.875rem;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-btn:hover {
    background: var(--bg-light);
    color: var(--text-primary);
}

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

.admin-section {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
}

.section-header {
    margin-bottom: 1.5rem;
}

.section-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-light);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    border: 1px solid var(--border);
    text-align: center;
}

.stat-card h3 {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.stat-card p {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
}

.users-table-container {
    background: var(--bg-light);
    border-radius: var(--border-radius);
    border: 1px solid var(--border);
    overflow: hidden;
}

.table-controls {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: 1rem;
}

.search-input,
.role-filter {
    padding: 0.5rem 0.75rem;
    background: var(--bg-darker);
    border: 1px solid var(--border);
    border-radius: var(--border-radius);
    color: var(--text-primary);
    font-size: 0.875rem;
}

.search-input {
    flex: 1;
}

.table-wrapper {
    overflow-x: auto;
}

.users-table {
    width: 100%;
    border-collapse: collapse;
}

.users-table th,
.users-table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.users-table th {
    background: var(--bg-darker);
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.875rem;
}

.users-table td {
    color: var(--text-primary);
}

.role-select {
    padding: 0.25rem 0.5rem;
    background: var(--bg-darker);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 0.75rem;
}

.btn-delete {
    padding: 0.25rem 0.5rem;
    background: var(--error);
    border: none;
    border-radius: 4px;
    color: white;
    cursor: pointer;
    font-size: 0.75rem;
    transition: var(--transition);
}

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

.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 1.5rem;
}

.chart-card {
    background: var(--bg-light);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    border: 1px solid var(--border);
    height: 400px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chart-card h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1rem;
    flex-shrink: 0;
}

.chart-card canvas {
    flex: 1;
    max-width: 100% !important;
    max-height: 100% !important;
    min-height: 0;
}

/* Responsive Design */
@media (max-width: 768px) {
    .sidebar {
        display: none;
    }
    
    .admin-header {
        flex-direction: column;
        gap: 1rem;
        align-items: flex-start;
    }
    
    .admin-nav {
        flex-wrap: wrap;
    }
    
    .table-controls {
        flex-direction: column;
    }
    
    .charts-grid {
        grid-template-columns: 1fr;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
}

/* Scrollbar Styles */
::-webkit-scrollbar {
    width: 8px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

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

/* Loading animation */
.loading-dots {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem 0;
}

.loading-dots span {
    display: inline-block;
    width: 12px;
    height: 12px;
    margin: 0 4px;
    background-color: var(--primary);
    border-radius: 50%;
    animation: loading-bounce 1.4s ease-in-out infinite both;
}

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

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

@keyframes loading-bounce {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1.2);
        opacity: 1;
    }
}

/* Loading message style */
.message.loading .message-content {
    min-height: 60px;
}

/* Chat date headers */
.chat-date-header {
    padding: 0.5rem 1rem;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--bg-darker);
    position: sticky;
    top: 0;
    z-index: 10;
}

.empty-history {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
} 