/* Modern Design System & CSS Reset */
:root {
    --bg-main: #0f172a;
    --bg-secondary: #1e293b;
    --sidebar-bg: #0b1121;
    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --text-primary: #f8fafc;
    --text-muted: #94a3b8;
    --border: rgba(51, 65, 85, 0.5);
    --bot-msg-bg: #334155;
    --user-msg-bg: #6366f1;
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --glass: rgba(30, 41, 59, 0.7);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --message-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    display: flex;
}

.app-container {
    display: flex;
    width: 100%;
    height: 100%;
}

/* Sidebar Styling */
.sidebar {
    width: 280px;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    transition: var(--transition);
}

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

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    font-size: 1.25rem;
}

.logo-icon {
    width: 2rem;
    height: 2rem;
    background: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.new-chat-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    transition: var(--transition);
    margin-bottom: 2rem;
    font-weight: 500;
}

.new-chat-btn:hover {
    background: var(--border);
    border-color: var(--accent);
}

.chat-history {
    flex-grow: 1;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: 10px;
    cursor: pointer;
    color: var(--text-muted);
    transition: var(--transition);
    border: 1px solid transparent;
    margin-bottom: 0.5rem;
}

.history-item:hover, .history-item.active {
    background: rgba(99, 102, 241, 0.1);
    color: var(--text-primary);
    border-color: rgba(99, 102, 241, 0.3);
}

