/*
 * The staff home (apps/core/templates/admin/lua_dashboard.html, apps.core.dashboard_ui).
 *
 * Layout: the hero, then one band (needs attention beside most urgent), then the panel
 * cards in a wrapping row. A card's base width comes from its size (half, wide, narrow)
 * and it grows to fill its line, so a panel a role does not see leaves no gap. Each card
 * is a size container: when it is wide enough, its chart sits beside its figures.
 *
 * Unfold's theme variables (--color-primary-*, --color-base-*) and its `.dark` class give
 * the colours in light and dark mode. Class names start with `ld-`, so none meets Unfold's.
 */

.ld {
	--ld-radius: 10px;
	--ld-gap: 1.25rem;
	--ld-card: #fff;
	--ld-chart-strong: var(--color-primary-700);
	--ld-chart-mid: var(--color-primary-500);
	--ld-chart-soft: var(--color-primary-300);
	--ld-line: var(--color-base-200);
	--ld-text: var(--color-base-900);
	--ld-muted: var(--color-base-600);
	--ld-soft: var(--color-base-50);
	--ld-danger: #b91c1c;
	--ld-danger-soft: #fef2f2;
	--ld-warn: #b45309;
	display: flex;
	flex-direction: column;
	gap: var(--ld-gap);
	color: var(--ld-text);
	font-variant-numeric: tabular-nums;
}

.dark .ld {
	--ld-chart-strong: var(--color-primary-200);
	--ld-chart-mid: var(--color-primary-400);
	--ld-chart-soft: var(--color-primary-500);
	--ld-card: var(--color-base-900);
	--ld-line: var(--color-base-800);
	--ld-text: var(--color-base-100);
	--ld-muted: var(--color-base-400);
	--ld-soft: rgb(255 255 255 / 0.04);
	--ld-danger: #f87171;
	--ld-danger-soft: rgb(220 38 38 / 0.16);
	--ld-warn: #fbbf24;
}

.ld p,
.ld ul,
.ld ol,
.ld figure {
	margin: 0;
}

.ld ul,
.ld ol {
	padding: 0;
	list-style: none;
}

.ld a:focus-visible,
.ld summary:focus-visible,
.ld button:focus-visible,
.ld [tabindex]:focus-visible {
	outline: 2px solid var(--color-primary-500);
	outline-offset: 2px;
	border-radius: 8px;
}

/* --- the hero ---------------------------------------------------------------------------- */

.ld-hero {
	position: relative;
	border: 1px solid var(--ld-line);
	border-radius: var(--ld-radius);
	padding: 1.5rem;
	color: var(--ld-text);
	background: var(--ld-card);
}

.ld-hero-top {
	position: relative;
	/* Above the KPI row, so the custom dates open over it. */
	z-index: 2;
	display: flex;
	flex-wrap: wrap;
	align-items: flex-start;
	justify-content: space-between;
	gap: 1rem;
}

.ld-hello {
	font-size: 1.75rem;
	font-weight: 700;
	letter-spacing: -0.02em;
	line-height: 1.15;
}

.ld .ld-date {
	margin-top: 0.35rem;
	font-size: 0.875rem;
	color: var(--ld-muted);
}

.ld-live {
	margin-left: 0.35rem;
	font-weight: 600;
	color: var(--ld-muted);
}

.ld-periods {
	display: flex;
	align-items: center;
	gap: 0.25rem;
	padding: 0.25rem;
	border-radius: 999px;
	background: var(--ld-soft);
}

.ld-periods a,
.ld-periods summary {
	display: inline-block;
	padding: 0.4rem 0.85rem;
	border-radius: 999px;
	font-size: 0.8125rem;
	font-weight: 600;
	white-space: nowrap;
	color: var(--ld-muted);
	text-decoration: none;
	cursor: pointer;
	list-style: none;
}

.ld-periods summary::-webkit-details-marker {
	display: none;
}

.ld-periods a:hover,
.ld-periods summary:hover {
	color: var(--ld-text);
	background: var(--ld-soft);
}

