.panel {
	background-color: $panel-bg;
	border-color: $panel-border-color;
	border-style: $panel-border-style;
	border-width: $panel-border-width;

	@include border-radius($panel-border-radius);

	margin-bottom: $panel-margin-bottom;
	word-wrap: break-word;
}

.panel-header {
	border-bottom: $panel-header-border-bottom-width solid transparent;

	@if not ($panel-header-offset-border-radius == 0) {
		@include border-top-radius($panel-header-offset-border-radius);
	}

	display: block;
	font-size: $panel-header-font-size;
	line-height: $panel-header-line-height;
	padding: $panel-header-padding-y $panel-header-padding-x;
	position: relative;
	width: 100%;

	&.collapsed {
		@if not ($panel-header-offset-border-radius == 0) {
			@include border-bottom-radius($panel-header-offset-border-radius);
		}
	}

	&.collapse-icon {
		padding-left: $panel-header-collapse-icon-padding-left;
		padding-right: $panel-header-collapse-icon-padding-right;
	}

	.collapse-icon-closed,
	.collapse-icon-open {
		bottom: $panel-header-collapse-icon-bottom;
		font-size: $panel-header-collapse-icon-font-size;
		left: $panel-header-collapse-icon-left;
		right: $panel-header-collapse-icon-right;
		top: $panel-header-collapse-icon-top;
	}
}

.panel-header-link {
	@include clay-link($panel-header-link);

	&.panel-header.collapsed {
		@include clay-link($panel-header-collapsed-link);
	}

	.collapse-icon {
		padding-left: $collapse-icon-padding-left;
		padding-right: $collapse-icon-padding-right;
	}
}

.panel-body {
	padding: $panel-body-padding-y $panel-header-padding-x;
}

.panel-footer {
	@if not ($panel-footer-offset-border-radius == 0) {
		@include border-bottom-radius($panel-footer-offset-border-radius);
	}

	border-top: $panel-footer-border-top-width solid transparent;
	padding: $panel-footer-padding-y $panel-footer-padding-x;
}

.panel-title {
	font-size: $panel-title-font-size;
	font-weight: $panel-title-font-weight;
	text-transform: $panel-title-text-transform;

	small,
	.small {
		font-size: $panel-title-small-font-size;
		margin-left: $panel-title-small-margin-left;
	}
}

// Panel Group

.panel-group {
	@include border-radius($panel-border-radius);

	.panel {
		margin-bottom: $panel-group-panel-margin-bottom;

		&:first-child,
		&:first-child .panel-header {
			@include border-bottom-radius(0);
		}

		&:not(:first-child) {
			@include border-radius(0);

			@if ($panel-border-bottom-width > 0) {
				margin-top: -$panel-border-bottom-width;
			}

			.panel-header {
				@include border-radius(0);
			}
		}

		&:last-child {
			@include border-bottom-radius($panel-border-radius);

			.panel-header.collapsed {
				@if not ($panel-header-offset-border-radius == 0) {
					@include border-bottom-radius($panel-header-offset-border-radius);
				}
			}
		}
	}

	.panel-header {
		border-bottom-width: 0;

		+ .panel-collapse > .panel-body {
			border-top: $panel-header-border-bottom-width solid transparent;
		}
	}
}

// Panel Group Fluid

.panel-group-fluid,
.panel-group-flush {
	.panel {
		@if ($panel-border-left-width > 0) {
			border-left-width: 0;
		}

		@if ($panel-border-right-width > 0) {
			border-right-width: 0;
		}

		&:first-child,
		&:last-child {
			@if ($panel-border-radius > 0) {
				border-radius: 0;
			}

			.panel-header {
				&, &.collapsed {
					border-radius: 0;
				}
			}
		}
	}
}

.panel-group-fluid-first {
	.panel {
		@if ($panel-border-left-width > 0) {
			border-left-width: 0;
		}

		@if ($panel-border-right-width > 0) {
			border-right-width: 0;
		}

		&:first-child {
			@if ($panel-border-top-width > 0) {
				border-top-width: 0;
			}
		}

		&:last-child {
			@if ($panel-border-radius > 0) {
				border-bottom-left-radius: 0;
				border-bottom-right-radius: 0;
			}
		}
	}
}

.panel-group-fluid-last {
	.panel {
		@if ($panel-border-left-width > 0) {
			border-left-width: 0;
		}

		@if ($panel-border-right-width > 0) {
			border-right-width: 0;
		}

		&:first-child {
			@if ($panel-border-radius > 0) {
				border-top-left-radius: 0;
				border-top-right-radius: 0;
			}
		}

		&:last-child {
			@if ($panel-border-bottom-width > 0) {
				border-bottom-width: 0;
			}
		}
	}
}

.card-body {
	> .panel-group-fluid,
	> .panel-group-fluid-first,
	> .panel-group-fluid-last {
		margin-left: -$card-spacer-x;
		margin-right: -$card-spacer-x;
	}
}

.sheet {
	> .panel-group-fluid {
		margin-left: -$sheet-padding-left;
		margin-right: -$sheet-padding-right;
	}

	> .panel-group-fluid-first {
		margin-left: -$sheet-padding-left;
		margin-right: -$sheet-padding-right;
		margin-top: -$sheet-padding-top;
	}

	> .panel-group-fluid-last {
		margin-bottom: -$sheet-padding-bottom;
		margin-left: -$sheet-padding-left;
		margin-right: -$sheet-padding-right;
	}
}

// Panel Group Flush

.panel-group-flush {
	.panel-header,
	.panel-header-link {
		padding-left: 0;
		padding-right: 0;
	}

	.panel-body {
		margin-bottom: $panel-group-flush-body-margin-bottom;
		padding: $panel-group-flush-body-padding;
	}

	.collapse-icon {
		padding-left: $panel-group-flush-collapse-icon-padding-left;
		padding-right: $panel-group-flush-collapse-icon-padding-right;
	}

	.collapse-icon-closed,
	.collapse-icon-open {
		left: $panel-group-flush-collapse-icon-left;
		right: $panel-group-flush-collapse-icon-right;
	}
}

// Panel Group Sizes

.panel-group-sm {
	.panel {
		@include clay-panel-variant($panel-group-sm);
	}
}

// Panel Variants

.panel-secondary {
	@include clay-panel-variant($panel-secondary);
}

// Panel Unstyled

.panel-unstyled {
	@include clay-panel-variant($panel-unstyled);
}