/* =========================================
   ONTOLOGY GRAPH - Matching Design System
   ========================================= */

.graph-page-container {
    --graph-overlay-shift: 8px;
    --graph-navbar-bottom: calc(var(--nav-height) + 16px);
    --graph-top-gap: 16px;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 12px);
    overflow: hidden;
    position: relative;
}

.graph-workspace {
    display: flex;
    flex: 1;
    position: relative;
    overflow: hidden;
}

/* =========================================
   CONTROLS (Top Left)
   ========================================= */
.graph-controls {
    position: absolute;
    top: calc(var(--graph-navbar-bottom) + var(--graph-top-gap) + var(--graph-overlay-shift));
    left: 1.5rem;
    z-index: 20;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.graph-btn {
    background: rgba(28, 25, 23, 0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    width: 40px;
    height: 40px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.graph-btn:hover {
    background: rgba(28, 25, 23, 0.95);
    color: var(--primary-400);
    border-color: var(--primary-500);
    transform: translateY(-2px);
}

.graph-controls-offset {
    top: 5rem;
}

/* =========================================
   TOP BAR (Center)
   ========================================= */
.graph-top-bar {
    position: absolute;
    top: calc(var(--graph-navbar-bottom) + var(--graph-top-gap));
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
}

.view-toggle {
    display: flex;
    background: rgba(28, 25, 23, 0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--border-subtle);
    border-radius: 10px;
    padding: 3px;
    gap: 3px;
}

.toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.9rem;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    text-decoration: none;
    transition: all 0.2s ease;
}

.toggle-btn i {
    width: 14px;
    height: 14px;
}

.toggle-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.toggle-btn.active {
    background: linear-gradient(135deg, var(--primary-500), var(--primary-600));
    color: white;
}

/* =========================================
   FILTER (Top Left, under controls)
   ========================================= */
.graph-filter-overlay {
    position: absolute;
    top: calc(var(--graph-navbar-bottom) + 80px + var(--graph-overlay-shift));
    left: 1.5rem;
    z-index: 100;
}

.filter-switch {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: rgba(28, 25, 23, 0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--border-subtle);
    padding: 0.6rem 1rem;
    border-radius: 12px;
}

.switch-label {
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    white-space: nowrap;
}

.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--bg-muted);
    transition: 0.3s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--success);
}

input:checked + .slider:before {
    transform: translateX(20px);
}

.auth-warning {
    color: var(--text-muted);
    font-size: 0.85rem;
    padding: 0.6rem 1rem;
    background: rgba(28, 25, 23, 0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
}

/* =========================================
   LAYOUT TOOLBAR (Bottom Center)
   ========================================= */
.layout-toolbar {
    position: absolute;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 20;
    display: flex;
    background: rgba(28, 25, 23, 0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--border-subtle);
    padding: 6px;
    border-radius: 12px;
    gap: 6px;
}

.toolbar-btn {
    background: transparent;
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-muted);
    transition: all 0.2s ease;
}

.toolbar-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.toolbar-btn.active {
    background: rgba(99, 102, 241, 0.15);
    color: var(--primary-400);
    border: 1px solid rgba(99, 102, 241, 0.3);
}

/* =========================================
   LEGEND (Bottom Left)
   ========================================= */
.graph-legend {
    position: absolute;
    bottom: 1rem;
    left: 1.5rem;
    transform: translateY(var(--graph-overlay-shift));
    background: rgba(28, 25, 23, 0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    padding: 1rem;
    z-index: 15;
    pointer-events: auto;
    max-width: 280px;
}

/* Filter inside legend */
.legend-filter {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding-bottom: 0.75rem;
    margin-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-subtle);
}

.legend-filter .switch-label {
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 500;
}

.auth-warning-legend {
    color: var(--text-muted);
    font-size: 0.75rem;
    padding-bottom: 0.75rem;
    margin-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-subtle);
}

.graph-info-panel.visible ~ .graph-legend {
    opacity: 0.3;
    transition: opacity 0.3s;
}

