/**
 * Modal Gallery برای کاربران
 * طراحی شبیه wp.media اما حرفه‌ای‌تر و مدرن‌تر
 */

/* قفل اسکرول body */
body.mlm-modal-open {
	overflow: hidden !important;
}

/* جلوگیری از drag برای تمام element های modal */
.mlm-media-modal * {
	-webkit-user-drag: none;
	-khtml-user-drag: none;
	-moz-user-drag: none;
	-o-user-drag: none;
	user-drag: none;
}

.mlm-media-modal img {
	pointer-events: auto;
	-webkit-user-drag: none;
	-khtml-user-drag: none;
	-moz-user-drag: none;
	-o-user-drag: none;
	user-drag: none;
}

.mlm-media-item {
	-webkit-user-select: none;
	-moz-user-select: none;
	-ms-user-select: none;
	user-select: none;
}

/* مخفی کردن تمام dropdown ها وقتی modal بسته است */
body:not(.mlm-modal-open) .mlm-media-filter-dropdown,
body:not(.mlm-modal-open) .mlm-media-dropdown,
body:not(.mlm-modal-open) .mlm-dropdown-menu {
	display: none !important;
	opacity: 0 !important;
	visibility: hidden !important;
	pointer-events: none !important;
}

/* مخفی کردن کامل تمام element های modal وقتی بسته است */
body:not(.mlm-modal-open) #mlm-media-modal,
body:not(.mlm-modal-open) #mlm-media-modal-backdrop {
	display: none !important;
	opacity: 0 !important;
	visibility: hidden !important;
	pointer-events: none !important;
	z-index: -9999 !important;
}

/* اطمینان از اینکه هیچ element modal در پس‌زمینه فعال نباشد */
#mlm-media-modal:not(.active),
#mlm-media-modal-backdrop:not(.active) {
	display: none !important;
	pointer-events: none !important;
}

/* Overlay */
.mlm-media-modal-backdrop {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: rgba(0, 0, 0, 0.7);
	z-index: 999998;
	opacity: 0;
	transition: opacity 0.2s ease;
}

.mlm-media-modal-backdrop.active {
	opacity: 1;
}

/* Modal Container */
.mlm-media-modal {
	position: fixed;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%) scale(0.9);
	width: 90%;
	max-width: 1200px;
	height: 85vh;
	max-height: 800px;
	background: #fff;
	border-radius: 12px;
	box-shadow: 0 10px 50px rgba(0, 0, 0, 0.3);
	z-index: 999999;
	display: flex;
	flex-direction: column;
	opacity: 0;
	transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
	overflow: hidden;
}

.mlm-media-modal.active {
	opacity: 1;
	transform: translate(-50%, -50%) scale(1);
}

/* Header */
.mlm-media-modal-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 20px 30px;
	border-bottom: 2px solid #e0e0e0;
	background: #fff;
	color: #333;
}

.mlm-media-modal-title {
	font-size: 20px;
	font-weight: 700;
	margin: 0;
	display: flex;
	align-items: center;
	gap: 10px;
}

.mlm-media-modal-title i {
	font-size: 24px;
}

.mlm-media-modal-close {
	background: #f5f5f5;
	border: none;
	color: #666;
	width: 40px;
	height: 40px;
	border-radius: 50%;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: all 0.2s;
	font-size: 20px;
}

.mlm-media-modal-close:hover {
	background: #e74c3c;
	color: #fff;
	transform: rotate(90deg);
}

/* Body */
.mlm-media-modal-body {
	display: flex;
	flex: 1;
	overflow: hidden;
	position: relative;
}

/* Sidebar */
.mlm-media-modal-sidebar {
	width: 220px;
	background: #f8f9fa;
	border-left: 1px solid #e0e0e0;
	padding: 20px;
	overflow-y: auto;
}

