:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --secondary: #64748b;
    --success: #22c55e;
    --danger: #ef4444;
    --warning: #f59e0b;
    --bg: #f8fafc;
    --bg-dark: #1e293b;
    --text: #1e293b;
    --text-light: #64748b;
    --border: #e2e8f0;
    --card-bg: #ffffff;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 0.5rem;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

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

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

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

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

.btn-small {
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
}

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

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

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    font-size: 1rem;
}

.form-group small {
    color: var(--text-light);
    font-size: 0.875rem;
}

.landing-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.landing-header {
    text-align: center;
    padding: 4rem 2rem 2rem;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
}

.logo {
    font-size: 3rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.tagline {
    font-size: 1.25rem;
    opacity: 0.9;
}

.landing-main {
    flex: 1;
    max-width: 1000px;
    margin: 0 auto;
    padding: 3rem 2rem;
}

.hero {
    text-align: center;
    margin-bottom: 3rem;
}

.hero h2 {
    font-size: 2rem;
    margin-bottom: 1rem;
}

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

.feature {
    background: var(--card-bg);
    padding: 2rem;
    border-radius: 1rem;
    box-shadow: var(--shadow);
}

.feature h3 {
    color: var(--primary);
    margin-bottom: 0.5rem;
}

.cta {
    text-align: center;
    padding: 2rem;
    background: var(--card-bg);
    border-radius: 1rem;
    box-shadow: var(--shadow);
}

.landing-footer {
    text-align: center;
    padding: 2rem;
    color: var(--text-light);
    border-top: 1px solid var(--border);
}

.admin-container {
    min-height: 100vh;
    background: var(--bg);
}

.admin-header {
    background: var(--bg-dark);
    color: white;
    padding: 1.5rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.admin-header a {
    color: white;
}

.admin-header .btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

.auth-section {
    max-width: 400px;
    margin: 4rem auto;
    padding: 2rem;
    background: var(--card-bg);
    border-radius: 1rem;
    box-shadow: var(--shadow-lg);
}

.auth-card {
    background: var(--card-bg);
    padding: 2rem;
    border-radius: 1rem;
    box-shadow: var(--shadow-lg);
}

.auth-card h2 {
    margin-bottom: 1.5rem;
    text-align: center;
}

.error-message {
    background: #fee2e2;
    color: #dc2626;
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
    font-size: 0.875rem;
}

.btn-full {
    width: 100%;
    margin-top: 1rem;
}

.auth-section h2 {
    margin-bottom: 1.5rem;
}

.error-message {
    color: var(--danger);
    margin-top: 1rem;
}

.admin-main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.ta-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
}

.ta-card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 1rem;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.ta-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.ta-card h3 {
    margin-bottom: 0.25rem;
}

.ta-card .course-name {
    color: var(--text-light);
    margin-bottom: 0.5rem;
}

.ta-card .ta-slug {
    font-family: monospace;
    color: var(--primary);
    margin-bottom: 1rem;
}

.ta-meta {
    display: flex;
    gap: 1rem;
    font-size: 0.875rem;
}

.status {
    padding: 0.25rem 0.75rem;
    border-radius: 1rem;
    font-weight: 500;
}

.status.indexed {
    background: #dcfce7;
    color: #166534;
}

.status.not-indexed {
    background: #fef3c7;
    color: #92400e;
}

.status.indexing {
    background: #dbeafe;
    color: #1d4ed8;
}

.ta-detail-section {
    background: var(--card-bg);
    padding: 2rem;
    border-radius: 1rem;
    box-shadow: var(--shadow);
}

.detail-info {
    margin-bottom: 2rem;
}

.detail-info p {
    margin-bottom: 0.5rem;
}

.upload-section,
.documents-section,
.actions-section,
.prompt-section,
.slug-section {
    margin-bottom: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

.upload-section h3,
.documents-section h3,
.prompt-section h3,
.slug-section h3 {
    margin-bottom: 1rem;
}

.slug-edit-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.slug-prefix {
    font-family: monospace;
    font-size: 1.1rem;
    color: var(--text-light);
}

.slug-edit-group input {
    flex: 1;
    max-width: 300px;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    font-family: monospace;
}

.slug-hint {
    font-size: 0.875rem;
    color: var(--text-light);
    margin-bottom: 0.5rem;
}

#slug-status {
    font-size: 0.875rem;
    min-height: 1.25rem;
}

#upload-form {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.drop-zone {
    border: 2px dashed var(--border);
    border-radius: 0.75rem;
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    background: var(--bg);
}

.drop-zone:hover {
    border-color: var(--primary);
    background: rgba(59, 130, 246, 0.05);
}

.drop-zone-active {
    border-color: var(--primary);
    background: rgba(59, 130, 246, 0.1);
    transform: scale(1.01);
}

.drop-zone-content {
    pointer-events: none;
}

.drop-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 1rem;
    color: var(--text-light);
}

.drop-zone:hover .drop-icon,
.drop-zone-active .drop-icon {
    color: var(--primary);
}

