/*
 * =====================================================
 * zuoekai-ai-canvas.css
 * AI Studio 无限画布专属 UI 组件样式
 * =====================================================
 * 命名空间：zuoekai-ai-canvas-*
 * 职责：
 *   - 画布整体布局（layout）
 *   - 画布视口容器（viewport）——棋盘格背景 + Konva Stage 挂载区
 *   - 工具栏（toolstrip）——横排/竖排工具图标
 *   - 图层面板（layer-rack）——图层列表/显隐/排序/锁定
 *   - 蒙版笔刷控制（brush-ctrl）——笔刷大小/硬度控制面板
 *   - 缩放浮层（zoom-hud）——画布右下角缩放比例显示
 *   - 生成参数停靠面板（gen-dock）——底部参数输入区
 * 依赖：assets/zuoekai-ui/tokens.css / base.css
 * 适配：桌面端优先，小屏（<768px）提供横向工具栏 + 图层抽屉模式
 * 归属：zuoekai-ui 的 AI 画布业务专属分支，不与通用组件类名冲突
 * =====================================================
 */

/* ═══════════════════════════════════════════════════
 * 画布页面整体布局根容器
 * 三栏：工具栏 | 画布视口 | 图层面板
 * ═══════════════════════════════════════════════════ */
.zuoekai-ai-canvas-layout {
	display: flex;
	position: relative;
	width: 100%;
	min-height: 560px;
	overflow: hidden;
	background: var(--zuoekai-bg-secondary, #0f172a);
	border-radius: var(--zuoekai-radius-lg, 12px);
	border: 1px solid rgba(148, 163, 184, 0.12);
}

/* ═══════════════════════════════════════════════════
 * 工具栏（zuoekai-ai-canvas-toolstrip）
 * 默认竖排，浮于画布左侧
 * ═══════════════════════════════════════════════════ */
.zuoekai-ai-canvas-toolstrip {
	flex-shrink: 0;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 2px;
	padding: 8px 6px;
	width: 48px;
	background: rgba(15, 23, 42, 0.92);
	backdrop-filter: blur(12px);
	-webkit-backdrop-filter: blur(12px);
	border-right: 1px solid rgba(148, 163, 184, 0.1);
	z-index: 10;
}

/* 工具栏横排变体 */
.zuoekai-ai-canvas-toolstrip--horizontal {
	flex-direction: row;
	width: 100%;
	height: 48px;
	padding: 6px 10px;
	border-right: none;
	border-bottom: 1px solid rgba(148, 163, 184, 0.1);
	overflow-x: auto;
	scrollbar-width: none;
}
.zuoekai-ai-canvas-toolstrip--horizontal::-webkit-scrollbar {
	display: none;
}

/* 工具栏分组分隔线 */
.zuoekai-ai-canvas-toolstrip__divider {
	width: 24px;
	height: 1px;
	background: rgba(148, 163, 184, 0.14);
	margin: 4px 0;
	flex-shrink: 0;
}
.zuoekai-ai-canvas-toolstrip--horizontal .zuoekai-ai-canvas-toolstrip__divider {
	width: 1px;
	height: 20px;
	margin: 0 4px;
}

/* 工具按钮 */
.zuoekai-ai-canvas-toolstrip__btn {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 36px;
	height: 36px;
	border-radius: 8px;
	border: none;
	background: transparent;
	color: rgba(148, 163, 184, 0.75);
	cursor: pointer;
	transition: background 0.15s ease, color 0.15s ease;
	flex-shrink: 0;
	padding: 0;
	position: relative;
}

.zuoekai-ai-canvas-toolstrip__btn:hover {
	background: rgba(148, 163, 184, 0.1);
	color: #e2e8f0;
}

/* 激活状态（当前使用中的工具） */
.zuoekai-ai-canvas-toolstrip__btn--active {
	background: rgba(99, 102, 241, 0.18);
	color: #818cf8;
}
.zuoekai-ai-canvas-toolstrip__btn--active:hover {
	background: rgba(99, 102, 241, 0.26);
	color: #a5b4fc;
}

/* 工具按钮内图标 */
.zuoekai-ai-canvas-toolstrip__btn svg,
.zuoekai-ai-canvas-toolstrip__btn .dashicons {
	width: 18px;
	height: 18px;
	pointer-events: none;
	display: block;
}

/* ═══════════════════════════════════════════════════
 * 画布视口（zuoekai-ai-canvas-viewport）
 * Konva Stage 的挂载区，棋盘格背景
 * ═══════════════════════════════════════════════════ */
.zuoekai-ai-canvas-viewport {
	flex: 1;
	position: relative;
	overflow: hidden;
	cursor: default;
	/* 棋盘格背景（CSS 实现，不依赖图片） */
	background-color: #1e293b;
	background-image:
		linear-gradient(45deg, rgba(255, 255, 255, 0.025) 25%, transparent 25%),
		linear-gradient(-45deg, rgba(255, 255, 255, 0.025) 25%, transparent 25%),
		linear-gradient(45deg, transparent 75%, rgba(255, 255, 255, 0.025) 75%),
		linear-gradient(-45deg, transparent 75%, rgba(255, 255, 255, 0.025) 75%);
	background-size: 20px 20px;
	background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

/* Konva 自动创建的 canvas 元素 */
.zuoekai-ai-canvas-viewport canvas {
	display: block;
}

/* 拖拽平移模式 */
.zuoekai-ai-canvas-viewport--panning {
	cursor: grab;
}
.zuoekai-ai-canvas-viewport--panning:active {
	cursor: grabbing;
}

/* 蒙版笔刷绘制模式 */
.zuoekai-ai-canvas-viewport--brush {
	cursor: crosshair;
}

/* ═══════════════════════════════════════════════════
 * 图层面板（zuoekai-ai-canvas-layer-rack）
 * 右侧侧边栏，展示图层列表
 * ═══════════════════════════════════════════════════ */
.zuoekai-ai-canvas-layer-rack {
	flex-shrink: 0;
	display: flex;
	flex-direction: column;
	width: 220px;
	background: rgba(15, 23, 42, 0.94);
	backdrop-filter: blur(12px);
	-webkit-backdrop-filter: blur(12px);
	border-left: 1px solid rgba(148, 163, 184, 0.1);
	overflow: hidden;
	z-index: 10;
}

/* 图层面板标题栏 */
.zuoekai-ai-canvas-layer-rack__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 10px 12px 8px;
	border-bottom: 1px solid rgba(148, 163, 184, 0.09);
	flex-shrink: 0;
}

.zuoekai-ai-canvas-layer-rack__title {
	font-size: 11px;
	font-weight: 600;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	color: rgba(148, 163, 184, 0.5);
	user-select: none;
}

/* 图层列表滚动区 */
.zuoekai-ai-canvas-layer-rack__list {
	flex: 1;
	overflow-y: auto;
	padding: 4px 0;
}
.zuoekai-ai-canvas-layer-rack__list::-webkit-scrollbar {
	width: 4px;
}
.zuoekai-ai-canvas-layer-rack__list::-webkit-scrollbar-thumb {
	background: rgba(148, 163, 184, 0.18);
	border-radius: 2px;
}

/* 空状态 */
.zuoekai-ai-canvas-layer-rack__empty {
	padding: 24px 14px;
	text-align: center;
	color: rgba(148, 163, 184, 0.35);
	font-size: 12px;
	line-height: 1.65;
}

/* 单条图层行 */
.zuoekai-ai-canvas-layer-rack__item {
	display: flex;
	align-items: center;
	gap: 7px;
	padding: 6px 10px;
	cursor: pointer;
	user-select: none;
	transition: background 0.1s ease;
	position: relative;
}
.zuoekai-ai-canvas-layer-rack__item:hover {
	background: rgba(148, 163, 184, 0.06);
}

/* 选中图层 */
.zuoekai-ai-canvas-layer-rack__item--active {
	background: rgba(99, 102, 241, 0.14);
}
.zuoekai-ai-canvas-layer-rack__item--active:hover {
	background: rgba(99, 102, 241, 0.19);
}

/* 隐藏状态 */
.zuoekai-ai-canvas-layer-rack__item--hidden {
	opacity: 0.38;
}

/* 锁定状态（名称变灰） */
.zuoekai-ai-canvas-layer-rack__item--locked .zuoekai-ai-canvas-layer-rack__item-name {
	color: rgba(148, 163, 184, 0.45);
}

/* 图层缩略图 */
.zuoekai-ai-canvas-layer-rack__item-thumb {
	width: 28px;
	height: 28px;
	border-radius: 4px;
	flex-shrink: 0;
	background: rgba(148, 163, 184, 0.08);
	overflow: hidden;
	border: 1px solid rgba(148, 163, 184, 0.14);
}
.zuoekai-ai-canvas-layer-rack__item-thumb img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

/* 图层名称 */
.zuoekai-ai-canvas-layer-rack__item-name {
	flex: 1;
	font-size: 12px;
	color: rgba(226, 232, 240, 0.82);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

/* 图层操作图标区（悬停时显示） */
.zuoekai-ai-canvas-layer-rack__item-actions {
	display: flex;
	align-items: center;
	gap: 2px;
	opacity: 0;
	transition: opacity 0.12s ease;
}
.zuoekai-ai-canvas-layer-rack__item:hover .zuoekai-ai-canvas-layer-rack__item-actions,
.zuoekai-ai-canvas-layer-rack__item--active .zuoekai-ai-canvas-layer-rack__item-actions {
	opacity: 1;
}

/* 图层操作小图标按钮 */
.zuoekai-ai-canvas-layer-rack__item-btn {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 22px;
	height: 22px;
	border-radius: 4px;
	border: none;
	background: transparent;
	color: rgba(148, 163, 184, 0.55);
	cursor: pointer;
	padding: 0;
	transition: background 0.1s ease, color 0.1s ease;
	flex-shrink: 0;
}
.zuoekai-ai-canvas-layer-rack__item-btn:hover {
	background: rgba(148, 163, 184, 0.1);
	color: #e2e8f0;
}
.zuoekai-ai-canvas-layer-rack__item-btn svg,
.zuoekai-ai-canvas-layer-rack__item-btn .dashicons {
	width: 13px;
	height: 13px;
	pointer-events: none;
	display: block;
}

/* ═══════════════════════════════════════════════════
 * 蒙版笔刷控制面板（zuoekai-ai-canvas-brush-ctrl）
 * 笔刷工具激活时浮现，控制大小/硬度/模式
 * ═══════════════════════════════════════════════════ */
.zuoekai-ai-canvas-brush-ctrl {
	position: absolute;
	left: 58px;
	top: 50%;
	transform: translateY(-50%);
	display: flex;
	flex-direction: column;
	gap: 12px;
	padding: 14px 12px;
	background: rgba(15, 23, 42, 0.96);
	backdrop-filter: blur(14px);
	-webkit-backdrop-filter: blur(14px);
	border: 1px solid rgba(148, 163, 184, 0.14);
	border-radius: 10px;
	min-width: 168px;
	box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
	z-index: 30;
}

.zuoekai-ai-canvas-brush-ctrl__row {
	display: flex;
	flex-direction: column;
	gap: 7px;
}

.zuoekai-ai-canvas-brush-ctrl__label {
	display: flex;
	align-items: center;
	justify-content: space-between;
	font-size: 11px;
	font-weight: 500;
	color: rgba(148, 163, 184, 0.55);
	user-select: none;
}

.zuoekai-ai-canvas-brush-ctrl__value {
	font-size: 11px;
	color: rgba(226, 232, 240, 0.7);
}

/* 滑块（accent-color 使用主色调） */
.zuoekai-ai-canvas-brush-ctrl__slider {
	width: 100%;
	height: 4px;
	accent-color: #818cf8;
	cursor: pointer;
}

/* ═══════════════════════════════════════════════════
 * 缩放浮层（zuoekai-ai-canvas-zoom-hud）
 * 固定在画布视口右下角
 * ═══════════════════════════════════════════════════ */
.zuoekai-ai-canvas-zoom-hud {
	position: absolute;
	bottom: 16px;
	right: 232px; /* 避开图层面板（220px + 12px） */
	display: flex;
	align-items: center;
	gap: 3px;
	padding: 5px 8px;
	background: rgba(15, 23, 42, 0.9);
	backdrop-filter: blur(10px);
	-webkit-backdrop-filter: blur(10px);
	border: 1px solid rgba(148, 163, 184, 0.13);
	border-radius: 8px;
	box-shadow: 0 2px 14px rgba(0, 0, 0, 0.32);
	z-index: 20;
	user-select: none;
}

.zuoekai-ai-canvas-zoom-hud__value {
	font-size: 11px;
	font-weight: 500;
	color: rgba(226, 232, 240, 0.65);
	min-width: 40px;
	text-align: center;
}

.zuoekai-ai-canvas-zoom-hud__btn {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 24px;
	height: 24px;
	border-radius: 5px;
	border: none;
	background: transparent;
	color: rgba(148, 163, 184, 0.65);
	cursor: pointer;
	padding: 0;
	font-size: 15px;
	line-height: 1;
	transition: background 0.1s ease, color 0.1s ease;
}
.zuoekai-ai-canvas-zoom-hud__btn:hover {
	background: rgba(148, 163, 184, 0.1);
	color: #e2e8f0;
}

/* ═══════════════════════════════════════════════════
 * 生成参数停靠面板（zuoekai-ai-canvas-gen-dock）
 * 底部可折叠参数面板
 * ═══════════════════════════════════════════════════ */
.zuoekai-ai-canvas-gen-dock {
	flex-shrink: 0;
	display: flex;
	flex-direction: column;
	background: rgba(15, 23, 42, 0.97);
	border-top: 1px solid rgba(148, 163, 184, 0.1);
	padding: 14px 16px;
	gap: 12px;
	transition: max-height 0.25s ease;
}

.zuoekai-ai-canvas-gen-dock__header {
	display: flex;
	align-items: center;
	gap: 10px;
}

.zuoekai-ai-canvas-gen-dock__title {
	flex: 1;
	font-size: 13px;
	font-weight: 600;
	color: rgba(226, 232, 240, 0.82);
	user-select: none;
}

/* ═══════════════════════════════════════════════════
 * gen-dock 扩展：快捷标签区（Talk-Tab-Tune / Tab 区域）
 * 用于一键将预设提示词追加到生成输入框
 * ═══════════════════════════════════════════════════ */
.zuoekai-ai-canvas-gen-dock__tags {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
}

.zuoekai-ai-canvas-gen-dock__tag {
	display: inline-flex;
	align-items: center;
	padding: 3px 10px;
	font-size: 11px;
	font-weight: 500;
	color: rgba(148, 163, 184, 0.75);
	background: rgba(148, 163, 184, 0.06);
	border: 1px solid rgba(148, 163, 184, 0.18);
	border-radius: 20px;
	cursor: pointer;
	user-select: none;
	transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
	white-space: nowrap;
}

.zuoekai-ai-canvas-gen-dock__tag:hover {
	background: rgba(99, 102, 241, 0.14);
	color: #a5b4fc;
	border-color: rgba(99, 102, 241, 0.35);
}

.zuoekai-ai-canvas-gen-dock__tag--active {
	background: rgba(99, 102, 241, 0.2);
	color: #818cf8;
	border-color: rgba(99, 102, 241, 0.45);
}

/* ═══════════════════════════════════════════════════
 * gen-dock 扩展：对话历史气泡区（Talk-Tab-Tune / Talk 区域）
 * 展示近期生成记录，点击可恢复提示词
 * ═══════════════════════════════════════════════════ */
.zuoekai-ai-canvas-gen-dock__history {
	display: flex;
	flex-direction: column;
	gap: 8px;
	max-height: 280px;
	overflow-y: auto;
	padding-right: 2px;
}

.zuoekai-ai-canvas-gen-dock__history::-webkit-scrollbar {
	width: 3px;
}

.zuoekai-ai-canvas-gen-dock__history::-webkit-scrollbar-thumb {
	background: rgba(148, 163, 184, 0.18);
	border-radius: 2px;
}

/* 单条历史气泡 */
.zuoekai-ai-canvas-gen-dock__bubble {
	display: flex;
	align-items: flex-start;
	gap: 8px;
	padding: 8px 10px;
	background: rgba(148, 163, 184, 0.05);
	border: 1px solid rgba(148, 163, 184, 0.1);
	border-radius: 8px;
	cursor: pointer;
	transition: background 0.12s ease, border-color 0.12s ease;
	flex-shrink: 0;
}

.zuoekai-ai-canvas-gen-dock__bubble:hover {
	background: rgba(99, 102, 241, 0.1);
	border-color: rgba(99, 102, 241, 0.28);
}

/* 气泡缩略图 */
.zuoekai-ai-canvas-gen-dock__bubble-thumb {
	flex-shrink: 0;
	width: 40px;
	height: 40px;
	border-radius: 5px;
	overflow: hidden;
	background: rgba(148, 163, 184, 0.08);
	border: 1px solid rgba(148, 163, 184, 0.14);
}

.zuoekai-ai-canvas-gen-dock__bubble-thumb img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

/* 气泡文字区 */
.zuoekai-ai-canvas-gen-dock__bubble-meta {
	flex: 1;
	display: flex;
	flex-direction: column;
	gap: 3px;
	min-width: 0;
}

.zuoekai-ai-canvas-gen-dock__bubble-prompt {
	font-size: 11px;
	color: rgba(226, 232, 240, 0.72);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	line-height: 1.5;
}

.zuoekai-ai-canvas-gen-dock__bubble-time {
	font-size: 10px;
	color: rgba(148, 163, 184, 0.38);
}

/* 空状态 */
.zuoekai-ai-canvas-gen-dock__history-empty {
	font-size: 11px;
	color: rgba(148, 163, 184, 0.35);
	text-align: center;
	padding: 12px 0;
}

/* ═══════════════════════════════════════════════════
 * 小屏适配（< 768px）
 * ═══════════════════════════════════════════════════ */
@media (max-width: 767px) {
	/* 布局从横三栏改为纵向堆叠 */
	.zuoekai-ai-canvas-layout {
		flex-direction: column;
		min-height: 400px;
	}

	/* 工具栏横排 */
	.zuoekai-ai-canvas-toolstrip {
		flex-direction: row;
		width: 100%;
		height: 44px;
		padding: 4px 8px;
		border-right: none;
		border-bottom: 1px solid rgba(148, 163, 184, 0.1);
		overflow-x: auto;
	}
	.zuoekai-ai-canvas-toolstrip__divider {
		width: 1px;
		height: 20px;
		margin: 0 4px;
	}

	/* 图层面板变为右侧抽屉，默认隐藏 */
	.zuoekai-ai-canvas-layer-rack {
		position: absolute;
		right: 0;
		top: 0;
		bottom: 0;
		width: 200px;
		transform: translateX(100%);
		transition: transform 0.22s ease;
		z-index: 30;
		box-shadow: -4px 0 24px rgba(0, 0, 0, 0.45);
	}
	.zuoekai-ai-canvas-layer-rack--open {
		transform: translateX(0);
	}

	/* 缩放 HUD 右下，无图层面板偏移 */
	.zuoekai-ai-canvas-zoom-hud {
		right: 12px;
		bottom: 12px;
	}

	/* 笔刷控制面板调整位置 */
	.zuoekai-ai-canvas-brush-ctrl {
		left: 8px;
		top: auto;
		bottom: 60px;
		transform: none;
	}
}
