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

body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif; }

/* SQL Highlighting */
.sql-hl .sql-kw { color: #7c3aed; font-weight: 600; }
.sql-hl .sql-str { color: #059669; }
.sql-hl .sql-num { color: #2563eb; }
.sql-hl .sql-comment { color: #9ca3af; font-style: italic; }

/* ── Tree Layout ── */
.tree-container {
    font-family: "SF Mono", "Monaco", "Menlo", monospace;
    font-size: 0.82rem;
    overflow-x: auto;
    padding: 8px 0;
}

/* Vertical flow: each wrapper stacks, children indented with line connectors */
.tree-node-wrapper {
    position: relative;
    padding-left: 32px;
    margin: 4px 0;
}

.tree-container > .tree-node-wrapper {
    padding-left: 0;
}

/* Vertical connector line from parent to children */
.tree-node-wrapper::before {
    content: "";
    position: absolute;
    left: 8px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: #e5e7eb;
}
.tree-container > .tree-node-wrapper::before { display: none; }

/* Horizontal connector from vertical line to node */
.tree-node {
    position: relative;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 8px 10px;
    min-width: 260px;
    max-width: 440px;
    display: inline-block;
    transition: box-shadow 0.2s, border-color 0.2s;
}

.tree-node::before {
    content: "";
    position: absolute;
    left: -25px;
    top: 16px;
    width: 18px;
    height: 2px;
    background: #e5e7eb;
}
.tree-container > .tree-node-wrapper > .tree-node::before { display: none; }

.tree-node:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    border-color: #93c5fd;
}

/* Severity color borders based on time percentage */
.tree-node[style*="--node-pct"] {
    border-left-width: 3px;
}
.tree-node {
    --pct: 0;
    border-left: 3px solid #e5e7eb;
}
/* These use inline style overrides */

/* Bottleneck path */
.tree-node.bottleneck {
    border-left: 3px solid #dc2626 !important;
    background: rgba(220, 38, 38, 0.03);
}

/* Node header - op type + table */
.tree-node-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
}
.tree-op-icon { font-size: 0.9rem; flex-shrink: 0; }
.tree-op-type { font-weight: 700; color: #1a1a2e; }
.tree-op-table { color: #2563eb; font-weight: 500; }
.tree-op-cte { color: #9333ea; font-size: 0.75rem; background: #f3e8ff; padding: 1px 5px; border-radius: 3px; }

/* Node stats grid */
.tree-node-stats { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.tree-stat-row { display: flex; gap: 4px; font-size: 0.73rem; }
.tree-stat-label { color: #9ca3af; }
.tree-stat-value { font-weight: 500; color: #374151; }
.tree-stat-value.critical { color: #dc2626; }
.tree-stat-value.warning  { color: #d97706; }
.tree-stat-value.ok       { color: #16a34a; }
.tree-stat-cond { flex-basis: 100%; }
.tree-stat-cond .tree-stat-value {
    color: #6b7280;
    font-size: 0.7rem;
    max-width: 380px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-style: italic;
}

/* Misestimate badge */
.tree-misestimate {
    font-size: 0.65rem;
    color: #d97706;
    background: #fef3c7;
    padding: 0 3px;
    border-radius: 2px;
    margin-left: 4px;
    cursor: help;
}

/* Time bar at bottom of node */
.tree-time-bar {
    margin-top: 6px;
    height: 4px;
    background: #f3f4f6;
    border-radius: 2px;
    position: relative;
}
.tree-time-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.5s ease;
    min-width: 2px;
}
.tree-time-fill.critical { background: #dc2626; }
.tree-time-fill.warning  { background: #d97706; }
.tree-time-fill.ok       { background: #60a5fa; }
.tree-time-label {
    position: absolute;
    right: -32px;
    top: -5px;
    font-size: 0.65rem;
    color: #9ca3af;
}

/* Warnings */
.tree-node-warning {
    font-size: 0.68rem;
    color: #d97706;
    margin-top: 4px;
    padding: 2px 6px;
    background: #fffbeb;
    border-radius: 3px;
}

/* Severity-driven left border */
.node-sev-0 { border-left-color: #60a5fa !important; }
.node-sev-1 { border-left-color: #d97706 !important; }
.node-sev-2 { border-left-color: #dc2626 !important; }

/* Compare page scrollbars */
.compare-panel::-webkit-scrollbar { height: 6px; }
.compare-panel::-webkit-scrollbar-track { background: #f1f1f1; border-radius: 3px; }
.compare-panel::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }

@media (max-width: 768px) {
    .tree-node-wrapper { padding-left: 20px; }
    .tree-node { max-width: 100%; min-width: auto; }
    .tree-node::before { left: -13px; width: 8px; }
}
