/* ===== CSS Custom Properties ===== */
:root {
    --color-primary: #7147e8;
    --color-primary-light: #ede5ff;
    --color-primary-dark: #5a35c4;
    --color-secondary: #4c8bf5;
    --color-secondary-light: #e3eeff;
    --color-bg: #f8f9fb;
    --color-card-bg: #ffffff;
    --color-border: #e0e4ea;
    --color-text: #292d32;
    --color-text-secondary: #6b7280;
    --color-text-muted: #9ca3af;
    --color-pipeline: #ff7a45;
    --color-pipeline-light: #fff2ec;
    --color-dashboard: #36b37e;
    --color-dashboard-light: #e6f9f0;
    --color-tag-pk: #dcfce7;
    --color-tag-pk-text: #166534;
    --color-tag-fk: #fef3c7;
    --color-tag-fk-text: #92400e;
    --color-hover: #f3f4f6;
    --color-column-highlight: rgba(76, 139, 245, 0.08);

    --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-card-hover: 0 4px 12px rgba(0, 0, 0, 0.12);
    --shadow-card-drag: 0 8px 24px rgba(0, 0, 0, 0.16);

    --radius-card: 8px;
    --radius-tag: 4px;
    --radius-btn: 6px;

    --toolbar-height: 48px;
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* ===== Reset & Base ===== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: var(--font-family);
    font-size: 13px;
    color: var(--color-text);
    background: var(--color-bg);
    -webkit-font-smoothing: antialiased;
}

/* ===== Toolbar ===== */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--toolbar-height);
    padding: 0 16px;
    background: #fff;
    border-bottom: 1px solid var(--color-border);
    z-index: 100;
    position: relative;
}

.toolbar__left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.toolbar__logo {
    color: var(--color-primary);
}

.toolbar__title {
    font-size: 15px;
    font-weight: 600;
    color: var(--color-text);
}

.toolbar__actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.toolbar__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-btn);
    background: #fff;
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
}

.toolbar__btn:hover {
    background: var(--color-hover);
    color: var(--color-text);
    border-color: #ccc;
}

.toolbar__btn--text {
    width: auto;
    padding: 0 10px;
    font-size: 12px;
    font-weight: 500;
}

.toolbar__zoom-level {
    font-size: 12px;
    font-weight: 500;
    color: var(--color-text-secondary);
    min-width: 40px;
    text-align: center;
    user-select: none;
}

.toolbar__separator {
    width: 1px;
    height: 20px;
    background: var(--color-border);
    margin: 0 6px;
}

/* ===== Graph Container ===== */
.graph-container {
    width: 100%;
    height: calc(100vh - var(--toolbar-height));
    overflow: hidden;
    position: relative;
    cursor: grab;
    background:
        radial-gradient(circle, var(--color-border) 1px, transparent 1px);
    background-size: 24px 24px;
}

.graph-container.is-panning {
    cursor: grabbing;
}

.transform-layer {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: 0 0;
    will-change: transform;
}

/* ===== Edge Layer (SVG) ===== */
.edge-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 1px;
    height: 1px;
    overflow: visible;
    pointer-events: none;
    z-index: 1;
}

/* ===== Node Layer ===== */
.node-layer {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 2;
}

