﻿/* ============================================
   19b. KNOWLEDGE GRAPH PAGE
   ============================================ */
.graph-page {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 0 !important;
    overflow: hidden;
    height: calc(100vh - var(--topbar-h));
    animation: none;
}

/* Toolbar */
.graph-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 16px 24px;
    background: var(--surface-card);
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
    flex-wrap: wrap;
}

.graph-toolbar-left {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    flex: 1;
}

.graph-toolbar-right {
    display: flex;
    gap: 6px;
    align-items: center;
}

.graph-filter-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.graph-filter-group label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 5px;
}

.graph-filter-group label i {
    font-size: 10px;
    color: var(--brand);
}

.graph-filter-group select {
    padding: 8px 12px;
    background: var(--surface-raised);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
    min-width: 150px;
    transition: border-color var(--duration-fast) var(--ease),
                box-shadow var(--duration-fast) var(--ease);
    cursor: pointer;
}

.graph-filter-group select:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: var(--ring-brand);
}

.graph-filter-group select:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.graph-btn {
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    background: var(--surface-raised);
    border: 1px solid var(--border-default);
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-spring);
    -webkit-tap-highlight-color: transparent;
}

.graph-btn:hover {
    color: var(--brand);
    border-color: var(--brand);
    background: var(--brand-muted);
    transform: scale(1.08);
}

.graph-btn:active {
    transform: scale(0.92);
}

.graph-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

/* Legend */
.graph-legend {
    display: flex;
    gap: 16px;
    align-items: center;
    padding: 8px 24px;
    background: rgba(17, 24, 39, 0.6);
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
    flex-wrap: wrap;
}

.legend-item,
.legend-edge {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
}

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

.legend-line {
    width: 20px;
    height: 2px;
    flex-shrink: 0;
}

.legend-line.solid {
    background: rgba(16, 185, 129, 0.6);
}

.legend-line.dashed {
    background: repeating-linear-gradient(
        90deg,
        rgba(239, 68, 68, 0.6) 0px,
        rgba(239, 68, 68, 0.6) 4px,
        transparent 4px,
        transparent 7px
    );
    height: 2px;
}

/* Graph Container */
.graph-container {
    flex: 1;
    position: relative;
    background:
        radial-gradient(circle at 50% 50%, rgba(99, 102, 241, 0.03) 0%, transparent 60%),
        var(--surface-base);
    overflow: hidden;
    min-height: 0;
}

.graph-container canvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
}

/* Loading State */
.graph-loading {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    z-index: 10;
    background: rgba(11, 15, 25, 0.8);
    backdrop-filter: blur(8px);
}

.graph-loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-default);
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.graph-loading p {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
    animation: none;
    min-height: auto;
}

/* Empty State */
.graph-empty {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    z-index: 5;
    padding: 24px;
    text-align: center;
}

.graph-empty i {
    font-size: 48px;
    color: var(--text-muted);
    opacity: 0.3;
}

.graph-empty h3 {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-secondary);
    margin: 0;
}

.graph-empty p {
    font-size: 14px;
    color: var(--text-muted);
    max-width: 360px;
    line-height: 1.6;
    animation: none;
    min-height: auto;
}

/* Detail Panel */
.graph-detail-panel {
    position: absolute;
    bottom: 16px;
    left: 16px;
    background: var(--surface-overlay);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    padding: 0;
    width: 280px;
    max-width: calc(100% - 32px);
    box-shadow: var(--shadow-xl);
    animation: detailSlideIn 0.35s var(--ease-spring) both;
    z-index: 20;
    overflow: hidden;
}

@keyframes detailSlideIn {
    from {
        opacity: 0;
        transform: translateY(16px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.graph-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 16px;
    border-bottom: 1px solid var(--border-subtle);
}

.graph-detail-header h4 {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 4px 0 0;
    line-height: 1.3;
}

.graph-detail-type {
    display: inline-flex;
    padding: 2px 10px;
    border-radius: var(--radius-full);
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.graph-detail-type.word {
    background: rgba(99, 102, 241, 0.15);
    color: #818cf8;
}

.graph-detail-type.opposite {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
}

.graph-detail-type.synonym {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
}

.graph-detail-type.property {
    background: rgba(245, 158, 11, 0.15);
    color: #fbbf24;
}

.graph-detail-close {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease);
    flex-shrink: 0;
}

.graph-detail-close:hover {
    background: var(--danger-muted);
    color: var(--danger);
}

.graph-detail-body {
    padding: 12px 16px 16px;
}

.graph-detail-body p {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 4px;
    animation: none;
    min-height: auto;
}

.graph-detail-body p:last-child {
    margin-bottom: 0;
}

/* Zoom Controls */
.graph-zoom-controls {
    position: absolute;
    bottom: 16px;
    right: 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    z-index: 20;
}

.graph-zoom-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    background: var(--surface-overlay);
    border: 1px solid var(--border-default);
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-spring);
    box-shadow: var(--shadow-sm);
    -webkit-tap-highlight-color: transparent;
}

.graph-zoom-btn:hover {
    color: var(--brand);
    border-color: var(--brand);
    background: var(--brand-muted);
    transform: scale(1.1);
}

.graph-zoom-btn:active {
    transform: scale(0.9);
}

/* ---- Graph Responsive ---- */
@media (max-width: 768px) {
    .graph-toolbar {
        padding: 12px 16px;
        gap: 10px;
    }

    .graph-toolbar-left {
        flex-direction: column;
        gap: 8px;
        width: 100%;
    }

    .graph-filter-group {
        width: 100%;
    }

    .graph-filter-group select {
        width: 100%;
        min-width: unset;
        min-height: 44px;
    }

    .graph-toolbar-right {
        width: 100%;
        justify-content: flex-end;
    }

    .graph-legend {
        padding: 6px 16px;
        gap: 10px;
    }

    .legend-item,
    .legend-edge {
        font-size: 10px;
    }

    .graph-detail-panel {
        bottom: 8px;
        left: 8px;
        right: 8px;
        width: auto;
        max-width: none;
    }

    .graph-zoom-controls {
        bottom: 8px;
        right: 8px;
    }

    .graph-page {
        height: calc(100vh - 56px);
    }
}

@media (max-width: 480px) {
    .graph-toolbar {
        padding: 10px 12px;
    }

    .graph-filter-group label {
        font-size: 9px;
    }

    .graph-btn {
        width: 36px;
        height: 36px;
    }

    .graph-legend {
        padding: 6px 12px;
        gap: 8px;
    }

    .graph-zoom-btn {
        width: 32px;
        height: 32px;
    }

    .graph-detail-header h4 {
        font-size: 14px;
    }
}

/* RTL support for graph page */
[dir="rtl"] .graph-detail-panel,
html[dir="rtl"] .graph-detail-panel {
    left: auto;
    right: 16px;
}

[dir="rtl"] .graph-zoom-controls,
html[dir="rtl"] .graph-zoom-controls {
    right: auto;
    left: 16px;
}

@media (max-width: 768px) {
    [dir="rtl"] .graph-detail-panel,
    html[dir="rtl"] .graph-detail-panel {
        left: 8px;
        right: 8px;
    }

    [dir="rtl"] .graph-zoom-controls,
    html[dir="rtl"] .graph-zoom-controls {
        left: 8px;
        right: auto;
    }
}
