// Dashboard, widgets and iterators.
// To maintain code clarity:
//   - Do not mix rules for dashboard view mode and dashboard edit mode.
//   - Do not mix rules for widgets and iterators.

.header-kioskmode-controls {
	.dashboard-kioskmode-controls {
		li {
			margin-right: 6px;
		}
	}
}

.dashboard-toggle-slideshow,
.dashboard-kioskmode-toggle-slideshow {
	&.slideshow-state-started .slideshow-state-stopped,
	&.slideshow-state-stopped .slideshow-state-started {
		display: none;
	}
}

.dashboard-edit {
	display: inline-block;
	margin-right: 5px;
	position: relative;

	&::after {
		content: '';
		position: absolute;
		min-height: 24px;
		z-index: -1;
		top: -5px;
		right: -5px;
		bottom: -5px;
		left: -5px;
		border: 1px solid $ui-border-color;
	}

	ul {
		li {
			vertical-align: middle;

			&:first-child {
				padding: 0;
			}

			.btn-dashboard-conf {
				vertical-align: middle;
			}
		}
	}
}

.dashboard-navigation-tabs {
	// Compensate 2px padding of tabs.
	margin: -2px 10px -2px 0;
	overflow: hidden;

	.sortable {
		// Accommodate 2px shadow of focused tabs.
		padding: 2px 0;
		// Hide the invisible tab paddings.
		margin: 0 -1.5px;
	}

	.sortable-list {
		display: flex;
		padding: 0;
		margin: 0;
		align-items: center;

		& > .sortable-item:focus:not(:active) {
			// Increase padding to accommodate the focused div's shadow.
			padding: 0 3.5px 0 3.5px;

			& > div {
				padding: 0 8px;
				border: 1px solid transparent;
				box-shadow: 0 0 0 2px rgba($blue, .35);
			}
		}
	}

	.sortable-item {
		// This container should not be visually styled at this level.
		box-sizing: border-box;
		display: block;
		// Invisible padding for tab separation.
		padding: 0 1.5px 0 1.5px;
		margin: 0;
		list-style-type: none;
		outline: none;

		& > div {
			display: flex;
			align-items: center;

			min-height: 22px;
			line-height: 22px;
			padding: 0 10px;
			flex-shrink: 0;

			font-size: 12px;
			white-space: nowrap;

			cursor: pointer;
			user-select: none;

			background-color: $ui-bg-color;
			border: 1px solid $ui-border-color;
			border-radius: 2px;

			@if $ui-transitions {
				transition: background-color $ui-transition-duration, border-color $ui-transition-duration;
			}

			span {
				@extend %overflow-ellipsis;
				max-width: 300px;
				color: $font-color;
			}

			button {
				margin: 0 -9px 0 4px;
			}

			&:not(.selected-tab) {
				button {
					display: none;
				}
			}
		}
	}

	.sortable > .sortable-item > div,
	.sortable-list > .sortable-item > div:hover {
		background: $action-hover-color;
		border: 1px solid darken($action-hover-color, 20%);
	}

	.sortable > .sortable-item > div.selected-tab,
	.sortable-list > .sortable-item > div.selected-tab {
		background-color: $ui-bg-selected-color;
		border: 1px solid transparent;

		span {
			color: $font-selected-color;
		}
	}

	.sortable-dragging {
		.sortable-item {
			& > div {
				@extend %cursor-dragging;
			}
		}
	}
}

.dashboard-navigation-controls {
	display: flex;
	flex-shrink: 0;

	button {
		margin-left: 10px;

		&.dashboard-previous-page,
		&.dashboard-next-page {
			display: none;
			margin: 0;
		}
	}
}

.dashboard-navigation {
	display: flex;
	margin-top: 10px;
	padding-bottom: 2px;

	&.is-scrollable {
		.dashboard-navigation-controls {
			button {
				&.dashboard-previous-page,
				&.dashboard-next-page {
					display: inline-block;
				}
			}
		}
	}
}

.dashboard-grid {
	position: relative;
	margin: 0 -4px -4px -4px;

	// For widget sliding headers to appear over the breadcrumbs.
	z-index: 3;

	&.reserve-header-lines-1 {
		margin-top: 2rem;
	}

	&.reserve-header-lines-2 {
		margin-top: calc(4rem + 8px);
	}

	@if $ui-transitions {
		transition: margin-top .3s;
	}
}

