/* ========================================
   Layer Box — bottom-docked wide layout
   ======================================== */

.layers-component.wide {
	height: 168px;
	width: 100%;
	min-width: 260px;
	position: relative;
}

/* Resize handle at top edge of layer box */
.layer-box-resize-handle {
	position: absolute;
	top: -4px;
	left: 0;
	right: 0;
	height: 8px;
	cursor: ns-resize;
	z-index: 2;
	-webkit-tap-highlight-color: transparent;
}
.layer-box-resize-handle::after {
	content: "";
	display: block;
	width: 44px;
	height: 5px;
	margin: 1px auto 0;
	background:
		linear-gradient(90deg, ButtonShadow 0 1px, transparent 1px 5px) 0 0 / 6px 5px;
	opacity: 0.75;
}

/* Close button */
.layer-box-close-btn {
	flex: 0 0 auto;
	width: 22px;
	height: 20px;
	border: 1px solid transparent;
	background: ButtonFace;
	font-size: 13px;
	line-height: 1;
	cursor: pointer;
	color: ButtonText;
	padding: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	-webkit-tap-highlight-color: transparent;
}
.layer-box-close-btn:hover,
.layer-box-close-btn:active {
	border-color: ButtonShadow ButtonHighlight ButtonHighlight ButtonShadow;
}

/* Toggle button to re-show the layer panel */
.layer-toggle-btn {
	font-size: 11px;
	padding: 3px 10px;
	margin: 2px 4px;
	cursor: pointer;
	min-height: 24px;
	border: 1px solid ButtonBorder;
	background: ButtonFace;
	color: ButtonText;
	-webkit-tap-highlight-color: transparent;
	flex: 0 0 auto;
}
.layer-toggle-btn:hover,
.layer-toggle-btn:active {
	background: Highlight;
	color: HighlightText;
}

/* Main layer box container */
.layer-box {
	display: flex;
	flex-direction: column;
	min-height: 0;
	flex: 1 1 auto;
	overflow: hidden;
	position: relative;
	width: 100%;
	box-sizing: border-box;
	background: ButtonFace;
	color: ButtonText;
}

.layer-box-header {
	display: flex;
	align-items: center;
	gap: 6px;
	min-height: 25px;
	padding: 2px 4px;
	box-sizing: border-box;
	border-bottom: 1px solid ButtonShadow;
	box-shadow: inset 0 1px ButtonHighlight;
}

.layer-box-title {
	flex: 0 0 auto;
	font-weight: bold;
	font-size: 11px;
	line-height: 16px;
}

.layer-box-summary {
	flex: 1 1 auto;
	min-width: 0;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	font-size: 10px;
	color: GrayText;
}

.layer-box-body {
	display: flex;
	flex: 1 1 auto;
	min-height: 0;
	gap: 4px;
	padding: 3px 4px 4px;
	box-sizing: border-box;
}

.layer-box .layer-main {
	display: flex;
	flex-direction: column;
	flex: 1 1 auto;
	min-width: 0;
	min-height: 0;
	gap: 3px;
	overflow: hidden;
}

/* Left column: opacity + layer list (scrollable) */
.layer-box .layer-opacity-row {
	display: grid;
	grid-template-columns: auto minmax(70px, 1fr) 44px;
	align-items: center;
	gap: 6px;
	padding: 1px 3px;
	font-size: 11px;
	flex: 0 0 auto;
	min-height: 25px;
	box-sizing: border-box;
}

.layer-box .layer-opacity-row label {
	white-space: nowrap;
}

.layer-box .layer-opacity-row input[type="range"] {
	min-width: 40px;
	min-height: 20px;
	width: 100%;
}

.layer-box .layer-opacity-row .opacity-value {
	text-align: right;
	font-size: 10px;
}

.layer-box .layer-list {
	flex: 1 1 auto;
	min-height: 0;
	overflow-y: auto;
	overflow-x: hidden;
	-webkit-overflow-scrolling: touch;
	border: 1px solid ButtonShadow;
	box-shadow:
		inset 1px 1px ButtonShadow,
		inset -1px -1px ButtonHighlight;
	background: Canvas;
	color: CanvasText;
}

.layer-box .layer-row {
	display: grid;
	grid-template-columns: 28px 50px minmax(0, 1fr) 24px;
	align-items: center;
	padding: 4px 6px;
	cursor: pointer;
	gap: 6px;
	border-bottom: 1px solid ButtonFace;
	min-height: 45px;
	user-select: none;
	-webkit-user-select: none;
	touch-action: none;
	position: relative;
	box-sizing: border-box;
	background: Canvas;
}

.layer-box .layer-row:hover {
	background: ButtonFace;
}

.layer-box .layer-row.active {
	background: Highlight;
	color: HighlightText;
}

