/* CTs SuperTree — application shell.
 *
 * Two columns: a fixed-ish sidebar carrying the brand, the active view's header,
 * search, and its panels; and a main column carrying the tab bar and the graph.
 * The brand bar and the tab bar share one band height so they align across the
 * split. Everything else is given to the graph pane.
 */

:root {
    --bg: #eef2f7;
    --pane-bg: #ffffff;   /* the graph canvas itself */
    --panel: #ffffff;
    --border: #d8dee8;
    --border-soft: #eef1f6;
    --text: #18212f;
    --muted: #657287;
    --accent: #155eef;
    --accent-soft: #edf2ff;

    --band-height: 56px;
    --sidebar-width: clamp(240px, 15%, 320px);
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    /* Pin the single row to the viewport; without this the row is `auto` and
       tall sidebar content stretches it, pushing the graph pane off-screen. */
    grid-template-rows: minmax(0, 100%);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system,
        BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: var(--bg);
    overflow: hidden;
}

button, input { font: inherit; }

/* ---- sidebar ----------------------------------------------------------- */

#sidebar {
    display: grid;
    grid-template-rows: var(--band-height) auto auto auto minmax(0, 1fr);
    min-width: 0;
    background: var(--panel);
    border-right: 1px solid var(--border);
}

#brandBar {
    display: flex;
    align-items: center;
    padding: 0 14px;
    border-bottom: 1px solid var(--border);
}

#siteTitle {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#viewHeader { padding: 13px 14px 11px; }

#viewTitle {
    margin: 0 0 4px;
    font-size: 15px;
    font-weight: 650;
    line-height: 1.25;
    letter-spacing: -0.005em;
}

#viewDescription {
    margin: 0;
    color: var(--muted);
    font-size: 11.5px;
    line-height: 1.45;
}

#searchWrap {
    position: relative;
    padding: 0 14px 12px;
}

#searchInput {
    width: 100%;
    height: 34px;
    padding: 0 32px 0 11px;
    border: 1px solid var(--border);
    border-radius: 9px;
    outline: none;
    background: #fbfcfe;
    font-size: 12.5px;
}

#searchInput:focus {
    border-color: #8ca9fb;
    box-shadow: 0 0 0 3px rgba(21, 94, 239, 0.12);
}

#searchButton {
    position: absolute;
    top: 0;
    right: 17px;
    width: 30px;
    height: 34px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}
#searchButton:hover { color: var(--text); }

.search-hint {
    margin: 5px 0 0;
    color: var(--muted);
    font-size: 10.5px;
    line-height: 1.3;
}
.search-hint kbd {
    display: inline-block;
    padding: 0 4px;
    border: 1px solid var(--border);
    border-bottom-width: 2px;
    border-radius: 4px;
    background: #f7f9fc;
    color: #46536d;
    font-family: inherit;
    font-size: 9.5px;
    line-height: 15px;
}

#viewFilters:empty { display: none; }
#viewFilters {
    padding: 0 14px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    border-top: 1px solid var(--border-soft);
    padding-top: 11px;
}
.filter-field { display: flex; flex-direction: column; gap: 3px; }
.filter-field > label {
    color: var(--muted); font-size: 10px; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.05em;
}
.filter-field > select {
    width: 100%; height: 30px; padding: 0 8px;
    border: 1px solid var(--border); border-radius: 8px;
    background: #fbfcfe; color: var(--text); font-size: 11.5px; cursor: pointer;
}
.filter-field > select:focus-visible { outline: 2px solid var(--accent); outline-offset: -1px; }
.filter-note { color: var(--muted); font-size: 10.5px; line-height: 1.4; }

#panelScroller {
    /* Positioned so child offsetTop is measured against this box, which is what
       lets a node click scroll the details panel to the top of the viewport. */
    position: relative;
    min-height: 0;
    overflow-y: auto;
    padding: 0 14px 16px;
    border-top: 1px solid var(--border-soft);
}

/* ---- main column ------------------------------------------------------- */

#main {
    display: grid;
    grid-template-rows: var(--band-height) minmax(0, 1fr);
    min-width: 0;
}

#tabBar {
    display: flex;
    align-items: flex-end;
    gap: 3px;
    padding: 0 14px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
}

