/**
 * Media picker (inc/js/spaces-editor-media.js).
 *
 * Loaded on demand together with the editor. Colors go through the theme's --f-color-* roles so the
 * picker follows the light and dark theme; the fallbacks keep it readable if the roles are missing.
 */

.spaces-editor-media {
	position: fixed;
	inset: 0;
	z-index: 1005;
	display: flex;
	align-items: center;
	justify-content: center;
}

.spaces-editor-media[hidden] {
	display: none;
}

.spaces-editor-media__backdrop {
	position: absolute;
	inset: 0;
	background: rgba(0, 0, 0, 0.5);
}

.spaces-editor-media__dialog {
	position: relative;
	display: flex;
	flex-direction: column;
	width: min(56rem, 92vw);
	max-height: 80vh;
	border: 1px solid var(--f-color-border-1, #ccc);
	border-radius: var(--f-radius-medium, 4px);
	background: var(--f-color-bg-1, #fff);
	color: var(--f-color-text-0, #000);
	box-shadow: 0 0.5rem 2rem rgba(0, 0, 0, 0.3);
}

.spaces-editor-media__dialog.is-dropping {
	outline: 2px dashed var(--f-color-success, #3adb76);
	outline-offset: -0.5rem;
}

.spaces-editor-media__header {
	display: flex;
	gap: 0.5rem;
	align-items: center;
	padding: 0.75rem;
	border-bottom: 1px solid var(--f-color-border-1, #ccc);
}

.spaces-editor-media__search {
	flex: 1 1 auto;
	margin: 0;
}

.spaces-editor-media__upload {
	margin: 0;
	cursor: pointer;
}

.spaces-editor-media__library {
	flex: 0 0 auto;
	margin: 0;
	white-space: nowrap;
}

.spaces-editor-media__close {
	position: static;
	flex: 0 0 auto;
}

.spaces-editor-media__grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(8rem, 1fr));
	gap: 0.5rem;
	overflow-y: auto;
	padding: 0.75rem;
}

.spaces-editor-media__tile {
	position: relative;
}

.spaces-editor-media__item {
	width: 100%;
	display: flex;
	align-items: center;
	justify-content: center;
	aspect-ratio: 1;
	overflow: hidden;
	padding: 0;
	border: 1px solid var(--f-color-border-0, #e6e6e6);
	border-radius: var(--f-radius-small, 3px);
	background: var(--f-color-bg-2, #f4f4f4);
	cursor: pointer;
}

.spaces-editor-media__item:hover,
.spaces-editor-media__item:focus-visible {
	border-color: var(--f-color-success, #3adb76);
}

.spaces-editor-media__item img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.spaces-editor-media__delete {
	position: absolute;
	top: 0.25rem;
	right: 0.25rem;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 1.75rem;
	height: 1.75rem;
	padding: 0;
	border: 0;
	border-radius: var(--f-radius-small, 3px);
	background: rgba(0, 0, 0, 0.6);
	color: #fff;
	cursor: pointer;
	opacity: 0;
	transition: opacity 150ms;
}

.spaces-editor-media__delete svg {
	width: 1rem;
	height: 1rem;
	fill: currentColor;
}

.spaces-editor-media__delete:hover {
	background: var(--f-color-alert, #cc4b37);
}

/* Without hover there is nothing to reveal the button, so it stays visible on touch. */
@media (hover: none) {
	.spaces-editor-media__delete {
		opacity: 1;
	}
}

.spaces-editor-media__tile:hover .spaces-editor-media__delete,
.spaces-editor-media__delete:focus-visible {
	opacity: 1;
}

.spaces-editor-media__delete[disabled] {
	cursor: default;
	opacity: 0.5;
}

.spaces-editor-media__file {
	overflow: hidden;
	padding: 0.5rem;
	font-size: 0.75rem;
	text-align: center;
	overflow-wrap: anywhere;
}

.spaces-editor-media__status:empty {
	display: none;
}

.spaces-editor-media__status {
	margin: 0;
	padding: 0 0.75rem 0.75rem;
	color: var(--f-color-text-2, #767676);
}

.spaces-editor-media__status--error {
	color: var(--f-color-alert, #cc4b37);
	font-weight: bold;
}

body.spaces-editor-media-open {
	overflow: hidden;
}
