:root {
    --bg-dark: #0f172a;
    --bg-darker: #020617;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --card-bg: rgba(30, 41, 59, 0.7);
    --border-color: rgba(148, 163, 184, 0.1);
    --glass: rgba(255, 255, 255, 0.05);
}

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

body {
    background-color: var(--bg-dark);
    background-image:
        radial-gradient(at 0% 0%, rgba(59, 130, 246, 0.1) 0px, transparent 50%),
        radial-gradient(at 100% 0%, rgba(16, 185, 129, 0.1) 0px, transparent 50%);
    color: var(--text-primary);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    min-height: 100vh;
    line-height: 1.6;
}

/* Typography */
h1,
h2,
h3 {
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    line-height: 1.2;
}

h1 {
    font-size: 2.5rem;
    background: linear-gradient(to right, #fff, #94a3b8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

a {
    color: var(--accent);
    text-decoration: none;
    transition: 0.2s;
}

a:hover {
    color: var(--accent-hover);
}

/* Layout */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* Legacy Sidebar removed */

.main-content {
    flex: 1;
    margin-left: 260px;
    padding: 2rem;
    max-width: 1400px;
}

/* Navigation */
.nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    color: var(--text-secondary);
    border-radius: 0.5rem;
    margin-bottom: 0.25rem;
    font-weight: 500;
}

.nav-link:hover,
.nav-link.active {
    background: var(--glass);
    color: var(--text-primary);
    border-left: 3px solid var(--accent);
}

.nav-section {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #64748b;
    margin: 1.5rem 0 0.5rem;
    font-weight: 600;
}

/* Cards */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    padding: 1.5rem;
    margin-bottom: 2rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

/* --- CHAT INTERFACE STYLES --- */
.chat-body {
    height: 100vh;
    overflow: hidden;
    background: #0f172a;
}

.chat-layout {
    display: flex;
    height: 100vh;
    width: 100vw;
}

.sidebar {
    width: 280px;
    min-width: 280px;
    /* Force width */
    flex-shrink: 0;
    /* Don't shrink */
    background: #1e293b;
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    z-index: 50;
}

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

.logo {
    font-family: 'Outfit', sans-serif;
    font-size: 1.5rem;
    color: var(--accent);
    margin-bottom: 1rem;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
}

.avatar {
    width: 32px;
    height: 32px;
    background: var(--primary);
    border-radius: 50%;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

.username {
    font-weight: 500;
    font-size: 0.9rem;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-menu {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex: 1;
}

.menu-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-secondary);
    border: 1px solid transparent;
    width: 100%;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s;
}

.menu-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: white;
    border-color: rgba(255, 255, 255, 0.1);
}

.menu-btn i {
    width: 18px;
    height: 18px;
}

.menu-btn.logout {
    color: #f87171;
    margin-top: auto;
}

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background: radial-gradient(circle at top right, #1e293b 0%, #0f172a 60%);
}

.chat-header {
    padding: 1rem;
    background: #1e293b;
    display: none;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    scroll-behavior: smooth;
}

.message {
    display: flex;
    width: 100%;
}

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

.ai-message {
    justify-content: flex-start;
}

.bubble {
    max-width: 80%;
    padding: 1rem 1.5rem;
    border-radius: 12px;
    font-size: 1rem;
    line-height: 1.5;
    word-wrap: break-word;
}

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

.ai-message .bubble {
    background: #334155;
    color: #e2e8f0;
    border-bottom-left-radius: 2px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

/* Typing dot animation */
.typing-indicator .bubble {
    padding: 0.8rem 1.2rem;
}

.chat-input-area {
    padding: 1.5rem;
    background: #1e293b;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

#chat-form {
    display: flex;
    gap: 10px;
    max-width: 900px;
    margin: 0 auto;
}

#user-input {
    flex: 1;
    padding: 1rem;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: #0f172a;
    color: white;
    outline: none;
    transition: border 0.2s;
}

#user-input:focus {
    border-color: var(--primary);
}

#send-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0 1.5rem;
    border-radius: 12px;
    cursor: pointer;
    transition: transform 0.1s;
}

#send-btn:active {
    transform: scale(0.95);
}

/* Markdown Styling in Bubbles */
.bubble table {
    width: 100%;
    border-collapse: collapse;
    margin: 10px 0;
    font-size: 0.9rem;
}

.bubble th,
.bubble td {
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 8px;
    text-align: left;
}

.bubble th {
    background: rgba(0, 0, 0, 0.2);
}

.bubble strong {
    color: #fff;
}

/* Mobile Responsive */
@media (max-width: 768px) {

    /* Hide sidebar by default on mobile, slide in from RIGHT */
    .sidebar {
        display: flex;
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        z-index: 100;
        transform: translateX(100%);
        transition: transform 0.3s ease-in-out;
        width: 85%;
        max-width: 320px;
        box-shadow: -5px 0 15px rgba(0, 0, 0, 0.5);
    }

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

    .chat-header {
        display: flex;
        align-items: center;
    }

    .chat-main {
        height: 100vh;
        width: 100%;
    }

    .bubble {
        max-width: 90%;
    }

    /* Ensure only mobile elements show */
    .mobile-only {
        display: block;
    }
}

@media (min-width: 769px) {
    .sidebar {
        display: flex !important;
        transform: none !important;
        position: relative;
        box-shadow: none;
    }

    .chat-header {
        display: none;
    }

    /* Hide header on desktop if desired, or keep */
    .mobile-only {
        display: none !important;
    }
}


/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.6rem 1.25rem;
    border-radius: 0.5rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    font-size: 0.95rem;
    gap: 0.5rem;
}

.btn-primary {
    background: var(--accent);
    color: white;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

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

.btn-glass {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-glass:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* Forms */
input {
    width: 100%;
    padding: 0.75rem;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    color: white;
    font-family: inherit;
    margin-bottom: 1rem;
}

input:focus {
    outline: none;
    border-color: var(--accent);
}

label {
    display: block;
    margin-bottom: 0.4rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* Utilities */
.text-center {
    text-align: center;
}

.mb-4 {
    margin-bottom: 1rem;
}

.mt-4 {
    margin-top: 1rem;
}

.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

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

@media (max-width: 600px) {
    .flex-between {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .flex-between>div {
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    h1 {
        font-size: 1.8rem;
    }

    .app-container {
        padding: 1rem;
    }
}

/* Alert */
.alert {
    padding: 1rem;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
    border-left: 4px solid;
}

.alert-warning {
    background: rgba(245, 158, 11, 0.1);
    border-color: var(--warning);
    color: #fbbf24;
}

.alert-danger {
    background: rgba(239, 68, 68, 0.1);
    border-color: var(--danger);
    color: #f87171;
}

.alert-info {
    background: rgba(59, 130, 246, 0.1);
    border-color: var(--accent);
    color: #60a5fa;
}

/* Login Page Specific */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem;
}

.login-card {
    width: 100%;
    max-width: 400px;
}