.ld-periods [aria-current="true"],
.ld-periods details[open] summary {
	color: var(--ld-text);
	background: var(--ld-card);
	box-shadow: 0 0 0 1px var(--ld-line);
}

.ld-custom {
	position: relative;
}

.ld-custom form {
	position: absolute;
	right: 0;
	top: calc(100% + 0.5rem);
	z-index: 20;
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
	align-items: flex-end;
	width: 18rem;
	padding: 0.85rem;
	border-radius: 12px;
	background: var(--ld-card);
	color: var(--ld-text);
	box-shadow: 0 12px 32px rgb(0 0 0 / 0.18);
}

.ld-custom label {
	display: block;
	font-size: 0.75rem;
	font-weight: 600;
	color: var(--ld-muted);
}

.ld-custom input {
	width: 7.5rem;
	margin-top: 0.2rem;
	padding: 0.4rem 0.55rem;
	border: 1px solid var(--ld-line);
	border-radius: 8px;
	background: transparent;
	color: inherit;
}

.ld-button {
	padding: 0.45rem 0.9rem;
	border: 0;
	border-radius: 8px;
	background: var(--color-primary-600);
	color: #fff;
	font-weight: 600;
	cursor: pointer;
}

.ld-kpis {
	position: relative;
	z-index: 1;
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(min(100%, 10rem), 1fr));
	gap: 0.75rem;
	margin-top: 1.5rem;
}

.ld-kpi {
	display: block;
	padding: 1rem 1.15rem;
	border-radius: var(--ld-radius);
	background: var(--ld-soft);
	border: 1px solid var(--ld-line);
	color: var(--ld-text);
	text-decoration: none;
	transition:
		background 150ms ease,
		transform 150ms ease;
}

.ld-kpi:hover {
	background: var(--ld-card);
	border-color: var(--color-primary-500);
}

.ld-kpi > span,
.ld-tile > span {
	display: block;
}

.ld-kpi-label {
	font-size: 0.8125rem;
	color: var(--ld-muted);
}

.ld-kpi-value {
	margin-top: 0.25rem;
	font-size: 2rem;
	font-weight: 700;
	letter-spacing: -0.02em;
	line-height: 1.1;
}

.ld-kpi-when {
	margin-top: 0.3rem;
	font-size: 0.75rem;
	color: var(--ld-muted);
}

.ld .ld-error {
	position: relative;
	z-index: 1;
	margin-top: 1rem;
	padding: 0.6rem 0.85rem;
	border-radius: 10px;
	background: rgb(255 255 255 / 0.95);
	color: #b91c1c;
	font-size: 0.875rem;
}

/* --- cards --------------------------------------------------------------------------------- */

.ld-card {
	min-width: 0;
	padding: 1.25rem 1.35rem;
	border: 1px solid var(--ld-line);
	border-radius: var(--ld-radius);
	background: var(--ld-card);
}

.ld-head {
	display: flex;
	flex-wrap: wrap;
	align-items: flex-start;
	justify-content: space-between;
	gap: 0.25rem 1rem;
	margin-bottom: 1rem;
}

.ld-title {
	font-size: 1.0625rem;
	font-weight: 700;
	letter-spacing: -0.01em;
	color: var(--ld-text);
}

.ld .ld-sub {
	margin-top: 0.15rem;
	font-size: 0.8125rem;
	color: var(--ld-muted);
}

.ld .ld-subhead {
	margin: 0 0 0.5rem;
	font-size: 0.6875rem;
	font-weight: 700;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	color: var(--ld-muted);
}

.ld-link {
	font-size: 0.8125rem;
	font-weight: 600;
	color: var(--color-primary-600);
	text-decoration: none;
	white-space: nowrap;
}

.dark .ld-link {
	color: var(--color-primary-300);
}

.ld-link:hover {
	text-decoration: underline;
}

/* --- the attention band: areas beside the most urgent items -------------------------------- */

.ld-band {
	display: grid;
	grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
	gap: var(--ld-gap);
	/* Each card its own height: a short list leaves no empty box below it. */
	align-items: start;
}