.mlm-media-modal-tabs {
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.mlm-media-modal-tab {
	padding: 12px 16px;
	background: white;
	border: 1px solid #e0e0e0;
	border-radius: 8px;
	cursor: pointer;
	transition: all 0.2s;
	display: flex;
	align-items: center;
	gap: 10px;
	font-weight: 500;
	color: #555;
}

.mlm-media-modal-tab i {
	font-size: 18px;
	width: 24px;
	text-align: center;
}

.mlm-media-modal-tab:hover {
	background: #3498db;
	color: white;
	border-color: #3498db;
}

.mlm-media-modal-tab.active {
	background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
	color: white;
	border-color: transparent;
	box-shadow: 0 4px 10px rgba(52, 152, 219, 0.3);
}

/* Content */
.mlm-media-modal-content {
	flex: 1;
	display: flex;
	flex-direction: column;
	overflow-y: auto;
	overflow-x: hidden;
}

/* Custom Scrollbar */
.mlm-media-modal-content::-webkit-scrollbar {
	width: 8px;
}

.mlm-media-modal-content::-webkit-scrollbar-track {
	background: #f1f1f1;
	border-radius: 10px;
}

.mlm-media-modal-content::-webkit-scrollbar-thumb {
	background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
	border-radius: 10px;
}

.mlm-media-modal-content::-webkit-scrollbar-thumb:hover {
	background: linear-gradient(135deg, #2980b9 0%, #3498db 100%);
}

/* Toolbar */
.mlm-media-modal-toolbar {
	padding: 15px 20px;
	border-bottom: 1px solid #e0e0e0;
	display: flex;
	align-items: center;
	gap: 15px;
	background: white;
}

.mlm-media-modal-search {
	flex: 1;
	position: relative;
}

.mlm-media-modal-search input {
	width: 100%;
	padding: 10px 15px 10px 40px;
	border: 1px solid #ddd;
	border-radius: 8px;
	font-size: 14px;
	transition: all 0.2s;
}

.mlm-media-modal-search input:focus {
	outline: none;
	border-color: #3498db;
	box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.mlm-media-modal-search i {
	position: absolute;
	right: 15px;
	top: 50%;
	transform: translateY(-50%);
	color: #999;
}

.mlm-media-modal-filter {
	display: flex;
	gap: 10px;
}

.mlm-media-modal-filter select {
	padding: 10px 15px;
	border: 1px solid #ddd;
	border-radius: 8px;
	font-size: 14px;
	background: white;
	cursor: pointer;
	transition: all 0.2s;
}

.mlm-media-modal-filter select:focus {
	outline: none;
	border-color: #3498db;
	box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

/* Grid/List View */
.mlm-media-modal-view-toggle {
	display: flex;
	gap: 5px;
	background: #f0f0f0;
	padding: 4px;
	border-radius: 8px;
}

.mlm-media-modal-view-btn {
	padding: 8px 12px;
	background: transparent;
	border: none;
	border-radius: 6px;
	cursor: pointer;
	transition: all 0.2s;
	color: #666;
}

.mlm-media-modal-view-btn:hover {
	background: rgba(52, 152, 219, 0.1);
	color: #3498db;
}

.mlm-media-modal-view-btn.active {
	background: white;
	color: #3498db;
	box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

/* Gallery Grid */
.mlm-media-modal-gallery {
	flex: 1;
	overflow-y: auto;
	padding: 20px;
	background: #fafafa;
}

.mlm-media-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
	gap: 15px;
}

.mlm-media-grid.list-view {
	grid-template-columns: repeat(2, 1fr);
	gap: 15px;
}

.mlm-media-item.list-item {
	aspect-ratio: auto;
	min-height: 80px;
	display: flex;
	flex-direction: row;
}

.mlm-media-item.list-item .mlm-media-item-inner {
	width: 80px;
	min-width: 80px;
	height: 80px;
}

.mlm-media-item.list-item .mlm-media-item-info {
	position: static;
	opacity: 1;
	background: transparent;
	color: #333;
	padding: 12px;
	flex: 1;
	display: flex;
	flex-direction: column;
	justify-content: center;
	gap: 4px;
}

.mlm-media-item.list-item .mlm-media-item-info .mlm-media-item-date {
	font-size: 11px;
	color: #666;
}

/* Media Item */
.mlm-media-item {
	position: relative;
	aspect-ratio: 1;
	background: white;
	border: 2px solid #e0e0e0;
	border-radius: 10px;
	cursor: pointer;
	overflow: hidden;
	transition: all 0.2s;
	display: flex;
	align-items: center;
	justify-content: center;
}

.mlm-media-item:hover {
	border-color: #3498db;
	transform: translateY(-2px);
	box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.mlm-media-item.selected {
	border-color: #3498db;
	box-shadow: 0 0 0 4px rgba(52, 152, 219, 0.2);
}

.mlm-media-item-inner {
	width: 100%;
	height: 100%;
	display: flex;
	align-items: center;
	justify-content: center;
	position: relative;
}

.mlm-media-item img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.mlm-media-item-icon {
	font-size: 48px;
	color: #3498db;
}

.mlm-media-item-info {
	position: absolute;
	bottom: 0;
	left: 0;
	right: 0;
	background: linear-gradient(to top, rgba(0, 0, 0, 0.9), rgba(0, 0, 0, 0.7));
	color: white;
	padding: 10px 8px;
	font-size: 12px;
	opacity: 0;
	transition: opacity 0.2s;
}

.mlm-media-item:hover .mlm-media-item-info {
	opacity: 1;
}

/* استایل‌های مجزا برای هر بخش */
.mlm-media-item-info .mlm-media-item-name,
.mlm-media-item-info .mlm-media-item-size,
.mlm-media-item-info .mlm-media-item-format,
.mlm-media-item-info .mlm-media-item-date {
	color: white !important;
}

.mlm-media-item-info .mlm-media-item-name {
	font-weight: 600;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.mlm-media-item-info .mlm-media-item-size {
	opacity: 0.9;
}

.mlm-media-item-info .mlm-media-item-format {
	opacity: 0.8;
	font-family: monospace;
	font-size: 11px;
}

.mlm-media-item-info .mlm-media-item-date {
	opacity: 0.7;
}

.mlm-media-item-size {
	font-size: 10px;
	opacity: 0.8;
	margin-top: 2px;
}

.mlm-media-item-date {
	font-size: 10px;
	opacity: 0.6;
	margin-top: 2px;
}

.mlm-media-item-format {
	font-size: 10px;
	opacity: 0.7;
	margin-top: 2px;
}

.mlm-media-item-checkbox {
	position: absolute;
	top: 8px;
	right: 8px;
	width: 24px;
	height: 24px;
	background: rgba(255, 255, 255, 0.9);
	border: 2px solid #ddd;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	opacity: 0;
	transition: all 0.2s;
	z-index: 10;
}

.mlm-media-item:hover .mlm-media-item-checkbox,
.mlm-media-item.selected .mlm-media-item-checkbox {
	opacity: 1;
}

.mlm-media-item.selected .mlm-media-item-checkbox {
	background: #3498db;
	border-color: #3498db;
	color: white;
}

/* Upload Area */
.mlm-media-upload-area {
	padding: 40px;
	text-align: center;
	background: white;
	border: 3px dashed #ddd;
	border-radius: 12px;
	margin: 20px;
	cursor: pointer;
	transition: all 0.3s;
}

.mlm-media-upload-area:hover {
	border-color: #3498db;
	background: #e8f4f8;
}

.mlm-media-upload-area.dragover {
	border-color: #3498db;
	background: #d6eaf8;
	transform: scale(1.02);
}

.mlm-media-upload-icon {
	font-size: 64px;
	color: #3498db;
	margin-bottom: 15px;
}

.mlm-media-upload-text {
	font-size: 18px;
	color: #333;
	margin-bottom: 8px;
	font-weight: 600;
}

.mlm-media-upload-hint {
	font-size: 14px;
	color: #999;
}

/* Footer */
.mlm-media-modal-footer {
	padding: 15px 30px;
	border-top: 1px solid #e0e0e0;
	display: flex;
	align-items: center;
	justify-content: space-between;
	background: #fafafa;
}

.mlm-media-modal-info {
	color: #666;
	font-size: 14px;
}

.mlm-media-modal-actions {
	display: flex;
	gap: 10px;
}

.mlm-media-modal-btn {
	padding: 12px 24px;
	border: none;
	border-radius: 8px;
	font-size: 14px;
	font-weight: 600;
	cursor: pointer;
	transition: all 0.2s;
	display: flex;
	align-items: center;
	gap: 8px;
}

.mlm-media-modal-btn-secondary {
	background: #e0e0e0;
	color: #666;
}

.mlm-media-modal-btn-secondary:hover {
	background: #d0d0d0;
}

.mlm-media-modal-btn-primary {
	background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
	color: white;
	box-shadow: 0 4px 15px rgba(52, 152, 219, 0.3);
}

.mlm-media-modal-btn-primary:hover {
	transform: translateY(-2px);
	box-shadow: 0 6px 20px rgba(52, 152, 219, 0.4);
}

.mlm-media-modal-btn:disabled {
	opacity: 0.5;
	cursor: not-allowed;
	transform: none !important;
}

/* Loading */
.mlm-media-modal-loading {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 60px;
	color: #999;
}

.mlm-media-modal-loading i {
	font-size: 48px;
	margin-bottom: 15px;
	animation: spin 1s linear infinite;
}

@keyframes spin {
	from { transform: rotate(0deg); }
	to { transform: rotate(360deg); }
}

/* Empty State */
.mlm-media-modal-empty {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 60px;
	color: #999;
}

.mlm-media-modal-empty i {
	font-size: 64px;
	margin-bottom: 15px;
	opacity: 0.5;
}

.mlm-media-modal-empty-text {
	font-size: 18px;
	margin-bottom: 8px;
	color: #666;
}

.mlm-media-modal-empty-hint {
	font-size: 14px;
	color: #999;
}

/* Responsive */
@media (max-width: 768px) {
	.mlm-media-modal {
		width: 95%;
		height: 90vh;
	}
	
	.mlm-media-modal-sidebar {
		display: none;
	}
	
	.mlm-media-grid {
		grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
		gap: 10px;
	}
	
	.mlm-media-modal-toolbar {
		flex-wrap: wrap;
	}
	
	.mlm-media-modal-filter {
		width: 100%;
	}
}

/* Quota Widget */
.mlm-modal-quota-widget {
	background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
	padding: 20px;
	margin: 0px 0 0 0;
	border-radius: 0;
	color: white;
	box-shadow: 0 2px 10px rgba(52, 152, 219, 0.2);
}

.mlm-modal-quota-title {
	font-size: 16px;
	font-weight: 600;
	margin-bottom: 12px;
	color: white;
}

.mlm-modal-quota-bar {
	width: 100%;
	height: 8px;
	background: rgba(255, 255, 255, 0.2);
	border-radius: 10px;
	overflow: hidden;
	margin-bottom: 12px;
}

.mlm-modal-quota-progress {
	height: 100%;
	background: linear-gradient(90deg, #3498db, #2980b9);
	transition: width 0.3s ease;
	border-radius: 10px;
}

.mlm-modal-quota-info {
	display: flex;
	justify-content: space-between;
	font-size: 13px;
	color: rgba(255, 255, 255, 0.9);
}

.mlm-modal-quota-info strong {
	color: white;
	font-weight: 600;
}

/* RTL Support */
[dir="rtl"] .mlm-media-modal-sidebar {
	border-left: none;
	border-right: 1px solid #e0e0e0;
}

[dir="rtl"] .mlm-media-modal-search i {
	right: auto;
	left: 15px;
}

[dir="rtl"] .mlm-media-item-checkbox {
	right: auto;
	left: 8px;
}

/* File Details Sidebar */
.mlm-media-details-sidebar {
	position: absolute;
	right: -280px;
	top: 70px;
	bottom: 10px;
	width: 260px;
	background: rgba(255, 255, 255, 0.98);
	backdrop-filter: blur(30px);
	-webkit-backdrop-filter: blur(30px);
	border: 1px solid rgba(255, 255, 255, 0.5);
	box-shadow: -10px 0 50px rgba(0, 0, 0, 0.15);
	border-radius: 10px 0 0 10px;
	z-index: 999;
	transition: right 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
	overflow: hidden;
	display: flex;
	flex-direction: column;
}

.mlm-media-details-sidebar.active {
	right: 0;
}

.mlm-media-details-header {
	padding: 12px 15px;
	background: linear-gradient(135deg, rgba(52, 152, 219, 0.1), rgba(41, 128, 185, 0.1));
	backdrop-filter: blur(10px);
	display: flex;
	justify-content: space-between;
	align-items: center;
	border-bottom: 1px solid rgba(52, 152, 219, 0.2);
}

.mlm-media-details-header h3 {
	margin: 0;
	font-size: 14px;
	font-weight: 600;
	color: #2c3e50;
}

.mlm-media-details-close {
	background: none;
	border: none;
	cursor: pointer;
	padding: 4px 8px;
	border-radius: 6px;
	transition: all 0.2s;
	color: #7f8c8d;
	font-size: 14px;
}

.mlm-media-details-close:hover {
	background: rgba(231, 76, 60, 0.1);
	color: #e74c3c;
}

.mlm-media-details-content {
	flex: 1;
	overflow-y: auto;
	padding: 15px;
}

.mlm-media-details-content::-webkit-scrollbar {
	width: 6px;
}

.mlm-media-details-content::-webkit-scrollbar-track {
	background: rgba(0, 0, 0, 0.05);
}

.mlm-media-details-content::-webkit-scrollbar-thumb {
	background: rgba(52, 152, 219, 0.3);
	border-radius: 10px;
}

.mlm-media-details-content::-webkit-scrollbar-thumb:hover {
	background: rgba(52, 152, 219, 0.5);
}

.mlm-media-details-field {
	margin-bottom: 12px;
}

.mlm-media-details-field label {
	display: block;
	margin-bottom: 5px;
	font-weight: 600;
	color: #2c3e50;
	font-size: 12px;
}

.mlm-media-details-field input,
.mlm-media-details-field textarea {
	width: 100%;
	padding: 7px 9px;
	border: 1px solid #ddd;
	border-radius: 6px;
	font-size: 12px;
	font-family: inherit;
	transition: all 0.2s;
	background: rgba(255, 255, 255, 0.9);
}

.mlm-media-details-field input:focus,
.mlm-media-details-field textarea:focus {
	outline: none;
	border-color: #3498db;
	box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.mlm-media-details-field textarea {
	resize: vertical;
	min-height: 45px;
}

.mlm-media-details-field small {
	display: block;
	margin-top: 4px;
	font-size: 10px;
	color: #7f8c8d;
	line-height: 1.3;
}

.mlm-media-details-field input[readonly] {
	background: rgba(0, 0, 0, 0.05);
	cursor: not-allowed;
}

.mlm-media-copy-btn {
	width: 100%;
	margin-top: 8px;
	padding: 7px 10px;
	background: linear-gradient(135deg, #3498db, #2980b9);
	color: white;
	border: none;
	border-radius: 6px;
	cursor: pointer;
	font-size: 11px;
	font-weight: 600;
	transition: all 0.2s;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
}

.mlm-media-copy-btn:hover {
	transform: translateY(-2px);
	box-shadow: 0 5px 15px rgba(52, 152, 219, 0.3);
}

.mlm-media-details-actions {
	margin-top: 15px;
	padding-top: 15px;
	border-top: 1px solid rgba(0, 0, 0, 0.1);
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.mlm-media-btn-primary,
.mlm-media-btn-secondary {
	padding: 9px 15px;
	border: none;
	border-radius: 6px;
	cursor: pointer;
	font-size: 12px;
	font-weight: 600;
	transition: all 0.2s;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
}

.mlm-media-btn-primary {
	background: linear-gradient(135deg, #3498db, #2980b9);
	color: white;
}

.mlm-media-btn-primary:hover {
	transform: translateY(-2px);
	box-shadow: 0 5px 15px rgba(52, 152, 219, 0.3);
}

.mlm-media-btn-secondary {
	background: rgba(231, 76, 60, 0.1);
	color: #e74c3c;
	border: 1px solid rgba(231, 76, 60, 0.3);
}

.mlm-media-btn-secondary:hover {
	background: rgba(231, 76, 60, 0.15);
	border-color: #e74c3c;
}

/* Mobile Tab Buttons */
.mlm-media-modal-mobile-tabs {
	display: none;
	gap: 10px;
	margin-bottom: 15px;
	padding: 0 5px;
	flex-direction: row;
	width: 100%;
}

.mlm-media-mobile-tab-btn {
	flex: 1;
	padding: 12px 15px;
	background: white;
	border: 2px solid #e0e0e0;
	border-radius: 8px;
	cursor: pointer;
	font-size: 13px;
	font-weight: 600;
	color: #666;
	transition: all 0.2s;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
}

.mlm-media-mobile-tab-btn:hover {
	background: #f8f9fa;
}

.mlm-media-mobile-tab-btn.active {
	background: linear-gradient(135deg, #3498db, #2980b9);
	color: white;
	border-color: #3498db;
}

/* Responsive */
@media (max-width: 768px) {
	/* مخفی کردن sidebar در موبایل */
	.mlm-media-modal-sidebar {
		display: none;
	}
	
	/* نمایش تب‌های موبایل */
	.mlm-media-modal-mobile-tabs {
		display: flex;
	}
	
	/* toolbar و محتوا full width شوند */
	.mlm-media-modal-content {
		flex: 1;
		width: 100%;
	}
	
	/* سایدبار جزئیات */
	.mlm-media-details-sidebar {
		width: 100%;
		right: -100%;
		border-radius: 20px 20px 0 0;
		position: fixed;
		bottom: -100%;
		left: 0;
		height: 70vh;
		z-index: 1001;
		transition: bottom 0.3s ease;
	}
	
	.mlm-media-details-sidebar.active {
		bottom: 0;
	}
	
	.mlm-media-details-header {
		padding: 15px 50px 15px 15px;
		position: relative;
		height: auto;
		min-height: 48px;
	}
	
	.mlm-media-details-close {
		position: absolute;
		top: 50%;
		transform: translateY(-50%);
		left: 12px;
		padding: 6px 10px;
	}
	
	.mlm-media-details-content {
		padding: 12px;
	}
	
	.mlm-media-details-field {
		margin-bottom: 10px;
	}
}

/* Dark Mode Support (اختیاری) */
@media (prefers-color-scheme: dark) {
	.mlm-media-modal {
		background: #1e1e1e;
		color: #e0e0e0;
	}
	
	.mlm-media-modal-sidebar {
		background: #2a2a2a;
		border-color: #444;
	}
	
	.mlm-media-modal-tab {
		background: #333;
		color: #e0e0e0;
		border-color: #444;
	}
	
	.mlm-media-modal-gallery {
		background: #252525;
	}
	
	.mlm-media-item {
		background: #333;
		border-color: #444;
	}
	
	.mlm-media-upload-area {
		background: #2a2a2a;
		border-color: #444;
	}
}

