/**
 * GDC Bottom Sheet Component
 *
 * Mobile-optimized overlay that slides up from the bottom.
 * Used for trip calculator, quick actions, and forms.
 *
 * 3 states:   hidden | visible | closing | dragging
 *
 * All animations use GPU-safe properties (transform, opacity).
 * Tokens sourced from tokens.css (layer 1 + 2).
 *
 * @package GDC
 * @since   1.0.0
 */

/* ==========================================================
   KEYFRAMES — GPU-safe (transform + opacity only)
   ========================================================== */

@keyframes gdc-bottom-sheet-fade-in {
	0%   { opacity: 0; }
	100% { opacity: 1; }
}

@keyframes gdc-bottom-sheet-fade-out {
	0%   { opacity: 1; }
	100% { opacity: 0; }
}

@keyframes gdc-bottom-sheet-slide-in {
	0%   { transform: translateY(100%) translateZ(0); }
	100% { transform: translateY(0) translateZ(0); }
}

@keyframes gdc-bottom-sheet-slide-out {
	0%   { transform: translateY(0) translateZ(0); }
	100% { transform: translateY(100%) translateZ(0); }
}

/* ==========================================================
   BACKDROP
   ========================================================== */

.gdc-bottom-sheet-backdrop {
	position: fixed;
	inset: 0;
	z-index: 1000;

	display: flex;
	align-items: flex-end;
	justify-content: center;

	background: rgba(0, 0, 0, 0.7);

	animation: gdc-bottom-sheet-fade-in var(--gdc-duration-standard) var(--gdc-ease-out) forwards;

	/* GPU layer promotion */
	will-change: opacity;
	transform: translateZ(0);
}

/* Hidden state */
.gdc-bottom-sheet-backdrop[data-state="hidden"] {
	display: none;
}

/* Closing state */
.gdc-bottom-sheet-backdrop[data-state="closing"] {
	animation: gdc-bottom-sheet-fade-out var(--gdc-duration-fast) var(--gdc-ease-out) forwards;
}

/* ==========================================================
   SHEET CONTAINER
   ========================================================== */

.gdc-bottom-sheet {
	position: relative;

	background: var(--gdc-bg-surface);
	border-radius: 12px 12px 0 0;
	box-shadow: var(--gdc-shadow-xl);

	width: 100%;
	max-width: 600px;
	max-height: 80vh;

	display: flex;
	flex-direction: column;

	animation: gdc-bottom-sheet-slide-in var(--gdc-duration-standard) var(--gdc-ease-spring) forwards;

	/* GPU layer promotion */
	will-change: transform;
	transform: translateZ(0);
}

/* Closing state */
.gdc-bottom-sheet-backdrop[data-state="closing"] .gdc-bottom-sheet {
	animation: gdc-bottom-sheet-slide-out var(--gdc-duration-fast) var(--gdc-ease-out) forwards;
}

/* Dragging state — disable animation so transform follows pointer */
.gdc-bottom-sheet-backdrop[data-state="dragging"] .gdc-bottom-sheet {
	animation: none;
	transition: none;
}

/* ==========================================================
   DRAG HANDLE
   ========================================================== */

.gdc-bottom-sheet__handle {
	display: flex;
	align-items: center;
	justify-content: center;

	padding: 12px 0 4px;

	cursor: grab;
	touch-action: none;

	flex-shrink: 0;
}

.gdc-bottom-sheet__handle:active {
	cursor: grabbing;
}

.gdc-bottom-sheet__handle-bar {
	width: 36px;
	height: 4px;

	background: var(--gdc-text-secondary, #A0A0A0);
	border-radius: 2px;
	opacity: 0.5;

	transition: opacity var(--gdc-duration-fast) var(--gdc-ease-out);
}

.gdc-bottom-sheet__handle:hover .gdc-bottom-sheet__handle-bar {
	opacity: 0.8;
}

/* ==========================================================
   HEADER
   ========================================================== */

.gdc-bottom-sheet__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 16px;

	padding: 4px 20px 0;

	flex-shrink: 0;
}

.gdc-bottom-sheet__title {
	margin: 0;

	font-family: var(--gdc-font-sans);
	font-size: var(--gdc-text-lg, 1.125rem);
	font-weight: var(--gdc-font-semibold);
	line-height: var(--gdc-leading-normal);
	color: var(--gdc-text-primary);
}

.gdc-bottom-sheet__close {
	display: inline-flex;
	align-items: center;
	justify-content: center;

	min-width: 44px;
	min-height: 44px;
	width: 44px;
	height: 44px;

	padding: 0;
	border: none;
	border-radius: 8px;
	background: transparent;
	cursor: pointer;

	color: var(--gdc-text-secondary, #A0A0A0);

	transition:
		background-color var(--gdc-duration-fast) var(--gdc-ease-out),
		color var(--gdc-duration-fast) var(--gdc-ease-out);

	flex-shrink: 0;
}

.gdc-bottom-sheet__close:hover {
	background-color: var(--gdc-bg-hover);
	color: var(--gdc-text-primary);
}

.gdc-bottom-sheet__close:focus-visible {
	outline: 2px solid var(--gdc-accent-cta);
	outline-offset: 2px;
}

.gdc-bottom-sheet__close svg {
	width: 18px;
	height: 18px;
}

/* ==========================================================
   BODY
   ========================================================== */

.gdc-bottom-sheet__body {
	padding: 16px 20px;

	overflow-y: auto;
	-webkit-overflow-scrolling: touch;
	overscroll-behavior-y: contain;

	flex: 1 1 auto;
	min-height: 0;

	font-family: var(--gdc-font-sans);
	font-size: var(--gdc-text-base);
	line-height: var(--gdc-leading-relaxed, 1.6);
	color: var(--gdc-text-secondary, #A0A0A0);
}

/* ==========================================================
   FOOTER (STICKY ACTIONS)
   ========================================================== */

.gdc-bottom-sheet__footer {
	display: flex;
	align-items: center;
	justify-content: flex-end;
	gap: 12px;

	padding: 12px 20px 20px;

	flex-shrink: 0;

	/* Sticky at bottom with top border */
	border-top: 1px solid rgba(255, 255, 255, 0.06);
}

/* Safe area for devices with home indicator */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
	.gdc-bottom-sheet__footer {
		padding-bottom: calc(20px + env(safe-area-inset-bottom));
	}
}

/* ==========================================================
   REDUCED MOTION
   ========================================================== */

@media (prefers-reduced-motion: reduce) {
	.gdc-bottom-sheet-backdrop,
	.gdc-bottom-sheet {
		animation-duration: 1ms !important;
	}
}

/* ==========================================================
   RESPONSIVE — Tablet (60vh max)
   ========================================================== */

@media (min-width: 768px) {
	.gdc-bottom-sheet {
		max-height: 60vh;
	}
}

/* ==========================================================
   RESPONSIVE — Landscape mode (half height)
   ========================================================== */

@media (orientation: landscape) and (max-height: 500px) {
	.gdc-bottom-sheet {
		max-height: 50vh;
	}
}
