/* Tokens follow service-summary-emails so the house apps look alike. */
:root {
  --page:        #f6f7fa;
  --surface:     #ffffff;
  --surface-sub: #eff1f6;
  --ink:         #131820;
  --ink-mid:     #4b5464;
  --ink-soft:    #6e7787;
  --border:      #dce0e8;
  --border-str:  #c2c8d4;
  --accent:      #1f3a93;
  --accent-sub:  #e6eaf7;
  --warn:        #9a5a0c;
  --warn-sub:    #f7eedf;
  --ok:          #0e6659;
  --ok-sub:      #e0efeb;
  --danger:      #8c2f39;
  --danger-sub:  #f6e7e8;
  --edge:        #9aa3b2;
  --radius: 8px;

  /* one colour per system type, for the graph and the type chips */
  --t-application: #3b5bdb;
  --t-saas:        #0c8599;
  --t-database:    #e8590c;
  --t-server:      #6b7280;
  --t-data:        #ae3ec9;
  --t-job:         #d6336c;
  --t-file:        #a07d1c;
  --t-idp:         #2b8a3e;
  --t-hosting:     #5c7cfa;
  --t-automation:  #c2255c;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page:        #10131a;
    --surface:     #171b24;
    --surface-sub: #1e232e;
    --ink:         #e7eaf1;
    --ink-mid:     #a6aebc;
    --ink-soft:    #838c9c;
    --border:      #272d3a;
    --border-str:  #38404f;
    --accent:      #8aa0ec;
    --accent-sub:  #1d2440;
    --warn:        #d9a05a;
    --warn-sub:    #2c2317;
    --ok:          #5fbfac;
    --ok-sub:      #142825;
    --danger:      #d98a92;
    --danger-sub:  #2b1a1d;
    --edge:        #4d5566;

    --t-application: #748ffc;
    --t-saas:        #3bc9db;
    --t-database:    #ff922b;
    --t-server:      #9ca3af;
    --t-data:        #da77f2;
    --t-job:         #f06595;
    --t-file:        #e0b84a;
    --t-idp:         #51cf66;
    --t-hosting:     #91a7ff;
    --t-automation:  #f783ac;
  }
}

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

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 500; line-height: 1.25; }
h1 { font-size: 20px; }
h2 { font-size: 17px; }
h3 { font-size: 14px; color: var(--ink-mid); margin: 16px 0 6px; }
p { margin: 0; }
code, .mono { font-family: "Cascadia Mono", Consolas, ui-monospace, monospace; font-size: 0.9em; }
.hidden { display: none !important; }
.muted { color: var(--ink-soft); }
.error { color: var(--danger); }

.shell { max-width: 1500px; margin: 0 auto; padding: 18px 20px 40px; }

/* ---------- top bar ---------- */

.topbar {
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding-bottom: 12px; border-bottom: 1px solid var(--border-str); margin-bottom: 14px;
}
.topbar .title { display: flex; flex-direction: column; gap: 2px; }
.topbar .eyebrow { font-size: 11px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-soft); }
.tabs { display: flex; gap: 4px; }
.tabs a {
  padding: 6px 12px; border-radius: var(--radius); color: var(--ink-mid); text-decoration: none; font-size: 14px;
}
.tabs a:hover { background: var(--surface-sub); }
.tabs a.active { background: var(--accent-sub); color: var(--accent); font-weight: 500; }
.who { margin-left: auto; display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--ink-mid); flex-wrap: wrap; }

/* ---------- controls ---------- */

button, select, input[type=search] {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--border-str); border-radius: var(--radius); padding: 5px 10px;
}
button { cursor: pointer; }
button:hover { background: var(--surface-sub); }
button.link { border: none; background: none; color: var(--accent); padding: 0; }
button.link:hover { text-decoration: underline; background: none; }
input[type=search] { min-width: 220px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-mid); }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }

/* Multi-select filter (controls.js): a button that says what it holds, and a checklist with counts. */
.multi { position: relative; }
.multi-button { padding-right: 26px; position: relative; white-space: nowrap; }
.multi-button::after { content: ""; position: absolute; right: 10px; top: 50%; margin-top: -2px; border: 4px solid transparent; border-top-color: var(--ink-soft); }
.multi-button.active { border-color: var(--accent); color: var(--accent); background: var(--accent-sub); }
.multi-pop {
  position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; min-width: 220px; max-width: 320px;
  background: var(--surface); border: 1px solid var(--border-str); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18); padding: 6px;
}
.multi-pop input[type=search] { min-width: 0; width: 100%; margin-bottom: 4px; }
.multi-list { max-height: 300px; overflow-y: auto; }
.multi-option { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 6px; cursor: pointer; }
.multi-option:hover { background: var(--surface-sub); }
.multi-option.empty .multi-label, .multi-option.empty .multi-count { color: var(--ink-soft); }
.multi-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.multi-count { color: var(--ink-soft); font-size: 12px; font-variant-numeric: tabular-nums; }
.multi-none { padding: 4px 6px; }
.multi-foot { border-top: 1px solid var(--border); margin-top: 4px; padding: 6px 6px 2px; }
.multi-foot button:disabled { color: var(--ink-soft); cursor: default; text-decoration: none; }

