/**
 * "Photo Directory" tab inside the wp.media modal.
 *
 * Metrics follow core's media-views.css so the tab reads as part of the
 * frame: same 1px #dcdcde rules, same #f6f7f7 sidebar, same 32px controls.
 */

/* Core's toolbar acts on attachments. Until an import has run there are
   none, so the tab carries its own footer instead. */
.photofetch-tab-active .media-frame-toolbar {
	display: none;
}

.photofetch-tab-active .media-frame-content {
	bottom: 0;
}

.photofetch-tab {
	position: absolute;
	top: 0;
	right: 0;
	bottom: 0;
	left: 0;
	display: flex;
	flex-direction: column;
	background: #fff;
}

.photofetch-tab__main {
	display: flex;
	flex: 1;
	min-height: 0;
}

/* ------------------------------------------------------------- browse pane */

.photofetch-tab__browse {
	display: flex;
	flex: 1;
	min-width: 0;
	flex-direction: column;
	gap: 12px;
	padding: 14px 16px;
}

.photofetch-tab__controls {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	align-items: center;
}

.photofetch-tab__searchwrap {
	position: relative;
	flex: 1;
	min-width: 180px;
}

.photofetch-tab__searchicon {
	position: absolute;
	top: 50%;
	left: 8px;
	color: #646970;
	font-size: 18px;
	line-height: 1;
	transform: translateY( -50% );
	pointer-events: none;
}

/* Deliberately over-qualified: core's `.media-frame input[type="search"]`
   and friends outrank a single class, so the form controls in this tab need
   three classes to keep their own metrics. */
.photofetch-tab .photofetch-tab__controls .photofetch-tab__search {
	width: 100%;
	margin: 0;
	height: 32px;
	padding: 0 8px 0 30px;
	border: 1px solid #8c8f94;
	border-radius: 3px;
	font-size: 13px;
	line-height: 1;
	color: #2c3338;
	background: #fff;
}

.photofetch-tab__search::-webkit-search-cancel-button {
	cursor: pointer;
}

.photofetch-tab .photofetch-tab__main .photofetch-tab__select {
	height: 32px;
	max-width: 190px;
	padding: 0 24px 0 8px;
	border: 1px solid #8c8f94;
	border-radius: 3px;
	font-size: 13px;
	line-height: 1;
	color: #2c3338;
	background-color: #fff;
}

.photofetch-tab__scroll {
	flex: 1;
	min-height: 0;
	overflow-y: auto;
}

.photofetch-tab__status {
	padding: 12px 0;
	font-size: 13px;
	color: #646970;
}

.photofetch-tab__grid {
	display: grid;
	grid-template-columns: repeat( 5, 1fr );
	gap: 10px;
}

.photofetch-tab__more {
	display: flex;
	justify-content: center;
	padding: 16px 0 4px;
}

.photofetch-tab__more:empty {
	display: none;
}

/* -------------------------------------------------------------------- tile */

.photofetch-tile {
	position: relative;
	padding-bottom: 100%;
	border: 1px solid #dcdcde;
	background: #f0f0f1;
	cursor: pointer;
}

