/* drawer.css - Reusable Bottom / Side Drawer.
   Modes: .ii-drawer--bottom (full-width, slides up) or .ii-drawer--side (sidebar-width, anchored right).
   Height via --ii-drawer-height (default 65vh). z-index: backdrop 5999, drawer 6000. */

/* CSS Custom Property defaults */
:root {
	--ii-drawer-height: 65vh;
	--ii-drawer-min-height: 80vh;
	--ii-drawer-min-height: 80svh;
	--ii-drawer-radius: 20px 20px 0 0;
	--ii-drawer-side-width: var(--ii-sidebar-width, 288px);
	--ii-drawer-transition: transform 0.38s cubic-bezier(0.32, 0.72, 0, 1);
	--ii-drawer-header-h: 56px;
	--ii-drawer-footer-h: 64px;
}

/* Backdrop */
.ii-drawer-backdrop {
	position: fixed;
	inset: 0;
	z-index: 5999;
	background: rgba(0, 0, 0, 0);
	pointer-events: none;
	transition: background 0.3s ease;
}

.ii-drawer-backdrop.is-visible {
	pointer-events: auto;
	background: rgba(0, 0, 0, 0.38);
	backdrop-filter: blur(8px);
	-webkit-backdrop-filter: blur(8px);
}

/* Drawer Shell - shared */
.ii-drawer {
	position: fixed;
	z-index: 6000;
	display: flex;
	flex-direction: column;
	background: var(--ii-surface-white, #fff);
	backface-visibility: hidden;
	transition:
		var(--ii-drawer-transition),
		visibility 0s linear 0.38s;
	visibility: hidden;
}

.ii-drawer.is-open {
	visibility: visible;
	transition:
		var(--ii-drawer-transition),
		visibility 0s linear 0s;
}

/* Bottom placement */
.ii-drawer--bottom {
	left: 0;
	right: 0;
	bottom: 0;

	height: var(--ii-drawer-height);
	min-height: var(--ii-drawer-min-height);
	max-height: 90vh;

	border-radius: var(--ii-drawer-radius);
	border-top: 1px solid var(--ii-border, #e5e7eb);
	box-shadow:
		0 -8px 40px -4px rgba(0, 0, 0, 0.13),
		0 -2px 8px rgba(0, 0, 0, 0.06);

	transform: translateY(100%);
}

.ii-drawer--bottom.is-open {
	transform: translateY(0);
}

/* Side placement (anchored to right edge of the sidebar) */
.ii-drawer--side {
	top: var(--header-sidebar-height, 3rem);
	left: var(--ii-drawer-side-width);
	bottom: 0;
	width: 320px;
	min-width: 280px;
	max-width: 380px;

	border-left: 1px solid var(--ii-border, #e5e7eb);
	border-top: none;
	border-radius: 0;
	box-shadow: 4px 0 32px rgba(0, 0, 0, 0.08);

	transform: translateX(-120%);
}

.ii-drawer--side.is-open {
	transform: translateX(0);
}

/* Drag handle (bottom only) */
.ii-drawer-handle {
	flex-shrink: 0;
	cursor: grab;
	padding: 12px 24px;
	box-sizing: content-box;
	background-clip: content-box;
	touch-action: none;
}

.ii-drawer-handle__line {
	display: block;
	width: 40px;
	height: 4px;
	background-color: var(--ii-bg-active, #d1d5db);
	margin: 0 auto;
	border-radius: 2px;
}

.ii-drawer-handle:hover .ii-drawer-handle__line {
	background-clip: content-box;
}

.ii-drawer-handle:active {
	cursor: grabbing;
}

/* Header */
.ii-drawer-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	flex-shrink: 0;
	height: var(--ii-drawer-header-h);
	padding: 0 18px;
	border-bottom: 1px solid var(--ii-border, #e5e7eb);
}

.ii-drawer-title-group {
	display: flex;
	flex-direction: column;
	gap: 1px;
	min-width: 0;
	flex: 1;
}

.ii-drawer-title {
	font-size: 14px;
	font-weight: 600;
	color: var(--ii-text-primary, #111827);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	line-height: 1.3;
	letter-spacing: -0.01em;
}

.ii-drawer-title--icon {
	display: flex;
	align-items: center;
	gap: 8px;
}

.ii-drawer-subtitle {
	color: var(--ii-text-tertiary, #9ca3af);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

/* Close button */
.ii-drawer-close-btn {
	flex-shrink: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 30px;
	height: 30px;
	border-radius: var(--ii-radius-sm);
	border: none;
	background: transparent;
	color: var(--ii-text-tertiary, #9ca3af);
	transition:
		background 0.15s ease,
		color 0.15s ease;
	outline: none;
	margin-left: auto;
}

.ii-drawer-close-btn:hover {
	background: var(--ii-bg-hover, #f3f4f6);
	color: var(--ii-text-primary, #111827);
}

.ii-drawer-close-btn:focus-visible {
	box-shadow: 0 0 0 2px var(--ii-accent-dim, rgba(37, 99, 235, 0.2));
}

.ii-drawer-close-btn svg {
	width: 16px;
	height: 16px;
}

/* Body */
.ii-drawer-body {
	flex: 1;
	overflow-y: auto;
	overflow-x: hidden;
	min-height: 0;
	overscroll-behavior: contain;
	-webkit-overflow-scrolling: touch;
}

@supports (-moz-appearance: none) {
	.ii-drawer-body {
		scrollbar-width: thin;
		scrollbar-color: var(--ii-bg-active, #d1d5db) transparent;
	}
}

.ii-drawer-body::-webkit-scrollbar {
	width: 4px;
}

.ii-drawer-body::-webkit-scrollbar-thumb {
	background: var(--ii-bg-active, #d1d5db);
	border-radius: 2px;
}

/* Footer (action bar) */
.ii-drawer-footer {
	flex-shrink: 0;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	padding: 12px 18px;
	padding-bottom: max(12px, env(safe-area-inset-bottom));
	border-top: 1px solid var(--ii-border, #e5e7eb);
	background: var(--ii-surface-white, #fff);
	min-height: var(--ii-drawer-footer-h);
}

.ii-drawer-footer:empty {
	display: none;
}

/* Selection count badge (footer) */
.ii-drawer-count-badge {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 22px;
	height: 22px;
	padding: 0 6px;
	border-radius: 11px;
	font-size: 11px;
	font-weight: 700;
	line-height: 1;
	background: var(--ii-accent-dim, rgba(37, 99, 235, 0.08));
	color: var(--ii-accent, #2563eb);
	border: 1px solid rgba(37, 99, 235, 0.18);
	transition:
		background 0.15s,
		color 0.15s;
}

.ii-drawer-count-badge.has-selection {
	background: var(--ii-accent, #2563eb);
	color: #fff;
	border-color: transparent;
}

/* Loading state */
.ii-drawer-loading {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 12px;
	padding: 48px 24px;
	min-height: 180px;
}

.ii-drawer-loading-dots {
	display: flex;
	gap: 6px;
}

.ii-drawer-loading-msg {
	font-size: 13px;
	color: var(--ii-text-tertiary);
}

/* Error state */
.ii-drawer-error {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 12px;
	padding: 40px 24px;
	text-align: center;
}

.ii-drawer-error p {
	font-size: 13.5px;
	color: var(--ii-error-text, #b91c1c);
	margin: 0;
}

.ii-drawer-retry-btn {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 8px 18px;
	border-radius: 8px;
	border: 1px solid var(--ii-retry-border);
	background: var(--ii-retry-bg);
	color: var(--ii-retry-color);
	font-size: 13px;
	font-weight: 600;
	cursor: pointer;
	font-family: var(--ii-font-body, Inter, sans-serif);
	transition: all 0.2s ease;
}

.ii-drawer-retry-btn:hover {
	background: var(--ii-retry-hover-bg);
	border-color: var(--ii-retry-hover-border);
}

/* Asset card */
.ii-drawer-asset-card {
	position: relative;
	border-radius: 10px;
	border: 2px solid var(--ii-border, #e5e7eb);
	background: var(--ii-bg-secondary, #f9fafb);
	cursor: pointer;
	overflow: hidden;
	transition:
		border-color 0.16s ease,
		transform 0.14s ease,
		box-shadow 0.16s ease;
	-webkit-tap-highlight-color: transparent;
	touch-action: manipulation;
}

.ii-drawer-asset-card:hover {
	transform: translateY(-1px);
	box-shadow: 0 3px 12px rgba(0, 0, 0, 0.07);
}

/* On touch devices, remove all hover-triggered visual changes so iOS fires
   the click on the first tap instead of treating it as a hover activation. */
@media (hover: none) and (pointer: coarse) {
	.ii-drawer-asset-card:hover {
		transform: none;
		box-shadow: none;
		border-color: var(--ii-border, #e5e7eb);
	}
}

.ii-drawer-asset-card.is-selected {
	background: var(--ii-primary-tinted, #f0f4ff);
	box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.ii-drawer-asset-card .ii-asset-view-btn {
	width: 28px;
	height: 28px;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: 2rem;
	background: var(--ii-bg-transparent);
	border: 1px solid rgba(255, 255, 255, 0.1);
	backdrop-filter: blur(4px);
	-webkit-backdrop-filter: blur(4px);
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
	color: #f0f1f5;
	opacity: 0;
	cursor: pointer;
	transition: all var(--ii-transition, 0.2s);
	padding: 0;
}

.ii-drawer-asset-card:hover .ii-asset-view-btn {
	opacity: 1;
}

.ii-drawer-asset-card .ii-asset-view-btn:hover {
	background: rgba(0, 0, 0, 0.78);
	transform: translateY(-2px);
}

.ii-drawer-asset-card .ii-asset-view-btn:active {
	transform: translateY(0px);
}

.ii-drawer-asset-card .ii-asset-view-btn svg {
	width: 16px;
	height: 16px;
}

/* Placeholder cards shown while an asset grid's first page is in flight.
   iiSkeletonShimmer lives in animations.css, which loads on every route;
   ii-skeleton-shimmer is catalog.css only, so this never animated off /catalog/. */
.ii-drawer-asset-card.is-skeleton {
	cursor: default;
	pointer-events: none;
}

.ii-drawer-asset-card.is-skeleton:hover {
	border-color: var(--ii-border, #e5e7eb);
	transform: none;
	box-shadow: none;
}

/* Infinite scroll sentinel + spinners */
.ii-drawer-sentinel {
	height: 1px;
	width: 100%;
}

/* Select-All button (inside Added Assets drawer footer) */
.ii-drawer-select-all-btn {
	display: inline-flex;
	align-items: center;
	height: 30px;
	padding: 0 12px;
	border-radius: 6px;
	font-size: 11.5px;
	font-weight: 600;
	white-space: nowrap;
	cursor: pointer;
	outline: none;
	background: transparent;
	border: 1px solid var(--ii-border, rgba(0, 0, 0, 0.1));
	color: var(--ii-text-secondary, #6b7280);
	font-family: var(--ii-font-body, Inter, sans-serif);
	transition:
		color 0.15s ease,
		background 0.15s ease,
		border-color 0.15s ease;
	flex-shrink: 0;
}

.ii-drawer-select-all-btn:hover {
	background: var(--ii-bg-hover, #f3f4f6);
	border-color: rgba(0, 0, 0, 0.15);
	color: var(--ii-text-primary, #111827);
}

/* Sidebar "Show All" gradient overlay - hides overflow cards, shows gradient + "Show All (N)" CTA */
.ii-sidebar-assets-overflow {
	position: relative;
	overflow: hidden;
	/* Show only ~4 rows of assets; the exact height depends on card size */
}

.ii-sidebar-show-all-overlay {
	position: absolute;
	bottom: 0;
	left: 0;
	right: 0;
	height: 90px;
	display: flex;
	align-items: flex-end;
	justify-content: center;
	padding-bottom: 10px;
	background: linear-gradient(
		to bottom,
		transparent 0%,
		var(--ii-surface-white, #fff) 70%
	);
	z-index: 3;
	cursor: pointer;
	transition: opacity 0.2s ease;
}

.ii-sidebar-show-all-overlay:hover {
	opacity: 0.95;
}

.ii-sidebar-show-all-overlay-btn {
	display: inline-flex;
	align-items: center;
	gap: 5px;
	padding: 6px 14px;
	border-radius: var(--ii-radius-rounded);
	font-size: 11.5px;
	font-weight: 600;
	color: var(--ii-accent, #2563eb);
	background: var(--ii-surface-white, #fff);
	border: 1px solid var(--ii-accent, #2563eb);
	cursor: pointer;
	font-family: var(--ii-font-body, Inter, sans-serif);
	outline: none;
	pointer-events: none;
	/* overlay handles the click */
	transition:
		background 0.15s ease,
		color 0.15s ease,
		transform 0.15s ease;
	box-shadow: 0 2px 8px rgba(37, 99, 235, 0.12);
}

.ii-sidebar-show-all-overlay:hover .ii-sidebar-show-all-overlay-btn {
	background: var(--ii-accent, #2563eb);
	color: #fff;
	transform: translateY(-1px);
	box-shadow: 0 4px 14px rgba(37, 99, 235, 0.25);
}

.ii-sidebar-show-all-overlay-btn svg {
	flex-shrink: 0;
	transition: transform 0.2s ease;
}

.ii-sidebar-show-all-overlay:hover .ii-sidebar-show-all-overlay-btn svg {
	transform: translateX(2px);
}

/* Dark mode */
.dark .ii-drawer {
	background: var(--ii-dk-surface-1, #111116);
	border-top-color: var(--ii-dk-border, #28282f);
	box-shadow:
		0 -8px 40px rgba(0, 0, 0, 0.5),
		0 -2px 8px rgba(0, 0, 0, 0.3);
}

.dark .ii-drawer--side {
	border-left-color: var(--ii-dk-border, #28282f);
	box-shadow: 4px 0 32px rgba(0, 0, 0, 0.4);
}

.dark .ii-drawer-header {
	border-bottom-color: var(--ii-dk-border, #28282f);
}

.dark .ii-drawer-footer {
	border-top-color: var(--ii-dk-border, #28282f);
	background: var(--ii-dk-surface-1, #111116);
}

.dark .ii-drawer-asset-card {
	background: var(--ii-dk-surface-2, #18181e);
	border-color: var(--ii-dk-border, #28282f);
}

.dark .ii-drawer-asset-card:hover {
	background: var(--ii-dk-surface-1, #111116);
}

.dark .ii-drawer-asset-card.is-selected {
	background: rgba(59, 130, 246, 0.1);
}

.dark .ii-drawer-select-all-btn {
	border-color: var(--ii-dk-border, #28282f);
	color: var(--ii-dk-text-secondary, #b2b2be);
}

.dark .ii-drawer-select-all-btn:hover {
	background: var(--ii-dk-hover, #262630);
	color: var(--ii-dk-text-primary, #e5e5ea);
}

.dark .ii-sidebar-show-all-overlay {
	background: linear-gradient(
		to bottom,
		transparent 0%,
		var(--ii-dk-surface-1, #111116) 70%
	);
}

.dark .ii-sidebar-show-all-overlay-btn {
	background: var(--ii-dk-surface-2, #18181e);
	border-color: rgba(96, 165, 250, 0.4);
	color: #60a5fa;
}

.dark .ii-sidebar-show-all-overlay:hover .ii-sidebar-show-all-overlay-btn {
	background: rgba(59, 130, 246, 0.2);
	color: #93bbfd;
}

/* Reduced-motion */
@media (prefers-reduced-motion: reduce) {
	.ii-drawer,
	.ii-drawer-backdrop {
		transition: none;
	}

	.ii-drawer-asset-card {
		transition: none;
	}

	.ii-drawer-asset-card:hover {
		transform: none;
	}
}

/* Responsive */
@media (max-width: 768px) {
	.ii-drawer--bottom {
		height: min(var(--ii-drawer-height), 80vh);
		max-height: 85vh;
		border-radius: 16px 16px 0 0;
	}

	.ii-drawer-header {
		padding: 0 14px;
	}

	.ii-drawer-footer {
		padding: 10px 14px;
		padding-bottom: max(10px, env(safe-area-inset-bottom));
	}
}