.ld-overdue-text {
	font-weight: 600;
	color: var(--ld-danger);
}

.ld-areas {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 0.35rem 1rem;
}

.ld-area {
	display: flex;
	align-items: center;
	gap: 0.65rem;
	height: 100%;
	padding: 0.5rem 0.6rem;
	border-radius: 12px;
	color: var(--ld-text);
	text-decoration: none;
	transition: background 150ms ease;
}

.ld-area:hover {
	background: var(--ld-soft);
}

.ld-area-icon {
	display: grid;
	place-items: center;
	flex: none;
	width: 2.1rem;
	height: 2.1rem;
	border-radius: 10px;
	background: var(--color-primary-50);
	color: var(--color-primary-700);
	font-size: 1.15rem;
}

.dark .ld-area-icon {
	background: rgb(255 255 255 / 0.06);
	color: var(--color-primary-300);
}

.ld-area[data-overdue] .ld-area-icon {
	background: var(--ld-danger-soft);
	color: var(--ld-danger);
}

.ld-area-label {
	flex: 1;
	min-width: 0;
	font-size: 0.8125rem;
	line-height: 1.3;
}

.ld-tag {
	flex: none;
	padding: 0.1rem 0.45rem;
	border-radius: 999px;
	font-size: 0.6875rem;
	font-weight: 700;
	background: var(--ld-danger-soft);
	color: var(--ld-danger);
}

.ld-area-count {
	flex: none;
	min-width: 2rem;
	padding: 0.15rem 0.5rem;
	border-radius: 999px;
	background: var(--ld-soft);
	font-size: 0.9375rem;
	font-weight: 700;
	text-align: center;
}

.ld .ld-clear {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.25rem;
	margin-top: 1rem;
	padding-top: 0.85rem;
	border-top: 1px solid var(--ld-line);
	font-size: 0.75rem;
	color: var(--ld-muted);
}

.ld-clear .material-symbols-outlined {
	font-size: 1rem;
	color: var(--color-primary-500);
}

.ld-clear span + span:not(.material-symbols-outlined)::before {
	content: "· ";
}

.ld-calm {
	display: flex;
	align-items: center;
	gap: 1rem;
	padding: 0.9rem 1.25rem;
}

.ld-calm-icon {
	display: grid;
	place-items: center;
	flex: none;
	width: 2.5rem;
	height: 2.5rem;
	border-radius: 999px;
	background: var(--color-primary-50);
	color: var(--color-primary-600);
}

.dark .ld-calm-icon {
	background: rgb(255 255 255 / 0.06);
	color: var(--color-primary-300);
}

.ld-calm-text {
	flex: 1;
	min-width: 0;
}

.ld .ld-calm .ld-clear {
	margin-top: 0.15rem;
	padding-top: 0;
	border-top: 0;
}

.ld-allclear {
	display: flex;
	align-items: center;
	gap: 0.6rem;
	font-size: 0.875rem;
	color: var(--ld-muted);
}

.ld-urgent {
	display: flex;
	flex-direction: column;
	gap: 0.5rem;
}

.ld-urgent li {
	padding: 0.6rem 0.75rem;
	border-left: 3px solid #f59e0b;
	border-radius: 0 10px 10px 0;
	background: var(--ld-soft);
}

.ld-urgent li[data-overdue] {
	border-left-color: var(--ld-danger);
}

.ld-urgent-line {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 0.5rem;
}

.ld-urgent-id {
	font-size: 0.8125rem;
	font-weight: 700;
	color: var(--ld-text);
	text-decoration: none;
	white-space: nowrap;
}

a.ld-urgent-id:hover {
	text-decoration: underline;
}

.ld-when {
	font-size: 0.75rem;
	font-weight: 700;
	white-space: nowrap;
	color: var(--ld-warn);
}

li[data-overdue] .ld-when {
	color: var(--ld-danger);
}

.ld .ld-urgent-what {
	margin-top: 0.1rem;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	font-size: 0.8125rem;
}

