/**
 * TVB-O Knowledge Graph Browser Styles
 */

/* Global utility class */
.hidden {
    display: none !important;
}

/* Container - natural flow, scrollable page */
.tvbo-kg-container {
    min-height: 80vh;
    background: #f8f9fa;
}

/* In-page hero search bar */
.tvbo-kg-container .kg-hero {
    background: linear-gradient(135deg, #2C3E50 0%, #3498DB 100%);
    padding: 36px 20px 28px;
    color: #fff;
    border-bottom: 1px solid #e2e8f0;
}

.tvbo-kg-container .kg-hero-inner {
    max-width: 900px;
    margin: 0 auto;
    text-align: center;
}

.tvbo-kg-container .kg-hero-title {
    font-size: 1.8rem;
    font-weight: 700;
    margin: 0 0 6px;
    color: #fff;
}

.tvbo-kg-container .kg-hero-subtitle {
    font-size: 0.95rem;
    margin: 0 0 18px;
    color: rgba(255, 255, 255, 0.85);
}

.tvbo-kg-container .kg-hero-search {
    position: relative;
    display: flex;
    align-items: center;
    background: #fff;
    border-radius: 999px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.15);
    padding: 6px 8px 6px 18px;
}

.tvbo-kg-container .kg-hero-search-icon {
    color: #3498DB;
    margin-right: 8px;
    flex-shrink: 0;
}

.tvbo-kg-container .kg-hero-search-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-size: 1.05rem;
    padding: 12px 8px;
    color: #2d3748;
}

.tvbo-kg-container .kg-hero-search-input::placeholder {
    color: #a0aec0;
}

.tvbo-kg-container .kg-hero-search-clear {
    border: none;
    background: #edf2f7;
    color: #4a5568;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease;
}

.tvbo-kg-container .kg-hero-search-clear:hover {
    background: #e2e8f0;
}

.tvbo-kg-container .kg-hero-search.has-value .kg-hero-search-clear {
    display: inline-flex;
}

.tvbo-kg-container .container-fluid {
    max-width: 1600px;
    padding: 0;
}

/* Performance Info - Now in results header */
.tvbo-kg-container .performance-info {
    font-size: 13px;
    color: #718096;
    font-weight: 500;
    white-space: nowrap;
}

/* Main Content Layout - sidebar + results side by side */
.tvbo-kg-container .main-content {
    display: flex;
    gap: 0;
}

/* Sidebar - sticky for scrolling */
.tvbo-kg-container .sidebar {
    width: 280px;
    flex: 0 0 280px;
    background: #fff;
    padding: 20px;
    border-right: 1px solid #e2e8f0;
    position: sticky;
    top: 70px;
    align-self: flex-start;
    max-height: calc(100vh - 80px);
    overflow-y: auto;
}

/* Facet Groups */
.tvbo-kg-container .facet-group {
    margin-bottom: 16px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    overflow: hidden;
}

.tvbo-kg-container .facet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: #f8f9fa;
    cursor: pointer;
    user-select: none;
    transition: background-color 0.2s ease;
}

.tvbo-kg-container .facet-header:hover {
    background: #edf2f7;
}

.tvbo-kg-container .facet-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: #2d3748;
    margin: 0;
}

.tvbo-kg-container .facet-content {
    padding: 10px 14px;
}

.tvbo-kg-container .facet-group.collapsed .facet-content {
    display: none;
}

.tvbo-kg-container .facet-item {
    display: flex;
    align-items: center;
    margin-bottom: 6px;
    padding: 6px 10px;
    border-radius: 6px;
    transition: all 0.2s ease;
    cursor: pointer;
}

.tvbo-kg-container .facet-item:hover {
    background: #e2e8f0;
}

.tvbo-kg-container .facet-item.active {
    background: linear-gradient(135deg, #3498DB 0%, #2C3E50 100%);
    color: white;
}

.tvbo-kg-container .facet-checkbox {
    margin-right: 8px;
    width: 16px;
    height: 16px;
    accent-color: #3498DB;
}

.tvbo-kg-container .facet-label {
    flex: 1;
    font-size: 0.9rem;
}

.tvbo-kg-container .facet-count {
    margin-left: auto;
    background: #e2e8f0;
    color: #4a5568;
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
}

.tvbo-kg-container .facet-item.active .facet-count {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.tvbo-kg-container .facet-item.dimmed {
    opacity: 0.5;
}

.tvbo-kg-container .facet-item.dimmed:hover {
    opacity: 0.8;
}

/* Property Section Header — shown above property facets for a selected class */
.tvbo-kg-container .property-section-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px 6px;
    font-size: 0.8rem;
    font-weight: 700;
    color: #4a5568;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-top: 2px solid #e2e8f0;
    margin-top: 8px;
}

/* Property Facets — visually subordinate to the main facets */
.tvbo-kg-container .facet-group.property-facet {
    border-color: #edf2f7;
    margin-bottom: 10px;
}

.tvbo-kg-container .facet-group.property-facet .facet-header {
    background: #f8f9fa;
    padding: 8px 14px;
}

.tvbo-kg-container .facet-group.property-facet .facet-title {
    font-size: 0.85rem;
    color: #4a5568;
}

.tvbo-kg-container .facet-group.property-facet .facet-content {
    max-height: 200px;
    overflow-y: auto;
}

/* Results Area */
.tvbo-kg-container .results-area {
    flex: 1;
    padding: 20px 30px;
    min-width: 0;
}

.tvbo-kg-container .results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid #e2e8f0;
}