.drop-text {
    font-size: 1rem;
    color: var(--text);
    margin-bottom: 0.5rem;
}

.drop-hint {
    font-size: 0.875rem;
    color: var(--text-light);
}

.upload-progress {
    margin-top: 1rem;
}

.upload-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem;
    background: var(--bg);
    border-radius: 0.375rem;
    margin-bottom: 0.5rem;
}

.upload-filename {
    font-size: 0.875rem;
    color: var(--text);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-right: 1rem;
}

.upload-status {
    font-size: 0.75rem;
    font-weight: 500;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    white-space: nowrap;
}

.upload-status.uploading {
    background: #fef3c7;
    color: #d97706;
}

.upload-status.success {
    background: #d1fae5;
    color: #059669;
}

.upload-status.error {
    background: #fee2e2;
    color: #dc2626;
}

.documents-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.doc-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem;
    background: var(--bg);
    border-radius: 0.5rem;
}

.doc-name {
    flex: 1;
}

.doc-type {
    padding: 0.25rem 0.5rem;
    background: var(--border);
    border-radius: 0.25rem;
    font-size: 0.75rem;
    text-transform: uppercase;
}

.actions-section {
    display: flex;
    gap: 1rem;
}

#system-prompt {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    font-family: inherit;
    margin-bottom: 1rem;
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: var(--card-bg);
    padding: 2rem;
    border-radius: 1rem;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
}

.close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-light);
}

.empty, .loading {
    color: var(--text-light);
    font-style: italic;
}

.chat-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 900px;
    margin: 0 auto;
}

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

.header-info h1 {
    font-size: 1.25rem;
    margin-bottom: 0.25rem;
}

.header-info .course-name {
    color: var(--text-light);
    font-size: 0.875rem;
}

.logo-link {
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--primary);
}

.chat-main {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

.messages {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.message {
    max-width: 85%;
    animation: fadeIn 0.3s ease;
}

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

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

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

.message-content {
    padding: 1rem 1.25rem;
    border-radius: 1rem;
    line-height: 1.6;
}

.message.user .message-content {
    background: var(--primary);
    color: white;
    border-bottom-right-radius: 0.25rem;
}

.message.assistant .message-content {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-bottom-left-radius: 0.25rem;
}

.message-content p {
    margin-bottom: 0.5rem;
}

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

.message-content code {
    background: rgba(0,0,0,0.1);
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    font-family: monospace;
}

.message-content .katex-display {
    margin: 1rem 0;
    overflow-x: auto;
    overflow-y: hidden;
}

.message-content .katex {
    font-size: 1.1em;
}

.message.user .message-content .katex {
    color: white;
}

.message-sources {
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-light);
}

.sources-label {
    margin-right: 0.5rem;
}

.source-tag {
    display: inline-block;
    background: var(--bg);
    padding: 0.125rem 0.5rem;
    border-radius: 0.25rem;
    margin-right: 0.25rem;
}

.typing-indicator {
    display: flex;
    gap: 0.25rem;
}

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

.typing-indicator span:nth-child(1) { animation-delay: 0s; }
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

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

.message.streaming .message-status {
    display: flex;
    align-items: center;
    margin-bottom: 0.75rem;
}

.message.streaming .status-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-light);
    font-size: 0.875rem;
}

.message.streaming .status-dot {
    width: 8px;
    height: 8px;
    background: var(--primary);
    border-radius: 50%;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.8); }
}

.message.streaming .status-text {
    animation: fadeInOut 2s ease-in-out infinite;
}

@keyframes fadeInOut {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

.message.streaming #streaming-content {
    white-space: pre-wrap;
    min-height: 1.5em;
}

.chat-footer {
    padding: 1rem 1.5rem;
    background: var(--card-bg);
    border-top: 1px solid var(--border);
}

.input-group {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
}

.btn-clear {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 44px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    background: var(--card-bg);
    color: var(--text-light);
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.btn-clear:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: rgba(247, 181, 0, 0.05);
}

.btn-clear svg {
    width: 18px;
    height: 18px;
}

#query-input {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    font-size: 1rem;
    resize: none;
    min-height: 44px;
    max-height: 150px;
    font-family: inherit;
}

#query-input:focus {
    outline: none;
    border-color: var(--primary);
}

.disclaimer {
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-light);
    text-align: center;
}

.error-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    text-align: center;
    padding: 2rem;
}

.error-container h1 {
    font-size: 6rem;
    color: var(--primary);
    margin-bottom: 0.5rem;
}

.error-container h2 {
    margin-bottom: 1rem;
}

.error-container p {
    color: var(--text-light);
    margin-bottom: 2rem;
}

@media (max-width: 768px) {
    .landing-header {
        padding: 2rem 1rem;
    }
    
    .logo {
        font-size: 2rem;
    }
    
    .features {
        grid-template-columns: 1fr;
    }
    
    .ta-list {
        grid-template-columns: 1fr;
    }
    
    .actions-section {
        flex-direction: column;
    }
    
    .message {
        max-width: 95%;
    }
}
