/* ============================================================
   IARA NEXUS V9.5 SOBERANO - CSS DEFINITIVO (FLUIDO E RESPONSIVO)
   Tridente de Front-end: HTML v7 + JS v10.3 + CSS v9.5
   Evoluções: Badge Eco Motors + Chat Multimodal + Malha APIs + Forja de Memória
   ============================================================ */

:root {
    /* Paleta Eco Motors Soberana */
    --bg-darker: #050811;
    --bg-dark: #0a0f1a;
    --bg-card: #12182b;
    --primary: #00d4ff;     /* Azul Tron */
    --accent: #00ff41;      /* Verde Hacker */
    --danger: #ff0055;
    --text-primary: #e5e7eb;
    --text-secondary: #9ca3af;
    --border: #1e293b;
    
    --shadow-md: 0 4px 16px rgba(0, 212, 255, 0.1);
    --shadow-glow: 0 0 15px rgba(0, 255, 65, 0.2);
    --transition: all 0.3s ease;
}

/* ============================================================
   RESET E BASE (A Cura da Tela Estática)
   ============================================================ */
* { margin: 0; padding: 0; box-sizing: border-box; }

/* 🔴 A CORREÇÃO MESTRA: Remover o 'overflow: hidden' que travava tudo */
html, body {
    width: 100%; 
    height: 100vh; /* Usa 100% da janela visível */
    overflow-x: hidden; /* Evita rolar para os lados sem querer */
    overflow-y: auto; /* PERMITE A ROLAGEM VERTICAL */
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-darker);
    color: var(--text-primary);
    line-height: 1.6;
}

/* ============================================================
   LAYOUT PRINCIPAL (SIDEBAR + CONTEÚDO)
   ============================================================ */
.container { 
    display: flex; 
    min-height: 100vh; /* Permite crescer se o conteúdo for maior */
    width: 100vw; 
}

/* SIDEBAR FIXA (Mas com rolagem interna se os menus crescerem) */
.sidebar {
    width: 260px;
    background: var(--bg-dark);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 100;
    position: sticky; /* Fica parada enquanto a tela rola */
    top: 0;
    height: 100vh; /* Ocupa exatamente a altura da tela */
    overflow-y: auto; /* Permite rolar os menus se necessário */
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    text-align: center;
}

.sidebar-header h1 {
    font-size: 1.5rem;
    color: var(--primary);
    letter-spacing: 2px;
    text-shadow: 0 0 10px rgba(0, 212, 255, 0.3);
}

.sidebar-header .version { font-size: 0.8rem; color: var(--accent); }

.sidebar-nav {
    flex: 1; padding: 20px 10px;
    display: flex; flex-direction: column; gap: 5px;
}

.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 15px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 8px;
    transition: var(--transition);
}

.nav-item:hover { background: rgba(0, 212, 255, 0.1); color: var(--text-primary); }

.nav-item.active {
    background: rgba(0, 255, 65, 0.1);
    color: var(--accent);
    border-left: 3px solid var(--accent);
}

.sidebar-footer {
    padding: 15px; border-top: 1px solid var(--border);
    text-align: center; font-size: 0.8rem; color: var(--text-secondary);
}

/* === FASE 1: Selo de Autoridade Eco Motors (Badge Soberano) === */
.eco-motors-badge {
    display: block;
    margin: 10px 15px;
    padding: 8px 12px;
    background: rgba(0, 255, 65, 0.05);
    border: 1px solid var(--accent);
    border-radius: 4px;
    color: var(--accent);
    font-size: 11px;
    font-weight: bold;
    letter-spacing: 1px;
    text-transform: uppercase;
    text-align: center;
    box-shadow: var(--shadow-glow);
    animation: glow-pulse 3s infinite ease-in-out;
}

@keyframes glow-pulse {
    0%, 100% { box-shadow: 0 0 5px rgba(0, 255, 65, 0.1); }
    50%       { box-shadow: 0 0 15px rgba(0, 255, 65, 0.3); }
}

/* ============================================================
   ÁREA DE CONTEÚDO (Fluida e com Rolagem)
   ============================================================ */