.photofetch-tile__img {
	position: absolute;
	top: 0;
	right: 0;
	bottom: 0;
	left: 0;
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

.photofetch-tile:focus {
	outline: 2px solid #2271b1;
	outline-offset: -2px;
}

.photofetch-tile.is-selected {
	border-color: #2271b1;
	box-shadow: 0 0 0 2px #2271b1;
}

.photofetch-tile__chip {
	position: absolute;
	top: 4px;
	right: 4px;
	display: none;
	width: 20px;
	height: 20px;
	border-radius: 50%;
	background: #2271b1;
	color: #fff;
	font-size: 14px;
	line-height: 20px;
	text-align: center;
}

.photofetch-tile.is-selected .photofetch-tile__chip {
	display: block;
}

.photofetch-tile__badge {
	position: absolute;
	bottom: 4px;
	left: 4px;
	padding: 2px 6px;
	border-radius: 2px;
	background: rgba( 0, 0, 0, 0.7 );
	color: #fff;
	font-size: 11px;
	line-height: 1.5;
}

/* ----------------------------------------------------------------- sidebar */

.photofetch-tab__sidebar {
	display: flex;
	flex-direction: column;
	gap: 12px;
	width: 300px;
	flex: none;
	padding: 14px;
	border-left: 1px solid #dcdcde;
	background: #f6f7f7;
	overflow-y: auto;
}

.photofetch-tab__sidebarlabel {
	font-size: 12px;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.03em;
	color: #646970;
}

.photofetch-tab__sidebarempty {
	margin: 0;
	font-size: 13px;
	color: #646970;
}

.photofetch-tab__preview {
	display: block;
	width: 100%;
	height: 150px;
	object-fit: cover;
	border: 1px solid #dcdcde;
	background: #f0f0f1;
}

.photofetch-tab__meta {
	font-size: 12px;
	line-height: 1.6;
	color: #646970;
}

.photofetch-tab__divider {
	height: 0;
	margin: 0;
	border: 0;
	border-top: 1px solid #dcdcde;
}

.photofetch-tab__field {
	display: flex;
	flex-direction: column;
	gap: 4px;
}

.photofetch-tab__fieldlabel {
	font-size: 12px;
	color: #646970;
}

.photofetch-tab .photofetch-tab__sidebar .photofetch-tab__input {
	width: 100%;
	height: 30px;
	padding: 0 8px;
	border: 1px solid #8c8f94;
	border-radius: 3px;
	font-size: 13px;
	color: #2c3338;
}

.photofetch-tab .photofetch-tab__sidebar .photofetch-tab__textarea {
	width: 100%;
	padding: 6px 8px;
	border: 1px solid #8c8f94;
	border-radius: 3px;
	font-size: 13px;
	line-height: 1.5;
	color: #2c3338;
	resize: vertical;
}

.photofetch-tab .photofetch-tab__sidebar .photofetch-tab__textarea--caption {
	color: #646970;
}

.photofetch-tab .photofetch-tab__sidebar .photofetch-tab__select {
	max-width: none;
	width: 100%;
}

/* ------------------------------------------------------------------ footer */

.photofetch-tab__footer {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	flex: none;
	padding: 12px 16px;
	border-top: 1px solid #dcdcde;
	background: #fff;
}

.photofetch-tab__count {
	font-size: 13px;
	color: #646970;
}

.photofetch-tab__actions {
	display: flex;
	gap: 8px;
}

.photofetch-tab__action.button {
	height: 32px;
	line-height: 30px;
	padding: 0 12px;
}

/* -------------------------------------------------------------- lightbox */

/*
 * Appended to document.body (see media-modal.js), not nested inside the
 * tab's own markup, so it only has to clear wp.media's own modal chrome
 * once rather than also fight any stacking context introduced by this
 * view's ancestors. wp.media's modal backdrop sits around z-index: 160000,
 * so this needs to clear that with room to spare.
 */
.photofetch-tab-lightbox {
	position: fixed;
	inset: 0;
	z-index: 999999;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 60px 40px 40px;
	box-sizing: border-box;
	background: rgba( 0, 0, 0, 0.85 );
}

.photofetch-tab-lightbox__frame {
	position: relative;
	max-width: 100%;
	max-height: 100%;
}

.photofetch-tab-lightbox__image {
	display: block;
	max-width: 100%;
	max-height: calc( 100vh - 100px );
	border-radius: 3px;
	box-shadow: 0 8px 32px rgba( 0, 0, 0, 0.4 );
}

.photofetch-tab-lightbox__close {
	position: absolute;
	top: -40px;
	right: 0;
	padding: 4px 8px;
	font-size: 32px;
	line-height: 1;
	color: #fff;
	cursor: pointer;
	background: none;
	border: 0;
}

.photofetch-tab-lightbox__close:hover {
	opacity: 0.8;
}

/* -------------------------------------------------------------- responsive */

@media screen and ( max-width: 1200px ) {
	.photofetch-tab__grid {
		grid-template-columns: repeat( 4, 1fr );
	}
}

@media screen and ( max-width: 960px ) {
	.photofetch-tab__grid {
		grid-template-columns: repeat( 3, 1fr );
	}
}

/* Below 782px core stacks the modal sidebar under the grid. */
@media screen and ( max-width: 782px ) {
	.photofetch-tab__main {
		flex-direction: column;
		overflow-y: auto;
	}

	.photofetch-tab__browse {
		flex: none;
	}

	.photofetch-tab__scroll {
		overflow: visible;
	}

	.photofetch-tab__sidebar {
		width: auto;
		border-left: 0;
		border-top: 1px solid #dcdcde;
		overflow: visible;
	}

	.photofetch-tab__grid {
		grid-template-columns: repeat( 2, 1fr );
	}

	.photofetch-tab__footer {
		flex-wrap: wrap;
	}
}
