/* bgview web app styles.
 *
 * One stylesheet for shell and report both, because unlike the Python
 * version there is no sandboxed iframe between them any more -- the report
 * is rendered into this document's DOM. That is safe here for a reason worth
 * stating: nothing off the analysed script ever becomes MARKUP. render.js
 * uses textContent and setAttribute exclusively, so a node named
 * `<img onerror=...>` is text, not an element.
 */

:root {
  color-scheme: dark;
  --bg: #14161a;
  --panel: #1b1e24;
  --panel-2: #1f242e;
  --edge: #2a2f38;
  --ink: #e6e8ec;
  --ink-dim: #9aa2ae;
  --accent: #7aa2f7;
  --info: #6cb6ff;
  --warn: #d7a13b;
  --error: #e06c75;
  --dataflow: #7aa2f7;
  --order: #d7a13b;
  --radius: 8px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#shell-header {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  padding: 12px 18px; border-bottom: 1px solid var(--edge);
  background: var(--panel); flex: 0 0 auto;
}
#shell-header h1 { margin: 0; font-size: 19px; letter-spacing: .4px; }
.tagline { margin: 2px 0 0; color: var(--ink-dim); font-size: 12.5px; max-width: 70ch; }

/* ------------------------------------------------------------- picker --- */
#picker {
  flex: 1 1 auto; overflow-y: auto;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 20px; padding: 30px 20px;
}
.card {
  width: min(680px, 100%); background: var(--panel);
  border: 1px solid var(--edge); border-radius: var(--radius); padding: 22px;
}
.card h2 { margin: 0 0 14px; font-size: 16px; font-weight: 600; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }

