:root {
	--primary: #6c5ce7;
	--primary-light: #a29bfe;
	--dark: #2d3436;
	--light: #dfe6e9;
	--white: #ffffff;
	--danger: #d63031;
	--success: #00b894;
	--radius: 12px;
	--shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
	--sidebar-width: 340px;
}

* {
	box-sizing: border-box;
	outline: none;
}

body {
	font-family: 'Vazir', sans-serif;
	background-color: #f0f2f5;
	margin: 0;
	padding: 0;
	color: var(--dark);
	height: 100vh;
	display: flex;
	flex-direction: column;
	overflow: hidden;
}

/* هدر */
header {
	background: var(--white);
	padding: 1rem 2rem;
	display: flex;
	justify-content: space-between;
	align-items: center;
	box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
	z-index: 100;
}

.logo {
	font-weight: 900;
	font-size: 1.5rem;
	color: var(--primary);
	display: flex;
	align-items: center;
	gap: 10px;
}

nav>* {
	background: transparent;
	border: none;
	padding: 0.5rem 1rem;
	cursor: pointer;
	font-size: 1rem;
	color: #636e72;
	transition: 0.3s;
	border-radius: var(--radius);
	font-family: inherit;
	border: 1px solid #CCC !important;
}

nav *.active,
nav button:hover {
	background: var(--primary);
	color: var(--white);
	border: 1px solid #FFF !important;
}

nav {
	display: flex;
	gap: 8px;
	flex-wrap: wrap;
}

.header-actions {
	display: flex;
	align-items: center;
	gap: 10px;
}

.user-badge {
	display: flex;
	align-items: center;
	gap: 8px;
	background: #f4f6fb;
	padding: 6px 10px;
	border-radius: 10px;
	font-size: 0.9rem;
	color: #2d3436;
}

.user-badge .dot {
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: #b2bec3;
}

.user-badge.online .dot {
	background: var(--success);
}

/* بدنه اصلی */
main {
	flex: 1;
	display: flex;
	overflow: hidden;
	position: relative;
}

/* سایدبار */
.sidebar {
	width: var(--sidebar-width);
	background: var(--white);
	display: flex;
	flex-direction: column;
	border-left: 1px solid #eee;
	z-index: 10;
}

.sidebar-scroll {
	flex: 1;
	padding: 1.5rem;
	overflow-y: auto;
}

.tool-group {
	margin-bottom: 1.5rem;
}

.tool-group h3 {
	font-size: 0.85rem;
	color: #b2bec3;
	margin-bottom: 0.8rem;
	text-transform: uppercase;
	display: flex;
	align-items: center;
	gap: 5px;
}

.control-row {
	display: flex;
	gap: 10px;
	margin-bottom: 10px;
}

input[type="text"],
input[type="number"],
select {
	width: 100%;
	padding: 10px;
	border: 1px solid #ddd;
	border-radius: 8px;
	font-family: inherit;
}

.btn {
	width: 100%;
	padding: 12px;
	border: none;
	border-radius: 8px;
	cursor: pointer;
	font-weight: bold;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	transition: 0.2s;
	font-family: inherit;
	margin-bottom: 5px;
}

.btn-primary {
	background: var(--primary);
	color: white;
}

.btn-success {
	background: var(--success);
	color: white;
}

.btn-danger {
	background: var(--danger);
	color: white;
}

.btn-outline {
	background: transparent;
	border: 1px solid #ddd;
	color: var(--dark);
}

.btn-sm {
	padding: 6px;
	width: auto;
	font-size: 0.9rem;
}

.btn-outline.active {
	background: var(--primary);
	color: #fff;
	border-color: var(--primary);
}

/* پالت رنگ */
.color-palette {
	display: flex;
	gap: 8px;
	flex-wrap: wrap;
	margin-bottom: 10px;
}

.color-swatch {
	width: 30px;
	height: 30px;
	border-radius: 50%;
	cursor: pointer;
	border: 2px solid #eee;
	transition: transform 0.2s;
}

