/* 
    Luna Portal - Premium Design System 
    Author: Antigravity
*/

:root {
    /* Color Palette */
    --bg-main: #0a0b10;
    --bg-secondary: #161922;
    --bg-glass: rgba(22, 25, 34, 0.7);
    --accent: #2e7bff;
    --accent-glow: rgba(46, 123, 255, 0.3);
    --text-primary: #ffffff;
    --text-secondary: #94a3b8;
    --border: rgba(255, 255, 255, 0.08);
    --glass-blur: blur(12px);

    /* Layout */
    --sidebar-width: 280px;
    --sub-sidebar-width: 280px;
    --header-height: 64px;
    --border-radius: 12px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'DM Sans', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.5;
    overflow: hidden;
    display: flex;
    /* Importante: impede scroll na janela inteira, mas usa dvh para mobile */
    height: 100dvh;
}

/* Glassmorphism Utility */
.glass {
    background: var(--bg-glass);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border);
}

/* Sidebar Styling */
.sidebar {
    position: relative;
    left: 0;
    top: 0;
    width: max-content;
    height: 100dvh;
    padding: 24px;
    display: flex;
    flex-direction: column;
    z-index: 100;
}

.sidebar-logo {
    font-size: 1.5rem;
    font-weight: 800;
    margin-bottom: 40px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.workspace-list {
    flex: 1;
    overflow-y: auto;
    width: max-content;
}

.workspace-item {
    width: max-content;
    padding: 12px 16px;
    border-radius: var(--border-radius);
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-secondary);
    border: 1px solid transparent
}

.workspace-item:hover,
.workspace-item.active {
    background: rgba(46, 123, 255, 0.1);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

/* Sub-Sidebar Styling (The Assistant List) */
.sub-sidebar {
    width: var(--sub-sidebar-width);
    height: calc(100dvh - var(--header-height));
    background: rgba(255, 255, 255, 0.02);
    border-right: 1px solid var(--border);
    display: none;
    /* Escondido por defeito, mostrado quando workspace ativo */
    flex-direction: column;
    padding: 20px 15px;
    overflow-y: auto;
}

.sub-sidebar.active {
    display: flex;
}

.sub-sidebar-header {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    letter-spacing: 0.05em;
    margin-bottom: 20px;
    padding-left: 10px;
}

.chat-nav-item {
    padding: 10px 12px;
    border-radius: 10px;
    margin-bottom: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.chat-nav-item i {
    font-size: 1.1rem;
}

.chat-nav-item:hover {
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-primary);
}

.chat-nav-item.active {
    background: var(--bg-secondary);
    color: var(--accent);
    border-color: var(--border);
}

.chat-nav-item.super-chat {
    background: rgba(46, 123, 255, 0.05);
    color: var(--accent);
    font-weight: 600;
    margin-bottom: 25px;
    border: 1px solid var(--accent-glow);
}

.chat-nav-item.super-chat:hover {
    background: rgba(46, 123, 255, 0.1);
}

.docs-manager-item {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    margin-bottom: 25px;
    color: var(--text-primary);
}

.docs-manager-item i {
    color: var(--accent);
}

.docs-manager-item:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--accent);
}

/* Main Dashboard Area */
.main-content {
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* --- Novo Viewport Estrutural --- */
.dashboard-viewport {
    flex: 1;
    display: flex;
    overflow: hidden;
    position: relative;
    width: 100%;
}

.chat-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    min-height: 0;
}

/* Modo Split-Screen: Empurra o chat para a esquerda */
body.preview-open .chat-section {
    padding-right: 850px;
}

/* Quando o preview abre, o viewport pode adicionar margem ou o modal responder */
body.preview-open #modal-workspace-settings,
body.preview-open #modal-document-manager {
    padding-right: 850px;
}

#modal-workspace-settings,
#modal-document-manager {
    transition: padding 0.4s cubic-bezier(0.4, 0, 0.2, 1) !important;
}

/* Secondary (Docs) Sidebar */
.docs-sidebar {
    position: fixed;
    right: 0;
    top: 0;
    width: var(--sidebar-width);
    height: 100dvh;
    padding: 24px;
    display: flex;
    flex-direction: column;
    z-index: 100;
}

