:root {
    --bg-color: #0f172a;
    --sidebar-bg: #1e293b;
    --card-bg: rgba(30, 41, 59, 0.7);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent-color: #3b82f6;
    --accent-hover: #2563eb;
    --success-color: #10b981;
    --error-color: #ef4444;
    --glass-border: 1px solid rgba(255, 255, 255, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --font-main: 'Inter', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-color);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    display: flex;
}

/* Typography */
h1,
h2,
h3 {
    font-weight: 600;
    letter-spacing: -0.025em;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--sidebar-bg);
    border-right: var(--glass-border);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    transition: transform 0.3s ease;
}

.brand {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent-color);
    margin-bottom: 2rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-links {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.nav-item {
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 500;
}

.nav-item:hover,
.nav-item.active {
    background-color: rgba(59, 130, 246, 0.1);
    color: var(--accent-color);
}

.nav-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.nav-item .delete-btn {
    opacity: 0;
    visibility: hidden;
    color: var(--text-secondary);
    transition: all 0.2s;
    padding: 2px;
}

.nav-item:hover .delete-btn {
    opacity: 1;
    visibility: visible;
}

.nav-item .delete-btn:hover {
    color: var(--error-color);
    background: rgba(239, 68, 68, 0.1);
    border-radius: 4px;
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
    position: relative;
    background: radial-gradient(circle at top right, rgba(59, 130, 246, 0.1), transparent 40%);
}

.section {
    display: none;
    animation: fadeIn 0.3s ease-out;
    max-width: 1200px;
    margin: 0 auto;
}

.section.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.section.full-height-section {
    height: calc(100vh - 4rem);
    flex-direction: column;
}

.section.full-height-section.active {
    display: flex;
}

.full-height-card {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.flex-grow {
    flex: 1;
    overflow: hidden;
    position: relative;
}

/* Chat Interface */
.chat-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 4rem);
    background: var(--card-bg);
    border: var(--glass-border);
    border-radius: 1rem;
    backdrop-filter: blur(12px);
    overflow: hidden;
}

.chat-history {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.message {
    max-width: 80%;
    padding: 1rem;
    border-radius: 1rem;
    line-height: 1.5;
    position: relative;
}

.message.user {
    align-self: flex-end;
    background-color: var(--accent-color);
    color: white;
    border-bottom-right-radius: 0.25rem;
}

.message.assistant {
    align-self: flex-start;
    background-color: rgba(255, 255, 255, 0.05);
    border: var(--glass-border);
    border-bottom-left-radius: 0.25rem;
}

.chat-input-area {
    padding: 1.5rem;
    background-color: rgba(15, 23, 42, 0.5);
    border-top: var(--glass-border);
    display: flex;
    gap: 1rem;
}

input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"],
textarea,
select {
    width: 100%;
    padding: 0.75rem 1rem;
    background-color: rgba(255, 255, 255, 0.05);
    border: var(--glass-border);
    border-radius: 0.5rem;
    color: var(--text-primary);
    font-family: inherit;
    transition: border-color 0.2s;
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--accent-color);
}

.btn {
    padding: 0.75rem 1.5rem;
    border-radius: 0.5rem;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-primary {
    background-color: var(--accent-color);
    color: white;
}

.btn-primary:hover {
    background-color: var(--accent-hover);
    transform: translateY(-1px);
}

/* Cards & Grid */
.grid-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-top: 1.5rem;
}

.card {
    background: var(--card-bg);
    border: var(--glass-border);
    border-radius: 1rem;
    padding: 1.5rem;
    backdrop-filter: blur(12px);
    transition: transform 0.2s;
}

