/* =================================
   1. VARIÁVEIS GLOBAIS E ESTILOS BASE
   ================================= */

:root {
    /* Paleta de cores Clean/Gemini */
    --primary-bg: #131314;
    --secondary-bg: #1e1f20;
    --input-bg: #1e1f20;
    --text-primary: #e3e3e3;
    --text-secondary: #bdc1c6;
    --accent-color: #2fb9a4;
    --text-on-accent: #202124;
    --border-color: #3c4043;
    --hover-bg: #2d2e30;
}

/* Global Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* =================================
   RAG STYLES - RESPONSIVE
   ================================= */

.rag-page .rag-container {
    padding: 28px 18px;
    box-sizing: border-box;
    width: 100%;
}

.rag-card {
    background: var(--secondary-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 18px;
    box-shadow: 0 6px 18px rgba(2, 6, 23, 0.6);
    width: 100%;
    max-width: 1100px;
    margin: 12px auto 0 auto;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    min-height: 700px;
}

.rag-card-body {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    flex-wrap: wrap;
    width: 100%;
    box-sizing: border-box;
}

/* ACTION BUTTONS - Base styles (used by RAG and other components) */
.rag-actions {
    display: flex;
    gap: 16px;
    align-items: stretch;
    flex-wrap: wrap;
    width: 100%;
}

.action-btn {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    padding: 14px 20px;
    border-radius: 12px;
    border: 1px solid transparent;
    cursor: pointer;
    flex: 1;
    min-width: 200px;
    transition: transform .12s ease, box-shadow .12s ease;
}

.action-btn .btn-icon {
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
}

.action-btn .btn-icon svg {
    width: 20px;
    height: 20px;
    stroke-width: 1.6;
    stroke: currentColor;
    fill: none;
}

.action-btn .btn-label {
    font-weight: 700;
    color: var(--text-primary);
    font-size: 0.95rem;
}

.action-btn .btn-sub {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.action-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 14px 30px rgba(16, 24, 40, 0.35);
}

.action-btn:active {
    transform: translateY(0);
}

.action-btn[disabled] {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Button variants */
.action-btn-primary {
    background: linear-gradient(180deg, rgba(47, 185, 164, 0.12), transparent);
    border-color: rgba(47, 185, 164, 0.18);
}

.action-btn-accent {
    background: linear-gradient(180deg, rgba(79, 129, 255, 0.06), transparent);
    border-color: rgba(79, 129, 255, 0.12);
}

.action-btn-danger {
    background: linear-gradient(180deg, rgba(220, 53, 69, 0.06), transparent);
    border-color: rgba(220, 53, 69, 0.12);
}

.action-btn-danger .btn-icon {
    color: #ffb3b8;
}

.action-btn-danger .btn-label {
    color: #ffb3b8;
}

.action-btn-danger .btn-sub {
    color: #ffdbdd;
}

.action-btn-danger:hover {
    transform: translateY(-2px);
    box-shadow: 0 14px 30px rgba(255, 77, 85, 0.12);
}

.action-btn-danger[disabled] {
    opacity: 0.5;
}

.action-btn .btn-spinner {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.action-btn .btn-spinner svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
}

.action-btn.loading {
    transform: none;
    box-shadow: 0 8px 20px rgba(2, 6, 23, 0.35);
}

.action-btn.loading .btn-label {
    opacity: 0.85;
}

/* RAG Status and Output */
.rag-status {
    flex: 1 1 480px;
    min-width: 300px;
    width: 100%;
}

.rag-output {
    background: rgba(10, 12, 14, 0.6);
    color: var(--text-primary);
    padding: 12px;
    border-radius: 8px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9rem;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 420px;
    overflow: auto;
    border: 1px solid var(--border-color);
    box-sizing: border-box;
    width: 100%;
}

/* Status Tabs */
.status-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    border-bottom: 2px solid var(--border-color);
}

.status-tab {
    padding: 10px 16px;
    border: none;
    background: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    transition: all 0.2s ease;
    position: relative;
    bottom: -2px;
}

.status-tab:hover {
    color: var(--text-primary);
}

.status-tab.active {
    color: var(--accent-color);
    border-bottom-color: var(--accent-color);
}

.status-tab-content {
    position: relative;
}

.tab-pane {
    display: none;
}

.tab-pane.active {
    display: block;
    animation: fadeIn 0.2s ease;
}



/* Uploads Header and Summary */
.uploads-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.uploads-info h3 {
    margin: 0;
    color: var(--text-primary);
    font-size: 1.1rem;
}

.uploads-count {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

.refresh-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: linear-gradient(135deg, rgba(47, 185, 164, 0.1), rgba(47, 185, 164, 0.05));
    color: var(--accent-color);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.refresh-btn:hover {
    border-color: var(--accent-color);
    background: linear-gradient(135deg, rgba(47, 185, 164, 0.15), rgba(47, 185, 164, 0.1));
    transform: scale(1.02);
}

.refresh-btn svg {
    width: 18px;
    height: 18px;
}

.refresh-btn:active {
    transform: scale(0.98);
}

/* Uploads Summary */
.uploads-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.summary-item {
    background: linear-gradient(135deg, rgba(255,255,255,0.03), rgba(255,255,255,0.01));
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px 16px;
    text-align: center;
}

.summary-label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.summary-value {
    display: block;
    font-size: 1.8rem;
    font-weight: 700;
    min-height: 40px;
    line-height: 1;
}

.summary-value.pending {
    color: #ffa94d;
}

.summary-value.running {
    color: #52e3ee;
}

.summary-value.done {
    color: #2fb9a4;
}

.summary-value.failed {
    color: #e74c3c;
}

/* Files for upload panel - IMPROVED */
.files-upload-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 8px;
    max-height: 500px;
    overflow-y: auto;
    padding: 8px;
    border-radius: 8px;
}

.files-upload-list::-webkit-scrollbar {
    width: 8px;
}

.files-upload-list::-webkit-scrollbar-track {
    background: transparent;
}

.files-upload-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.files-upload-list::-webkit-scrollbar-thumb:hover {
    background: rgba(255,255,255,0.2);
}

/* Force content left alignment inside the files-for-upload list */
.files-upload-list,
.files-upload-item,
.files-upload-info,
.files-upload-info .title,
.files-upload-info .meta,
.files-empty {
    text-align: left;
}

.files-upload-item {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 14px;
    border: 1px solid rgba(255,255,255,0.05);
    border-radius: 8px;
    background: linear-gradient(135deg, rgba(255,255,255,0.02), transparent);
    transition: all 0.2s ease;
    gap: 16px;
}

.files-upload-item:hover {
    background: linear-gradient(135deg, rgba(255,255,255,0.04), rgba(255,255,255,0.01));
    border-color: rgba(255,255,255,0.1);
}

.files-upload-info {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
    min-width: 0;
}

.files-upload-info .title {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.95rem;
    line-height: 1.3;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.files-upload-info .meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.files-upload-info .meta-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.files-upload-actions {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    white-space: nowrap;
}

.files-empty {
    padding: 32px 24px;
    text-align: center;
    color: var(--text-secondary);
    border: 1px dashed var(--border-color);
    border-radius: 8px;
    background: rgba(255,255,255,0.01);
}

.files-empty-icon {
    font-size: 2.5rem;
    margin-bottom: 12px;
    opacity: 0.5;
}

.files-upload-badge {
    font-size: 0.75rem;
    padding: 6px 12px;
    border-radius: 999px;
    font-weight: 500;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.status-badge {
    border: 1px solid currentColor;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.status-badge.status-idle {
    color: var(--text-secondary);
    border-color: var(--text-secondary);
    background: transparent;
}

.status-badge.status-pending {
    color: #ffa94d;
    border-color: #ffa94d;
    background: rgba(255, 169, 77, 0.1);
}

.status-badge.status-running {
    color: #52e3ee;
    border-color: #52e3ee;
    background: rgba(82, 227, 238, 0.1);
}

.status-badge.status-completed {
    color: #2fb9a4;
    border-color: #2fb9a4;
    background: rgba(47, 185, 164, 0.1);
}

.status-badge.status-done {
    color: #2fb9a4;
    border-color: #2fb9a4;
    background: rgba(47, 185, 164, 0.1);
}

.status-badge.status-failed {
    color: #e74c3c;
    border-color: #e74c3c;
    background: rgba(231, 76, 60, 0.1);
}

/* Uploads Footer */
.uploads-footer {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

.uploads-help {
    margin: 0;
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-align: center;
}

/* Config Styles */
.config-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.config-header h3 {
    margin: 0;
    color: var(--text-primary);
    font-size: 1.1rem;
}

.save-config-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: linear-gradient(135deg, rgba(47, 185, 164, 0.1), rgba(47, 185, 164, 0.05));
    color: var(--accent-color);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.save-config-btn:hover {
    border-color: var(--accent-color);
    background: linear-gradient(135deg, rgba(47, 185, 164, 0.15), rgba(47, 185, 164, 0.1));
    transform: scale(1.02);
}

.save-config-btn svg {
    width: 18px;
    height: 18px;
}

.save-config-btn:active {
    transform: scale(0.98);
}

.config-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
}

.config-header h3 {
    margin: 0;
    flex: 1;
}

.config-form {
    display: flex;
    flex-direction: column;
    gap: 24px;
    margin-bottom: 24px;
}

.config-section {
    background: linear-gradient(135deg, rgba(255,255,255,0.03), rgba(255,255,255,0.01));
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 16px;
}

.config-section h4 {
    margin: 0 0 16px 0;
    color: var(--accent-color);
    font-size: 0.95rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.config-row {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.config-row:last-child {
    margin-bottom: 0;
}

.config-row-inline {
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
    align-items: flex-start;
}

.config-row-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.config-field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.checkbox-label {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    cursor: pointer;
    padding: 8px 0;
}

.checkbox-label input[type="checkbox"] {
    margin-top: 4px;
    cursor: pointer;
    accent-color: var(--accent-color);
    width: 18px;
    height: 18px;
}

.checkbox-label span {
    color: var(--text-primary);
    font-size: 0.95rem;
}

.checkbox-label small {
    display: block;
    color: var(--text-secondary);
    font-size: 0.8rem;
    margin-top: 4px;
    margin-left: 30px;
}

.input-label {
    display: block;
    color: var(--text-primary);
    font-size: 0.9rem;
    margin-bottom: 8px;
}

.config-input {
    padding: 10px 12px;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.95rem;
    transition: all 0.2s ease;
}

.config-input:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(47, 185, 164, 0.2);
}

.config-input:hover {
    border-color: var(--accent-color);
}

.config-footer {
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

#configStatus {
    margin: 0;
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-align: center;
}

#configStatus.success {
    color: #2fb9a4;
}

/* MEDIA QUERIES - RAG RESPONSIVE FOR MOBILE */

/* Tablets (900px and below) */
@media (max-width: 900px) {
    .rag-card {
        padding: 14px;
    }
    
    .rag-card-body {
        flex-direction: column;
        gap: 14px;
    }

    .rag-actions {
        flex-direction: column;
        width: 100%;
    }

    .action-btn {
        width: 100%;
        min-width: unset;
    }

    .rag-status {
        width: 100%;
        min-width: unset;
    }

    /* Config adjustments for tablets */
    .config-row-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .config-row-inline {
        gap: 16px;
    }
}

/* Large Phones/Small Tablets (768px and below) */
@media (max-width: 768px) {
    .rag-page .rag-container {
        padding: 16px 12px;
    }

    .rag-card {
        padding: 12px;
    }

    .action-btn {
        padding: 12px 14px;
        gap: 4px;
    }

    .action-btn .btn-icon {
        width: 24px;
        height: 24px;
    }

    .action-btn .btn-icon svg {
        width: 18px;
        height: 18px;
    }

    .action-btn .btn-label {
        font-size: 0.9rem;
    }

    .action-btn .btn-sub {
        font-size: 0.8rem;
    }

    .rag-output {
        max-height: 300px;
        font-size: 0.85rem;
        padding: 10px;
    }

    /* Config adjustments for large phones */
    .config-form {
        gap: 18px;
    }

    .config-section {
        padding: 14px;
    }

    .config-row-grid {
        grid-template-columns: 1fr;
        gap: 14px;
    }

    .config-row-inline {
        gap: 14px;
        flex-direction: column;
    }

    .config-row-inline .checkbox-label {
        width: 100%;
    }
}

/* Mobile Phones (480px and below) */
@media (max-width: 480px) {
    .rag-page .rag-container {
        padding: 12px 8px;
    }

    .rag-card {
        padding: 10px;
        border-radius: 8px;
        margin-top: 8px;
    }

    .rag-actions {
        gap: 8px;
    }

    .action-btn {
        padding: 10px 12px;
        min-width: unset;
        flex: 0 1 calc(50% - 4px);

        border-radius: 8px;
    }

    .action-btn .btn-icon {
        width: 20px;
        height: 20px;
    }

    .action-btn .btn-icon svg {
        width: 16px;
        height: 16px;
    }

    .action-btn .btn-label {
        font-size: 0.8rem;
        font-weight: 600;
    }

    .action-btn .btn-sub {
        display: none;
    }

    .rag-status {
        margin-top: 12px;
    }

    .rag-output {
        max-height: 250px;
        font-size: 0.8rem;
        padding: 8px;
    }

    /* Config adjustments for mobile phones */
    .config-header {
        flex-direction: column;
        gap: 12px;
    }

    .config-header h3 {
        margin: 0;
    }

    .save-config-btn {
        width: 100%;
    }

    .config-form {
        gap: 16px;
    }

    .config-section {
        padding: 12px;
    }

    .config-section h4 {
        font-size: 0.85rem;
        margin-bottom: 12px;
    }

    .config-row {
        margin-bottom: 12px;
    }

    .config-row-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .config-field {
        gap: 6px;
    }

    .input-label {
        font-size: 0.85rem;
    }

    .config-input {
        padding: 10px;
        font-size: 16px;
    }

    .checkbox-label {
        gap: 10px;
        padding: 6px 0;
    }

    .checkbox-label input[type="checkbox"] {
        width: 16px;
        height: 16px;
    }

    .checkbox-label span {
        font-size: 0.9rem;
    }

    .checkbox-label small {
        margin-left: 26px;
        font-size: 0.75rem;
    }

    #configStatus {
        font-size: 0.8rem;
    }

    .rag-files-upload-header {
        gap: 6px;
    }

    .small-btn {
        padding: 4px 8px;
        font-size: 0.8rem;
        gap: 4px;
    }

    .welcome-greeting {
        font-size: 1.5rem;
        margin-bottom: 12px;
    }
}


body {
    background-color: var(--primary-bg);
    color: var(--text-primary);
    font-family: 'Roboto', 'Google Sans', sans-serif;
    display: flex;
    height: 100dvh;
    margin: 0;
    overflow: auto;
    /* allow page scrolling so native pull-to-refresh can work */
    /* Impede o body de rolar */
}

/* Allow native overscroll behaviors (pull-to-refresh) unless explicitly prevented
   Some browsers require the document to be scrollable (body/html) to trigger native refresh. */
html,
body {
    overscroll-behavior-y: auto;
}

.chat-main {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    /* Garante que ocupe a altura da viewport */
    overflow: hidden;
    background-color: var(--primary-bg);
}

/* =================================
   2. ESTILOS DA TELA DE LOGIN (COM EFEITO DE RÓTULO)
   ================================= */

body.login-page {
    justify-content: center;
    align-items: center;
}

.login-page .form-wrapper {
    text-align: center;
    width: 100%;
    max-width: 400px;
    padding: 20px;
}

.login-page .logo {
    max-width: 150px;
    margin-bottom: 40px;
}

.login-form .input-group {
    position: relative;
    margin-bottom: 30px;
}

.login-form label {
    position: absolute;
    top: 15px;
    left: 20px;
    color: var(--text-secondary);
    pointer-events: none;
    transition: all 0.2s ease-in-out;
}

.login-page input[type="text"],
.login-page input[type="password"] {
    width: 100%;
    padding: 15px 20px;
    border: 1px solid var(--border-color);
    border-radius: 28px;
    background-color: var(--primary-bg);
    color: var(--text-primary);
    font-size: 16px;
    box-sizing: border-box;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.login-page input[type="text"]:focus,
.login-page input[type="password"]:focus {
    outline: none;
    border-color: var(--accent-color);
}

/* * ESTA É A REGRA MÁGICA! 
 * Ela ativa quando o input está em foco (focus) OU quando o placeholder não está sendo exibido 
 * (:not(:placeholder-shown)), o que acontece assim que você digita algo.
 * ESSA REGRA DEPENDE DO placeholder=" " NO HTML.
*/
.login-page input[type="text"]:focus+label,
.login-page input[type="text"]:not(:placeholder-shown)+label,
.login-page input[type="password"]:focus+label,
.login-page input[type="password"]:not(:placeholder-shown)+label {
    top: -10px;
    font-size: 12px;
    color: var(--accent-color);
    background-color: var(--primary-bg);
    /* Cor de fundo da página */
    padding: 0 5px;
}


.login-page button[type="submit"] {
    width: 100%;
    padding: 15px;
    border: 1px solid var(--accent-color);
    border-radius: 28px;
    background-color: transparent;
    color: var(--accent-color);
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
}

.login-page button[type="submit"]:hover {
    background-color: var(--accent-color);
    color: var(--text-on-accent);
}

.error-message {
    color: #ff8a80;
    background-color: rgba(255, 138, 128, 0.1);
    border: 1px solid #ff8a80;
    border-radius: 28px;
    padding: 15px;
    margin-bottom: 25px;
    font-size: 14px;
    text-align: center;
}


/* =================================
   3. ESTILOS DA TELA DE CHAT
   ================================= */

/* --- ESTRUTURA DA SIDEBAR DE HISTÓRICO --- */
.history-sidebar {
    width: 260px;
    background-color: var(--secondary-bg);
    flex-shrink: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 8px;
    box-sizing: border-box;
    transition: margin-left 0.3s ease;
    z-index: 200;
    border-right: 1px solid var(--border-color);
}

.history-sidebar.collapsed {
    margin-left: -261px;
    /* Leva em conta a borda */
}

.sidebar-header {
    padding: 8px 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    /* Centraliza os itens */
    gap: 15px;
    margin-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
}

.logo-sidebar {
    max-width: 100px;
    /* Aumenta o tamanho do logo */
}

.sidebar-action-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 12px;
    border-radius: 8px;
    background-color: transparent;
    color: var(--text-secondary);
    border: none;
    text-decoration: none;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    font-size: 14px;
    text-align: left;
    cursor: pointer;
    transition: background-color 0.2s;
}

.sidebar-action-btn:hover {
    background-color: var(--hover-bg);
}

/* Garantir alinhamento idêntico para <a> e <button> com a mesma classe */
.sidebar-action-btn {
    box-sizing: border-box;
    line-height: 1;
}

.sidebar-action-btn svg {
    display: block;
    flex-shrink: 0;
    width: 20px;
    height: 20px;
}

.sidebar-action-btn span {
    display: inline-block;
    vertical-align: middle;
}

.conversation-list {
    flex-grow: 1;
    overflow-y: auto;
}

.conversation-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
    transition: background-color 0.2s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-item:hover,
.conversation-item.active {
    background-color: var(--hover-bg);
}

.conversation-item .actions {
    gap: 8px;
}

.conversation-item .title {
    flex-grow: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-item .actions button {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.conversation-item .actions button:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

/* --- ESTRUTURA PRINCIPAL DO CHAT --- */
body.chat-page {
    flex-direction: row;
    justify-content: flex-start;
}


.chat-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    background-color: var(--primary-bg);
    flex-shrink: 0;
    box-sizing: border-box;
    z-index: 1000;
    position: sticky;
    top: 0;
    left: 0;
    right: 0;
    min-height: 56px;
    /* Fixa o header no topo em mobile e desktop */
}

#toggle-sidebar-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
    margin-right: 10px;
    z-index: 1100;
}

#toggle-sidebar-btn:hover {
    background-color: var(--hover-bg);
}

.user-profile {
    display: flex;
    justify-content: flex-end;
}

.user-info {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    text-align: right;
}

.user-name {
    font-size: 16px;
    color: var(--text-primary);
    font-weight: 500;
}

.logout-link {
    color: var(--accent-color);
    text-decoration: none;
    font-size: 12px;
    transition: filter 0.2s;
    margin-top: 2px;
}

.logout-link:hover {
    text-decoration: underline;
    filter: brightness(1.2);
}

/* --- SELETOR DE MODELO --- */
.model-selector-container {
    display: flex;
    justify-content: center;
    /* keep internal content centered */
    margin: 0;
    /* place the selector at the top center of the header */
    position: absolute;
    top: 8px;
    /* small gap from the header top */
    left: 50%;
    transform: translateX(-50%);
    z-index: 50;
    pointer-events: auto;
}

.model-selector-display {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 4px 10px;
    border-radius: 12px;
    transition: background-color 0.2s, box-shadow 0.18s, transform 0.12s;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent);
    border: 1px solid var(--border-color);
    padding: 6px 12px;
}

.model-selector-display:hover {
    background-color: var(--hover-bg);
}

.model-display {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
}

.model-selector-container .dropdown-arrow {
    color: var(--text-secondary);
    transition: transform 0.18s ease;
}

.model-selector-container.open .model-selector-display {
    background-color: var(--secondary-bg);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
    transform: translateY(-1px);
}

.dropdown-arrow {
    transition: transform 0.2s;
}

.model-selector-container.open .dropdown-arrow {
    transform: rotate(180deg);
}

.model-options {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--secondary-bg);
    border-radius: 8px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.55);
    width: 310px;
    /* slightly wider */
    max-width: calc(100vw - 32px);
    z-index: 100;
    padding: 10px;
    border: 1px solid var(--border-color);
}

