/**
 * CKP Ontology Browser — Styles
 * Concept Kernel Protocol v3.5-alpha6
 */

/* --- Base Font --- */
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    overflow: hidden;
    margin: 0;
}

/* --- Top Loading Bar (YouTube-style) --- */
.top-loading-bar {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    width: 0%;
    background: linear-gradient(90deg, #3b82f6, #8b5cf6, #3b82f6);
    background-size: 200% 100%;
    z-index: 9999;
    transition: width 0.4s ease, opacity 0.3s ease;
    opacity: 0;
    pointer-events: none;
}
.top-loading-bar.active {
    opacity: 1;
    animation: loading-shimmer 1.5s linear infinite;
}
.top-loading-bar.done {
    width: 100% !important;
    opacity: 0;
    transition: width 0.2s ease, opacity 0.5s ease 0.3s;
}
@keyframes loading-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* --- CKP Header Bar --- */
.ckp-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #0D2137;
    color: #ffffff;
    padding: 0 1.5rem;
    height: 48px;
    flex-shrink: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.ckp-header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.ckp-header-brand {
    font-weight: 800;
    font-size: 1rem;
    letter-spacing: -0.02em;
    color: #ffffff;
    text-decoration: none;
}

.ckp-header-brand:hover {
    opacity: 0.9;
}

.ckp-header-separator {
    width: 1px;
    height: 20px;
    background: rgba(255, 255, 255, 0.25);
}

.ckp-header-title {
    font-weight: 500;
    font-size: 0.875rem;
    color: rgba(255, 255, 255, 0.8);
}

.ckp-header-right {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

.ckp-header-link {
    font-size: 0.8rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    transition: color 0.15s;
}

.ckp-header-link:hover {
    color: #ffffff;
}

/* --- Main App Layout --- */
.app-wrapper {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.app-container {
    display: flex;
    flex: 1;
    min-height: 0;
}

/* --- Sidebar (1/4) --- */
.sidebar {
    width: 28%;
    min-width: 350px;
    height: 100%;
    background: #f8f9fb;
    border-right: 1px solid #e5e7eb;
    display: flex;
    flex-direction: column;
}

/* --- Main Content (3/4) --- */
.main-content {
    flex: 1;
    height: 100%;
    overflow-y: auto;
    background: #ffffff;
    padding: 2.5rem;
}

#infoPlaceholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    flex-direction: column;
    color: #6b7280;
}
#infoPlaceholder svg {
    width: 50px;
    height: 50px;
    margin-bottom: 1rem;
}

/* --- Module Toggle Bar --- */
.module-toggle-bar {
    background: white;
    padding: 12px 16px;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0;
}
.module-toggle-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #6b7280;
    margin-bottom: 8px;
}
.module-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.module-pill {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    border-radius: 99px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.15s ease;
    user-select: none;
    color: #fff;
}
.module-pill.active {
    opacity: 1;
}
.module-pill.inactive {
    background: #e5e7eb !important;
    color: #9ca3af !important;
    border-color: transparent;
}
.module-pill.inactive:hover {
    background: #d1d5db !important;
    color: #6b7280 !important;
}
.module-pill.failed {
    background: #fecaca !important;
    color: #991b1b !important;
    border-color: #f87171;
    cursor: not-allowed;
    text-decoration: line-through;
}
.module-pill .pill-count {
    margin-left: 5px;
    font-size: 10px;
    opacity: 0.8;
}

/* --- Entity Heading with Count Badge --- */
.entity-heading h2 {
    display: flex;
    align-items: center;
    gap: 8px;
}
.entity-count-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #0D2137;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    min-width: 24px;
    height: 22px;
    padding: 0 7px;
    border-radius: 99px;
    line-height: 1;
}

/* --- Sidebar Panel Styling --- */
.panel {
    background: white;
    padding: 20px;
    border-bottom: 1px solid #e5e7eb;
}
.ontology-browser {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    border-bottom: none;
}