.main-content {
    flex: 1; 
    padding: 30px;
    background: radial-gradient(circle at top right, #0a0f1a, #050811);
    /* 🔴 IMPORTANTE: Não colocamos altura fixa aqui, ela cresce com o conteúdo */
}

.content-section { display: none; animation: fadeIn 0.4s ease-in-out; }
.content-section.active { display: block; }

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

.section-header { margin-bottom: 25px; }
.section-header h2 { font-size: 2rem; color: var(--text-primary); }
.section-header p { color: var(--text-secondary); }

/* ============================================================
   GRIDS E CARDS
   ============================================================ */
.dashboard-grid, .telemetry-grid, .memory-grid, .tools-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px; margin-bottom: 20px;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow-md);
    overflow: hidden;
    /* Evita que o card encolha e quebre o layout interno */
    display: flex;
    flex-direction: column;
}

.card.full-width { grid-column: 1 / -1; }

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

.card-header h3 { font-size: 1.1rem; font-weight: 600; color: var(--primary); }
.card-content { padding: 20px; flex: 1; }

/* ============================================================
   MÉTRICAS E BARRAS DE PROGRESSO (O Visual Antigo Restaurado)
   ============================================================ */
.metric { display: flex; flex-direction: column; margin-bottom: 15px; }
.metric:last-child { margin-bottom: 0; }
.metric-label { font-size: 0.85rem; color: var(--text-secondary); text-transform: uppercase; }
.metric-value { font-size: 1.3rem; font-weight: bold; color: var(--accent); }

.progress-bar {
    height: 8px; width: 100%;
    background: #1e293b;
    border-radius: 4px; margin-top: 5px; overflow: hidden;
}
.progress-fill { height: 100%; background: var(--primary); transition: width 0.5s ease; box-shadow: 0 0 10px var(--primary);}

/* ============================================================
   BOTÕES E SELETORES
   ============================================================ */
.btn {
    padding: 10px 20px; border: none; border-radius: 6px;
    font-weight: bold; cursor: pointer; transition: var(--transition);
}
.btn-primary { background: var(--primary); color: #000; }
.btn-primary:hover { background: #00b3d6; box-shadow: 0 0 10px rgba(0, 212, 255, 0.4); }

.btn-secondary { background: var(--bg-dark); border: 1px solid var(--primary); color: var(--primary); }
.btn-secondary:hover { background: rgba(0, 212, 255, 0.1); }

.btn-small { padding: 5px 10px; font-size: 0.8rem; }

.mode-selector { display: flex; gap: 10px; flex-wrap: wrap; }
.mode-btn {
    padding: 8px 15px; background: transparent;
    border: 1px solid var(--border); color: var(--text-secondary);
    border-radius: 6px; cursor: pointer; transition: var(--transition);
}
.mode-btn.active { border-color: var(--accent); color: var(--accent); background: rgba(0, 255, 65, 0.1); }

/* ============================================================
   CHAT SOBERANO E IARA (Caixas Fluidas)
   ============================================================ */

/* O Container do Chat precisa ter uma altura fixa para poder rolar internamente,
   mas a parte de baixo (input) NUNCA PODE SER CORTADA. */
.chat-container { 
    display: flex; 
    flex-direction: column; 
    height: 600px; /* Altura segura */
}

.chat-messages {
    flex: 1; 
    overflow-y: auto; 
    padding: 20px;
    display: flex; 
    flex-direction: column; 
    gap: 15px;
}

.message { display: flex; gap: 15px; }
.message-user { flex-direction: row-reverse; }

.message-avatar {
    width: 40px; height: 40px; border-radius: 50%;
    background: var(--bg-dark); border: 1px solid var(--border);
    display: flex; justify-content: center; align-items: center; font-size: 1.2rem;
    flex-shrink: 0; /* Impede o avatar de ser esmagado */
}

.message-content {
    max-width: 75%; padding: 15px;
    border-radius: 8px; /* Fase 2: Gemini refinamento */
    font-size: 14px;    /* Fase 2: Tamanho padrão legível */
    position: relative; line-height: 1.5;
    box-shadow: var(--shadow-md); /* Fase 2: Profundidade visual */
}

.message-iara .message-content {
    background: rgba(0, 212, 255, 0.05);
    border: 1px solid var(--primary);
    border-top-left-radius: 0;
}

.message-user .message-content {
    background: rgba(0, 255, 65, 0.05);
    border: 1px solid var(--accent);
    border-top-right-radius: 0;
}

.message-time {
    display: block; font-size: 0.7rem; color: var(--text-secondary);
    margin-top: 8px; text-align: right;
}

/* Área de digitação (Fixa no rodapé do container do chat) */
.chat-input-area {
    padding: 15px; border-top: 1px solid var(--border);
    display: flex; gap: 10px; background: rgba(0,0,0,0.2);
    flex-shrink: 0; /* NUNCA esmagar a área de digitar */
}

#chatInput, textarea {
    flex: 1; background: var(--bg-dark); border: 1px solid var(--border);
    color: var(--text-primary); padding: 12px; border-radius: 6px;
    font-family: inherit; resize: vertical; /* Permite aumentar o campo se quiser */
    min-height: 60px;
}
#chatInput:focus, textarea:focus { outline: none; border-color: var(--primary); }

/* === FASE 2: Botão de Anexo de Visão Multimodal === */
#btn-attach-vision {
    transition: all 0.3s ease;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.05);
}