.layer-box .layer-row:focus {
	outline: 1px dotted CanvasText;
	outline-offset: -4px;
}

.layer-box .layer-row.active:focus {
	outline-color: HighlightText;
}

/* Visual feedback during drag reorder */
.layer-box .layer-row.drag-over-above {
	border-top: 2px solid Highlight;
}
.layer-box .layer-row.drag-over-below {
	border-bottom: 2px solid Highlight;
}
.layer-box .layer-row.dragging {
	opacity: 0.4;
}

/* Visibility toggle */
.layer-box .layer-row .layer-visibility-wrap {
	flex: 0 0 auto;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 28px;
	height: 28px;
	cursor: pointer;
	-webkit-tap-highlight-color: transparent;
}

.layer-box .layer-row .layer-visibility {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	width: 24px;
	height: 24px;
	margin: 0;
	padding: 0;
	border: 1px solid ButtonShadow;
	background: ButtonFace;
	color: ButtonText;
	box-sizing: border-box;
}

.layer-box .layer-row .layer-visibility::before {
	content: "";
	display: block;
	width: 13px;
	height: 8px;
	border: 1px solid currentColor;
	border-radius: 50%;
	box-sizing: border-box;
}

.layer-box .layer-row .layer-visibility::after {
	content: "";
	position: absolute;
	left: 50%;
	top: 50%;
	width: 4px;
	height: 4px;
	border-radius: 50%;
	background: currentColor;
	transform: translate(-50%, -50%);
}

.layer-box .layer-row .layer-visibility:not(.is-visible)::before {
	opacity: 0.45;
}

.layer-box .layer-row .layer-visibility:not(.is-visible)::after {
	width: 16px;
	height: 1px;
	border-radius: 0;
	transform: translate(-50%, -50%) rotate(-35deg);
}

.layer-box .layer-row.active .layer-visibility {
	border-color: HighlightText;
	background: Highlight;
	color: HighlightText;
}

