/* Редактор изображений — в стиле темы Admin-Lic. Всё изолировано в .aie-app */

.aie-root {
	--aie-card: #252a35;
	--aie-card-2: #2a303c;
	--aie-line: rgba(255, 255, 255, .075);
	--aie-line-2: rgba(255, 255, 255, .12);
	--aie-text: #e3e6ed;
	--aie-muted: #949bab;
	--aie-faint: #6f7686;
	--aie-amber: #845adf;
	--aie-amber-2: #9e7bea;
	--aie-amber-ink: #ffffff;
	--aie-amber-soft: rgba(132, 90, 223, .12);
	--aie-green: #34d399;
	--aie-green-soft: rgba(52, 211, 153, .12);
	--aie-red: #f87171;
	--aie-red-soft: rgba(248, 113, 113, .13);
	--aie-blue: #60a5fa;
	--aie-blue-soft: rgba(96, 165, 250, .12);
	--aie-violet: #a78bfa;
	--aie-violet-soft: rgba(167, 139, 250, .12);
	--aie-well: rgba(0, 0, 0, .2);
	--aie-shadow: 0 1px 0 rgba(255, 255, 255, .03) inset, 0 18px 40px -24px rgba(0, 0, 0, .7);

	display: block;
	max-width: 100%;
	color: var(--aie-text);
	font-family: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
	font-size: 14px;
	line-height: 1.45;
}

html[data-theme="light"] .aie-root {
	--aie-card: #ffffff;
	--aie-card-2: #f9fafc;
	--aie-line: rgba(15, 23, 42, .08);
	--aie-line-2: rgba(15, 23, 42, .14);
	--aie-text: #232a3b;
	--aie-muted: #737985;
	--aie-faint: #98a2b3;
	--aie-amber: #7448d4;
	--aie-amber-2: #845adf;
	--aie-amber-soft: rgba(132, 90, 223, .12);
	--aie-well: rgba(15, 23, 42, .04);
	--aie-shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 12px 32px -20px rgba(15, 23, 42, .25);
}

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

.aie-app {
	outline: none;
}

.aie-app svg {
	width: 16px;
	height: 16px;
	flex: none;
	display: block;
}

.aie-app h1,
.aie-app h2,
.aie-app h3,
.aie-app p {
	margin: 0;
	padding: 0;
	letter-spacing: normal;
	text-transform: none;
}

.aie-app [hidden] {
	display: none !important;
}

.aie-sr-only {
	position: absolute !important;
	width: 1px !important;
	height: 1px !important;
	overflow: hidden !important;
	clip: rect(0 0 0 0) !important;
	white-space: nowrap !important;
	border: 0 !important;
	padding: 0 !important;
	margin: -1px !important;
}

/* ---------- Шапка ---------- */
.aie-head {
	display: flex;
	align-items: flex-end;
	justify-content: space-between;
	gap: 16px;
	flex-wrap: wrap;
	margin-bottom: 16px;
}

.aie-eyebrow {
	color: var(--aie-amber);
	font-size: 11px;
	font-weight: 800;
	letter-spacing: .14em;
	text-transform: uppercase;
	margin-bottom: 4px;
}

.aie-app .aie-title {
	font-size: clamp(22px, 2.4vw, 28px);
	font-weight: 800;
	line-height: 1.15;
	color: var(--aie-text);
	font-family: inherit;
}

.aie-app .aie-sub {
	color: var(--aie-muted);
	margin-top: 6px;
	max-width: 680px;
}

.aie-head-actions {
	display: flex;
	align-items: center;
	gap: 10px;
	flex-wrap: wrap;
}

.aie-pill {
	display: inline-flex;
	align-items: center;
	gap: 7px;
	padding: 7px 12px;
	border-radius: 999px;
	font-size: 12px;
	font-weight: 600;
	color: var(--aie-green);
	background: var(--aie-green-soft);
	border: 1px solid rgba(52, 211, 153, .22);
}

.aie-pill svg {
	width: 14px;
	height: 14px;
}

/* ---------- Кнопки ---------- */
.aie-app button {
	font: inherit;
	margin: 0;
	text-transform: none;
	letter-spacing: normal;
	box-shadow: none;
	min-height: 0;
	line-height: 1.2;
}

.aie-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	height: 40px;
	padding: 0 16px;
	border-radius: 11px;
	border: 1px solid var(--aie-line-2);
	background: var(--aie-card-2);
	color: var(--aie-text);
	font-weight: 700;
	font-size: 13.5px;
	cursor: pointer;
	white-space: nowrap;
	transition: background .15s, border-color .15s, transform .1s, opacity .15s;
}