.legend-title {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.legend-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 12px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.legend-color {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    flex-shrink: 0;
}

.legend-blue { background: #3b82f6; }
.legend-green { background: #10b981; }
.legend-yellow { background: #f59e0b; }
.legend-purple { background: #8b5cf6; }
.legend-pink { background: #ec4899; }
.legend-teal { background: #14b8a6; }
.legend-rose { background: #f43f5e; }
.legend-slate { background: #64748b; }
.legend-indigo { background: #6366f1; }
.legend-cyan { background: #06b6d4; }

.edge-legend {
    margin-top: 0.75rem;
    border-top: 1px solid var(--border-subtle);
    padding-top: 0.75rem;
}

.legend-title-margin {
    margin-bottom: 0.5rem;
}

.edge-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.edge-line {
    width: 20px;
    height: 2px;
    flex-shrink: 0;
}

/* =========================================
   INFO PANEL (Right Side)
   ========================================= */
.graph-info-panel {
    position: absolute;
    top: calc(var(--nav-height) + 48px);
    right: -400px;
    width: 360px;
    max-height: 85%;
    background: rgba(28, 25, 23, 0.9);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-subtle);
    border-radius: 16px;
    padding: 1.5rem;
    z-index: 30;
    display: flex;
    flex-direction: column;
    transition: right 0.3s ease;
    overflow-y: auto;
}

.graph-info-panel.visible {
    right: 1.5rem;
}

.panel-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
    line-height: 1.3;
}

.panel-uri {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
    margin-bottom: 1rem;
    word-break: break-all;
    background: rgba(0, 0, 0, 0.2);
    padding: 0.5rem;
    border-radius: 6px;
}

.panel-desc {
    font-size: 0.9rem;
    line-height: 1.6;
    margin-bottom: 1rem;
    color: var(--text-secondary);
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.panel-section-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-subtle);
    padding-bottom: 0.5rem;
}

.panel-connections {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    overflow-y: auto;
    flex-grow: 1;
}

.panel-connections li {
    font-size: 0.85rem;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    padding: 0.75rem;
    line-height: 1.4;
}

.panel-conn-type {
    font-weight: 700;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    display: block;
    margin-bottom: 0.25rem;
    color: var(--primary-400);
}

.panel-conn-node {
    font-weight: 600;
    color: var(--text-primary);
}

/* =========================================
   MAIN GRAPH AREA
   ========================================= */
.graph-main-area {
    flex: 1;
    min-width: 0;
    min-height: 0;
    /* Transparent to show particles canvas behind */
    background-color: transparent;
    background-image: radial-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px);
    background-size: 24px 24px;
}

#ontology-graph {
    width: 100%;
    height: 100%;
    cursor: grab;
}

#ontology-graph:active {
    cursor: grabbing;
}

/* =========================================
   D3 NODE STYLES
   ========================================= */
.node rect {
    rx: 4;
    ry: 4;
    stroke: var(--bg-base);
    stroke-width: 2px;
    cursor: pointer;
    transition: all 0.2s;
    filter: drop-shadow(0px 4px 6px rgba(0, 0, 0, 0.4));
}

.node text {
    font-size: 11px;
    font-weight: 600;
    fill: #ffffff;
    text-anchor: middle;
    pointer-events: none;
    text-shadow: 0px 1px 2px rgba(0, 0, 0, 0.8);
}

.node:hover rect {
    filter: drop-shadow(0px 0px 12px rgba(255, 255, 255, 0.3));
}

.link {
    transition: opacity 0.3s;
}

/* =========================================
   SCROLLBAR
   ========================================= */
.graph-info-panel::-webkit-scrollbar,
.panel-connections::-webkit-scrollbar {
    width: 6px;
}

.graph-info-panel::-webkit-scrollbar-track,
.panel-connections::-webkit-scrollbar-track {
    background: transparent;
}

.graph-info-panel::-webkit-scrollbar-thumb,
.panel-connections::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

/* =========================================
   RESPONSIVE
   ========================================= */
/* =========================================
   MOBILE LEGEND TOGGLE BUTTON
   ========================================= */
.legend-toggle-btn {
    display: none;
    position: absolute;
    bottom: 5rem;
    right: 1.5rem;
    z-index: 25;
    background: rgba(28, 25, 23, 0.9);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    width: 48px;
    height: 48px;
    border-radius: 50%;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    pointer-events: auto;
}

.legend-toggle-btn:hover {
    background: rgba(99, 102, 241, 0.2);
    color: var(--primary-400);
    border-color: var(--primary-500);
    transform: scale(1.05);
}

.legend-toggle-btn svg {
    width: 22px;
    height: 22px;
}

/* =========================================
   MOBILE LEGEND MODAL
   ========================================= */
.legend-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.legend-modal.visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.legend-modal-content {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(28, 25, 23, 0.98);
    border: 1px solid var(--border-subtle);
    border-radius: 20px 20px 0 0;
    padding: 1.25rem;
    max-height: 80vh;
    overflow-y: auto;
    transform: translateY(100%);
    transition: transform 0.3s ease;
}

.legend-modal.visible .legend-modal-content {
    transform: translateY(0);
}

.legend-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-subtle);
}

.legend-modal-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.legend-modal-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.legend-modal-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.legend-modal-body {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.legend-section {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    padding: 1rem;
}

.legend-filter-mobile {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
}

.auth-warning-legend-mobile {
    color: var(--text-muted);
    font-size: 0.85rem;
    padding: 0.75rem 1rem;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    text-align: center;
}

.legend-grid-mobile {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem 1rem;
}

.edge-legend-mobile {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* =========================================
   INFO PANEL BACKDROP (Mobile)
   ========================================= */
.info-panel-backdrop {
    display: none;
}

@media (max-width: 768px) {
    .info-panel-backdrop {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 150;
        background: rgba(0, 0, 0, 0.6);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }
    
    .info-panel-backdrop.visible {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }
    
    .graph-legend {
        display: none;
    }
    
    .legend-toggle-btn {
        display: flex;
        bottom: 5.5rem;
    }
    
    .legend-modal {
        display: block;
    }
    
    /* Info panel centered on mobile */
    .graph-info-panel {
        position: fixed;
        top: 50%;
        left: 50%;
        right: auto;
        bottom: auto;
        width: calc(100% - 2rem);
        max-width: 360px;
        max-height: 70vh;
        transform: translate(-50%, -50%) scale(0.95);
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        border-radius: 16px;
        z-index: 200;
        transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease;
    }
    
    .graph-info-panel.visible {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }
    
    .view-toggle {
        flex-direction: column;
    }
    
    .toggle-btn {
        padding: 0.5rem 1rem;
        font-size: 0.85rem;
    }
}