.dashboard {
	&:not(.dashboard-is-multipage):not(.dashboard-is-edit-mode) {
		.dashboard-navigation {
			display: none;
		}
	}

	&.dashboard-is-edit-mode,
	&:not(.dashboard-is-multipage) {
		.dashboard-toggle-slideshow {
			display: none;
		}
	}
}

.dashboard-grid-widget-blocker {
	position: absolute;
	width: 100%;
	height: 100%;
	z-index: 998; // Below the new widget placeholder.
}

.dashboard-widget-placeholder {
	box-sizing: border-box;
	display: flex;
	height: 200px;
	padding: .25rem;
	width: calc(100% / 6 - .65rem);
	z-index: 999;
	color: $font-alt-color;
	cursor: pointer;
	user-select: none;

	.dashboard-widget-placeholder-box {
		background-color: rgba($ui-bg-color, .7);
		border: 1px dashed $form-border-color;
		box-shadow: 2px 2px 6px $action-shadow-color;
		flex: 1;
		position: relative;
		overflow: hidden;
	}

	.dashboard-widget-placeholder-label {
		$icon-height: 28px;

		position: absolute;
		left: 0;
		top: calc(50% - #{$icon-height / 2});
		right: 0;
		bottom: 0;
		padding: ($icon-height + 10px) 5px 5px;
		text-align: center;

		&::before {
			background: url($sprite-path) no-repeat -157px -888px;
			content: ' ';
			height: $icon-height;
			width: 36px;
			position: absolute;
			top: 0;
			left: 50%;
			transform: translateX(-50%);
		}

		span {
			&.hidden {
				display: none;
			}
		}
	}

	.dashboard-widget-placeholder-resizing {
		background: darken($body-bg-color, 6%);
		box-shadow: inset 2px 2px 6px $action-shadow-color;

		.dashboard-widget-placeholder-label {
			&::before {
				background: url($sprite-path) no-repeat -345px -888px;
			}
		}
	}

	&.disabled {
		opacity: 1;

		.dashboard-widget-placeholder-box {
			background-color: rgba($ui-bg-color, .7);

			.dashboard-widget-placeholder-label::before {
				background: url($sprite-path) no-repeat -122px -284px;
			}
		}
	}

	&.hidden {
		display: none;
	}
}

.dashboard-grid-widget-container {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	padding: .25rem;
	box-sizing: border-box;
	display: flex;
	flex-direction: column;
}

.dashboard-grid-widget-head {
	position: absolute;
	top: .25rem;
	left: .25rem;
	right: .25rem;
	height: 2rem;
	padding-left: 10px;
	display: flex;
	flex-wrap: nowrap;
	flex-direction: row;
	overflow: hidden;
	align-items: flex-start;
	border: 1px solid $ui-border-color;
	border-bottom: 0;
	background-color: $ui-bg-color;

	// For floating headers to appear over other widgets.
	// Cannot rely on DOM order here, since widgets of iterators can be shuffled on refresh.
	z-index: 3;

	h4 {
		flex-grow: 1;
		margin-top: .5rem;
		color: widget-head-font-color($font-color);
		font-weight: bold;
		@extend %overflow-ellipsis;
	}

	ul {
		flex-shrink: 0;

		li {
			float: left;
			padding: 0;

			select {
				margin: 4px 0;
			}
		}
	}
}

.dashboard-grid-widget-actions {
	opacity: 0;
	transition: opacity .2s ease-out;
}

.dashboard-grid-widget-content {
	flex-grow: 1;
	margin-top: 2rem;
	box-sizing: border-box;
	height: calc(100% - 2rem);
	padding-bottom: 8px;
	overflow: auto;
	border: 1px solid $ui-border-color;
	background-color: $ui-bg-color;

	@extend %webkit-scrollbar;

	.list-table {
		border: 0;

		th {
			@extend %dashboard-widget-td;
		}

		td {
			@extend %dashboard-widget-td;
		}

		tbody tr {
			&:last-child th,
			&:last-child td {
				border-bottom: 1px solid $table-border-color;

				&.list-table-footer {
					border-bottom: 0;
				}
			}
		}

		&.sticky-footer {
			margin-bottom: -8px;

			tfoot {
				bottom: -8px;
			}
		}
	}

	.debug-output {
		max-height: none;
		border-color: $table-border-color;
	}

	.msg-bad,
	.msg-good,
	.msg-warning {
		margin: 0 10px;
	}
}

.dashboard-grid-widget-mask {
	position: absolute;
	top: .25rem;
	left: .25rem;
	right: .25rem;
	bottom: .25rem;
	display: none;
}

.dashboard-grid-widget {
	position: absolute;

	&.dashboard-grid-widget-hidden-header {
		.dashboard-grid-widget-head {
			height: 0;
			transition: height .3s, margin-top .3s, box-shadow .3s;
		}

		.dashboard-grid-widget-content {
			margin-top: 0;
			height: 100%;
			padding-top: 8px;

			.list-table {
				&.sticky-footer {
					margin-bottom: 0;

					tfoot {
						bottom: 0;
					}
				}
			}
		}

		&.dashboard-grid-widget-focus {
			.dashboard-grid-widget-head {
				height: 2rem;
				margin-top: -2rem;
				box-shadow: 0 -6px 8px -2px rgba(128, 128, 128, .15);
				z-index: 5;
			}
		}
	}

	&.dashboard-grid-widget-focus {
		.dashboard-grid-widget-actions {
			opacity: 1;
		}
	}

	&.ui-resizable-resizing.resizing-top {
		.dashboard-grid-widget-container {
			top: auto;
			bottom: 0;
		}
	}

	&.ui-resizable-resizing.resizing-left {
		.dashboard-grid-widget-container {
			left: auto;
			right: 0;
		}
	}
}

.dashboard-grid-iterator-container {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
}

.dashboard-grid-iterator-head {
	position: absolute;
	top: .25rem;
	left: .25rem;
	right: .25rem;
	height: 0;
	display: flex;
	flex-wrap: nowrap;
	flex-direction: row;
	overflow: hidden;
	padding-left: 10px;
	box-sizing: border-box;
	border: 1px solid $ui-border-color;
	border-bottom: 0;
	background-color: $ui-bg-color;
	opacity: 0;

	// Transition for opacity is set for best border disappearance on different themes.
	transition: margin-top .3s ease-out, height .3s ease-out, opacity .15s .15s ease-out, box-shadow .3s ease-out;

	// Not to loose hovered header while widget underneath is updating.
	z-index: 3;

	h4 {
		flex-grow: 1;
		margin-top: .5rem;
		color: widget-head-font-color($font-color);
		font-weight: bold;
		@extend %overflow-ellipsis;
	}

	ul {
		flex-shrink: 0;

		li {
			float: left;
			padding: 0;
		}
	}

	.dashboard-grid-iterator-pager {
		margin: 0 10px;
		height: 2rem;
		display: none;
		flex-direction: row;
		flex-shrink: 0; // IE11 fix.
		align-items: center;

		.dashboard-grid-iterator-pager-info {
			margin: 2px .5em 0;
			white-space: nowrap;
			color: widget-head-font-color($font-color);
		}
	}

	&.pager-visible .dashboard-grid-iterator-pager {
		display: flex;
	}
}

.dashboard-grid-iterator-content {
	// To catch vertical resize events correctly.
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;

	// To allow overflowing of the floating headers of child widgets.
	overflow: visible;

	transition: margin-top .3s ease-out;
}

.dashboard-grid-iterator-placeholder {
	position: absolute;
	display: flex;

	> div {
		margin: .25rem;
		display: flex;
		flex-grow: 1;
		flex-direction: column;
		border: 1px solid $ui-border-color;
		background-color: rgba($ui-bg-color, .3);
	}
}

.dashboard-grid-iterator-too-small {
	position: absolute;
	top: .25rem;
	left: .25rem;
	right: .25rem;
	bottom: .25rem;
	overflow: hidden;
	display: none;
	align-items: center;
	justify-content: center;
	border: 1px solid $ui-border-color;
	background-color: $ui-bg-color;

	> div {
		padding: 0 10px;
		text-align: center;
		color: $font-alt-color;
	}
}

.dashboard-grid-iterator-mask {
	position: absolute;
	top: .25rem;
	left: .25rem;
	right: .25rem;
	bottom: .25rem;
	display: none;
}

.dashboard-grid-iterator {
	position: absolute;

	&.iterator-too-small {
		.dashboard-grid-iterator-too-small {
			display: flex;
		}

		.dashboard-grid-iterator-content {
			display: none;
		}
	}

	&.dashboard-grid-iterator-focus {
		z-index: 5;

		.dashboard-grid-iterator-head {
			margin-top: -2rem;
			height: 2rem;
			box-shadow: 0 -6px 8px -2px rgba(128, 128, 128, .15);
			opacity: 1;

			// Not inheriting opacity transition here.
			transition: margin-top .3s ease-out, height .3s ease-out, box-shadow .3s ease-out;
		}

		&.dashboard-grid-iterator-hidden-header.iterator-double-header {
			.dashboard-grid-iterator-head {
				margin-top: calc(-4rem - 8px);
				height: calc(4rem + 8px);
			}
		}
	}

	&.ui-resizable-resizing.resizing-top {
		.dashboard-grid-iterator-container {
			top: auto;
			bottom: 0;
		}
	}

	&.ui-resizable-resizing.resizing-left {
		.dashboard-grid-iterator-container {
			left: auto;
			right: 0;
		}
	}

	&.iterator-alt-content {
		.dashboard-grid-iterator-content {
			position: absolute;
			top: .25rem;
			left: .25rem;
			right: .25rem;
			bottom: .25rem;
			border: 1px solid $ui-border-color;
			background-color: $ui-bg-color;

			> div {
				padding-top: 8px;

				.list-table {
					border: 0;

					th {
						@extend %dashboard-widget-td;
					}

					td {
						@extend %dashboard-widget-td;
					}

					tbody tr {
						&:last-child th,
						&:last-child td {
							border-bottom: 1px solid $table-border-color;

							&.list-table-footer {
								border-bottom: 0;
							}
						}
					}
				}

				.msg-good,
				.msg-bad {
					margin: 0 10px;
				}
			}
		}
	}
}

.dashboard-grid-widget.ui-draggable,
.dashboard-grid-iterator.ui-draggable {
	.dashboard-grid-widget-head,
	.dashboard-grid-iterator-head {
		@extend %cursor-drag;
	}

	&.ui-draggable-dragging {
		.dashboard-grid-widget-head,
		.dashboard-grid-iterator-head {
			@extend %cursor-dragging;
		}
	}

	.dashboard-grid-widget .dashboard-grid-widget-head,
	.dashboard-grid-iterator .dashboard-grid-iterator-head {
		cursor: auto;
	}
}

.dashboard.dashboard-is-edit-mode {
	.dashboard-grid-widget-actions {
		opacity: 1;
	}

	&.dashboard-positioning {
		// No lazy transitions while dragging or resizing.

		.dashboard-grid-widget {
			&.dashboard-grid-widget-hidden-header {
				.dashboard-grid-widget-head {
					transition: none;
				}
			}
		}

		.dashboard-grid-iterator {
			&.dashboard-grid-widget-hidden-header {
				.dashboard-grid-widget-head {
					transition: none;
				}
			}
		}

		// No widget interactivity while dragging or resizing.

		.dashboard-grid-widget-mask {
			display: block;
		}

		.dashboard-grid-iterator-mask {
			display: block;
		}
	}

	.dashboard-grid-widget {
		.ui-resizable-handle {
			visibility: hidden;
		}

		&.dashboard-grid-widget-focus .ui-resizable-handle {
			visibility: visible;
		}

		&.ui-resizable-resizing {
			&.dashboard-grid-widget-hidden-header {
				.dashboard-grid-widget-head {
					margin-top: 0;
					height: 0;
					box-shadow: none;
				}
			}
		}

		&.ui-draggable-dragging {
			.ui-resizable-handle {
				visibility: hidden;
			}

			&.dashboard-grid-widget-hidden-header {
				.dashboard-grid-widget-head {
					margin-top: -2rem;
					height: 2rem;
					box-shadow: 0 -6px 8px -2px rgba(128, 128, 128, .15);
					opacity: .5;
				}
			}
		}

		&.ui-resizable-resizing,
		&.ui-draggable-dragging {
			z-index: 1000;

			&::before {
				content: '';
				display: block;
				position: absolute;
				top: .25rem;
				left: .25rem;
				right: .25rem;
				bottom: .25rem;
				background-color: rgba(darken($body-bg-color, 6%), .75);
				box-shadow: 0 4px 20px 2px rgba(0, 0, 0, .15);
			}

			.dashboard-grid-widget-head {
				border-color: darken($ui-border-color, 6%);
			}

			.dashboard-grid-widget-content {
				border-color: darken($ui-border-color, 6%);
			}
		}
	}

	.dashboard-grid-iterator {
		.ui-resizable-handle {
			visibility: hidden;
		}

		&.dashboard-grid-iterator-focus .ui-resizable-handle {
			visibility: visible;
		}

		&.ui-resizable-resizing {
			.dashboard-grid-iterator-head {
				margin-top: 0;
				height: 0;
				box-shadow: none;
				opacity: 0;
			}
		}

		&.ui-draggable-dragging {
			.ui-resizable-handle {
				visibility: hidden;
			}

			.dashboard-grid-iterator-head {
				margin-top: -2rem;
				height: 2rem;
				box-shadow: 0 -6px 8px -2px rgba(128, 128, 128, .15);
				opacity: .5;
			}

			&.dashboard-grid-iterator-hidden-header.iterator-double-header {
				.dashboard-grid-iterator-head {
					margin-top: calc(-4rem - 8px);
					height: calc(4rem + 8px);
				}
			}
		}

		&.ui-resizable-resizing,
		&.ui-draggable-dragging {
			z-index: 1000;

			&::before {
				content: '';
				display: block;
				position: absolute;
				top: .25rem;
				left: .25rem;
				right: .25rem;
				bottom: .25rem;
				background-color: rgba(darken($body-bg-color, 6%), .75);
				box-shadow: 0 4px 20px 2px rgba(0, 0, 0, .15);
			}

			.dashboard-grid-iterator-head {
				border-color: darken($ui-border-color, 6%);
			}

			.dashboard-grid-iterator-content {
				.dashboard-grid-widget {
					.dashboard-grid-widget-head {
						border-color: darken($ui-border-color, 6%);
					}

					.dashboard-grid-widget-content {
						border-color: darken($ui-border-color, 6%);
					}
				}

				.dashboard-grid-iterator-placeholder > div {
					border-color: darken($ui-border-color, 6%);
				}
			}

			.dashboard-grid-iterator-mask {
				border: 1px solid darken($ui-border-color, 8%);
				border-top: 0;
			}
		}
	}

	.dashboard-grid-widget-placeholder {
		position: absolute;
		z-index: 999;

		> div {
			position: absolute;
			top: .25rem;
			left: .25rem;
			right: .25rem;
			bottom: .25rem;
			background-color: darken($body-bg-color, 6%) !important;
		}
	}
}

@keyframes zoom-in-out {
	0% {
		transform: scale(1);
	}
	50% {
		transform: scale(1.05);
	}
	100% {
		transform: scale(1);
	}
}

.new-widget {
	animation: zoom-in-out .2s linear;
}

.dashboard-widget {
	min-width: 250px;
	margin: 0 10px 10px 0;
	background-color: $ui-bg-color;
	border: 1px solid $ui-border-color;

	.list-table {
		border: 0;

		th {
			@extend %dashboard-widget-td;
		}

		td {
			@extend %dashboard-widget-td;
		}

		tbody tr {
			&:last-child td {
				border-bottom: 1px solid $table-border-color;
			}
		}
	}

	.msg-bad,
	.msg-good,
	.msg-warning {
		margin: 0 10px;
	}

	&.dashboard-widget-fluid {
		margin-right: 0;
	}
}

%dashboard-widget-td {
	&:first-child {
		padding-left: 10px;
	}

	&:last-child {
		padding-right: 10px;
	}
}

.dashboard-widget-head {
	position: relative;
	padding: 8px 60px 8px 10px;

	h4 {
		color: widget-head-font-color($font-color);
		font-weight: bold;
	}

	ul {
		position: absolute;
		top: 0;
		right: 0;

		li {
			display: block;
			float: left;
			padding: 0;

			select {
				margin: 4px 0;
			}
		}
	}

	z-select {
		.list {
			li {
				float: none;
				line-height: normal;
				padding: 5px;
			}
		}
	}
}

.dashboard-widget-foot {
	text-align: right;
	color: $font-alt-color;
	margin: 0 10px;

	li {
		display: inline-block;
		padding: 8px 0 8px 13px;
	}
}

.dashboard-widget-graph-link {
	display: block;

	&:link {
		border: 0;
	}
}

.dashboard-grid-widget-content,
.dashboard-grid-iterator-content {
	&.is-loading::before {
		margin: calc(.25rem + 1px);
	}
}

// Dashboard list table.
.dashboard-list {
	.dashboard-list-item {
		display: flex;
		justify-content: space-between;
		height: 18px;

		.status-green {
			background-color: $dashboard-my-bg-color;
			border-color: $dashboard-my-bg-color;
		}

		.status-yellow {
			background-color: $dashboard-shared-bg-color;
			border-color: $dashboard-shared-bg-color;
		}
	}
}

.wrapper.layout-kioskmode {

	.dashboard-navigation {
		display: none;
	}
}