/* Typeahead (controls.js): matching items listed under the search box. */
.typeahead { position: relative; display: inline-block; }
.typeahead input { padding-right: 30px; }
.typeahead input::-webkit-search-cancel-button { display: none; }
.typeahead-clear {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%); border: none; background: none;
  color: var(--ink-soft); padding: 0 6px; font-size: 17px; line-height: 1;
}
.typeahead-clear:hover { color: var(--ink); background: none; }
/* Holding a selection, the box is marked the way a filter that is set is (.multi-button.active). */
.typeahead.held input { border-color: var(--accent); color: var(--accent); background: var(--accent-sub); }
.typeahead.held .typeahead-clear { color: var(--accent); }
.typeahead-list {
  position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; min-width: 100%; width: max-content; max-width: 420px;
  margin: 0; padding: 4px; list-style: none; background: var(--surface); border: 1px solid var(--border-str);
  border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18); max-height: 340px; overflow-y: auto;
}
.typeahead-option { padding: 5px 8px; border-radius: 6px; cursor: pointer; }
.typeahead-option:hover, .typeahead-option.active { background: var(--accent-sub); }
.typeahead-line { display: flex; align-items: center; gap: 8px; }
.typeahead-label { font-weight: 500; }
.typeahead-detail { color: var(--ink-soft); font-size: 12px; }
.typeahead-option.retired .typeahead-label { color: var(--ink-mid); }
.typeahead-note { display: block; color: var(--ink-soft); font-size: 12px; margin-left: 18px; }
.typeahead-none { padding: 5px 8px; color: var(--ink-soft); }
.typeahead mark { background: none; color: var(--accent); font-weight: 600; }

@media (max-width: 640px) {
  .multi { position: static; }
  .multi-pop, .typeahead-list { left: 0; right: 0; max-width: none; width: auto; }
  .toolbar { position: relative; }
  .typeahead-list { width: calc(100vw - 40px); }
}

/* ---------- banners, cards, chips ---------- */

.banner { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 12px; font-size: 13px; }
.banner-danger { background: var(--danger-sub); color: var(--danger); }
.banner-warn { background: var(--warn-sub); color: var(--warn); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; display: flex; flex-direction: column; gap: 8px; }

.chip { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--surface-sub); color: var(--ink-mid); white-space: nowrap; }
.chip.accent { background: var(--accent-sub); color: var(--accent); }
.chip.danger { background: var(--danger-sub); color: var(--danger); }
.chip.ok { background: var(--ok-sub); color: var(--ok); }
.chip.warn { background: var(--warn-sub); color: var(--warn); }
.chip.flow { background: var(--accent-sub); color: var(--accent); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }

/* ---------- layout ---------- */

.layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; }
.layout.with-detail { grid-template-columns: minmax(0, 1fr) 380px; }
@media (max-width: 1000px) {
  .layout.with-detail { grid-template-columns: minmax(0, 1fr); }
  /* narrow: the selected item comes first, so a click shows its detail without scrolling */
  .layout .detail { order: -1; position: static; max-height: none; }
}
.view { min-width: 0; }
.footer { margin-top: 12px; font-size: 12px; }

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

