/* =========================================================
   SIRIUSX QUANT - HOJA DE ESTILOS BLINDADA (v3.1.0)
   ========================================================= */

/* --- 1. VARIABLES GLOBALES --- */
:root {
    --bg-base: #0f172a;
    --bg-panel: #1e293b;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --accent: #10b981;
    --accent-hover: #059669;
    --border: #334155;
    --danger: #ef4444;
}

[data-theme="light"] {
    --bg-base: #f1f5f9;
    --bg-panel: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border: #cbd5e1;
}

/* --- 2. BASE, RESET Y SCROLLBARS TÁCTICOS --- */
* { 
    box-sizing: border-box; 
    margin: 0; 
    padding: 0; 
    font-family: 'Segoe UI', system-ui, sans-serif; 
}

body { 
    background: var(--bg-base); 
    color: var(--text-main); 
    display: flex; 
    height: 100vh; 
    overflow: hidden; 
    transition: background 0.3s; 
    font-size: 16px;
}

/* 🚀 NUEVO: Scrollbars oscuros de grado militar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-base); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* --- 3. ESTRUCTURA PRINCIPAL (LAYOUT) --- */
#app-container { display: flex; width: 100%; height: 100%; }
#main-content { flex: 1; padding: 20px; overflow-y: auto; position: relative; }

/* --- 4. BARRA DE NAVEGACIÓN --- */
#nav-bar {
    width: 250px;
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 20px 0;
    transition: all 0.3s;
    z-index: 100;
}

.nav-header { 
    padding: 0 20px 20px; 
    font-weight: bold; 
    font-size: 1.2rem; 
    border-bottom: 1px solid var(--border); 
    margin-bottom: 10px; 
    display: flex; 
    justify-content: space-between; 
    align-items: center;
}

.nav-item {
    padding: 15px 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 15px;
    color: var(--text-muted);
    transition: 0.2s;
}

.nav-item:hover, .nav-item.active { 
    background: rgba(16, 185, 129, 0.1); 
    color: var(--accent); 
    border-right: 4px solid var(--accent); 
}
.nav-item i { width: 20px; text-align: center; }

/* --- 5. VISTAS Y LOGIN --- */
.view { display: none; animation: fadeIn 0.3s ease-out; }
.view.active { display: block; }
@keyframes fadeIn { 
    from { opacity: 0; transform: translateY(10px); } 
    to { opacity: 1; transform: translateY(0); } 
}
.theme-toggle { cursor: pointer; padding: 5px; }

.login-overlay { 
    position: fixed; inset: 0; background: var(--bg-base); z-index: 999; 
    display: flex; flex-direction: column; align-items: center; justify-content: center; 
}
#totp-input { width: 100%; max-width: 280px; font-size: 2em; letter-spacing: 15px; }

/* --- 6. COMPONENTES GLOBALES (TARJETAS, KPIS, TABLAS) --- */
.panel-card { 
    background: var(--bg-panel); border: 1px solid var(--border); 
    border-radius: 10px; padding: 20px; margin-bottom: 20px; 
}

.kpi-grid { 
    display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); 
    gap: 15px; margin-bottom: 20px; 
}
.kpi-box { 
    background: var(--bg-panel); border: 1px solid var(--border); 
    border-radius: 8px; padding: 15px 10px; text-align: center; 
    container-type: inline-size; overflow: hidden; 
}
.kpi-valor { 
    font-weight: bold; margin-top: 5px; color: var(--accent); 
    font-size: min(1.5rem, 14cqi); white-space: nowrap;
}

.table-responsive {
    width: 100%; 
    margin-bottom: 15px; 
    box-shadow: 0 4px 6px rgba(0,0,0,0.1); 
    border-radius: 8px;
}
.data-table { 
    width: 100%; 
    border-collapse: collapse; 
    text-align: left; 
}
.data-table th, .data-table td { 
    padding: 10px; 
    border-bottom: 1px solid var(--border); 
}
.data-table th { 
    color: var(--text-muted); 
    font-size: 0.85rem; 
    text-transform: uppercase; 
}

