/* style.css */
:root {
    --font-primary: 'Inter', sans-serif;
    --primary-bg: #f4f7f6; /* Light grayish-blue */
    --secondary-bg: #ffffff;
    --sidebar-bg: #2c3e50; /* Dark blue-gray */
    --sidebar-text-color: #ecf0f1; /* Light gray for sidebar text */
    --sidebar-hover-bg: #34495e; /* Slightly lighter dark blue-gray */
    --chat-header-bg: #ffffff;
    --text-color-primary: #333333;
    --text-color-secondary: #555555;
    --accent-color: #3498db; /* Bright blue */
    --accent-color-darker: #2980b9;
    --border-color: #e0e0e0;
    --message-user-bg: #dcf8c6; /* Light green (WhatsApp like) */
    --message-chatbot-bg: #ffffff;
    --message-text-color: #333333;
    --error-color: #e74c3c;
    --success-color: #2ecc71;

    --border-radius-small: 4px;
    --border-radius-medium: 8px;
    --border-radius-large: 16px;
    --box-shadow-light: 0 2px 8px rgba(0, 0, 0, 0.05);
    --box-shadow-medium: 0 4px 12px rgba(0, 0, 0, 0.1);

    --spacing-xs: 4px;
    --spacing-s: 8px;
    --spacing-m: 16px;
    --spacing-l: 24px;
    --spacing-xl: 32px;
    --sidebar-width: 280px;
    --sidebar-collapsed-width: 70px;
    --sidebar-mobile-overlay-bg: rgba(0,0,0,0.4); /* For the backdrop when sidebar is open on mobile */
}

/* General Reset and Body Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%; /* Ensure html and body take full height */
}

body {
    font-family: var(--font-primary);
    background-color: var(--primary-bg);
    color: var(--text-color-primary);
    line-height: 1.6;
    overflow: hidden; /* Prevent body scroll, manage scrolling within components */
}

.container {
    display: flex;
    height: 100vh; /* Full viewport height */
}

/* Sidebar Styles */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text-color);
    padding: var(--spacing-m);
    display: flex;
    flex-direction: column;
    transition: width 0.3s ease, padding 0.3s ease;
    overflow-y: auto; /* Scroll sidebar content if it overflows */
    flex-shrink: 0; /* Prevent sidebar from shrinking if content is too wide */
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
    padding: var(--spacing-m) var(--spacing-xs); /* Adjust padding for collapsed state */
}

.sidebar-mobile-links {
    display: none; /* Hidden by default, shown on mobile */
    flex-direction: column;
    gap: var(--spacing-s);
    margin-top: var(--spacing-m);
    padding-top: var(--spacing-m);
    border-top: 1px solid var(--sidebar-hover-bg);
}

.sidebar-mobile-links a {
    color: var(--sidebar-text-color);
    text-decoration: none;
    padding: var(--spacing-s) var(--spacing-m);
    border-radius: var(--border-radius-medium);
    display: block;
}

.sidebar-mobile-links a:hover {
    background-color: var(--sidebar-hover-bg);
}


.sidebar.collapsed .sidebar-title,
.sidebar.collapsed .chat-list-item-text, /* Text within chat list items */
.sidebar.collapsed .new-chat-button span { /* Text within new chat button */
    display: none;
}
.sidebar.collapsed .new-chat-button svg {
    margin-right: 0;
}
.sidebar.collapsed .collapse-icon svg {
    transform: rotate(180deg);
}
.sidebar.collapsed .chat-list li {
    justify-content: center; /* Center icons in collapsed chat list items */
}


.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-l);
    padding-bottom: var(--spacing-s);
    border-bottom: 1px solid var(--sidebar-hover-bg);
    flex-shrink: 0; /* Prevent header from shrinking */
}

.sidebar-title {
    font-size: 1.2em;
    font-weight: 600;
    white-space: nowrap; /* Prevent title from wrapping */
}

.collapse-icon {
    background: none;
    border: none;
    color: var(--sidebar-text-color);
    cursor: pointer;
    padding: var(--spacing-s);
    border-radius: var(--border-radius-small);
    display: flex;
    align-items: center;
    justify-content: center;
}
.collapse-icon:hover {
    background-color: var(--sidebar-hover-bg);
}
.collapse-icon svg {
    transition: transform 0.3s ease;
}


