/* Spoti PWA - warstwa "app feel" (F3).
 * Zgodnie z globalna regula PREMIUM APP FEEL: tokeny ruchu, tylko transform/opacity,
 * touch targety >= 44px (pointer coarse), tap-highlight wylaczony z wlasnym :active,
 * przejscia miedzy stronami (MPA View Transitions), bottom-sheet z gestem,
 * prefers-reduced-motion honorowane. Subtelnie - "bez bolu" dla istniejacego wygladu. */

:root {
	--spoti-ease-out: cubic-bezier(0.22, 1, 0.36, 1);
	--spoti-dur-fast: 130ms;
	--spoti-dur: 240ms;
	--spoti-dur-slow: 340ms;
}

/* ── Reakcja na dotyk: bez systemowego blysku, wlasny stan wcisniecia ── */

a, button, [role="button"], input[type="submit"], input[type="button"] {
	-webkit-tap-highlight-color: transparent;
}

button:active,
.btn:active,
[role="button"]:active,
input[type="submit"]:active,
.masterstudy-button:active,
.btn-default:active,
.spoti-pwa-pressable:active {
	transform: scale(0.97);
	transition: transform 80ms ease;
}

/* ── Touch targety i wygoda formularzy na ekranach dotykowych ── */

@media (pointer: coarse) {
	.btn,
	.masterstudy-button,
	button[type="submit"],
	input[type="submit"],
	input[type="button"] {
		min-height: 44px;
	}

	input[type="text"],
	input[type="email"],
	input[type="password"],
	input[type="search"],
	input[type="number"],
	select,
	textarea {
		min-height: 44px;
		/* >=16px zapobiega auto-zoomowi iOS przy fokusowaniu pola. */
		font-size: max(16px, 1em);
	}
}

/* ── Standalone (zainstalowana apka): zachowanie natywne ── */

body.spoti-pwa-standalone {
	/* Bez "gumowania" calej strony i pull-to-refresh w srodku apki. */
	overscroll-behavior-y: contain;
	/* Notch/inset - tresc nie wchodzi pod systemowe paski. */
	padding-left: env(safe-area-inset-left, 0px);
	padding-right: env(safe-area-inset-right, 0px);
}

/* ── Dashboard: wejscie kafelkow (fade+rise, stagger) ──
 * Stan poczatkowy (opacity:0) zalezy od klasy html.spoti-reveal-on, ktora
 * synchroniczny inline-skrypt w <head> (class-pwa-head.php) ustawia PRZED
 * pierwszym malowaniem - dzieki temu kafelki sa ukryte od poczatku (bez flash-
 * of-content), a nie ukrywane po fakcie przez defer-skrypt. Bez JS / bez wsparcia
 * IntersectionObserver / przy reduced-motion klasa nie jest dodawana = kafelki
 * normalnie widoczne. Animujemy @keyframes (nie transition), zeby nie nadpisac
 * hoverowych przejsc; po zakonczeniu JS utrwala opacity:1 inline (hover translateY
 * dziala bez kolizji z fill animacji). Failsafe w head zdejmuje klase po 6s. */

html.spoti-reveal-on .msat-dashboard__tile {
	opacity: 0;
}
.msat-dashboard__tile.is-revealing {
	animation: spoti-fade-rise var(--spoti-dur-slow) var(--spoti-ease-out) both;
	will-change: opacity, transform;
}

@keyframes spoti-fade-rise {
	from { opacity: 0; transform: translateY(16px); }
	to   { opacity: 1; transform: translateY(0); }
}

/* ── Przejscia miedzy stronami (MPA View Transitions, Chrome 126+) ──
 * Progressive enhancement: przegladarki bez wsparcia po prostu ignoruja. */

@view-transition {
	navigation: auto;
}

@keyframes spoti-vt-out {
	to { opacity: 0; }
}

@keyframes spoti-vt-in {
	from { opacity: 0; transform: translateY(8px); }
	to { opacity: 1; transform: translateY(0); }
}

