/*
 * Graylog Code Blocks: front-end styles.
 * Everything is scoped to .glc-* classes so the theme is not affected.
 * Selectors are a little heavier than usual (div.glc-wrap pre.glc) because
 * Elementor and the theme ship their own <pre> styles that would otherwise win.
 */

/* Outer frame added by front.js: top bar + the <pre>. */
div.glc-wrap {
	--glc-max-lines: 22;            /* tallest a block gets before it scrolls; change this one number */
	position: relative;
	margin: 1.5em 0;
	border-radius: 8px;
	overflow: hidden;
	background: #f6f8fb;            /* light grey-blue */
	border: 1px solid #dde3ec;
	font-size: 14px;
}

/* Top bar: block type on the left, Copy button on the right. */
div.glc-wrap .glc-bar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 6px 8px 6px 14px;
	background: #eef2f7;
	border-bottom: 1px solid #dde3ec;
	font-family: Arial, Helvetica, sans-serif;
}

div.glc-wrap .glc-label {
	font-size: 11px;
	font-weight: 700;
	letter-spacing: 1px;
	text-transform: uppercase;
	color: #5b6b82;
}

div.glc-wrap button.glc-copy {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	margin: 0;
	padding: 5px 12px;
	font: 600 12px/1.2 Arial, Helvetica, sans-serif;
	color: #0d2240;                 /* Graylog navy text */
	background: #ffffff;
	border: 1px solid #c9d2df;
	border-radius: 6px;
	cursor: pointer;
	text-transform: none;
	letter-spacing: 0;
	box-shadow: none;
	transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

div.glc-wrap button.glc-copy:hover,
div.glc-wrap button.glc-copy:focus-visible {
	background: #e3e9f2;
	border-color: #aebbd0;
	color: #0d2240;
}

div.glc-wrap button.glc-copy:focus-visible {
	outline: 2px solid #0d2240;
	outline-offset: 2px;
}

/* "Copied" state: Graylog mint. */
div.glc-wrap button.glc-copy.is-copied {
	background: #00e1a0;
	border-color: #00c48c;
	color: #0d2240;
}

div.glc-wrap button.glc-copy svg {
	width: 14px;
	height: 14px;
	flex: none;
}

/* The code itself. Shared by both types. */
div.glc-wrap pre.glc {
	margin: 0;
	padding: 14px 16px;
	background: transparent;
	border: 0;
	border-radius: 0;
	color: #1a2233;
	font-family: "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
	font-size: 13.5px;
	line-height: 1.6;
	tab-size: 4;
	-moz-tab-size: 4;
	/* Height cap: N lines (line-height 1.6em each) plus top and bottom padding.
	   Longer blocks scroll inside the box; Copy still copies everything. */
	max-height: calc(var(--glc-max-lines) * 1.6em + 28px);
	overflow-y: auto;
	overscroll-behavior: contain;  /* scrolling to the end of a block does not jerk the page */
}

/* Fade at the bottom so readers can tell there is more to scroll.
   front.js adds .is-scrollable when the code is taller than the cap,
   and .at-end once the reader has scrolled to the bottom. */
div.glc-wrap.is-scrollable:not(.at-end)::after {
	content: "";
	position: absolute;
	left: 0;
	right: 0;
	bottom: 0;
	height: 36px;
	background: linear-gradient(to bottom, rgba(246, 248, 251, 0), #f6f8fb);
	pointer-events: none;
	border-radius: 0 0 8px 8px;
}

div.glc-wrap pre.glc code {
	display: block;
	padding: 0;
	margin: 0;
	background: transparent;
	border: 0;
	color: inherit;
	font: inherit;
	white-space: inherit;
	word-break: inherit;
	overflow-wrap: inherit;
}

/* ---- CodeW: wrap everything, no line numbers. For big log messages. ---- */
div.glc-wrap pre.glc-w {
	white-space: pre-wrap;
	overflow-wrap: anywhere;   /* breaks long tokens like hashes and URLs */
	word-break: normal;
	overflow-x: visible;
}

/* ---- CodeYML: keep every line intact, scroll sideways, number lines. ---- */
div.glc-wrap pre.glc-yml {
	white-space: pre;
	overflow-wrap: normal;
	word-break: normal;
	overflow-x: auto;
	padding-left: 0;
}

div.glc-wrap pre.glc-yml code {
	counter-reset: glc-ln;
	width: max-content;
	min-width: 100%;
}

div.glc-wrap pre.glc-yml .glc-line::before {
	counter-increment: glc-ln;
	content: counter(glc-ln);
	display: inline-block;
	width: var(--glc-gutter, 2ch);
	margin-right: 16px;
	padding: 0 12px 0 16px;     /* left padding matches CodeW's inner spacing */
	box-sizing: content-box;
	text-align: right;
	color: #8a96a8;
	border-right: 1px solid #dde3ec;
	-webkit-user-select: none;
	user-select: none;          /* numbers are never selected or copied */
}

/* Small screens: slightly smaller text so more of each line fits. */
@media (max-width: 600px) {
	div.glc-wrap pre.glc {
		font-size: 12.5px;
	}
}

/* Fallback if the script has not run (or JavaScript is off): still readable. */
pre.glc:not(.glc-ready) {
	background: #f6f8fb;
	color: #1a2233;
	border: 1px solid #dde3ec;
	padding: 14px 16px;
	border-radius: 8px;
	font-family: "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
	font-size: 13.5px;
	line-height: 1.6;
	max-height: calc(22 * 1.6em + 28px);
	overflow-y: auto;
}
pre.glc-w:not(.glc-ready) {
	white-space: pre-wrap;
	overflow-wrap: anywhere;
}
pre.glc-yml:not(.glc-ready) {
	white-space: pre;
	overflow-x: auto;
}
