:root {
      color-scheme: light;
      font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
      background: #eef1f5;
      color: #172033;
    }

    * { box-sizing: border-box; }

    body {
      margin: 0;
      min-height: 100vh;
      display: grid;
      grid-template-rows: auto 1fr;
      background: #eef1f5;
    }

    header {
      padding: 14px 18px;
      background: #fff;
      border-bottom: 1px solid #d6dce5;
      box-shadow: 0 1px 4px rgba(20, 30, 50, 0.08);
      z-index: 2;
    }

    h1 {
      margin: 0 0 10px;
      font-size: 18px;
      font-weight: 700;
    }

    .toolbar {
      display: grid;
      grid-template-columns: minmax(0, 1fr) auto;
      gap: 12px;
      align-items: start;
    }

    .filter-panels {
      display: grid;
      gap: 10px;
    }

    .filter-panel {
      padding: 10px;
      border: 1px solid #cfd6e1;
      border-radius: 10px;
      background: #f8fafc;
    }

    .filter-panel-title {
      margin: 0 0 8px;
      color: #3f4c61;
      font-size: 13px;
      font-weight: 750;
      text-transform: uppercase;
      letter-spacing: 0.04em;
    }

    .categories-all-row,
    .tags-controls {
      display: grid;
      grid-template-rows: minmax(0, 1fr) auto;
      gap: 8px;
      min-height: 0;
    }

    .tag-grid {
      display: flex;
      flex-wrap: wrap;
      align-content: flex-start;
      gap: 7px;
      min-height: 0;
      overflow-y: auto;
      padding-right: 4px;
    }

    .filter-panel[data-filter-kind="tags"] {
      min-height: 0;
      overflow: hidden;
    }

    .category-grid {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
      gap: 8px;
      margin-top: 8px;
    }

    .category-card {
      display: grid;
      gap: 5px;
      align-content: start;
      padding: 7px;
      border: 1px solid #d7dde7;
      border-radius: 8px;
      background: #fff;
    }

    .category-card button {
      width: 100%;
      text-align: left;
    }

    .category-card button[data-level="group"] {
      font-weight: 700;
      background: #edf2f8;
    }

    button {
      appearance: none;
      border: 1px solid #aeb8c7;
      border-radius: 7px;
      background: #f7f9fc;
      color: #172033;
      padding: 7px 11px;
      font: inherit;
      font-size: 13px;
      cursor: pointer;
    }

    button:hover { background: #e8edf5; }

    button.active {
      border-color: #285ea8;
      background: #285ea8;
      color: #fff;
    }

    .status {
      align-self: start;
      padding: 8px 10px;
      border-radius: 8px;
      background: #eef3f8;
      color: #566174;
      font-size: 13px;
      white-space: nowrap;
    }

    button.action-green {
      border-color: #2f7d44;
      background: #2f8f4e;
      color: #fff;
      font-weight: 700;
    }

    button.action-green:hover {
      background: #267b42;
    }

    button.action-green.active {
      border-color: #1f6d38;
      background: #1f7d40;
      color: #fff;
    }

    .toolbar-separator {
      width: 1px;
      height: 28px;
      margin: 0 3px;
      background: #cfd6e1;
    }

    .toolbar-label {
      color: #566174;
      font-size: 13px;
      font-weight: 600;
    }

    button[data-tag].active {
      border-color: #7b4f00;
      background: #f2b84b;
      color: #2f2107;
    }

    button[data-level="subgroup"] {
      padding: 6px 9px;
      font-size: 12px;
      background: #fafbfd;
    }

    #diagram svg path.flowchart-link {
      stroke-width: 4px !important;
    }
    #diagram svg marker path {
      stroke-width: 1.5px !important;
    }

    #diagram svg g.node image {
      filter: drop-shadow(0 2px 3px rgba(20, 30, 50, 0.28));
    }

    #diagram svg g.node.selected-node image {
      filter:
        drop-shadow(0 0 2px #1f5fae)
        drop-shadow(0 0 7px rgba(31, 95, 174, 0.9));
    }

    #diagram svg g.node.tag-match image {
      filter:
        drop-shadow(0 0 2px #9a6500)
        drop-shadow(0 0 8px rgba(242, 184, 75, 0.95));
    }

    #diagram svg g.node.tag-match .label text,
    #diagram svg g.node.tag-match .label span {
      fill: #6d4600 !important;
      color: #6d4600 !important;
      font-weight: 800 !important;
    }

    #diagram svg g.node {
      cursor: pointer;
    }

    #diagram svg g.node > rect.node-background {
      fill: #ffffff !important;
      stroke: #728198 !important;
      stroke-width: 2px !important;
      rx: 10px;
      ry: 10px;
      filter: drop-shadow(0 3px 5px rgba(20, 30, 50, 0.22));
      transition: fill 120ms ease, stroke 120ms ease, stroke-width 120ms ease;
    }

    #diagram svg g.node:hover > rect.node-background {
      fill: #f2f7ff !important;
      stroke: #285ea8 !important;
      stroke-width: 3px !important;
    }

    #diagram svg g.node.selected-info-node > rect.node-background {
      fill: #dcecff !important;
      stroke: #174f93 !important;
      stroke-width: 5px !important;
    }

    #diagram svg g.node.selected-node > rect.node-background {
      fill: #e8f2ff !important;
      stroke: #1f5fae !important;
      stroke-width: 3px !important;
    }

    #diagram svg g.node.tag-match > rect.node-background {
      fill: #fff0bd !important;
      stroke: #b57600 !important;
      stroke-width: 5px !important;
    }

    #diagram svg g.node.selected-info-node.tag-match > rect.node-background {
      fill: #ffe4a5 !important;
      stroke: #174f93 !important;
      stroke-width: 5px !important;
    }

    .node-card-content {
      width: 100%;
      padding: 9px 10px 10px;
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 8px;
      color: #172033;
      font-family: Inter, ui-sans-serif, system-ui, sans-serif;
      font-size: 15px;
      font-weight: 700;
      line-height: 1.2;
      text-align: center;
      user-select: none;
      box-sizing: border-box;
    }

    .node-card-content span {
      display: block;
      width: 100%;
      min-height: calc(var(--graph-card-label-font-size) * 2.4);
      white-space: normal;
      overflow: visible;
      overflow-wrap: normal;
      word-break: normal;
    }

    .node-card-content img {
      width: 72px;
      height: 72px;
      display: block;
      object-fit: contain;
      border-radius: 6px;
    }

    #diagram svg g.cluster .cluster-label {
      display: block !important;
    }

    #diagram svg g.cluster.subgroup-cluster > rect {
      fill: #ffffff !important;
      stroke: #a8b3c3 !important;
      stroke-width: 2px !important;
      stroke-dasharray: 10 7;
      filter: none;
    }

    #diagram svg g.cluster.subgroup-cluster.selected-cluster > rect {
      fill: #e8f2ff !important;
      stroke: #1f5fae !important;
      stroke-width: 4px !important;
      stroke-dasharray: none;
    }


    #info-panel {
      min-height: 0;
      overflow: auto;
      border: 1px solid #cbd3df;
      border-radius: 10px;
      background: #fff;
      padding: 18px;
      box-shadow: 0 2px 7px rgba(20, 30, 50, 0.08);
    }

    #info-panel h2 {
      margin: 0 0 18px;
      font-size: 22px;
      line-height: 1.2;
      color: #172033;
    }

    #info-panel h3 {
      margin: 20px 0 8px;
      padding-bottom: 5px;
      border-bottom: 1px solid #d9dfe8;
      font-size: 15px;
      color: #344158;
    }

    #info-panel ul {
      margin: 0;
      padding-left: 20px;
    }

    #info-panel li {
      margin: 5px 0;
      line-height: 1.35;
    }

    #info-panel .empty {
      margin: 0;
      color: #7a8495;
      font-style: italic;
    }

    #info-panel .prompt {
      margin: 0;
      color: #657086;
      line-height: 1.5;
    }

    @media (max-width: 900px) {
      main {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(500px, 70vh) auto;
      }

      #info-panel {
        max-height: 36vh;
      }
    }

    main {
      min-height: 0;
      padding: 12px;
      display: grid;
      grid-template-columns: minmax(0, 1fr) 320px;
      gap: 14px;
    }

    #viewport {
      position: relative;
      width: 100%;
      height: 100%;
      min-height: 500px;
      overflow: hidden;
      border: 1px solid #cbd3df;
      border-radius: 10px;
      background: #fff;
    }

    #diagram {
      width: 100%;
      height: 100%;
    }

    #diagram svg {
      width: 100%;
      height: 100%;
      max-width: none !important;
      display: block;
    }

    #viewport,
    #diagram,
    #diagram svg,
    #diagram svg * {
      -webkit-user-select: none;
      user-select: none;
    }

    #viewport {
      touch-action: none;
    }

    #viewport.graph-panning {
      cursor: grabbing;
    }

    #viewport.graph-panning #diagram,
    #viewport.graph-panning #diagram svg,
    #viewport.graph-panning #diagram svg * {
      cursor: grabbing !important;
    }

    #loading, #error {
      position: absolute;
      inset: 0;
      display: grid;
      place-items: center;
      padding: 30px;
      text-align: center;
      background: rgba(255, 255, 255, 0.94);
      z-index: 3;
    }

    #error {
      display: none;
      color: #8b1e1e;
      white-space: pre-wrap;
      font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
      font-size: 13px;
    }


    #diagram svg g.cluster rect {
      fill: #f8fafc !important;
      stroke: #8491a6 !important;
      stroke-width: 3px !important;
      rx: 12px;
      ry: 12px;
      filter: drop-shadow(0 5px 7px rgba(28, 39, 58, 0.18));
    }

    #diagram svg g.cluster .cluster-label text,
    #diagram svg g.cluster .cluster-label span {
      font-weight: 700 !important;
      fill: #27364c !important;
      color: #27364c !important;
    }

    #diagram svg g.node rect,
    #diagram svg g.node polygon,
    #diagram svg g.node circle,
    #diagram svg g.node ellipse {
      transition: fill 120ms ease, stroke 120ms ease, stroke-width 120ms ease;
    }

    #diagram svg g.cluster.selected-cluster rect {
      fill: #dcecff !important;
      stroke: #1f5fae !important;
      stroke-width: 5px !important;
      filter: drop-shadow(0 6px 10px rgba(31, 95, 174, 0.32));
    }

    #diagram svg g.cluster.selected-cluster .cluster-label text,
    #diagram svg g.cluster.selected-cluster .cluster-label span {
      fill: #123f77 !important;
      color: #123f77 !important;
    }

    #diagram svg g.node.selected-node rect,
    #diagram svg g.node.selected-node polygon,
    #diagram svg g.node.selected-node circle,
    #diagram svg g.node.selected-node ellipse {
      fill: #c9e1ff !important;
      stroke: #1f5fae !important;
      stroke-width: 3px !important;
    }

    #diagram svg g.node.selected-node .label text,
    #diagram svg g.node.selected-node .label span {
      fill: #102f56 !important;
      color: #102f56 !important;
      font-weight: 700 !important;
    }

    .hint {
      position: absolute;
      left: 12px;
      bottom: 10px;
      z-index: 2;
      padding: 5px 8px;
      border-radius: 5px;
      background: rgba(255, 255, 255, 0.88);
      color: #657086;
      font-size: 12px;
      pointer-events: none;
    }
  
    :root {
      color-scheme: dark;
      --bg: #111827;
      --panel: #1f2937;
      --panel-2: #273449;
      --border: #475569;
      --text: #f8fafc;
      --muted: #cbd5e1;
      --button: #334155;
      --button-hover: #475569;
      --button-selected: #2563eb;
      --button-selected-text: #ffffff;
      --accent: #16a34a;
      --accent-hover: #15803d;
    }

    body {
      background: var(--bg) !important;
      color: var(--text) !important;
    }

    .filters-panel {
      margin: 12px;
      border: 1px solid var(--border);
      border-radius: 12px;
      background: var(--panel);
      overflow: hidden;
      box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
    }

    .filters-panel > summary {
      cursor: pointer;
      padding: 12px 16px;
      font-size: 18px;
      font-weight: 800;
      color: var(--text);
      background: #182235;
      user-select: none;
    }

    .filters-panel > summary:hover {
      background: #202d43;
    }

    .filters-content {
      display: grid;
      grid-template-columns: repeat(2, minmax(0, 1fr));
      gap: 12px;
      padding: 12px;
    }

    .filter-panel,
    .category-subpanel {
      background: var(--panel-2);
      border: 1px solid var(--border);
      color: var(--text);
    }

    .filter-panel {
      border-radius: 10px;
      padding: 12px;
    }

    .filter-panel h2,
    .filter-panel h3 {
      color: var(--text);
    }

    .category-subpanel {
      border-radius: 8px;
      padding: 8px;
    }

    button {
      background: var(--button);
      color: var(--text);
      border: 1px solid #64748b;
    }

    button:hover {
      background: var(--button-hover);
      color: #ffffff;
    }

    button.active,
    button.selected,
    button[aria-pressed="true"] {
      background: var(--button-selected) !important;
      color: var(--button-selected-text) !important;
      border-color: #60a5fa !important;
    }

    button.control-green,
    #allCategoriesButton,
    #clearTagsButton {
      background: var(--accent) !important;
      color: #ffffff !important;
      border-color: #4ade80 !important;
    }

    button.control-green:hover,
    #allCategoriesButton:hover,
    #clearTagsButton:hover {
      background: var(--accent-hover) !important;
    }

    #status,
    .status-text,
    #statusText {
      position: static !important;
      margin: 0 !important;
      padding: 0 !important;
      color: var(--muted) !important;
      background: transparent !important;
      border: 0 !important;
      box-shadow: none !important;
    }

    footer {
      min-height: 24px;
      padding: 8px 12px;
      color: var(--muted);
      background: #0b1220;
      border-top: 1px solid #334155;
      font-size: 12px;
    }

    @media (max-width: 900px) {
      .filters-content {
        grid-template-columns: 1fr;
      }
    }

  
    /* Final filter colour overrides */
    .filters-panel,
    .filters-content,
    .filter-panel,
    .category-grid,
    .tag-grid {
      background: #1f2937 !important;
      color: #f8fafc !important;
    }

    .filter-panel {
      border-color: #475569 !important;
    }

    .category-subpanel {
      background: #334155 !important;
      border: 1px solid #64748b !important;
      color: #f8fafc !important;
    }

    .category-subpanel button,
    .filter-panel button,
    .filters-panel button {
      background: #475569 !important;
      color: #f8fafc !important;
      border: 1px solid #64748b !important;
      box-shadow: none !important;
    }

    .category-subpanel button:hover,
    .filter-panel button:hover,
    .filters-panel button:hover {
      background: #5b6b82 !important;
      color: #ffffff !important;
      border-color: #94a3b8 !important;
    }

    /* Top-level category button: visually distinct from subgroup buttons */
    .category-subpanel > button:first-child,
    .category-subpanel .category-button,
    button[data-level="group"] {
      background: #243b53 !important;
      color: #ffffff !important;
      border-color: #7aa2cc !important;
      font-weight: 800 !important;
    }

    .category-subpanel > button:first-child:hover,
    .category-subpanel .category-button:hover,
    button[data-level="group"]:hover {
      background: #304f70 !important;
    }

    /* Selected states */
    .category-subpanel button.active,
    .category-subpanel button.selected,
    .category-subpanel button[aria-pressed="true"],
    .filter-panel button.active,
    .filter-panel button.selected,
    .filter-panel button[aria-pressed="true"],
    .filters-panel button.active,
    .filters-panel button.selected,
    .filters-panel button[aria-pressed="true"] {
      background: #2563eb !important;
      color: #ffffff !important;
      border-color: #93c5fd !important;
    }

    /* Green action buttons remain green */
    #allCategoriesButton,
    #clearTagsButton,
    .control-green {
      background: #16a34a !important;
      color: #ffffff !important;
      border-color: #4ade80 !important;
      font-weight: 800 !important;
    }

    #allCategoriesButton:hover,
    #clearTagsButton:hover,
    .control-green:hover {
      background: #15803d !important;
      color: #ffffff !important;
    }

  
    /* Complete application-wide dark theme */
    :root {
      color-scheme: dark;
      --app-bg: #0f172a;
      --surface-1: #111827;
      --surface-2: #1e293b;
      --surface-3: #273449;
      --surface-4: #334155;
      --border-dark: #475569;
      --border-light: #64748b;
      --text-primary: #f8fafc;
      --text-secondary: #cbd5e1;
      --text-muted: #94a3b8;
      --blue: #2563eb;
      --blue-hover: #1d4ed8;
      --green: #16a34a;
      --green-hover: #15803d;
    }

    html,
    body {
      background: var(--app-bg) !important;
      color: var(--text-primary) !important;
    }

    body,
    main,
    #app,
    .app,
    .page,
    .page-shell,
    .content,
    .main-content,
    .workspace,
    .graph-and-info,
    .graph-section {
      background: var(--app-bg) !important;
      color: var(--text-primary) !important;
    }

    /* Graph viewport/canvas */
    #graph,
    #graphContainer,
    #diagram,
    #diagramContainer,
    #mermaidGraph,
    .graph-container,
    .diagram-container,
    .mermaid-container,
    .svg-container,
    .pan-zoom-container {
      background: var(--surface-1) !important;
      color: var(--text-primary) !important;
      border-color: var(--border-dark) !important;
    }

    #graph svg,
    #graphContainer svg,
    #diagram svg,
    #diagramContainer svg,
    .graph-container svg,
    .diagram-container svg,
    .mermaid-container svg {
      background: var(--surface-1) !important;
    }

    /* Mermaid top-level and nested cluster panels */
    svg g.cluster rect,
    svg .cluster rect,
    g.cluster > rect,
    .cluster rect,
    g.cluster.subgroup-cluster > rect,
    g.cluster.subgroup-cluster rect {
      fill: var(--surface-2) !important;
      stroke: var(--border-light) !important;
    }

    svg g.cluster.subgroup-cluster rect,
    svg .subgroup-cluster rect {
      fill: var(--surface-3) !important;
      stroke: #7890ad !important;
    }

    svg .cluster-label,
    svg .cluster-label text,
    svg .cluster-label span {
      fill: var(--text-primary) !important;
      color: var(--text-primary) !important;
    }

    /* Mermaid node cards */
    svg g.node rect.node-background {
      fill: var(--surface-4) !important;
      stroke: #7890ad !important;
    }

    .node-card-content,
    .node-card,
    foreignObject .node-card-content,
    foreignObject .node-card {
      background: var(--surface-4) !important;
      color: var(--text-primary) !important;
    }

    .node-card-content span,
    .node-card span,
    svg .nodeLabel,
    svg .nodeLabel p,
    svg .nodeLabel span {
      color: var(--text-primary) !important;
      fill: var(--text-primary) !important;
    }

    /* Graph edges and arrow markers */
    svg .flowchart-link,
    svg .edgePath path,
    svg path.path {
      stroke: #94a3b8 !important;
    }

    svg marker path,
    svg .arrowheadPath {
      fill: #94a3b8 !important;
      stroke: #94a3b8 !important;
    }

    /* Information/description panel */
    #infoPanel,
    #descriptionPanel,
    #detailsPanel,
    .info-panel,
    .description-panel,
    .details-panel,
    aside {
      background: var(--surface-2) !important;
      color: var(--text-primary) !important;
      border-color: var(--border-dark) !important;
    }

    #infoPanel *,
    #descriptionPanel *,
    #detailsPanel *,
    .info-panel *,
    .description-panel *,
    .details-panel *,
    aside * {
      color: inherit;
    }

    #infoPanel h1,
    #infoPanel h2,
    #infoPanel h3,
    #descriptionPanel h1,
    #descriptionPanel h2,
    #descriptionPanel h3,
    #detailsPanel h1,
    #detailsPanel h2,
    #detailsPanel h3,
    .info-panel h1,
    .info-panel h2,
    .info-panel h3 {
      color: var(--text-primary) !important;
    }

    #infoPanel p,
    #infoPanel li,
    #descriptionPanel p,
    #descriptionPanel li,
    #detailsPanel p,
    #detailsPanel li,
    .info-panel p,
    .info-panel li,
    .description-panel p,
    .description-panel li {
      color: var(--text-secondary) !important;
    }

    /* Filters and all nested panels */
    .filters-panel {
      background: var(--surface-1) !important;
      border-color: var(--border-dark) !important;
      color: var(--text-primary) !important;
    }

    .filters-panel > summary {
      background: #172033 !important;
      color: var(--text-primary) !important;
    }

    .filters-panel > summary:hover {
      background: #202c42 !important;
    }

    .filters-content,
    .filter-panel,
    .categories-panel,
    .tags-panel {
      background: var(--surface-2) !important;
      color: var(--text-primary) !important;
      border-color: var(--border-dark) !important;
    }

    .category-grid,
    .tag-grid,
    .category-list,
    .tag-list {
      background: transparent !important;
    }

    .category-subpanel,
    .subcategory-panel,
    .subgraph-panel {
      background: var(--surface-3) !important;
      color: var(--text-primary) !important;
      border-color: var(--border-light) !important;
    }

    /* All controls */
    button,
    input,
    select,
    textarea {
      background: var(--surface-4) !important;
      color: var(--text-primary) !important;
      border-color: var(--border-light) !important;
    }

    button:hover {
      background: #40516a !important;
      color: #ffffff !important;
    }

    .category-subpanel > button:first-child,
    .category-subpanel .category-button,
    button[data-level="group"] {
      background: #243b53 !important;
      color: #ffffff !important;
      border-color: #7aa2cc !important;
    }

    button.active,
    button.selected,
    button[aria-pressed="true"] {
      background: var(--blue) !important;
      color: #ffffff !important;
      border-color: #93c5fd !important;
    }

    button.active:hover,
    button.selected:hover,
    button[aria-pressed="true"]:hover {
      background: var(--blue-hover) !important;
    }

    #allCategoriesButton,
    #clearTagsButton,
    .control-green {
      background: var(--green) !important;
      color: #ffffff !important;
      border-color: #4ade80 !important;
    }

    #allCategoriesButton:hover,
    #clearTagsButton:hover,
    .control-green:hover {
      background: var(--green-hover) !important;
    }

    /* Pan/zoom controls and helper copy */
    .svg-pan-zoom-control,
    .svg-pan-zoom-control-background,
    .pan-zoom-controls,
    .zoom-controls {
      fill: var(--surface-3) !important;
      background: var(--surface-3) !important;
      color: var(--text-primary) !important;
      stroke: var(--border-light) !important;
    }

    .svg-pan-zoom-control-element {
      fill: var(--text-primary) !important;
    }

    .helper-text,
    #helperText,
    .instructions,
    .graph-help {
      background: rgba(15, 23, 42, 0.92) !important;
      color: var(--text-secondary) !important;
      border-color: var(--border-dark) !important;
    }

    /* Footer/debug status */
    footer {
      background: #0b1220 !important;
      color: var(--text-muted) !important;
      border-color: #334155 !important;
    }

    footer *,
    #status,
    #statusText,
    .status-text {
      color: var(--text-muted) !important;
    }

    /* Neutralise legacy white/light surfaces */
    .panel,
    .card,
    .toolbar,
    .controls,
    .control-panel {
      color: var(--text-primary);
      border-color: var(--border-dark);
    }

  
    /* Definitive dark theme: exact selectors used by this document */
    :root {
      color-scheme: dark !important;
      background: #0f172a !important;
      color: #f8fafc !important;
    }

    html,
    body {
      background: #0f172a !important;
      color: #f8fafc !important;
    }

    header {
      background: #111827 !important;
      color: #f8fafc !important;
      border-bottom-color: #334155 !important;
      box-shadow: 0 1px 4px rgba(0, 0, 0, 0.45) !important;
    }

    h1,
    .filter-panel-title,
    .toolbar-label {
      color: #f8fafc !important;
    }

    main {
      background: #0f172a !important;
    }

    .filters-panel {
      background: #111827 !important;
      border-color: #475569 !important;
    }

    .filters-panel > summary {
      background: #172033 !important;
      color: #f8fafc !important;
    }

    .filters-content,
    .filter-panel {
      background: #1e293b !important;
      color: #f8fafc !important;
      border-color: #475569 !important;
    }

    .category-card {
      background: #273449 !important;
      color: #f8fafc !important;
      border-color: #64748b !important;
    }

    .category-card button,
    button[data-level="subgroup"],
    button[data-tag] {
      background: #334155 !important;
      color: #f8fafc !important;
      border-color: #64748b !important;
    }

    .category-card button[data-level="group"] {
      background: #243b53 !important;
      color: #ffffff !important;
      border-color: #7aa2cc !important;
      font-weight: 700 !important;
    }

    button:hover,
    .category-card button:hover,
    button[data-level="subgroup"]:hover,
    button[data-tag]:hover {
      background: #475569 !important;
      color: #ffffff !important;
    }

    button.active,
    button[data-tag].active,
    .category-card button.active {
      background: #2563eb !important;
      color: #ffffff !important;
      border-color: #93c5fd !important;
    }

    button.action-green,
    button.action-green.active {
      background: #16a34a !important;
      color: #ffffff !important;
      border-color: #4ade80 !important;
    }

    button.action-green:hover {
      background: #15803d !important;
    }

    #viewport {
      background: #111827 !important;
      border-color: #475569 !important;
    }

    #diagram,
    #diagram svg {
      background: #111827 !important;
    }

    #loading,
    #error {
      background: rgba(17, 24, 39, 0.96) !important;
      color: #f8fafc !important;
    }

    #info-panel {
      background: #1e293b !important;
      color: #f8fafc !important;
      border-color: #475569 !important;
      box-shadow: 0 2px 7px rgba(0, 0, 0, 0.32) !important;
    }

    #info-panel h2,
    #info-panel h3 {
      color: #f8fafc !important;
    }

    #info-panel h3 {
      border-bottom-color: #475569 !important;
    }

    #info-panel p,
    #info-panel li {
      color: #cbd5e1 !important;
    }

    #info-panel .empty,
    #info-panel .prompt {
      color: #94a3b8 !important;
    }

    #diagram svg g.cluster > rect {
      fill: #1e293b !important;
      stroke: #64748b !important;
    }

    #diagram svg g.cluster.subgroup-cluster > rect {
      fill: #273449 !important;
      stroke: #7890ad !important;
    }

    #diagram svg g.cluster.subgroup-cluster.selected-cluster > rect,
    #diagram svg g.cluster.selected-cluster > rect {
      fill: #243b53 !important;
      stroke: #60a5fa !important;
    }

    #diagram svg g.node > rect.node-background {
      fill: #334155 !important;
      stroke: #7890ad !important;
      filter: drop-shadow(0 3px 5px rgba(0, 0, 0, 0.38)) !important;
    }

    #diagram svg g.node:hover > rect.node-background {
      fill: #40516a !important;
      stroke: #60a5fa !important;
    }

    #diagram svg g.node.selected-info-node > rect,
    #diagram svg g.node.selected-info-node > polygon,
    #diagram svg g.node.selected-info-node > path,
    #diagram svg g.node.selected-node > rect.node-background {
      fill: #1e40af !important;
      stroke: #93c5fd !important;
    }

    #diagram svg g.node.tag-match > rect.node-background {
      fill: #78350f !important;
      stroke: #fbbf24 !important;
      stroke-width: 7px !important;
      stroke-dasharray: 14 7;
      vector-effect: non-scaling-stroke;
      filter:
        drop-shadow(0 0 3px #fbbf24)
        drop-shadow(0 0 9px rgb(245 158 11 / 95%));
    }

    #diagram svg g.node.tag-match image {
      filter:
        drop-shadow(0 0 3px #fbbf24)
        drop-shadow(0 0 10px rgb(245 158 11 / 100%));
    }

    #diagram svg g.node.selected-info-node.tag-match > rect.node-background {
      fill: #1e3a8a !important;
      stroke: #fbbf24 !important;
    }

    .node-card-content,
    .node-card-content span,
    #diagram svg .nodeLabel,
    #diagram svg .nodeLabel p,
    #diagram svg .nodeLabel span {
      color: #f8fafc !important;
      fill: #f8fafc !important;
    }

    #diagram svg g.node.tag-match .label text,
    #diagram svg g.node.tag-match .label span {
      fill: #fef3c7 !important;
      color: #fef3c7 !important;
    }

    #diagram svg path.flowchart-link {
      stroke: #94a3b8 !important;
    }

    #diagram svg marker path,
    #diagram svg .arrowheadPath {
      fill: #94a3b8 !important;
      stroke: #94a3b8 !important;
    }

    .viewport-help {
      background: rgba(15, 23, 42, 0.92) !important;
      color: #cbd5e1 !important;
      border-color: #475569 !important;
    }

    footer {
      background: #0b1220 !important;
      color: #94a3b8 !important;
      border-top-color: #334155 !important;
    }

    .status,
    footer .status {
      background: transparent !important;
      color: #94a3b8 !important;
    }

  
    /* Filter layout correction */
    .filters-content {
      display: grid !important;
      grid-template-columns: minmax(0, 3fr) minmax(260px, 1fr) !important;
      align-items: start !important;
      gap: 12px !important;
    }

    .filters-content > .filter-panel {
      min-width: 0 !important;
      width: auto !important;
    }

    @media (max-width: 900px) {
      .filters-content {
        grid-template-columns: 1fr !important;
      }
    }

  
    /* Tag state is colour-only so selection cannot change wrapping */
    button[data-tag],
    button[data-tag]:hover,
    button[data-tag].active,
    button[data-tag].selected,
    button[data-tag][aria-pressed="true"] {
      font-weight: 400 !important;
    }

  
    /* Debounced node-name search */
    main {
      grid-template-rows: auto minmax(0, 1fr) !important;
    }

    .search-bar {
      grid-column: 1;
      grid-row: 1;
      display: grid;
      grid-template-columns: auto minmax(160px, 1fr) auto;
      gap: 8px;
      align-items: center;
      min-width: 0;
      padding: 10px 12px;
      border: 1px solid #475569;
      border-radius: 10px;
      background: #1e293b;
      color: #f8fafc;
    }

    .search-bar label {
      font-weight: 700;
      white-space: nowrap;
    }

    .search-autocomplete-shell {
      position: relative;
      min-width: 0;
    }

    .search-bar input {
      width: 100%;
      min-width: 0;
      padding: 8px 10px;
      border: 1px solid #64748b !important;
      border-radius: 7px;
      background: #111827 !important;
      color: #f8fafc !important;
      font: inherit;
    }

    .search-bar input:focus {
      outline: 2px solid #38bdf8;
      outline-offset: 1px;
      border-color: #38bdf8 !important;
    }

    .search-suggestions {
      position: absolute;
      z-index: 20;
      top: calc(100% + 4px);
      right: 0;
      left: 0;
      max-height: 111px;
      overflow-y: auto;
      border: 1px solid #64748b;
      border-radius: 7px;
      background: #111827;
      box-shadow: 0 8px 20px rgb(0 0 0 / 35%);
    }

    .search-suggestions[hidden] {
      display: none;
    }

    .search-suggestion {
      display: block;
      width: 100%;
      min-height: 37px;
      padding: 8px 10px;
      border: 0;
      border-radius: 0;
      background: transparent;
      color: #f8fafc;
      font: inherit;
      text-align: left;
      cursor: pointer;
    }

    .search-suggestion:hover,
    .search-suggestion.active {
      background: #164e63;
    }

    #search-status {
      min-width: 9em;
      color: #cbd5e1;
      font-size: 13px;
      white-space: nowrap;
    }

    #viewport {
      grid-column: 1;
      grid-row: 2;
    }

    #info-panel {
      grid-column: 2;
      grid-row: 1 / span 2;
    }

    /*
     * Search uses a non-scaling magenta halo. Unlike the solid blue click
     * selection, it remains conspicuous when the graph is zoomed far out.
     */
    #diagram svg g.node.search-match > rect.node-background,
    #diagram svg g.node.search-match.tag-match > rect.node-background,
    #diagram svg g.node.selected-info-node.search-match > rect.node-background {
      fill: #701a75 !important;
      stroke: #f0abfc !important;
      stroke-width: 7px !important;
      stroke-dasharray: 14 7;
      vector-effect: non-scaling-stroke;
      filter:
        drop-shadow(0 0 3px #f0abfc)
        drop-shadow(0 0 9px rgb(232 121 249 / 95%));
    }

    #diagram svg g.node.search-match image {
      filter:
        drop-shadow(0 0 3px #f0abfc)
        drop-shadow(0 0 10px rgb(232 121 249 / 100%));
    }

    #diagram svg g.node.search-match .label text,
    #diagram svg g.node.search-match .label span,
    #diagram svg g.node.search-match .nodeLabel,
    #diagram svg g.node.search-match .nodeLabel span {
      fill: #fdf4ff !important;
      color: #fdf4ff !important;
      font-weight: 800 !important;
    }

    @media (max-width: 900px) {
      main {
        grid-template-columns: 1fr !important;
        grid-template-rows: auto minmax(500px, 70vh) auto !important;
      }

      .search-bar {
        grid-column: 1;
        grid-row: 1;
        grid-template-columns: auto minmax(0, 1fr) auto;
      }

      #search-status {
        grid-column: 1 / -1;
        min-width: 0;
      }

      #viewport {
        grid-column: 1;
        grid-row: 2;
      }

      #info-panel {
        grid-column: 1;
        grid-row: 3;
      }
    }

    /* Compact hover/focus help control */
    .hint {
      position: absolute;
      left: 12px;
      bottom: 10px;
      width: 28px;
      height: 28px;
      z-index: 2;
      pointer-events: auto;
      padding: 0;
      border: 0;
      border-radius: 0;
      background: transparent;
      box-shadow: none;
      color: inherit;
    }

    .hint-collapsed {
      position: absolute;
      inset: 0;
      display: grid;
      place-items: center;
      border: 1px solid #475569;
      border-radius: 50%;
      background: rgba(15, 23, 42, 0.94);
      color: #cbd5e1;
      font-size: 14px;
      font-weight: 800;
      line-height: 1;
      cursor: help;
    }

    .hint-expanded {
      position: absolute;
      left: 0;
      bottom: 0;
      display: none;
      padding: 10px 14px;
      border: 1px solid #475569;
      border-radius: 7px;
      background: rgba(15, 23, 42, 0.94);
      color: #cbd5e1;
      font-size: 24px;
      line-height: 1.2;
      white-space: nowrap;
      cursor: help;
    }

    .hint:hover .hint-expanded,
    .hint:focus-within .hint-expanded,
    .hint:focus-visible .hint-expanded {
      display: block;
    }

    .hint:hover .hint-collapsed,
    .hint:focus-within .hint-collapsed,
    .hint:focus-visible .hint-collapsed {
      opacity: 0;
    }

    /* Resizable graph/info split */
    main {
      --info-panel-width: 320px;
      grid-template-columns:
        minmax(360px, 1fr)
        8px
        minmax(240px, var(--info-panel-width)) !important;
      column-gap: 7px !important;
    }

    .search-bar,
    #viewport {
      grid-column: 1;
    }

    #panel-resizer {
      grid-column: 2;
      grid-row: 1 / span 2;
      position: relative;
      align-self: stretch;
      min-width: 8px;
      cursor: col-resize;
      touch-action: none;
      user-select: none;
    }

    #panel-resizer::before {
      content: "";
      position: absolute;
      top: 0;
      bottom: 0;
      left: 50%;
      width: 2px;
      transform: translateX(-50%);
      border-radius: 2px;
      background: #475569;
      transition: width 100ms ease, background 100ms ease;
    }

    #panel-resizer:hover::before,
    #panel-resizer:focus-visible::before,
    body.resizing-panels #panel-resizer::before {
      width: 4px;
      background: #60a5fa;
    }

    #panel-resizer:focus-visible {
      outline: none;
    }

    #info-panel {
      grid-column: 3;
      grid-row: 1 / span 2;
      min-width: 0;
    }

    body.resizing-panels {
      cursor: col-resize;
      user-select: none;
    }

    body.resizing-panels iframe,
    body.resizing-panels svg {
      pointer-events: none;
    }

    @media (max-width: 900px) {
      main {
        --info-panel-width: auto;
        grid-template-columns: 1fr !important;
        grid-template-rows: auto minmax(500px, 70vh) auto !important;
        column-gap: 0 !important;
      }

      #panel-resizer {
        display: none;
      }

      #info-panel {
        grid-column: 1;
        grid-row: 3;
      }
    }


    /* Selected-node relationship highlighting */
    #diagram svg g.node.relationship-required > rect.node-background {
      fill: #713f12 !important;
      stroke: #facc15 !important;
      stroke-width: 5px !important;
    }

    #diagram svg g.node.relationship-required .label text,
    #diagram svg g.node.relationship-required .label span,
    #diagram svg g.node.relationship-required .nodeLabel,
    #diagram svg g.node.relationship-required .nodeLabel span {
      fill: #fef9c3 !important;
      color: #fef9c3 !important;
      font-weight: 800 !important;
    }

    #diagram svg g.node.relationship-enabled > rect.node-background {
      fill: #14532d !important;
      stroke: #4ade80 !important;
      stroke-width: 5px !important;
    }

    #diagram svg g.node.relationship-enabled .label text,
    #diagram svg g.node.relationship-enabled .label span,
    #diagram svg g.node.relationship-enabled .nodeLabel,
    #diagram svg g.node.relationship-enabled .nodeLabel span {
      fill: #dcfce7 !important;
      color: #dcfce7 !important;
      font-weight: 800 !important;
    }

    #diagram svg path.flowchart-link.relationship-required {
      stroke: #facc15 !important;
      opacity: 1 !important;
    }

    #diagram svg path.flowchart-link.relationship-enabled {
      stroke: #4ade80 !important;
      opacity: 1 !important;
    }

    /* Invisible implicit subgraph used to keep direct group nodes together. */
    #diagram svg g.cluster.implicit-direct-cluster > rect {
      fill: transparent !important;
      stroke: transparent !important;
      stroke-width: 0 !important;
      filter: none !important;
    }

    #diagram svg g.cluster.implicit-direct-cluster > .cluster-label {
      display: none !important;
    }


    /* Graph typography settings */
    :root {
      --graph-group-heading-font-size: 16px;
      --graph-subgroup-heading-font-size: 16px;
      --graph-card-label-font-size: 15px;
    }

    #diagram svg g.cluster.group-cluster > .cluster-label {
      font-size: var(--graph-group-heading-font-size) !important;
    }

    #diagram svg g.cluster.subgroup-cluster > .cluster-label {
      font-size: var(--graph-subgroup-heading-font-size) !important;
    }

    .node-card-content {
      font-size: var(--graph-card-label-font-size) !important;
    }

    /* Graph settings control */
    .graph-settings-button {
      position: absolute;
      top: 10px;
      right: 10px;
      z-index: 4;
      width: 34px;
      height: 34px;
      display: grid;
      place-items: center;
      padding: 0;
      border-radius: 8px;
      font-size: 20px;
      line-height: 1;
    }

    .settings-backdrop[hidden] {
      display: none !important;
    }

    .settings-backdrop {
      position: fixed;
      inset: 0;
      z-index: 1000;
      display: grid;
      place-items: center;
      padding: 20px;
      background: rgba(0, 0, 0, 0.62);
    }

    .settings-modal {
      width: min(440px, 100%);
      padding: 20px;
      border: 1px solid #64748b;
      border-radius: 12px;
      background: #1e293b;
      color: #f8fafc;
      box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
    }

    .settings-modal h2 {
      margin: 0 0 18px;
      font-size: 22px;
    }

    .settings-fields {
      display: grid;
      grid-template-columns: minmax(0, 1fr) 90px;
      gap: 12px 16px;
      align-items: center;
    }

    .settings-fields label {
      color: #e2e8f0;
    }

    .settings-fields input {
      width: 100%;
      padding: 7px 9px;
      border: 1px solid #64748b;
      border-radius: 7px;
      background: #111827 !important;
      color: #f8fafc !important;
      font: inherit;
    }

    .settings-actions {
      display: flex;
      flex-wrap: wrap;
      justify-content: flex-end;
      gap: 8px;
      margin-top: 20px;
    }

    #settings-defaults {
      margin-right: auto;
    }

    @media (max-width: 520px) {
      .settings-fields {
        grid-template-columns: 1fr;
        gap: 6px;
      }

      .settings-fields input {
        margin-bottom: 8px;
      }
    }
