:root {
    /* Paleta Oscura */
    --primary: #8B5CF6; /* Morado de tus referencias */
    --primary-hover: #7C3AED;
    --dark: #0F172A; /* Fondo base muy oscuro */
    --bg: #0F172A;
    --bg-card: rgba(30, 41, 59, 0.7); /* Cristal semitransparente */
    --text: #F1F5F9; /* Texto claro */
    --text-muted: #94A3B8;
    --border: rgba(255, 255, 255, 0.1); /* Bordes sutiles de cristal */
    --success: #10B981;
    --error: #EF4444;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    
    /* Degradado Personalizado (Amarillo -> Naranja -> Rojo) */
    --gradient-brand: linear-gradient(90deg, #FBBF24, #F97316, #EF4444);
}
* { box-sizing: border-box; margin: 0; padding: 0; font-family: -apple-system, sans-serif; }
body { background-color: var(--bg); color: var(--text); }

[x-cloak] { display: none !important; }

/* Header */

.header-brand { display: flex; align-items: center; gap: 12px; }
.logo { 
    width: 40px; 
    height: 40px; 
    object-fit: contain; 
    background: var(--bg); 
    border-radius: 8px; 
    padding: 2px;
}
.brand-text h1 { font-size: 18px; color: var(--dark); font-weight: 700; line-height: 1; }
.header-subtitle { font-size: 11px; color: var(--text-muted); }
.header-status { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 600; color: var(--text-muted); }
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--text-muted); }
.status-connected { background: var(--success); }

/* Layout */


.nav-link { display: flex; align-items: center; gap: 12px; padding: 10px 12px; color: var(--text-muted); text-decoration: none; border-radius: 6px; font-weight: 600; cursor: pointer; transition: 0.2s; }
.nav-link:hover { background: var(--bg); color: var(--dark); }
.nav-link.active { 
    background: rgba(139, 92, 246, 0.15); /* Fondo morado muy sutil */
    color: var(--primary); 
    border-left: 4px solid; 
    border-image: var(--gradient-brand) 1; /* Borde degradado */
    border-radius: 0 6px 6px 0;
}
.nav-link svg { width: 18px; height: 18px; }

.main:has(.vista[x-show="vista === 'chat'"]) { overflow: hidden; }
.vista[x-show="vista === 'chat'"] { height: 100%; display: flex; flex-direction: column; overflow: hidden; }
#chat-messages { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
#chat-messages::-webkit-scrollbar { width: 6px; }
#chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.vista h2 { font-size: 22px; margin-bottom: 24px; color: var(--dark); }
.muted { color: var(--text-muted); }

/* Cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; margin-bottom: 32px; }
.card { 
    background: var(--bg-card); 
    backdrop-filter: blur(12px); 
    -webkit-backdrop-filter: blur(12px); 
    border: 1px solid var(--border); 
    border-radius: 12px; 
    padding: 20px; 
    box-shadow: var(--shadow); 
}
.card-title { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; }
.card-value { font-size: 36px; font-weight: 700; color: var(--primary); line-height: 1; }

/* Charts */
.chart-container { background: var(--bg-card); padding: 20px; border-radius: 12px; border: 1px solid var(--border); height: 300px; box-shadow: var(--shadow); }

