:root {
    --bg: #0d1117;
    --surface: #151b24;
    --surface-muted: #11161e;
    --text: #e6edf3;
    --text-muted: #9aa4b2;
    --border: #2a3340;
    --accent: #58a6ff;
    --accent-hover: #79b8ff;
    --accent-soft: rgba(88, 166, 255, 0.14);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
    --row-hover: #1f2835;
    --table-header-bg: #21262d;
    --table-header-text: #e6edf3;
    --graph-bg-start: #151b24;
    --graph-bg-end: #0d1117;
    --graph-loading-bg: rgba(13, 17, 23, 0.88);
    --legend-swatch-border: rgba(255, 255, 255, 0.12);
    --error-bg: #2d1517;
    --error-border: #6e3039;
    --error-text: #ff8e98;
    --radius: 10px;
    --sidebar-width: min(420px, 36vw);
    --font: "Inter", system-ui, -apple-system, sans-serif;
    --mobile-bar-height: 0px;
    color-scheme: dark;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    height: 100%;
}

body {
    margin: 0;
    height: 100%;
    overflow: hidden;
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.app {
    display: flex;
    height: 100dvh;
    overflow: hidden;
}

.mobile-bar {
    display: none;
}

.sidebar {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    width: var(--sidebar-width);
    min-width: 300px;
    height: 100%;
    overflow: hidden;
    background: var(--surface);
    border-right: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.tabs {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    flex-shrink: 0;
    padding: 12px 12px 0;
    border-bottom: 1px solid var(--border);
}

.tab {
    appearance: none;
    border: 1px solid transparent;
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    background: transparent;
    color: var(--text-muted);
    font: inherit;
    font-weight: 500;
    padding: 10px 14px;
    cursor: pointer;
    transition: color 0.15s ease, background 0.15s ease;
}

.tab:hover {
    color: var(--accent);
}

.tab.active {
    color: var(--text);
    background: var(--surface-muted);
    border-color: var(--border);
}

.sidebar-panels {
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.panel {
    display: none;
    flex-direction: column;
    gap: 12px;
    height: 100%;
    min-height: 0;
    padding: 16px;
    overflow: hidden;
    background: var(--surface-muted);
}

#panel-legend {
    overflow: auto;
}

.panel.active {
    display: flex;
}

.panel-header {
    flex-shrink: 0;
}

.panel-header h2 {
    margin: 0 0 4px;
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.panel-header p {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.8125rem;
    line-height: 1.4;
}

.search-field {
    flex-shrink: 0;
}

.search-field input {
    width: 100%;
    padding: 8px 11px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 0.875rem;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.search-field input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.table-scroll {
    flex: 1 1 auto;
    min-height: 0;
    max-height: 100%;
    overflow: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.table-scroll--fit {
    flex: 0 0 auto;
    max-height: none;
    overflow: visible;
    align-self: flex-start;
    width: 100%;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

th,
td {
    padding: 7px 10px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

#nodeTable td:nth-child(2),
#nodeTable td:nth-child(3),
#nodeTable th:nth-child(2),
#nodeTable th:nth-child(3) {
    width: 2.75rem;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

#legendTable th:last-child,
#legendTable td:last-child {
    width: 4rem;
}

th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--table-header-bg);
    color: var(--table-header-text);
    font-size: 0.71875rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

tbody tr:last-child td {
    border-bottom: none;
}

tbody tr {
    cursor: pointer;
    transition: background 0.12s ease;
}

tbody tr:hover {
    background: var(--row-hover);
}

.sort-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    font-size: inherit;
    font-weight: inherit;
    letter-spacing: inherit;
    text-transform: inherit;
    cursor: pointer;
}

.sort-icon {
    fill: currentColor;
    opacity: 0.7;
    transition: transform 0.15s ease;
}

.sort-btn.ascending .sort-icon {
    transform: rotate(180deg);
}

.legend-swatch {
    width: 100%;
    min-width: 36px;
    height: 16px;
    border-radius: 3px;
    border: 1px solid var(--legend-swatch-border);
}

.graph-panel {
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    height: 100%;
    display: flex;
    background: radial-gradient(circle at top, var(--graph-bg-start) 0%, var(--graph-bg-end) 100%);
}

.graph {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    width: 100%;
    height: 100%;
}

.graph-loading {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: grid;
    place-items: center;
    color: var(--text-muted);
    font-weight: 500;
    background: var(--graph-loading-bg);
    backdrop-filter: blur(4px);
    pointer-events: none;
}

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

.graph-reset-btn {
    position: absolute;
    right: 16px;
    bottom: 16px;
    z-index: 3;
    appearance: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text-muted);
    font: inherit;
    font-size: 0.8125rem;
    font-weight: 500;
    padding: 8px 12px;
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.graph-reset-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-soft);
}

.graph-reset-btn.hidden {
    display: none;
}

.graph-error {
    max-width: 28rem;
    padding: 16px 20px;
    border: 1px solid var(--error-border);
    border-radius: var(--radius);
    background: var(--error-bg);
    color: var(--error-text);
    text-align: center;
}

@media (max-width: 900px) {
    :root {
        --mobile-bar-height: 52px;
    }

    .app {
        flex-direction: column;
    }

    .mobile-bar {
        display: flex;
        flex-shrink: 0;
        gap: 8px;
        height: var(--mobile-bar-height);
        padding: 8px 12px;
        background: var(--surface);
        border-bottom: 1px solid var(--border);
    }

    .view-btn {
        flex: 1;
        appearance: none;
        border: 1px solid var(--border);
        border-radius: 8px;
        background: var(--surface-muted);
        color: var(--text-muted);
        font: inherit;
        font-size: 0.875rem;
        font-weight: 500;
        padding: 8px 10px;
        cursor: pointer;
        transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
    }

    .view-btn.active {
        background: var(--accent-soft);
        border-color: var(--accent);
        color: var(--accent-hover);
    }

    .sidebar,
    .graph-panel {
        width: 100%;
        min-width: 0;
        height: auto;
    }

    .app.view-split .sidebar {
        flex: 0 0 42dvh;
        max-height: 42dvh;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .app.view-split .graph-panel {
        flex: 1 1 auto;
        min-height: 0;
    }

    .app.view-list .sidebar {
        flex: 1 1 auto;
        min-height: 0;
        max-height: none;
        border-bottom: none;
    }

    .app.view-list .graph-panel {
        display: none;
    }

    .app.view-graph .sidebar {
        display: none;
    }

    .app.view-graph .graph-panel {
        flex: 1 1 auto;
        min-height: 0;
    }

    .panel {
        padding: 16px;
    }

    .panel-header p {
        font-size: 0.8125rem;
    }
}