.layer-box .layer-row .layer-thumbnail {
	flex: 0 0 auto;
	width: 48px;
	height: 36px;
	border: 1px solid ButtonShadow;
	background-image:
		linear-gradient(45deg, #ccc 25%, transparent 25%),
		linear-gradient(-45deg, #ccc 25%, transparent 25%),
		linear-gradient(45deg, transparent 75%, #ccc 75%),
		linear-gradient(-45deg, transparent 75%, #ccc 75%);
	background-size: 8px 8px;
	background-position: 0 0, 0 4px, 4px -4px, -4px 0;
	image-rendering: auto;
	box-sizing: border-box;
}

.layer-box .layer-row .layer-info {
	display: flex;
	flex-direction: column;
	gap: 1px;
	min-width: 0;
	overflow: hidden;
}

.layer-box .layer-row .layer-name {
	font-size: 11px;
	font-weight: bold;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	min-width: 0;
	line-height: 1.4;
}

.layer-box .layer-row .layer-meta {
	font-size: 10px;
	line-height: 1.2;
	color: GrayText;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.layer-box .layer-row.active .layer-meta {
	color: HighlightText;
	opacity: 0.78;
}

/* Rename button (replaces double-click) */
.layer-box .layer-row .layer-rename-btn {
	flex: 0 0 auto;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 24px;
	height: 24px;
	cursor: pointer;
	font-size: 12px;
	border: 1px solid transparent;
	background: ButtonFace;
	color: inherit;
	padding: 0;
	-webkit-tap-highlight-color: transparent;
	opacity: 0.5;
}
.layer-box .layer-row .layer-rename-btn:hover,
.layer-box .layer-row .layer-rename-btn:active {
	opacity: 1;
	border-color: ButtonShadow ButtonHighlight ButtonHighlight ButtonShadow;
}
.layer-box .layer-row.active .layer-rename-btn {
	background: Highlight;
	color: HighlightText;
}

.layer-box .layer-row .layer-name-input {
	font-size: 11px;
	border: 1px solid ButtonShadow;
	padding: 2px 4px;
	width: 100%;
	box-sizing: border-box;
	min-height: 24px;
}

/* Action buttons — right side column in wide layout */
.layer-box .layer-actions {
	display: grid;
	grid-template-columns: repeat(2, minmax(38px, 1fr));
	align-content: start;
	gap: 3px;
	padding-left: 4px;
	flex: 0 0 116px;
	border-left: 1px solid ButtonShadow;
}

.layer-box .layer-actions .layer-action-btn {
	display: grid;
	grid-template-columns: 15px minmax(0, 1fr);
	align-items: center;
	gap: 3px;
	font-size: 10px;
	padding: 2px 4px;
	min-width: 0;
	min-height: 24px;
	white-space: nowrap;
	box-sizing: border-box;
	text-align: left;
}

.layer-box .layer-actions .layer-action-glyph {
	display: flex;
	align-items: center;
	justify-content: center;
	font-weight: bold;
	line-height: 1;
}

.layer-box .layer-actions .layer-action-label {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.layer-box .layer-actions .layer-action-btn:disabled .layer-action-glyph,
.layer-box .layer-actions .layer-action-btn:disabled .layer-action-label {
	color: GrayText;
}

@media (max-width: 640px) {
	.layer-box .layer-actions {
		grid-template-columns: repeat(2, 26px);
		flex-basis: 58px;
		justify-content: center;
	}

	.layer-box .layer-actions .layer-action-btn {
		grid-template-columns: 1fr;
		justify-items: center;
		padding: 2px;
	}

	.layer-box .layer-actions .layer-action-label {
		display: none;
	}

	.layer-box .layer-row {
		grid-template-columns: 28px 42px minmax(0, 1fr) 24px;
	}

	.layer-box .layer-row .layer-thumbnail {
		width: 40px;
		height: 30px;
	}
}

/* ========================================
   Touch device enhancements
   ======================================== */

@media (pointer: coarse) {
	.layer-box-close-btn {
		width: 40px;
		height: 34px;
		font-size: 20px;
	}

	.layer-box-resize-handle {
		top: -8px;
		height: 16px;
	}
	.layer-box-resize-handle::after {
		width: 50px;
		height: 5px;
		margin-top: 5px;
	}

	.layer-toggle-btn {
		font-size: 14px;
		padding: 8px 14px;
		min-height: 36px;
	}

	.layer-box .layer-row {
		grid-template-columns: 40px 58px minmax(0, 1fr) 40px;
		min-height: 56px;
		padding: 4px 8px;
		gap: 8px;
	}

	.layer-box .layer-row .layer-visibility-wrap {
		width: 40px;
		height: 40px;
	}

	.layer-box .layer-row .layer-visibility {
		width: 32px;
		height: 32px;
	}

	.layer-box .layer-row .layer-thumbnail {
		width: 56px;
		height: 42px;
	}

	.layer-box .layer-row .layer-name {
		font-size: 13px;
	}

	.layer-box .layer-row .layer-meta {
		font-size: 11px;
	}

	.layer-box .layer-row .layer-rename-btn {
		width: 40px;
		height: 40px;
		font-size: 16px;
		opacity: 0.7;
	}

	.layer-box .layer-actions {
		flex-basis: 130px;
		gap: 4px;
	}

	.layer-box .layer-actions .layer-action-btn {
		font-size: 12px;
		padding: 4px 8px;
		min-height: 36px;
	}

	.layer-box .layer-opacity-row {
		min-height: 36px;
		padding: 4px 8px;
	}

	.layer-box .layer-opacity-row input[type="range"] {
		min-height: 28px;
	}

	.layers-component.wide {
		height: 210px;
	}
}

/* ========================================
   Enlarge UI mode
   ======================================== */

.enlarge-ui .layers-component.wide {
	height: 230px;
}

.enlarge-ui .layer-box .layer-row {
	grid-template-columns: 44px 66px minmax(0, 1fr) 44px;
	min-height: 64px;
	padding: 6px 10px;
	gap: 10px;
}

.enlarge-ui .layer-box .layer-row .layer-visibility-wrap {
	width: 44px;
	height: 44px;
}

.enlarge-ui .layer-box .layer-row .layer-visibility {
	width: 34px;
	height: 34px;
}

.enlarge-ui .layer-box .layer-row .layer-thumbnail {
	width: 64px;
	height: 48px;
}

.enlarge-ui .layer-box .layer-row .layer-name {
	font-size: 1rem;
}

.enlarge-ui .layer-box .layer-row .layer-meta {
	font-size: 0.85rem;
}

.enlarge-ui .layer-box .layer-row .layer-rename-btn {
	width: 44px;
	height: 44px;
	font-size: 1.2rem;
}

.enlarge-ui .layer-box .layer-row .layer-name-input {
	font-size: 1rem;
	min-height: 32px;
}

.enlarge-ui .layer-box .layer-actions {
	flex-basis: 152px;
}

.enlarge-ui .layer-box .layer-actions .layer-action-btn {
	font-size: 1rem;
	padding: 6px 10px;
	min-height: 40px;
}

.enlarge-ui .layer-box .layer-opacity-row {
	min-height: 40px;
	font-size: 1rem;
	padding: 6px 10px;
}

.enlarge-ui .layer-box .layer-opacity-row input[type="range"] {
	min-height: 28px;
}

.enlarge-ui .layer-box .layer-opacity-row .opacity-value {
	font-size: 0.9rem;
	width: 40px;
}
