/**
 * ReportCharts (assets/js/report-charts.js): the hourly column chart and the issue ring.
 *
 * Every colour is a CSS variable - the theme's (--text-color, --content-bg) and the plugin's
 * status colours - so dark mode and custom colours need nothing from the script. A chart
 * takes its colour from --rb-status, which its data-status sets, or which a parent sets
 * (the report box does, for its frame and count too).
 */

.rb-chart,
.rb-ring {
	--rb-grid: color-mix(in srgb, var(--text-color, #333) 10%, transparent);
}

.rb-chart[data-status="success"],
.rb-ring[data-status="success"] {
	--rb-status: var(--status-success);
}

.rb-chart[data-status="warning"],
.rb-ring[data-status="warning"] {
	--rb-status: var(--status-warning);
}

.rb-chart[data-status="critical"],
.rb-ring[data-status="critical"] {
	--rb-status: var(--status-critical);
}

/* ============================================
   COLUMN CHART
   The scale on the left, a column per hour, the hours along the bottom.
   ============================================ */

.rb-chart {
	display: grid;
	grid-template-columns: auto 1fr;
	grid-template-rows: 1fr auto;
	column-gap: 6px;
	row-gap: 5px;
	font-size: 10px;
	line-height: 1;
	color: var(--text-color, #333);
	font-variant-numeric: tabular-nums;
}

.rb-scale {
	position: relative;
	grid-area: 1 / 1;
	min-width: calc(var(--rb-digits, 1) * 0.65em + 2px);
	opacity: 0.6;
}

.rb-scale span {
	position: absolute;
	inset-inline-end: 0;
	transform: translateY(-50%);
}

/* Grid lines at every step of the scale, the axis along the bottom. */
.rb-plot {
	position: relative;
	grid-area: 1 / 2;
	display: flex;
	gap: 2px;
	background: linear-gradient(to bottom, var(--rb-grid) 1px, transparent 1px) 0 0 / 100% calc(100% / var(--rb-steps, 2));
	border-bottom: 1px solid color-mix(in srgb, var(--text-color, #333) 25%, transparent);
	touch-action: pan-y;
}

/* Each column is the full height, so a low or empty hour is as easy to point at as a tall
   one; what it reports is drawn by ::after. */
.rb-bar {
	position: relative;
	flex: 1;
	border-radius: 3px 3px 0 0;
}

.rb-bar::after {
	content: '';
	position: absolute;
	inset-inline: 0;
	bottom: 0;
	height: var(--h);
	background: var(--rb-status, var(--status-success));
	opacity: 0.45;
	border-radius: 2px 2px 0 0;
	transition: height 0.4s ease, opacity 0.15s ease, background-color 0.4s ease;
}

/* The last two hours decide the status, so they are drawn at full strength. */
.rb-bar.is-recent::after,
.rb-bar.is-active::after {
	opacity: 1;
}

.rb-bar.is-active {
	background: var(--rb-grid);
}

/* An hour under its column; the first and last are kept inside the chart. */
.rb-time {
	position: relative;
	grid-area: 2 / 2;
	height: 1em;
	opacity: 0.6;
	white-space: nowrap;
}

.rb-time span {
	position: absolute;
	inset-inline-start: var(--x);
	transform: translateX(-50%);
}

[dir="rtl"] .rb-time span {
	transform: translateX(50%);
}

.rb-time span.is-first {
	inset-inline-start: 0;
	transform: none;
}

.rb-time span.is-last {
	inset-inline-start: auto;
	inset-inline-end: 0;
	transform: none;
}

.rb-tip {
	position: absolute;
	bottom: calc(100% + 6px);
	transform: translateX(-50%);
	max-width: 100%;
	width: max-content;
	padding: 6px 9px;
	border-radius: 6px;
	background: var(--text-color, #333);
	color: var(--content-bg, #fff);
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
	display: flex;
	flex-direction: column;
	gap: 2px;
	text-align: center;
	font-size: 11px;
	line-height: 1.3;
	pointer-events: none;
	z-index: 5;
}

.rb-tip[hidden] {
	display: none;
}

.rb-tip strong {
	font-size: 13px;
}

/* ============================================
   RING
   One percentage, drawn with a conic gradient and a hole cut by a mask.
   ============================================ */

.rb-ring {
	--rb-track: var(--rb-grid);
	--rb-thickness: 14%;
	position: relative;
	width: 100%;
	aspect-ratio: 1;
	border-radius: 50%;
	background: conic-gradient(var(--rb-status, var(--status-success)) calc(var(--p) * 1%), var(--rb-track) 0);
	display: grid;
	place-items: center;
}

.rb-ring::before {
	content: '';
	position: absolute;
	inset: var(--rb-thickness);
	border-radius: 50%;
	background: var(--content-bg, #fff);
}

.rb-ring span {
	position: relative;
	font-size: clamp(16px, 4.5vw, 30px);
	font-weight: 700;
	color: var(--rb-status, var(--status-success));
	font-variant-numeric: tabular-nums;
}

@media screen and (max-width: 600px) {
	.rb-ring {
		--rb-thickness: 11%;
	}
}

/* ============================================
   BADGE
   Reports in the last 24 hours in the status colour - icon, number, word: "148 reports".
   On the report boxes and in the related list. The status comes from data-status on the
   badge, or from --rb-status set by a parent.
   ============================================ */

.rb-badge[data-status="success"] {
	--rb-status: var(--status-success);
}

.rb-badge[data-status="warning"] {
	--rb-status: var(--status-warning);
}

.rb-badge[data-status="critical"] {
	--rb-status: var(--status-critical);
}

.rb-badge {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	width: fit-content;
	padding: 5px 11px 5px 8px;
	border-radius: 999px;
	background: var(--rb-status, var(--status-success));
	color: #fff;
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
	font-size: 13px;
	font-weight: 700;
	line-height: 1;
	white-space: nowrap;
	font-variant-numeric: tabular-nums;
}

/* Yellow takes dark text. */
.rb-badge[data-status="warning"] {
	color: #1d1d1d;
}

/* Nothing to show until the numbers are in - but the place is kept, so nothing jumps when
   they arrive. */
.rb-badge[data-filled="0"] {
	visibility: hidden;
}

.rb-badge-number {
	font-size: 1.15em;
}

.rb-badge-number:empty::before {
	content: '0';
}

.rb-badge-word {
	font-weight: 600;
}

.rb-badge-icon {
	width: 1.1em;
	height: 1.1em;
	flex: none;
	background-color: currentColor;
	mask: url('../img/signs-outage/check.svg') center / contain no-repeat;
	-webkit-mask: url('../img/signs-outage/check.svg') center / contain no-repeat;
}

.rb-badge[data-status="warning"] .rb-badge-icon {
	mask-image: url('../img/signs-outage/question.svg');
	-webkit-mask-image: url('../img/signs-outage/question.svg');
}

.rb-badge[data-status="critical"] .rb-badge-icon {
	mask-image: url('../img/signs-outage/minus.svg');
	-webkit-mask-image: url('../img/signs-outage/minus.svg');
}

@media screen and (max-width: 768px) {
	.rb-badge {
		padding: 4px 8px 4px 6px;
		gap: 4px;
		font-size: 11px;
	}
}
