/**
 * Osom CTS v3.1 — Sidebar Styles
 */

/* ---- Trigger tab ---- */

.osom-cts-trigger {
	position: fixed;
	right: 0;
	top: 50%;
	transform: translateY(-50%);
	z-index: 9998;
	display: flex;
	align-items: center;
	gap: 0;
	padding: 10px 8px;
	background: #fff;
	border: 1px solid #ddd;
	border-right: none;
	border-radius: 4px 0 0 4px;
	box-shadow: -2px 2px 6px rgba(0, 0, 0, 0.08);
	cursor: pointer;
	transition: padding 0.2s ease, gap 0.2s ease;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
	color: #1e1e1e;
	line-height: 1;
}

.osom-cts-trigger:hover {
	background: #f6f6f6;
}

.osom-cts-trigger svg {
	width: 24px;
	height: 24px;
	flex-shrink: 0;
}

.osom-cts-trigger__label {
	max-width: 0;
	overflow: hidden;
	white-space: nowrap;
	opacity: 0;
	transition: max-width 0.3s ease, opacity 0.2s ease, margin 0.2s ease;
	font-size: 13px;
	font-weight: 500;
	margin-left: 0;
}

.osom-cts-trigger:hover .osom-cts-trigger__label,
.osom-cts-trigger:focus-visible .osom-cts-trigger__label {
	max-width: 80px;
	opacity: 1;
	margin-left: 6px;
}

.osom-cts-trigger.is-hidden {
	opacity: 0;
	pointer-events: none;
	transform: translateY(-50%) translateX(20px);
	transition: opacity 0.2s ease, transform 0.2s ease;
}

/* ---- Overlay ---- */

.osom-cts-overlay {
	position: fixed;
	inset: 0;
	background: rgba(0, 0, 0, 0.12);
	z-index: 9999;
	opacity: 0;
	visibility: hidden;
	transition: opacity 0.3s ease, visibility 0.3s ease;
}

.osom-cts-overlay.is-visible {
	opacity: 1;
	visibility: visible;
}

/* ---- Sidebar ---- */

.osom-cts-sidebar {
	position: fixed;
	top: 50%;
	right: -320px;
	transform: translateY(-50%);
	width: 320px;
	max-height: calc(100vh - 48px);
	background: #fff;
	border-radius: 8px;
	box-shadow: -4px 0 12px rgba(0, 0, 0, 0.08);
	z-index: 10000;
	overflow-y: auto;
	transition: right 0.3s ease;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
}

/* Prevent content typography changes from affecting the panel UI. */
.osom-cts-sidebar h2,
.osom-cts-sidebar h3,
.osom-cts-sidebar button:not(.osom-cts-card) {
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
}

.osom-cts-sidebar.is-open {
	right: 0;
}

.osom-cts-sidebar__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 16px;
	border-bottom: 1px solid #e0e0e0;
	position: sticky;
	top: 0;
	background: #fff;
	z-index: 1;
	border-radius: 8px 8px 0 0;
}

.osom-cts-sidebar__title {
	font-size: 13px;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.5px;
	color: #1e1e1e;
	margin: 0;
}

.osom-cts-sidebar__close {
	display: flex;
	align-items: center;
	justify-content: center;
	background: none;
	border: none;
	cursor: pointer;
	padding: 4px;
	color: #757575;
	border-radius: 2px;
	line-height: 1;
}

.osom-cts-sidebar__close:hover {
	background: #f0f0f0;
	color: #1e1e1e;
}

.osom-cts-sidebar__close:focus-visible {
	outline: 2px solid #1e1e1e;
	outline-offset: 2px;
}

.osom-cts-sidebar__close svg {
	width: 20px;
	height: 20px;
}

.osom-cts-sidebar__content {
	padding: 16px;
}

/* ---- Sections ---- */

.osom-cts-section {
	margin-bottom: 24px;
}

.osom-cts-section__label {
	font-size: 11px;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.5px;
	color: #757575;
	margin: 0 0 12px;
	padding: 0;
}

/* ---- Grids ---- */

.osom-cts-grid {
	display: grid;
	gap: 12px;
}

.osom-cts-grid--styles {
	grid-template-columns: 1fr 1fr;
}

.osom-cts-grid--colors {
	grid-template-columns: 1fr 1fr;
}

.osom-cts-grid--typography {
	grid-template-columns: repeat(3, 1fr);
}

/* ---- Cards (shared) ---- */

.osom-cts-card {
	position: relative;
	display: flex;
	flex-direction: column;
	border: 1px solid #e0e0e0;
	border-radius: 8px;
	cursor: pointer;
	background: #fff;
	transition: border-color 0.15s ease, box-shadow 0.15s ease;
	padding: 0;
	text-align: center;
	font-family: inherit;
}

/* Overflow hidden moved to children so the tooltip escapes the card. */
.osom-cts-card > * {
	overflow: hidden;
	border-radius: 7px; /* card radius minus border width */
}