.chat-list {
    list-style: none;
    flex-grow: 1; /* Allow chat list to take available space */
    overflow-y: auto; /* Allow scrolling for chat list if it overflows */
    margin-bottom: var(--spacing-m);
}

.chat-list li {
    padding: var(--spacing-s) var(--spacing-m);
    margin-bottom: var(--spacing-s);
    border-radius: var(--border-radius-medium);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background-color 0.2s ease, border-left 0.2s ease;
    border-left: 3px solid transparent;
    overflow: hidden; /* Prevent content from spilling out */
}

.chat-list li:hover {
    background-color: var(--sidebar-hover-bg);
}

.chat-list li.active {
    background-color: var(--accent-color);
    color: var(--secondary-bg);
    font-weight: 500;
    border-left: 3px solid var(--accent-color-darker); /* Or a contrasting color */
}
.chat-list li.active .delete-chat-button svg path {
    stroke: var(--secondary-bg); /* Make delete icon visible on active background */
}
.chat-list li.active .delete-chat-button:hover svg path {
    stroke: var(--error-color); /* Keep error color on hover for active item */
}


.chat-list-item-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-grow: 1;
    margin-right: var(--spacing-s); /* Space before delete button */
}

.delete-chat-button {
    background: none;
    border: none;
    color: var(--sidebar-text-color); /* Default color */
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.2s ease, color 0.2s ease;
    padding: var(--spacing-xs);
    flex-shrink: 0; /* Prevent button from shrinking */
}
.delete-chat-button svg {
    display: block; /* Remove extra space below SVG */
}

.delete-chat-button:hover {
    opacity: 1;
    color: var(--error-color); /* Error color on hover */
}
.delete-chat-button:hover svg path {
    stroke: var(--error-color); /* Ensure SVG stroke also changes */
}


.new-chat-button {
    background-color: var(--accent-color);
    color: var(--secondary-bg);
    padding: var(--spacing-s) var(--spacing-m);
    border: none;
    cursor: pointer;
    width: 100%;
    border-radius: var(--border-radius-medium);
    font-size: 1em;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease;
    flex-shrink: 0; /* Prevent button from shrinking */
}
.new-chat-button span { /* Target the span inside the button */
    white-space: nowrap; /* Prevent text from wrapping */
}

.new-chat-button:hover {
    background-color: var(--accent-color-darker);
}

/* Main Content Styles */
.main-content {
    flex: 1; /* Takes remaining width */
    display: flex;
    flex-direction: column;
    background-color: var(--primary-bg);
    overflow: hidden; /* Important: child elements will manage their own scroll */
}

.chat-header {
    background-color: var(--chat-header-bg);
    padding: var(--spacing-m) var(--spacing-l);
    display: flex;
    justify-content: space-between; /* This will push title to left and logo to right */
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--box-shadow-light);
    flex-shrink: 0; /* Prevent header from shrinking */
    position: relative; /* For positioning header links if needed */
}

.hamburger-icon {
    display: none; /* Hidden by default, shown on mobile */
    background: none;
    border: none;
    color: var(--text-color-primary);
    cursor: pointer;
    padding: var(--spacing-s);
    margin-right: var(--spacing-s);
}

.hamburger-icon svg {
    width: 24px;
    height: 24px;
}

.header-links {
    display: flex;
    gap: var(--spacing-m);
    margin-left: var(--spacing-m); /* Add space between title and links */
}

.header-links a {
    color: var(--text-color-secondary);
    text-decoration: none;
    font-size: 0.9em;
    padding: var(--spacing-xs) 0;
}

.header-links a:hover {
    color: var(--accent-color);
    text-decoration: underline;
}


.chat-title {
    font-size: 1.3em;
    font-weight: 600;
    color: var(--text-color-primary);
    margin-right: auto; /* Pushes links and logo to the right */
}

/* Logo specific styles */
.logo-right { /* More specific selector for Goethe Logo */
    height: 50px; /* Adjust height as needed */
    width: auto; /* Maintain aspect ratio */
    margin-left: var(--spacing-m); 
}

.message-area-container {
    flex: 1; /* Takes up available vertical space */
    overflow-y: auto; /* Enables scrolling for messages */
    padding: var(--spacing-m) var(--spacing-l);
    background-color: var(--primary-bg);
}

.message-area {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-m);
}


