/* ========================================
   VisuLearn Design System
   ======================================== */

:root {
    /* Colours */
    --primary: #0A3D62;
    --secondary: #D0D3D4;
    --accent: #F5A623;
    --background: #F4F6F8;
    --white: #FFFFFF;
    --text-body: #333333;
    --text-muted: #888888;
    --success: #2ECC71;
    --warning: #F1C40F;
    --error: #E74C3C;
    --code-block: #0D202F;

    /* Typography */
    --font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-mono: 'Courier New', Courier, monospace;
}

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

body {
    font-family: var(--font-family);
    font-size: 1rem;
    line-height: 1.6;
    color: var(--text-body);
    background: var(--background);
}

/* App Container */
#app-container {
    padding: 40px;
    min-height: 100vh;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 40px;
}

header h1 {
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 8px;
}

header h2 {
    font-size: 1.2rem;
    font-weight: 400;
    color: var(--text-muted);
    margin-bottom: 8px;
}

header .brand {
    font-size: 1rem;
    font-weight: 600;
    color: var(--primary);
    opacity: 0.8;
}

/* Main Content Card */
#main-content {
    background: var(--white);
    border-radius: 16px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    padding: 32px;
    max-width: 1200px;
    margin: 0 auto;
}

/* Sections */
section {
    margin-bottom: 32px;
}

section:last-child {
    margin-bottom: 0;
}

h3 {
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--text-body);
    margin-bottom: 16px;
}

hr {
    border: none;
    border-top: 1px solid var(--secondary);
    margin: 32px 0;
}

/* Buttons */
.btn {
    border-radius: 8px;
    padding: 12px 24px;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    font-family: var(--font-family);
}

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

.btn-primary:hover {
    filter: brightness(110%);
}

.btn-primary:disabled {
    background: var(--secondary);
    color: var(--text-muted);
    cursor: not-allowed;
}

.btn-secondary {
    background: white;
    color: var(--primary);
    border: 2px solid var(--primary);
}

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

.btn-small {
    padding: 8px 16px;
    font-size: 0.875rem;
}

/* Upload Area */
#upload-section {
    border: 2px dashed var(--secondary);
    border-radius: 12px;
    padding: 40px;
    text-align: center;
    transition: all 0.2s ease;
    background: var(--background);
}

#upload-section.drag-over {
    border-color: var(--primary);
    background: rgba(10, 61, 98, 0.05);
}

#upload-section p {
    margin-bottom: 16px;
    color: var(--text-muted);
}

#file-input {
    display: none;
}

.file-types {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-top: 12px;
}

/* Or paste text */
.or-divider {
    display: flex;
    align-items: center;
    margin: 24px 0;
    color: var(--text-muted);
}

.or-divider::before,
.or-divider::after {
    content: '';
    flex: 1;
    border-top: 1px solid var(--secondary);
}

.or-divider span {
    padding: 0 16px;
    font-size: 0.875rem;
}

#paste-area {
    width: 100%;
    min-height: 150px;
    padding: 16px;
    border: 1px solid var(--secondary);
    border-radius: 8px;
    font-family: var(--font-family);
    font-size: 1rem;
    line-height: 1.6;
    resize: vertical;
}

#paste-area:focus {
    outline: none;
    border-color: var(--primary);
}

/* File preview */
#file-preview {
    display: none;
    background: var(--background);
    border-radius: 8px;
    padding: 16px;
    margin-top: 16px;
}

#file-preview.visible {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.file-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.file-icon {
    width: 40px;
    height: 40px;
    background: var(--primary);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
}

.file-name {
    font-weight: 600;
    color: var(--text-body);
}

.file-size {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.remove-file {
    background: none;
    border: none;
    color: var(--error);
    cursor: pointer;
    font-size: 1.2rem;
    padding: 8px;
}

/* Chat Area */
#chat-section {
    display: none;
}

#chat-section.visible {
    display: block;
}

#chat-messages {
    max-height: 500px;
    overflow-y: auto;
    padding: 16px;
    background: var(--background);
    border-radius: 12px;
    margin-bottom: 16px;
}

.message {
    margin-bottom: 16px;
    padding: 16px;
    border-radius: 12px;
    max-width: 90%;
}

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

