/* Integration map.
   Landscape: a sidebar for views and details, the map beside it.
   Portrait: the map fills the screen and a bottom sheet holds views and details. */
body.map-page { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; background: #0B1724; }
.mx { --ease: cubic-bezier(.16,1,.3,1); flex: 1; min-height: 0; display: grid; grid-template-columns: 360px minmax(0, 1fr); font-family: Inter, system-ui, sans-serif; color: #F4F6F3; line-height: 1.45; }
.mx button { font-family: inherit; line-height: inherit; }
.mx :focus-visible { outline: 3px solid #FFB020; outline-offset: 2px; }

/* ---------- Side panel ---------- */
.mx-side { position: relative; z-index: 5; min-height: 0; display: flex; flex-direction: column; background: #0F1E2E; border-right: 1px solid #2A3E52; }
.mx-grip { display: none; }
.mx-head { padding: 18px 20px 8px; display: flex; flex-direction: column; gap: 4px; }
.mx-crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; font-family: "IBM Plex Mono", ui-monospace, Menlo, monospace; font-size: 12px; color: #8FA0B0; }
.mx-crumbs button { border: 0; background: none; padding: 2px 0; font-size: inherit; color: #FFB020; cursor: pointer; }
.mx-crumbs button:hover { text-decoration: underline; }
.mx-crumbs i { font-style: normal; color: #5C6E80; }
.mx-title { margin: 0; font-family: "Space Grotesk", Inter, system-ui, sans-serif; font-size: 24px; font-weight: 600; line-height: 1.15; }
.mx-tabs { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 20px 14px; }
.mx-tab { display: inline-flex; align-items: center; gap: 7px; min-height: 34px; padding: 0 12px; border-radius: 999px; border: 1px solid #2E4458; background: transparent; color: #C4D0DB; font-size: 13px; cursor: pointer; white-space: nowrap; transition: background-color .2s ease, color .2s ease, border-color .2s ease; }
.mx-tab i { width: 8px; height: 8px; border-radius: 50%; background: var(--c); flex: none; }
.mx-tab:hover { color: #FFFFFF; border-color: #5C6E80; }
.mx-tab[aria-pressed="true"] { background: #F4F6F3; border-color: #F4F6F3; color: #13202E; font-weight: 600; }
.mx-body { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 16px 20px 28px; border-top: 1px solid #22364A; display: flex; flex-direction: column; gap: 12px; font-size: 14px; }
.mx-body p { margin: 0; color: #C4D0DB; }
.mx-sec { margin-top: 8px; font-size: 11px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; color: #8FA0B0; }
.mx-kind { font-family: "IBM Plex Mono", ui-monospace, Menlo, monospace; font-size: 12px; color: #A9B8C6; }
.mx-h2 { margin: 0; font-family: "Space Grotesk", Inter, system-ui, sans-serif; font-size: 20px; font-weight: 600; line-height: 1.2; }
.mx-back { align-self: flex-start; min-height: 34px; padding: 0 12px; border-radius: 8px; border: 1px solid #2E4458; background: transparent; color: #C4D0DB; font-size: 13px; cursor: pointer; }
.mx-back:hover { border-color: #C4D0DB; color: #FFFFFF; }
.mx-tag { align-self: flex-start; font-family: "IBM Plex Mono", ui-monospace, Menlo, monospace; font-size: 11px; padding: 2px 8px; border-radius: 4px; }
.mx-tag.built { background: #F4F6F3; color: #13202E; }
.mx-tag.part { border: 1px solid #FFB020; color: #FFB020; }
.mx-tag.plan { border: 1px dashed #A9B8C6; color: #C4D0DB; }
.mx-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.mx-item { display: block; width: 100%; padding: 8px 10px; margin: 0 -10px; border-radius: 8px; border: 0; background: transparent; color: #E6ECF0; text-align: left; font-size: 14px; }
button.mx-item { cursor: pointer; }
button.mx-item:hover { background: rgba(255,255,255,.05); }
.mx-item small { display: block; margin-top: 2px; font-size: 12.5px; color: #A9B8C6; line-height: 1.4; }
.mx-view { display: flex; align-items: flex-start; gap: 12px; width: 100%; padding: 12px; border-radius: 10px; border: 1px solid #2A3E52; background: #132538; color: #F4F6F3; text-align: left; cursor: pointer; transition: border-color .2s ease, transform .2s ease; }
.mx-view:hover { border-color: var(--c); transform: translateX(2px); }
.mx-view i { flex: none; width: 10px; height: 10px; margin-top: 6px; border-radius: 50%; background: var(--c); }
.mx-view b { display: block; font-family: "Space Grotesk", Inter, system-ui, sans-serif; font-size: 16px; font-weight: 600; }
.mx-view small { display: block; font-size: 12.5px; color: #A9B8C6; }
.mx-views { display: flex; flex-direction: column; gap: 8px; }
.mx-steps { display: flex; flex-wrap: wrap; gap: 6px; }
.mx-step { min-height: 30px; padding: 0 10px; border-radius: 6px; border: 1px solid color-mix(in srgb, var(--c) 55%, transparent); background: #0F2133; color: #E6ECF0; font-size: 12.5px; cursor: pointer; }
.mx-step:hover { border-color: var(--c); color: #FFFFFF; }
.mx-step.plan { border-style: dashed; }
.mx-pipe-name { font-weight: 600; font-size: 14px; color: #F4F6F3; }
.mx-legend { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: #C4D0DB; }
.mx-legend span { display: flex; align-items: center; gap: 10px; }
.mx-legend svg { flex: none; }
.mx-link { align-self: flex-start; display: inline-flex; align-items: center; min-height: 36px; color: #FFB020; font-weight: 600; font-size: 14px; text-decoration: none; }
.mx-link:hover { color: #FFD27A; text-decoration: underline; }
.mx-action { align-self: flex-start; min-height: 40px; padding: 0 16px; border-radius: 8px; border: 0; background: #FFB020; color: #13202E; font-weight: 600; font-size: 14px; cursor: pointer; }
.mx-action:hover { background: #FFC24D; }

/* ---------- Map ---------- */
.mx-stage { position: relative; min-width: 0; min-height: 0; overflow: hidden; overflow: clip; cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; background-color: #0B1724; background-image: radial-gradient(rgba(255,255,255,.06) 1px, transparent 1px); background-size: 24px 24px; }
.mx-stage.dragging { cursor: grabbing; }
.mx-world { position: absolute; left: 0; top: 0; width: 0; height: 0; transform-origin: 0 0; transition: transform .65s var(--ease); }
.mx-stage.dragging .mx-world, .mx-world.instant { transition: none; }
.mx-stage.dragging .mx-node { transition: opacity .3s ease, box-shadow .2s ease, border-color .2s ease; }
.mx-world.instant .mx-node, .mx-world.instant .mx-group { transition: none; }

.mx-edges { position: absolute; left: 0; top: 0; width: 1px; height: 1px; overflow: visible; pointer-events: none; transition: opacity .35s ease; }
.mx-stage.moving .mx-edges { opacity: 0; transition: none; }
.mx-edges path { fill: none; stroke: var(--c); stroke-width: 1.6; stroke-linecap: round; transition: opacity .25s ease, stroke-width .2s ease; }
.mx-edges .e-chain { stroke-width: 2; opacity: .75; }
.mx-edges .e-ring { stroke-width: 1; opacity: .35; }
.mx-edges .e-flow { stroke-width: 2; opacity: .85; }
.mx-edges .e-soft { stroke-width: 1.5; opacity: .35; }
.mx-edges .e-erp { stroke-dasharray: 6 5; opacity: .32; }
.mx-edges .e-post { opacity: .28; }
.mx-edges .e-other { stroke-dasharray: 1.5 4.5; stroke-width: 2; opacity: 0; }
/* The overview has many links; keep them quiet until something is hovered or chosen. */
.mx-stage.is-all .mx-edges path.e-erp:not(.lit):not(.dim) { opacity: .16; }
.mx-stage .mx-edges path.lit { opacity: 1; stroke-width: 2.4; }
.mx-edges .e-chain.lit { stroke-width: 2.4; }
.mx-stage .mx-edges path.dim { opacity: .05; }
.mx-stage .mx-edges path.e-other.dim { opacity: 0; }

.mx-group { position: absolute; box-sizing: border-box; border-radius: 14px; border: 1px solid #22364A; background: rgba(20,38,58,.55); pointer-events: none; transition: left .65s var(--ease), top .65s var(--ease), width .65s var(--ease), height .65s var(--ease), opacity .3s ease; }
.mx-group.card { border-color: color-mix(in srgb, var(--c) 40%, transparent); background: color-mix(in srgb, var(--c) 5%, rgba(20,38,58,.6)); }
.mx-group.erp { border-color: rgba(110,168,254,.4); background: rgba(26,51,80,.45); }
.mx-group.lane { border-style: dashed; background: rgba(255,255,255,.02); }
.mx-group.dim { opacity: .3; }
.mx-group.enter { opacity: 0; }

.mx-node { position: absolute; box-sizing: border-box; display: flex; flex-direction: column; justify-content: center; align-items: flex-start; gap: 2px; padding: 4px 10px; border-radius: 8px; border: 1px solid #2E4458; background: #132538; color: #F4F6F3; font-size: 12.5px; line-height: 1.2; text-align: left; cursor: pointer; transition: left .65s var(--ease), top .65s var(--ease), width .65s var(--ease), height .65s var(--ease), opacity .3s ease, transform .3s ease, box-shadow .2s ease, border-color .2s ease; }
.mx-node b { font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.mx-node small { font-size: 10.5px; font-weight: 500; color: #8FA0B0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.mx-node:hover { border-color: var(--c); }
.mx-node.core { align-items: center; text-align: center; background: #1A3350; border: 2px solid #6EA8FE; }
.mx-node.core.round { border-radius: 50%; justify-content: center; box-shadow: 0 0 40px rgba(110,168,254,.22); }
.mx-node.core b { font-family: "Space Grotesk", Inter, system-ui, sans-serif; font-size: 18px; }
.mx-node.fn { border-left: 3px solid #6EA8FE; background: #10233A; }
.mx-node.fn.plan { border-style: dashed; }
.mx-node.fn.quiet:not(.sel):not(:hover) { opacity: .42; }
.mx-node.hub { background: #14263A; border: 2px solid var(--c); }
.mx-node.hub b { font-family: "Space Grotesk", Inter, system-ui, sans-serif; font-size: 15px; }
.mx-node.hub small { color: var(--c); }
.mx-node.key { border-left: 3px solid var(--c); }
.mx-node.pipe { background: var(--c); border: 0; color: #0D1B2A; }
.mx-node.pipe small { color: rgba(13,27,42,.72); }
.mx-node.stage { background: #0F2133; border-color: color-mix(in srgb, var(--c) 55%, transparent); }
.mx-node.stage small { color: var(--c); }
.mx-node.stage small.note { color: #FFB020; }
.mx-node.stage.part { border-width: 2px; }
.mx-node.stage.plan { border-style: dashed; }
.mx-node.sel { box-shadow: 0 0 0 3px #F4F6F3, 0 0 24px rgba(255,255,255,.25); z-index: 2; }
.mx-node.dim { opacity: .16; }
.mx-node.enter { opacity: 0; transform: scale(.9); }
.mx-node.gone { opacity: 0; transform: scale(.9); pointer-events: none; }

/* ---------- Layout switch (top-left corner) ---------- */
.mx-corner { position: absolute; top: 12px; left: 12px; right: 12px; z-index: 3; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; pointer-events: none; }
.mx-corner > * { pointer-events: auto; }
.mx-mode { display: flex; gap: 2px; padding: 3px; border-radius: 10px; background: rgba(13,27,42,.92); border: 1px solid #2E4458; box-shadow: 0 6px 18px rgba(0,0,0,.3); }
.mx-mode button { min-height: 30px; padding: 0 11px; border-radius: 7px; border: 0; background: transparent; color: #A9B8C6; font-size: 12.5px; cursor: pointer; }
.mx-mode button:hover { color: #FFFFFF; }
.mx-mode button[aria-pressed="true"] { background: #F4F6F3; color: #13202E; font-weight: 600; }
.mx-stage.rot-drag { cursor: alias; }

/* ---------- Selection bar (bottom-left corner) ---------- */
.mx-selbar { display: flex; align-items: center; gap: 6px; min-width: 0; max-width: min(440px, 100%); padding: 4px 4px 4px 12px; border-radius: 10px; background: rgba(13,27,42,.95); border: 1px solid #2E4458; box-shadow: 0 6px 18px rgba(0,0,0,.35); animation: mx-pop .25s ease; }
.mx-selbar[hidden] { display: none; }
.mx-seltext { display: flex; flex-direction: column; min-width: 0; margin-right: 4px; line-height: 1.2; }
.mx-seltext small { font-family: "IBM Plex Mono", ui-monospace, Menlo, monospace; font-size: 10.5px; color: #8FA0B0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mx-seltext b { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mx-selbar .mx-btn[hidden] { display: none; }
.mx-btn.mx-min { font-size: 12.5px; font-weight: 600; white-space: nowrap; border-color: color-mix(in srgb, var(--c, #6EA8FE) 60%, #2E4458); }
.mx-btn.mx-detail { background: #FFB020; border-color: #FFB020; color: #13202E; font-size: 12.5px; font-weight: 600; }
.mx-stage.has-sel .mx-hint { display: none; }
@keyframes mx-pop { from { opacity: 0; transform: translateY(6px); } }

/* ---------- Zoom tools ---------- */
.mx-tools { position: absolute; left: 14px; right: 14px; bottom: calc(var(--sheet-h, 0px) + 14px); z-index: 3; display: flex; flex-wrap: wrap-reverse; align-items: center; justify-content: space-between; gap: 8px 10px; pointer-events: none; transition: bottom .3s var(--ease); }
.mx-tools > * { pointer-events: auto; }
.mx-hint { padding: 6px 12px; border-radius: 999px; background: rgba(13,27,42,.85); border: 1px solid #22364A; font-size: 12px; color: #A9B8C6; }
.mx-zoom { margin-left: auto; display: flex; align-items: center; gap: 3px; padding: 3px; border-radius: 10px; background: rgba(13,27,42,.92); border: 1px solid #2E4458; box-shadow: 0 8px 24px rgba(0,0,0,.35); }
.mx-btn { min-width: 32px; min-height: 32px; padding: 0 8px; border-radius: 7px; border: 1px solid #2E4458; background: #14263A; color: #F4F6F3; font-size: 14px; cursor: pointer; }
.mx-btn[aria-pressed="true"] { background: #FFB020; border-color: #FFB020; color: #13202E; font-weight: 600; }
.mx-rot { display: flex; align-items: center; gap: 3px; }
.mx-rot[hidden] { display: none; }
.mx-rot #rotDrag { font-size: 12px; }
.mx-sep { width: 1px; height: 20px; margin: 0 3px; background: #2E4458; }
.mx-btn:hover { border-color: #C4D0DB; }
.mx-fit { font-size: 12px; font-weight: 600; }
.mx-zoomtext { min-width: 40px; text-align: center; font-family: "IBM Plex Mono", ui-monospace, Menlo, monospace; font-size: 12px; color: #A9B8C6; }

/* ---------- Narrower landscape: slimmer sidebar ---------- */
@media (max-width: 1100px) {
  .mx { grid-template-columns: 300px minmax(0, 1fr); }
  .mx-hint { display: none; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .mx-head { padding-top: 10px; }
  .mx-title { font-size: 18px; }
  .mx-tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 10px; }
  .mx-body { padding-top: 10px; }
}

/* ---------- Portrait: bottom sheet ---------- */
@media (orientation: portrait) {
  .mx { display: block; position: relative; }
  .mx-stage { position: absolute; inset: 0; }
  .mx-side { position: absolute; left: 0; right: 0; bottom: 0; max-height: 72%; border-right: 0; border-top: 1px solid #2E4458; border-radius: 18px 18px 0 0; box-shadow: 0 -12px 32px rgba(0,0,0,.4); padding-bottom: env(safe-area-inset-bottom); }
  .mx-grip { display: flex; flex-direction: column; align-items: center; gap: 6px; width: 100%; padding: 8px 20px 2px; border: 0; background: none; color: #A9B8C6; font-size: 12px; cursor: pointer; }
  .mx-grip-bar { width: 40px; height: 4px; border-radius: 2px; background: #5C6E80; }
  .mx-grip:hover .mx-grip-bar { background: #C4D0DB; }
  .mx-head { padding: 4px 16px 4px; }
  .mx-title { font-size: 18px; }
  .mx-tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding: 6px 16px 12px; }
  .mx-tabs::-webkit-scrollbar { display: none; }
  .mx-side:not(.open) .mx-body { display: none; }
  .mx-side.open .mx-body { animation: mx-up .35s var(--ease); padding: 14px 16px 24px; }
  .mx-hint { display: none; }
}
@keyframes mx-up { from { opacity: 0; transform: translateY(16px); } }

@media (prefers-reduced-motion: reduce) {
  .mx-world, .mx-node, .mx-group, .mx-tools { transition: opacity .2s ease; }
  .mx-side.open .mx-body { animation: none; }
}
