/* The system explorer page. Its article is not .prose, and everything here stays under this class. */
.system-explorer {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 40px 0 24px;
  font: 14px/1.5 var(--sans);

  /* Each role names a site token, so the dark theme follows. */
  --edge: var(--wood);
  --bad: var(--coral);
  --bad-soft: color-mix(in srgb, var(--coral) 12%, var(--panel));
  --cycle: var(--amber);
  --cycle-ink: color-mix(in srgb, var(--amber) 38%, var(--ink));
  --cycle-soft: color-mix(in srgb, var(--amber) 20%, var(--panel));
  --uses: var(--water);
  --uses-soft: color-mix(in srgb, var(--water) 12%, var(--panel));
  --usedby: var(--route);
  --usedby-soft: color-mix(in srgb, var(--route) 10%, var(--panel));
  --ok: var(--water);
  --ok-soft: color-mix(in srgb, var(--water) 12%, var(--panel));
  --sel: color-mix(in srgb, var(--forest) 8%, var(--panel));
  --hl: var(--parchment-2);

  button { font: inherit; color: inherit; }
  :focus-visible { outline: 2px solid var(--forest); outline-offset: 2px; }
  .name, code { font-family: var(--mono); }
  /* Small mono capitals: the site's section label (.nav-section, .toc-title). */
  .label, .filters legend, .focus .col h3, .problems h3, .ov-col h3 {
    font: 400 11px/1.4 var(--mono); letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-faint);
  }

  /* Header */
  header.top { margin-bottom: 20px; }
  header.top h1 { font: 700 clamp(30px, 4vw, 41px)/1.12 var(--sans); letter-spacing: -0.01em; margin: 0 0 10px; }
  .top-row { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 24px; }
  .note { color: var(--ink-soft); font-size: 17px; line-height: 1.5; margin: 0; }
  .stats { color: var(--ink-soft); font-size: 14px; font-variant-numeric: tabular-nums; }
  .stats b { color: var(--ink); font-weight: 700; }
  .stats .bad { color: var(--bad); }
  .stats .warn { color: var(--cycle-ink); }

  /* Toolbar */
  .toolbar {
    display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px;
    padding: 12px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  }
  .tabs { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 6px; overflow: hidden; }
  .tabs button {
    border: 0; background: var(--panel); padding: 7px 16px; cursor: pointer; color: var(--ink-soft);
    border-right: 1px solid var(--line-strong);
  }
  .tabs button:last-child { border-right: 0; }
  .tabs button[aria-selected="true"] { background: var(--parchment-2); color: var(--forest-deep); font-weight: 700; }
  .tabs button:not([aria-selected="true"]):hover { background: var(--parchment); color: var(--ink); }
  .tabs button:focus-visible { outline-offset: -2px; }
  .search input {
    width: 240px; max-width: 100%; padding: 7px 10px; border-radius: 6px;
    border: 1px solid var(--line-strong); background: var(--parchment); color: var(--ink); font: 13px var(--mono);
  }
  .search input::placeholder { color: var(--ink-faint); }
  .search input:focus { outline: 2px solid var(--forest); outline-offset: 1px; }
  .filters { flex-basis: 100%; display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; font-size: 14px; }
  .filters fieldset { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; }
  .filters legend { float: left; margin-right: 4px; }
  .filters label { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; white-space: nowrap; }
  .filters input { accent-color: var(--forest); margin: 0; }
  .sep { width: 1px; align-self: stretch; background: var(--line); }

  /* Trail and legend */
  .subbar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 16px; margin: 14px 0 18px; }
  .trail { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; font: 13px var(--mono); }
  .trail .back {
    font: 13px var(--sans); border: 1px solid var(--line-strong); background: var(--panel); color: var(--ink);
    border-radius: 6px; padding: 3px 10px; cursor: pointer; margin-right: 6px;
  }
  .trail .back:hover:not(:disabled) { border-color: var(--forest); }
  .trail .back:disabled { color: var(--ink-faint); opacity: .6; cursor: default; }
  .trail .crumb { border: 0; background: none; padding: 2px 4px; cursor: pointer; color: var(--forest); border-radius: 4px; }
  .trail .crumb:hover { background: var(--parchment-2); color: var(--forest-deep); }
  .trail .crumb.cur { color: var(--ink); font-weight: 700; cursor: default; background: none; }
  .trail .gt { color: var(--ink-faint); }
  .legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 13px; color: var(--ink-soft); }
  .legend span { display: inline-flex; align-items: center; gap: 6px; }
  .legend svg { overflow: visible; }
  .sw-vio, .chip .vio { font: 700 10.5px/1 var(--mono); font-style: normal; padding: 2px 5px; border-radius: 999px; background: var(--bad-soft); color: var(--bad); }
  .ring { display: inline-block; flex: none; width: 9px; height: 9px; border-radius: 50%; border: 2px solid var(--cycle); }

  /* Shared edge styles */
  .wire { fill: none; stroke: var(--edge); stroke-width: 1.5; }
  .wire.test { stroke-dasharray: 5 4; }
  .wire.cycle { stroke: var(--cycle); stroke-width: 3.5; }
  .wire.undecl { stroke: var(--bad); }
  .wire.uses { stroke: var(--uses); stroke-width: 1.75; }
  .wire.usedby { stroke: var(--usedby); stroke-width: 1.75; }
  .ah-edge { fill: var(--edge); }
  .ah-bad { fill: var(--bad); }
  .ah-warn { fill: var(--cycle); }
  .ah-uses { fill: var(--uses); }
  .ah-usedby { fill: var(--usedby); }

  .view[hidden] { display: none; }

  /* Focus view */
  .focus {
    position: relative; display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(280px, 380px) minmax(0, 1fr);
    grid-template-rows: minmax(360px, auto) auto;
    column-gap: 72px;
    --col-head: 26px;
    --panel-gap: 14px;
  }
  .focus > svg.wires { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
  .focus .col { display: flex; flex-direction: column; min-width: 0; position: relative; }
  .focus .col h3 { margin: 0 0 10px; line-height: calc(var(--col-head) - 10px); }
  .focus .col h3 .n, .problems h3 .n { color: var(--ink-soft); letter-spacing: 0; }
  .focus .stack { display: flex; flex-direction: column; justify-content: center; gap: 8px; flex: 1; }
  .focus .col.usedby h3 { text-align: right; }
  .focus .empty { color: var(--ink-faint); font-size: 14px; padding: 14px; border: 1px dashed var(--line-strong); border-radius: 8px; text-align: center; }
  .focus .col.uses { grid-area: 1 / 1; }
  .focus .col.usedby { grid-area: 1 / 3; }
  /* The card is centred on the neighbour stacks, which start below their column heading. */
  .focus > .center-card { grid-area: 1 / 2; align-self: center; margin-top: var(--col-head); }
  .focus > .problems { grid-area: 2 / 2; align-self: start; }
  .focus.hovering .wire { opacity: .2; }
  .focus.hovering .wire.hot { opacity: 1; }

  .nb {
    display: grid; grid-template-columns: auto 1fr; column-gap: 8px; row-gap: 2px; align-items: center;
    text-align: left; cursor: pointer; padding: 9px 12px; background: var(--panel);
    border: 1px solid var(--line); border-radius: 8px;
  }
  .nb:hover { border-color: var(--forest); }
  .nb .glyph { display: none; grid-row: span 3; }
  .nb .nb-name { font: 600 13.5px/1.3 var(--mono); overflow-wrap: anywhere; }
  .nb .nb-meta { font-size: 12.5px; color: var(--ink-soft); }
  .nb .tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; }
  .nb .tags:empty { display: none; }
  .nb > :not(.glyph) { grid-column: 2; }
  .pdot, .nb.problem .nb-name::after { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--bad); margin-left: 6px; vertical-align: middle; }

  /* Tags follow the site's .pill. */
  .tag, .badge {
    display: inline-block; font: 11px/1.3 var(--mono); letter-spacing: 0.04em; padding: 1px 8px; border-radius: 999px;
    border: 1px solid transparent; white-space: nowrap;
  }
  .tag.test { border-color: var(--line-strong); border-style: dashed; color: var(--ink-soft); }
  .tag.undecl { background: var(--bad-soft); color: var(--bad); }
  .tag.cycle { background: var(--cycle-soft); color: var(--cycle-ink); }
  .badge.approved { background: var(--ok-soft); color: var(--ok); }
  .badge.draft { background: var(--parchment-3); color: var(--ink-soft); }
  .badge.kind { border-color: var(--line-strong); color: var(--ink-soft); }

  .center-card { background: var(--panel); border: 2px solid var(--forest); border-radius: 12px; padding: 18px 20px; }
  .center-card .top { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
  .center-card .area { margin-left: auto; font-size: 13px; color: var(--ink-soft); }
  .center-card h2 { font: 600 22px/1.25 var(--mono); margin: 12px 0 6px; overflow-wrap: anywhere; }
  .center-card p { margin: 0 0 10px; font-size: 15px; line-height: 1.5; }
  .doc-link { display: inline-block; margin: 0 0 14px; font-size: 14px; font-weight: 600; }
  .facts { display: flex; gap: 28px; margin: 0; padding-top: 12px; border-top: 1px solid var(--line); }
  .facts dt { font: 11px/1.4 var(--mono); letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-faint); }
  .facts dd { margin: 2px 0 0; font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
  .facts dd.bad { color: var(--bad); }

  /* Problems: one quiet panel, grouped by rule. */
  .problems { margin-top: 14px; padding: 14px 18px 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
  .problems h3 { margin: 0 0 4px; }
  .pgroup { padding: 10px 0; border-top: 1px solid var(--line); }
  .problems h3 + .pgroup { border-top: 0; padding-top: 6px; }
  .pgroup h4 { margin: 0 0 4px; font-size: 14px; font-weight: 700; color: var(--bad); }
  .pgroup.cycle h4 { color: var(--cycle-ink); }
  .pgroup h4 .n { margin-left: 4px; font-weight: 400; color: var(--ink-faint); font-variant-numeric: tabular-nums; }
  .pgroup .with { margin: 0 0 6px; font-size: 13.5px; color: var(--ink-soft); }
  .pgroup .with button {
    border: 0; background: none; padding: 0; color: var(--forest); font: 600 13px var(--mono);
    text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 2px; cursor: pointer;
  }
  .pgroup .with button:hover { color: var(--forest-deep); }
  .pgroup > ul { list-style: none; margin: 0; padding: 0; }
  .pgroup > ul > li { padding: 5px 0; font-size: 13.5px; line-height: 1.45; overflow-wrap: anywhere; }
  .prow { display: flex; align-items: baseline; gap: 10px; }
  .prow .pair { flex: 1; min-width: 0; font: 13px/1.45 var(--mono); color: var(--ink); }
  .prow .nm { white-space: nowrap; }
  .prow .cnt { margin-left: auto; flex: none; font-size: 12.5px; color: var(--ink-faint); font-variant-numeric: tabular-nums; white-space: nowrap; }
  .problems summary { list-style: none; cursor: pointer; border-radius: 4px; }
  .problems summary::-webkit-details-marker { display: none; }
  .problems summary .cnt { color: var(--forest); }
  .problems summary .cnt::after {
    content: ""; display: inline-block; width: 6px; height: 6px; margin-left: 7px; vertical-align: 2px;
    border: solid currentColor; border-width: 0 1.5px 1.5px 0; transform: rotate(45deg);
  }
  .problems details[open] summary .cnt::after { transform: rotate(-135deg); vertical-align: -1px; }
  .problems summary:hover .pair { color: var(--forest-deep); }
  .crates { list-style: none; margin: 4px 0 2px; padding: 0 0 0 10px; border-left: 1px solid var(--line-strong); font-size: 12.5px; line-height: 1.55; color: var(--ink-soft); }
  .crates li { padding: 1px 0; }
  .crates code { white-space: nowrap; color: var(--ink); }
  .crates .t { font: 10.5px var(--mono); color: var(--ink-faint); padding: 0 5px; border: 1px dashed var(--line-strong); border-radius: 999px; white-space: nowrap; }

  /* Below this width the content column is too narrow for three columns beside the sidebar. */
  @media (max-width: 1020px) {
    .focus { grid-template-columns: minmax(0, 1fr); grid-template-rows: none; row-gap: 24px; }
    .focus .col.uses, .focus .col.usedby, .focus > .center-card, .focus > .problems { grid-area: auto; }
    .focus > .center-card { order: -2; margin-top: 0; }
    .focus > .problems { order: -1; margin-top: -10px; }
    .focus .col.usedby h3 { text-align: left; }
    .focus > svg.wires { display: none; }
    .nb .glyph { display: block; }
  }

  /* Matrix view */
  .mx-wrap { overflow: auto; max-height: 76vh; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
  table.mx { border-collapse: separate; border-spacing: 0; font-size: 12px; }
  .mx th, .mx td { padding: 0; background: var(--panel); }
  .mx thead th { position: sticky; z-index: 2; }
  .mx thead tr:first-child th { top: 0; height: 26px; }
  .mx thead tr:nth-child(2) th { top: 26px; }
  .mx .corner {
    left: 0; z-index: 4 !important; text-align: left; vertical-align: bottom; padding: 8px 12px;
    color: var(--ink-faint); font-weight: 400; border-right: 1px solid var(--line-strong); border-bottom: 1px solid var(--line-strong);
  }
  .mx .ag, .mx tr.grp th { font: 400 11px/1.4 var(--mono); letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-faint); text-align: left; }
  .mx .ag {
    padding: 0 6px; border-left: 1px solid var(--line-strong); border-bottom: 1px solid var(--line);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 0;
  }
  .mx .cl {
    height: 156px; width: 20px; min-width: 20px; vertical-align: bottom; padding: 6px 0; cursor: pointer;
    border-bottom: 1px solid var(--line-strong); font-weight: 400; color: var(--ink-soft);
  }
  .mx .cl span { writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap; font-family: var(--mono); display: inline-block; }
  .mx .cl:hover, .mx .rl:hover { color: var(--forest); }
  .mx .rl {
    position: sticky; left: 0; z-index: 1; text-align: left; font: 400 12px var(--mono); color: var(--ink);
    padding: 0 12px; height: 20px; white-space: nowrap; cursor: pointer; border-right: 1px solid var(--line-strong);
  }
  .mx tr.grp th { position: sticky; left: 0; z-index: 1; padding: 10px 12px 3px; border-right: 1px solid var(--line-strong); }
  .mx tr.grp td { border-bottom: 1px solid var(--line); }
  .mx td { width: 20px; min-width: 20px; height: 20px; text-align: center; vertical-align: middle; border-bottom: 1px solid var(--line); }
  .mx .gs { border-left: 1px solid var(--line-strong); }
  .mx td.diag { background: var(--parchment-2); }
  .mx .selr, .mx .selc { background: var(--sel); }
  .mx .rl.selr, .mx .cl.selc { color: var(--forest-deep); font-weight: 700; }
  .mx .hr, .mx .hc { background: var(--hl); }
  .mx .hr.rl, .mx .hc.cl { color: var(--forest); }
  .m { display: inline-block; width: 12px; height: 12px; border-radius: 2px; vertical-align: middle; background: var(--edge); }
  .m.test { background: transparent; border: 2px dashed var(--edge); }
  .m.undecl { background: var(--bad); }
  .m.test.undecl { background: transparent; border-color: var(--bad); }
  .m.cycle { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--cycle); }
  .tip {
    position: fixed; z-index: 10; pointer-events: none; background: var(--ink); color: var(--parchment);
    font-size: 12.5px; padding: 5px 9px; border-radius: 6px; max-width: 320px;
  }
  .tip[hidden] { display: none; }
  .tip .name { font-weight: 600; }

  /* Overview */
  .ov { position: relative; }
  .ov > svg.wires { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
  .ov-grid { position: relative; display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 24px 24px; align-items: start; }
  .ov-col h3 { margin: 0 0 10px; }
  .ov-col h3 .n { color: var(--ink-soft); letter-spacing: 0; }
  .ov-col .chips { display: flex; flex-direction: column; gap: 6px; }
  .chip {
    position: relative; display: flex; align-items: center; gap: 6px; width: 100%; text-align: left; cursor: pointer;
    padding: 5px 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
    font: 12px/1.3 var(--mono); letter-spacing: -0.01em;
  }
  .chip .cname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .chip .ok { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); flex: none; }
  .chip:hover { border-color: var(--ink-soft); }
  .ov.active .chip { opacity: .35; }
  .ov.active .chip.on, .ov.active .chip.uses, .ov.active .chip.usedby { opacity: 1; }
  .chip.on { border-color: var(--forest); box-shadow: 0 0 0 1px var(--forest); }
  .chip.uses { background: var(--uses-soft); border-color: var(--uses); }
  .chip.usedby { background: var(--usedby-soft); border-color: var(--usedby); }
  .chip.uses.usedby { background: linear-gradient(90deg, var(--uses-soft) 50%, var(--usedby-soft) 50%); }
  .ov-hint { color: var(--ink-soft); font-size: 13px; margin: 0 0 14px; }
  .empty-view { color: var(--ink-soft); padding: 24px; text-align: center; }

  @media (max-width: 520px) {
    .note { font-size: 16px; }
    .toolbar { padding: 10px; }
    .tabs { width: 100%; }
    .tabs button { flex: 1; }
    .search, .search input { width: 100%; }
    .sep { display: none; }
    .center-card { padding: 16px; }
    .problems { padding: 12px 14px 4px; }
  }
}
