/* Sheets, pushed pages, nav bars and action sheets (素 Plain §3.1, §3.5, §3.14). */

.sheet-layer {
  position: fixed;
  inset: 0;
  /* Same box as #app (viewport.ts): a sheet with a field stays above the keyboard. */
  top: var(--vvt, 0px);
  height: var(--vvh, auto);
}

.sheet-scrim {
  position: absolute;
  inset: 0;
  background: var(--scrim);
  opacity: 0;
  transition: opacity var(--d-sheet) var(--e-spring);
}

.sheet-layer[data-open="true"] .sheet-scrim {
  opacity: 1;
}

.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  max-height: calc(100% - var(--safe-top) - var(--s-3));
  padding-right: var(--safe-right);
  padding-bottom: max(var(--safe-bottom), var(--s-4));
  padding-left: var(--safe-left);
  border-radius: var(--r-sheet) var(--r-sheet) 0 0;
  background: var(--bg-sheet);
  box-shadow: var(--shadow-3);
  outline: none;
  transform: translateY(100%);
  transition: transform var(--d-sheet) var(--e-spring);
  touch-action: pan-x pan-y;
  will-change: transform;
}

.sheet-layer[data-open="true"] .sheet {
  transform: translateY(0);
}

.sheet[data-dragging="true"] {
  transition: none;
}

.sheet[data-size="tall"] {
  height: 92%;
}

.sheet[data-size="full"] {
  height: 100%;
  max-height: 100%;
  padding-top: var(--safe-top);
  border-radius: 0;
  background: var(--bg);
}

.sheet-grab {
  display: grid;
  place-items: center;
  flex: none;
  height: 20px;
  cursor: grab;
  touch-action: none;
}

.sheet-grab i {
  width: 36px;
  height: 5px;
  border-radius: var(--r-full);
  background: var(--fill-2);
}

.sheet-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 var(--s-4);
}

/* ── Pushed page: slides in from the right, full screen ───── */
.page-layer .sheet-scrim {
  background: rgb(0 0 0 / 0.18);
}

.sheet.page {
  top: 0;
  height: 100%;
  max-height: 100%;
  padding-top: var(--safe-top);
  padding-bottom: 0;
  border-radius: 0;
  background: var(--bg-grouped);
  box-shadow: -8px 0 32px rgb(0 0 0 / 0.18);
  transform: translateX(100%);
  transition: transform 300ms var(--e-spring);
}

/* A page's edge swipe back (sheet.ts edgeSwipe) is a horizontal drag the page handles itself:
   vertical panning only, so the browser never claims it and cancels the pointer. The body is
   its own scroll container, so it says the same; sideways scrollers inside keep their pan-x. */
.sheet.page,
.sheet.page > .sheet-body {
  touch-action: pan-y;
}

.page-layer[data-open="true"] .sheet.page {
  transform: translateX(0);
}

.sheet.page .sheet-body {
  padding: 0 var(--s-4) calc(var(--safe-bottom) + var(--s-8));
}

/* A page whose content is a plain screen (chat-like, browser). */
.sheet.page[data-plain="true"] {
  background: var(--bg);
}

@media (prefers-reduced-motion: reduce) {
  .sheet.page {
    transform: none;
    opacity: 0;
    transition: opacity 150ms linear;
  }
  .page-layer[data-open="true"] .sheet.page {
    opacity: 1;
  }
  .sheet:not(.page) {
    transform: none;
    opacity: 0;
    transition: opacity 150ms linear;
  }
  .sheet-layer[data-open="true"] .sheet:not(.page) {
    opacity: 1;
  }
}

/* ── Nav bar (pages and form sheets) ──────────────────────── */
.nav-bar {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  flex: none;
  min-height: var(--nav-h);
  padding: 0 var(--s-2);
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  box-shadow: 0 0.5px 0 transparent;
  transition: box-shadow var(--d-fast) linear;
}

.sheet.page > .nav-bar {
  background: var(--bg-grouped);
}

.sheet:not(.page) > .nav-bar {
  background: transparent;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

.nav-bar[data-under="true"] {
  box-shadow: 0 0.5px 0 var(--separator);
}

.nav-title {
  max-width: 62vw;
  margin: 0;
  overflow: hidden;
  font-size: var(--t-headline);
  font-weight: 600;
  line-height: 1.3;
  text-align: center;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.nav-lead,
.nav-trail {
  display: flex;
  align-items: center;
  min-width: 0;
}

.nav-trail {
  justify-content: flex-end;
}

.nav-back {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  min-height: var(--touch);
  padding: 0 var(--s-2) 0 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: var(--t-body);
}

.nav-back .icon {
  margin-right: -2px;
  stroke-width: 2;
}

.nav-back-label {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.nav-back:active {
  opacity: 0.5;
}

.nav-bar .text-btn {
  white-space: nowrap;
}

.nav-bar .text-btn.strong {
  font-weight: 600;
}

/* ── Action sheet (iOS) ───────────────────────────────────── */
.action-sheet.sheet {
  left: var(--s-2);
  right: var(--s-2);
  bottom: max(var(--safe-bottom), var(--s-2));
  padding: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.action-sheet .sheet-grab {
  display: none;
}

.action-sheet .sheet-body {
  padding: 0;
  overflow: visible;
}

.as {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
}

.as-group {
  overflow: hidden;
  border-radius: var(--r-xl);
  background: var(--bg-elevated);
}

.as-head {
  padding: var(--s-4) var(--s-4) var(--s-3);
  text-align: center;
}

.as-title {
  margin: 0;
  color: var(--label-2);
  font-size: var(--t-footnote);
  font-weight: 600;
  line-height: 1.4;
}

.as-msg {
  margin: var(--s-1) 0 0;
  color: var(--label-2);
  font-size: var(--t-footnote);
  line-height: 1.4;
}

.as-error {
  margin: 0;
  padding: 0 var(--s-4) var(--s-3);
  color: var(--danger);
  font-size: var(--t-footnote);
  text-align: center;
}

.as-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  width: 100%;
  min-height: 56px;
  padding: var(--s-2) var(--s-4);
  border: 0;
  border-top: 0.5px solid var(--separator);
  background: transparent;
  color: var(--accent);
  font-size: 1.176rem;
  line-height: 1.3;
}

.as-btn[data-tone="danger"] {
  color: var(--danger);
}

.as-btn .icon {
  position: absolute;
  right: var(--s-4);
  stroke-width: 2;
}

.as-btn:active:not(:disabled) {
  background: var(--fill);
}

.as-btn:disabled:not([data-busy="true"]) {
  opacity: 0.4;
}

.as-head + .as-btn,
.as-group > .as-btn:first-child {
  border-top-color: var(--separator);
}

.as-group > .as-btn:first-child {
  border-top: 0;
}

.as-cancel {
  border: 0;
  border-radius: var(--r-xl);
  background: var(--bg-elevated);
  font-weight: 600;
}

.as-group .cells {
  border-radius: 0;
  background: transparent;
}

.as-group .group {
  margin: 0;
}