#btn-attach-vision:hover {
    border-color: var(--primary);
    color: var(--primary);
    transform: scale(1.1);
}

/* Indicador de Digitação da IARA */
#typing-indicator {
    font-style: italic;
    font-size: 13px;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}

/* ============================================================
   LOGS DE SEGURANÇA E TABELAS (A Tabela Restaurada)
   ============================================================ */
.security-log {
    height: 400px; overflow-y: auto; font-family: monospace;
    background: #000; padding: 15px; border-radius: 6px;
}
.log-entry { margin-bottom: 5px; border-bottom: 1px dashed #333; padding-bottom: 5px; display: flex; align-items: flex-start; gap: 10px; }
.log-time { color: var(--primary); flex-shrink: 0; }
.log-type { font-weight: bold; flex-shrink: 0; }
.log-info .log-type { color: var(--primary); }
.log-warn .log-type { color: #ffea00; }
.log-error .log-type { color: var(--danger); }
.log-message { color: var(--text-primary); word-break: break-word;}

/* Tabela Padrão (Usada no Cofre de Arquivos) */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; padding: 12px; color: var(--accent); border-bottom: 2px solid #004d00; font-weight: bold; }
td { padding: 12px; border-bottom: 1px solid #111; color: var(--text-primary); }
tr:hover td { background: rgba(0, 255, 65, 0.05); }

/* === FASE 3: Malha de Endpoints (10 APIs Soberanas) === */
.api-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
}

/* Card individual de endpoint */
.api-endpoint-card {
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px 15px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    transition: var(--transition);
}

.api-endpoint-card.online  { border-left: 3px solid var(--accent); }
.api-endpoint-card.offline { border-left: 3px solid var(--danger); }
.api-endpoint-card.armed   { border-left: 3px solid #ff6b35; }

.api-endpoint-card:hover { background: rgba(0, 212, 255, 0.05); }

.api-endpoint-name   { font-size: 0.85rem; font-weight: bold; color: var(--text-primary); }
.api-endpoint-status { font-size: 0.75rem; color: var(--text-secondary); }
.api-endpoint-latency { font-size: 0.75rem; color: var(--primary); font-family: monospace; }

/* Realce da Linha Laranja de Latência no Gráfico */
.chart-legend-latency {
    color: #ff6b35 !important; /* Laranja vibrante — Linha Soberana */
    font-weight: bold;
}

/* ============================================================
   MODAIS E COFRE SOBERANO
   ============================================================ */
.modal {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0, 0, 0, 0.85); backdrop-filter: blur(5px);
    display: none; justify-content: center; align-items: center; z-index: 9999;
}
.modal.active { display: flex; }

.modal-content {
    background: var(--bg-card); border: 1px solid var(--accent);
    border-radius: 10px; width: 90%; max-width: 800px;
    max-height: 90vh; /* Impede que o modal vaze da tela */
    display: flex; flex-direction: column;
    box-shadow: var(--shadow-glow);
}

.modal-header {
    padding: 20px; border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
    flex-shrink: 0;
}
.modal-header h2 { color: var(--accent); font-size: 1.3rem; }
.modal-close { background: none; border: none; color: #fff; font-size: 1.5rem; cursor: pointer; }
.modal-close:hover { color: var(--danger); }

.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; flex-shrink: 0;}

/* Animações e Scrollbars Específicas */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-darker); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary); }