.model-options .model-option-title {
    color: var(--text-primary);
}

.model-options a {
    display: flex;
    flex-direction: column;
    gap: 2px;
    color: var(--text-primary);
    text-decoration: none;
    padding: 10px;
    transition: background-color 0.2s;
    border-bottom: 1px solid var(--border-color);
}

.model-options a .model-option-desc {
    color: var(--text-secondary);
    font-size: 12px;
}

/* Hover highlight for option */
.model-options a:hover {
    background-color: var(--hover-bg);
    border-radius: 6px;
}

/* Responsive: shrink dropdown width on very small screens */
@media (max-width: 420px) {
    .model-options {
        width: calc(100vw - 32px);
        left: 50%;
        transform: translateX(-50%);
    }
}

/* Mobile: center dropdown in viewport so it doesn't depend on parent width/position */
@media (max-width: 600px) {
    .model-options {
        position: fixed;
        top: 64px;
        /* adjust if your header has different height */
        left: 50%;
        transform: translateX(-50%);
        width: calc(100vw - 32px);
        max-width: none;
        z-index: 9999;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.65);
        border-radius: 10px;
    }
}

/* When active, ensure the dropdown is centered and uses the defined transform */
.model-options.active {
    display: block;
    left: 50%;
    transform: translateX(-50%);
}