.message {
    padding: var(--spacing-s) var(--spacing-m);
    border-radius: var(--border-radius-large);
    max-width: 70%;
    word-wrap: break-word; /* Ensures long words break and wrap */
    overflow-wrap: break-word; /* Alias for word-wrap, good for compatibility */
    box-shadow: var(--box-shadow-light);
    line-height: 1.5;
    position: relative; /* For potential future use with pseudo-elements like tails */
}

.message.user {
    background-color: var(--message-user-bg);
    color: var(--message-text-color);
    align-self: flex-end;
    border-bottom-right-radius: var(--border-radius-small); /* WhatsApp like tail */
}

.message.chatbot {
    background-color: var(--message-chatbot-bg);
    color: var(--message-text-color);
    align-self: flex-start;
    border-bottom-left-radius: var(--border-radius-small); /* WhatsApp like tail */
}

/* Markdown generated content styling */
.message p,
.message ul,
.message ol,
.message pre,
.message table {
    margin-left: 0; /* Ensure no unexpected negative margins */
    margin-right: 0; /* Ensure content respects message padding */
}

.message ul,
.message ol {
    padding-left: var(--spacing-l); /* Indent lists (e.g., 24px) */
    list-style-position: inside; /* Keeps markers inside the flow */
    margin-top: var(--spacing-s);
    margin-bottom: var(--spacing-s);
}

.message li {
    margin-bottom: var(--spacing-xs);
}

.message table {
    border-collapse: collapse;
    width: 100%;
    margin-top: var(--spacing-s);
    margin-bottom: var(--spacing-s);
    font-size: 0.9em;
}

.message th, .message td {
    border: 1px solid var(--border-color);
    padding: var(--spacing-s);
    text-align: left;
}

.message th {
    background-color: #f0f0f0; 
    font-weight: 600;
}
.message code {
    background-color: #e8e8e8;
    padding: 2px 5px;
    border-radius: var(--border-radius-small);
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9em;
}
.message pre {
    background-color: #2d2d2d; 
    color: #f0f0f0; 
    padding: var(--spacing-s);
    border-radius: var(--border-radius-medium);
    overflow-x: auto; 
    font-size: 0.9em;
    line-height: 1.4;
}
.message pre code {
    background-color: transparent;
    padding: 0;
    border-radius: 0;
    color: inherit; 
    font-size: 1em; 
}


.input-area-wrapper {
    padding: var(--spacing-m) var(--spacing-l);
    background-color: var(--secondary-bg);
    border-top: 1px solid var(--border-color);
    box-shadow: 0 -2px 5px rgba(0,0,0,0.03);
    flex-shrink: 0; /* Prevent input area from shrinking */
}

.lecture-display {
    font-size: 0.85em;
    color: var(--text-color-secondary);
    margin-bottom: var(--spacing-s);
    text-align: center;
}

.input-area {
    display: flex;
    align-items: center;
    gap: var(--spacing-s);
    background-color: var(--secondary-bg); /* Ensure this matches wrapper if needed */
}

.message-input {
    flex: 1;
    padding: var(--spacing-s) var(--spacing-m);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-large); /* More rounded */
    font-size: 1em;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.message-input:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}

.send-button {
    background-color: var(--accent-color);
    color: white;
    padding: var(--spacing-s);
    border: none;
    cursor: pointer;
    border-radius: 50%; /* Round button */
    width: 44px; /* Fixed size for round button */
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease;
}

.send-button:hover {
    background-color: var(--accent-color-darker);
}
.send-button svg {
    width: 20px;
    height: 20px;
}

.button-container {
    display: flex;
    justify-content: center; /* Center buttons */
    gap: var(--spacing-m); /* Space between buttons */
    padding-top: var(--spacing-m);
}