.card:hover {
    transform: translateY(-2px);
    border-color: rgba(255, 255, 255, 0.2);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.card-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Markdown Content */
.markdown-body {
    color: var(--text-primary);
    font-size: 0.95rem;
    line-height: 1.6;
}

.markdown-body>*:first-child {
    margin-top: 0 !important;
}

.markdown-body>*:last-child {
    margin-bottom: 0 !important;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
    margin-top: 1.5em;
    margin-bottom: 0.5em;
    font-weight: 600;
    line-height: 1.25;
}

.markdown-body h1 {
    font-size: 1.8em;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 0.3em;
}

.markdown-body h2 {
    font-size: 1.5em;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 0.3em;
}

.markdown-body h3 {
    font-size: 1.25em;
}

.markdown-body h4 {
    font-size: 1em;
}

.markdown-body p {
    margin-bottom: 1em;
}

.markdown-body ul,
.markdown-body ol {
    margin-bottom: 1em;
    padding-left: 2em;
    list-style-type: disc;
}

.markdown-body ol {
    list-style-type: decimal;
}

.markdown-body li {
    margin-bottom: 0.25em;
}

.markdown-body li>p {
    margin-bottom: 0.5em;
}

.markdown-body blockquote {
    margin: 0 0 1em 0;
    padding: 0.5em 1em;
    color: var(--text-secondary);
    border-left: 0.25em solid var(--accent-color);
    background: rgba(255, 255, 255, 0.05);
    border-radius: 0 0.25em 0.25em 0;
}

.markdown-body hr {
    height: 0.15em;
    padding: 0;
    margin: 1.5em 0;
    background-color: rgba(255, 255, 255, 0.1);
    border: 0;
}

.markdown-body table {
    display: block;
    width: 100%;
    width: max-content;
    max-width: 100%;
    margin-bottom: 1em;
    overflow: auto;
    border-spacing: 0;
    border-collapse: collapse;
}

.markdown-body table th,
.markdown-body table td {
    padding: 0.5em 1em;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.markdown-body table th {
    font-weight: 600;
    background: rgba(255, 255, 255, 0.1);
}

.markdown-body table tr:nth-child(2n) {
    background-color: rgba(255, 255, 255, 0.02);
}

.markdown-body img {
    max-width: 100%;
    box-sizing: content-box;
    background-color: transparent;
    border-radius: 0.5rem;
}

.markdown-body pre {
    margin-bottom: 1em;
    background: rgba(0, 0, 0, 0.3);
    padding: 1rem;
    border-radius: 0.5rem;
    overflow-x: auto;
}

.markdown-body code {
    font-family: 'Fira Code', monospace;
    font-size: 0.9em;
    background: rgba(255, 255, 255, 0.1);
    padding: 0.2em 0.4em;
    border-radius: 0.25em;
}

.markdown-body pre code {
    background: transparent;
    padding: 0;
}

.markdown-body a {
    color: var(--accent-color);
    text-decoration: none;
}

.markdown-body a:hover {
    text-decoration: underline;
}

/* Loading Spinner */
.loader {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Custom Tooltip */
.d3-tooltip {
    position: absolute;
    text-align: center;
    padding: 8px 12px;
    font: 14px sans-serif;
    background: rgba(15, 23, 42, 0.9);
    color: #fff;
    border: 1px solid var(--accent-color);
    border-radius: 8px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 1000;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    max-width: 250px;
}

/* History Tabs */
.history-tabs {
    display: flex;
    overflow-x: auto;
    border-bottom: 2px solid var(--glass-border);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
}

.history-tab {
    padding: 0.5rem 1rem;
    cursor: pointer;
    white-space: nowrap;
    color: var(--text-secondary);
    border-radius: 0.5rem;
    transition: all 0.2s ease;
    font-size: 0.9rem;
    margin-right: 0.5rem;
}

.history-tab:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.history-tab.active {
    background: var(--accent-color);
    color: white;
}

.history-section {
    display: none;
}

.history-section.active {
    display: block;
}

.history-item-badge {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.7rem;
    margin-right: 8px;
    font-weight: bold;
    text-transform: uppercase;
}

.badge-quiz {
    background-color: rgba(59, 130, 246, 0.2);
    color: #60a5fa;
}

.badge-flashcards {
    background-color: rgba(16, 185, 129, 0.2);
    color: #34d399;
}

.badge-mindmap {
    background-color: rgba(168, 85, 247, 0.2);
    color: #c084fc;
}

.badge-text {
    background-color: rgba(255, 255, 255, 0.1);
    color: #94a3b8;
}

/* Flashcards */
.flashcard-container {
    perspective: 1000px;
    width: 600px;
    max-width: 100%;
    margin: 2rem auto;
    text-align: center;
}

.flashcard {
    background-color: transparent;
    width: 100%;
    height: 450px;
    perspective: 1000px;
    cursor: pointer;
}

.flashcard-inner {
    position: relative;
    width: 100%;
    height: 100%;
    text-align: center;
    transition: transform 0.6s;
    transform-style: preserve-3d;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    border-radius: 1.5rem;
}

.flashcard.flipped .flashcard-inner {
    transform: rotateY(180deg);
}

.flashcard-front,
.flashcard-back {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    padding: 2.5rem;
    border-radius: 1.5rem;
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    border: 1px solid rgba(255, 255, 255, 0.1);
    overflow-y: auto;
}

.flashcard-back {
    transform: rotateY(180deg);
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
}

.card-content {
    width: 100%;
    margin-top: auto;
    margin-bottom: auto;
}

.flashcard h3 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: var(--accent-color);
}

.flashcard p {
    font-size: 1.1rem;
    line-height: 1.6;
}

.flashcard-controls {
    margin-top: 1.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
}

/* Quiz */
.quiz-container {
    max-width: 800px;
    margin: 0 auto;
}

.quiz-question {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 0.5rem;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    transition: border-color 0.3s;
}

.quiz-option {
    display: block;
    margin: 0.5rem 0;
    cursor: pointer;
}

.quiz-textarea {
    width: 100%;
    margin-top: 0.5rem;
    background: rgba(0, 0, 0, 0.2);
}

.image-upload-label {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.image-upload-label:hover {
    background: rgba(255, 255, 255, 0.2) !important;
    border-color: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
}

.history-sidebar {
    margin-top: 2rem;
    border-top: var(--glass-border);
    padding-top: 1rem;
}

.history-sidebar ul {
    list-style: none;
    padding: 0;
}

.history-sidebar li {
    font-size: 0.9rem;
    color: var(--text-secondary);
    border-radius: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-sidebar li:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.citation-image {
    display: block;
    max-width: 100%;
    max-height: 400px;
    margin: 1rem auto;
    border-radius: 0.5rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.pdf-source-link {
    display: inline-block;
    padding: 2px 6px;
    margin: 0 4px;
    background: transparent;
    border: 1px solid rgba(59, 130, 246, 0.4);
    color: var(--text-secondary);
    border-radius: 12px;
    font-size: 0.75rem;
    text-decoration: none;
    transition: all 0.2s ease;
    vertical-align: middle;
}

.pdf-source-link:hover {
    background: var(--accent-color);
    color: white;
    text-decoration: none;
    transform: translateY(-1px);
}

/* Fullscreen Graph Mode */
body.fullscreen-graph-mode .sidebar {
    display: none;
}

body.fullscreen-graph-mode .main-content {
    margin: 0;
    padding: 0;
    height: 100vh;
    overflow: hidden;
}

body.fullscreen-graph-mode #knowledge-graph-section {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1000;
    background: var(--bg-color);
    padding: 1rem;
    margin: 0;
    max-width: none;
}

body.fullscreen-graph-mode .full-height-card {
    border: none;
    border-radius: 0;
    background: var(--bg-color);
}

body.fullscreen-graph-mode #knowledge-graph-container {
    height: calc(100vh - 120px) !important;
    /* Adjust for header/legend */
}

/* Answer Sheet Upload */
.answer-sheet-section {
    transition: all 0.3s ease;
}

.answer-sheet-section:hover {
    background: rgba(255, 255, 255, 0.08) !important;
    border-color: var(--accent-color) !important;
}

#global-sheet-remove {
    font-size: 1.2rem;
    padding: 0 0.5rem;
    transition: color 0.2s;
}

#global-sheet-remove:hover {
    color: #ff6b6b;
    transform: scale(1.1);
}

/* Teacher Dashboard Tabs */
.tab-btn:hover {
    color: var(--accent-color) !important;
    background: rgba(59, 130, 246, 0.1) !important;
}

.tab-btn.active {
    color: var(--accent-color) !important;
    border-bottom-color: var(--accent-color) !important;
}

.badge.secondary {
    background: rgba(100, 116, 139, 0.2);
    color: #94a3b8;
    padding: 0.2rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.85rem;
    text-transform: capitalize;
}

.badge.success {
    background: rgba(16, 185, 129, 0.2);
    color: #10b981;
    padding: 0.2rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.85rem;
}

.badge.warning {
    background: rgba(245, 158, 11, 0.2);
    color: #f59e0b;
    padding: 0.2rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.85rem;
}

.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.875rem;
}