.btn {
  display: inline-block; padding: 8px 15px; border: 1px solid var(--edge);
  border-radius: 6px; background: #232833; color: var(--ink);
  font: inherit; cursor: pointer; transition: border-color 120ms, background 120ms;
}
.btn:hover { border-color: var(--accent); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #0d1017; font-weight: 600; }
.btn.choice {
  display: block; width: 100%; margin-top: 6px; text-align: left;
  font-family: ui-monospace, Consolas, monospace; font-size: 12.5px;
}

.hint { margin: 0 0 10px; color: var(--ink-dim); font-size: 12.5px; }
.status {
  margin: 0; padding: 8px 11px; border-radius: 6px; background: var(--panel-2);
  border: 1px solid var(--edge); font-size: 12.5px;
  font-family: ui-monospace, Consolas, monospace;
}
.status.busy { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }
@media (prefers-reduced-motion: reduce) { .status.busy { animation: none; } .btn { transition: none; } }

.choices { margin-top: 12px; }
.error {
  margin: 12px 0 0; padding: 9px 11px; border-radius: 6px;
  border: 1px solid var(--error); background: rgba(224,108,117,.09);
  font-family: ui-monospace, Consolas, monospace; font-size: 12px;
  white-space: pre-wrap; word-break: break-word;
}
.meta { width: min(680px, 100%); color: var(--ink-dim); font-size: 12px; }
.meta p { margin: 0; }
.meta code {
  font-family: ui-monospace, Consolas, monospace; background: var(--panel-2);
  border: 1px solid var(--edge); border-radius: 4px; padding: 1px 5px;
}

/* ------------------------------------------------------------- report --- */
.report { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }

.report-header {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 9px 16px; border-bottom: 1px solid var(--edge); background: var(--panel);
  flex: 0 0 auto; flex-wrap: wrap;
}
.report-title h2 { margin: 0; font-size: 15px; }
.title-meta { color: var(--ink-dim); font-size: 12px; }

.legend { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; font-size: 12px; color: var(--ink-dim); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.legend-wire { width: 22px; height: 0; border-top: 2px solid var(--dataflow); display: inline-block; }
.legend-wire.order { border-top-style: dashed; border-top-color: var(--order); }
.sev-info { background: var(--info); }
.sev-warn { background: var(--warn); }
.sev-error { background: var(--error); }

.report-body { flex: 1 1 auto; display: flex; min-height: 0; }

/* findings panel */
.findings-panel {
  width: 340px; flex: 0 0 auto; border-right: 1px solid var(--edge);
  background: var(--panel); display: flex; flex-direction: column; min-height: 0;
}
.filter-row { display: flex; gap: 6px; padding: 8px 10px; border-bottom: 1px solid var(--edge); }
.chip {
  padding: 4px 10px; border-radius: 999px; border: 1px solid var(--edge);
  background: transparent; color: var(--ink-dim); font: inherit; font-size: 12px; cursor: pointer;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #0d1017; font-weight: 600; }

.findings-list { overflow-y: auto; flex: 1 1 auto; }
.finding {
  padding: 8px 12px; border-bottom: 1px solid var(--edge); cursor: pointer;
  border-left: 3px solid transparent;
}
.finding:hover { background: var(--panel-2); }
.finding.sev-info { border-left-color: var(--info); }
.finding.sev-warn { border-left-color: var(--warn); }
.finding.sev-error { border-left-color: var(--error); }
/* Dimmed, never hidden: the severity filter already hides rows, and a second
   remover would make it impossible to tell which one acted. Dimmed rows stay
   clickable. */
.finding.dimmed { opacity: .34; }
.finding-head { display: flex; gap: 7px; align-items: baseline; font-size: 11px; }
.finding-sev { text-transform: uppercase; font-weight: 700; letter-spacing: .4px; }
.finding-sev.sev-info { background: none; color: var(--info); }
.finding-sev.sev-warn { background: none; color: var(--warn); }
.finding-sev.sev-error { background: none; color: var(--error); }
.finding-det { color: var(--ink-dim); font-family: ui-monospace, Consolas, monospace; }
.finding-loc { color: var(--ink-dim); margin-left: auto; font-family: ui-monospace, Consolas, monospace; }
.finding-msg { margin-top: 3px; font-size: 12.5px; }
.empty { padding: 18px; color: var(--ink-dim); font-size: 13px; }

/* panel toggles */
.panel-toggles { display: flex; gap: 6px; }
.toggle {
  padding: 4px 11px; border-radius: 6px; border: 1px solid var(--edge);
  background: transparent; color: var(--ink-dim); font: inherit; font-size: 12px; cursor: pointer;
}
.toggle:hover { border-color: var(--accent); }
.toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.toggle.on { background: var(--panel-2); color: var(--ink); border-color: #3a4250; }

/* details / inspector -- answers "what IS this node", which the graph can
   only gesture at: a box shows that an edge exists, not what rode along it. */
.details-panel {
  width: 320px; flex: 0 0 auto; border-left: 1px solid var(--edge);
  background: var(--panel); display: flex; flex-direction: column; min-height: 0;
}
.details-body { overflow-y: auto; padding: 12px 14px; }
.details-title {
  margin: 0 0 10px; font-size: 14px; font-family: ui-monospace, Consolas, monospace;
  word-break: break-word;
}
.details-meta {
  display: grid; grid-template-columns: auto 1fr; gap: 3px 10px;
  margin: 0 0 14px; font-size: 12px;
}
.details-meta dt { color: var(--ink-dim); }
.details-meta dd { margin: 0; font-family: ui-monospace, Consolas, monospace; word-break: break-word; }

.details-sec { margin-bottom: 13px; }
.details-sec h4 {
  margin: 0 0 5px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .5px; color: var(--ink-dim); font-weight: 600;
}
.details-sec .none { color: #5b6472; font-size: 12px; font-style: italic; }

.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.tagchip {
  padding: 2px 7px; border-radius: 4px; font-size: 11.5px;
  font-family: ui-monospace, Consolas, monospace; word-break: break-all;
  border: 1px solid var(--edge); background: var(--panel-2); color: var(--ink);
}
/* Colour follows DIRECTION, matching the graph's wires: what this node hands
   out vs what it takes in. Requires/After stay neutral -- they name nodes,
   not tags, and their tags already appear under Consumes. */
.tagchip.produces { border-color: #3f7d54; color: #8fd6a4; }
.tagchip.creates  { border-color: #3f6a7d; color: #8fc6d6; }
.tagchip.consumes { border-color: #6a5f8f; color: #b8aee0; }

.linky { cursor: pointer; }
.linky:hover { border-color: var(--accent); color: var(--accent); }
.details-meta dd.linky { text-decoration: underline dotted; }
.linky:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.details-finding {
  display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap;
  padding: 5px 0; border-top: 1px solid var(--edge); font-size: 11.5px; cursor: pointer;
}
.details-finding:hover { background: var(--panel-2); }
.details-finding-msg { flex: 1 1 100%; color: var(--ink); }

/* main pane */
.report-main { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.tabstrip { display: flex; gap: 2px; padding: 6px 10px 0; border-bottom: 1px solid var(--edge); background: var(--panel); }
.tab {
  padding: 6px 14px; border: 1px solid var(--edge); border-bottom: none;
  border-radius: 6px 6px 0 0; background: transparent; color: var(--ink-dim);
  font: inherit; font-size: 12.5px; cursor: pointer;
}
.tab.on { background: var(--bg); color: var(--ink); }

.graph-area { flex: 1 1 auto; overflow: hidden; position: relative; cursor: grab; }
.graph-area:active { cursor: grabbing; }
.graph { display: block; }

.lane-bg { fill: rgba(255,255,255,.022); stroke: var(--edge); stroke-width: 1; }
.lane-label { fill: var(--ink); font: 600 12px "Segoe UI", system-ui, sans-serif; }
.lane-meta { fill: var(--ink-dim); font: 10.5px "Segoe UI", system-ui, sans-serif; }

.edge { fill: none; stroke: var(--dataflow); stroke-width: 1.4; opacity: .55; }
.edge.order { stroke: var(--order); stroke-dasharray: 5 4; }
/* ONE treatment for incident edges: weight plus a halo. Direction already
   reads off the arrowhead, and colour/dash are spoken for by the edge KIND --
   overriding either would turn an After edge into what looks like proven
   dataflow. */
.edge.incident { opacity: 1; stroke-width: 2.4; filter: drop-shadow(0 0 4px currentColor); }
.arrowhead { fill: var(--dataflow); }
.arrowhead.order { fill: var(--order); }

.node { cursor: pointer; }
.node-box { fill: #262c37; stroke: #3a4250; stroke-width: 1.2; }
.node.warn .node-box { stroke: var(--warn); stroke-width: 1.8; }
.node.selected .node-box { stroke: var(--accent); stroke-width: 2.4; }
.node:focus-visible .node-box { stroke: var(--accent); }
.node-label { fill: var(--ink); font: 11.5px ui-monospace, Consolas, monospace; pointer-events: none; }

/* source view */
.source-area { flex: 1 1 auto; overflow: auto; background: var(--bg); }
.file-bar {
  position: sticky; top: 0; z-index: 2; display: flex; gap: 4px; flex-wrap: wrap;
  padding: 6px 10px; background: var(--panel); border-bottom: 1px solid var(--edge);
}
.file-tab {
  padding: 3px 9px; border: 1px solid var(--edge); border-radius: 5px;
  background: transparent; color: var(--ink-dim); font: inherit; font-size: 11.5px; cursor: pointer;
}
.file-tab.on { background: var(--panel-2); color: var(--ink); }

.code-wrap { font-family: ui-monospace, Consolas, "Cascadia Mono", monospace; font-size: 12.5px; }
.code-row { display: flex; align-items: stretch; line-height: 1.5; }
.code-row.row-info { background: rgba(108,182,255,.07); }
.code-row.row-warn { background: rgba(215,161,59,.09); }
.code-row.row-error { background: rgba(224,108,117,.10); }
.code-row.current { outline: 1px solid var(--accent); outline-offset: -1px; }
/* De-emphasis never touches .code-text -- readability is the view's whole
   job, so a muted row loses its tint, not its legibility. */
.code-row.muted { background: none; }

/* The selected node's WHOLE element, `<Node ...>` through `</Node>`. A node
   is a range, not a line: highlighting only the opening tag leaves the reader
   to work out where it ends. Drawn as a left rail plus a wash, so it reads as
   one block and still composes with the per-line severity tints underneath
   rather than replacing them. */
.code-row.span {
  background: rgba(122, 162, 247, .10);
  box-shadow: inset 3px 0 0 var(--accent);
}
.code-row.span.row-warn  { background: rgba(215, 161, 59, .13); }
.code-row.span.row-error { background: rgba(224, 108, 117, .14); }
.code-row.span-start { border-top: 1px solid rgba(122, 162, 247, .5); }
.code-row.span-end   { border-bottom: 1px solid rgba(122, 162, 247, .5); }
.code-row.span .line-no { color: var(--accent); }
.code-row.muted .gutter-dot { opacity: .3; }

/* Fixed width, sized for the worst case of three dots: the code column must
   start at the same x on every row or the file stops reading as code. */
.gutter { flex: 0 0 21px; display: flex; gap: 2px; align-items: center; padding-left: 3px; }
.gutter-dot { width: 5px; height: 5px; border-radius: 50%; cursor: help; align-self: center; }
.line-no {
  flex: 0 0 52px; text-align: right; padding-right: 10px;
  color: #5b6472; user-select: none;
}
.code-text { white-space: pre; padding-right: 16px; }

[hidden] { display: none !important; }

@media (max-width: 1100px) {
  .details-panel { width: 260px; }
}
@media (max-width: 900px) {
  .report-body { flex-direction: column; }
  .findings-panel, .details-panel {
    width: 100%; max-height: 34vh; border-right: none; border-left: none;
    border-bottom: 1px solid var(--edge);
  }
}
