@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    /* Messenger Palette */
    --messenger-blue: #0084FF;
    --messenger-bg: #FFFFFF;
    --messenger-gray-bg: #F0F2F5;
    --bubble-gray: #E4E6EB;
    --text-primary: #050505;
    --text-secondary: #65676B;
    --border-color: #DBDBDB;

    /* Layout */
    --sidebar-width: 300px;
    --docs-width: 300px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--messenger-gray-bg);
    color: var(--text-primary);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    line-height: 1.34;
}

.app-container {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr var(--docs-width);
    height: 100vh;
    height: 100dvh;
    max-width: 1920px;
    margin: 0 auto;
    background: #fff;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
}

/* LEFT SIDEBAR (Config) - "Inbox Style" */
.sidebar {
    background: #fff;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.sidebar-header {
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid transparent;
    /* Cleaner look */
}

.sidebar-header h2 {
    font-size: 24px;
    font-weight: 700;
}

.config-group {
    padding: 10px 16px;
}

.config-item {
    margin-bottom: 20px;
}

.config-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
    display: block;
    text-transform: uppercase;
}

/* Styled Inputs */
input[type="text"],
input[type="password"],
select {
    width: 100%;
    padding: 10px 12px;
    background: var(--messenger-gray-bg);
    border: none;
    border-radius: 8px;
    font-size: 15px;
    color: var(--text-primary);
}

input:focus,
select:focus {
    outline: none;
    background: #e4e6eb;
}

/* Upload Area */
.drop-zone {
    border: 2px dashed #ccc;
    background: #fafafa;
    border-radius: 10px;
    padding: 20px;
    text-align: center;
    cursor: pointer;
    transition: 0.2s;
}

.drop-zone:hover {
    border-color: var(--messenger-blue);
    opacity: 0.8;
}

.drop-zone p {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
}

/* CENTER CHAT (Messenger Style) */
.main-chat {
    display: flex;
    flex-direction: column;
    background: #fff;
    border-right: 1px solid var(--border-color);
    min-height: 0;
    /* Critical for Grid Item scrolling */
    overflow: hidden;
    /* Ensure it doesn't grow beyond grid track */
}

.chat-header-top {
    height: 60px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 16px;
    justify-content: space-between;
    background: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    z-index: 10;
}

.chat-user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar-circle {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #00C6FF, #0072FF);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
}

.chat-name {
    font-weight: 600;
    font-size: 17px;
}

.active-status {
    font-size: 13px;
    color: var(--text-secondary);
}

.chat-window {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: #fff;
    min-height: 0;
    /* Important for flex scrolling */
    scroll-behavior: smooth;
}

/* Custom Scrollbar for Chat */
.chat-window::-webkit-scrollbar {
    width: 8px;
}

.chat-window::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.chat-window::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}

.chat-window::-webkit-scrollbar-thumb:hover {
    background: #999;
}

/* Messages */
.message {
    display: flex;
    flex-direction: column;
    max-width: 65%;
    animation: fadeIn 0.15s ease-out;
}

.message.user {
    align-self: flex-end;
    align-items: flex-end;
}

.message.system {
    align-self: flex-start;
    align-items: flex-start;
}

.message .content {
    padding: 8px 12px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.4;
    position: relative;
    word-wrap: break-word;
}

.message.user .content {
    background-color: var(--messenger-blue);
    color: white;
    border-bottom-right-radius: 4px;
    /* Stack effect */
}

.message.system .content {
    background-color: var(--bubble-gray);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
    /* Stack effect */
}

.sources {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 4px;
    padding-left: 12px;
}

/* Input Area */
.input-area {
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-top: 1px solid var(--border-color);
}

#chatInput {
    background: var(--messenger-gray-bg);
    border-radius: 20px;
    padding: 10px 16px;
    min-height: 36px;
}

.btn-send {
    background: none;
    border: none;
    color: var(--messenger-blue);
    font-size: 20px;
    cursor: pointer;
    padding: 8px;
    transition: 0.2s;
}

.btn-send:hover {
    background: var(--messenger-gray-bg);
    border-radius: 50%;
}

/* RIGHT SIDEBAR (Documentation) */
.right-panel {
    background: #fff;
    padding: 20px;
    overflow-y: auto;
}

.doc-section {
    margin-bottom: 30px;
}

.doc-header {
    text-align: center;
    margin-bottom: 24px;
}

.profile-large {
    width: 80px;
    height: 80px;
    background: var(--messenger-blue);
    border-radius: 50%;
    margin: 0 auto 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 40px;
    color: white;
}

.doc-title {
    font-size: 20px;
    font-weight: 700;
}

.doc-subtitle {
    font-size: 15px;
    color: var(--text-secondary);
}

.info-card {
    margin-bottom: 16px;
}

.info-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.info-text {
    font-size: 15px;
    color: var(--text-primary);
    line-height: 1.5;
}

/* Progress & Status */
.status-message {
    font-size: 12px;
    margin-top: 4px;
    color: var(--text-secondary);
}

.status-success {
    color: #31A24C;
}

.status-warning {
    color: #ff9800;
}

.status-error {
    color: #f44336;
}