.tvbo-kg-container .results-count {
    font-size: 1rem;
    color: #4a5568;
    font-weight: 500;
}

.tvbo-kg-container .sort-select {
    padding: 6px 10px;
    border: 2px solid #e2e8f0;
    border-radius: 6px;
    background: #fff;
    color: #2d3748;
    font-size: 14px;
}

.tvbo-kg-container .sort-select:focus {
    border-color: #3498DB;
    outline: none;
}

.tvbo-kg-container .clear-filters {
    background: #e53e3e;
    color: white;
    border: none;
    padding: 6px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s ease;
}

.tvbo-kg-container .clear-filters:hover {
    background: #c53030;
}

/* Results Grid */
.tvbo-kg-container .results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
}

@media (min-width: 1400px) {
    .tvbo-kg-container .results-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Result Cards */
.tvbo-kg-container .result-card {
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    transition: all 0.3s ease;
    overflow: hidden;
    border: 1px solid #e2e8f0;
    padding: 20px;
    cursor: pointer;
    min-height: 120px;
}

.tvbo-kg-container .result-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
}

.tvbo-kg-container .field-display {
    margin-bottom: 8px;
}

.tvbo-kg-container .field-value {
    color: #2d3748;
}

.tvbo-kg-container .card-body {
    margin-top: 8px;
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.tvbo-kg-container .card-thumb {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    flex: 0 0 auto;
}

.tvbo-kg-container .card-thumb + .card-desc {
    max-height: 80px;
    overflow: hidden;
}

.tvbo-kg-container .card-desc {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 0.9rem;
    color: #4a5568;
    line-height: 1.5;
}

.tvbo-kg-container .card-equation {
    font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.8rem;
    color: #553c9a;
    background: #f7f5ff;
    padding: 4px 8px;
    border-radius: 6px;
    margin-bottom: 6px;
    line-height: 1.4;
    word-break: break-word;
}

.tvbo-kg-container .card-equation-latex {
    font-family: inherit;
    font-size: 0.85rem;
    overflow-x: auto;
}

.tvbo-kg-container .card-tags {
    margin-top: 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.tvbo-kg-container .tag-pill {
    background: #edf2f7;
    color: #4a5568;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
}

/* Badges */
.tvbo-kg-container .badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #edf2f7;
    color: #4a5568;
    padding: 3px 8px;
    border-radius: 9999px;
    font-size: 11px;
    margin: 2px 4px 2px 0;
    border: 1px solid transparent;
}

.tvbo-kg-container .badge.type-badge {
    color: #fff;
    font-weight: 600;
    border: none;
    padding: 3px 10px;
    letter-spacing: 0.02em;
}

.tvbo-kg-container .badge.type-badge i {
    font-size: 11px;
    line-height: 1;
}

/* Ontology symbol display */
.tvbo-kg-container .ontology-symbol {
    font-family: 'Times New Roman', serif;
    font-style: italic;
    font-size: 1rem;
    color: #5e35b1;
    background: #f3e5f5;
    padding: 2px 8px;
    border-radius: 4px;
}

/* No Results */
.tvbo-kg-container .no-results {
    text-align: center;
    padding: 60px 20px;
    color: #718096;
    grid-column: 1 / -1;
}

/* Modal Styles */
.tvbo-kg-container .modal.hidden {
    display: none !important;
}

.tvbo-kg-container .modal {
    position: fixed;
    inset: 0;
    z-index: 1050;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tvbo-kg-container .modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
}

.tvbo-kg-container .modal-dialog {
    position: relative;
    max-width: 800px;
    width: 90%;
    max-height: 85vh;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.tvbo-kg-container .modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #e2e8f0;
    background: #f9fafb;
}

.tvbo-kg-container .modal-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: #2d3748;
}

.tvbo-kg-container .modal-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.tvbo-kg-container .modal-btn {
    border: 1px solid #cbd5e1;
    background: #fff;
    color: #1f2937;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.2s;
}

.tvbo-kg-container .modal-btn:hover {
    background: #f3f4f6;
}

.tvbo-kg-container .modal-close {
    border: none;
    background: transparent;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    color: #4a5568;
    padding: 0 4px;
}

.tvbo-kg-container .modal-close:hover {
    color: #1a202c;
}

