/* The hover outlines that mark a layer's nodes in the page used to live
   here. They are drawn in js now, as fixed boxes inside the sysdebug shadow
   root, so no page css can suppress or clip them - see
   js/domElementOverlay.js. Their colours are variables on the overlay
   container, editable in the devtools just like the ones below. */

div.sysdebug.domLayersServer {
	left: 0;
	top: 20%;

	&.closed>div.head {
		border-radius: 0 10px 10px 0;
		min-width: 16px;
		flex: 0 0 50px;
		border-left: 4px solid #660066;
	}

	table.info {
		left: calc(100% + 0px);
	}


}

div.sysdebug.domLayersClient {
	right: 0;
	top: 20%;

	&.closed>div.head {
		border-radius: 10px 0 0 10px;
		min-width: 16px;
		flex: 0 0 50px;
		border-right: 4px solid #660066;
	}

	table.info {
		right: 100%;
	}

}

div.sysdebug.domLayersServer,
div.sysdebug.domLayersClient {
	/* Every colour of the layer trees, in one place, so they can be tried
	   out live: open the devtools, select this element and edit a value -
	   both trees follow at once. The rules below only reference them.

	   --layer-*        what the CLIENT does: keep / update / new
	   --layer-*-top    the same, for the outermost layer of a run (the
	                    :not(x) > x rules) - stronger, so a block of equal
	                    layers reads as one region
	   --ref-*          the reference tree's verdict, drawn as an outline
	   --overlay-*      NOT here: those sit on the overlay container itself,
	                    see tools/debug/js/domElementOverlay.js */
	--layer-keep: rgba(0, 0, 0, 0.1);
	--layer-update: rgba(0, 0, 0, 0.1);
	--layer-update-top: rgb(206, 255, 225);
	--layer-new: rgba(0, 0, 0, 0.1);
	--layer-new-top: rgb(206, 255, 253);

	/* Page layers take their own pair at the top of a run, so a page
	   subtree inside the cms reads as a region of its own. The muted
	   variants above are shared - only the top is worth the distinction. */
	--layer-page-update-top: rgb(226, 214, 255);
	/* violett */
	--layer-page-new-top: rgb(255, 214, 240);
	/* rosa */

	/* The box frames are structure, not signal: faint, so the colours and
	   the outline on top of them carry the meaning. */
	--layer-border: rgba(0, 0, 0, 0.2);
	/* The render-model marker is off: 'solid' makes a page layer look like
	   any other box. Set it to dashed or dotted to get the frame back that
	   says "from here down it is the page renderer". */
	--layer-source-page-style: solid;
	--layer-source-page-border: rgba(0, 0, 0, 0.2);
	--layer-placeholder-opacity: .45;

	/* The reference verdict, drawn on the frame of a reference layer. Only
	   the `replaced` state is styled - see the rule further down. */
	--ref-outline: 1px;
	--ref-outline-color: rgb(255, 0, 0);
	--ref-replaced-style: dashed;

	--layer-body-bg: gray;
	--layer-pre-bg: rgba(0, 0, 0, 0.1);
	--layer-info-bg: yellowgreen;

	/* Not layer frames, so they kept their full black: the hover table is a
	   popup that needs an edge, and the pin is a control whose visibility is
	   already driven by opacity. Variables anyway, in case you want them
	   faded like the boxes. */
	--layer-info-border: black;
	--layer-pin-border: black;

	table.info {
		position: absolute;
		border: 1px solid var(--layer-info-border);
		color: black;
		border-radius: 10px 10px 10px 10px;
		background: var(--layer-info-bg);
		top: -1px;

		tr:nth-child(even) {
			background-color: rgba(0, 0, 0, 0.1);
		}

		td {
			padding: 0 5px;
			white-space: nowrap;

			&.key {
				font-weight: normal;
			}

			&.value {
				font-weight: bold;
			}
		}

		span.caller {
			font-family: monospace;
		}

		span.caller.link {
			cursor: pointer;
			text-decoration: underline;
			color: #003a8c;
		}

		span.caller.link:hover {
			color: #c41a16;
		}
	}

	div.body {
		color: black;
		background: var(--layer-body-bg);

		div {
			display: block;
		}

		table.info {
			display: none
		}

		/* The header is the handle: hovering it opens its table, the circle on
		   the right keeps it open. Both are done by moving the table out of
		   here - see hoverflowout in js/htmlPrompt.js. Nothing below may show
		   a table in place: the boxes it sits in would clip it. */
		span.pin {
			display: block;
			position: absolute;
			right: 4px;
			top: 3px;
			width: 9px;
			height: 9px;
			padding: 0;
			box-sizing: border-box;
			border: 1px solid var(--layer-pin-border);
			border-radius: 50%;
			opacity: 0;
			cursor: pointer;
		}

		pre:hover>span.pin {
			opacity: .55;
		}

		span.pin:hover {
			opacity: 1;
		}

		pre.pinned>span.pin {
			opacity: 1;
			background: black;
		}

		div.domLayersContainer {
			display: flex;

		}

		div.domLayersContainer div {
			flex-direction: row;
			width: fit-content;
			border: 1px solid var(--layer-border);
			padding: 0;
			margin: 3px 20px;
		}

		div.domLayersContainer .slice {
			display: none;
		}

		div._debug.domLayers div.domLayersContainer {
			.slice {
				background: none;
				border: none;
				opacity: .5;
				margin-top: -18px;
				padding: 1px;
				height: 13px;
				display: block;
			}

			.layer {
				margin-bottom: 18px;
			}

			.layer>pre {
				margin-bottom: 18px;
			}

			.layer:hover>div.slice {
				opacity: 1;
			}
		}


		/* Colour = what the client does with the layer. The :not(x) > x form
		   only paints the TOP of a run: a block of layers that all did the
		   same thing reads as one region instead of a stack of frames. */
		:not(.new)>div.layer.new {
			background: var(--layer-new-top);
		}

		div.layer.new {
			background: var(--layer-new);
		}

		:not(.update)>div.layer.update {
			background: var(--layer-update-top);
		}

		div.layer.update {
			background: var(--layer-update);
		}

		div.layer.keep {
			background: var(--layer-keep);
		}

		/* The same for page layers, one class more so they win - but "top"
		   means one thing more here. A page layer starts a region when its
		   parent is of another type (as above) OR when the parent is not a
		   page at all: that is the boundary where the page renderer takes
		   over from the panels.

		   Without the second selector the cms preview stayed muted. A full
		   cms render has no reference, so every panel layer above the
		   preview is `new` too - the parent matched `.new`, `:not(.new)`
		   failed, and the one box that should mark the boundary did not. */
		:not(.new)>div.layer.new.source-page,
		:not(.source-page)>div.layer.new.source-page {
			background: var(--layer-page-new-top);
		}

		:not(.update)>div.layer.update.source-page,
		:not(.source-page)>div.layer.update.source-page {
			background: var(--layer-page-update-top);
		}

		/** pages **/
		/* The render model as an edge - background is taken (it says what the
		   client does), so this axis gets the frame. Only the OUTERMOST page
		   layer is drawn: everything inside one is a page as well, and the cms
		   preview nests ~150 of them.

		   Currently neutral, see --layer-source-page-style. The class is still
		   emitted by both trees, so it is one word away. */
		:not(.source-page)>div.layer.source-page {
			border: 1px var(--layer-source-page-style) var(--layer-source-page-border);
		}

		/* An insertion point that stayed empty: the open was cancelled and the
		   slot only exists so the child index keeps lining up. The `reason`
		   row says why ("reached end of children").

		   Third channel, and deliberately not one of the other two: the
		   background means diff type, the border means render model, so this
		   takes the weight. A cancelled layer never has children, so fading
		   the whole box is safe. */
		div.layer.placeholder {
			opacity: var(--layer-placeholder-opacity);
		}

		div.layer.placeholder>pre {
			font-style: italic;
		}

		/* Reference tree only: was this dom thrown away? An OUTLINE, not a
		   border and not a colour - the box already uses its background for
		   what it was when it was current, and its border for the render
		   model. outline draws outside the box and overlaps nothing.

		   Only `replaced` is drawn. A box without it either survived
		   (`kept`) or was never compared - both classes are still emitted by
		   the server, so telling those two apart is a rule away. */
		div.layer.replaced {
			outline: var(--ref-outline) var(--ref-replaced-style) var(--ref-outline-color);
			outline-offset: -1px;
		}

		pre {
			background: var(--layer-pre-bg);
			/* room for the pin: it is positioned out of flow, so a label that
			   fills the header would otherwise run underneath it */
			padding-right: 18px;
		}


		pre,
		div.slice {
			position: relative;
		}

		div.layer:hover>pre {
			font-weight: bold;
			text-decoration: underline;
		}
	}

}