/* ===== Edge Paths ===== */
.edge {
    fill: none;
    stroke: var(--color-primary);
    stroke-width: 2;
    stroke-opacity: 0.5;
    marker-end: url(#arrowhead);
    transition: stroke-opacity 0.2s ease, stroke-width 0.2s ease;
}

.edge:hover {
    stroke-opacity: 1;
    stroke-width: 2.5;
}

.edge--column {
    stroke: var(--color-secondary);
    stroke-width: 1.5;
    stroke-opacity: 0.6;
    marker-end: url(#arrowhead-column);
}

.edge--highlighted {
    stroke-opacity: 1;
    stroke-width: 3;
    filter: url(#edge-glow);
}

.edge--column.edge--highlighted {
    stroke-width: 2.5;
}

.edge--dimmed {
    stroke-opacity: 0.12;
}

/* ===== Node Base ===== */
.node {
    position: absolute;
    background: var(--color-card-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
    cursor: default;
    user-select: none;
    transition: box-shadow 0.2s ease;
    overflow: visible;
}

.node:hover {
    box-shadow: var(--shadow-card-hover);
}

.node.is-dragging {
    box-shadow: var(--shadow-card-drag);
    z-index: 10;
    opacity: 0.95;
}

.node.is-highlighted {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px var(--color-primary-light), var(--shadow-card-hover);
}

.node.is-dimmed {
    opacity: 0.4;
}

/* ===== Node Header ===== */
.node__header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    cursor: grab;
    border-bottom: 1px solid transparent;
}

.node--expanded .node__header {
    border-bottom-color: var(--color-border);
}

.node.is-dragging .node__header {
    cursor: grabbing;
}

.node__icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.node__icon svg {
    width: 16px;
    height: 16px;
}

.node__label {
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.node__badge {
    font-size: 11px;
    color: var(--color-text-muted);
    white-space: nowrap;
    flex-shrink: 0;
}

.node__expand-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--color-text-secondary);
    cursor: pointer;
    font-size: 10px;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.node__expand-btn:hover {
    background: var(--color-hover);
    color: var(--color-text);
}

.node--expanded .node__expand-btn {
    transform: rotate(180deg);
}

/* ===== Node Subtitle ===== */
.node__subtitle {
    padding: 0 12px 8px;
    font-size: 11px;
    color: var(--color-text-muted);
}

/* ===== Node Type: Table ===== */
.node--table {
    border-left: 3px solid var(--color-primary);
    width: 260px;
}

/* ===== Node Type: Pipeline ===== */
.node--pipeline {
    border-left: 3px solid var(--color-pipeline);
    width: 200px;
}

.node--pipeline .node__icon {
    color: var(--color-pipeline);
}

/* ===== Node Type: Dashboard ===== */
.node--dashboard {
    border-left: 3px solid var(--color-dashboard);
    width: 220px;
}

.node--dashboard .node__icon {
    color: var(--color-dashboard);
}

/* ===== Dashboard Charts ===== */
.node__charts {
    padding: 4px 12px 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.node__chart-pill {
    font-size: 10px;
    padding: 2px 8px;
    background: var(--color-dashboard-light);
    color: var(--color-dashboard);
    border-radius: 10px;
    white-space: nowrap;
    font-weight: 500;
}

/* ===== Column List ===== */
.node__columns {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.25s ease;
}

.node--expanded .node__columns {
    max-height: 300px;
    overflow: visible;
}

.node__columns::-webkit-scrollbar {
    width: 4px;
}

.node__columns::-webkit-scrollbar-track {
    background: transparent;
}

.node__columns::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 2px;
}

.node__column {
    display: flex;
    align-items: center;
    padding: 4px 12px;
    gap: 6px;
    position: relative;
    transition: background 0.1s ease;
    cursor: pointer;
}

.node__column:hover {
    background: var(--color-hover);
}

.node__column.is-highlighted {
    background: var(--color-column-highlight);
}

.node__column:nth-child(even) {
    background: rgba(0, 0, 0, 0.015);
}

.node__column:nth-child(even):hover {
    background: var(--color-hover);
}

/* ===== Column Ports ===== */
.node__column-port {
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    border: 2px solid var(--color-secondary);
    background: #fff;
    top: 50%;
    transform: translateY(-50%);
    z-index: 3;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.node--expanded .node__column-port {
    opacity: 1;
}

.node__column-port--left {
    left: -5px;
}

.node__column-port--right {
    right: -5px;
}

.node__column-port.is-active {
    background: var(--color-secondary);
}

/* ===== Column Content ===== */
.node__column-name {
    font-size: 12px;
    color: var(--color-text);
    flex: 1;
    padding-left: 6px;
}

.node__column-type {
    font-size: 10px;
    color: var(--color-text-muted);
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
    flex-shrink: 0;
}

.node__column-tag {
    font-size: 9px;
    font-weight: 600;
    padding: 1px 5px;
    border-radius: var(--radius-tag);
    flex-shrink: 0;
}

.node__column-tag--pk {
    background: var(--color-tag-pk);
    color: var(--color-tag-pk-text);
}

.node__column-tag--fk {
    background: var(--color-tag-fk);
    color: var(--color-tag-fk-text);
}

/* ===== Pipeline Description ===== */
.node__description {
    padding: 0 12px 10px;
    font-size: 11px;
    color: var(--color-text-secondary);
    line-height: 1.4;
}

/* ===== System Group Boxes ===== */
.group-box {
    position: absolute;
    border: 1.5px dashed var(--color-border);
    border-radius: 12px;
    background: rgba(113, 71, 232, 0.02);
    pointer-events: none;
    z-index: 0;
}

.group-box__label {
    position: absolute;
    top: 4px;
    left: 12px;
    font-size: 11px;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ===== Minimap placeholder ===== */
/* (stretch goal) */
