/**
 * 𒈨𒁾 ME.DUB — Interactive Pattern Graph CSS
 * D3.js Force-Directed Graph Visualization
 */

/* ============================================
   Graph Container
   ============================================ */

.medub-graph-container {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--bg-primary);
}

.medub-graph-container svg {
    width: 100%;
    height: 100%;
    display: block;
}

/* ============================================
   Graph Toolbar
   ============================================ */

.medub-graph-toolbar {
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    z-index: 25;
    font-size: 11px;
}

.medub-graph-toolbar .graph-tb-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: 28px;
    padding: 0 10px;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 11px;
    font-weight: 500;
    font-family: inherit;
    transition: all 0.15s;
    white-space: nowrap;
}

.medub-graph-toolbar .graph-tb-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.medub-graph-toolbar .graph-tb-btn.active {
    background: var(--accent-light);
    color: var(--accent);
    border-color: var(--accent);
}

.medub-graph-toolbar .graph-tb-sep {
    width: 1px;
    height: 20px;
    background: var(--border-color);
    margin: 0 4px;
}

.medub-graph-toolbar .graph-tb-search {
    width: 140px;
    height: 28px;
    padding: 0 8px 0 28px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 11px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s;
}

.medub-graph-toolbar .graph-tb-search:focus {
    border-color: var(--accent);
}

.medub-graph-toolbar .graph-search-wrap {
    position: relative;
}