.aie-btn:hover:not(:disabled) {
	border-color: rgba(132, 90, 223, .45);
	background: var(--aie-amber-soft);
}

.aie-btn:active:not(:disabled) {
	transform: translateY(1px);
}

.aie-btn:disabled,
.aie-icon-btn:disabled {
	opacity: .42;
	cursor: not-allowed;
}

.aie-btn--primary {
	background: linear-gradient(180deg, var(--aie-amber-2), var(--aie-amber));
	border-color: transparent;
	color: var(--aie-amber-ink);
	box-shadow: 0 8px 22px -10px rgba(132, 90, 223, .7);
}

.aie-btn--primary:hover:not(:disabled) {
	background: linear-gradient(180deg, #a988f0, var(--aie-amber-2));
	border-color: transparent;
}

.aie-btn--ghost {
	background: transparent;
}

.aie-btn--sm {
	height: 34px;
	padding: 0 12px;
	font-size: 12.5px;
	border-radius: 10px;
}

.aie-btn--block {
	width: 100%;
	height: 46px;
	margin-top: 4px;
}

.aie-icon-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 34px;
	height: 34px;
	padding: 0;
	border-radius: 10px;
	border: 1px solid var(--aie-line-2);
	background: var(--aie-card-2);
	color: var(--aie-text);
	cursor: pointer;
	transition: border-color .15s, color .15s, background .15s;
}

.aie-icon-btn:hover:not(:disabled) {
	color: var(--aie-amber);
	border-color: rgba(132, 90, 223, .45);
}

.aie-app button:focus-visible,
.aie-app input:focus-visible,
.aie-app select:focus-visible,
.aie-cropbox:focus-visible {
	outline: 2px solid var(--aie-amber);
	outline-offset: 2px;
}

/* ---------- Карточки ---------- */
.aie-card {
	background: linear-gradient(180deg, var(--aie-card-2), var(--aie-card));
	border: 1px solid var(--aie-line);
	border-radius: 16px;
	box-shadow: var(--aie-shadow);
	padding: 20px;
	min-width: 0;
}

.aie-card-head {
	margin-bottom: 14px;
}

.aie-app .aie-card-head h3 {
	font-size: 16px;
	font-weight: 800;
	color: var(--aie-text);
	font-family: inherit;
	line-height: 1.3;
}

.aie-app .aie-card-head p {
	font-size: 12.5px;
	color: var(--aie-muted);
	margin-top: 3px;
}

/* ---------- Загрузка ---------- */
.aie-upload {
	padding: 10px;
}

.aie-drop {
	display: flex;
	flex-direction: column;
	align-items: center;
	text-align: center;
	gap: 14px;
	padding: 44px 20px 28px;
	border-radius: 12px;
	border: 1.5px dashed var(--aie-line-2);
	background: radial-gradient(600px 220px at 50% 0%, rgba(167, 139, 250, .1), transparent 70%);
	transition: border-color .2s, background-color .2s;
}

.aie-drop.is-over {
	border-color: var(--aie-amber);
	background-color: var(--aie-amber-soft);
}

.aie-drop-icon {
	width: 60px;
	height: 60px;
	border-radius: 18px;
	display: grid;
	place-items: center;
	color: var(--aie-violet);
	background: var(--aie-violet-soft);
	border: 1px solid rgba(167, 139, 250, .3);
	box-shadow: 0 0 40px -6px rgba(167, 139, 250, .5);
}

.aie-drop-icon svg {
	width: 26px;
	height: 26px;
}

.aie-drop-text {
	display: flex;
	flex-direction: column;
	gap: 4px;
}

.aie-drop-text strong {
	font-size: 17px;
	font-weight: 800;
}

.aie-drop-text span {
	color: var(--aie-muted);
	font-size: 13px;
}

.aie-drop-actions {
	display: flex;
	gap: 10px;
	flex-wrap: wrap;
	justify-content: center;
}

.aie-file {
	display: inline-flex;
	align-items: center;
	gap: 10px;
	max-width: 100%;
	padding: 8px 14px;
	border-radius: 10px;
	background: var(--aie-card-2);
	border: 1px solid var(--aie-line-2);
}

.aie-file-name {
	font-weight: 700;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	min-width: 0;
}

.aie-file-meta {
	color: var(--aie-muted);
	font-size: 12px;
	flex: none;
}

.aie-formats {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	justify-content: center;
}

.aie-formats span {
	font: 600 10.5px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
	padding: 5px 8px;
	border-radius: 6px;
	color: var(--aie-muted);
	border: 1px solid var(--aie-line);
	background: rgba(255, 255, 255, .02);
}