.color-swatch:hover {
	transform: scale(1.1);
	border-color: #aaa;
}

/* تب‌های دسته‌بندی */
.category-tabs {
	display: flex;
	gap: 5px;
	overflow-x: auto;
	padding-bottom: 5px;
	margin-bottom: 10px;
	scrollbar-width: none;
}

.cat-tab {
	white-space: nowrap;
	padding: 6px 12px;
	font-size: 0.8rem;
	background: #eee;
	border-radius: 20px;
	cursor: pointer;
	border: none;
	transition: 0.2s;
}

.cat-tab.active {
	background: var(--primary);
	color: white;
}

.bg-grid {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: 8px;
}

.bg-thumb {
	width: 100%;
	aspect-ratio: 1/1.4;
	border-radius: 6px;
	cursor: pointer;
	border: 2px solid transparent;
	background-size: cover;
	background-position: center;
	transition: transform 0.2s;
}

.bg-thumb:hover,
.bg-thumb.active {
	border-color: var(--primary);
	transform: scale(1.05);
}

/* پنل لایه‌ها */
.layer-panel {
	border-top: 1px solid #eee;
	background: #f9f9f9;
	max-height: 250px;
	display: flex;
	flex-direction: column;
}

.layer-header {
	padding: 10px 15px;
	font-size: 0.9rem;
	font-weight: bold;
	background: #eee;
	display: flex;
	justify-content: space-between;
	align-items: center;
}

.layer-list {
	overflow-y: auto;
	flex: 1;
	padding: 5px;
}

.layer-item {
	padding: 10px;
	background: white;
	border-bottom: 1px solid #eee;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: space-between;
	font-size: 0.9rem;
}

.layer-item:hover {
	background: #f0f0f0;
}

.layer-item.active {
	background: var(--primary-light);
	color: var(--primary);
	border-right: 3px solid var(--primary);
}

.layer-name {
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	max-width: 120px;
}

.layer-actions i {
	margin-right: 8px;
	color: #999;
	cursor: pointer;
	transition: 0.2s;
}

.layer-actions i:hover {
	color: var(--dark);
}

.layer-actions i.fa-trash:hover {
	color: var(--danger);
}

/* فضای کار */
.workspace {
	flex: 1;
	background-color: #dfe6e9;
	display: flex;
	justify-content: center;
	align-items: center;
	position: relative;
	overflow: auto;
	padding: 20px;
}

#card-canvas {
	background-color: white;
	box-shadow: var(--shadow);
	position: relative;
	overflow: hidden;
	transition: all 0.3s ease;
	/* انیمیشن تغییر سایز */
	background-size: cover;
	background-position: center;
	/* سایز پیش‌فرض */
	width: 500px;
	height: 700px;
}

/* واترمارک سایت */
#branding-footer {
	position: absolute;
	bottom: 10px;
	left: 0;
	width: 100%;
	text-align: center;
	font-size: 12px;
	color: rgba(255, 255, 255, 0.8);
	text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
	font-family: sans-serif;
	pointer-events: none;
	/* کلیک‌ها را رد می‌کند */
	z-index: 9999;
	letter-spacing: 0.5px;
}

/* المان‌ها */
.draggable {
	position: absolute;
	cursor: grab;
	user-select: none;
	padding: 5px;
	border: 1px dashed transparent;
	line-height: 1.4;
	min-width: 20px;
	min-height: 20px;
}

.draggable:hover {
	border: 1px dashed var(--primary);
}

.draggable.selected {
	border: 1px solid var(--primary);
	background: rgba(108, 92, 231, 0.05);
	cursor: grabbing;
	z-index: 1000 !important;
}

.draggable img {
	max-width: 150px;
	pointer-events: none;
	width: 100%;
	display: block;
}

/* گالری */
#gallery-view {
	display: none;
	padding: 2rem;
	overflow-y: auto;
	width: 100%;
}