.ld-urgent-kind {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	font-size: 0.75rem;
	color: var(--ld-muted);
}

/* --- the panel cards ------------------------------------------------------------------------ */

.ld-grid {
	display: flex;
	flex-wrap: wrap;
	gap: var(--ld-gap);
}

.ld-panel {
	display: flex;
	flex-direction: column;
	flex: 1 1 calc(50% - var(--ld-gap));
	container-type: inline-size;
}

.ld-panel[data-size="wide"] {
	flex-basis: calc(64% - var(--ld-gap));
}

.ld-panel[data-size="narrow"] {
	flex-basis: calc(32% - var(--ld-gap));
	min-width: 18rem;
}

.ld-body {
	display: flex;
	flex-direction: column;
	gap: 1rem;
}

.ld-chart-box {
	position: relative;
	height: 13rem;
}

.ld-chart-box[data-type="doughnut"] {
	height: 11.5rem;
}

.ld-tiles {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr));
	align-content: start;
	gap: 0.6rem;
}

/* A wide enough card: the chart on the left, the figures on the right. */
@container (min-width: 40rem) {
	.ld-body:has(.ld-chart):has(.ld-tiles) {
		display: grid;
		grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
		column-gap: 1.5rem;
	}
}

.ld-tile {
	display: block;
	padding: 0.75rem 0.85rem;
	border-radius: 12px;
	background: var(--ld-soft);
	color: var(--ld-text);
	text-decoration: none;
	transition: background 150ms ease;
}

.ld-tile:hover {
	background: var(--color-primary-50);
}

.dark .ld-tile:hover {
	background: rgb(255 255 255 / 0.08);
}

.ld-tile-label {
	font-size: 0.75rem;
	line-height: 1.3;
	color: var(--ld-muted);
}

.ld-tile-value {
	margin-top: 0.3rem;
	font-size: 1.35rem;
	font-weight: 700;
	letter-spacing: -0.01em;
}

.ld-tile-value[data-empty] {
	font-size: 0.95rem;
	font-weight: 600;
	color: var(--ld-muted);
}

.ld-tile-when {
	margin-top: 0.15rem;
	font-size: 0.6875rem;
	color: var(--ld-muted);
}

.ld-foot {
	display: flex;
	flex-wrap: wrap;
	gap: 0.25rem 1.25rem;
	margin-top: auto;
	padding-top: 0.85rem;
}

details.ld-more {
	font-size: 0.75rem;
}

details.ld-more summary {
	width: fit-content;
	color: var(--ld-muted);
	cursor: pointer;
}

details.ld-more[open] {
	flex-basis: 100%;
}

details.ld-more table {
	width: 100%;
	margin-top: 0.5rem;
	border-collapse: collapse;
	font-size: 0.8125rem;
}

details.ld-more th,
details.ld-more td {
	padding: 0.35rem 0.25rem;
	border-bottom: 1px solid var(--ld-line);
	text-align: right;
}

details.ld-more th:first-child,
details.ld-more td:first-child {
	text-align: left;
}

details.ld-more dl {
	display: grid;
	gap: 0.5rem;
	margin-top: 0.5rem;
	font-size: 0.8125rem;
}

details.ld-more dt {
	font-weight: 600;
}

details.ld-more dd {
	margin: 0;
	color: var(--ld-muted);
}

/* --- narrower screens ------------------------------------------------------------------------ */

@media (max-width: 1279px) {
	.ld-band {
		grid-template-columns: minmax(0, 1fr);
	}
}

@media (max-width: 1023px) {
	.ld-kpis {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}

	.ld-panel,
	.ld-panel[data-size] {
		flex-basis: 100%;
	}
}