.aie-limits {
	color: var(--aie-faint);
	font-size: 12px;
}

.aie-banner {
	display: flex;
	align-items: flex-start;
	gap: 10px;
	padding: 12px 14px;
	border-radius: 12px;
	color: var(--aie-red);
	background: var(--aie-red-soft);
	border: 1px solid rgba(248, 113, 113, .35);
	font-size: 13px;
	font-weight: 600;
	text-align: left;
	max-width: 620px;
}

.aie-banner svg {
	margin-top: 2px;
}

/* ---------- KPI ---------- */
.aie-kpis {
	display: grid;
	grid-template-columns: repeat(4, minmax(0, 1fr));
	gap: 14px;
	margin-bottom: 16px;
}

.aie-kpi {
	--tone: var(--aie-amber);
	--tone-soft: var(--aie-amber-soft);
	display: flex;
	gap: 14px;
	align-items: flex-start;
	padding: 16px 16px 16px 18px;
	border-radius: 14px;
	border: 1px solid var(--aie-line);
	background: linear-gradient(180deg, var(--aie-card-2), var(--aie-card));
	box-shadow: inset 2px 0 0 var(--tone), var(--aie-shadow);
	min-width: 0;
}

.aie-kpi--blue { --tone: var(--aie-blue); --tone-soft: var(--aie-blue-soft); }
.aie-kpi--green { --tone: var(--aie-green); --tone-soft: var(--aie-green-soft); }
.aie-kpi--violet { --tone: var(--aie-violet); --tone-soft: var(--aie-violet-soft); }

.aie-kpi-ic {
	width: 36px;
	height: 36px;
	border-radius: 10px;
	display: grid;
	place-items: center;
	color: var(--tone);
	background: var(--tone-soft);
	flex: none;
}

.aie-kpi-body {
	display: flex;
	flex-direction: column;
	min-width: 0;
}

.aie-kpi-body span {
	font-size: 12px;
	color: var(--aie-muted);
	font-weight: 600;
}

