/* ============================================================
 * AI 生图工作台 · v4.0.0
 * 三栏布局：左控制面板 / 中查看区 / 右生成结果区
 * 全部类名 ais- 前缀，避免与 B2 主题样式冲突
 * ============================================================ */

.ais-app {
	--ais-bg: #f4f5f8;
	--ais-card: #ffffff;
	--ais-card-soft: #fafbfc;
	--ais-border: #eceef3;
	--ais-border-strong: #d8dce4;
	--ais-text: #1a1d29;
	--ais-text-2: #6b7280;
	--ais-text-3: #9ca3af;
	--ais-accent: #0f172a;
	--ais-accent-hover: #1e293b;
	--ais-shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
	--ais-radius-sm: 6px;
	--ais-radius-md: 10px;
	--ais-radius-lg: 14px;
	--ais-radius-pill: 999px;

	display: grid;
	grid-template-columns: 360px minmax(0, 1fr);
	/* 查看区固定高度（600px），记录区吃剩余空间——
	   不定高会被图片固有尺寸撑开导致整页变形拉长 */
	grid-template-rows: 600px minmax(300px, 1fr);
	gap: 16px;
	padding: 24px 32px; /* CTA 已内嵌左面板底部，无需额外悬浮留位 */
	max-width: 1280px;
	margin: 0 auto;
	/* 显式高度（非 min-height）：grid 行高需要确定值，图片才能按比例收进查看区 */
	height: calc(100vh - 160px);
	min-height: 940px;
	box-sizing: border-box;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
	             "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
	font-size: 13px;
	line-height: 1.5;
	color: var(--ais-text);
	-webkit-font-smoothing: antialiased;
}

.ais-app *, .ais-app *::before, .ais-app *::after { box-sizing: border-box; }

/* hidden 属性兜底：我们自己的 display:flex/grid 规则优先级高于 UA 的
   [hidden]{display:none}，必须显式声明，否则 loading 横幅/参考图格常驻显示 */
.ais-app [hidden] { display: none !important; }

.ais-panel-left   { grid-column: 1; grid-row: 1 / 3; min-height: 0; }
.ais-panel-middle { grid-column: 2; grid-row: 1;     min-height: 0; }
.ais-panel-right  { grid-column: 2; grid-row: 2;     min-height: 0; }

/* ========== 面板通用 ========== */
.ais-panel {
	background: var(--ais-card);
	border-radius: var(--ais-radius-lg);
	box-shadow: var(--ais-shadow-sm);
	border: 1px solid var(--ais-border);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	min-height: 0;
}

.ais-panel-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	padding: 16px 18px 12px;
	flex-shrink: 0;
}

.ais-panel-title {
	font-size: 14px;
	font-weight: 600;
	color: var(--ais-text);
	letter-spacing: 0.2px;
}

.ais-panel-body {
	padding: 0 18px 18px;
	flex: 1;
	overflow-y: auto;
	min-height: 0;
}