/* Typing Dots */
.typing-dots span {
    background-color: var(--text-secondary);
    width: 6px;
    height: 6px;
    margin: 0 1px;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Validation */
.error-field {
    border: 2px solid #d32f2f !important;
    background-color: #fce8e6 !important;
}

.mobile-menu-btn.error-field {
    color: #d32f2f !important;
    /* Red icon */
    border: none !important;
    /* No border for icon btn */
    background: none !important;
    animation: shake 0.5s;
}

@keyframes shake {
    0% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-5px);
    }

    50% {
        transform: translateX(5px);
    }

    75% {
        transform: translateX(-5px);
    }

    100% {
        transform: translateX(0);
    }
}

/* Mobile Utils */
.mobile-only {
    display: none;
}

.desktop-only {
    display: flex;
}

.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    font-size: 24px;
    color: var(--messenger-blue);
    cursor: pointer;
    margin-right: 15px;
}

/* Mobile Responsive */
@media (max-width: 1000px) {
    .app-container {
        grid-template-columns: 1fr;
    }

    .doc-panel {
        display: none;
        /* Hide docs on mobile for space */
    }

    .mobile-only {
        display: block;
    }

    .desktop-only {
        display: none;
    }

    .mobile-menu-btn {
        display: block;
    }

    .sidebar {
        display: flex;
        /* Restore display */
        position: fixed;
        left: -100%;
        /* Hide off-screen */
        top: 0;
        bottom: 0;
        width: 85%;
        max-width: 320px;
        z-index: 1000;
        transition: left 0.3s ease-in-out;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.2);
    }

    .sidebar.active {
        left: 0;
        /* Slide in */
    }

    /* Overlay when sidebar is open */
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 900;
        display: none;
    }

    .sidebar-overlay.active {
        display: block;
    }
}

/* Custom Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    /* Ensures full screen coverage (top/left/right/bottom) */
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(2px);
    /* Adds blur effect */
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    /* Higher Z-index */
    animation: fadeIn 0.15s ease-out;
}

.modal-content {
    background: #fff;
    padding: 32px 24px;
    border-radius: 16px;
    width: 90%;
    max-width: 420px;
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.2);
    text-align: center;
    font-family: inherit;
    position: relative;
    /* Ensure it doesn't get squashed */
    margin: auto;
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    /* Center buttons */
    width: 100%;
}

.modal-btn {
    flex: 1;
    /* Equal width buttons */
    padding: 12px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    font-size: 15px;
    transition: all 0.2s;
}

.modal-btn.cancel {
    background: #e4e6eb;
    color: var(--text-primary);
}

.modal-btn.cancel:hover {
    background: #d8dadf;
}

.modal-btn.confirm {
    background: #d32f2f;
    color: white;
}

.modal-btn.confirm:hover {
    background: #b71c1c;
}

/* Pending Files List */
#pendingFilesList {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.pending-file-item {
    background: #f0f2f5;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    color: var(--text-primary);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid var(--border-color);
}

.pending-file-item .remove-icon {
    color: #cb1111;
    cursor: pointer;
    font-size: 14px;
    padding: 4px;
}

.pending-file-item .remove-icon:hover {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 50%;
}

/* Process Button */
#startProcessingBtn {
    width: 100%;
    padding: 10px;
    background: #42b72a;
    /* Messenger Green/Action */
    color: white;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 12px;
    transition: background 0.2s;
}

#startProcessingBtn:hover {
    background: #36a420;
}

#startProcessingBtn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* Mobile Visibility Helper Classes */
.mobile-only {
    display: none !important;
}

.desktop-only {
    display: block;
}

/* Mobile Responsive Styles */
@media (max-width: 768px) {
    .mobile-only {
        display: block !important;
    }

    .desktop-only {
        display: none !important;
    }

    /* Show mobile buttons in header */
    .mobile-menu-btn {
        display: flex !important;
        align-items: center;
        justify-content: center;
    }

    /* Mobile Right Panel (How It Works Docs) */
    .right-panel {
        position: fixed;
        top: 0;
        right: -100%;
        width: 300px;
        height: 100vh;
        z-index: 999;
        transition: right 0.3s ease;
        box-shadow: -2px 0 10px rgba(0, 0, 0, 0.1);
    }

    .right-panel.active {
        right: 0;
    }

    /* Grid layout for mobile - hide right panel by default */
    .app-container {
        grid-template-columns: 1fr;
    }

    /* Left sidebar mobile positioning (already exists but ensuring consistency) */
    .sidebar {
        position: fixed;
        left: -100%;
        width: 300px;
        height: 100vh;
        z-index: 999;
        transition: left 0.3s ease;
    }

    .sidebar.active {
        left: 0;
    }
}

@keyframes errorBuzz {
    0% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-4px);
    }

    50% {
        transform: translateX(4px);
    }

    75% {
        transform: translateX(-4px);
    }

    100% {
        transform: translateX(0);
    }
}

.error-buzz {
    animation: errorBuzz 0.4s ease-in-out;
}

.error-buzz i {
    color: #ff0000 !important;
    /* Force red color */
    transition: color 0.2s;
}