.aie-kpi-body b {
	font-size: 20px;
	font-weight: 800;
	line-height: 1.3;
	font-variant-numeric: tabular-nums;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.aie-kpi-body small {
	font-size: 11.5px;
	color: var(--aie-muted);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

/* ---------- Рабочая область ---------- */
.aie-layout {
	display: grid;
	grid-template-columns: minmax(0, 1fr) 360px;
	gap: 16px;
	align-items: start;
}

.aie-side {
	display: flex;
	flex-direction: column;
	gap: 16px;
	min-width: 0;
}

.aie-toolbar {
	display: flex;
	align-items: flex-end;
	justify-content: space-between;
	gap: 12px;
	flex-wrap: wrap;
	margin-bottom: 14px;
}

.aie-tgroup {
	display: flex;
	align-items: center;
	gap: 8px;
	flex-wrap: wrap;
}

.aie-stage {
	display: flex;
	justify-content: center;
	align-items: center;
	min-height: 260px;
	padding: 18px;
	border-radius: 12px;
	border: 1px solid var(--aie-line);
	/* шахматка — видно прозрачные области */
	background:
		conic-gradient(rgba(255, 255, 255, .05) 25%, transparent 0 50%, rgba(255, 255, 255, .05) 0 75%, transparent 0) 0 0 / 20px 20px,
		var(--aie-well);
	overflow: hidden;
}

.aie-wrap {
	position: relative;
	flex: none;
	touch-action: none;
	cursor: crosshair;
	user-select: none;
	-webkit-user-select: none;
}

.aie-view {
	display: block;
}

.aie-cropbox {
	position: absolute;
	box-shadow: 0 0 0 9999px rgba(5, 8, 12, .62);
	outline: 1.5px solid var(--aie-amber);
	cursor: move;
}

.aie-grid {
	position: absolute;
	inset: 0;
	pointer-events: none;
	background:
		linear-gradient(90deg, transparent calc(33.333% - .5px), rgba(255, 255, 255, .35) calc(33.333% - .5px) calc(33.333% + .5px), transparent calc(33.333% + .5px) calc(66.666% - .5px), rgba(255, 255, 255, .35) calc(66.666% - .5px) calc(66.666% + .5px), transparent calc(66.666% + .5px)),
		linear-gradient(transparent calc(33.333% - .5px), rgba(255, 255, 255, .35) calc(33.333% - .5px) calc(33.333% + .5px), transparent calc(33.333% + .5px) calc(66.666% - .5px), rgba(255, 255, 255, .35) calc(66.666% - .5px) calc(66.666% + .5px), transparent calc(66.666% + .5px));
	opacity: 0;
	transition: opacity .15s;
}

.aie-cropbox:hover .aie-grid,
.is-dragging .aie-grid {
	opacity: 1;
}

.aie-h {
	position: absolute;
	width: 14px;
	height: 14px;
	margin: -7px 0 0 -7px;
	border-radius: 4px;
	background: var(--aie-amber);
	border: 2px solid #1b1f27;
	z-index: 2;
}

.aie-h-nw { left: 0; top: 0; cursor: nwse-resize; }
.aie-h-n { left: 50%; top: 0; cursor: ns-resize; }
.aie-h-ne { left: 100%; top: 0; cursor: nesw-resize; }
.aie-h-e { left: 100%; top: 50%; cursor: ew-resize; }
.aie-h-se { left: 100%; top: 100%; cursor: nwse-resize; }
.aie-h-s { left: 50%; top: 100%; cursor: ns-resize; }
.aie-h-sw { left: 0; top: 100%; cursor: nesw-resize; }
.aie-h-w { left: 0; top: 50%; cursor: ew-resize; }

.aie-boxlabel {
	position: absolute;
	left: 50%;
	bottom: 8px;
	transform: translateX(-50%);
	padding: 3px 8px;
	border-radius: 6px;
	font: 700 11px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
	font-style: normal;
	color: var(--aie-amber-ink);
	background: var(--aie-amber);
	white-space: nowrap;
	pointer-events: none;
}

.aie-cropfields {
	display: grid;
	grid-template-columns: repeat(4, minmax(0, 1fr));
	gap: 10px;
	margin-top: 14px;
}

.aie-hint {
	margin-top: 10px;
	font-size: 11.5px;
	color: var(--aie-faint);
}

/* ---------- Поля ---------- */
.aie-field {
	display: flex;
	flex-direction: column;
	gap: 6px;
	margin: 0 0 12px;
	min-width: 0;
}

.aie-field--inline {
	margin: 0;
	min-width: 220px;
}

.aie-cropfields .aie-field,
.aie-wh .aie-field {
	margin: 0;
}

.aie-field > span {
	font-size: 11.5px;
	font-weight: 700;
	color: var(--aie-muted);
}

.aie-field > span b {
	color: var(--aie-amber);
}

.aie-app .aie-field input:not([type="range"]),
.aie-app .aie-field select,
.aie-app .aie-dpi input {
	width: 100%;
	height: 40px;
	padding: 0 12px;
	margin: 0;
	border-radius: 10px;
	border: 1px solid var(--aie-line-2);
	background-color: var(--aie-well);
	color: var(--aie-text);
	font-family: inherit;
	font-size: 13px;
	font-weight: 600;
	box-shadow: none;
}

html[data-theme="light"] .aie-app .aie-field input:not([type="range"]),
html[data-theme="light"] .aie-app .aie-field select,
html[data-theme="light"] .aie-app .aie-dpi input {
	background-color: #fff;
}

.aie-app .aie-field select option,
.aie-app .aie-field select optgroup {
	background: var(--aie-card);
	color: var(--aie-text);
}

.aie-orient {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 4px;
	padding: 4px;
	margin-bottom: 12px;
	border-radius: 12px;
	background: var(--aie-well);
	border: 1px solid var(--aie-line);
}

.aie-app .aie-orient button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	height: 36px;
	border: 0;
	border-radius: 9px;
	background: transparent;
	color: var(--aie-muted);
	font-weight: 700;
	font-size: 13px;
	cursor: pointer;
}

.aie-app .aie-orient button.is-active {
	color: var(--aie-amber-ink);
	background: linear-gradient(180deg, var(--aie-amber-2), var(--aie-amber));
}

.aie-wh {
	display: grid;
	grid-template-columns: 1fr auto 1fr;
	align-items: end;
	gap: 8px;
	margin-bottom: 12px;
}

.aie-chain {
	height: 40px;
	width: 36px;
}

.aie-chain.is-on {
	color: var(--aie-amber);
	border-color: rgba(132, 90, 223, .5);
	background: var(--aie-amber-soft);
}

.aie-bgrow {
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.aie-color,
.aie-check {
	display: flex;
	align-items: center;
	gap: 10px;
	margin: 0;
	font-size: 13px;
	color: var(--aie-muted);
	cursor: pointer;
}

.aie-color input {
	width: 34px;
	height: 28px;
	padding: 0;
	border: 1px solid var(--aie-line-2);
	border-radius: 7px;
	background: none;
	cursor: pointer;
}

.aie-check input {
	width: 16px;
	height: 16px;
	accent-color: var(--aie-amber);
}

.aie-check.is-disabled {
	opacity: .45;
}

.aie-warn {
	margin-top: 12px !important;
	padding: 10px 12px;
	border-radius: 10px;
	font-size: 12.5px;
	color: var(--aie-amber);
	background: var(--aie-amber-soft);
	border: 1px solid rgba(132, 90, 223, .3);
}

.aie-dpi {
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.aie-app .aie-dpi input {
	font-size: 20px;
	font-weight: 800;
	height: 46px;
}

.aie-chips {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
}

.aie-app .aie-chips button {
	padding: 6px 10px;
	border-radius: 8px;
	border: 1px solid var(--aie-line-2);
	background: transparent;
	color: var(--aie-muted);
	font: 700 12px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
	cursor: pointer;
}

.aie-app .aie-chips button:hover,
.aie-app .aie-chips button.is-active {
	color: var(--aie-amber);
	border-color: rgba(132, 90, 223, .5);
	background: var(--aie-amber-soft);
}

.aie-note {
	margin-top: 10px !important;
	font-size: 12.5px;
	color: var(--aie-muted);
}

.aie-note:empty {
	display: none;
}

.aie-preview {
	display: grid;
	place-items: center;
	min-height: 140px;
	padding: 12px;
	margin-bottom: 14px;
	border-radius: 12px;
	border: 1px solid var(--aie-line);
	background:
		conic-gradient(rgba(255, 255, 255, .06) 25%, transparent 0 50%, rgba(255, 255, 255, .06) 0 75%, transparent 0) 0 0 / 16px 16px,
		var(--aie-well);
}

.aie-preview canvas {
	display: block;
	max-width: 100%;
	max-height: 260px;
	box-shadow: 0 6px 20px -8px rgba(0, 0, 0, .7);
}

.aie-app input.aie-range {
	-webkit-appearance: none;
	appearance: none;
	width: 100%;
	height: 4px;
	margin: 8px 0;
	padding: 0;
	border: 0;
	border-radius: 99px;
	background: var(--aie-line-2);
	cursor: pointer;
}

.aie-app input.aie-range::-webkit-slider-thumb {
	-webkit-appearance: none;
	width: 16px;
	height: 16px;
	border-radius: 50%;
	background: var(--aie-amber);
	border: 2px solid var(--aie-card);
	box-shadow: 0 0 0 1px var(--aie-amber);
}

.aie-app input.aie-range::-moz-range-thumb {
	width: 14px;
	height: 14px;
	border-radius: 50%;
	background: var(--aie-amber);
	border: 2px solid var(--aie-card);
}

.aie-result {
	margin-top: 10px !important;
	font-size: 12.5px;
	font-weight: 700;
	color: var(--aie-green);
}

.aie-result:empty {
	display: none;
}

/* ---------- Тост ---------- */
.aie-toast {
	position: fixed;
	left: 50%;
	bottom: 24px;
	z-index: 100002;
	max-width: min(620px, calc(100vw - 32px));
	padding: 12px 16px;
	border-radius: 12px;
	font-weight: 700;
	font-size: 13px;
	color: var(--aie-text);
	background: var(--aie-card-2);
	border: 1px solid var(--aie-line-2);
	box-shadow: 0 18px 40px -12px rgba(0, 0, 0, .6);
	transform: translate(-50%, 20px);
	opacity: 0;
	pointer-events: none;
	transition: opacity .2s, transform .2s;
}

.aie-toast.is-show {
	opacity: 1;
	transform: translate(-50%, 0);
}

.aie-toast.is-ok {
	border-color: rgba(52, 211, 153, .45);
}

.aie-toast.is-error {
	border-color: rgba(248, 113, 113, .55);
	color: var(--aie-red);
}

/* ---------- Адаптив ---------- */
@media (max-width: 1100px) {
	.aie-kpis {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}

	.aie-layout {
		grid-template-columns: minmax(0, 1fr);
	}
}

@media (max-width: 640px) {
	.aie-card {
		padding: 16px;
	}

	.aie-kpi {
		padding: 12px;
		gap: 10px;
	}

	.aie-kpi-ic {
		display: none;
	}

	.aie-kpi-body b {
		font-size: 16px;
	}

	.aie-stage {
		padding: 10px;
	}

	.aie-cropfields {
		grid-template-columns: 1fr 1fr;
	}

	.aie-field--inline {
		min-width: 0;
		width: 100%;
	}

	.aie-h {
		width: 20px;
		height: 20px;
		margin: -10px 0 0 -10px;
	}
}

@media (prefers-reduced-motion: reduce) {
	.aie-app *,
	.aie-app *::before,
	.aie-app *::after {
		transition: none !important;
	}
}