/* ============================================================
   RESPONSIVIDADE (A Mágica para Celulares e Telas Menores)
   ============================================================ */

@media (max-width: 1024px) {
    /* Em telas médias, a área do chat dupla quebra para empilhar */
    div[style*="display: flex; gap: 20px;"] {
        flex-direction: column !important;
    }
    div[style*="flex: 0 0 70%;"] {
        flex: 1 1 100% !important;
    }
    div[style*="flex: 0 0 30%;"] {
        flex: 1 1 100% !important;
    }
}

@media (max-width: 768px) {
    /* No celular, a barra lateral vira um menu no topo */
    .container {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        height: auto;
        position: relative; /* Deixa de ser fixa */
        border-right: none;
        border-bottom: 2px solid var(--border);
    }
    
    .sidebar-nav {
        flex-direction: row;
        flex-wrap: wrap;
        padding: 10px;
    }
    
    .nav-item {
        flex: 1;
        min-width: 120px; /* Botões menores */
        padding: 10px;
        justify-content: center; /* Centraliza ícone e texto */
    }
    
    .main-content {
        padding: 15px; /* Menos margem no celular */
    }
    
    .dashboard-grid, .telemetry-grid, .memory-grid, .tools-grid {
        grid-template-columns: 1fr; /* 1 coluna só */
    }
    
    /* Protege o Chat no celular */
    .chat-container {
        height: 60vh; /* Ocupa 60% da tela do celular para sobrar espaço pra rolar a página toda */
    }
    
    .message-content {
        max-width: 90%; /* Balões de texto ocupam quase a largura toda */
    }
    
    .chat-input-area {
        flex-direction: column; /* Coloca os botões de voz e enviar em baixo do input */
    }
    
    .chat-input-area div[style*="flex-direction: column;"] {
        flex-direction: row !important; /* Coloca o Mic e Enviar lado a lado */
        width: 100%;
    }
}

/* ============================================================
   LOGIN MODAL SOBERANO (TALOS)
   ============================================================ */
#loginModal {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(5, 5, 5, 0.95);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
}

.login-box {
    background: rgba(0, 212, 255, 0.05);
    border: 1px solid var(--primary);
    padding: 50px;
    border-radius: 15px;
    text-align: center;
    box-shadow: 0 0 50px rgba(0, 212, 255, 0.15);
    width: 380px;
    max-width: 95vw;
}

.login-box h1 {
    color: var(--primary);
    letter-spacing: 5px;
    margin-bottom: 5px;
    font-size: 32px;
    text-shadow: 0 0 20px rgba(0, 212, 255, 0.5);
}

.login-box p {
    color: var(--text-secondary);
    font-size: 0.7rem;
    margin-bottom: 30px;
    text-transform: uppercase;
    letter-spacing: 2px;
}

#privateKeyInput {
    width: 100%;
    box-sizing: border-box;
    padding: 15px;
    background: #000;
    border: 1px solid #333;
    color: #fff;
    text-align: center;
    font-size: 1.2rem;
    border-radius: 5px;
    outline: none;
    margin-bottom: 20px;
    transition: all 0.3s ease;
    font-family: 'Courier New', monospace;
}

#privateKeyInput:focus {
    border-color: var(--primary);
    box-shadow: 0 0 15px rgba(0, 212, 255, 0.3);
}

