/* --- 1. Variables & Reset --- */
:root {
    --bg-main: #fcfcfc;
    --bg-container: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-tertiary: #94a3b8;
    --border-color: #e2e8f0;
    --primary-accent: #7c3aed;
    --primary-accent-hover: #6d28d9;
    --bubble-user-bg: #f3f4f6;
    --bubble-user-text: #0f172a;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden; /* Prevent body scroll, handle inside app-container */
}

*, *::before, *::after {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
}

/* --- 2. Main Layout Wrapper --- */
#app-container {
    display: flex;
    flex-direction: column;
    height: 100dvh; /* Modern viewport unit fixes mobile jumping */
    max-width: 100%;
    position: relative;
}

/* --- 3. Sticky Minimal Header --- */
#chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background: rgba(252, 252, 252, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 50;
    height: 60px;
}

#logo-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-svg {
    width: 28px;
    height: 28px;
}

#logo-container h1 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

#new-chat-button {
    background: transparent;
    border: 1px solid var(--border-color);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
}

#new-chat-button:hover {
    background: var(--bubble-user-bg);
}

.mobile-only { display: none; }
.desktop-only { display: inline-block; }

/* --- 4. Main Fluid Canvas (Chat Stream) --- */
#chat-stream {
    flex-grow: 1;
    overflow-y: auto;
    scroll-behavior: smooth;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 20px 180px 20px;
}

#chat-container {
    width: 100%;
    max-width: 768px; /* Ideal reading width */
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* --- 5. Message Bubbles --- */
.message {
    display: flex;
    flex-direction: column;
    width: 100%;
    animation: fadeIn 0.3s ease-out;
}

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

.message-content {
    line-height: 1.6;
    word-wrap: break-word;
    font-size: 1rem;
}

/* User Message */
.message.user {
    align-items: flex-end;
}

.message.user .message-content {
    background-color: var(--bubble-user-bg);
    color: var(--bubble-user-text);
    padding: 12px 18px;
    border-radius: 20px 20px 4px 20px;
    max-width: 85%;
}

/* Assistant Message (Fluid Document Style) */
.message.assistant {
    align-items: flex-start;
}

.message.assistant .message-content {
    width: 100%;
    color: var(--text-primary);
}

.message.assistant .message-content p {
    margin-top: 0;
    margin-bottom: 1em;
}

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

/* --- 6. Inline Source Tray (Google Style) --- */
.inline-sources-container {
    margin-bottom: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.inline-sources-header {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: flex;
    align-items: center;
    gap: 6px;
}

.inline-sources-tray {
    display: flex;
    overflow-x: auto;
    gap: 12px;
    padding-bottom: 8px;
    scrollbar-width: none; /* Firefox */
}
.inline-sources-tray::-webkit-scrollbar {
    display: none; /* Safari/Chrome */
}

.source-chip {
    flex: 0 0 auto;
    width: 220px;
    background: var(--bg-container);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 12px;
    text-decoration: none;
    color: inherit;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s, border-color 0.2s;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.source-chip:hover {
    box-shadow: var(--shadow-md);
    border-color: #cbd5e1;
}

.source-chip-top {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.source-chip-icon {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background-color: var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
}

.source-chip-domain {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

.source-chip-title {
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.view-all-sources-btn {
    align-self: flex-start;
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.view-all-sources-btn:hover {
    background: var(--bubble-user-bg);
}

/* --- 7. Slide-Over Inspector (Sources Drawer) --- */
#drawer-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.4);
    z-index: 100;
    opacity: 0;
    transition: opacity 0.3s ease;
}
#drawer-overlay:not(.hidden) {
    display: block;
    opacity: 1;
}
.hidden {
    display: none !important;
}

#source-inspector {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 400px;
    background: var(--bg-container);
    box-shadow: -4px 0 24px rgba(0,0,0,0.1);
    z-index: 101;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
}

#source-inspector.open {
    transform: translateX(0);
}

#sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}

#sidebar-header h2 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
}

#close-drawer-btn {
    background: transparent;
    border: none;
    font-size: 1.2rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
}

#results-list {
    flex-grow: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.result-item {
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}
.result-item:last-child { border-bottom: none; }

.result-item a {
    color: var(--primary-accent);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95rem;
    display: block;
    margin-bottom: 4px;
}
.result-item a:hover { text-decoration: underline; }
.result-item .url {
    font-size: 0.8rem;
    color: var(--text-tertiary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 6px;
}
.result-item p {
    margin: 0;
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* --- 8. Elastic Smart Omnibox (Floating Dock) --- */
#input-dock {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0 20px 20px 20px;
    background: linear-gradient(to top, var(--bg-main) 70%, transparent);
    z-index: 10;
}

#chat-form {
    width: 100%;
    max-width: 768px;
    background: var(--bg-container);
    border: 1px solid var(--border-color);
    border-radius: 26px;
    padding: 8px 12px;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: flex-end;
    gap: 8px;
    position: relative;
    transition: border-color 0.2s, box-shadow 0.2s;
}