.document-item {
    padding: 12px;
    border-radius: 12px;
    border: 1px solid var(--border);
    margin-bottom: 12px;
    font-size: 0.85rem;
    position: relative;
    background: rgba(255, 255, 255, 0.02);
}

.doc-main-info {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
}

.document-item .doc-name {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 5px;
}

.document-item .doc-meta {
    font-size: 0.75rem;
    color: var(--text-secondary);
    display: flex;
    justify-content: space-between;
}

.btn-delete-doc {
    color: #ff4d4d;
    cursor: pointer;
    font-size: 0.8rem;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.btn-delete-doc:hover {
    opacity: 1;
}

/* Document Grid Layout */
.document-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 15px;
    padding: 10px;
    max-height: 480px;
    /* Limite aproximado de 3-4 linhas dependendo do zoom */
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--accent) transparent;
}

/* Scrollbar Styling - Premium Feel */
.document-grid::-webkit-scrollbar {
    width: 6px;
}

.document-grid::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.02);
    border-radius: 10px;
}

.document-grid::-webkit-scrollbar-thumb {
    background: var(--accent);
    border-radius: 10px;
}

.document-grid::-webkit-scrollbar-thumb:hover {
    background: #5090ff;
}

.item-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 25px 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    user-select: none;
    min-height: 150px;
}

.item-card:hover {
    background: rgba(46, 123, 255, 0.08);
    border-color: rgba(46, 123, 255, 0.3);
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.item-card.dragging {
    opacity: 0.5;
    transform: scale(0.95);
}

.item-card.drag-over {
    background: rgba(0, 255, 136, 0.1) !important;
    border-color: #00ff88 !important;
    box-shadow: 0 0 15px rgba(0, 255, 136, 0.2);
}

.item-card i {
    font-size: 2.2rem;

}

.item-card .item-name {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    line-height: 1.4;
    color: var(--text-primary);
    width: 100%;
    margin-bottom: 5px;
    padding: 0 4px;
    /* Mostrar até 2 linhas caso o nome seja longo */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: normal;
}

.item-card .item-meta {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    gap: 5px;
}

.item-card .btn-delete-item,
.item-card .btn-download-item,
.item-card .btn-preview-item {
    padding: 2px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    opacity: 0.3;
    transition: all 0.2s;
    cursor: pointer;
}

.item-card .btn-delete-item i,
.item-card .btn-download-item i,
.item-card .btn-preview-item i {
    font-size: 0.9rem !important;
}

.item-card .btn-delete-item:hover {
    color: #ff4d4d;
    opacity: 1;
    transform: scale(1.1);
}

.item-card .btn-download-item:hover {
    color: var(--accent);
    opacity: 1;
    transform: scale(1.1);
}

.item-card .btn-preview-item:hover {
    color: white;
    opacity: 1;
    transform: scale(1.1);
}

.item-card .status-indicator {
    position: absolute;
    top: 8px;
    left: 8px;
}

/* Progress Bar Styling */
.rag-progress-wrapper {
    width: 85%;
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.rag-progress-container {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.rag-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), #00ff88);
    width: 0%;
    transition: width 0.3s ease;
    box-shadow: 0 0 10px rgba(46, 123, 255, 0.5);
}

/* Drag & Drop Zone */
.drop-zone {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(46, 123, 255, 0.2);
    backdrop-filter: blur(8px);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 4px dashed var(--accent);
    margin: -4px;
    /* offset border */
    pointer-events: auto;
}

.drop-zone-content {
    background: var(--bg-secondary);
    padding: 40px 60px;
    border-radius: 24px;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--border);
}

.drop-zone-content h2 {
    font-family: 'DM Sans', sans-serif;
    margin-bottom: 15px;
    color: var(--accent);
}

/* Status Dots */
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    vertical-align: middle;
    margin-right: 8px;
}

.dot-processing {
    background: #ffaa00;
    box-shadow: 0 0 8px #ffaa00;
    animation: pulse-amber 1.5s infinite;
}