.model-option-title {
    font-weight: 500;
    font-size: 14px;
    margin: 1px;
}

.model-option-desc {
    font-size: 12px;
    color: var(--text-secondary);
    margin: 4px 0 0;
}

/* --- ESTRUTURA PRINCIPAL DO CHAT --- */

.chat-container {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    overflow: hidden;
    min-height: 0;
    /* Essencial para o flex-grow funcionar */
    justify-content: flex-end;
    padding-bottom: 20px;
    box-sizing: border-box;
    transition: justify-content 0.5s ease;
}

.chat-container.initial-view {
    justify-content: center;
}

.initial-content {
    display: none;
    text-align: center;
    animation: surgir 0.5s ease-out;
    margin-bottom: 20px;
}

/* Ensure initial content shows for RAG container as well */
.chat-container.initial-view .initial-content,
.rag-container .initial-content {
    display: block;
}

.welcome-greeting {
    font-family: 'Google Sans', sans-serif;
    font-size: 2.8rem;
    font-weight: 400;
    margin: 0;
    background: -webkit-linear-gradient(45deg, #8ab4f8, #c2e7ff);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.welcome-subtitle {
    font-size: 1.25rem;
    color: var(--text-secondary);
    margin-top: 8px;
}


.chat-window {
    flex-grow: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
    display: none;
    /* Começa escondido */
}

.chat-container:not(.initial-view) .chat-window {
    display: flex;
    /* Mostra quando a conversa começa */
}


.message {
    position: relative;
    max-width: 80%;
    padding: 12px 18px;
    border-radius: 18px;
    line-height: 1.6;
    animation: surgir 0.4s ease-out;
    word-wrap: break-word;
}

/* Lists inside messages: reduce excessive indentation and keep bullets inside the text block */
.message .message-content ul,
.message .message-content ol {
    margin: 0.4rem 0 0.4rem 0;
    padding-left: 1.05rem;
    /* smaller than browser default */
    list-style-position: inside;
}

.message .message-content li {
    margin: 0.25rem 0;
}

.message.bot {
    background-color: transparent;
    color: var(--text-primary);
    align-self: flex-start;
}

.message.bot .message-content p:first-child {
    margin-top: 0;
}

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

.rag-badge {
    display: inline-block;
    margin-top: 12px;
    padding: 6px 12px;
    background-color: rgba(47, 185, 164, 0.15);
    border: 1px solid rgba(47, 185, 164, 0.3);
    border-radius: 6px;
    font-size: 0.85rem;
    color: var(--accent-color);
    font-weight: 500;
}

.no-rag-badge {
    display: inline-block;
    margin-top: 12px;
    padding: 6px 12px;
    background-color: rgba(255, 152, 0, 0.15);
    border: 1px solid rgba(255, 152, 0, 0.3);
    border-radius: 6px;
    font-size: 0.85rem;
    color: #ff9800;
    font-weight: 500;
}

.message.user {
    background-color: var(--secondary-bg);
    color: var(--text-primary);
    align-self: flex-end;
    border-radius: 6px 18px 18px 18px;
    position: relative;
    /* Necessário para o posicionamento absoluto do botão */
    padding-bottom: 30px;
    /* Adiciona espaço para o botão não sobrepor o texto */
}

.toggle-text-btn {
    position: absolute;
    bottom: 5px;
    right: 8px;
    background-color: var(--hover-bg);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    width: 28px;
    height: 28px;
    border-radius: 5px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    opacity: 0.7;
    transition: opacity 0.2s, color 0.2s, background-color 0.2s;
    margin: 5px;
}

.toggle-text-btn:hover {
    opacity: 1;
    background-color: var(--accent-color);
    color: var(--text-on-accent);
}

@keyframes surgir {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

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

/* --- ÁREA DE INPUT --- */

.chat-input-area {
    padding: 0 20px;
    flex-shrink: 0;
    position: relative;
    width: 100%;
    box-sizing: border-box;
}

#message-form {
    width: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    /* O gap foi removido daqui pois o input-wrapper agora é um item único */
}

.input-wrapper {
    display: flex;
    flex-direction: column;
    /* ALTERADO: Organiza os itens (preview e input-row) verticalmente */
    gap: 10px;
    /* ALTERADO: Adiciona espaço entre o preview e a linha de input */
    background-color: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 28px;
    padding: 10px 15px;
    /* AJUSTADO para melhor espaçamento interno */
    transition: box-shadow 0.2s, border-color 0.2s;
}

.input-wrapper:focus-within {
    box-shadow: 0 0 0 1px var(--accent-color);
    border-color: var(--accent-color);
}

/* NOVO: Regra para a linha de input */
.input-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    width: 100%;
}


