/* ============================================
   GraphRAG - Estilos principales
   ============================================ */

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

body {
    font-family: 'Segoe UI', 'Source Sans Pro', sans-serif;
    background-color: #0e1117;
    color: #fafafa;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ---------- Header ---------- */
header {
    background-color: #1a1f2e;
    padding: 1rem 2rem;
    border-bottom: 1px solid #2d3748;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

header h1 {
    font-size: 1.3rem;
    font-weight: 600;
}

nav {
    display: flex;
    gap: 0.5rem;
}

.tab-btn {
    background: transparent;
    border: 1px solid #4a5568;
    color: #a0aec0;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.tab-btn:hover {
    background-color: #2d3748;
    color: #fff;
}

.tab-btn.active {
    background-color: #ff4b4b;
    border-color: #ff4b4b;
    color: #fff;
}

/* ---------- Main ---------- */
main {
    flex: 1;
    padding: 1.5rem;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ---------- Grafo (Cytoscape) ---------- */
.graph-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    background-color: #1a1f2e;
    border-radius: 8px;
}

#graph-stats {
    color: #a0aec0;
    font-size: 0.9rem;
}

#btn-reload {
    background-color: #2d3748;
    color: #fff;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s;
}

#btn-reload:hover {
    background-color: #4a5568;
}

#cy {
    width: 100%;
    height: 600px;
    background-color: #1a1f2e;
    border-radius: 8px;
    border: 1px solid #2d3748;
    position: relative;
}

/* ---------- Búsqueda de ensayos ---------- */
.search-box {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

#search-input,
#paper-search-input {
    flex: 1;
    padding: 0.75rem 1rem;
    border-radius: 6px;
    border: 1px solid #4a5568;
    background-color: #1a1f2e;
    color: #fff;
    font-size: 1rem;
}

#search-input:focus,
#paper-search-input:focus {
    outline: none;
    border-color: #ff4b4b;
}

#btn-search,
#btn-paper-search {
    background-color: #ff4b4b;
    color: #fff;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
}

#btn-search:hover,
#btn-paper-search:hover {
    background-color: #e63e3e;
}

#trials-results,
#paper-search-results {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.trial-card {
    background-color: #1a1f2e;
    border: 1px solid #2d3748;
    border-radius: 8px;
    padding: 1rem;
    transition: border-color 0.2s;
}

.trial-card:hover {
    border-color: #ff4b4b;
}

.trial-card h3 {
    color: #fff;
    margin-bottom: 0.5rem;
    font-size: 1rem;
}

.trial-card .nct-id {
    color: #ff4b4b;
    font-weight: 600;
    font-size: 0.85rem;
}

.trial-card .status {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 4px;
    font-size: 0.75rem;
    margin-left: 0.5rem;
}

.status-RECRUITING { background-color: #22543d; color: #68d391; }
.status-COMPLETED { background-color: #2a4365; color: #63b3ed; }
.status-TERMINATED { background-color: #742a2a; color: #fc8181; }
.status-ACTIVE_NOT_RECRUITING { background-color: #744210; color: #f6ad55; }

/* ---------- Chat RAG: Layout de dos columnas ---------- */
.chat-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    height: calc(100vh - 180px);
    min-height: 500px;
}

@media (max-width: 1000px) {
    .chat-layout {
        grid-template-columns: 1fr;
        height: auto;
    }
}

/* Columna izquierda: Chat */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background-color: #1a1f2e;
    border-radius: 8px;
    border: 1px solid #2d3748;
    margin-bottom: 1rem;
    min-height: 200px;
}

.chat-message {
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    max-width: 80%;
}

.chat-message.user {
    background-color: #2d3748;
    margin-left: auto;
    text-align: right;
}

.chat-message.assistant {
    background-color: #1f2937;
    border-left: 3px solid #ff4b4b;
}

.chat-input {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

#chat-question {
    flex: 1;
    padding: 0.75rem 1rem;
    border-radius: 6px;
    border: 1px solid #4a5568;
    background-color: #1a1f2e;
    color: #fff;
    font-size: 1rem;
}

#btn-ask {
    background-color: #ff4b4b;
    color: #fff;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
}

#btn-ask:hover {
    background-color: #e63e3e;
}

.chat-examples {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.examples-label {
    color: #a0aec0;
    font-size: 0.85rem;
}

.example-btn {
    background-color: #1f2937;
    border: 1px solid #4a5568;
    color: #a0aec0;
    padding: 0.4rem 0.8rem;
    border-radius: 16px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s;
}

.example-btn:hover {
    border-color: #ff4b4b;
    color: #fff;
}

/* Columna derecha: Grafo contextual */
.chat-graph-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

.chat-graph-container .graph-controls {
    margin-bottom: 0.75rem;
    padding: 0.6rem 1rem;
    background-color: #1a1f2e;
    border-radius: 8px;
    border: 1px solid #2d3748;
}

#cy-chat {
    flex: 1;
    min-height: 400px;
    background-color: #1a1f2e;
    border-radius: 8px;
    border: 1px solid #2d3748;
    width: 100%;
}

/* ---------- Layout de Ensayos y Papers (dos paneles) ---------- */
.trials-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

@media (max-width: 900px) {
    .trials-layout {
        grid-template-columns: 1fr;
    }
}

.panel {
    background-color: #161b26;
    border: 1px solid #2d3748;
    border-radius: 8px;
    padding: 1.25rem;
}