.action-button {
    padding: var(--spacing-s) var(--spacing-m);
    cursor: pointer;
    border: 1px solid var(--accent-color);
    background-color: var(--secondary-bg);
    color: var(--accent-color);
    border-radius: var(--border-radius-medium);
    font-weight: 500;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.action-button:hover {
    background-color: var(--accent-color);
    color: var(--secondary-bg);
}

.powered-by {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: var(--spacing-m);
    font-size: 0.8em;
    color: var(--text-color-secondary);
}

.logo-bottom { /* More specific selector for Studium Digitale Logo */
    height: 40px; /* Adjust height as needed */
    width: auto; /* Maintain aspect ratio */
    margin-left: var(--spacing-s);
    vertical-align: middle; /* Align with text better */
}

/* Modal Styles */
.modal {
    display: none; /* Hidden by default, JS will toggle 'show' class */
    opacity: 0;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto; /* Enable scroll if needed */
    background-color: rgba(0,0,0,0.5); /* Darker overlay */
    transition: opacity 0.3s ease;
    align-items: center; /* For vertical centering */
    justify-content: center; /* For horizontal centering */
}

.modal.show {
    display: flex; /* Use flex for centering */
    opacity: 1;
}

.modal-content {
    background-color: var(--secondary-bg);
    margin: auto; /* Centering handled by flex on .modal */
    padding: var(--spacing-l);
    border: none;
    border-radius: var(--border-radius-medium);
    width: 90%;
    max-width: 500px;
    box-shadow: var(--box-shadow-medium);
    position: relative;
    transform: scale(0.95);
    transition: transform 0.3s ease;
}

.modal.show .modal-content {
    transform: scale(1);
}

/* Specific styles for Impressum Modal */
#impressum-modal .modal-content {
    max-width: 700px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}
#impressum-modal .flow {
    overflow-y: auto;
    padding-right: var(--spacing-s); /* Space for scrollbar */
}
#impressum-modal h2 {
    font-size: 1.2em;
    font-weight: 600;
    margin-bottom: var(--spacing-m);
    color: var(--text-color-primary);
}
#impressum-modal p {
    font-size: 0.9em;
    line-height: 1.5;
    margin-bottom: var(--spacing-s);
}
#impressum-modal a {
    color: var(--accent-color);
}


/* Specific styles for Agreement Modal */
.agreement-modal .modal-content {
    max-width: 800px; /* Wider for agreement text */
    max-height: 80vh; /* Limit height and allow scrolling */
    display: flex;
    flex-direction: column;
}

.agreement-text {
    flex-grow: 1;
    overflow-y: auto; /* Enable scrolling for the agreement text */
    margin-bottom: var(--spacing-m);
    padding-right: var(--spacing-s); /* Space for scrollbar */
    font-size: 0.9em;
    line-height: 1.5;
}

.agreement-text p,
.agreement-text ul,
.agreement-text ol {
    margin-bottom: var(--spacing-s);
}

.agreement-text strong {
    font-weight: 600;
}

.agreement-text hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: var(--spacing-m) 0;
}

#agreement-acceptance-status {
    font-size: 0.9em;
    color: #155724; /* Dark green for success text */
    display: flex;
    align-items: center;
}

.checkmark-icon {
    color: var(--success-color);
    font-size: 1.2em;
    margin-right: var(--spacing-s);
    font-weight: bold;
}


.modal-close-button {
    color: var(--text-color-secondary);
    position: absolute;
    top: var(--spacing-m);
    right: var(--spacing-m);
    font-size: 1.8em;
    font-weight: bold;
    background: none;
    border: none;
    cursor: pointer;
    line-height: 1;
}

.modal-close-button:hover,
.modal-close-button:focus {
    color: var(--text-color-primary);
}

.modal-title {
    font-size: 1.4em;
    font-weight: 600;
    margin-bottom: var(--spacing-m);
    color: var(--text-color-primary);
}

.modal p {
    margin-bottom: var(--spacing-l);
    font-size: 1em;
    color: var(--text-color-secondary);
}

.form-group {
    margin-bottom: var(--spacing-m);
}

.form-group label {
    display: block;
    margin-bottom: var(--spacing-s);
    font-weight: 500;
    color: var(--text-color-secondary);
}

.modal-select {
    width: 100%;
    padding: var(--spacing-s);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-medium);
    font-size: 1em;
    background-color: var(--primary-bg); /* Consistent with other inputs */
}
.modal-select:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}


.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--spacing-s);
    margin-top: var(--spacing-l);
}

.modal-button {
    padding: var(--spacing-s) var(--spacing-m);
    border-radius: var(--border-radius-medium);
    border: 1px solid var(--border-color);
    background-color: var(--secondary-bg);
    color: var(--text-color-primary);
    cursor: pointer;
    font-weight: 500;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.modal-button.primary {
    background-color: var(--accent-color);
    border-color: var(--accent-color);
    color: var(--secondary-bg);
}

.modal-button:hover {
    border-color: var(--accent-color-darker);
}
.modal-button.primary:hover {
    background-color: var(--accent-color-darker);
    border-color: var(--accent-color-darker);
}


/* Scrollbar Styling (WebKit browsers) */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--primary-bg);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb {
    background: #bdc3c7; /* Lighter gray for scrollbar thumb */
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: #95a5a6; /* Slightly darker on hover */
}


