/* ============================================================
   DIAGRAM.CSS — Diagram pane, tables, relations, legend
   ============================================================ */

/* ── Diagram pane ─────────────────────────────────────────── */

#diagram-pane {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: var(--bg-primary);
}

#diagram-container {
    position: relative;
    width: 100%;
    height: 100%;
    background: var(--bg-primary);
    background-image: 
        linear-gradient(var(--grid-color) 1px, transparent 1px),
        linear-gradient(90deg, var(--grid-color) 1px, transparent 1px);
    background-size: 20px 20px;
}

svg#diagram,
svg#yaml-diagram {
    width: 100%;
    height: 100%;
    cursor: grab;
    background: transparent;
}

svg#diagram:active,
svg#yaml-diagram:active {
    cursor: grabbing;
}

/* ── Tables ──────────────────────────────────────────────── */

.table-group {
    cursor: move;
}

.table-group:hover .table-rect {
    stroke: var(--accent);
    stroke-width: 2;
}

.table-group:hover .table-shadow {
    opacity: 0.4;
}

.table-shadow {
    fill: rgba(0,0,0,0.4);
    opacity: 0.3;
}

.table-rect {
    fill: var(--bg-card);
    stroke: var(--border);
    stroke-width: 1.5;
    rx: 8;
    ry: 8;
}

.table-header {
    fill: var(--accent);
}

.table-header-line {
    fill: #c73e54;
}

.table-name {
    fill: #fff;
    font-size: 13px;
    font-weight: 600;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    pointer-events: none;
}

.column-name {
    fill: var(--text-primary);
    font-size: 12px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    pointer-events: none;
}

.column-type {
    fill: var(--text-muted);
    font-size: 10px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    pointer-events: none;
}

.badge-pk-text {
    fill: var(--warning);
    font-size: 9px;
    font-weight: 600;
    font-family: -apple-system, BlinkMacSystemFont, sans-serif;
    pointer-events: none;
}

.badge-fk-text {
    fill: var(--primary);
    font-size: 9px;
    font-weight: 600;
    font-family: -apple-system, BlinkMacSystemFont, sans-serif;
    pointer-events: none;
}

/* Table glow effects (applied via JS) */
.table-group .table-rect {
    transition: stroke 0.2s, stroke-width 0.2s, filter 0.2s;
}

.table-group .table-header,
.table-group .table-header-line {
    transition: fill 0.2s;
}

.table-group .table-name {
    transition: fill 0.2s;
}

/* ── Relations ────────────────────────────────────────────── */

.relation-line {
    stroke: var(--text-muted);
    stroke-width: 2;
    fill: none;
    transition: stroke 0.2s, stroke-width 0.2s;
}

.relation-line:hover {
    stroke: var(--accent);
    stroke-width: 2.5;
}

.relation-label rect {
    fill: var(--bg-secondary);
    stroke: var(--border);
    stroke-width: 1;
    transition: fill 0.2s, stroke 0.2s;
}

.relation-label text {
    fill: var(--text-secondary);
    font-size: 10px;
    font-weight: 600;
    font-family: -apple-system, BlinkMacSystemFont, sans-serif;
    pointer-events: none;
}

/* ── Selected table ──────────────────────────────────────── */

.table-group.selected .table-rect {
    stroke: var(--success);
    stroke-width: 2.5;
}

.table-group.selected .table-header {
    fill: var(--success);
}

.table-group.selected .table-header-line {
    fill: #1e8449;
}

/* ── Legend ──────────────────────────────────────────────── */

#legend {
    position: absolute;
    bottom: 20px;
    left: 20px;
    background: rgba(27, 38, 59, 0.95);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 16px;
    font-size: 11px;
    z-index: 100;
}

#legend h4 {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#legend .item {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    color: var(--text-secondary);
}

#legend .item:last-child {
    margin-bottom: 0;
}

#legend .circle-outline {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 2px solid var(--text-muted);
}

#legend .many-dots {
    display: flex;
    gap: 2px;
}

#legend .many-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
}

#legend .line-indicator {
    width: 20px;
    height: 2px;
    background: var(--text-muted);
}

/* ── Help hint ───────────────────────────────────────────── */

#help-hint {
    position: absolute;
    bottom: 20px;
    right: 20px;
    background: rgba(27, 38, 59, 0.9);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 11px;
    color: var(--text-muted);
    z-index: 100;
}

#help-hint kbd {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 1px 5px;
    font-size: 10px;
    color: var(--text-secondary);
}
