/* ===== Reset & Base ===== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg: #0f0f13;
    --bg-card: #1a1a24;
    --bg-hover: #22223a;
    --text: #e0e0e8;
    --text-muted: #8888a0;
    --primary: #6c5ce7;
    --primary-hover: #7d6ff0;
    --accent: #00cec9;
    --danger: #e74c3c;
    --border: #2a2a3d;
    --radius: 8px;
    --shadow: 0 2px 8px rgba(0,0,0,0.3);
    --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
}

/* ===== Navbar ===== */
.navbar {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 0 2rem;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}

.navbar-brand {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    text-decoration: none;
    letter-spacing: -0.5px;
}

.navbar-links {
    display: flex;
    gap: 0.25rem;
    list-style: none;
}

.navbar-links a {
    color: var(--text-muted);
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s;
}

.navbar-links a:hover,
.navbar-links a.active {
    color: var(--text);
    background: var(--bg-hover);
}

/* ===== Container ===== */
.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 2rem;
}

/* ===== Cards ===== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.25rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

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

.btn-danger {
    background: var(--danger);
    color: white;
}
.btn-danger:hover { background: #c0392b; }

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}
.btn-outline:hover { background: var(--bg-hover); }

/* ===== Forms ===== */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.35rem;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.form-input {
    width: 100%;
    padding: 0.65rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    font-size: 0.95rem;
    transition: border-color 0.2s;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
}

textarea.form-input {
    resize: vertical;
    min-height: 80px;
}

/* ===== Tables ===== */
.table {
    width: 100%;
    border-collapse: collapse;
}

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

.table th {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}

.table tr:hover td {
    background: var(--bg-hover);
}

/* ===== Chat ===== */
.chat-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 56px - 4rem);
    max-width: 800px;
    margin: 0 auto;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.message {
    max-width: 85%;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    font-size: 0.95rem;
    line-height: 1.5;
}

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

.message.bot {
    align-self: flex-start;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-bottom-left-radius: 2px;
}

.message .sources {
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Markdown-rendered content inside bot messages */
.message.bot strong { color: var(--accent); font-weight: 700; }
.message.bot em { color: var(--text); font-style: italic; }
.message.bot code {
    background: var(--bg);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.85em;
    font-family: monospace;
}
.message.bot pre {
    background: var(--bg);
    padding: 0.75rem;
    border-radius: var(--radius);
    overflow-x: auto;
    margin: 0.5rem 0;
}
.message.bot pre code {
    background: none;
    padding: 0;
}
.message.bot ul, .message.bot ol {
    padding-left: 1.25rem;
    margin: 0.5rem 0;
}
.message.bot li {
    margin-bottom: 0.25rem;
}
.message.bot p {
    margin-bottom: 0.5rem;
}
.message.bot p:last-child {
    margin-bottom: 0;
}
.message.bot h1, .message.bot h2, .message.bot h3,
.message.bot h4, .message.bot h5, .message.bot h6 {
    margin: 0.75rem 0 0.5rem;
    line-height: 1.3;
}
.message.bot blockquote {
    border-left: 3px solid var(--primary);
    padding-left: 1rem;
    color: var(--text-muted);
    margin: 0.5rem 0;
}
.message.bot a {
    color: var(--accent);
    text-decoration: underline;
}

.chat-input-area {
    padding: 1rem 1.5rem;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    display: flex;
    gap: 0.75rem;
}

.chat-input-area .form-input {
    flex: 1;
}

/* ===== File Upload ===== */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 3rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 1.5rem;
}

.upload-zone:hover,
.upload-zone.drag-over {
    border-color: var(--primary);
    background: var(--bg-hover);
}

.upload-zone p {
    color: var(--text-muted);
    margin-top: 0.5rem;
    font-size: 0.9rem;
}

/* ===== Status Badges ===== */
.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-success { background: #27ae60; color: white; }
.badge-warning { background: #f39c12; color: white; }
.badge-error { background: var(--danger); color: white; }

/* ===== Alerts ===== */
.alert {
    padding: 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.alert-error {
    background: rgba(231, 76, 60, 0.15);
    border: 1px solid var(--danger);
    color: #e74c3c;
}

.alert-success {
    background: rgba(39, 174, 96, 0.15);
    border: 1px solid #27ae60;
    color: #27ae60;
}

.alert-info {
    background: rgba(108, 92, 231, 0.15);
    border: 1px solid var(--primary);
    color: var(--primary);
}

/* ===== Progress Bar ===== */
.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--bg);
    border-radius: 4px;
    overflow: hidden;
    margin: 0.5rem 0;
}

.progress-bar-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 4px;
    transition: width 0.3s;
}

/* ===== Spinner ===== */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ===== Settings ===== */
.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
}

.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
}

.setting-row:last-child { border-bottom: none; }

.setting-label {
    font-weight: 500;
}

.setting-value {
    color: var(--text-muted);
    font-family: monospace;
    font-size: 0.85rem;
}

/* ===== Utility ===== */
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ===== Mobile Responsive ===== */

/* Hamburger menu — hidden on desktop */
.hamburger {
    display: none;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text);
    cursor: pointer;
    width: 40px;
    height: 40px;
    border-radius: var(--radius);
}
.hamburger:hover {
    background: var(--bg-hover);
}

@media (max-width: 768px) {
    .navbar {
        padding: 0 1rem;
    }

    .hamburger {
        display: flex;
    }

    .navbar-links {
        position: absolute;
        top: 56px;
        left: 0;
        right: 0;
        background: var(--bg-card);
        flex-direction: column;
        padding: 0.5rem;
        border-bottom: 1px solid var(--border);
        display: none;
        z-index: 99;
    }
    .navbar-links.open {
        display: flex;
    }
    .navbar-links a {
        padding: 0.75rem 1rem;
        border-radius: var(--radius);
    }

    .container {
        padding: 1rem;
    }

    .chat-container {
        height: calc(100vh - 56px);
        max-width: 100%;
    }

    .chat-messages {
        padding: 1rem;
    }

    .message {
        max-width: 90%;
        font-size: 0.9rem;
    }

    .chat-input-area {
        padding: 0.75rem;
        gap: 0.5rem;
    }
    .chat-input-area .btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.85rem;
        white-space: nowrap;
    }

    .settings-grid {
        grid-template-columns: 1fr;
    }

    .upload-zone {
        padding: 1.5rem 1rem;
    }
    .upload-zone p {
        font-size: 0.85rem;
    }

    .table {
        font-size: 0.8rem;
    }
    .table th, .table td {
        padding: 0.5rem 0.4rem;
    }
    .table thead th:nth-child(4),
    .table tbody td:nth-child(4),
    .table thead th:nth-child(5),
    .table tbody td:nth-child(5) {
        display: none;
    }
}

@media (max-width: 480px) {
    h1 {
        font-size: 1.5rem !important;
    }
    h2 {
        font-size: 1.25rem !important;
    }
    h3 {
        font-size: 1.1rem !important;
    }

    .message {
        max-width: 95%;
        padding: 0.65rem 0.85rem;
    }

    .btn {
        padding: 0.5rem 1rem;
        font-size: 0.85rem;
    }

    .card {
        padding: 1rem;
    }

    .upload-zone {
        padding: 1.25rem 0.75rem;
    }

    .table {
        font-size: 0.75rem;
    }
}