#message-input {
    flex-grow: 1;
    background-color: transparent;
    border: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 16px;
    resize: none;
    max-height: 200px;
    overflow-y: auto;
    outline: none;
    margin-bottom: 5px;
}

/* Ajustes responsivos para textarea em dispositivos móveis */
@media (max-width: 900px) {
    #message-input {
        max-height: 160px;
    }
}

@media (max-width: 600px) {
    #message-input {
        max-height: 110px;
    }

    .history-sidebar {
        position: fixed;
        top: 56px;
        /* altura do header */
        left: 0;
        bottom: 0;
        margin-left: -261px;
        transition: margin-left 0.25s ease;
        z-index: 3000;
        height: calc(100vh - 56px);
        box-shadow: 2px 0 12px rgba(0, 0, 0, 0.25);
    }

    .history-sidebar.opened {
        margin-left: 0;
    }

    /* Centraliza o seletor de modelo no header em mobile */
    .model-selector-container {
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
        width: max-content;
        min-width: 0;
        z-index: 2000;
    }

    .chat-header {
        min-height: 56px;
        height: 56px;
        /* Fix header to viewport on mobile so it remains visible when body scrolls */
        position: fixed !important;
        top: env(safe-area-inset-top, 0) !important;
        left: 0;
        right: 0;
        z-index: 6000 !important;
        background: var(--primary-bg);
        display: flex;
        align-items: center;
    }

    .chat-main {
        width: 100%;
    }

    #toggle-sidebar-btn {
        display: flex !important;
    }

    /* Compensate for the fixed header so chat content isn't hidden underneath */
    .chat-container {
        padding-top: calc(72px + env(safe-area-inset-top, 0));
        /* header height + small gap + notch safe area */
    }
}