.tvbo-kg-container .modal-content {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.tvbo-kg-container .modal-section {
    margin-bottom: 16px;
}

.tvbo-kg-container .modal-details {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.tvbo-kg-container .detail-row {
    display: flex;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid #f0f0f0;
}

.tvbo-kg-container .detail-label {
    flex: 0 0 120px;
    font-weight: 600;
    color: #4a5568;
    font-size: 0.9rem;
}

.tvbo-kg-container .detail-value {
    flex: 1;
    color: #2d3748;
    font-size: 0.9rem;
    line-height: 1.5;
}

.tvbo-kg-container .eq-display {
    font-family: 'Courier New', monospace;
    background: #f8f9fa;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.85rem;
    margin-top: 4px;
}

/* Ontology-specific modal styles */
.tvbo-kg-container .ontology-header {
    text-align: center;
    margin-bottom: 16px;
}

.tvbo-kg-container .ontology-symbol-large {
    font-family: 'Times New Roman', serif;
    font-style: italic;
    font-size: 2rem;
    color: #5e35b1;
    background: linear-gradient(135deg, #f3e5f5 0%, #e3f2fd 100%);
    padding: 8px 20px;
    border-radius: 8px;
    display: inline-block;
}

.tvbo-kg-container .ontology-iri {
    text-align: center;
    margin-bottom: 16px;
    font-size: 0.8rem;
}

.tvbo-kg-container .ontology-iri a {
    color: #5e35b1;
    text-decoration: none;
    word-break: break-all;
}

.tvbo-kg-container .ontology-iri a:hover {
    text-decoration: underline;
}

/* Guard against long unbreakable tokens (IRIs, ids, equations) forcing a card
   — and the whole page — wider than the mobile viewport. `anywhere` also lets
   the box shrink below its min-content width, which is what prevents overflow. */
.tvbo-kg-container .field-display,
.tvbo-kg-container .field-value,
.tvbo-kg-container .card-desc {
    overflow-wrap: anywhere;
}

/* The results toolbar (view toggle + sort + clear) is a single non-wrapping
   flex row; on narrow screens it must wrap instead of overflowing the page. */
.tvbo-kg-container .results-tools {
    flex-wrap: wrap;
}

/* Responsive */
@media (max-width: 900px) {
    .tvbo-kg-container .main-content {
        flex-direction: column;
    }

    .tvbo-kg-container .sidebar {
        width: 100%;
        flex: none;
        position: static;
        max-height: none;
        border-right: none;
        border-bottom: 1px solid #e2e8f0;
    }

    .tvbo-kg-container .results-header {
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
    }

    /* Let the toolbar breathe across the full width and stay reachable. */
    .tvbo-kg-container .results-tools {
        width: 100%;
        gap: 10px 12px;
    }

    .tvbo-kg-container .results-tools .sort-select {
        flex: 1 1 auto;
        min-width: 0;
    }

    .tvbo-kg-container .results-tools .clear-filters {
        margin-left: auto;
    }

    .tvbo-kg-container .results-grid {
        grid-template-columns: 1fr;
    }
}

/* ===================
   Graph Visualization
   =================== */

.view-toggle {
    display: flex;
    gap: 4px;
    background: #edf2f7;
    padding: 4px;
    border-radius: 8px;
}

.view-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    color: #718096;
    transition: all 0.2s ease;
    /* Clip the icon-font ligature label so a slow/blocked Material Icons load
       degrades to a clipped glyph instead of overflowing onto the neighbouring
       controls. */
    overflow: hidden;
    flex: 0 0 auto;
}

.view-btn:hover {
    background: #e2e8f0;
    color: #4a5568;
}

.view-btn.active {
    background: #667eea;
    color: white;
}

.view-btn .mi-svg {
    display: block;
}

.graph-container {
    position: relative;
    width: 100%;
    height: 70vh;
    min-height: 500px;
    background: linear-gradient(135deg, #f7fafc 0%, #edf2f7 100%);
    border-radius: 12px;
    overflow: hidden;
}

.graph-container.hidden {
    display: none;
}

#graphSvg {
    width: 100%;
    height: 100%;
}

.graph-controls {
    position: absolute;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.graph-control-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #4a5568;
    transition: all 0.2s ease;
}

.graph-control-btn:hover {
    background: #667eea;
    color: white;
    transform: scale(1.05);
}

.graph-legend {
    position: absolute;
    top: 20px;
    left: 20px;
    background: white;
    padding: 16px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    font-size: 13px;
    max-width: 200px;
}

.legend-title {
    font-weight: 700;
    color: #2d3748;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid #e2e8f0;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.legend-color {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.legend-label {
    color: #4a5568;
}

.legend-stats {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #e2e8f0;
    color: #718096;
    font-size: 12px;
}

.legend-stats div {
    margin-bottom: 4px;
}

/* Graph tooltip */
.graph-tooltip {
    position: absolute;
    pointer-events: none;
    background: white;
    padding: 12px 16px;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.15s ease;
    max-width: 300px;
}

.graph-tooltip.visible {
    opacity: 1;
}

.tooltip-title {
    font-weight: 700;
    color: #2d3748;
    margin-bottom: 4px;
}

.tooltip-type {
    font-size: 12px;
    color: #667eea;
    text-transform: capitalize;
}

.tooltip-iri {
    font-size: 11px;
    color: #a0aec0;
    word-break: break-all;
    margin-top: 4px;
}

/* Node styling via D3 */
.node {
    cursor: pointer;
}

.node:hover circle {
    stroke: #667eea;
    stroke-width: 3px;
}

.links line {
    stroke-linecap: round;
}
