@use "sass:color";

// Secondary Color
$color__secondary: #757575;
$color__secondary-variation: color.adjust($color__secondary, $lightness: -10%);

// System Font
$font__system: -apple-system, blinkmacsystemfont, "Segoe UI", roboto, oxygen, ubuntu, cantarell,
	"Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;

// Sizes
$overlay__gap: 16px;
$size__x-small: 380px;
$size__small: 544px;
$size__medium: 784px;
$size__large: 1264px;

// Widths
$width__mobile: 600px;
$width__tablet: 782px;

.newspack-lightbox {
	align-items: center;
	display: flex;
	inset: 0;
	justify-content: center;
	margin: 0 !important;
	max-width: 100% !important;
	opacity: 1;
	position: fixed;
	transition: opacity 0.5s ease-in-out;
	width: 100% !important;
	z-index: 99999;

	&.hidden {
		opacity: 0;
		z-index: -1;

		.newspack-popup-wrapper {
			transform: translateY(5rem);
		}
	}

	.admin-bar & {
		@media only screen and ( min-width: #{$width__mobile + 1} ) {
			padding-top: 46px !important;
		}

		@media only screen and ( min-width: #{$width__tablet + 1} ) {
			padding-top: 32px !important;
		}
	}

	.newspack-lightbox-overlay {
		background: black;
		border: 0;
		border-radius: 0;
		cursor: auto;
		height: 100%;
		left: 0;
		margin: 0;
		padding: 0;
		position: absolute;
		top: 0;
		user-select: none;
		width: 100%;
		z-index: 0;
	}

	.newspack-popup-wrapper {
		background: white;
		border: none;
		box-shadow: 0 0 1em 0.5em rgba(black, 0.1);
		overflow: hidden;
		position: relative;
		transform: none;
		transition: transform 0.2s ease-in-out;
		z-index: 1;
	}

	.newspack-popup {
		&__content-wrapper {
			background: transparent;
			margin: 0 auto;
			max-width: $size__medium;
			overflow: auto;
		}

		&__content {
			padding: $overlay__gap;
			@media only screen and ( min-width: $width__mobile ) {
				padding: #{2 * $overlay__gap};
			}
		}
		&__featured-image {
			display: none;
			max-height: #{13 * $overlay__gap};
			overflow: hidden;
			@media only screen and ( min-width: $width__tablet ) {
				align-items: center;
				display: flex;
				justify-content: center;
			}

			img {
				height: auto;
				width: 100%;
			}

			amp-img.amp-wp-enforced-sizes {
				object-fit: cover;
			}
		}

		&__content,
		.wp-block-column {
			> *:first-child {
				margin-top: 0;
			}

			> *:last-child {
				margin-bottom: 0;
			}
		}
	}

	// Small Padding overlay
	&.newspack-lightbox-no-border {
		.newspack-popup__content {
			padding: calc($overlay__gap / 2);
			@media only screen and ( min-width: $width__mobile ) {
				padding: $overlay__gap;
			}
		}
	}

	// Large Padding overlay
	&.newspack-lightbox-large-border {
		.newspack-popup {
			&__content {
				padding-top: #{3.5 * $overlay__gap};

				@media only screen and ( min-width: $width__mobile ) {
					padding-top: #{2 * $overlay__gap};
				}

				@media only screen and ( min-width: $width__tablet ) {
					padding: #{4 * $overlay__gap};
				}
			}
		}

		.newspack-lightbox__close {
			border-radius: 3px;
			height: #{2.5 * $overlay__gap};
			margin: #{0.5 * $overlay__gap};
			padding: 0;
			width: #{2.5 * $overlay__gap};

			@media only screen and ( min-width: $width__mobile ) {
				height: #{1.875 * $overlay__gap};
				margin: #{0.125 * $overlay__gap};
				width: #{1.875 * $overlay__gap};
			}

			@media only screen and ( min-width: $width__tablet ) {
				height: #{3 * $overlay__gap};
				margin: #{0.5 * $overlay__gap};
				width: #{3 * $overlay__gap};
			}

			&:active,
			&:focus,
			&:hover {
				background: #111;
				color: white;
				opacity: 1;
			}

			&:focus {
				outline: 1.5px solid #111;
				outline-offset: 2px;
			}
		}
	}

	// No Padding overlay
	&.newspack-lightbox-no-padding {
		.newspack-popup__content {
			padding: 0;
		}

		&.newspack-lightbox-size-full-width .newspack-popup__content-wrapper {
			max-width: 100%;
		}
	}

	// Close button
	.newspack-lightbox__close {
		align-items: center;
		background-color: transparent;
		border: none;
		border-radius: 0;
		box-shadow: none;
		color: inherit;
		cursor: pointer;
		display: flex;
		font-size: inherit;
		height: 36px;
		justify-content: center;
		margin: 0;
		padding: 6px;
		position: absolute;
		right: 0;
		top: 0;
		width: 36px;
		z-index: 10;

		svg {
			fill: currentcolor;
			flex: 0 0 24px;
		}

		&:active,
		&:hover {
			opacity: 0.6;
		}

		&:focus {
			outline: 1.5px solid;
			outline-offset: -1px;
		}
	}

	&-featured-image {
		@media only screen and ( min-width: $width__tablet ) {
			.newspack-lightbox__close {
				border-radius: 3px;
				height: 48px;
				margin: 8px;
				width: 48px;

				&:active,
				&:focus,
				&:hover {
					background-color: rgba(black, 0.95);
					opacity: 1;
				}

				&:focus {
					outline-offset: 2px;
				}
			}

			&:not(.newspack-lightbox-close-button-background) {
				.newspack-lightbox__close {
					background-color: rgba(black, 0.5);
					color: white !important;
				}
			}
		}
	}

	/* Placements */
	&.newspack-lightbox-placement-center,
	&.newspack-lightbox-placement-bottom_left,
	&.newspack-lightbox-placement-bottom_right,
	&.newspack-lightbox-placement-center_left,
	&.newspack-lightbox-placement-center_right,
	&.newspack-lightbox-placement-top_left,
	&.newspack-lightbox-placement-top_right {
		.newspack-popup-wrapper {
			max-height: calc(100% - #{$overlay__gap});
		}
	}

	&.newspack-lightbox-placement-bottom,
	&.newspack-lightbox-placement-top {
		.newspack-popup-wrapper {
			max-height: 100%;
		}
	}

	/* Sizing */
	&.newspack-lightbox-size-x-small,
	&.newspack-lightbox-size-small,
	&.newspack-lightbox-size-medium,
	&.newspack-lightbox-size-large,
	&.newspack-lightbox-size-full-width {
		.newspack-popup-wrapper {
			min-width: calc(100% - #{$overlay__gap});
			width: calc(100% - #{$overlay__gap});
		}

		.newspack-popup__content-wrapper {
			max-height: 80vh;
			max-width: 100%;

			@media only screen and ( min-width: $width__tablet ) {
				max-height: calc(100vh - #{2 * $overlay__gap});
			}
		}
	}

	&.newspack-lightbox-size-x-small {
		.newspack-popup-wrapper {
			@media only screen and ( min-width: #{$size__x-small + $overlay__gap} ) {
				min-width: $size__x-small;
				width: $size__x-small;
			}
		}
	}

	&.newspack-lightbox-size-small {
		.newspack-popup-wrapper {
			@media only screen and ( min-width: #{$size__small + $overlay__gap} ) {
				min-width: $size__small;
				width: $size__small;
			}
		}
	}

	&.newspack-lightbox-size-medium {
		.newspack-popup-wrapper {
			@media only screen and ( min-width: #{$size__medium + $overlay__gap} ) {
				min-width: $size__medium;
				width: $size__medium;
			}
		}
	}

	&.newspack-lightbox-size-large {
		.newspack-popup-wrapper {
			@media only screen and ( min-width: #{$size__large + $overlay__gap} ) {
				min-width: $size__large;
				width: $size__large;
			}
		}
	}

	&.newspack-lightbox-size-full-width {
		.newspack-popup-wrapper {
			min-width: 100%;
			width: 100%;
		}

		.newspack-popup__content-wrapper {
			max-width: $size__large;
		}
	}

	&.newspack-lightbox-placement-bottom {
		align-items: flex-end;
	}

	&.newspack-lightbox-placement-top {
		align-items: flex-start;
	}

	&.newspack-lightbox-placement-bottom_right {
		align-items: flex-end;
		justify-content: flex-end;
	}

	&.newspack-lightbox-placement-bottom_left {
		align-items: flex-end;
		justify-content: flex-start;
	}

	&.newspack-lightbox-placement-top_right {
		align-items: flex-start;
		justify-content: flex-end;
	}

	&.newspack-lightbox-placement-top_left {
		align-items: flex-start;
		justify-content: flex-start;
	}

	&.newspack-lightbox-placement-center_right {
		justify-content: flex-end;
	}

	&.newspack-lightbox-placement-center_left {
		justify-content: flex-start;
	}

	/* Background */
	&.newspack-lightbox-no-overlay {
		pointer-events: none;

		.newspack-popup-wrapper {
			pointer-events: all;
		}
	}
}

// Alignment
.entry-content {
	/* stylelint-disable-next-line no-duplicate-selectors */
	.newspack-lightbox {
		.newspack-popup__content-wrapper {
			.alignfull,
			.alignwide {
				margin-left: 0;
				margin-right: 0;
				max-width: 100%;
				padding-left: 0;
				padding-right: 0;

				@media only screen and ( min-width: $width__mobile ) {
					&.wp-block-columns {
						margin-left: -16px;
						margin-right: -16px;
						max-width: calc(100% + 32px);
						width: calc(100% + 32px);
					}
				}

				&.wp-block-columns,
				&.wp-block-columns .wp-block-column {
					padding-left: 0;
					padding-right: 0;
				}
			}

			@media only screen and ( min-width: $width__mobile ) {
				.alignfull.wp-block-columns {
					margin-left: -16px;
					margin-right: -16px;
					max-width: calc(100% + 32px);
					width: calc(100% + 32px);
				}
			}
		}
	}
}

.newspack-inline-popup {
	display: block;
	border: 1px solid rgba(black, 0.2);
	clear: both;
	padding: 0.75em;

	&.hidden {
		display: none;
	}

	&:focus {
		outline: none;
	}

	&.newspack-lightbox-no-border {
		border: none;
		padding: 0;
	}

	&.newspack-lightbox-large-border {
		@media only screen and ( min-width: $width__mobile ) {
			padding: 1.5em;
		}
	}
}

.newspack-inactive-popup-status {
	&::before {
		background: black;
		border-radius: 2px;
		color: white;
		content: attr(data-popup-status);
		font-family: $font__system;
		font-size: 12px;
		font-weight: 600;
		text-transform: uppercase;
		left: 4px;
		line-height: 2;
		padding: 0 0.5em;
		position: absolute;
		top: 4px;
		z-index: 10;
	}
}

.newspack-above-header-popup {
	display: block;
	clear: both;

	&:focus {
		outline: none;
	}

	&.hidden {
		display: none;
	}
}

// This is needed for the scroll-triggered popups to function properly.
// (#page-position-marker element is an absolutely-placed child of .entry-content)
/* stylelint-disable-next-line no-duplicate-selectors */
.entry-content {
	position: relative !important;
}

.hide {
	display: none;
}

.newspack-modal-checkout-open,
.newspack-signin {
	.newspack-lightbox {
		display: none !important;
	}
}