/* Garante que o botão de abrir sidebar sempre aparece em mobile, mesmo quando sidebar está oculta */
@media (max-width: 600px) {
    #toggle-sidebar-btn {
        display: flex !important;
        z-index: 4100;
    }

    .history-sidebar.collapsed+.chat-main .chat-header #toggle-sidebar-btn {
        display: flex !important;
    }
}

#send-button {
    background-color: transparent;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    transition: background-color 0.2s, color 0.2s;
    align-self: flex-end;
    /* Mantem o botão na parte de baixo */
}

#send-button:not(:disabled) {
    color: var(--accent-color);
}

#send-button:not(:disabled):hover {
    background-color: var(--hover-bg);
}

#send-button:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}


#clear-chat-btn {
    position: sticky;
    top: 10px;
    align-self: flex-end;
    background-color: var(--secondary-bg);
    border: none;
    color: var(--text-secondary);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    margin-bottom: 5px;
    z-index: 10;
    transition: all 0.2s;
    flex: none;
}

#clear-chat-btn:hover {
    background-color: var(--hover-bg);
    color: var(--text-primary);
}


/* --- INDICADOR DE "PENSANDO" --- */
.message.bot.thinking .message-content span {
    display: inline-block;
    background-color: var(--text-secondary);
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin: 0 2px;
    animation: bounce 1.4s infinite ease-in-out both;
}