/* Responsive Design */
@media (max-width: 768px) {
    .container {
        flex-direction: column;
    height: auto; /* Allow content to define height */
    min-height: 100vh; /* Ensure it still takes full viewport height */
    position: relative; /* For sidebar overlay */
    overflow-x: hidden; /* Prevent horizontal scroll when sidebar is out */
    }

    .sidebar {
        position: fixed; /* Or absolute, depending on desired effect */
        left: -100%; /* Start off-screen */
        top: 0;
        bottom: 0;
        width: 80%; /* Or a fixed width like 280px */
        max-width: 300px; /* Max width for sidebar */
        height: 100%;
        z-index: 1200; /* Above other content */
        transition: left 0.3s ease;
        box-shadow: 2px 0 5px rgba(0,0,0,0.1);
        overflow-y: auto; /* Ensure sidebar content can scroll */
        padding: var(--spacing-m); /* Reset padding for mobile overlay */
    }

    .sidebar.open {
        left: 0; /* Slide in */
    }
    /* Optional: Add a backdrop for the overlay */
    body.sidebar-open-overlay::before {
        content: "";
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: var(--sidebar-mobile-overlay-bg);
        z-index: 1100; /* Below sidebar, above main content */
        opacity: 1;
        transition: opacity 0.3s ease;
    }


    .sidebar.collapsed { /* Adjust collapsed state for mobile if needed, or hide collapse button */
        width: 80%; /* When collapsed, it's essentially hidden or managed by 'open' class */
        left: -100%;
        padding: var(--spacing-m);
    }
    .sidebar.collapsed .collapse-icon {
        /* display: none; /* Hide desktop collapse icon on mobile, use hamburger */
    }
    .collapse-icon { /* Desktop collapse icon */
        display: block; /* Keep it for desktop */
    }

    .sidebar-mobile-links {
        display: flex; /* Show mobile links in the sidebar */
    }

    .main-content {
        width: 100%; /* Main content takes full width */
        transition: margin-left 0.3s ease; /* If sidebar pushes content */
    }
    /* If sidebar pushes content:
    .main-content.shifted {
        margin-left: var(--sidebar-width);
    }
    */

    .hamburger-icon {
        display: block; /* Show hamburger icon */
    }

    .header-links {
        display: none; /* Hide desktop header links */
    }

    .chat-header {
        padding: var(--spacing-m);
    }
    .chat-title {
        font-size: 1.1em;
        margin-left: var(--spacing-s); /* Space next to hamburger */
    }
    .logo-right {
        height: 30px; /* Adjust Goethe logo for smaller screens */
    }
    .logo-bottom {
        height: 30px; /* Adjust Studium Digitale logo */
    }


    .message {
        max-width: 90%; /* Slightly more width for messages */
    }

    .message-area-container {
        padding: var(--spacing-m);
    }

    .input-area-wrapper {
        padding: var(--spacing-s) var(--spacing-m);
    }

    .modal-content {
        width: 95%;
        padding: var(--spacing-m);
    }
    .modal-title {
        font-size: 1.2em;
    }
    .modal-actions {
        flex-direction: column; /* Stack modal buttons on small screens */
    }
    .modal-button {
        width: 100%;
    }
}

/* Typing Indicator Styles (Spinner) */
.typing-indicator {
    display: flex;
    justify-content: flex-start;
    margin-bottom: var(--spacing-m);
}

.typing-indicator .message.chatbot {
    background-color: var(--message-chatbot-bg);
    color: var(--message-text-color);
    padding: var(--spacing-s); /* Adjust padding if needed for the spinner */
    border-radius: var(--border-radius-large);
    border-bottom-left-radius: var(--border-radius-small);
    box-shadow: var(--box-shadow-light);
    display: flex; /* To center spinner if needed, or for layout */
    align-items: center;
    justify-content: center;
    width: fit-content; /* Adjust to content */
    min-width: 50px; /* Ensure it has some width for the spinner */
    min-height: 40px; /* Ensure it has some height for the text */
    padding: var(--spacing-s) var(--spacing-m); /* Ensure padding is consistent */
}

.loading-text {
    font-style: italic;
    color: var(--text-color-secondary);
}

/* Spinner styles removed as it's replaced by loading-text */