.tab {
    flex: 0 0 auto;
    height: 36px;
    padding: 0 15px;
    border: 1px solid transparent;
    border-bottom: 0;
    border-radius: 9px 9px 0 0;
    background: transparent;
    color: #46536d;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
}
.tab:hover { background: #f2f5fa; }
.tab.active {
    background: var(--pane-bg);
    border-color: var(--border);
    color: var(--accent);
    font-weight: 650;
    box-shadow: 0 1px 0 var(--pane-bg);
}
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

#paneStack {
    position: relative;
    min-height: 0;
    background:
        radial-gradient(circle at 35% 20%, #ffffff 0, #f7f9fc 42%, #eef2f7 100%);
}

/* The minimap's geometry is shared: on the sources tab the legend stacks
   directly beneath it, so both derive from one pair of values. */
.graph-pane {
    position: absolute; inset: 0; display: none;
    --minimap-top: 14px;
    --minimap-h: min(360px, 45%);
}
.graph-pane.active { display: block; }

.cy-host { position: absolute; inset: 0; background: var(--pane-bg); }

/* Per-node decorations a view paints itself (e.g. label-count rays), kept out
   of the graph model so they never affect traversal, search, or hit-testing. */
.node-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 4;
}

/* ---- text tab ---------------------------------------------------------- */
/* A pane with no graph. The pane markup is unchanged, so the graph furniture is
   hidden here rather than special-cased at every call site. */
.doc-pane .minimap,
.doc-pane .status-badge,
.doc-pane .legend,
.doc-pane .node-overlay { display: none; }
.doc-pane .cy-host { overflow-y: auto; }

body[data-view-kind="doc"] #searchWrap,
body[data-view-kind="doc"] #panelScroller { display: none; }