.osom-cts-card:hover {
	border-color: #1e1e1e;
}

.osom-cts-card:focus-visible {
	outline: 2px solid #1e1e1e;
	outline-offset: 2px;
}

.osom-cts-card.is-active {
	border-color: #1e1e1e;
	box-shadow: 0 0 0 1px #1e1e1e;
}

/* ---- Tooltip (fallback: absolute positioning) ---- */

.osom-cts-card[data-tooltip]::after {
	content: attr(data-tooltip);
	position: absolute;
	top: calc(100% + 6px);
	left: 50%;
	transform: translateX(-50%);
	background: #1e1e1e;
	color: #fff;
	padding: 4px 8px;
	border-radius: 4px;
	font-size: 11px;
	font-weight: 500;
	line-height: 1.4;
	white-space: wrap;
	pointer-events: none;
	opacity: 0;
	z-index: 1;
	transition: opacity 0.15s ease;
}

.osom-cts-card[data-tooltip]:hover::after,
.osom-cts-card[data-tooltip]:focus-visible::after {
	opacity: 1;
}

/* Anchor positioning enhancement: escapes overflow clipping, auto-flips. */

@supports (anchor-scope: all) {
	.osom-cts-card[data-tooltip] {
		anchor-scope: all;
		anchor-name: --cts-card;
	}

	.osom-cts-card[data-tooltip]::after {
		position: fixed;
		top: auto;
		left: auto;
		transform: none;
		position-anchor: --cts-card;
		position-area: block-end center;
		width: fit-content;
		margin: 6px 0 0;
		position-try-fallbacks: flip-block;
	}
}

/* ---- Style variation cards ---- */

.osom-cts-card--style .osom-cts-card__preview {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 24px 16px;
}

.osom-cts-card__aa {
	font-size: 32px;
	font-weight: 400;
	line-height: 1;
}

.osom-cts-card__dots {
	display: flex;
	flex-direction: column;
	gap: 4px;
}

.osom-cts-card__dot {
	width: 14px;
	height: 14px;
	border-radius: 50%;
	border: 1px solid rgba(0, 0, 0, 0.08);
}

/* ---- Color variation cards ---- */

.osom-cts-card--color {
	flex-direction: row;
}

.osom-cts-card__swatches {
	display: flex;
	gap: 0;
	flex-shrink: 0;
	overflow: hidden;
	width: 100%;
}

.osom-cts-card__swatch {
	flex: 1;
	height: 40px;
	display: block;
}

/* ---- Typography cards ---- */

.osom-cts-card--typography .osom-cts-card__preview--typo {
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 16px 8px;
	background: #f8f8f8;
}

.osom-cts-card--typography .osom-cts-card__aa {
	font-size: 28px;
	color: #1e1e1e;
}

/* ---- Reset button ---- */

.osom-cts-section--reset {
	border-top: 1px solid #e0e0e0;
	padding-top: 16px;
	text-align: center;
}

.osom-cts-reset {
	background: none;
	border: 1px solid #e0e0e0;
	border-radius: 4px;
	padding: 8px 16px;
	font-size: 13px;
	color: #757575;
	cursor: pointer;
	width: 100%;
	transition: background 0.15s ease, color 0.15s ease;
	font-family: inherit;
}

.osom-cts-reset:hover {
	background: #f0f0f0;
	color: #1e1e1e;
}

.osom-cts-reset:focus-visible {
	outline: 2px solid #1e1e1e;
	outline-offset: 2px;
}

/* ---- Keep open checkbox ---- */

.osom-cts-keep-open {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	margin-top: 12px;
	font-size: 12px;
	color: #757575;
	cursor: pointer;
	font-family: inherit;
}

.osom-cts-keep-open input[type="checkbox"] {
	margin: 0;
	cursor: pointer;
	accent-color: #1e1e1e;
}

.osom-cts-keep-open span {
	user-select: none;
}

/* ---- Reduced motion ---- */

@media (prefers-reduced-motion: reduce) {
	.osom-cts-trigger,
	.osom-cts-trigger.is-hidden,
	.osom-cts-trigger__label,
	.osom-cts-overlay,
	.osom-cts-sidebar,
	.osom-cts-card {
		transition: none !important;
	}
}

/* ---- Keep open: instant state (before JS) ---- */

html.osom-cts-keep-open .osom-cts-sidebar {
	right: 16px;
	transition: none;
}

html.osom-cts-keep-open .osom-cts-trigger {
	opacity: 0;
	pointer-events: none;
	transition: none;
}

/* ---- Responsive ---- */

@media (max-width: 480px) {
	.osom-cts-sidebar {
		width: calc(100vw - 32px);
		right: calc(-100vw + 32px);
	}

	.osom-cts-sidebar.is-open {
		right: 16px;
	}

	.osom-cts-grid--typography {
		grid-template-columns: 1fr 1fr;
	}
}