.message.bot.thinking .message-content span:nth-child(1) {
    animation-delay: -0.32s;
}

.message.bot.thinking .message-content span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1.0);
    }
}

/* --- MENSAGEM DE SISTEMA --- */
.message.system {
    align-self: center;
    text-align: center;
    font-size: 12px;
    color: var(--text-secondary);
    background-color: var(--secondary-bg);
    padding: 5px 15px;
    border-radius: 15px;
    margin: 10px 0;
    max-width: 80%;
}

/* --- BARRA DE ROLAGEM --- */

/* Compatibilidade SVG: mantém tamanho e cor herdados, sem sobrescrever fill/stroke */
button svg,
a svg {
    flex-shrink: 0;
    /* width: 1.8em;
    height: 1.8em; */
    vertical-align: middle;
    /* Não sobrescreve fill/stroke, deixa o SVG herdar do contexto */
}

.chat-window::-webkit-scrollbar,
#message-input::-webkit-scrollbar {
    width: 8px;
}

.chat-window::-webkit-scrollbar-track,
#message-input::-webkit-scrollbar-track {
    background: transparent;
}

.chat-window::-webkit-scrollbar-thumb {
    background-color: #444;
    border-radius: 8px;
    border: 4px solid var(--primary-bg);
    background-clip: padding-box;
}

.chat-window:hover::-webkit-scrollbar-thumb {
    background-color: #666;
}

/* --- BOTÃO COPIAR --- */
.copy-btn {
    position: absolute;
    bottom: 8px;
    right: -40px;
    background-color: var(--secondary-bg);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    width: 28px;
    height: 28px;
    border-radius: 5px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    opacity: 0;
    transition: opacity 0.2s, color 0.2s, background-color 0.2s;
}

.message:hover .copy-btn {
    opacity: 1;
}

.copy-btn:hover {
    background-color: var(--hover-bg);
    color: var(--text-primary);
}

.copy-btn.copied svg {
    fill: var(--accent-color);
}

/* --- MENSAGEM DE ERRO --- */
.message.error {
    background-color: transparent;
    border: 1px solid #ff8a80;
    color: #ffc2c2;
}

.error-actions {
    display: flex;
    gap: 15px;
    align-items: center;
    margin-top: 10px;
}

.retry-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background-color: #ff8f8f;
    color: var(--primary-bg);
    border: none;
    padding: 5px 12px;
    border-radius: 15px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.2s;
}