.login-btn {
    width: 100%;
    padding: 15px;
    background: var(--primary);
    color: #000;
    font-weight: bold;
    letter-spacing: 2px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 14px;
    text-transform: uppercase;
}

.login-btn:hover {
    background: var(--accent);
    box-shadow: 0 0 20px rgba(0, 255, 65, 0.5);
    transform: scale(1.02);
}

#loginFeedback {
    margin-top: 20px;
    color: var(--danger);
    font-size: 0.85rem;
    min-height: 20px;
}

.login-footer {
    color: #444;
    margin-top: 30px;
    font-size: 0.7rem;
}


/* ============================================================
   STATUS BADGES E HEARTBEAT
   ============================================================ */
.status-badge {
    display: inline-block;
    font-size: 16px;
    transition: 0.3s;
}

.status-running {
    color: var(--accent);
    animation: pulse 1s infinite;
    text-shadow: 0 0 10px var(--accent);
}

.status-idle {
    color: #555;
    animation: none;
    filter: grayscale(1);
}

.status-error {
    color: var(--danger);
    animation: pulse 0.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.card-status {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 3px;
    font-weight: bold;
    background: rgba(0, 0, 0, 0.5);
    color: #555;
}

#heartbeat-dot {
    display: inline-block;
    width: 10px; height: 10px;
    border-radius: 50%;
    background: var(--accent);
    animation: pulse 1s infinite;
    box-shadow: 0 0 8px var(--accent);
    margin-right: 5px;
}

/* ============================================================
   FASE 4: FORJA DE MEMÓRIA — Ingestão Cognitiva + Explorador Soberano
   ============================================================ */

/* Botões especiais da aba Memória — override soberano */
#section-memory .btn-secondary,
.section-memory .btn-secondary {
    border-color: var(--primary);
    color: var(--primary);
    transition: var(--transition);
}

#section-memory .btn-secondary:hover,
.section-memory .btn-secondary:hover {
    background: rgba(0, 212, 255, 0.1);
    box-shadow: 0 0 10px rgba(0, 212, 255, 0.2);
}

/* Botão Explorador Soberano — destaque verde */
#section-memory .btn-secondary[onclick*="openFilesModal"],
.section-memory .btn-secondary[onclick*="openFilesModal"] {
    border-color: var(--accent);
    color: var(--accent);
}

#section-memory .btn-secondary[onclick*="openFilesModal"]:hover,
.section-memory .btn-secondary[onclick*="openFilesModal"]:hover {
    background: rgba(0, 255, 65, 0.1);
    box-shadow: 0 0 10px rgba(0, 255, 65, 0.2);
}

/* Campo de Ingestão Cognitiva */
#ingestText {
    width: 100%;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 12px;
    border-radius: 6px;
    font-family: inherit;
    resize: vertical;
    min-height: 80px;
    transition: var(--transition);
}

#ingestText:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 10px rgba(0, 255, 65, 0.1);
}

/* Barra de progresso da ingestão */
#ingest-progress {
    height: 4px;
    background: linear-gradient(90deg, var(--accent), var(--primary));
    border-radius: 2px;
    transition: width 0.5s ease;
    box-shadow: 0 0 8px rgba(0, 255, 65, 0.3);
}

/* Grid de artefatos no Explorador Soberano */
.artifacts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 10px;
    margin-top: 10px;
}

.artifact-card {
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    transition: var(--transition);
    cursor: pointer;
}

.artifact-card:hover {
    border-color: var(--primary);
    background: rgba(0, 212, 255, 0.05);
}

.artifact-name {
    font-size: 0.85rem;
    font-weight: bold;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.artifact-meta {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* ============================================================
   CHECKLIST DE CERTIFICAÇÃO CSS v9.5 — APROVADO
   1. [x] Rolagem Liberada: overflow-y: auto em html, body e sidebar
   2. [x] Glow da Soberania: .eco-motors-badge com glow-pulse 3s
   3. [x] Foco Visual: #btn-attach-vision + #chatInput alinhados
   4. [x] Grade de APIs: .api-grid com 10 cards responsivos
   ============================================================ */
