@import 'variables-content.less';

/**
 * Block media items
 */

figure[ typeof~='mw:File' ],
figure[ typeof~='mw:File/Frameless' ] {
	margin: 0; // Maybe belongs in element.css for figure

	> a {
		// The addition of the class is needed for higher specificity
		// than Vector's print styles
		.mw-body-content & {
			border: 0;
		}
	}

	&.mw-halign-right {
		/* @noflip */
		margin: @margin-floatright;
		/* @noflip */
		clear: right;
		/* @noflip */
		float: right;
	}

	&.mw-halign-left {
		/* @noflip */
		margin: @margin-floatleft;
		/* @noflip */
		clear: left;
		/* @noflip */
		float: left;
	}

	&.mw-halign-none {
		clear: none;
		float: none;
	}

	&.mw-halign-center {
		/* Matches *.center * in element.css */
		margin: 0 auto;
		display: table;
		border-collapse: collapse;
		clear: none;
		float: none;
	}

	/* Hide the caption for frameless and plain floated images */
	> figcaption {
		display: none;
	}
}

figure[ typeof~='mw:File/Thumb' ],
figure[ typeof~='mw:File/Frame' ] {
	display: table;
	text-align: center;
	border-collapse: collapse;
	line-height: 0;

	> a {
		// The addition of the class is needed for higher specificity
		// than Vector's print styles
		.mw-body-content & {
			border: 0;
		}
	}

	// Default where page content language is not set
	// Allow to flip
	margin: @margin-tright;
	clear: right;
	float: right;

	// Defaults for page content language

	.mw-content-ltr & {
		/* @noflip */
		margin: @margin-tright;
		/* @noflip */
		clear: right;
		/* @noflip */
		float: right;
	}

	.mw-content-rtl & {
		/* @noflip */
		margin: @margin-tleft;
		/* @noflip */
		clear: left;
		/* @noflip */
		float: left;
	}

	// Override defaults when explicitly set
	// Order of application is important, so don't combine with the defaults

	&.mw-halign-right {
		/* @noflip */
		margin: @margin-tright;
		/* @noflip */
		clear: right;
		/* @noflip */
		float: right;
	}

	&.mw-halign-left {
		/* @noflip */
		margin: @margin-tleft;
		/* @noflip */
		clear: left;
		/* @noflip */
		float: left;
	}

	&.mw-halign-none {
		/* Override the default margin from mw-content-xxx above */
		margin: 0;
		margin-bottom: @margin-bottom-thumb;
		clear: none;
		float: none;
	}

	&.mw-halign-center {
		/* Override the default margin from mw-content-xxx above
		 * And, matches *.center * in element.css
		 */
		margin: 0 auto @margin-bottom-thumb auto;
		clear: none;
		float: none;
	}

	> :not( figcaption ) {
		.mw-file-element {
			margin: 0.75em;
			margin-bottom: 0.5em;
		}

		/**
		 * Broken media get a span instead.
		 */
		.mw-broken-media {
			display: inline-block;
			line-height: 1.5;
			word-break: break-word; // Same as in the figcaption
			/* This is hardcoded in Linker::makeThumbLink2 for broken media */
			width: 180px;
		}
	}

	> figcaption {
		display: table-caption;
		caption-side: bottom;
		line-height: @line-height-thumbcaption;
		min-height: 1em;

		/**
		 * The "break-word" value is deprecated, however, it's well supported
		 * at 94.73%
		 * https://caniuse.com/mdn-css_properties_word-break_break-word
		 *
		 * The spec suggests it has the same effect as,
		 *
		 *   word-break: normal;
		 *   overflow-wrap: anywhere;
		 *
		 * https://drafts.csswg.org/css-text-3/#word-break-property
		 *
		 * So, we should use that. However, support for "anywhere" is lagging
		 * at just 72.39%, with Safari being a notable miss.
		 * https://caniuse.com/mdn-css_properties_overflow-wrap_anywhere
		 *
		 * "Soft wrap opportunities introduced by the word break are considered
		 * when calculating min-content intrinsic sizes."
		 * From https://developer.mozilla.org/en-US/docs/Web/CSS/overflow-wrap
		 */
		word-break: break-word;

		// Default where page content language is not set
		// Allow to flip
		text-align: left;

		// Defaults for page content language

		.mw-content-ltr & {
			/* @noflip */
			text-align: left;
		}

		.mw-content-rtl & {
			/* @noflip */
			text-align: right;
		}

		/* taken from .thumbcaption, plus .thumbinner */
		padding: 0 0.75em 0.75em 0.75em;
	}
}

// Remove bogus padding from framed images without captions
// However, it's still necessary for thumbs because the magnifying icon is present
figure[ typeof~='mw:File/Frame' ] > figcaption:empty {
	padding-bottom: 0.25em; // Accounts for the difference in margin-bottom above
	min-height: 0;
}

/**
 * Inline media items
 */
.mw-valign-middle .mw-file-element {
	vertical-align: middle;
}

.mw-valign-baseline .mw-file-element {
	vertical-align: baseline;
}

.mw-valign-sub .mw-file-element {
	vertical-align: sub;
}

.mw-valign-super .mw-file-element {
	vertical-align: super;
}

.mw-valign-top .mw-file-element {
	vertical-align: top;
}

.mw-valign-text-top .mw-file-element {
	vertical-align: text-top;
}

.mw-valign-bottom .mw-file-element {
	vertical-align: bottom;
}

.mw-valign-text-bottom .mw-file-element {
	vertical-align: text-bottom;
}