.retry-btn:hover {
    background-color: #ffc2c2;
    transform: translateY(-1px);
}

.debug-toggle {
    font-size: 12px;
    color: #ff8f8f;
    text-decoration: underline;
    cursor: pointer;
    background: none;
    border: none;
    padding: 0;
}

.debug-details {
    display: none;
    margin-top: 10px;
    padding: 10px;
    background-color: rgba(0, 0, 0, 0.3);
    border-radius: 5px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 13px;
    white-space: pre-wrap;
    word-break: break-all;
}

/* --- ANEXOS E FERRAMENTAS --- */
.input-actions-left {
    display: flex;
    align-items: center;
    align-self: flex-end;
    /* Mantem os botões na parte de baixo */
}

#attach-file-btn {
    background-color: transparent;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
}

#attach-file-btn:hover {
    background-color: var(--hover-bg);
    color: var(--text-primary);
}

/* Quando o botão de anexar estiver desabilitado, não aplica hover nem pointer events */
#attach-file-btn:disabled,
#attach-file-btn.disabled {
    opacity: 0.6;
    /* visual de desativado */
    cursor: default;
    pointer-events: none;
    background-color: transparent;
    /* evita variar com :hover */
    color: var(--text-secondary);
}

#file-preview-container {
    background-color: var(--secondary-bg);
    padding: 10px 15px;
    border-radius: 8px;
    display: none;
    align-items: center;
    gap: 10px;
    animation: surgir 0.3s ease-out;
    /* align-self: flex-start; foi REMOVIDO para que o item ocupe o espaço no contêiner flex pai */
    width: fit-content;
    max-width: 100%;
    box-sizing: border-box;
}

.file-info {
    display: flex;
    align-items: center;
    gap: 8px;
    overflow: hidden;
}

.file-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 14px;
}

#remove-file-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 20px;
    padding: 0 5px;
}

#remove-file-btn:hover {
    color: var(--text-primary);
}

.message .attached-file-container {
    margin-top: 10px;
    padding: 8px 12px;
    background-color: var(--hover-bg);
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    max-width: 100%;
    font-size: 14px;
}

.message .attached-file-container.downloadable {
    cursor: pointer;
    transition: filter 0.2s;
}

.message .attached-file-container.downloadable:hover {
    filter: brightness(1.2);
}

/* Indicador textual para anexos pendentes (enviando) */
.file-spinner {
    margin-left: 8px;
    font-size: 12px;
    color: var(--text-secondary);
    font-style: italic;
}

/* Spinner circular para indicar upload em andamento */
.file-upload-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.08);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    margin-left: 8px;
    vertical-align: middle;
    animation: spin 1s linear infinite;
}



/* Quando a área de preview estiver em estado de uploading, mostra o spinner ao lado do nome */
.file-info.uploading::after {
    content: '';
    display: inline-block;
    width: 14px;
    height: 14px;
    margin-left: 8px;
    border: 2px solid rgba(255, 255, 255, 0.08);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* Menu de ferramentas comentado no HTML - estilos reservados para futuras implementações */

/* ========== MODAL DE CONFIRMAÇÃO ========== */
.confirm-modal {
    position: fixed;
    inset: 0;
    display: none;
    /* hidden by default */
    align-items: center;
    justify-content: center;
    z-index: 5000;
}

.confirm-modal[aria-hidden="false"] {
    display: flex;
}

.confirm-modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(2px);
}

.confirm-modal-content {
    /* use fixed positioning + transform to ensure perfect centering on the viewport
       (solves cases where flex centering is affected by other layout rules) */
    position: fixed;
    background: var(--secondary-bg);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 20px;
    border-radius: 12px;
    width: 90%;
    max-width: 420px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
    z-index: 2;
    /* Slight elevation for the RAG table */
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

/* Pipeline status badges */
.status-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 72px;
    padding: 6px 10px;
    border-radius: 999px;
    font-weight: 600;
    font-size: 13px;
    color: var(--text-on-accent);
    background-color: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-color);
}

.status-badge.status-idle {
    background-color: transparent;
    color: var(--text-secondary);
    border-color: var(--border-color);
}

.status-badge.status-running {
    background-color: var(--accent-color);
    color: var(--text-on-accent);
    border-color: rgba(47, 185, 164, 0.25);
}

.status-badge.status-completed {
    background-color: #4caf50;
    color: white;
    border-color: rgba(76, 175, 80, 0.2);
}

.status-badge.status-failed {
    background-color: #ff6b6b;
    color: white;
    border-color: rgba(255, 107, 107, 0.2);
}

/* Pipeline controls layout */


.confirm-modal-content h2 {
    margin: 0 0 8px 0;
    font-size: 18px;
}

.confirm-modal-content p {
    margin: 0 0 16px 0;
    color: var(--text-secondary);
    font-size: 14px;
}

.confirm-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.btn {
    padding: 8px 14px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
}