/* Formularios */
.vista-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.btn { padding: 8px 16px; border-radius: 6px; border: none; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.btn-primary { 
    background: var(--primary); 
    color: white; 
    box-shadow: 0 0 10px rgba(139, 92, 246, 0.4); /* Resplandor morado */
    border: none;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: #FEE2E2; color: var(--error); }
.form-card { background: var(--bg-card); border: 1px solid var(--border); padding: 20px; border-radius: 8px; margin-bottom: 24px; box-shadow: var(--shadow); }
.form-card h3 { margin-bottom: 16px; font-size: 16px; }
.form-card input, .form-card select { width: 100%; padding: 10px; border: 1px solid var(--border); border-radius: 6px; margin-bottom: 12px; font-size: 14px; }
.form-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 8px; }
.form-actions button { padding: 8px 16px; border-radius: 6px; border: none; font-weight: 600; cursor: pointer; }

/* Tablas */
.table { width: 100%; border-collapse: collapse; background: var(--bg-card); border-radius: 8px; overflow: hidden; border: 1px solid var(--border); }
.table th { background: var(--bg); padding: 12px; text-align: left; font-size: 12px; color: var(--text-muted); text-transform: uppercase; border-bottom: 1px solid var(--border); }
.table td { padding: 12px; border-bottom: 1px solid var(--border); font-weight: 500; }
.badge { padding: 4px 8px; border-radius: 4px; font-size: 11px; font-weight: 700; background: var(--bg); color: var(--text-muted); }
.badge-success { background: #D1FAE5; color: var(--success); }

/* Toasts */
.toasts { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 8px; z-index: 1000; }
.toast { background: var(--bg-card); border-left: 4px solid var(--primary); padding: 12px 16px; border-radius: 6px; box-shadow: 0 4px 12px rgba(0,0,0,0.15); animation: slideIn 0.3s; min-width: 280px; }
.toast-title { font-weight: 600; margin-bottom: 4px; }
.toast-message { font-size: 13px; color: var(--text-muted); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Busqueda Semantica */
.search-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
}
.search-bar select {
    width: 200px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
}
.search-bar input {
    flex: 1;
    padding: 10px 16px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 15px;
}
.search-bar input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 102, 255, 0.1);
}

.results-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 16px;
    font-weight: 600;
    color: var(--dark);
    border-bottom: 2px solid var(--border);
    padding-bottom: 8px;
}

.result-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-left: 4px solid var(--primary);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: var(--shadow);
}

.result-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
}

.score-badge {
    background: #D1FAE5;
    color: #10B981;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 700;
}

.result-type {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-muted);
    background: var(--bg);
    padding: 2px 8px;
    border-radius: 4px;
}

.result-path {
    font-family: monospace;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 8px;
    word-break: break-all;
}

.result-snippet {
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    background: #F8FAFC;
    padding: 12px;
    border-radius: 6px;
    border: 1px solid var(--border);
}

/* Ajustes */
.setting-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    font-weight: 600;
}
.setting-row input[type="range"] {
    flex: 1;
    cursor: pointer;
}
.setting-row input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
}

/* Chat Interno */
.chat-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    max-height: 60vh;
}
.chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #F8FAFC;
}
.chat-bubble {
    max-width: 70%;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 14px;
    line-height: 1.4;
}
.chat-bubble.received {
    background: var(--bg-card);
    border: 1px solid var(--border);
    align-self: flex-start;
    border-bottom-left-radius: 0;
}
.chat-bubble.sent {
    background: var(--primary);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 0;
}
.chat-meta {
    font-size: 10px;
    color: var(--text-muted);
    margin-bottom: 2px;
}
.chat-bubble.sent .chat-meta { color: rgba(255,255,255,0.8); }
.chat-input-area {
    display: flex;
    padding: 12px;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    gap: 12px;
}
.chat-input-area input {
    flex: 1;
    padding: 10px 16px;
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 14px;
}
.chat-input-area input:focus {
    outline: none;
    border-color: var(--primary);
}

/* Acciones de resultados */
.result-actions {
    margin-top: 12px;
    display: flex;
    gap: 8px;
    border-top: 1px solid var(--border);
    padding-top: 12px;
}
.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 4px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.btn-sm:hover {
    background: #E2E8F0;
}
.btn-sm.btn-primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}
.btn-sm.btn-primary:hover {
    background: var(--primary-hover);
}
.btn-sm svg {
    width: 14px;
    height: 14px;
}

/* Botones dentro del chat de la IA */
.chat-bubble .btn-sm {
    background: white;
    border: 1px solid var(--border);
    color: var(--text);
    padding: 4px 8px;
    font-size: 11px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    border-radius: 4px;
    cursor: pointer;
    transition: 0.2s;
}
.chat-bubble .btn-sm:hover {
    background: #F1F5F9;
}
.chat-bubble .btn-sm.btn-primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}
.chat-bubble .btn-sm.btn-primary:hover {
    background: var(--primary-hover);
}

/* Asegurar que el texto del chat se puede seleccionar con el ratón */
.chat-bubble {
    user-select: text !important;
    -webkit-user-select: text !important;
}

/* Arreglo para iconos SVG en botones */
.btn svg, .nav-link svg { width: 16px; height: 16px; }

.majom-logo-sidebar {
    width: 32px;
    height: 32px;
    object-fit: contain;
    margin-right: 12px;
    vertical-align: middle;
}

