/* Global Styles */
* {
    box-sizing: border-box;
}

/* Ensure padding doesn't increase width */

body {
    background-color: #f7f9fc;
    background-image: linear-gradient(rgba(247, 249, 252, 0.95), rgba(247, 249, 252, 0.95)), url('../img/wallpaper_1.jpg');
    background-size: cover;
    background-attachment: fixed;
    background-repeat: no-repeat;
    color: #333;
    font-family: 'Fredoka', 'Segoe UI', sans-serif;
    margin: 0;
    padding: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.container {
    width: 98%;
    /* Maximize space */
    max-width: 1600px;
    margin: 0 auto;
    padding: 10px;
    /* Reduce padding to give more space to content */
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* ... Header Styles ... */
.logo-container {
    text-align: center;
    margin-bottom: 1rem;
    /* Reduce header space */
}

/* 3-Column App Layout */
.app-wrapper {
    display: grid;
    /* Use minmax to allow shrinking but keep readable width. Use fr for center. */
    grid-template-columns: 280px 1fr 300px;
    gap: 15px;
    /* Reduce gap slightly */
    flex: 1;
    min-height: 0;
    height: calc(100vh - 100px);
    /* Adjust for header/footer */
    align-items: stretch;
}

/* Panels */
.paper-panel {
    background: #ffffff;
    border-radius: 20px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    padding: 20px;
    /* Slightly reduced padding */
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    height: 100%;
    /* Custom Scrollbar */
    scrollbar-width: thin;
    scrollbar-color: #d1d9e6 transparent;
}

/* Webkit Scrollbar styling */
.paper-panel::-webkit-scrollbar {
    width: 6px;
}

.paper-panel::-webkit-scrollbar-track {
    background: transparent;
}

.paper-panel::-webkit-scrollbar-thumb {
    background-color: #d1d9e6;
    border-radius: 20px;
}

.section-title {
    font-size: 1.1rem;
    margin-bottom: 1rem;
    padding-bottom: 8px;
    color: #004aad;
    border-bottom: 2px solid #f0f4f8;
}

/* Form Controls */
.form-group {
    background: transparent;
    padding: 0;
    box-shadow: none;
    margin-bottom: 1.2rem;
    width: 100%;
    /* Ensure it fits container */
}

.form-control {
    width: 100%;
    /* Force width 100% of parent */
    max-width: 100%;
    padding: 10px 12px;
    font-size: 0.9rem;
}

/* Input Area in Chat */
.chat-input-wrapper {
    padding: 15px;
}

/* Make sidebars vanish/stack earlier on smaller screens */
@media (max-width: 900px) {
    .app-wrapper {
        grid-template-columns: 1fr;
        height: auto;
    }

    .container {
        height: auto;
        display: block;
    }

    .logo-container img {
        max-width: 300px;
        /* Shrink logo on mobile */
    }
}

/* Chat Area */
.chat-area {
    position: relative;
    padding: 0;
    /* Reset padding for internal layout */
    background: #ffffff;
    overflow: hidden;
    /* Manage scroll internally */
}

.chat-header {
    display: flex;
    align-items: center;
    padding: 15px 25px;
    border-bottom: 1px solid #f0f0f0;
    background: rgba(255, 255, 255, 0.95);
}

.chat-logo {
    height: 40px;
    width: auto;
    margin-right: 15px;
}

.header-info h2 {
    margin: 0;
    font-size: 1.2rem;
    text-align: left;
}

.status-dot {
    height: 10px;
    width: 10px;
    background-color: #28a745;
    border-radius: 50%;
    display: inline-block;
    margin-right: 5px;
}

.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 25px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    background-image: radial-gradient(#004aad40 1px, transparent 1px);
    background-size: 20px 20px;
    background-color: #fafbfc;
    height: 95%;
    max-height: calc(100vh - 180px);
    min-height: 500px;
}

/* Chat Messages */
.message {
    background: white;
    border-radius: 12px;
    padding: 12px 18px;
    margin-bottom: 15px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    width: 98%;
    max-width: 98%;
}

.user-message {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    width: 85%;
    max-width: 85%;
    margin-left: auto;
    margin-right: 0;
}

.user-message strong {
    color: #fff;
    opacity: 0.9;
}

.user-message p {
    margin: 8px 0 0 0;
    color: white;
    font-size: 10pt;
}

.ai-message {
    background: white;
    width: 98%;
    max-width: 98%;
}

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

.message-actions {
    margin-top: 15px;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ai-message {
    background: #ffffff;
    border-top-left-radius: 4px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
    align-self: flex-start;
    border: 1px solid #eef0f5;
}

.welcome-message {
    text-align: center;
    color: #8899a6;
    margin-top: 50px;
}

/* Input Area */
.chat-input-wrapper {
    padding: 15px 20px;
    background: #ffffff;
    border-top: 1px solid #f0f0f0;
    display: flex;
    gap: 10px;
    align-items: flex-end;
    height: 5%;
    min-height: 80px;
    max-height: 120px;
}

.chat-input {
    flex: 1;
    border: 2px solid #eef0f5;
    border-radius: 15px;
    padding: 15px;
    font-family: inherit;
    resize: none;
    height: 60px;
    /* Initial height */
    transition: border-color 0.2s;
    background: #f9f9f9;
}

.chat-input:focus {
    outline: none;
    border-color: #004aad;
    background: #fff;
}

.btn-send {
    background: #004aad;
    color: white;
    border: none;
    border-radius: 15px;
    padding: 0 25px;
    height: 60px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-send:hover {
    background: #003380;
}

/* Form Controls (Sidebar adjustments) */
.form-group {
    background: transparent;
    padding: 0;
    box-shadow: none;
    margin-bottom: 1.5rem;
}

.form-label {
    margin-bottom: 0.5rem;
    font-size: 0.95rem;
    color: #666;
}

.form-control {
    padding: 12px 15px;
    border-radius: 10px;
    font-size: 0.95rem;
    background-color: #f7f9fc;
    border: 1px solid #e1e4e8;
}

/* Context Button */
.context-btn {
    width: 100%;
    padding: 10px;
    font-size: 0.9rem;
    border-radius: 10px;
    background: #eef0f5;
    color: #333;
    border: none;
    align-items: center;
    justify-content: center;
    display: flex;
    cursor: pointer;
}

.context-btn:hover {
    background: #e1e4e8;
}

/* File Input Styling */
input[type="file"].form-control {
    padding: 10px;
    background: #fcfcfc;
    height: auto;
}

input[type="file"]::file-selector-button {
    border: none;
    background: #004aad;
    color: white;
    padding: 8px 15px;
    border-radius: 8px;
    margin-right: 15px;
    cursor: pointer;
    font-family: 'Fredoka', sans-serif;
    transition: background 0.2s;
}

input[type="file"]::file-selector-button:hover {
    background: #003380;
}

/* Footer Logo */
.footer-logo {
    opacity: 0.8;
    transition: opacity 0.3s;
}

.footer-logo:hover {
    opacity: 1;
}

/* Responsive adjustments */
@media (max-width: 1024px) {
    .app-wrapper {
        grid-template-columns: 1fr;
        /* Stack everything */
        height: auto;
        display: flex;
        flex-direction: column;
    }

    .sidebar-left,
    .sidebar-right,
    .chat-area {
        height: auto;
        max-height: none;
        width: 100%;
        /* Full width */
        margin-bottom: 20px;
        /* Spacing between stacked items */
    }

    /* Order adjustments */
    .chat-area {
        height: 600px;
        /* Keep fixed height for chat scroll */
        order: 2;
        /* Ensure chat is in middle */
    }

    .sidebar-left {
        order: 1;
    }

    .sidebar-right {
        order: 3;
    }
}

.btn-action {
    background: #004aad;
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    margin-top: 10px;
}

/* Footer Adjustments */
/* Footer Adjustments */
footer {
    padding: 20px;
    margin-top: 20px;
}

/* Modal Styling */
.modal {
    display: none;
    /* Hidden by default */
    position: fixed;
    /* Stay in place */
    z-index: 1000;
    /* Sit on top */
    left: 0;
    top: 0;
    width: 100%;
    /* Full width */
    height: 100%;
    /* Full height */
    overflow: auto;
    /* Enable scroll if needed */
    background-color: rgba(0, 0, 0, 0.6);
    /* Black w/ opacity */
    backdrop-filter: blur(5px);
}

.modal-content {
    background-color: #fefefe;
    margin: 5% auto;
    /* 5% from top and centered */
    padding: 30px;
    border: 1px solid #888;
    width: 80%;
    /* Could be more or less, depending on screen size */
    max-width: 900px;
    border-radius: 15px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
    animation: slideDown 0.3s ease-out;
    position: relative;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

@keyframes slideDown {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.close-modal {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    position: absolute;
    right: 20px;
    top: 15px;
    transition: color 0.2s;
}

.close-modal:hover,
.close-modal:focus {
    color: #000;
    text-decoration: none;
    cursor: pointer;
}

.markdown-body {
    overflow-y: auto;
    flex: 1;
    padding-right: 10px;
    line-height: 1.6;
    color: #333;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
    color: #004aad;
    margin-top: 1.5em;
}

.markdown-body ul {
    padding-left: 20px;
}

.markdown-body blockquote {
    border-left: 4px solid #004aad;
    padding-left: 15px;
    color: #555;
    background: #f9f9f9;
    padding: 10px;
    border-radius: 4px;
}

/* Responsive Tweaks */
@media (max-width: 900px) {
    .app-wrapper {
        grid-template-columns: 1fr;
        height: auto;
        display: flex;
        flex-direction: column;
    }

    /* Order: Chat first (2), Params (1), Context (3) - wait, Chat is main focus */
    .sidebar-left {
        order: 2;
        margin-bottom: 20px;
    }

    .chat-area {
        order: 1;
        height: 600px;
        margin-bottom: 20px;
    }

    .sidebar-right {
        order: 3;
        margin-bottom: 20px;
    }

    .modal-content {
        width: 95%;
        margin: 10% auto;
    }
}

/* Processing Overlay */
.processing-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    /* Hidden by default */
    justify-content: center;
    align-items: center;
    z-index: 9999;
    color: white;
    text-align: center;
    flex-direction: column;
}

.spinner {
    width: 60px;
    height: 60px;
    border: 6px solid #f3f3f3;
    border-top: 6px solid #4ade80;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.processing-text h2 {
    color: white !important;
    margin: 10px 0;
    font-family: 'Fredoka', sans-serif;
}

.processing-text p {
    font-size: 1.1rem;
    opacity: 0.9;
}

/* Markdown Content Styles - 8PT BASE */
.markdown-content {
    font-size: 8pt !important;
    line-height: 1.6;
    color: #2c3e50;
    font-family: Arial, sans-serif;
}

.markdown-content h1 {
    font-size: 11pt !important;
    font-weight: 700;
    color: #1a1a1a;
    margin: 16px 0 10px 0;
    padding-bottom: 6px;
    border-bottom: 2px solid #e0e0e0;
}

.markdown-content h2 {
    font-size: 10pt !important;
    font-weight: 700;
    color: #1a1a1a;
    margin: 14px 0 8px 0;
}

.markdown-content h3 {
    font-size: 9pt !important;
    font-weight: 600;
    color: #333;
    margin: 12px 0 6px 0;
}

.markdown-content p {
    font-size: 8pt !important;
    margin: 8px 0;
    line-height: 1.6;
    text-align: justify;
    color: #2c3e50;
}

.markdown-content ul,
.markdown-content ol {
    font-size: 8pt !important;
    margin: 10px 0;
    padding-left: 25px;
    line-height: 1.6;
}

.markdown-content li {
    font-size: 8pt !important;
    margin: 5px 0;
    line-height: 1.5;
}

.markdown-content strong {
    font-weight: 700;
    color: #1a1a1a;
}

.markdown-content em {
    font-style: italic;
}

.markdown-content code {
    background: #f5f5f5;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

.markdown-content pre {
    background: #f5f5f5;
    padding: 15px;
    border-radius: 5px;
    overflow-x: auto;
    margin-bottom: 1em;
}

.markdown-content blockquote {
    border-left: 4px solid #1a73e8;
    padding-left: 1em;
    margin-left: 0;
    color: #666;
    font-style: italic;
}

/* Optimize chat history height */
.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    max-height: calc(100vh - 250px);
    min-height: 400px;
}