.dot-processing-blue {
    background: #2e7bff;
    box-shadow: 0 0 8px #2e7bff;
    animation: pulse-blue 1.5s infinite;
}

.dot-indexed {
    background: #00ff88;
    box-shadow: 0 0 8px #00ff88;
}

.dot-error {
    background: #ff4444;
    box-shadow: 0 0 8px #ff4444;
}

@keyframes pulse-blue {
    0% {
        transform: scale(0.9);
        opacity: 0.7;
    }

    50% {
        transform: scale(1.1);
        opacity: 1;
    }

    100% {
        transform: scale(0.9);
        opacity: 0.7;
    }
}

@keyframes pulse-amber {
    0% {
        transform: scale(0.9);
        opacity: 0.7;
    }

    50% {
        transform: scale(1.1);
        opacity: 1;
    }

    100% {
        transform: scale(0.9);
        opacity: 0.7;
    }
}

/* RAG Progress Bar */
.rag-progress-wrapper {
    margin-top: 8px;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.rag-progress-container {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 4px;
}

.rag-progress-fill {
    height: 100%;
    background: var(--accent);
    width: 0%;
    transition: width 0.3s ease;
}

/* Token Badges */
.token-badge {
    font-size: 0.7rem;
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.05);
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 8px;
    border: 1px solid var(--border);
    font-family: monospace;
}

.message .token-badge {
    display: block;
    margin-top: 8px;
    text-align: right;
    border: none;
    background: transparent;
    opacity: 0.6;
}

/* Tool Result Card (Super-Chat) */
.tool-result-card {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    background: rgba(16, 185, 129, 0.08);
    border: 1px solid rgba(16, 185, 129, 0.25);
    border-radius: 12px;
    padding: 14px 18px;
    margin: 8px 0;
    max-width: 600px;
}

.tool-result-icon {
    color: #10b981;
    font-size: 1.3rem;
    flex-shrink: 0;
    margin-top: 2px;
}

.tool-result-title {
    font-weight: 600;
    font-size: 0.9rem;
    color: #10b981;
    margin-bottom: 4px;
}

.tool-result-preview {
    font-size: 0.82rem;
    color: var(--text-secondary);
    font-family: monospace;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 480px;
}

.header {
    height: var(--header-height);
    padding: 0 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 90;
}

.chat-container {
    flex: 1;
    margin: 0;
    width: 100%;
    /* Removido o padding fixo para alinhar scrollbar na borda direita */
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Novo estilo para o bloco de mensagens - Implementa o corredor central de 1000px */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    padding-top: 40px;
    padding-bottom: 40px;
    /* Cálculo para centralizar o conteúdo alinhado com o input (max 1000px) */
    padding-left: max(24px, calc((100% - 1000px) / 2));
    padding-right: max(24px, calc((100% - 1000px) / 2));
    gap: 20px;
    scrollbar-width: thin;
    scrollbar-color: var(--accent) transparent;
    flex: 1;
    min-height: 0;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--accent);
    border-radius: 10px;
}

.message {
    padding: 16px 20px;
    border-radius: 16px;
    max-width: 70%;
    /* Ocupar apenas 70% da largura como solicitado */
    width: fit-content;
    position: relative;
}

.message.assistant {
    align-self: flex-start;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.message.user {
    align-self: flex-end;
    background: var(--accent);
    color: white;
    width: max-content;
    /* Usar apenas o espaço necessário */
    max-width: 70%;
    border-bottom-right-radius: 4px;
    text-align: left;
    /* Manter o texto à esquerda dentro da bolha */
}

.message-edit-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    left: -32px;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.8rem;
    opacity: 0;
    transition: all 0.2s ease;
}

.message.user:hover .message-edit-btn {
    opacity: 1;
}

.message-edit-btn:hover {
    background: var(--bg-secondary);
    color: white;
    border-color: rgba(255, 255, 255, 0.3);
}

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

.message-content p {
    margin-bottom: 10px;
}

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

.message-content ul,
.message-content ol {
    margin-left: 20px;
    margin-bottom: 15px;
}

.message-content li {
    margin-bottom: 5px;
}