::view-transition-old(root) {
	animation: spoti-vt-out var(--spoti-dur-fast) var(--spoti-ease-out) both;
}

::view-transition-new(root) {
	animation: spoti-vt-in var(--spoti-dur) var(--spoti-ease-out) both;
}

/* ── Bottom-sheet (SpotiSheet) - otwarcie slide-up, zamkniecie gestem W GORE ── */

.spoti-sheet-backdrop {
	position: fixed;
	inset: 0;
	z-index: 99990;
	background: rgba(15, 23, 42, 0.45);
	opacity: 0;
	/* Klikalny dopiero po otwarciu; w trakcie zanikania przepuszcza klikniecia. */
	pointer-events: none;
	transition: opacity var(--spoti-dur) var(--spoti-ease-out);
}

.spoti-sheet-backdrop.is-open {
	opacity: 1;
	pointer-events: auto;
}

.spoti-sheet-backdrop.is-dismissing,
.spoti-sheet.is-dismissing {
	pointer-events: none;
}

/* Tryb ciemny platformy (konwencja :root.dark jak w blokach front-endu). */
:root.dark .spoti-sheet {
	--spoti-sheet-bg: #1e2530;
	--spoti-sheet-text: #e5e7eb;
}

.spoti-sheet {
	position: fixed;
	left: 0;
	right: 0;
	bottom: 0;
	z-index: 99991;
	max-height: 86vh;
	max-height: 86dvh;
	display: flex;
	flex-direction: column;
	background: var(--spoti-sheet-bg, #ffffff);
	color: var(--spoti-sheet-text, #1f2937);
	border-radius: 20px 20px 0 0;
	box-shadow: 0 -12px 40px rgba(2, 8, 20, 0.18);
	padding-bottom: env(safe-area-inset-bottom, 0px);
	transform: translateY(100%);
	transition: transform var(--spoti-dur-slow) var(--spoti-ease-out), opacity var(--spoti-dur) var(--spoti-ease-out);
	touch-action: none;
	will-change: transform;
}

.spoti-sheet.is-open {
	transform: translateY(0);
}

.spoti-sheet.is-dragging {
	transition: none;
}

.spoti-sheet.is-dismissing {
	transform: translateY(-110%);
	opacity: 0;
}

.spoti-sheet__grip {
	flex: none;
	width: 44px;
	height: 5px;
	margin: 10px auto 6px;
	border-radius: 999px;
	background: #d1d5db;
}

.spoti-sheet__head {
	flex: none;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 4px 20px 10px;
}

.spoti-sheet__title {
	margin: 0;
	font-size: 17px;
	font-weight: 700;
}

.spoti-sheet__close {
	flex: none;
	min-width: 44px;
	min-height: 44px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	font-size: 22px;
	line-height: 1;
	color: #6b7280;
	background: transparent;
	border: 0;
	border-radius: 12px;
	cursor: pointer;
}

.spoti-sheet__body {
	flex: 1;
	min-height: 0;
	overflow-y: auto;
	-webkit-overflow-scrolling: touch;
	padding: 0 20px 20px;
	touch-action: pan-y;
}

@media (min-width: 720px) {
	.spoti-sheet {
		left: 50%;
		right: auto;
		width: 560px;
		transform: translate(-50%, 100%);
	}

	.spoti-sheet.is-open {
		transform: translate(-50%, 0);
	}

	.spoti-sheet.is-dismissing {
		transform: translate(-50%, -110%);
	}
}

/* ── Reduced motion: statyka (jedyny dozwolony !important) ── */

@media (prefers-reduced-motion: reduce) {
	::view-transition-old(root),
	::view-transition-new(root) {
		animation: none !important;
	}

	.spoti-sheet,
	.spoti-sheet-backdrop,
	button:active,
	.btn:active {
		transition: none !important;
		animation: none !important;
	}
}