#chat-form:focus-within {
    border-color: var(--primary-accent);
    box-shadow: 0 4px 20px rgba(124, 58, 237, 0.15);
}

#chat-form.drag-over {
    background-color: rgba(124, 58, 237, 0.05);
    border-color: var(--primary-accent);
}

#attach-button {
    background: transparent;
    border: none;
    color: var(--text-tertiary);
    font-size: 1.2rem;
    padding: 10px;
    cursor: pointer;
    border-radius: 50%;
    height: 44px;
    width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, background 0.2s;
    flex-shrink: 0;
}
#attach-button:hover {
    background: var(--bubble-user-bg);
    color: var(--text-secondary);
}
#attach-button.has-image {
    color: var(--primary-accent);
}

.input-wrapper {
    flex-grow: 1;
    display: flex;
    align-items: center;
    min-height: 44px;
}

#message-input {
    width: 100%;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 1rem;
    line-height: 1.5;
    padding: 10px 0;
    resize: none;
    max-height: 35vh; /* Elastic scaling limit */
    overflow-y: hidden; /* Hidden until max-height is reached, managed by JS */
    color: var(--text-primary);
}
#message-input:focus { outline: none; }

#send-button {
    background: var(--primary-accent);
    color: white;
    border: none;
    height: 36px;
    width: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    margin-bottom: 4px;
    transition: background 0.2s, transform 0.1s;
}
#send-button:hover { background: var(--primary-accent-hover); }
#send-button:active { transform: scale(0.95); }
#send-button:disabled { background: #cbd5e1; cursor: not-allowed; }

/* Image Preview Pill */
#image-preview-container {
    position: absolute;
    bottom: calc(100% + 12px);
    left: 20px;
    background: var(--bg-container);
    padding: 8px;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    animation: popIn 0.2s ease-out;
}
#image-preview {
    max-height: 60px;
    border-radius: 6px;
}
#remove-image {
    position: absolute;
    top: -8px;
    right: -8px;
    background: var(--text-secondary);
    color: white;
    border: 2px solid var(--bg-container);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    cursor: pointer;
}

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

/* --- 9. Footer & Privacy --- */
#footer-info {
    width: 100%;
    max-width: 768px;
    margin-top: 12px;
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-tertiary);
}
#footer-info p { margin: 0; }
#footer-info a { color: var(--text-secondary); text-decoration: none; }
#footer-info a:hover { text-decoration: underline; color: var(--primary-accent); }

.footer-links {
    margin-top: 4px;
    display: flex;
    justify-content: center;
    gap: 8px;
}
.privacy-toggle { cursor: pointer; }
.privacy-toggle:hover { color: var(--primary-accent); }

.privacy-content {
    margin-top: 8px;
    text-align: left;
    background: var(--bg-container);
    padding: 12px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    white-space: pre-wrap;
    box-shadow: var(--shadow-sm);
}

/* --- 10. Thinking & Streaming Indicators --- */
.thinking-indicator {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    padding: 8px 16px;
    background: var(--bubble-user-bg);
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 10px;
}

.thinking-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--primary-accent);
    animation: thinking-pulse 1.2s ease-in-out infinite;
}

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

.error-text {
    color: #b91c1c;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 8px;
    padding: 12px 16px;
    font-size: 0.95rem;
}

/* Markdown specific */
.message-content pre {
    background-color: #1e293b;
    color: #f8fafc;
    padding: 16px;
    padding-top: 36px;
    border-radius: 12px;
    overflow-x: auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.85rem;
    position: relative;
    margin: 1.5em 0;
}
.copy-code-button {
    position: absolute;
    top: 8px; right: 8px;
    background: rgba(255,255,255,0.1);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: background 0.2s;
}
.copy-code-button:hover { background: rgba(255,255,255,0.2); }