h2 {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 15px;
    color: #0D2137;
    border-bottom: 1px solid #e5e7eb;
    padding-bottom: 10px;
}

/* --- Advanced Loader (collapsible) --- */
.advanced-loader {
    flex-shrink: 0;
    background: white;
    border-top: 1px solid #e5e7eb;
}
.advanced-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 16px;
    background: none;
    border: none;
    border-radius: 0;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    color: #6b7280;
    text-align: left;
    margin: 0;
    transition: color 0.15s;
}
.advanced-toggle:hover {
    color: #374151;
    background: #f9fafb;
}
.advanced-toggle-icon {
    font-size: 10px;
    display: inline-block;
    transition: transform 0.2s ease;
}
.advanced-toggle-icon.expanded {
    transform: rotate(90deg);
}
.advanced-content {
    display: none;
    padding: 0 16px 16px 16px;
}
.advanced-content.expanded {
    display: block;
}

#dependencyCheck { padding: 8px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 12px; margin-bottom: 10px; background: #f9fafb; }
textarea { width: 100%; height: 100px; padding: 10px; border: 1px solid #d1d5db; border-radius: 8px; font-family: 'Monaco', 'Menlo', monospace; font-size: 12px; resize: vertical; transition: border-color 0.2s, box-shadow 0.2s; box-sizing: border-box; }
textarea:focus { outline: none; border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1); }