/* The map fills the window below the toolbar, so the whole drawing is in view without scrolling. */
.graph-wrap { --map-h: max(420px, calc(100vh - 290px)); background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
#graph { display: block; width: 100%; height: var(--map-h); cursor: grab; user-select: none; touch-action: none; }
#graph.panning { cursor: grabbing; }
#graph .edge { stroke: var(--edge); stroke-width: 1.2; fill: none; }
#graph .edge.retired { stroke-dasharray: 4 3; }
#graph .node { cursor: pointer; }
#graph .node circle { stroke: var(--surface); stroke-width: 2; }
#graph .node text { fill: var(--ink); font-size: 11px; paint-order: stroke; stroke: var(--surface); stroke-width: 3px; stroke-linejoin: round; pointer-events: none; }
#graph .node.retired circle { opacity: 0.45; }
#graph.focus .node:not(.near) { opacity: 0.18; }
#graph.focus .edge:not(.near) { opacity: 0.12; }
#graph .edge.near { stroke: var(--accent); stroke-width: 2; }
#graph .node.selected circle { stroke: var(--accent); stroke-width: 3; }
#graph .arrow { fill: var(--edge); }
#graph .arrow.near { fill: var(--accent); }
#map { display: block; width: 100%; height: var(--map-h); cursor: grab; user-select: none; touch-action: none; }
#map.panning { cursor: grabbing; }
#map .card { cursor: pointer; }
#map .card .box { fill: var(--surface); stroke: var(--border-str); stroke-width: 1; }
#map .card:hover .box, #map .card:focus-visible .box { stroke: var(--accent); }
#map .card:focus { outline: none; }
#map .card .name { fill: var(--ink); font-size: 12.5px; font-weight: 500; pointer-events: none; }
#map .card .sub { fill: var(--ink-soft); font-size: 11px; pointer-events: none; }
#map .group-link { fill: var(--accent); font-size: 11px; font-weight: 600; cursor: pointer; }
#map .group-link:hover { text-decoration: underline; }
#map .card.more .box { fill: var(--surface-sub); stroke-dasharray: 4 3; }
#map .card.more .name { fill: var(--accent); }
#map .card.focus .box { fill: var(--accent-sub); stroke: var(--accent); stroke-width: 2; }
#map .card.retired { opacity: 0.55; }
#map .card.retired .box { stroke-dasharray: 4 3; }
#map .group { fill: var(--ink-soft); font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; }
#map .edge { stroke: var(--edge); stroke-width: 1.3; fill: none; pointer-events: none; }
#map .edge.unverified { stroke-dasharray: 5 4; }
#map .edge.retired { stroke-dasharray: 2 3; opacity: 0.6; }
#map .edge.bundled { opacity: 0.45; }
#map .hit { stroke: transparent; stroke-width: 10; fill: none; cursor: pointer; }
#map .hit:hover { stroke: var(--accent-sub); }
#map .arrow { fill: var(--edge); }
#map .arrow.near { fill: var(--accent); }
#map.dim .card:not(.near) { opacity: 0.25; }
#map.dim .edge:not(.near) { opacity: 0.1; }
#map .edge.near { stroke: var(--accent); stroke-width: 2; }
#map .card.selected .box { stroke: var(--accent); stroke-width: 2; }
#map .card.far { opacity: 0.85; }
#map .card.far .box { fill: var(--surface-sub); }
#map .flow-badge { fill: var(--accent-sub); stroke: var(--accent); stroke-width: 0.8; }
#map .flow-badge-text { fill: var(--accent); font-size: 9.5px; font-weight: 600; pointer-events: none; }
#map .flow-badge-link { cursor: pointer; }
#map .flow-badge-link:hover .flow-badge { fill: var(--accent); }
#map .flow-badge-link:hover .flow-badge-text { fill: var(--surface); }
#map .edge.flow { stroke: var(--accent); stroke-width: 2; }
#map .card.on-flow .box { stroke: var(--accent); }
#map .card.hub .box { stroke-dasharray: 6 3; }
#map .card.repeat { opacity: 0.6; }
#map .card.repeat .box { stroke-dasharray: 4 3; fill: none; }
#map .card.hub .sub { fill: var(--warn); }
#map.flowing .card:not(.on-flow) { opacity: 0.55; }
#map.flowing .edge:not(.flow) { opacity: 0.35; }
.part-of-link { display: inline-flex; align-items: center; gap: 8px; margin-left: auto; font-size: 13px; }
.part-of-link .flow-link { background: var(--accent-sub); color: var(--accent); border-radius: 8px; padding: 3px 10px; text-decoration: none; }
.part-of-link .flow-link:hover { text-decoration: underline; }
#map .step { fill: var(--ink-soft); font-size: 10.5px; }
#map .caption { fill: var(--ink-mid); font-size: 12px; }
@keyframes map-in { from { opacity: 0; } }
@keyframes map-out { to { opacity: 0; } }
#map .entering { animation: map-in 220ms ease-out 140ms both; }
#map .entering-late { animation: map-in 200ms ease-out 260ms both; }
#map .ghost.leaving { animation: map-out 180ms ease-in both; pointer-events: none; }
.trail { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; margin: -2px 0 8px; font-size: 13px; color: var(--ink-soft); }
.trail a { color: var(--accent); text-decoration: none; }
.trail a:hover { text-decoration: underline; }
.trail .here { color: var(--ink); font-weight: 500; }
.trail .sep { color: var(--ink-soft); }
.trail button { margin-left: 6px; font-size: 12px; padding: 0 8px; }
.graph-wrap { position: relative; }
.map-wide-toggle { position: absolute; z-index: 5; top: 10px; right: 10px; width: 32px; height: 32px; padding: 6px; display: flex; align-items: center; justify-content: center; background: var(--surface); }
.map-wide-toggle svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.map-wide-toggle .leave, .map-wide-toggle[aria-pressed="true"] .enter { display: none; }
.map-wide-toggle[aria-pressed="true"] .leave { display: block; }
.map-wide-toggle[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
body.map-wide .shell { max-width: none; }
body.map-wide .layout.with-detail { grid-template-columns: minmax(0, 1fr); }
body.map-wide .layout .detail { display: none; }
/* Switching to or from Network: the two drawings cross-fade, with the shared duration (motion.js). */
.graph-wrap svg.fade-out { position: absolute; left: 0; top: 0; animation: map-out 320ms ease-in both; pointer-events: none; }
.graph-wrap svg.fade-in { animation: map-in 320ms ease-out both; }
@media (prefers-reduced-motion: reduce) { .graph-wrap svg.fade-out, .graph-wrap svg.fade-in { animation: none; } }
.hidden-note { margin: -2px 0 8px; font-size: 13px; color: var(--warn); }
.hidden-note button { margin-left: 6px; }
.map-empty {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; padding: 24px; text-align: center; background: var(--surface);
}
.map-empty p:first-child { font-size: 16px; }
.picks { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-width: 760px; }
.segmented { display: inline-flex; border: 1px solid var(--border-str); border-radius: var(--radius); overflow: hidden; }
.segmented button { border: none; border-radius: 0; }
.segmented button + button { border-left: 1px solid var(--border-str); }
.segmented button[aria-checked="true"] { background: var(--accent-sub); color: var(--accent); font-weight: 500; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 8px; font-size: 12px; color: var(--ink-mid); }

.fill-application { fill: var(--t-application); background: var(--t-application); }
.fill-saas { fill: var(--t-saas); background: var(--t-saas); }
.fill-database { fill: var(--t-database); background: var(--t-database); }
.fill-server { fill: var(--t-server); background: var(--t-server); }
.fill-data { fill: var(--t-data); background: var(--t-data); }
.fill-job { fill: var(--t-job); background: var(--t-job); }
.fill-file { fill: var(--t-file); background: var(--t-file); }
.fill-idp { fill: var(--t-idp); background: var(--t-idp); }
.fill-hosting { fill: var(--t-hosting); background: var(--t-hosting); }
.fill-automation { fill: var(--t-automation); background: var(--t-automation); }

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

.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th { text-align: left; font-weight: 500; color: var(--ink-soft); padding: 8px 12px; border-bottom: 1px solid var(--border-str); white-space: nowrap; }
table.grid td { padding: 7px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.grid tbody tr { cursor: pointer; }
table.grid tbody tr:hover { background: var(--surface-sub); }
table.grid tbody tr.selected { background: var(--accent-sub); }
table.grid tr.retired td { color: var(--ink-soft); }
.count { margin-top: 8px; font-size: 12px; }

/* ---------- detail panel ---------- */

.detail {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px;
  position: sticky; top: 12px; max-height: calc(100vh - 24px); overflow-y: auto;
}
.detail .head { display: flex; align-items: baseline; gap: 8px; justify-content: space-between; }
.detail .close { border: none; background: none; color: var(--ink-soft); font-size: 18px; line-height: 1; padding: 0 4px; }
.detail .chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 4px; }
.detail dl { display: grid; grid-template-columns: 128px minmax(0, 1fr); gap: 4px 10px; margin: 0; font-size: 13px; }
.detail dt { color: var(--ink-soft); }
.detail dd { margin: 0; overflow-wrap: anywhere; }
.detail ul { list-style: none; margin: 0; padding: 0; font-size: 13px; display: flex; flex-direction: column; gap: 4px; }
.detail li .muted { font-size: 12px; }
.detail .links { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.detail .links a { color: var(--accent); }
.detail .howto { font-size: 12px; color: var(--ink-soft); }
.detail .purpose { margin: 6px 0 10px; font-size: 13px; }
.detail .part-of { margin: 8px 0 10px; padding: 8px 10px; border-radius: 8px; background: var(--accent-sub); font-size: 13px; }
.detail .part-of p { margin: 0 0 2px; }
.detail .part-of p.muted { margin-bottom: 6px; font-size: 12px; }
.detail ol.steps { margin: 0; padding-left: 20px; font-size: 13px; display: flex; flex-direction: column; gap: 4px; }
.detail ol.steps .muted { font-size: 12px; }
.dot.flow { background: var(--accent); border-radius: 2px; }
a.sys { color: var(--accent); text-decoration: none; cursor: pointer; }
a.sys:hover { text-decoration: underline; }