/* --- 11. Mermaid Universele Styling --- */
.mermaid-diagram-container {
    background: #ffffff !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 12px !important;
    padding: 24px !important;
    margin: 20px 0 !important;
    box-shadow: var(--shadow-sm) !important;
    overflow-x: auto !important;
    text-align: center !important;
}
.mermaid-diagram-container svg {
    max-width: 100% !important;
    height: auto !important;
    display: block !important;
    margin: 0 auto !important;
}
.mermaid-diagram-container svg path.line, .mermaid-diagram-container svg path[class*="line"] {
    stroke: var(--primary-accent) !important;
    stroke-width: 3.5px !important;
    fill: none !important;
}
.mermaid-diagram-container svg circle {
    fill: var(--primary-accent) !important;
    stroke: #ffffff !important;
    stroke-width: 2px !important;
}
.mermaid-diagram-container svg rect.bar {
    fill: var(--primary-accent) !important;
    rx: 4px !important; ry: 4px !important;
}
.mermaid-diagram-container svg text {
    font-family: inherit !important;
    fill: var(--text-primary) !important;
}
.mermaid-diagram-container svg .node rect, .mermaid-diagram-container svg .node polygon {
    fill: #f5f3ff !important;
    stroke: var(--primary-accent) !important;
    rx: 8px !important; ry: 8px !important;
}

/* --- 12. Mobile Responsive (Bottom Sheet Architecture) --- */
@media (max-width: 768px) {
    .desktop-only { display: none !important; }
    .mobile-only { display: inline-block !important; }

    #chat-container { padding: 0; }
    #chat-stream { padding-left: 16px; padding-right: 16px; padding-bottom: 160px; }

    #input-dock { padding: 0 12px 16px 12px; }
    #chat-form { border-radius: 20px; padding: 6px 10px; }

    .message.user .message-content { max-width: 90%; }
    
    /* Bottom Sheet Transformation */
    #source-inspector {
        width: 100%;
        top: auto;
        height: 85dvh;
        border-radius: 24px 24px 0 0;
        transform: translateY(100%);
    }
    #source-inspector.open {
        transform: translateY(0);
    }
    
    /* Visual drag handle hint */
    #sidebar-header::before {
        content: '';
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 4px;
        background: var(--border-color);
        border-radius: 2px;
    }
    
    .source-chip { width: 200px; }
}

/* Privacy Content Box*/
.privacy-content {
    margin-top: 12px;
    text-align: left;
    background: var(--bg-container);
    padding: 16px 20px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    white-space: pre-wrap;
    box-shadow: var(--shadow-lg);
    color: var(--text-secondary); /* Dit fixt de lichte letters */
    font-size: 0.85rem;
    line-height: 1.6;
}

/* ==========================================================================
   13. ABOUT PAGE STYLING
   ========================================================================== */
.about-wrapper {
    overflow-y: auto;
    display: block; /* Zorgt dat het niet de flex-layout van de chat forceert */
    height: 100dvh;
}

#about-content {
    max-width: 900px;
    margin: 0 auto;
    padding: 40px 20px 80px 20px;
    color: var(--text-primary);
}

.hero-section {
    text-align: center;
    margin-bottom: 50px;
    animation: fadeIn 0.4s ease-out;
}

.hero-section h2 {
    font-size: 2.4rem;
    color: var(--primary-accent);
    margin-bottom: 16px;
    line-height: 1.2;
    letter-spacing: -0.02em;
}

.hero-section .lead {
    font-size: 1.1rem;
    color: var(--text-secondary);
    max-width: 600px;
    margin: 0 auto;
    line-height: 1.6;
}

.grid-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 24px;
    margin-bottom: 60px;
}

.card {
    background: var(--bg-container);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 24px;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
    border-color: #cbd5e1;
}

.card .icon {
    font-size: 2rem;
    color: var(--primary-accent);
    margin-bottom: 16px;
}

.card h3 {
    margin: 0 0 12px 0;
    font-size: 1.2rem;
    font-weight: 600;
}

.card p {
    margin: 0;
    color: var(--text-secondary);
    line-height: 1.6;
    font-size: 0.95rem;
}

.bot-section {
    background: var(--bubble-user-bg);
    border-radius: 20px;
    padding: 32px;
    margin-bottom: 40px;
}

.bot-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

.bot-header i {
    font-size: 2rem;
    color: #0085ff; /* Bluesky brand color */
}

.bot-header h3 {
    margin: 0;
    font-size: 1.4rem;
}

.bot-details {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 24px;
    margin-top: 24px;
}

.detail-col h4, .feedback-box h4 {
    color: var(--text-primary);
    margin-bottom: 12px;
    font-size: 1.1rem;
}

.bot-section ul {
    padding-left: 20px;
    color: var(--text-secondary);
    line-height: 1.6;
}

.bot-section ul li {
    margin-bottom: 10px;
}

.feedback-box {
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
}

.about-wrapper #footer-info {
    margin: 0 auto;
    max-width: 900px;
    padding-bottom: 40px;
}