.doc {
    max-width: 720px;
    margin: 0 auto;
    padding: 30px 28px 56px;
    color: var(--text);
    font-size: 13.5px;
    line-height: 1.6;
}
.doc h1 { margin: 0 0 14px; font-size: 25px; font-weight: 750; letter-spacing: -0.01em; }
.doc h2 {
    margin: 30px 0 10px; padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
    font-size: 11px; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.06em; color: #4f5b70;
}
.doc h3 { margin: 0 0 3px; font-size: 13.5px; font-weight: 700; }
.doc p { margin: 0 0 12px; }
.doc a { color: var(--accent); overflow-wrap: anywhere; }
.doc-repo { color: var(--muted); font-size: 12.5px; }
.doc-item { margin-bottom: 14px; }
.doc-item p { margin: 0; color: #46536d; }

/* ---- graph overlays ---------------------------------------------------- */

.status-badge:empty { display: none; }
.status-badge {
    position: absolute;
    left: 14px;
    top: 14px;
    max-width: 60%;
    padding: 7px 10px;
    border: 1px solid rgba(204, 212, 224, 0.95);
    border-radius: 9px;
    background: rgba(255, 255, 255, 0.94);
    color: #445168;
    font-size: 11px;
    z-index: 6;
}

.legend {
    position: absolute;
    left: 50%;
    bottom: 14px;
    transform: translateX(-50%);
    width: 90%;
    padding: 10px 14px;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    column-gap: 18px;
    row-gap: 3px;
    border: 1px solid rgba(204, 212, 224, 0.95);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 8px 30px rgba(49, 67, 92, 0.10);
    backdrop-filter: blur(7px);
    z-index: 6;
}
body[data-legend="top"] .legend { top: 14px; bottom: auto; }

.legend-title { grid-column: 1 / -1; margin-bottom: 3px; font-size: 12px; font-weight: 700; }
/* A second heading inside one legend, so a view can group its channels
   (fill, size) instead of running every key together in one list. */
.legend-subhead {
    grid-column: 1 / -1; margin: 7px 0 2px;
    font-size: 11.5px; font-weight: 700; color: #2b3647;
}
.legend-row {
    display: flex; align-items: center; gap: 9px; margin: 2px 0;
    color: #364258; font-size: 11px; line-height: 1.25;
}
.legend-note {
    grid-column: 1 / -1; margin-top: 5px; padding-top: 7px;
    border-top: 1px solid #e3e7ee; color: var(--muted);
    font-size: 10.5px; line-height: 1.35;
}

/* Legends describe node color only; edge styling is explained in .legend-note. */
.dot { flex: 0 0 auto; width: 13px; height: 13px; border-radius: 50%; }

/* Legend marks that mirror Cytoscape node shapes and the diverging ramp. */
.swatch { flex: 0 0 auto; display: inline-block; width: 13px; height: 13px; background: #6b7280; }
.swatch.circle { border-radius: 50%; }
/* A source slot, shaped like the bar segment it stands for. */
.swatch.slot {
    width: 11px; height: 13px; border-radius: 1px;
    border: 1px solid rgba(75, 85, 99, 0.3);
}

.slot-no {
    flex: 0 0 auto; min-width: 12px; text-align: right;
    color: var(--muted); font-size: 9.5px; font-variant-numeric: tabular-nums;
}
td.slot-no { width: 18px; }

.chip-row { display: flex; flex-wrap: wrap; gap: 5px; }
.src-chip {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 2px 7px 2px 4px;
    border: 1px solid var(--border); border-radius: 999px;
    background: #fff; font-size: 10.5px; white-space: nowrap;
}
.src-chip .swatch.slot { width: 9px; height: 11px; }
.swatch.hollow { background: #fff; border: 1.5px solid #9aa3b0; }
/* Size marks for the HLCA legend: membership in the comparison is shown by
   node size, so the legend says so with two dots rather than a colour. */
.swatch.size-big { width: 13px; height: 13px; border-radius: 50%; background: #7B1FA2; }
.swatch.size-small { width: 6px; height: 6px; border-radius: 50%; background: #8A8F98; margin: 0 3px; }
.swatch.square { border-radius: 1px; }
.swatch.diamond { transform: rotate(45deg); border-radius: 1px; }
.swatch.sizes { width: auto; height: 13px; background: none; display: inline-flex; align-items: center; gap: 3px; }
.swatch.sizes i { display: block; background: #6b7280; border-radius: 50%; }
.swatch.sizes i:nth-child(1) { width: 5px; height: 5px; }
.swatch.sizes i:nth-child(2) { width: 8px; height: 8px; }
.swatch.sizes i:nth-child(3) { width: 12px; height: 12px; }

.legend-row.ramp-row { grid-column: 1 / -1; align-items: center; }
/* A key whose text is a sentence takes the full width rather than one
   column, so it reads on a single line. */
.legend-row.wide-key { grid-column: 1 / -1; }
.legend-row.wide-key span { white-space: nowrap; }
.ramp {
    flex: 0 0 auto; width: 132px; height: 10px; border-radius: 3px;
    border: 1px solid rgba(75, 85, 99, 0.35);
}
.ramp-ends { color: #46536d; }

/* Overview + detail. Portrait, because the supertree is a tall narrow ribbon
   (~1:2.7) — a landscape box would leave most of itself empty. Top-right,
   since the legend owns the bottom of the pane. Sized so that it plus the
   legend beneath it still clear the bottom on a short viewport. */
.minimap {
    position: absolute;
    top: var(--minimap-top);
    right: 14px;
    width: 200px;
    height: var(--minimap-h);
    border: 1px solid rgba(204, 212, 224, 0.95);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 8px 30px rgba(49, 67, 92, 0.10);
    backdrop-filter: blur(7px);
    overflow: hidden;
    cursor: crosshair;
    touch-action: none;
    z-index: 7;
}
.minimap canvas { display: block; width: 100%; height: 100%; }

/* Sits above the canvas, so its clicks never reach the pan/zoom handlers. */
.minimap-reset {
    position: absolute;
    top: 6px;
    left: 6px;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.92);
    cursor: pointer;
    z-index: 2;
}
.minimap-reset:hover { background: #eef2fb; border-color: #a6baf2; }
.minimap-reset:active { background: #e3eafb; }
.minimap-reset:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.minimap-reset img { display: block; width: 14px; height: 14px; }

@media (max-width: 900px) {
    .minimap { display: none; }
}

.view-status {
    position: absolute; inset: 0; z-index: 8;
    display: flex; align-items: center; justify-content: center;
    color: var(--muted); font-size: 13px; background: var(--pane-bg);
}
.view-status.hidden { display: none; }
.view-status.error { color: #b42318; }

#tooltip {
    position: fixed; display: none; max-width: 340px; padding: 9px 11px;
    border: 1px solid #cfd6e2; border-radius: 9px;
    background: rgba(20, 28, 40, 0.96); color: #fff;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.22);
    font-size: 11.5px; line-height: 1.35; pointer-events: none; z-index: 30;
}
.tooltip-title { font-weight: 700; margin-bottom: 3px; }
.tooltip-muted { color: #c7d0dc; }

/* ---- panel content ----------------------------------------------------- */

.card {
    margin-top: 12px;
    padding: 11px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
}

.card-title {
    margin: 0 0 8px;
    color: #4f5b70;
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
/* A title written as a sentence, so it keeps the capitalization it was given
   instead of being shouted. Still a heading: same color, weight and size. */
.card-title.as-written {
    text-transform: none;
    letter-spacing: 0.01em;
    font-size: 11px;
}

/* A title that carries its own count, pushed to the right edge of the card so
   the heading answers "how many" without a sentence underneath it. */
.card-title.with-count { display: flex; align-items: baseline; gap: 8px; }
.card-title .title-count {
    margin-left: auto;
    color: var(--text);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0;
}

.kpi-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.kpi { padding: 8px; border-radius: 8px; background: #f4f7fb; }
.kpi-value { font-size: 16px; font-weight: 750; font-variant-numeric: tabular-nums; }
.kpi-label { margin-top: 1px; color: var(--muted); font-size: 10px; line-height: 1.3; }

.detail-grid {
    display: grid; grid-template-columns: 40% minmax(0, 1fr);
    gap: 6px 8px; font-size: 11px;
}
.detail-key { color: var(--muted); font-size: 10.5px; }
/* Key column sized to its longest label rather than a flat 40%, so each row is
   one line: label on the left, its count immediately after, nothing wrapping. */
.detail-grid.key-fit { grid-template-columns: max-content auto; }
.detail-grid.key-fit .detail-key,
.detail-grid.key-fit .detail-value { white-space: nowrap; }
.detail-value { overflow-wrap: anywhere; color: #263247; font-variant-numeric: tabular-nums; }

.path-box, .list-box {
    margin-top: 7px; padding: 7px 8px; border-radius: 7px;
    background: #f6f8fb; color: #334057; font-size: 10.5px;
    line-height: 1.45; overflow-wrap: anywhere;
}

.empty-state {
    margin-top: 12px;
    padding: 16px 12px; border: 1px dashed #ccd4e0; border-radius: 10px;
    color: var(--muted); font-size: 12px; line-height: 1.5; text-align: center;
}

/* ---- panel tables ------------------------------------------------------ */

.scroll-box {
    max-height: 190px; overflow: auto;
    border: 1px solid var(--border); border-radius: 8px; background: #fff;
    overscroll-behavior: contain;
}
.scroll-box.short { max-height: 150px; }

.panel-table { width: 100%; border-collapse: collapse; font-size: 10.5px; }
.panel-table th {
    position: sticky; top: 0; z-index: 1;
    padding: 5px 7px; background: #f7f9fc; color: var(--muted);
    font-size: 10px; font-weight: 700; text-align: left; white-space: nowrap;
    border-bottom: 1px solid var(--border);
}
.panel-table td {
    padding: 4px 7px; color: #263247; vertical-align: top;
    border-bottom: 1px solid var(--border-soft);
}
.panel-table tbody tr:last-child td { border-bottom: 0; }
.panel-table tbody tr:hover td { background: #f7f9fc; }
.panel-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.panel-table.nowrap th, .panel-table.nowrap td { white-space: nowrap; }

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 10.5px; }

.subcard-label {
    display: flex; align-items: center; gap: 6px;
    margin: 0 0 6px; color: var(--muted); font-size: 10.5px; line-height: 1.35;
}

.tag { flex: 0 0 auto; padding: 1px 6px; border-radius: 999px; font-size: 9.5px; font-weight: 700; }
.tag.inc { background: #e7f6ec; color: #1a7f37; }
.tag.exc { background: #fdeced; color: #b42318; }

.source-details {
    margin-top: 6px; border: 1px solid var(--border);
    border-radius: 8px; background: #fff; overflow: hidden;
}
.source-details > summary {
    display: flex; align-items: center; justify-content: space-between; gap: 7px;
    padding: 6px 8px; font-size: 11.5px; cursor: pointer; list-style: none;
}
.source-details > summary::-webkit-details-marker { display: none; }
.source-details > summary::before {
    content: "▸"; flex: 0 0 auto; color: var(--muted); font-size: 9px;
}
.source-details[open] > summary::before { content: "▾"; }
.source-details > summary:hover { background: #f4f7fb; }
.source-details > summary > span:first-of-type {
    flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.source-details .scroll-box { border: 0; border-top: 1px solid var(--border); border-radius: 0; }

.details-empty {
    padding: 8px; color: var(--muted); font-size: 10.5px; line-height: 1.4;
    border-top: 1px solid var(--border);
}

/* ---- source slots (the sources view) ----------------------------------- */
/* The legend reproduces a single node's bar rather than listing swatches: the
   slots sit in their painted order with the same thin gaps, and each source
   name runs downwards from its own slot. */
.slot-key {
    grid-column: 1 / -1;
    display: flex; align-items: flex-start; gap: 2px; margin-top: 4px;
}
/* The slots share out the card's width rather than carrying a fixed one, so
   the bar always spans exactly as far as the minimap above it. */
.slot-key-cell {
    flex: 1 1 0; min-width: 0;
    display: flex; flex-direction: column; align-items: center;
}
.slot-key-swatch { flex: 0 0 auto; width: 100%; height: 18px; }
/* Rotated a further half turn so each name reads bottom to top. The boxes stay
   hung from their slot, so a name still ends flush against the colour it
   labels and the mapping survives the flip. */
.slot-key-name {
    margin-top: 5px; writing-mode: vertical-rl; transform: rotate(180deg);
    white-space: nowrap;
    color: #364258; font-size: 10px; line-height: 1.1;
}
.legend-subline {
    display: block; margin-top: 2px;
    font-weight: 400; font-size: 10.5px; color: var(--muted);
}
/* This view has no scope control, so the legend takes that slot instead: same
   width, same right edge, same card treatment, directly under the minimap, so
   the two read as one stack. */
body[data-view-kind="sources"] .legend {
    left: auto; right: 14px; bottom: auto;
    top: calc(var(--minimap-top) + var(--minimap-h) + 10px);
    transform: none;
    width: 200px;
    padding: 9px 10px 10px;
    border-radius: 10px;
    grid-template-columns: auto;
    column-gap: 0;
}

/* The sidebar is narrow, so a table can be fixed to the width available with
   its headings wrapping, rather than table-layout:auto letting one long
   heading push the last column out of view. */
.panel-table.wrap-head { table-layout: fixed; width: 100%; }
.panel-table.wrap-head th { white-space: normal; line-height: 1.2; }
/* Four columns in a 185px sidebar: the label column takes what its longest
   entry needs and never wraps, so a glyph and its word stay together, and the
   numeric columns are trimmed to fit their own headers. Padding and header
   type are reduced here only, because the default leaves ~50px too little. */
.panel-table.wrap-head col.c-label { width: 28%; }
.panel-table.wrap-head col.c-a     { width: 14%; }
.panel-table.wrap-head col.c-b     { width: 32%; }
.panel-table.wrap-head col.c-c     { width: 26%; }
.panel-table.wrap-head td:first-child { white-space: nowrap; }
.panel-table.wrap-head th { font-size: 9px; letter-spacing: 0; }
.panel-table.wrap-head th,
.panel-table.wrap-head td { padding-left: 2px; padding-right: 2px; }

/* Modality heading inside the sources table. */
.panel-table .group-row td {
    padding-top: 7px;
    background: #f7f9fc;
    color: #4f5b70; font-size: 9.5px; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.04em;
    white-space: normal; line-height: 1.25;
}

@media (prefers-reduced-motion: reduce) {
    * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