.gallery-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
	gap: 2rem;
	max-width: 1200px;
	margin: 0 auto;
}

/* Force two-column layout for user's gallery on desktop */
#gallery-view .gallery-grid {
	grid-template-columns: repeat(2, 1fr);
	gap: 1.2rem;
	max-width: 900px;
	margin: 0 auto;
}

@media (max-width: 700px) {
	#gallery-view .gallery-grid {
		grid-template-columns: 1fr;
	}
}

.gallery-item {
	background: white;
	border-radius: var(--radius);
	overflow: hidden;
	box-shadow: var(--shadow);
}

.gallery-item img {
	width: 100%;
	display: block;
}

.gallery-actions {
	padding: 1rem;
	display: flex;
	gap: 10px;
	justify-content: center;
}

.gallery-actions .btn {
	width: auto;
	margin: 0;
}

/* مودال و Toast */
.toast {
	position: fixed;
	top: 20px;
	left: 20px;
	background: var(--dark);
	color: white;
	padding: 1rem 2rem;
	border-radius: 8px;
	z-index: 2000;
	opacity: 0;
	transform: translateY(20px);
	transition: 0.3s;
}

.toast.show {
	opacity: 1;
	transform: translateY(0);
}

.modal-overlay {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: rgba(0, 0, 0, 0.5);
	display: flex;
	justify-content: center;
	align-items: center;
	z-index: 200;
	opacity: 0;
	pointer-events: none;
	transition: 0.3s;
}

.modal-overlay.open {
	opacity: 1;
	pointer-events: all;
}

.modal {
	background: white;
	padding: 2rem;
	border-radius: var(--radius);
	width: 90%;
	max-width: 400px;
	text-align: center;
}

.share-links {
	display: flex;
	justify-content: center;
	gap: 15px;
	margin-top: 20px;
}

.share-btn {
	width: 50px;
	height: 50px;
	border-radius: 50%;
	display: flex;
	justify-content: center;
	align-items: center;
	color: white;
	font-size: 1.2rem;
	text-decoration: none;
	transition: 0.2s;
}

.share-btn:hover {
	transform: scale(1.1);
}

.bg-telegram {
	background: #0088cc;
}

.bg-whatsapp {
	background: #25d366;
}

.bg-facebook {
	background: #3b5998;
}

.auth-tabs {
	display: flex;
	gap: 8px;
	margin-bottom: 12px;
}

.auth-tab {
	flex: 1;
	padding: 10px;
	border: 1px solid #eee;
	border-radius: 10px;
	background: #fafafa;
	cursor: pointer;
	font-weight: 700;
}

.auth-tab.active {
	background: var(--primary);
	color: white;
	border-color: var(--primary);
}

.auth-form {
	display: flex;
	flex-direction: column;
	gap: 10px;
	margin-top: 10px;
}

.muted {
	color: #636e72;
	font-size: 0.85rem;
}

.sheet-handle {
	display: none;
}

/* Theme (dark mode) */
body.theme-dark {
	--primary: #7c6ee6;
	--primary-light: #a29bfe;
	--dark: #e5e7eb;
	--light: #1c1f24;
	--white: #161a23;
	--danger: #ef4444;
	--success: #22c55e;
	background-color: #0f131a;
	color: #e5e7eb;
}

body.theme-dark header {
	background: #161a23;
	box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
}

body.theme-dark .sidebar {
	background: #151a23;
	border-color: #242b38;
}

body.theme-dark .workspace {
	background: #0c1017;
}

body.theme-dark .layer-panel {
	background: #111622;
}

body.theme-dark .btn-outline {
	border-color: #3a4253;
	color: #e5e7eb;
}

body.theme-dark input,
body.theme-dark select {
	background: #1c2230;
	border-color: #2f3645;
	color: #e5e7eb;
}

body.theme-dark .bg-thumb {
	border-color: #2d3445;
}