.message.user {
    background: var(--primary);
    color: white;
    margin-left: auto;
}

.message.assistant {
    background: white;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
}

.message-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    font-size: 0.875rem;
    font-weight: 600;
}

.message.user .message-header {
    color: rgba(255, 255, 255, 0.8);
}

.message.assistant .message-header {
    color: var(--primary);
}

.message-content {
    line-height: 1.6;
}

/* Markdown rendering in messages */
.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4 {
    margin-top: 16px;
    margin-bottom: 8px;
    color: var(--primary);
}

.message-content h1:first-child,
.message-content h2:first-child,
.message-content h3:first-child {
    margin-top: 0;
}

.message-content ul,
.message-content ol {
    margin: 8px 0;
    padding-left: 24px;
}

.message-content li {
    margin-bottom: 4px;
}

.message-content p {
    margin-bottom: 8px;
}

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

.message-content code {
    background: var(--code-block);
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.9em;
}

.message-content pre {
    background: var(--code-block);
    padding: 16px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 12px 0;
}

.message-content pre code {
    background: none;
    padding: 0;
}

.message-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
}

.message-content th,
.message-content td {
    border: 1px solid var(--secondary);
    padding: 8px 12px;
    text-align: left;
}

.message-content th {
    background: var(--background);
    font-weight: 600;
}

.message-content strong {
    font-weight: 600;
}

.message-content blockquote {
    border-left: 4px solid var(--primary);
    padding-left: 16px;
    margin: 12px 0;
    color: var(--text-muted);
}

/* User input area */
#input-area {
    display: flex;
    gap: 12px;
}

#user-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--secondary);
    border-radius: 8px;
    font-family: var(--font-family);
    font-size: 1rem;
    resize: none;
    min-height: 48px;
    max-height: 150px;
}

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

/* Loading indicator */
.loading {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
    padding: 16px;
}

.loading-dots {
    display: flex;
    gap: 4px;
}

.loading-dots span {
    width: 8px;
    height: 8px;
    background: var(--primary);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

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

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

/* Download buttons */
#download-section {
    display: none;
    margin-top: 24px;
    padding: 24px;
    background: rgba(46, 204, 113, 0.1);
    border-radius: 12px;
    border: 2px solid var(--success);
}

#download-section.visible {
    display: block;
}

#download-section h3 {
    color: var(--success);
    margin-bottom: 16px;
}

.download-buttons {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

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

.btn-download:hover {
    filter: brightness(110%);
}

/* Copy button on messages */
.copy-btn {
    background: none;
    border: 1px solid var(--secondary);
    color: var(--text-muted);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.copy-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.copy-btn.copied {
    background: var(--success);
    border-color: var(--success);
    color: white;
}

/* Error message */
.error-message {
    background: rgba(231, 76, 60, 0.1);
    border: 1px solid var(--error);
    color: var(--error);
    padding: 16px;
    border-radius: 8px;
    margin-bottom: 16px;
}

/* Status indicator */
#status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--background);
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 0.875rem;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--secondary);
}

.status-dot.connected {
    background: var(--success);
}

.status-dot.error {
    background: var(--error);
}

/* Responsive */
@media (max-width: 768px) {
    #app-container {
        padding: 20px;
    }

    #main-content {
        padding: 20px;
    }

    header h1 {
        font-size: 1.8rem;
    }

    .download-buttons {
        flex-direction: column;
    }

    .message {
        max-width: 100%;
    }
}

/* Intro explanation box */
.intro-box {
    text-align: left;
    background: white;
    border: 1px solid var(--secondary);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 24px;
}

.intro-box h3 {
    color: var(--primary);
    margin-bottom: 12px;
}

.intro-box ol {
    margin: 16px 0;
    padding-left: 24px;
}

.intro-box li {
    margin-bottom: 8px;
}

.intro-box .intro-note {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-style: italic;
    margin-top: 16px;
    margin-bottom: 0;
}

/* Red section headings in Sam's responses */
.message-content h1,
.message-content h2 {
    color: #C0392B !important;
    border-bottom: 2px solid #C0392B;
    padding-bottom: 8px;
    margin-top: 24px;
}

.message-content h3 {
    color: #C0392B !important;
    margin-top: 20px;
}