.message-content strong {
    color: var(--text-primary);
}

.message-content pre {
    background: #0f111a;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    border: 1px solid var(--border);
    margin-bottom: 15px;
}

.message-content code {
    font-family: inherit;
    font-size: 0.9em;
    color: #00ff88;
}

/* Markdown Tables Styling */
.message-content table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 15px;
    font-size: 0.9em;
}

.message-content th,
.message-content td {
    padding: 10px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    text-align: left;
}

.message-content th {
    background: rgba(255, 255, 255, 0.05);
    color: var(--accent);
    font-weight: 600;
}

.message-content tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.02);
}

.message.user {
    align-self: flex-end;
    background: var(--accent);
    color: white;
}

.message.assistant {
    align-self: flex-start;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
}

/* Input Area */
.input-zone {
    padding: 24px;
    position: sticky;
    bottom: 0;
    background: linear-gradient(to top, var(--bg-main) 60%, transparent);
}

.input-wrapper {
    max-width: 1000px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    /* Alinhamento vertical absoluto */
    gap: 12px;
    padding: 8px 12px;
    border-radius: 16px;
}

.btn-secondary {
    background: transparent;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0 10px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    height: 42px;
}

input[type="text"] {
    flex: 1;
    background: transparent;
    border: none;
    color: white;
    padding: 12px;
    font-size: 1rem;
}

input[type="text"]:focus {
    outline: none;
}

.btn-send {
    background: var(--accent);
    color: white;
    border: none;
    padding: 10px 24px;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    height: 42px;
    /* Altura fixa para alinhar com o input */
}

.btn-send:active {
    transform: scale(0.95);
}

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

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

.animate-fade {
    animation: fadeIn 0.4s ease forwards;
}

/* --- Preview Sidebar Styles (Hybrid Fixed Mode) --- */
.preview-sidebar {
    position: fixed;
    top: calc(var(--header-height) + 12px);
    right: -900px;
    /* Escondido por defeito */
    width: 850px;
    height: calc(100dvh - var(--header-height) - 24px);
    z-index: 10010;
    /* Acima do modal (10000+10001) e do overlay */
    display: flex;
    flex-direction: column;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px 0 0 12px;
    background: var(--bg-glass);
    backdrop-filter: var(--glass-blur);
    overflow: hidden;
}

.preview-sidebar.active {
    right: 0;
}

.preview-header {
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.2);
}