.medub-graph-toolbar .graph-search-wrap .search-icon {
    position: absolute;
    left: 8px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

/* Depth slider */
.medub-graph-toolbar .graph-depth-wrap {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 4px;
}

.medub-graph-toolbar .graph-depth-label {
    font-size: 10px;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.medub-graph-toolbar .graph-depth-val {
    font-size: 11px;
    color: var(--accent);
    font-weight: 700;
    min-width: 22px;
    text-align: center;
}

.medub-graph-toolbar input[type="range"] {
    width: 60px;
    height: 4px;
    accent-color: var(--accent);
    cursor: pointer;
}

/* ============================================
   Graph Nodes
   ============================================ */

.graph-node {
    cursor: pointer;
    transition: opacity 0.3s;
}

.graph-node circle {
    stroke: #fff;
    stroke-width: 1.5;
    transition: r 0.3s, stroke-width 0.2s, filter 0.3s;
}

.graph-node:hover circle {
    stroke-width: 3;
    filter: drop-shadow(0 0 8px rgba(0, 0, 0, 0.25));
}

.graph-node.selected circle {
    stroke: var(--accent);
    stroke-width: 3;
    filter: drop-shadow(0 0 10px var(--accent));
}

.graph-node.dimmed {
    opacity: 0.08;
    pointer-events: none;
}

.graph-node.highlighted circle {
    stroke-width: 3;
    filter: drop-shadow(0 0 12px currentColor);
}

.graph-node.path-node circle {
    stroke: #F59E0B;
    stroke-width: 3;
    filter: drop-shadow(0 0 10px #F59E0B);
}

.graph-node-label {
    font-size: 7px;
    font-weight: 700;
    fill: #fff;
    text-anchor: middle;
    pointer-events: none;
    opacity: 1;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

/* Larger text when zoomed in */
.graph-labels-visible .graph-node-label {
    opacity: 1;
}

/* ============================================
   Graph Links
   ============================================ */

.graph-link {
    stroke: var(--border-color);
    stroke-opacity: 0.12;
    stroke-width: 1;
    transition: stroke-opacity 0.3s, stroke 0.3s, stroke-width 0.3s;
}

.graph-link.highlighted {
    stroke: var(--accent);
    stroke-opacity: 0.6;
    stroke-width: 2;
}

.graph-link.path-link {
    stroke: #F59E0B;
    stroke-opacity: 0.8;
    stroke-width: 3;
    stroke-dasharray: 8 4;
    animation: graph-path-dash 1s linear infinite;
}

@keyframes graph-path-dash {
    to {
        stroke-dashoffset: -12;
    }
}

.graph-link.dimmed {
    stroke-opacity: 0.03;
}

/* ============================================
   Tooltip
   ============================================ */

.graph-tooltip {
    position: absolute;
    padding: 8px 12px;
    background: rgba(15, 15, 20, 0.9);
    color: #fff;
    border-radius: var(--radius-md);
    font-size: 11px;
    pointer-events: none;
    z-index: 50;
    backdrop-filter: blur(8px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    max-width: 240px;
    line-height: 1.4;
    transform: translate(-50%, -100%);
    margin-top: -12px;
    opacity: 0;
    transition: opacity 0.15s;
}

.graph-tooltip.visible {
    opacity: 1;
}

.graph-tooltip .tt-num {
    font-weight: 700;
    color: #F59E0B;
    margin-right: 4px;
}

.graph-tooltip .tt-title {
    font-weight: 600;
}

.graph-tooltip .tt-scale {
    font-size: 9px;
    color: rgba(255, 255, 255, 0.6);
    margin-top: 2px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.graph-tooltip .tt-connections {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.5);
    margin-top: 2px;
}

/* ============================================
   Detail Popover (on click)
   ============================================ */

.graph-popover {
    position: absolute;
    width: 300px;
    max-height: 420px;
    overflow-y: auto;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    z-index: 40;
    font-size: 12px;
    animation: popover-in 0.2s ease;
}

@keyframes popover-in {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(8px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.graph-popover::-webkit-scrollbar {
    width: 4px;
}

.graph-popover::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.graph-popover-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.graph-popover-title {
    font-weight: 700;
    font-size: 13px;
    color: var(--text-primary);
}

.graph-popover-num {
    font-weight: 700;
    font-size: 12px;
    color: var(--accent);
    margin-right: 6px;
}

.graph-popover-close {
    width: 24px;
    height: 24px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.graph-popover-close:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
}

.graph-popover-body {
    padding: 12px 14px;
}

.graph-popover-scale {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-size: 10px;
    font-weight: 600;
    margin-bottom: 8px;
}

.graph-popover-scale.town {
    background: #FEF3C7;
    color: #92400E;
}

.graph-popover-scale.building {
    background: #D1FAE5;
    color: #065F46;
}

.graph-popover-scale.construction {
    background: #DBEAFE;
    color: #1E40AF;
}

.graph-popover-section {
    margin-bottom: 10px;
}

.graph-popover-section-title {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.graph-popover-section-text {
    color: var(--text-secondary);
    line-height: 1.5;
    font-size: 11px;
}

.graph-popover-connections {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 4px;
}

.graph-popover-conn-chip {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-size: 10px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-secondary);
    transition: all 0.15s;
}

.graph-popover-conn-chip:hover {
    background: var(--accent-light);
    color: var(--accent);
    border-color: var(--accent);
}

.graph-popover-conn-chip.up {
    border-left: 3px solid #F59E0B;
}

.graph-popover-conn-chip.down {
    border-left: 3px solid #3B82F6;
}

.graph-popover-actions {
    display: flex;
    gap: 6px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border-color);
}

.graph-popover-actions button {
    flex: 1;
    height: 28px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-size: 10px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s;
}

.graph-popover-actions button:hover {
    background: var(--accent-light);
    color: var(--accent);
    border-color: var(--accent);
}

.graph-popover-actions button.primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.graph-popover-actions button.primary:hover {
    background: var(--accent-hover);
}

/* ============================================
   Legend
   ============================================ */

.graph-legend {
    position: absolute;
    bottom: 38px;
    left: 12px;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 6px 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    z-index: 25;
    font-size: 10px;
    color: var(--text-secondary);
}

.graph-legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
}

.graph-legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 1.5px solid rgba(0, 0, 0, 0.1);
}

/* ============================================
   Stats bar
   ============================================ */

.graph-stats {
    position: absolute;
    bottom: 38px;
    right: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    z-index: 25;
    font-size: 10px;
    color: var(--text-muted);
}

.graph-stats span {
    font-weight: 600;
}

/* ============================================
   Loading overlay
   ============================================ */

.graph-loading {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    z-index: 30;
    gap: 12px;
}

.graph-loading-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: graph-spin 0.8s linear infinite;
}

@keyframes graph-spin {
    to {
        transform: rotate(360deg);
    }
}

.graph-loading-text {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

.graph-loading-progress {
    width: 200px;
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: 2px;
    overflow: hidden;
}

.graph-loading-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 0.3s;
}

/* ============================================
   Right-Click Context Menu
   ============================================ */

.graph-ctx-menu {
    position: absolute;
    min-width: 190px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12), 0 1px 4px rgba(0, 0, 0, 0.06);
    z-index: 60;
    padding: 4px;
    animation: ctx-in 0.12s ease;
}

@keyframes ctx-in {
    from {
        opacity: 0;
        transform: scale(0.96) translateY(4px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.graph-ctx-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 7px 10px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-primary);
    font-size: 11px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.12s;
    text-align: left;
}

.graph-ctx-item:hover {
    background: var(--bg-tertiary);
    color: var(--accent);
}

.graph-ctx-item svg {
    flex-shrink: 0;
    width: 14px;
    height: 14px;
    color: var(--text-secondary);
}

.graph-ctx-item:hover svg {
    color: var(--accent);
}

/* ============================================
   Style Inspector Panel
   ============================================ */

.graph-inspector {
    position: absolute;
    top: 48px;
    right: 0;
    width: 240px;
    height: calc(100% - 86px);
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.08);
    z-index: 30;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.25s ease;
    overflow: hidden;
}

.graph-inspector.open {
    transform: translateX(0);
}

.graph-inspector-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    flex-shrink: 0;
}

.graph-inspector-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.graph-inspector-close {
    width: 22px;
    height: 22px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: all 0.15s;
}

.graph-inspector-close:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
}

.graph-inspector-body {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px 16px;
}

.graph-inspector-body::-webkit-scrollbar {
    width: 4px;
}

.graph-inspector-body::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

/* Section */
.gi-section {
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
}

.gi-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.gi-section-title {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 8px;
}

/* Row layout */
.gi-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.gi-row:last-child {
    margin-bottom: 0;
}

.gi-row label {
    flex: 1;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
}

/* Color picker */
.gi-row input[type="color"] {
    width: 28px;
    height: 22px;
    padding: 0;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: none;
    cursor: pointer;
    flex-shrink: 0;
}

.gi-row input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 2px;
}

.gi-row input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 2px;
}

/* Range slider */
.gi-row input[type="range"] {
    flex: 1;
    height: 4px;
    accent-color: var(--accent);
    cursor: pointer;
    max-width: 80px;
}

.gi-val {
    font-size: 10px;
    font-weight: 600;
    color: var(--accent);
    min-width: 24px;
    text-align: right;
}