.ais-panel-body::-webkit-scrollbar { width: 6px; }
.ais-panel-body::-webkit-scrollbar-track { background: transparent; }
.ais-panel-body::-webkit-scrollbar-thumb { background: #e0e3ea; border-radius: 3px; }
.ais-panel-body::-webkit-scrollbar-thumb:hover { background: #c8ccd6; }

/* ========== 余额徽章（左面板头部） ========== */
.ais-balance {
	display: inline-flex;
	align-items: center;
	gap: 5px;
	background: var(--ais-card-soft);
	border: 1px solid var(--ais-border);
	border-radius: var(--ais-radius-pill);
	padding: 3px 10px;
	font-size: 11.5px;
	color: var(--ais-text-2);
	white-space: nowrap;
}
.ais-balance-value { font-weight: 600; color: var(--ais-text); }
.ais-balance-recharge {
	color: #2563eb;
	text-decoration: none;
	font-weight: 500;
	margin-left: 2px;
}
.ais-balance-recharge:hover { text-decoration: underline; }

/* ========== Section ========== */
.ais-section { margin-bottom: 18px; }
.ais-section-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	margin-bottom: 8px;
}
.ais-section-title { font-size: 12px; font-weight: 500; color: var(--ais-text); }
.ais-section-actions { display: flex; gap: 6px; }

/* ========== 小按钮 ========== */
.ais-btn-ghost {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	height: 24px;
	padding: 0 8px;
	background: var(--ais-card);
	border: 1px solid var(--ais-border-strong);
	border-radius: var(--ais-radius-pill);
	color: var(--ais-text-2);
	font-size: 11px;
	font-family: inherit;
	cursor: pointer;
	transition: all .15s ease;
	white-space: nowrap;
}
.ais-btn-ghost:hover { background: var(--ais-card-soft); color: var(--ais-text); }
.ais-btn-ghost:disabled { opacity: .45; cursor: not-allowed; }
.ais-btn-icon { width: 14px; height: 14px; display: inline-flex; align-items: center; justify-content: center; }
.ais-btn-ghost svg { width: 11px; height: 11px; }

/* ========== 提示词 ========== */
.ais-textarea {
	width: 100%;
	min-height: 96px;
	padding: 10px 12px;
	border: 1px solid var(--ais-border);
	border-radius: var(--ais-radius-md);
	background: var(--ais-card);
	font-family: inherit;
	font-size: 12.5px;
	color: var(--ais-text);
	resize: vertical;
	outline: none;
	transition: border-color .15s ease;
}
.ais-textarea::placeholder { color: var(--ais-text-3); }
.ais-textarea:focus { border-color: var(--ais-border-strong); }

/* ========== 参考图 ========== */
.ais-dropzone {
	width: 100%;
	min-height: 96px;
	border: 1px dashed var(--ais-border-strong);
	border-radius: var(--ais-radius-md);
	background: var(--ais-card-soft);
	display: flex;
	align-items: center;
	justify-content: center;
	color: var(--ais-text-3);
	font-size: 12px;
	text-align: center;
	padding: 12px;
	transition: all .15s ease;
}
.ais-dropzone.ais-dragover {
	border-color: var(--ais-accent);
	background: #f0f4ff;
	color: var(--ais-text-2);
}
.ais-refs-grid {
	display: grid;
	grid-template-columns: repeat(4, 1fr);
	gap: 6px;
	margin-top: 8px;
}
.ais-ref-thumb {
	position: relative;
	aspect-ratio: 1 / 1;
	border-radius: 6px;
	overflow: hidden;
	background: var(--ais-card-soft);
	border: 1px solid var(--ais-border);
}
.ais-ref-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ais-ref-remove {
	position: absolute;
	top: 2px; right: 2px;
	width: 18px; height: 18px;
	border-radius: 50%;
	background: rgba(15, 23, 42, 0.7);
	color: #fff;
	border: none;
	cursor: pointer;
	font-size: 13px;
	line-height: 1;
	display: flex;
	align-items: center;
	justify-content: center;
	opacity: 0;
	transition: opacity .15s ease;
}
.ais-ref-thumb:hover .ais-ref-remove { opacity: 1; }

/* ========== 下拉 ========== */
.ais-select {
	width: 100%;
	height: 32px;
	padding: 0 28px 0 12px;
	border: 1px solid var(--ais-border);
	border-radius: var(--ais-radius-md);
	background-color: var(--ais-card);
	background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'><path fill='none' stroke='%236b7280' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round' d='M2 4l3 3 3-3'/></svg>");
	background-repeat: no-repeat;
	background-position: right 10px center;
	appearance: none;
	-webkit-appearance: none;
	font-family: inherit;
	font-size: 12px;
	color: var(--ais-text);
	outline: none;
	cursor: pointer;
}
.ais-select:focus { border-color: var(--ais-border-strong); }

/* ========== 分段控件 ========== */
.ais-segmented { display: flex; gap: 6px; flex-wrap: wrap; }
.ais-seg-item {
	height: 28px;
	min-width: 44px;
	padding: 0 12px;
	border-radius: var(--ais-radius-pill);
	border: 1px solid var(--ais-border-strong);
	color: var(--ais-text-2);
	font-size: 12px;
	font-family: inherit;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	background: var(--ais-card);
	transition: all .15s ease;
}
.ais-seg-item:hover { color: var(--ais-text); }
.ais-seg-item.active {
	background: var(--ais-accent);
	border-color: var(--ais-accent);
	color: #fff;
}

/* ========== 尺寸组 ========== */
.ais-size-group {
	border: 1px solid var(--ais-border);
	border-radius: var(--ais-radius-md);
	padding: 10px 12px 12px;
	background: var(--ais-card);
}
.ais-sub-label {
	font-size: 11.5px;
	color: var(--ais-text-3);
	margin-bottom: 6px;
	display: block;
}

/* ========== 开关 ========== */
.ais-toggle-block {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 12px;
}
.ais-toggle-info { flex: 1; min-width: 0; }
.ais-hint { font-size: 11px; color: var(--ais-text-3); margin-top: 2px; line-height: 1.4; }
.ais-switch {
	position: relative;
	width: 26px;
	height: 14px;
	background: #d8dce4;
	border-radius: 999px;
	cursor: pointer;
	transition: background .15s ease;
	flex-shrink: 0;
	margin-top: 2px;
}
.ais-switch::after {
	content: "";
	position: absolute;
	top: 1.5px; left: 1.5px;
	width: 11px; height: 11px;
	background: #fff;
	border-radius: 50%;
	box-shadow: 0 1px 2px rgba(0,0,0,.15);
	transition: transform .15s ease;
}
.ais-switch.on { background: var(--ais-accent); }
.ais-switch.on::after { transform: translateX(12px); }

/* ========== 宽高比 ========== */
.ais-ratio-grid {
	display: grid;
	grid-template-columns: repeat(4, 1fr);
	gap: 6px;
}
.ais-ratio-item {
	border: 1px solid var(--ais-border-strong);
	border-radius: var(--ais-radius-md);
	background: var(--ais-card);
	padding: 8px 4px 6px;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 4px;
	cursor: pointer;
	transition: all .15s ease;
	min-height: 52px;
}
.ais-ratio-item:hover { border-color: var(--ais-text-2); }
.ais-ratio-item.active { background: var(--ais-accent); border-color: var(--ais-accent); }
.ais-ratio-shape { background: var(--ais-border-strong); border-radius: 1.5px; flex-shrink: 0; }
.ais-ratio-item.active .ais-ratio-shape { background: #fff; }
.ais-ratio-label { font-size: 10.5px; color: var(--ais-text-2); }
.ais-ratio-item.active .ais-ratio-label { color: #fff; }
.ais-ratio-item.ais-ratio-auto .ais-ratio-label { font-size: 11px; }

/* ========== 生成张数 ========== */
.ais-count-grid {
	display: grid;
	grid-template-columns: repeat(4, 1fr);
	gap: 6px;
}
.ais-count-item {
	height: 30px;
	width: 100%;
	min-width: 0;
	border: 1px solid var(--ais-border-strong);
	border-radius: var(--ais-radius-pill);
	background: var(--ais-card);
	color: var(--ais-text-2);
	font-size: 11.5px;
	font-family: inherit;
	cursor: pointer;
	transition: all .15s ease;
	padding: 0 4px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
}
.ais-count-item:hover { color: var(--ais-text); }
.ais-count-item.active { background: var(--ais-accent); border-color: var(--ais-accent); color: #fff; }
.ais-count-input {
	height: 30px;
	width: 100%;
	min-width: 0;
	border: 1px solid var(--ais-border-strong);
	border-radius: var(--ais-radius-pill);
	background: var(--ais-card);
	color: var(--ais-text-2);
	font-size: 11.5px;
	font-family: inherit;
	text-align: center;
	outline: none;
	padding: 0 6px;
}
.ais-count-input::placeholder { color: var(--ais-text-3); }
.ais-count-input:focus { border-color: var(--ais-text-2); }

/* ========== 查看区 ========== */
.ais-result-actions { display: flex; align-items: center; gap: 8px; color: var(--ais-text-3); }
.ais-result-actions.disabled { opacity: .4; pointer-events: none; }
.ais-icon-btn {
	width: 26px; height: 26px;
	border: none;
	background: transparent;
	border-radius: var(--ais-radius-sm);
	display: inline-flex;
	align-items: center;
	justify-content: center;
	color: var(--ais-text-2);
	cursor: pointer;
	transition: all .15s ease;
}
.ais-icon-btn:hover { background: var(--ais-card-soft); color: var(--ais-text); }
.ais-icon-btn svg { width: 14px; height: 14px; }

.ais-result-canvas {
	flex: 1;
	display: flex;
	align-items: center;
	justify-content: center;
	min-height: 0;
	position: relative;
}
.ais-result-image-wrap {
	width: 100%;
	height: 100%;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 20px;
}
.ais-result-image {
	max-width: 100%;
	max-height: 100%;
	width: auto;
	height: auto;
	object-fit: contain; /* 居中 + 按比例：宽度随宽高比自适应，绝不变形 */
	border-radius: 8px;
	box-shadow: 0 6px 24px rgba(15, 23, 42, 0.1);
	cursor: zoom-in;
	display: block;
}
.ais-result-empty {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	color: var(--ais-text-3);
	font-size: 12px;
	pointer-events: none;
}

/* ========== 生成结果区 ========== */
.ais-count-badge {
	background: var(--ais-card-soft);
	color: var(--ais-text-2);
	border-radius: var(--ais-radius-pill);
	padding: 2px 8px;
	font-size: 11px;
	font-weight: 500;
	border: 1px solid var(--ais-border);
}
.ais-records-actions {
	display: flex;
	gap: 6px;
	padding: 0 18px 12px;
	flex-shrink: 0;
	flex-wrap: wrap;
}
.ais-records-body {
	flex: 1;
	display: flex;
	flex-direction: column;
	padding: 4px 14px 14px;
	overflow-y: auto;
	min-height: 0;
}
.ais-records-body::-webkit-scrollbar { width: 6px; }
.ais-records-body::-webkit-scrollbar-thumb { background: #e0e3ea; border-radius: 3px; }

.ais-records-loading {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	padding: 10px 12px;
	margin: 4px 0 8px;
	background: var(--ais-card-soft);
	border: 1px solid var(--ais-border);
	border-radius: var(--ais-radius-md);
	color: var(--ais-text-2);
	font-size: 12px;
	flex-shrink: 0;
}
.ais-records-loading .ais-loading-text { color: var(--ais-text-2); }
.ais-records-loading #aisProgressCount { color: var(--ais-text); font-weight: 600; }

.ais-spinner {
	width: 16px; height: 16px;
	border: 2px solid #e8eaef;
	border-top-color: var(--ais-accent);
	border-radius: 50%;
	animation: aisSpin .8s linear infinite;
	flex-shrink: 0;
}
@keyframes aisSpin { to { transform: rotate(360deg); } }

.ais-records-grid {
	display: grid;
	grid-template-columns: repeat(4, 1fr);
	gap: 6px;
	align-content: start;
	padding: 4px 0;
}
.ais-record-card {
	position: relative;
	aspect-ratio: 1 / 1;
	border-radius: 8px;
	overflow: hidden;
	background: var(--ais-card-soft);
	border: 1.5px solid var(--ais-border);
	cursor: pointer;
	transition: all .15s ease;
	animation: aisRecordIn .3s ease;
}
@keyframes aisRecordIn {
	from { opacity: 0; transform: scale(.9); }
	to   { opacity: 1; transform: scale(1); }
}
.ais-record-card:hover {
	border-color: var(--ais-border-strong);
	transform: translateY(-1px);
	box-shadow: 0 4px 10px rgba(15, 23, 42, .08);
}
.ais-record-card.active {
	border-color: var(--ais-accent);
	box-shadow: 0 0 0 2px rgba(15, 23, 42, .12);
}
.ais-record-card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ais-record-card .ais-check {
	position: absolute;
	top: 4px; left: 4px;
	width: 18px; height: 18px;
	border-radius: 50%;
	background: rgba(255,255,255,.95);
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: 0 1px 3px rgba(0,0,0,.15);
	transition: all .15s ease;
	opacity: 0;
}
.ais-record-card:hover .ais-check { opacity: 1; }
.ais-record-card.selected .ais-check { opacity: 1; background: var(--ais-accent); color: #fff; }
.ais-record-card.selected { border-color: var(--ais-accent); }
.ais-record-card .ais-check svg { width: 11px; height: 11px; }
.ais-record-empty {
	flex: 1;
	display: flex;
	align-items: center;
	justify-content: center;
	color: var(--ais-text-3);
	font-size: 12px;
	min-height: 60px;
}

/* ========== 开始生图：固定在左面板最下方 ========== */
/* .ais-cta-wrap 是 .ais-panel-body 的兄弟节点（flex-shrink:0），
   左面板高度固定时它永远钉在面板底部，内容区独立滚动不被遮挡；
   移动端（≤1024px）改为 fixed 屏幕底部通栏，长面板下随时可点。 */
.ais-cta-wrap {
	padding: 14px 18px 16px;
	flex-shrink: 0;
	background: var(--ais-card);
	border-top: 1px solid var(--ais-border);
	position: relative;
	z-index: 2;
	box-shadow: 0 -8px 20px rgba(15, 23, 42, .05);
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 6px;
}
.ais-btn-generate {
	width: 100%;
	height: 44px;
	padding: 0 26px;
	background: var(--ais-accent);
	color: #fff;
	border: 1px solid var(--ais-accent);
	border-radius: var(--ais-radius-md);
	font-family: inherit;
	font-size: 13.5px;
	font-weight: 500;
	cursor: pointer;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	transition: background .15s ease;
	opacity: 1; /* 防御 B2 主题 button:disabled 全局透明度 */
	appearance: none;
	-webkit-appearance: none;
}
.ais-btn-generate:hover:not(:disabled) { background: var(--ais-accent-hover); border-color: var(--ais-accent-hover); }
.ais-btn-generate:disabled {
	background: #e8eaef;
	border-color: #e8eaef;
	color: #9ca3af;
	cursor: not-allowed;
	opacity: 1;
}
.ais-btn-generate svg { width: 15px; height: 15px; }
.ais-btn-generate:disabled svg { opacity: .6; }
.ais-cta-price {
	font-size: 11px;
	color: var(--ais-text-3);
	line-height: 1.4;
	text-align: center;
}
.ais-cta-price:empty { display: none; }

/* ========== 弹窗（看图） ========== */
.ais-modal {
	position: fixed; inset: 0;
	z-index: 100000;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 24px;
	background: rgba(15, 23, 42, .65);
	backdrop-filter: blur(6px);
	animation: aisFadeIn .2s ease;
}
@keyframes aisFadeIn { from { opacity: 0; } to { opacity: 1; } }
.ais-modal-content {
	position: relative;
	max-width: 92vw;
	max-height: 92vh;
	background: #fff;
	border-radius: 14px;
	padding: 12px;
	box-shadow: 0 24px 80px rgba(0,0,0,.4);
}
.ais-modal-content img {
	max-width: 100%;
	max-height: 78vh;
	object-fit: contain;
	display: block;
	border-radius: 6px;
}
.ais-modal-close {
	position: absolute;
	top: -12px; right: -12px;
	width: 32px; height: 32px;
	border-radius: 50%;
	background: #0f172a;
	color: #fff;
	border: none;
	cursor: pointer;
	font-size: 18px;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: 0 4px 12px rgba(0,0,0,.25);
}
.ais-modal-actions {
	display: flex;
	justify-content: center;
	gap: 8px;
	margin-top: 12px;
	padding-top: 12px;
	border-top: 1px solid #eceef3;
}
.ais-modal-actions .ais-btn-ghost { height: 30px; padding: 0 14px; font-size: 12px; }

/* ========== Toast ========== */
.ais-toast {
	position: fixed;
	bottom: 24px;
	left: 50%;
	transform: translateX(-50%);
	background: #0f172a;
	color: #fff;
	padding: 10px 18px;
	border-radius: 8px;
	font-size: 13px;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
	box-shadow: 0 6px 24px rgba(15, 23, 42, .25);
	z-index: 100001;
	animation: aisToastIn .2s ease;
	max-width: 86vw;
	text-align: center;
}
@keyframes aisToastIn {
	from { transform: translate(-50%, 16px); opacity: 0; }
	to   { transform: translate(-50%, 0);    opacity: 1; }
}

/* ========== 响应式 ========== */
@media (max-width: 1024px) {
	.ais-app {
		grid-template-columns: 1fr;
		grid-template-rows: auto auto auto;
		max-width: 760px;
		padding: 16px 16px 96px; /* 底部给 fixed CTA 留位 */
		gap: 14px;
		min-height: 0;
	}
	.ais-panel-left, .ais-panel-middle, .ais-panel-right { grid-column: 1; grid-row: auto; }
	.ais-panel-left   { grid-row: 1; }
	.ais-panel-middle { grid-row: 2; height: 420px; min-height: 0; } /* 定高：图片按比例收进查看区 */
	.ais-panel-right  { grid-row: 3; min-height: 200px; }
	/* 移动端：开始生图固定屏幕底部通栏，长面板滚动时随时可点 */
	.ais-cta-wrap {
		position: fixed;
		left: 0;
		right: 0;
		bottom: 0;
		z-index: 900;
		padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px));
		background: #ffffff;
		border-top: 1px solid #eceef3;
		box-shadow: 0 -8px 20px rgba(15, 23, 42, .08);
	}
	.ais-cta-price { display: none; } /* 底部通栏空间紧张，价格提示省略 */
}

@media (max-width: 720px) {
	.ais-app { padding: 12px 12px 96px; gap: 12px; }
	.ais-panel-middle { height: 320px; }
	.ais-panel-right  { min-height: 160px; }
}

@media (max-width: 480px) {
	.ais-records-grid { grid-template-columns: repeat(3, 1fr); }
}