/* Scoped button styles for advanced loader and load-external */
.advanced-content button:not(.entity-filter button),
.load-external-btn {
    background: #3b82f6; color: white; border: none; padding: 10px 20px; border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: 600; transition: background 0.2s; width: 100%; margin-top: 10px;
}
.advanced-content button:not(.entity-filter button):hover { background: #2563eb; }
.advanced-content button:not(.entity-filter button):disabled { background: #9ca3af; cursor: not-allowed; }

.progress { width: 100%; height: 4px; background: #e5e7eb; border-radius: 2px; margin-top: 12px; overflow: hidden; }
.progress-bar { height: 100%; background: #3b82f6; transition: width 0.3s ease; border-radius: 2px; }
.status { font-size: 12px; color: #6b7280; margin-top: 8px; }
#loadLogs { margin-top: 5px; max-height: 60px; overflow-y: auto; background: #f9fafb; border: 1px solid #f3f4f6; border-radius: 4px; padding: 5px; }
.log { font-size: 10px; color: #6b7280; margin-top: 2px; font-family: 'Monaco', 'Menlo', monospace; }
.success { color: #16a34a; }
.error { color: #dc2626; }
.warning { color: #d97706; }

/* --- Ontology Browser List (Sidebar) --- */
.search-controls input { width: 100%; padding: 8px 12px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 14px; margin-bottom: 10px; box-sizing: border-box; }
.entity-filter { display: flex; gap: 5px; margin-bottom: 10px; }
.entity-filter button { flex: 1; font-size: 12px; background: #f3f4f6; color: #4b5563; padding: 6px 10px; margin-top: 0; border: none; border-radius: 8px; cursor: pointer; font-weight: 600; transition: background 0.2s; width: auto; }
.entity-filter button.active { background: #0D2137; color: white; font-weight: 700; }
.entity-filter button:hover:not(.active) { background: #e5e7eb; }
.ontology-tree { flex: 1; overflow-y: auto; border: 1px solid #e5e7eb; border-radius: 8px; padding: 5px; background: #fafafa; }
.ontology-item { margin-bottom: 5px; border: 1px solid #e5e7eb; border-radius: 8px; overflow: hidden; background: #ffffff; }
.ontology-header { background: #f8f9fb; padding: 10px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #e5e7eb; }
.ontology-header:hover { background: #eef1f5; }
.ontology-header strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ontology-header-uri { font-size: 11px; color: #666; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ontology-stats { font-size: 11px; color: #6b7280; display: flex; gap: 8px; flex-shrink: 0; }
.ontology-stats span { white-space: nowrap; }
.entity-list { background: white; max-height: 0; overflow: hidden; transition: max-height 0.3s ease-out; }
.entity-list.expanded { max-height: 500px; overflow-y: auto; }

/* Clickable Entity Item — label first, badge right */
.entity-item {
    padding: 8px 10px;
    border-bottom: 1px solid #f0f0f0;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    cursor: pointer;
    background: none;
    border: none;
    border-left: none;
    border-right: none;
    border-top: none;
    border-bottom: 1px solid #f0f0f0;
    width: 100%;
    text-align: left;
    margin: 0;
    border-radius: 0;
}
.entity-item:last-child { border-bottom: none; }
.entity-item:hover { background: #f8fafc; }

.entity-label {
    font-weight: 600;
    color: #111827;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}

.entity-type {
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 700;
    white-space: nowrap;
    flex-shrink: 0;
    text-align: center;
}
.entity-type.Class { background: #dbeafe; color: #1e40af; }
.entity-type.Property { background: #d4edda; color: #166534; }
.entity-type.Individual { background: #fef3c7; color: #92400e; }
.entity-type.Resource { background: #e5e7eb; color: #4b5563; }
.entity-type.Ontology { background: #f3e5f5; color: #6B21A8; }


/* --- Main Content Info Panel Styling --- */
#breadcrumbs {
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    color: #6b7280;
}
.breadcrumb-item {
    font-weight: 500;
    color: #3b82f6;
    cursor: pointer;
    text-decoration: none;
}
.breadcrumb-item:hover {
    text-decoration: underline;
}
.breadcrumb-separator {
    margin: 0 0.5rem;
}

#infoLabel {
    font-size: 2.25rem;
    font-weight: 800;
    color: #111827;
    margin-bottom: 0.25rem;
}

#infoUri {
    font-size: 0.875rem;
    color: #6b7280;
    font-family: 'Monaco', 'Menlo', monospace;
    margin-bottom: 2rem;
    word-break: break-all;
}

.info-section {
    margin-top: 2rem;
}
.info-section h3 {
    font-size: 1.25rem;
    font-weight: 700;
    color: #0D2137;
    border-bottom: 1px solid #e5e7eb;
    padding-bottom: 0.5rem;
    margin-bottom: 1rem;
}

.triple-row, .detail-row {
    display: grid;
    grid-template-columns: 2fr 5fr;
    grid-gap: 1rem;
    padding: 0.75rem 0.5rem;
    border-bottom: 1px solid #f3f4f6;
    font-size: 0.875rem;
    align-items: start;
}
.triple-row:last-child, .detail-row:last-child {
    border-bottom: none;
}

/* Prose/paragraph content in the Details section */
.prose-row {
    padding: 0.75rem 0.5rem;
    border-bottom: 1px solid #f3f4f6;
    font-size: 0.875rem;
}
.prose-row:last-child {
    border-bottom: none;
}
.prose-row .predicate {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-family: 'Inter', sans-serif;
}
.prose-row .object-literal {
    /* Styles inherited from group */
}

.predicate {
    font-weight: 600;
    color: #374151;
    font-family: 'Monaco', 'Menlo', monospace;
    word-break: break-all;
}

.object-link {
    font-weight: 600;
    color: #3b82f6;
    text-decoration: none;
}
.object-link:hover {
    text-decoration: underline;
}
.object-link.predicate {
    font-family: 'Monaco', 'Menlo', monospace;
    font-weight: 600;
    color: #4338ca;
}
.object-link.predicate:hover {
    color: #3730a3;
}

.object-literal {
    color: #1f2937;
}

.object-link-uri {
    display: block;
    font-size: 0.75rem;
    color: #6b7280;
    font-weight: 400;
    font-family: 'Monaco', 'Menlo', monospace;
    margin-top: 0.25rem;
}

.load-external-btn {
    background: #eef2ff;
    color: #4338ca;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 99px;
    margin-left: 8px;
    cursor: pointer;
    border: 1px solid #c7d2fe;
    transition: all 0.2s;
    width: auto;
}
.load-external-btn:hover {
    background: #e0e7ff;
    border-color: #a5b4fc;
}
.load-external-btn:disabled {
    background: #e5e7eb;
    color: #9ca3af;
    cursor: not-allowed;
    border-color: #d1d5db;
}

/* --- Grouping --- */
.object-literal-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    white-space: pre-wrap;
    word-break: break-word;
    color: #1f2937;
}
.object-literal-item {
    display: block;
}
/* Special styles for prose group */
.prose-row .object-literal-group {
    line-height: 1.6;
    color: #111827;
}

.object-literal-lang {
    font-size: 0.75rem;
    color: #6b7280;
    font-weight: 500;
    margin-left: 0.25rem;
    font-family: sans-serif;
    border: 1px solid #e5e7eb;
    padding: 0 4px;
    border-radius: 4px;
    background: #f9fafb;
}

/* --- Placeholder / Empty State --- */
.canvas-placeholder {
    color: #9ca3af;
    font-size: 13px;
    text-align: center;
    padding: 2rem 1rem;
}

/* =================================================================
   WELCOME PANEL — Rich landing page on initial load
   ================================================================= */

.welcome-panel {
    max-width: 960px;
    margin: 0 auto;
    animation: welcome-fade-in 0.4s ease;
}

@keyframes welcome-fade-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Hero */
.welcome-hero {
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid #e5e7eb;
}
.welcome-hero-badge {
    display: inline-block;
    background: #0D2137;
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 3px 12px;
    border-radius: 99px;
    letter-spacing: 0.03em;
    margin-bottom: 0.75rem;
}
.welcome-hero-title {
    font-size: 2rem;
    font-weight: 800;
    color: #111827;
    margin: 0 0 0.5rem 0;
    line-height: 1.2;
}
.welcome-hero-tagline {
    font-size: 1.125rem;
    font-weight: 600;
    color: #4b5563;
    margin: 0 0 0.5rem 0;
}
.welcome-hero-description {
    font-size: 0.9375rem;
    color: #6b7280;
    line-height: 1.6;
    margin: 0;
    max-width: 680px;
}

/* Stats Bar */
.welcome-stats {
    display: flex;
    gap: 1px;
    background: #e5e7eb;
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 2rem;
}
.welcome-stat {
    flex: 1;
    background: #f8f9fb;
    padding: 1rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.welcome-stat-value {
    font-size: 1.5rem;
    font-weight: 800;
    color: #0D2137;
}
.welcome-stat-label {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #6b7280;
}

/* Section Titles */
.welcome-section {
    margin-bottom: 2rem;
}
.welcome-section-title {
    font-size: 1.125rem;
    font-weight: 700;
    color: #0D2137;
    margin: 0 0 1rem 0;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #e5e7eb;
}

/* Three Loops */
.welcome-loops {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}
.welcome-loop {
    background: #f8f9fb;
    border-radius: 10px;
    padding: 1rem;
    border-left: 4px solid;
}
.welcome-loop-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 0.5rem;
}
.welcome-loop-badge {
    display: inline-block;
    color: #fff;
    font-size: 0.6875rem;
    font-weight: 800;
    padding: 2px 8px;
    border-radius: 6px;
    letter-spacing: 0.04em;
}
.welcome-loop strong {
    font-size: 0.875rem;
    color: #111827;
}
.welcome-loop p {
    font-size: 0.8125rem;
    color: #6b7280;
    margin: 0;
    line-height: 1.5;
}

/* Module Overview Cards */
.welcome-modules {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}
.welcome-module-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 1rem;
    cursor: pointer;
    transition: all 0.15s ease;
    border-left: 4px solid;
}
.welcome-module-card:hover {
    background: #f8f9fb;
    border-color: #d1d5db;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
.welcome-module-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}
.welcome-module-name {
    font-size: 0.9375rem;
    font-weight: 700;
    color: #111827;
}
.welcome-module-count {
    font-size: 0.75rem;
    font-weight: 700;
    color: #fff;
    padding: 2px 8px;
    border-radius: 99px;
    min-width: 24px;
    text-align: center;
}
.welcome-module-desc {
    font-size: 0.8125rem;
    color: #6b7280;
    line-height: 1.5;
    margin: 0;
}

/* Featured Entities */
.welcome-featured {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}
.welcome-entity-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 0.75rem 1rem;
    cursor: pointer;
    transition: all 0.15s ease;
}
.welcome-entity-card:hover {
    background: #eff6ff;
    border-color: #93c5fd;
    box-shadow: 0 2px 6px rgba(59,130,246,0.1);
}
.welcome-entity-name {
    font-size: 0.875rem;
    font-weight: 700;
    color: #1e40af;
    margin-bottom: 2px;
}
.welcome-entity-type-badge {
    display: inline-block;
    font-size: 0.625rem;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 4px;
    margin-bottom: 4px;
}
.welcome-entity-type-badge.Class { background: #dbeafe; color: #1e40af; }
.welcome-entity-type-badge.Property { background: #d4edda; color: #166534; }
.welcome-entity-type-badge.Individual { background: #fef3c7; color: #92400e; }
.welcome-entity-desc {
    font-size: 0.75rem;
    color: #6b7280;
    line-height: 1.4;
    margin: 0;
}

/* Ontology Layering */
.welcome-layers {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
}
.welcome-layer {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: #f8f9fb;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 0.75rem 1rem;
}
.welcome-layer-label {
    font-size: 0.6875rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #0D2137;
    min-width: 60px;
    flex-shrink: 0;
}
.welcome-layer-content {
    font-size: 0.875rem;
    color: #111827;
}
.welcome-layer-content strong {
    display: inline;
}
.welcome-layer-note {
    color: #6b7280;
    font-size: 0.8125rem;
    margin-left: 0.5rem;
}
.welcome-layer-arrow {
    text-align: center;
    color: #9ca3af;
    font-size: 0.75rem;
    padding: 2px 0;
}

/* Quick Links */
.welcome-links {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}
.welcome-link {
    display: block;
    background: #f8f9fb;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 0.75rem 1rem;
    text-decoration: none;
    transition: all 0.15s ease;
}
.welcome-link:hover {
    background: #eff6ff;
    border-color: #93c5fd;
}
.welcome-link strong {
    display: block;
    font-size: 0.875rem;
    color: #111827;
    margin-bottom: 2px;
}
.welcome-link span {
    font-size: 0.75rem;
    color: #6b7280;
}

/* Back to Welcome button */
.info-panel-nav {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.5rem;
}
.back-to-welcome {
    background: none;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    padding: 4px 12px;
    font-size: 0.8125rem;
    font-weight: 600;
    color: #4b5563;
    cursor: pointer;
    transition: all 0.15s;
    flex-shrink: 0;
}
.back-to-welcome:hover {
    background: #f3f4f6;
    color: #111827;
    border-color: #9ca3af;
}

/* =================================================================
   STRUCTURED NAVIGATION — Type groups within each module
   ================================================================= */

.entity-type-group {
    border-top: 1px solid #f0f0f0;
}
.entity-type-group:first-child {
    border-top: none;
}
.entity-type-group-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: #f9fafb;
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #6b7280;
    border-bottom: 1px solid #f0f0f0;
}
.entity-type-group-count {
    font-size: 0.625rem;
    font-weight: 700;
    color: #fff;
    padding: 1px 6px;
    border-radius: 99px;
    min-width: 16px;
    text-align: center;
}

/* Module description in sidebar header */
.ontology-header-desc {
    font-size: 0.6875rem;
    color: #6b7280;
    margin-top: 4px;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Ensure all entity lists can expand fully */
.entity-list.expanded {
    max-height: 2000px;
    overflow-y: auto;
}