@keyframes latido-majom {
    0% { transform: scale(1); opacity: 0.8; }
    50% { transform: scale(1.15); opacity: 1; }
    100% { transform: scale(1); opacity: 0.8; }
}

.majom-watermark {
    position: relative;
    overflow: hidden;
}
.majom-watermark::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 300px;
    height: 300px;
    background-image: url('/static/majom_logo.png');
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    opacity: 0.04;
    pointer-events: none;
    z-index: 0;
}
.majom-watermark > * {
    position: relative;
    z-index: 1;
}

/* Forzar color azul y estilo del texto MAJOM en el sidebar */
.sidebar-header h1, 
.sidebar-brand h1, 
.logo h1 {
    color: #0066FF !important;
    font-weight: 800 !important;
    letter-spacing: -0.5px;
}

/* Cabecera principal */
.header-brand {
    display: flex;
    align-items: center;
    gap: 16px;
}

.majom-logo-principal {
    width: 95px;
    height: 95px;
    object-fit: contain;
    margin-top: -18px;
    margin-bottom: -18px;
}

.brand-text {
    display: flex;
    flex-direction: column;
}

.brand-title {
    color: #0066FF !important; /* Azul MAJOM */
    font-weight: 900 !important;
    font-size: 26px !important;
    letter-spacing: -0.5px;
    margin: 0 !important;
    line-height: 1.1;
}

.header-subtitle {
    color: var(--text-muted);
    font-size: 12px;
    margin-top: 2px;
}


/* Burbuja de IA de MAJOM */
.majom-ia-bubble {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 18px;
    background: var(--bg-card, #ffffff);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    margin-bottom: 16px;
    width: fit-content;
    animation: aparecer-burbuja 0.3s ease-out;
}

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

.majom-ia-avatar {
    width: 48px;
    height: 48px;
    object-fit: contain;
    animation: majom-vivo 2s infinite ease-in-out;
    filter: drop-shadow(0px 4px 8px rgba(0, 102, 255, 0.4));
}

@keyframes majom-vivo {
    0% { transform: translateY(0) scale(1) rotate(0deg); }
    25% { transform: translateY(-8px) scale(1.05) rotate(3deg); }
    50% { transform: translateY(-12px) scale(1.1) rotate(-3deg); }
    75% { transform: translateY(-4px) scale(1.05) rotate(2deg); }
    100% { transform: translateY(0) scale(1) rotate(0deg); }
}



.vista { min-height: min-content; }




.header { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    padding: 12px 24px; 
    background: rgba(15, 23, 42, 0.8); 
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border); 
    z-index: 10; 
    flex-shrink: 0; 
    position: relative;
}

/* La línea mágica Amarillo -> Naranja -> Rojo en la parte superior */
.header::before {
    content: "";
    display: none;
}





.sidebar { 
    width: 240px; 
    background: rgba(15, 23, 42, 0.8); 
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-right: 1px solid var(--border); 
    padding: 16px; 
    display: flex; 
    flex-direction: column; 
    gap: 4px; 
    overflow-y: auto; /* Si el menú tiene muchas opciones, que también scrollee */
    flex-shrink: 0;
}

/* FORZAR SCROLL EN PYWEBVIEW */
body {
    margin: 0;
    padding: 0;
    height: 100vh; /* Usar vh en lugar de % */
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg);
}

.layout {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.main {
    flex: 1;
    padding: 32px;
    padding-bottom: 100px;
    overflow-y: scroll !important; /* FORZAR SCROLL */
    -webkit-overflow-scrolling: touch; /* Arreglo para Mac */
    min-height: 0;
}

/* ==========================================
   ESTILOS DEL NAVEGADOR EMBEBIDO
   ========================================== */
.navegador-vista {
    display: flex;
    flex-direction: column;
    /* Calculamos el alto: 100% de la pantalla menos la cabecera y los paddings */
    height: calc(100vh - 180px) !important; 
    min-height: 500px;
    overflow: hidden;
}

.navegador-container {
    flex: 1;
    padding: 0;
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
    background: white;
}

.navegador-iframe {
    width: 100%;
    height: 100%;
    border: none;
    flex: 1;
}

/* Puntero y selección morado clarito MAJOM */
* { caret-color: #C4B5FD; }
::selection { background: rgba(167, 139, 250, 0.35); color: #F8FAFC; }