.preview-title {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.preview-body {
    flex: 1;
    padding: 10px;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    background: rgba(0, 0, 0, 0.05);
}

.btn-close-preview {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.1rem;
    transition: color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-close-preview:hover {
    color: white;
}

/* Placeholders & Loading */
.preview-placeholder {
    text-align: center;
    color: var(--text-secondary);
}

.spinner {
    width: 30px;
    height: 30px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 15px;
}

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

/* Reference Buttons in Chat */
.btn-ref {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(var(--accent-rgb), 0.08);
    border: 1px solid rgba(var(--accent-rgb), 0.2);
    color: var(--accent);
    padding: 2px 10px;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    margin: 0 4px;
    vertical-align: middle;
}

.btn-ref:hover {
    background: rgba(var(--accent-rgb), 0.15);
    border-color: var(--accent);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.btn-ref i {
    font-size: 0.9rem;
}

/* --- Home View & Workspace Grid --- */
.home-view {
    padding: 60px 40px;
    max-width: 1200px;
    margin: 0 auto;
    height: 100%;
    overflow-y: auto;
    scrollbar-width: thin;
}

.home-header {
    margin-bottom: 40px;
    text-align: left;
}

.home-header h1 {
    font-size: 2.5rem;
    font-weight: 800;
    margin-bottom: 10px;
    background: linear-gradient(135deg, #fff 0%, var(--accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.home-header p {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

.workspace-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 25px;
}

.workspace-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 30px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    position: relative;
    overflow: hidden;
    backdrop-filter: blur(10px);
}

.workspace-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--accent);
    opacity: 0;
    transition: opacity 0.3s;
}

.workspace-card:hover {
    background: rgba(255, 255, 255, 0.07);
    border-color: rgba(46, 123, 255, 0.4);
    transform: translateY(-8px);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

.workspace-card:hover::before {
    opacity: 1;
}

.ws-card-icon {
    width: 50px;
    height: 50px;
    background: rgba(46, 123, 255, 0.1);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: var(--accent);
}

.ws-card-info h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

.ws-card-info p {
    margin: 8px 0 0;
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.ws-card-footer {
    margin-top: auto;
    display: flex;
    justify-content: flex-end;
}

.btn-open-ws {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 8px 20px;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    transition: all 0.2s;
}

.workspace-card:hover .btn-open-ws {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

/* --- Footnote Citation System --- */
.ref-indicator {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    background: rgba(var(--accent-rgb), 0.08);
    color: var(--accent);
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    vertical-align: middle;
    margin: 0 2px;
    transition: all 0.2s;
    user-select: none;
    border: 1px solid rgba(var(--accent-rgb), 0.15);
    max-width: 180px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ref-indicator:hover {
    background: var(--accent);
    color: white;
    transform: scale(1.05);
}

.ref-indicator i {
    font-size: 0.6rem;
}

.sources-footer {
    margin-top: 15px;
    padding-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.footer-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.footer-btns {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.btn-ref-footer {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 6px 14px;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    max-width: 250px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-ref-footer:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.btn-ref-footer i {
    font-size: 0.9rem;
}



/* ==========================================================================
   LOGIN PAGE
   ========================================================================== */
.login-page {
    height: 100dvh;
    width: 100vw;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at top right, #1a2035, #0a0b10);
    overflow: hidden;
    position: relative;
}

.login-page::before {
    content: "";
    position: absolute;
    width: 300px;
    height: 300px;
    background: var(--accent);
    filter: blur(150px);
    opacity: 0.15;
    top: -100px;
    right: -100px;
    border-radius: 50%;
}

.login-card {
    width: 100%;
    max-width: 400px;
    padding: 40px;
    border-radius: 24px;
    animation: slideUpFade 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slideUpFade {
    from {
        opacity: 0;
        transform: translateY(30px);
    }

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

.login-brand {
    text-align: center;
    margin-bottom: 32px;
}

.login-brand .logo-symbol {
    font-size: 2.5rem;
    color: var(--accent);
    margin-bottom: 12px;
    display: block;
    text-shadow: 0 0 20px var(--accent-glow);
}

.login-brand h1 {
    font-size: 1.75rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.login-brand p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 8px;
}

.login-form .form-group {
    margin-bottom: 20px;
}

.login-form label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
    margin-left: 4px;
}

.input-container {
    position: relative;
    display: flex;
    align-items: center;
}

.input-container i {
    position: absolute;
    left: 16px;
    color: var(--text-secondary);
    font-size: 1.1rem;
}

.input-container input {
    width: 100%;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    padding: 14px 16px 14px 48px;
    border-radius: 12px;
    color: white;
    font-family: inherit;
    font-size: 1rem;
    transition: all 0.3s;
}

.input-container input:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.06);
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-glow);
}

.btn-login {
    width: 100%;
    background: var(--accent);
    color: white;
    border: none;
    padding: 14px;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s;
    margin-top: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.btn-login:hover {
    background: #4089ff;
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(46, 123, 255, 0.3);
}

.login-error {
    background: rgba(255, 68, 68, 0.1);
    border: 1px solid rgba(255, 68, 68, 0.2);
    color: #ff8080;
    padding: 12px;
    border-radius: 10px;
    font-size: 0.85rem;
    text-align: center;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

/* ==========================================================================
   RESPONSIVE DESIGN (MOBILE & TABLET)
   ========================================================================== */

/* Overlay de fundo quando sidebar está aberta */
.body-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100dvh;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 299990;
    /* Acima do header (200000) mas abaixo das sidebars */
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: all 0.3s ease;
}

body.sidebar-open .body-overlay {
    opacity: 1;
    visibility: visible;
    pointer-events: all;
}

.btn-mobile-toggle {
    display: none;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
    margin-right: 15px;
}

.btn-back-sidebar {
    display: none;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    margin-bottom: 20px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s;
    width: 100%;
    box-shadow: 0 4px 15px rgba(46, 123, 255, 0.3);
}

.btn-back-sidebar:hover {
    background: #4089ff;
    transform: translateY(-2px);
}

@media (max-width: 768px) {
    body {
        position: relative;
        overflow-x: hidden;
        display: block;
    }

    /* Sidebars: Global Overlays */
    .sidebar,
    .sub-sidebar {
        position: fixed !important;
        top: 0;
        left: 0;
        height: 100dvh;
        width: 290px !important;
        z-index: 300000 !important;
        /* Acima do Header (200000) e Overlay (299990) */
        transform: translate3d(-110%, 0, 0) !important;
        transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 20px 0 50px rgba(0, 0, 0, 0.5);
        background: var(--bg-secondary) !important;
        visibility: visible !important;
        display: flex !important;
        padding-top: 20px !important;
    }

    /* Sub-sidebar fica à frente da principal se ativa */
    .sub-sidebar {
        z-index: 300001 !important;
        background: #11141d !important;
        left: 0 !important;
    }

    /* Activação */
    body.sidebar-open .sidebar {
        transform: translate3d(0, 0, 0) !important;
    }

    body.sidebar-open .sub-sidebar.active {
        transform: translate3d(0, 0, 0) !important;
    }

    .btn-back-sidebar {
        display: flex !important;
        margin-top: 10px;
    }

    .main-content {
        margin-left: 0 !important;
        width: 100vw;
        height: 100dvh;
        position: relative;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .dashboard-viewport {
        flex: 1 !important;
        display: flex !important;
        min-height: 0 !important;
        overflow: hidden !important;
    }

    .header {
        padding: 0 16px;
        position: sticky;
        top: 0;
        z-index: 200000 !important;
        justify-content: left;
        /* Deve estar acima de tudo para ser clicável */
    }

    .btn-mobile-toggle {
        display: flex !important;
    }

    .chat-section {
        height: auto !important;
        flex: 1 !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
        min-height: 0 !important;
    }

    .chat-container {
        flex: 1 !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
        min-height: 0 !important;
    }

    .chat-messages {
        padding: 20px 16px !important;
        flex: 1 !important;
        overflow-y: auto !important;
        min-height: 0 !important;
        max-height: none !important;
    }

    .input-zone {
        padding: 12px 16px !important;
        background: var(--bg-main) !important;
        position: relative !important;
        bottom: auto !important;
    }

    .message {
        max-width: 95% !important;
    }

    .workspace-grid {
        grid-template-columns: 1fr !important;
        padding: 16px;
    }

    .preview-sidebar {
        width: 100vw !important;
        z-index: 20000;
    }

    .workspace-title h2 {
        font-size: 1.1rem;
        max-width: 180px;
        width: 100%;
        text-wrap: nowrap;
    }

    .user-profile span {
        display: none;
    }

    /* Input Area Mobile */
    .input-zone {
        padding: 12px 16px !important;
        background: var(--bg-main) !important;
    }

    .input-wrapper {
        gap: 8px !important;
        padding: 6px 10px !important;
        border-radius: 12px !important;
    }

    .btn-send span {
        display: none !important;
    }

    .btn-send {
        padding: 10px 15px !important;
    }

    .btn-secondary {
        padding: 0 5px !important;
    }

    /* Modais em Mobile */
    .modal-card {
        width: 100% !important;
        height: auto !important;
        max-height: 95dvh !important;
        border-radius: 12px;
    }

    .modal-card.modal-lg {
        height: 90dvh !important;
    }
}

/* Modais Dinâmicos */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100dvh;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    z-index: 500000;
    /* Prioridade máxima absoluta */
    display: none;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease;
    padding: 20px;
}

.modal-card {
    background: #1e1e2d;
    border: 1px solid var(--border);
    border-radius: 16px;
    width: 500px;
    max-width: 100%;
    max-height: 90dvh;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    z-index: 500001;
    animation: slideUp 0.3s ease-out;
}

.modal-card.modal-lg {
    width: 850px;
    height: 85dvh;
}

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

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

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}