body.theme-dark .modal {
	background: #151a23;
	color: #e5e7eb;
}

body.theme-dark .toast {
	background: #111622;
}

/* Mobile app-like layout */
@media (max-width: 768px) {
	header {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		padding: 12px 14px;
	}

	.hidden {
		display: none;
	}

	header {
		gap: 10px;
		flex-wrap: wrap;
	}

	.logo {
		font-size: 1.05rem;
		flex: 1 1 100%;
	}

	nav {
		width: 100%;
		display: flex;
	}

	nav>* {
		padding: 5px !important;
		font-size: 0.95rem !important;
		border-radius: 12px !important;
		text-align: center !important;
		min-width: 40px;
		background: #EFEFEF !important;
		important;
		border: 1px solid #CCC !important;
	}

	.theme-dark nav>* {
		background: #333 !important;
		important;
		border: 1px solid #FFF !important;
		color: #FFF !important;
	}

	.theme-dark .sheet-handle,
	.theme-dark .footerbot {
		background: var(--primary);
		color: #FFF;
	}

	.footerbot {
		padding: 1rem;
		border-top: 1px solid #eee;
		background: #fff;
	}

	#auth-ope !n-btn,
	#user-badge {
		margin-left: auto;
	}

	body {
		height: 100svh;
	}

	main {
		padding-top: 64px;
	}

	/* Bottom-sheet tools */
	.sidebar {
		position: fixed;
		left: 0;
		right: 0;
		bottom: 0;
		width: 100%;
		height: min(68svh, 560px);
		border-left: none;
		border-top: 1px solid #eee;
		border-radius: 16px 16px 0 0;
		box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.12);
		transform: translateY(calc(100% - 72px));
		transition: transform 0.25s ease;
		z-index: 150;
	}

	.sidebar.open {
		transform: translateY(0);
	}

	.sidebar-scroll {
		padding: 12px 14px 18px;
	}

	.layer-panel {
		display: none;
	}

	.sheet-handle {
		height: 44px;
		display: flex;
		align-items: center;
		justify-content: center;
		border-bottom: 1px solid #f1f1f1;
		background: #fff;
		border-radius: 16px 16px 0 0;
		flex: 0 0 auto;
		cursor: pointer;
	}

	.sheet-handle .bar {
		width: 56px;
		height: 6px;
		border-radius: 10px;
		background: #dfe6e9;
	}

	.workspace {
		padding: 10px;
		height: calc(100svh - 60px);
		overflow: hidden;
		align-items: flex-start;
	}

	#card-canvas {
		transform-origin: top center;
		margin: 0 auto;
		touch-action: none;
	}
}

/* Quick layer picker (floating corner) */
.layer-quick {
	position: absolute;
	top: 12px;
	right: 12px;
	width: 180px;
	max-height: 220px;
	overflow-y: auto;
	background: rgba(255, 255, 255, 0.95);
	border-radius: 12px;
	box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
	padding: 8px;
	z-index: 2;
	font-size: 0.85rem;
}

.layer-quick .quick-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 8px;
	margin-bottom: 8px;
}

.layer-quick .quick-list {
	display: flex;
	flex-direction: column;
	gap: 6px;
}

.layer-quick .quick-item {
	display: flex;
	gap: 8px;
	align-items: center;
	padding: 6px;
	border-radius: 8px;
	cursor: pointer;
	background: transparent;
	transition: 0.15s;
}

.layer-quick .quick-item:hover {
	background: rgba(108, 92, 231, 0.06);
}

.layer-quick .quick-item.active {
	background: rgba(108, 92, 231, 0.12);
	border: 1px solid rgba(108, 92, 231, 0.12);
}

.layer-quick .thumb {
	width: 36px;
	height: 36px;
	border-radius: 6px;
	background: #f0f0f0;
	display: flex;
	align-items: center;
	justify-content: center;
	overflow: hidden;
}

.layer-quick .thumb img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

.layer-quick .name {
	flex: 1;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}