@media (max-width: 639px) {
	.ld {
		--ld-gap: 1rem;
	}

	.ld-hero {
		padding: 1.25rem;
	}

	.ld-hello {
		font-size: 1.4rem;
	}

	.ld-kpi-value {
		font-size: 1.6rem;
	}

	.ld-periods {
		width: 100%;
		justify-content: space-between;
	}

	.ld-periods a,
	.ld-periods summary {
		padding: 0.4rem 0.55rem;
		font-size: 0.75rem;
	}

	.ld-card {
		padding: 1rem;
	}

	.ld-areas {
		grid-template-columns: minmax(0, 1fr);
	}

	.ld-tiles {
		grid-template-columns: repeat(2, minmax(0, 1fr));
		gap: 0.5rem;
	}

	.ld-panel[data-size="narrow"] {
		min-width: 0;
	}
}

@media (prefers-reduced-motion: reduce) {
	.ld-kpi,
	.ld-area,
	.ld-tile {
		transition: none;
	}

	.ld-kpi:hover {
		transform: none;
	}
}

/* Working controls keep attention on data rather than decoration. */
.ld .ld-eyebrow {
	font-size: 0.75rem;
	font-weight: 650;
	text-transform: uppercase;
	letter-spacing: 0.08em;
	color: var(--ld-muted);
	margin-bottom: 0.5rem;
}
.ld-shortcuts {
	display: flex;
	flex-wrap: wrap;
	gap: 0.6rem;
}
.ld-shortcuts a {
	display: inline-flex;
	align-items: center;
	gap: 0.5rem;
	min-height: 44px;
	border: 1px solid var(--ld-line);
	border-radius: 8px;
	padding: 0.6rem 0.9rem;
	font-size: 0.8125rem;
	background: var(--ld-card);
}
.ld-shortcuts a:hover {
	border-color: var(--color-primary-600);
}
.ld-shortcuts .material-symbols-outlined {
	font-size: 20px;
	color: var(--color-primary-600);
}
.ld-toolbar {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	padding: 1rem 0;
	border-block: 1px solid var(--ld-line);
}
.ld-filters,
.ld-refresh-controls {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.75rem;
	font-size: 0.8125rem;
}
.ld-filters select {
	border: 1px solid var(--ld-line);
	border-radius: 6px;
	background: var(--ld-card);
	color: var(--ld-text);
	padding: 0.6rem 2rem 0.6rem 0.7rem;
	max-width: 100%;
}
.ld-check {
	display: inline-flex;
	align-items: center;
	gap: 0.5rem;
	min-height: 44px;
}
.ld-check input {
	width: 1rem;
	height: 1rem;
	accent-color: var(--color-primary-600);
}
.ld-toolbar > .ld-sub {
	flex-basis: 100%;
	max-width: 100ch;
	line-height: 1.6;
}
.ld-refresh-controls button {
	background: var(--ld-card);
	color: var(--ld-text);
	border: 1px solid var(--ld-line);
}
.ld button:disabled {
	opacity: 0.6;
	cursor: wait;
}
.ld[data-ld-stale] .ld-live {
	color: var(--ld-warn);
}
.ld-comparison {
	margin-top: 0.5rem;
	font-size: 0.75rem;
	color: var(--ld-muted);
	line-height: 1.5;
}
.ld-previous {
	display: block;
}
.ld-button,
.ld-periods a,
.ld-periods summary {
	min-height: 44px;
	display: inline-flex;
	align-items: center;
}
.ld-periods {
	border-radius: 8px;
	flex-wrap: wrap;
}
.ld-periods a,
.ld-periods summary {
	border-radius: 6px;
}
@media (max-width: 639px) {
	.ld-hero {
		padding: 1rem;
	}
	.ld-periods {
		justify-content: flex-start;
	}
	.ld-shortcuts {
		display: grid;
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}
	.ld-shortcuts a {
		padding: 0.6rem;
	}
	.ld-filters {
		align-items: stretch;
	}
	.ld-filters select {
		flex: 1;
		min-width: 0;
		font-size: 16px;
	}
	.ld-check {
		flex-basis: 100%;
	}
}
@media print {
	.ld-toolbar,
	.ld-shortcuts,
	.ld-periods {
		display: none;
	}
	.ld-more {
		display: block;
	}
}

.dark .ld-shortcuts .material-symbols-outlined {
	color: var(--color-primary-300);
}