.panel h2 {
    font-size: 1.1rem;
    margin-bottom: 0.25rem;
}

.panel-subtitle {
    color: #718096;
    font-size: 0.8rem;
    margin-bottom: 1rem;
}

/* ---------- Acciones de importación ---------- */
.import-actions {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.btn-primary {
    background-color: #2f855a;
    color: #fff;
    border: none;
    padding: 0.6rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
}

.btn-primary:hover:not(:disabled) {
    background-color: #38a169;
}

.btn-primary:disabled {
    background-color: #2d3748;
    color: #718096;
    cursor: not-allowed;
}

.btn-danger {
    background-color: transparent;
    color: #fc8181;
    border: 1px solid #742a2a;
    padding: 0.6rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
}

.btn-danger:hover {
    background-color: #742a2a;
    color: #fff;
}

/* ---------- Progreso de importación ---------- */
.progress-box {
    margin-bottom: 1rem;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background-color: #2d3748;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background-color: #ff4b4b;
    transition: width 0.3s ease;
}

#progress-text {
    color: #a0aec0;
    font-size: 0.85rem;
}

/* ---------- Checkbox de selección en tarjetas ---------- */
.trial-card label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    color: #a0aec0;
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
}

.trial-card input[type="checkbox"] {
    accent-color: #ff4b4b;
    width: 16px;
    height: 16px;
    cursor: pointer;
}

/* ---------- Lista de importados ---------- */
.imported-card {
    background-color: #1a1f2e;
    border: 1px solid #2d3748;
    border-radius: 8px;
    padding: 0.75rem 1rem;
    margin-bottom: 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
}

.imported-card .nct-id {
    color: #ff4b4b;
    font-weight: 600;
    font-size: 0.85rem;
    display: block;
}

.imported-card .trial-title {
    color: #cbd5e0;
    font-size: 0.8rem;
    display: block;
    margin-top: 0.2rem;
}

.imported-card .badge-demo {
    background-color: #2a4365;
    color: #63b3ed;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.7rem;
    white-space: nowrap;
}

.btn-delete {
    background-color: transparent;
    color: #fc8181;
    border: 1px solid #742a2a;
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.75rem;
    white-space: nowrap;
}

.btn-delete:hover {
    background-color: #742a2a;
    color: #fff;
}

/* ---------- Scroll en paneles ---------- */
#trials-results,
#imported-list,
#paper-search-results,
#imported-papers-list {
    max-height: 65vh;
    overflow-y: auto;
    padding-right: 0.5rem;
}

#trials-results::-webkit-scrollbar,
#imported-list::-webkit-scrollbar,
#paper-search-results::-webkit-scrollbar,
#imported-papers-list::-webkit-scrollbar {
    width: 8px;
}

#trials-results::-webkit-scrollbar-track,
#imported-list::-webkit-scrollbar-track,
#paper-search-results::-webkit-scrollbar-track,
#imported-papers-list::-webkit-scrollbar-track {
    background: #1a1f2e;
}

#trials-results::-webkit-scrollbar-thumb,
#imported-list::-webkit-scrollbar-thumb,
#paper-search-results::-webkit-scrollbar-thumb,
#imported-papers-list::-webkit-scrollbar-thumb {
    background: #4a5568;
    border-radius: 4px;
}

#trials-results::-webkit-scrollbar-thumb:hover,
#imported-list::-webkit-scrollbar-thumb:hover,
#paper-search-results::-webkit-scrollbar-thumb:hover,
#imported-papers-list::-webkit-scrollbar-thumb:hover {
    background: #ff4b4b;
}

/* ---------- Panel flotante de detalles del nodo ---------- */
.node-details-panel {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 320px;
    background-color: #1a1f2e;
    border: 1px solid #2d3748;
    border-left: 4px solid #8e44ad;
    border-radius: 8px;
    padding: 1rem 1.25rem;
    z-index: 100;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
    animation: slideIn 0.2s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.close-details-btn {
    position: absolute;
    top: 8px;
    right: 10px;
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: #a0aec0;
    line-height: 1;
    padding: 0;
    width: 28px;
    height: 28px;
    border-radius: 4px;
    transition: all 0.2s;
}

.close-details-btn:hover {
    background-color: #742a2a;
    color: #fff;
}

#node-details-content h3 {
    margin-top: 0;
    margin-bottom: 0.75rem;
    color: #fff;
    font-size: 1rem;
    padding-right: 20px;
}

#node-details-content p {
    font-size: 0.85rem;
    color: #cbd5e0;
    margin: 0.4rem 0;
    line-height: 1.4;
}

#node-details-content p strong {
    color: #a0aec0;
    font-weight: 600;
}

#node-details-content em {
    color: #e2e8f0;
    font-style: italic;
    font-size: 0.82rem;
    line-height: 1.3;
}

.pubmed-link {
    display: inline-block;
    margin-top: 0.75rem;
    padding: 0.5rem 1rem;
    background-color: #8e44ad;
    color: white;
    text-decoration: none;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    transition: background-color 0.2s;
}

.pubmed-link:hover {
    background-color: #6c3483;
    color: #fff;
}

/* ---------- Utilidades ---------- */
.loading {
    text-align: center;
    color: #a0aec0;
    padding: 2rem;
}

.error {
    color: #fc8181;
    padding: 1rem;
    background-color: #742a2a;
    border-radius: 6px;
}

.success {
    color: #68d391;
    padding: 1rem;
    background-color: #22543d;
    border-radius: 6px;
}