.bottom-sheet {
  position: relative;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  width: 100%;
  max-width: var(--sheet-max-width);
  max-height: min(var(--sheet-content-max-height), 100%);
  overflow: hidden;
  border: var(--control-border-width) solid var(--sheet-border);
  border-block-end: 0;
  border-radius: var(--sheet-radius) var(--sheet-radius) 0 0;
  background: var(--sheet-background);
  color: var(--color-text-primary);
  box-shadow: var(--overlay-shadow-sheet);
  transform: translateY(0);
  transition: transform var(--overlay-duration) var(--overlay-easing);
}

.bottom-sheet[data-dragging='true'] {
  transition: none;
  touch-action: none;
}

.bottom-sheet[data-snap-point='content'] {
  height: auto;
}

.bottom-sheet[data-snap-point='medium'] {
  height: min(var(--sheet-height-medium), 100%);
}

.bottom-sheet[data-snap-point='large'] {
  height: min(var(--sheet-height-large), 100%);
}

.bottom-sheet[data-snap-point='fullscreen'] {
  position: absolute;
  inset: 0;
  height: min(var(--sheet-height-fullscreen), 100%);
  max-height: none;
  margin-inline: auto;
  border-radius: 0;
}

.bottom-sheet[data-overlay-state='opening'],
.bottom-sheet[data-overlay-state='closing'] {
  transform: translateY(var(--sheet-closed-translate));
}

.bottom-sheet__handle {
  position: relative;
  justify-self: center;
  width: calc(var(--sheet-handle-width) + (var(--space-4) * 2));
  height: calc(var(--sheet-handle-height) + (var(--space-2) * 2));
  margin-block-start: var(--space-1);
  background: transparent;
  touch-action: none;
  cursor: grab;
}

.bottom-sheet__handle::before {
  content: '';
  position: absolute;
  inset-inline-start: 50%;
  inset-block-start: 50%;
  width: var(--sheet-handle-width);
  height: var(--sheet-handle-height);
  border-radius: var(--radius-sm);
  background: var(--color-border);
  transform: translate(-50%, -50%);
}

.bottom-sheet[data-dragging='true'] .bottom-sheet__handle {
  cursor: grabbing;
}

.bottom-sheet__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  gap: var(--sheet-gap);
  padding: var(--sheet-padding);
  border-block-end: var(--control-border-width) solid var(--sheet-border);
  touch-action: none;
}

.bottom-sheet__heading {
  flex: 1 1 auto;
  min-width: 0;
}

.bottom-sheet__title {
  margin: 0;
  overflow: hidden;
  font-size: var(--font-size-overlay-title);
  line-height: var(--overlay-heading-line-height);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bottom-sheet__description {
  margin-block-start: var(--space-1);
  color: var(--color-text-secondary);
  font-size: var(--font-size-control-md);
}

.bottom-sheet__header-end {
  flex: 0 0 auto;
  min-width: 0;
  margin-inline-start: auto;
}

.bottom-sheet__header-action {
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-control-danger);
  font: inherit;
  font-size: var(--font-size-control-md);
  font-weight: var(--font-weight-control);
  line-height: var(--overlay-heading-line-height);
  cursor: pointer;
}

.bottom-sheet__header-action:hover {
  color: var(--color-control-danger-hover);
}

.bottom-sheet__header-action:focus-visible {
  outline: var(--control-focus-width) solid var(--color-control-focus);
  outline-offset: var(--control-focus-offset);
}

.bottom-sheet__close {
  flex: 0 0 auto;
  margin-inline-start: auto;
}

.bottom-sheet__header-end:not([hidden]) ~ .bottom-sheet__close {
  margin-inline-start: 0;
}

.bottom-sheet__body {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--sheet-padding);
  -webkit-overflow-scrolling: touch;
  /* Native vertical scroll; sheet claim via Touch Adapter preventDefault. */
  touch-action: pan-y;
}

.bottom-sheet__content {
  min-width: 0;
}

.bottom-sheet__loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--sheet-loading-background);
}

.bottom-sheet__spinner {
  width: var(--loading-indicator-size);
  height: var(--loading-indicator-size);
  border: var(--loading-indicator-width) solid var(--color-text-secondary);
  border-block-start-color: transparent;
  border-radius: 50%;
  animation: bottom-sheet-loading var(--duration-loading) linear infinite;
}

.bottom-sheet__footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--bottom-action-space);
  padding-inline: var(--bottom-action-space);
  padding-block-start: var(--bottom-action-space);
  padding-block-end: max(var(--bottom-action-space), var(--safe-area-bottom));
  border-block-start: var(--control-border-width) solid var(--sheet-border);
}

.bottom-sheet__footer .button--full-width {
  flex: 1 1 100%;
}

.bottom-sheet__handle[hidden],
.bottom-sheet__header[hidden],
.bottom-sheet__heading[hidden],
.bottom-sheet__title[hidden],
.bottom-sheet__description[hidden],
.bottom-sheet__header-end[hidden],
.bottom-sheet__close[hidden],
.bottom-sheet__loading[hidden],
.bottom-sheet__footer[hidden] {
  display: none;
}

@keyframes bottom-sheet-loading {
  to {
    transform: rotate(1turn);
  }
}

@media (prefers-reduced-motion: reduce) {
  .bottom-sheet {
    transition: none;
  }
}