.btn:focus {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

.btn-secondary {
    background: transparent;
    color: var(--text-secondary);
}

/* Mobile: keep input fixed to bottom and ensure chat content has safe spacing */
@media (max-width: 600px) {
    .chat-input-area {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        padding: 10px 12px;
        background: linear-gradient(180deg, rgba(19, 19, 20, 0.85), rgba(19, 19, 20, 0.95));
        z-index: 5000;
    }

    /* Give the chat container/window enough bottom padding so last messages aren't hidden */
    .chat-container,
    .chat-window {
        padding-bottom: 92px;
        /* roughly input height + margin */
    }

    /* Ensure textarea doesn't get behind the virtual keyboard by allowing viewport-height resizing */
    #message-input {
        max-height: 90px;
    }

    /* Sidebar: use transform for show/hide so it can overlay without disappearing after messages render */
    .history-sidebar {
        position: fixed;
        top: 56px;
        /* below header */
        left: 0;
        bottom: 0;
        height: calc(100vh - 56px);
        margin-left: 0;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        z-index: 4000;
        box-shadow: 2px 0 12px rgba(0, 0, 0, 0.25);
    }

    .history-sidebar.opened {
        transform: translateX(0);
    }

    /* Make sure the toggle button is above everything and can toggle sidebar */
    #toggle-sidebar-btn {
        position: relative;
        z-index: 5100;
    }

    /* Bot messages left-aligned for readability */
    .message.bot {
        text-align: left;
        align-self: flex-start;
    }

    /* On small screens allow messages to use nearly full width to avoid unused gutter when lists are present */
    .message {
        max-width: 96%;
    }

    /* Further reduce list indentation specifically on very narrow screens */
    .message .message-content ul,
    .message .message-content ol {
        padding-left: 0.8rem;
    }

    /* Always show copy button on mobile and keep it inside the message bubble */
    .copy-btn {
        opacity: 1 !important;
        right: -10px;
        bottom: -10px;
        width: 25px;
        height: 25px;
        display: flex;
    }
}

/* =================================
   RAG PAGE STYLES
   ================================= */

body.rag-page {
    /* reuse chat-page layout but allow vertical flow */
    flex-direction: row;
}

.rag-actions {
    width: 100%;
    max-width: 900px;
}

/* New container for RAG page to center content */
.rag-panel {
    margin: 28px auto;
    max-width: 1100px;
    width: calc(100% - 48px);
    background-color: transparent;
    /* sem cor de fundo */
    border: none;
    /* sem borda */
    border-radius: 12px;
    padding: 20px 28px;
    box-shadow: none;
    /* sem sombra */
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
    overflow: visible;
}

.rag-panel h1.welcome-greeting,
.rag-panel h3 {
    text-align: center;
}

.rag-panel .rag-actions,
.rag-panel .rag-files,
.rag-panel .card,
.rag-panel table {
    width: 100%;
}

.rag-panel .rag-files-list {
    display: flex;
    justify-content: center;
}

.rag-panel .d-flex.justify-content-between {
    width: 100%;
}

/* New RAG container to replace chat-container on RAG page
   Ensures content doesn't sit under the header and keeps the same background. */
.rag-container {
    box-sizing: border-box;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    background-color: var(--primary-bg);
    /* mantém o fundo original */
    /* Pad pequeno para o topo conforme solicitado */
    padding-top: 8px;
    padding-bottom: 40px;
    /* Garante que o container tenha no mínimo a altura visível menos header */
    min-height: calc(100vh - 56px);
    overflow: auto;
    /* permitir rolagem caso o conteúdo seja maior */
}

/* Em telas pequenas o header pode ser fixo; aumenta o padding-top para evitar sobreposição */
@media (max-width: 600px) {
    .rag-container {
        padding-top: calc(56px + 28px);
        padding-bottom: 92px;
        /* compensa input fixo no mobile */
    }

    .rag-panel {
        padding: 16px;
    }
}

.rag-actions .input-row {
    display: flex;
    gap: 12px;
    align-items: center;
}

/* Buttons consistent look */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    text-decoration: none;
    color: var(--text-primary);
    background-color: transparent;
}

.btn-primary {
    background-color: var(--input-bg);
    color: var(--accent-color);
    border-color: rgba(47, 185, 164, 0.2);
}

.btn-secondary {
    background-color: transparent;
    color: var(--text-secondary);
    border-color: var(--border-color);
}

.btn-danger {
    background-color: transparent;
    color: #ff7a7a;
    border-color: var(--border-color);
}

.btn-sm {
    padding: 6px 8px;
    font-size: 13px;
    border-radius: 6px;
}

.rag-files-list {
    margin-top: 12px;
}

.rag-files-table {
    width: 100%;
    border-collapse: collapse;
    background-color: var(--secondary-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
}

.rag-files-table thead th {
    text-align: center;
    padding: 12px 16px;
    font-size: 13px;
    color: var(--text-secondary);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent);
    border-bottom: 1px solid var(--border-color);
}

.rag-files-table tbody td {
    padding: 12px 16px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    font-size: 14px;
    color: var(--text-primary);
    vertical-align: middle;
}

/* Nome do arquivo: não quebrar linha e truncar com ellipsis (preservando extensão via JS) */
.rag-files-table tbody td:first-child {
    max-width: 420px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rag-files-table tbody tr:hover td {
    background-color: var(--hover-bg);
}

.file-download-link {
    color: var(--accent-color);
    text-decoration: none;
}

.file-download-link:hover {
    text-decoration: underline;
}

/* Actions column alignment */
.rag-files-table tbody td.actions,
.rag-files-table tbody td:last-child {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: flex-end;
    white-space: nowrap;
}

/* Tighter layout for small screens */
@media (max-width: 720px) {
    /* Upload UI removed; no styles needed here. */
}

/* Responsividade */
@media (max-width: 720px) {
    .rag-files-table thead {
        display: none;
    }

    .rag-files-table,
    .rag-files-table tbody,
    .rag-files-table tr,
    .rag-files-table td {
        display: block;
        width: 100%;
    }

    .rag-files-table tr {
        margin-bottom: 12px;
    }

    .rag-files-table td {
        padding: 10px 12px;
    }

    .rag-files-table td:nth-child(1) {
        font-weight: 600;
    }
}