div.sysdebug.panelTreeDebug {
	left: 0;
	top: 50%;

	&.closed>div.head {
		border-radius: 0 10px 10px 0;
		min-width: 16px;
		flex: 0 0 50px;
		border-left: 4px solid #006666;
	}

	table.info {
		left: calc(100% + 0px);
	}

	table.info {
		position: absolute;
		border: 1px solid black;
		color: black;
		border-radius: 10px;
		background: #b0d0e8;
		top: -1px;

		tr:nth-child(even) {
			background-color: rgba(0, 0, 0, 0.1);
		}

		td {
			padding: 0 5px;
			white-space: nowrap;

			&.key {
				font-weight: normal;
			}

			&.value {
				font-weight: bold;
			}
		}

		span.caller {
			font-family: monospace;
		}

		span.caller.link {
			cursor: pointer;
			text-decoration: underline;
			color: #003a8c;
		}

		span.caller.link:hover {
			color: #c41a16;
		}
	}

	div.body {
		color: black;
		background: #556;

		div {
			display: block;
		}

		table.info {
			display: none;
		}

		div.panelTreeDebugContainer {
			display: flex;
		}

		div.panelTreeDebugContainer div {
			flex-direction: row;
			width: fit-content;
			border: 1px solid black;
			padding: 0;
			margin: 3px 20px;
		}

		div.panel {
			background: rgba(0, 180, 220, 0.1);
		}

		div.panel.inPath {
			background: rgba(0, 180, 220, 0.25);
		}

		div.panel.selected {
			background: rgba(0, 220, 120, 0.4);
		}

		div.buildLogContainer {
			margin-top: 10px;
			border-top: 2px solid rgba(0, 0, 0, 0.3);
		}

		div.buildEvent {
			background: rgba(255, 200, 0, 0.1);
		}

		div.buildEvent.accessDenied {
			background: rgba(255, 80, 0, 0.2);
		}

		div.buildEvent.scanChildren {
			background: rgba(100, 100, 255, 0.15);
		}

		pre {
			background: rgba(0, 0, 0, 0.1);
		}

		pre,
		div.buildEvent {
			position: relative;
		}

		div.panel:hover>pre {
			font-weight: bold;
			text-decoration: underline;
		}
	}
}