.sidebar-footer {
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-avatar {
    width: 2.5rem;
    height: 2.5rem;
    background: #475569;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
}

.user-info {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-weight: 600;
    font-size: 0.875rem;
}

.user-status {
    color: #10b981;
    font-size: 0.75rem;
}

/* Chat Main Area Styling */
.chat-main {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background: linear-gradient(135deg, #0f172a 0%, #171717 100%);
}

.chat-header {
    height: 70px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.sidebar-toggle {
    display: none;
}

.bot-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.bot-status-indicator {
    width: 0.75rem;
    height: 0.75rem;
    background: #10b981;
    border-radius: 50%;
    box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.2);
}

.chat-header h1 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.25rem;
    font-weight: 600;
}

/* Messages List Styling */
.messages-container {
    flex-grow: 1;
    overflow-y: auto;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.messages-container::-webkit-scrollbar {
    width: 6px;
}

.messages-container::-webkit-scrollbar-thumb {
    background-color: var(--border);
    border-radius: 10px;
}

.message {
    display: flex;
    gap: 1.25rem;
    max-width: 80%;
    animation: slideUp 0.4s ease-out;
}

.message.bot {
    align-self: flex-start;
}

.message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-avatar {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.bot .message-avatar {
    background: var(--accent);
    color: white;
}

.user .message-avatar {
    background: #475569;
    color: white;
}

.message-content {
    padding: 1rem 1.25rem;
    border-radius: 1.25rem;
    line-height: 1.6;
    font-size: 0.9375rem;
    position: relative;
    box-shadow: var(--message-shadow);
}

.bot .message-content {
    background: var(--bot-msg-bg);
    border-bottom-left-radius: 4px;
}

.user .message-content {
    background: var(--user-msg-bg);
    border-bottom-right-radius: 4px;
}

.message-time {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

.user .message-time {
    color: rgba(255, 255, 255, 0.7);
    text-align: right;
}

/* typing bubble */
.message.bot .typing {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.typing span {
    width: 6px;
    height: 6px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.typing span:nth-child(1) { animation-delay: -0.32s; }
.typing span:nth-child(2) { animation-delay: -0.16s; }

.retry-text {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
    font-style: italic;
}

/* Input Footer Styling */
.chat-footer {
    padding: 1.5rem 2rem 2rem;
    background: transparent;
    max-width: 900px;
    width: 100%;
    margin: 0 auto;
}

.input-wrapper {
    position: relative;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 0.75rem 1rem;
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
    transition: var(--transition);
    box-shadow: var(--shadow-lg);
}

.input-wrapper:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

textarea {
    flex-grow: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9375rem;
    resize: none;
    max-height: 200px;
    padding: 0.5rem 0;
    outline: none;
}

textarea::placeholder {
    color: var(--text-muted);
}

.send-btn {
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 10px;
    width: 2.5rem;
    height: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
}

.send-btn:hover:not(:disabled) {
    background: var(--accent-hover);
    transform: scale(1.05);
}

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

.footer-note {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 1rem;
}

/* Animations */
@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

.fade-in {
    animation: slideUp 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        left: -100%;
        z-index: 100;
        height: 100%;
    }

    .sidebar.open {
        left: 0;
    }

    .sidebar-toggle {
        display: block;
        cursor: pointer;
    }

    .message {
        max-width: 90%;
    }

    .chat-header {
        padding: 0 1rem;
    }

    .chat-footer {
        padding: 1rem;
    }
}

/* Markdown Content Styles */
.message-content h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 1rem 0 0.75rem;
    color: var(--text-primary);
    line-height: 1.3;
}

.message-content h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0.875rem 0 0.625rem;
    color: var(--text-primary);
    line-height: 1.35;
}

.message-content h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0.75rem 0 0.5rem;
    color: var(--accent);
    line-height: 1.4;
}

.message-content p {
    margin: 0.5rem 0;
    line-height: 1.7;
}

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

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

.message-content ul,
.message-content ol {
    margin: 0.75rem 0;
    padding-left: 1.5rem;
}

.message-content li {
    margin: 0.375rem 0;
    line-height: 1.6;
}

.message-content ul li {
    list-style-type: disc;
}

.message-content ol li {
    list-style-type: decimal;
}

.message-content code {
    background: rgba(0, 0, 0, 0.3);
    color: #e879f9;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.85em;
}

.message-content pre {
    background: #0d1117;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    margin: 0.75rem 0;
    overflow-x: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.message-content pre::-webkit-scrollbar {
    height: 6px;
}

.message-content pre::-webkit-scrollbar-thumb {
    background-color: var(--border);
    border-radius: 10px;
}

.message-content pre code {
    background: transparent;
    color: var(--text-primary);
    padding: 0;
    font-size: 0.875rem;
    line-height: 1.6;
}

.message-content blockquote {
    border-left: 4px solid var(--accent);
    background: rgba(99, 102, 241, 0.1);
    padding: 0.75rem 1rem;
    margin: 0.75rem 0;
    border-radius: 0 8px 8px 0;
    font-style: italic;
    color: var(--text-muted);
}

.message-content blockquote p {
    margin: 0;
}

.message-content a {
    color: var(--accent);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: var(--transition);
}

.message-content a:hover {
    border-bottom-color: var(--accent);
}

.message-content hr {
    border: none;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--border), transparent);
    margin: 1rem 0;
}

.message-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.75rem 0;
    font-size: 0.9rem;
}

.message-content th,
.message-content td {
    border: 1px solid var(--border);
    padding: 0.5rem 0.75rem;
    text-align: left;
}

.message-content th {
    background: rgba(99, 102, 241, 0.15);
    font-weight: 600;
}

.message-content tr:nth-child(even) {
    background: rgba(0, 0, 0, 0.15);
}

.message-content img {
    max-width: 100%;
    border-radius: 8px;
    margin: 0.5rem 0;
}

.message-content strong {
    font-weight: 600;
    color: var(--text-primary);
}

.message-content em {
    font-style: italic;
    color: var(--text-muted);
}

.message-content del {
    text-decoration: line-through;
    opacity: 0.7;
}

/* Long content scroll */
.message-content {
    max-height: 500px;
    overflow-y: auto;
}

.bot .message-content {
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.bot .message-content::-webkit-scrollbar {
    width: 4px;
}

.bot .message-content::-webkit-scrollbar-thumb {
    background-color: var(--border);
    border-radius: 10px;
}

/* Highlight.js overrides for dark theme */
.hljs {
    background: transparent !important;
}
