@use "../teydea-admin" as *;

/**
 * Drill-down settings sidebar
 */
.tsc-drill-down-sidebar {
	display: flex;
	flex-direction: column;
	min-width: 0;

	&__search {
		padding: $tsc-space-4 $tsc-space-6 $tsc-space-1;
	}

	&__before {
		padding: $tsc-space-3 $tsc-space-6 $tsc-space-1;
	}

	&__group {
		padding: $tsc-space-3 0 $tsc-space-1;
	}

	&__group-title {
		@include tsc-overline;
		margin: 0;
		padding: 0 $tsc-space-6 $tsc-space-1;
	}

	&__rows {
		list-style: none;
		margin: 0;
		padding: 0;
	}

	&__row-item {
		margin: 0;
	}

	&__row {
		align-items: center;
		background: transparent;
		border: 0;
		color: $tsc-ink;
		cursor: pointer;
		display: flex;
		font: inherit;
		gap: $tsc-space-3;
		min-height: $tsc-touch-target;
		padding: 6px $tsc-space-6;
		text-align: start;
		width: 100%;

		&:hover {
			background: $tsc-surface-hover;
		}

		&:focus-visible {
			box-shadow: inset 0 0 0 2px $tsc-accent;
			outline: 2px solid transparent;
		}
	}

	&__row-icon {
		fill: currentColor;
		flex: none;
	}

	&__row-text {
		display: flex;
		flex: 1;
		flex-direction: column;
		gap: 1px;
		min-width: 0;
	}

	&__row-title {
		align-items: center;
		display: flex;
		font-size: 13px;
		font-weight: 500;
		gap: 6px;
	}

	&__row-summary {
		color: $tsc-ink-muted;
		font-size: 12px;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	&__row-chevron {
		fill: $tsc-ink-muted;
		flex: none;
	}

	&__no-results {
		color: $tsc-ink-muted;
		margin: 0;
		padding: $tsc-space-2 $tsc-space-6;
	}

	// The way back and the panel's name stay in view while its settings scroll under them.
	&__panel-header {
		align-items: center;
		background: $tsc-surface;
		border-bottom: 1px solid $tsc-hairline;
		display: flex;
		gap: $tsc-space-2;
		padding: $tsc-space-3 $tsc-space-3 $tsc-space-3 $tsc-space-4;
		position: sticky;
		top: 0;
		z-index: 2;
	}

	&__panel-heading {
		flex: 1;
		min-width: 0;
	}

	&__breadcrumb {
		color: $tsc-ink-muted;
		font-size: 12px;
	}

	&__panel-title {
		align-items: center;
		display: flex;
		font-size: 15px;
		font-weight: 600;
		gap: 6px;
		line-height: 20px;
		margin: 0;

		// The title takes focus only so a screen reader starts reading the opened panel there; it cannot be operated, so it shows no focus ring.
		&:focus,
		&:focus-visible {
			box-shadow: none;
			outline: none;
		}
	}

	&__panel-body {
		display: flex;
		flex-direction: column;

		// Controls that raise themselves, such as a slider thumb or a toggle group's selected option, stay layered inside the body and so pass under the header that stays in view.
		isolation: isolate;

		// A field scrolled into view, by focus or by a search result, stops below the header that stays in view (65 px tall) rather than under it.
		* {
			scroll-margin-top: 72px;
		}
	}

	&__panel-footer {
		border-top: 1px solid $tsc-hairline;
		font-size: 12px;
		padding: 10px $tsc-space-6;
	}

	&__section {
		display: flex;
		flex-direction: column;
		gap: 14px;
		padding: $tsc-space-4 $tsc-space-6;

		& + & {
			border-top: 1px solid $tsc-hairline;
		}
	}

	&__section-title {
		@include tsc-overline;
		margin: 0;
	}

	&__section-fields {
		display: flex;
		flex-direction: column;
		gap: $tsc-space-4;
	}

	// A field a search result opened the panel at: an outline and a tint that fade, so the person sees which one matched.
	&__target--highlighted,
	&__section--highlighted {
		animation: tsc-drill-down-sidebar-highlight 2.4s ease-out forwards;
		outline: 2px solid $tsc-accent;

		// Drawn inside an element that runs to the sidebar's edges, and around a field, which has room in its section.
		outline-offset: -2px;

		@media (prefers-reduced-motion: reduce) {
			animation: none;
			background-color: $tsc-accent-subtle;
		}

		@media (forced-colors: active) {
			animation: none;
			outline-color: Highlight;
		}
	}

	&__section-fields &__target--highlighted {
		outline-offset: 2px;
	}
}

@keyframes tsc-drill-down-sidebar-highlight {
	0%,
	60% {
		background-color: $tsc-accent-subtle;
		outline-color: $tsc-accent;
	}

	100% {
		background-color: transparent;
		outline-color: transparent;
	}
}