/* --- 7. CENTRO DE MANDO (AJUSTES) --- */
.setting-row { display: flex; justify-content: space-between; align-items: center; padding: 15px 0; border-bottom: 1px solid var(--border); }
.setting-row:last-child { border-bottom: none; }
.setting-info h4 { margin-bottom: 5px; color: var(--text-main); font-size: 1rem; }
.setting-info p { font-size: 0.85rem; color: var(--text-muted); }

.switch { position: relative; display: inline-block; width: 46px; height: 24px; flex-shrink: 0;}
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: var(--border); transition: .3s; border-radius: 24px; }
.slider:before { position: absolute; content: ""; height: 16px; width: 16px; left: 4px; bottom: 4px; background-color: white; transition: .3s; border-radius: 50%; }
input:checked + .slider { background-color: var(--accent); }
input:checked + .slider:before { transform: translateX(22px); }

.setting-input {
    width: 100%; padding: 10px 12px; background: #0f172a; border: 1px solid var(--border);
    color: var(--accent); border-radius: 6px; margin-top: 8px; font-family: monospace;
    font-size: 0.95rem; transition: 0.3s;
}
.setting-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 5px rgba(16, 185, 129, 0.3); }

.market-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.market-pill { padding: 6px 12px; border-radius: 20px; font-size: 0.85rem; font-weight: bold; cursor: pointer; transition: 0.2s; user-select: none; border: 1px solid var(--border); }
.market-pill.active { background: rgba(16, 185, 129, 0.2); color: var(--accent); border-color: var(--accent); }
.market-pill.excluded { background: rgba(239, 68, 68, 0.2); color: var(--danger); border-color: var(--danger); }
.market-pill.warning { background: rgba(245, 158, 11, 0.2); color: #f59e0b; border-color: #f59e0b; }
.market-pill.neutral { background: rgba(148, 163, 184, 0.2); color: #94a3b8; border-color: #334155; }

.min-op-container { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 15px; margin-top: 10px; }
.min-op-row { display: flex; align-items: center; background: var(--bg-base); padding: 8px; border-radius: 6px; border: 1px solid var(--border); }
.min-op-row span.coin-label { font-weight: bold; width: 50px; color: var(--text-main); }
.min-op-row input { width: 95px; background: transparent; border: none; border-bottom: 1px solid var(--border); color: var(--accent); font-weight: bold; text-align: center; margin: 0 10px; outline: none; -moz-appearance: textfield; }
.min-op-row input::-webkit-outer-spin-button, .min-op-row input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* --- 8. ACORDEONES (COLLAPSIBLES) --- */
.cmd-accordion { background: var(--bg-panel); border: 1px solid var(--border); border-radius: 10px; margin-bottom: 15px; overflow: hidden; transition: 0.3s ease; }
.cmd-accordion summary { padding: 15px 20px; font-size: 1.05rem; font-weight: bold; color: var(--text-main); cursor: pointer; display: flex; align-items: center; justify-content: space-between; list-style: none; user-select: none; background: rgba(255, 255, 255, 0.02); }
.cmd-accordion summary::-webkit-details-marker { display: none; }
.cmd-accordion summary .arrow { transition: transform 0.3s ease; color: var(--accent); }
.cmd-accordion[open] summary .arrow { transform: rotate(180deg); }
.cmd-accordion[open] summary { border-bottom: 1px solid var(--border); }
.accordion-content { padding: 20px; background: var(--bg-base); }
.btn-save-settings { width: 100%; padding: 15px; background: var(--border); color: white; border: none; border-radius: 8px; cursor: pointer; font-weight: bold; font-size: 1.05rem; transition: 0.3s; margin-top: 10px; }
.btn-save-settings:hover { background: var(--accent); box-shadow: 0 0 10px rgba(16, 185, 129, 0.4); }

/* --- 9. MÓDULOS TÁCTICOS Y RADARES --- */
.audit-bar-pulse { animation: auditPulse 0.8s infinite alternate; }
@keyframes auditPulse { 0% { filter: brightness(0.8); opacity: 0.8; } 100% { filter: brightness(1.3); opacity: 1; } }
.led-dot:last-child { border-right: none; }
.led-dot.excluded { background-color: #334155; opacity: 0.5; }
.led-dot.pending { background-color: transparent; }
.led-dot.scanned { background-color: #10b981; box-shadow: inset 0 0 6px rgba(255, 255, 255, 0.3); opacity: 1; }
.led-dot.audit-pending { background-color: transparent; }
.led-dot.audit-active { background-color: #d946ef; box-shadow: inset 0 0 8px rgba(255, 255, 255, 0.5); animation: pulseHealth 0.8s infinite alternate; opacity: 1; }

#audit-eval-result table { width: 100%; border-collapse: collapse; margin: 15px 0; font-size: 0.85rem; text-align: left; }
#audit-eval-result th { background-color: rgba(59, 130, 246, 0.2); color: #38bdf8; padding: 10px; border: 1px solid #1e3a8a; }
#audit-eval-result td { padding: 8px 10px; border: 1px solid var(--border); color: var(--text-main); }
#audit-eval-result tr:nth-child(even) { background-color: rgba(255, 255, 255, 0.02); }

.tactical-card { background: rgba(15, 23, 42, 0.8); border: 1px solid #334155; border-radius: 8px; padding: 15px; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5); transition: transform 0.2s, border-color 0.2s; position: relative; overflow: hidden; }
.tactical-card:hover { transform: translateY(-2px); border-color: #38bdf8; }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; border-bottom: 1px solid rgba(255,255,255,0.1); padding-bottom: 8px; }
.coin-title { font-size: 1.2rem; font-weight: 900; color: #f8fafc; letter-spacing: 1px; }
.status-badge { font-size: 0.7rem; padding: 3px 6px; border-radius: 4px; font-weight: bold; text-transform: uppercase; }
.badge-free { background: rgba(16, 185, 129, 0.1); color: #10b981; border: 1px solid #10b981; }
.badge-hold { background: rgba(239, 68, 68, 0.1); color: #ef4444; border: 1px solid #ef4444; }
.data-row { display: flex; justify-content: space-between; font-size: 0.85rem; margin-bottom: 5px; }
.data-label { color: #94a3b8; }
.data-value { font-weight: bold; color: #e2e8f0; font-family: monospace; }
.profit-green { color: #10b981 !important; }
.loss-red { color: #ef4444 !important; }

/* --- 10. MANUAL TÁCTICO (MARKDOWN & MERMAID) --- */

/* 🚀 BLOQUEO DE CONTENEDOR PADRE */
#manual-content { 
    width: 100% !important;
    max-width: calc(100vw - 300px); /* Restamos el ancho del nav-bar (250px) + padding */
    overflow-x: hidden !important; 
    display: block;
}

#manual-content h1, #manual-content h2, #manual-content h3 { 
    color: #a855f7; margin-top: 1.5em; margin-bottom: 0.5em; 
    border-bottom: 1px solid rgba(168, 85, 247, 0.3); padding-bottom: 5px; 
}
#manual-content ul, #manual-content ol { margin-left: 20px; margin-bottom: 15px; color: var(--text-muted); }
#manual-content li { margin-bottom: 5px; }
#manual-content p { margin-bottom: 15px; }

/* 📊 TABLAS MARKDOWN (ANCLAJE DE TITANIO ESTRICTO) */
#manual-content table { 
    width: 100% !important; 
    max-width: 100% !important;
    border-collapse: collapse; 
    margin: 20px 0; 
    display: table !important; 
    table-layout: fixed !important; /* Fuerza a la tabla a medir exactamente el ancho del contenedor */
}

/* 📊 TABLAS MARKDOWN (AJUSTE DE PALABRA ÍNTEGRA) */
#manual-content th, 
#manual-content td { 
    padding: 12px 10px; 
    border: 1px solid var(--border); 
    text-align: left;
    
    /* 🚀 LA REPARACIÓN: */
    white-space: normal !important; /* Permite múltiples líneas */
    word-break: normal !important;  /* ❌ DESACTIVADA LA MOTOSIERRA: No corta palabras */
    overflow-wrap: break-word !important; /* 🟢 SOLO rompe si la palabra es más larga que toda la columna */
    hyphens: none !important; /* Evita guiones de ruptura */
}

#manual-content th { 
    background-color: rgba(168, 85, 247, 0.15); 
    color: #d946ef; 
}

#manual-content td { 
    color: var(--text-main); 
}

#manual-content tr:nth-child(even) { 
    background-color: rgba(255, 255, 255, 0.03); 
}

#manual-content blockquote { border-left: 4px solid #38bdf8; background: rgba(56, 189, 248, 0.1); margin: 15px 0; padding: 10px 15px; border-radius: 0 4px 4px 0; }
#manual-content pre { background: #0f172a; padding: 15px; border-radius: 6px; overflow-x: auto; border: 1px solid #334155; margin-bottom: 15px; }

/* 🔀 MERMAID: RESTRICCIÓN VECTORIAL ESTRICTA */
.mermaid { 
    background-color: #f1f5f9 !important; 
    padding: 15px !important;
    margin: 20px auto !important;
    border-radius: 6px;
    border: 1px solid #cbd5e1;
    display: flex;
    justify-content: center;
    overflow-x: auto;
    overflow-y: hidden;
}

.mermaid svg { 
    max-height: 450px !important; 
    width: auto !important;
    max-width: 100% !important;
    height: auto !important; 
}

.mermaid .edgeLabel text, 
.mermaid .nodeLabel, 
.mermaid text {
    fill: #0f172a !important; 
    font-weight: bold;
    font-size: 0.95rem !important; 
    font-family: 'Segoe UI', system-ui, sans-serif !important; 
}

/* =========================================================
   11. MEDIA QUERIES (¡SIEMPRE AL FINAL!)
   ========================================================= */
@media screen and (max-width: 768px) {
    #app-container { flex-direction: column; }
    #main-content { padding-bottom: 80px; } 
    #nav-bar { position: fixed; bottom: 0; width: 100%; height: 70px; border-right: none; border-top: 1px solid var(--border); flex-direction: row; padding: 0; justify-content: space-around; z-index: 1000; }
    .nav-header { display: none; }
    .nav-item { flex-direction: column; padding: 10px 5px; gap: 5px; font-size: 0.75rem; border-right: none; flex: 1; text-align: center; }
    .nav-item.active { border-right: none; border-top: 3px solid var(--accent); background: none; }
}

@media screen and (max-width: 600px) {
    .led-matrix { height: 12px; }
}

@media screen and (max-width: 430px) {
    body { font-size: 14px; }
    .panel-card { padding: 12px; margin-bottom: 12px; border-radius: 8px; }
    .panel-card h3 { font-size: 0.9rem; }
    #saldo-clp { font-size: 0.85rem; padding: 4px 8px; }
    .kpi-grid { gap: 8px; margin-bottom: 15px; }
    .kpi-box { padding: 10px 5px; }
    .kpi-valor { font-size: 1.1rem; }
    .kpi-box div:first-child { font-size: 0.65rem; letter-spacing: 0; }
    .data-table { min-width: auto; }
    .data-table th, .data-table td { padding: 8px 4px; font-size: 0.75rem; }
    #chart-ppp { height: 200px; }
    .login-overlay h2 { font-size: 1.2rem; }
    #nav-btn-manual { display: none !important; }
}