/*
  The page skeleton (docs/design/slice-00-scaffold.md, "Page skeleton"): app bar actions and the ⋯ menu, view tabs,
  the entry dock, the snackbar and the sheet. Loaded after every feature stylesheet, so a shared part looks the same
  on every page. Features place these parts; they do not restyle them.
*/

/* --- app bar: back, icon actions, ⋯ menu ------------------------------------------------------------------- */

.hw-appbar-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: none;
  margin-right: -8px;
}

.hw-appbar-icon,
.hw-appbar-icon:hover:not(:disabled) {
  position: relative;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--bsft-color-muted);
}

.hw-appbar-icon:hover:not(:disabled) {
  background: var(--hw-surface-2);
  color: var(--bsft-color-text);
}

.hw-appbar-icon .hw-icon {
  width: 22px;
  height: 22px;
}

.hw-appbar-icon[aria-pressed="true"],
.hw-appbar-icon[aria-pressed="true"]:hover:not(:disabled),
.hw-appbar-icon[aria-expanded="true"] {
  background: var(--hw-accent-soft);
  color: var(--bsft-color-primary);
}

.hw-appbar-back {
  margin-left: -10px;
  color: var(--bsft-color-text);
}

/* A sub-page's own title ("Reihenfolge im Laden") sits beside the back button: a step smaller on phones, so it stays
   on one line at 360px. */
@media (max-width: 899.98px) {
  .hw-appbar:has(.hw-appbar-back) .hw-title {
    font-size: 20px;
    line-height: 1.15;
  }
}

.hw-appbar-dot {
  position: absolute;
  top: 9px;
  right: 9px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--bsft-color-primary);
  box-shadow: 0 0 0 2px var(--hw-ground);
}

.hw-menu-anchor {
  position: relative;
  flex: none;
}

.hw-menu-scrim {
  position: fixed;
  inset: 0;
  z-index: 30;
}

.hw-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 31;
  display: flex;
  flex-direction: column;
  min-width: 230px;
  max-width: calc(100vw - 24px);
  padding: 6px;
  border: 1px solid var(--bsft-color-border);
  border-radius: 16px;
  background: var(--bsft-color-surface);
  box-shadow: 0 18px 40px -16px rgba(0, 0, 0, 0.35);
  animation: hw-fade 0.12s ease-out;
}

.hw-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 46px;
  padding: 8px 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--bsft-color-text);
  font-size: 15px;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.hw-menu-item:hover:not(:disabled),
.hw-menu-item:focus-visible {
  background: var(--hw-surface-2);
}

.hw-menu-item:focus-visible {
  outline-offset: -2px;
}

.hw-menu-item .hw-icon {
  width: 20px;
  height: 20px;
  color: var(--bsft-color-muted);
}

.hw-menu-item:disabled {
  opacity: 0.45;
  cursor: default;
}

.hw-menu-separator {
  margin: 4px 6px;
  border: 0;
  border-top: 1px solid var(--bsft-color-border);
}

.hw-menu > .hw-menu-separator:first-child {
  display: none;
}

/* --- view tabs ------------------------------------------------------------------------------------------ */

.hw-page-tabs {
  display: flex;
  width: 100%;
}

.hw-page-tabs > * {
  flex: 1 1 0;
}

/* --- entry field and dock ------------------------------------------------------------------------------ */

.hw-entry-field {
  display: flex;
  flex-direction: column;
}

.hw-entry-submit,
.hw-entry-submit:hover:not(:disabled) {
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: var(--bsft-color-primary);
  color: var(--bsft-color-primary-contrast);
}

.hw-entry-submit:hover:not(:disabled) {
  filter: brightness(1.08);
}

/* The dock is the last part of the page and sticks above the tab bar. While the keyboard is open on a phone the tab
   bar steps aside and the dock sits directly on the keyboard: the keyboard shrinks the viewport
   (interactive-widget=resizes-content), and where a browser overlays it instead, --hw-keyboard-inset lifts the dock. */
.hw-entry-dock {
  position: sticky;
  bottom: calc(var(--hw-tabbar-height) + env(safe-area-inset-bottom));
  z-index: 4;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: auto -16px -24px;
  padding: 8px 16px 10px;
  background: var(--hw-ground);
}

.hw-entry-dock-preview {
  max-height: min(40vh, 280px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.hw-entry-dock-preview:empty {
  display: none;
}

@media (max-width: 899.98px) {
  html[data-hw-keyboard] .hw-entry-dock {
    bottom: var(--hw-keyboard-inset);
  }

  html[data-hw-keyboard] .hw-nav {
    visibility: hidden;
  }

  html[data-hw-keyboard] .hw-snackbar {
    bottom: calc(var(--hw-keyboard-inset) + 14px);
  }

  html[data-hw-keyboard] .hw-app:has(.hw-entry-dock) .hw-snackbar {
    bottom: calc(var(--hw-keyboard-inset) + 76px);
  }
}

@media (min-width: 900px) {
  .hw-entry-dock {
    bottom: 0;
    margin: auto -32px -48px;
    padding: 12px 32px 20px;
  }
}

/* --- rows: the row a sheet belongs to, and the changed row --------------------------------------------- */

.is-sheet-open {
  background: var(--hw-accent-soft);
}

.is-flashed {
  animation: hw-row-flash 1.4s ease-out;
}

@keyframes hw-row-flash {
  from { background: var(--hw-accent-soft); }
  to { background: transparent; }
}

@keyframes hw-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes hw-sheet-up {
  from { transform: translateY(24px); opacity: 0.4; }
  to { transform: none; opacity: 1; }
}

/* --- sheet (HwSheet) ------------------------------------------------------------------------------------ */

.bsft-dialog-overlay:has(> .bsft-dialog-panel > .hw-sheet-frame) {
  z-index: 40;
  align-items: flex-end;
  padding: 0 0 var(--hw-keyboard-inset);
  background: rgba(10, 15, 12, 0.45);
  animation: hw-fade 0.16s ease-out;
}

.bsft-dialog-panel:has(> .hw-sheet-frame) {
  width: 100%;
  max-width: 560px;
  max-height: calc(100dvh - var(--hw-keyboard-inset) - 24px - env(safe-area-inset-top));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0;
  border-radius: 26px 26px 0 0;
  animation: hw-sheet-up 0.22s ease-out;
}

.hw-sheet.hw-sheet-frame {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: auto;
  max-width: none;
  max-height: none;
  overflow: visible;
  border-radius: 0;
  padding: 10px 18px 0;
}

.hw-sheet-head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.hw-sheet-heading {
  flex: 1;
  min-width: 0;
}

.hw-sheet-frame .hw-sheet-title {
  font-size: 24px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.hw-sheet-subtitle {
  margin: 4px 0 0;
  font-size: 14px;
  color: var(--bsft-color-muted);
}

.hw-sheet-close {
  margin: -6px -10px 0 0;
}

.hw-sheet-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.hw-sheet-footer {
  position: sticky;
  bottom: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 -18px;
  padding: 12px 18px calc(16px + env(safe-area-inset-bottom));
  background: var(--bsft-color-surface);
}

.hw-sheet-footer > * {
  flex: 1 1 auto;
}

.hw-sheet-footer > .bsft-button-primary {
  flex-basis: 100%;
  min-height: 48px;
}

html[data-hw-keyboard] .hw-sheet-footer {
  padding-bottom: 12px;
}

@media (min-width: 900px) {
  .bsft-dialog-overlay:has(> .bsft-dialog-panel > .hw-sheet-frame) {
    align-items: center;
    padding: 24px;
  }

  .bsft-dialog-panel:has(> .hw-sheet-frame) {
    max-width: 440px;
    max-height: calc(100dvh - 48px);
    border-radius: 22px;
    animation: hw-fade 0.16s ease-out;
  }

  .hw-sheet-frame .hw-sheet-grab {
    display: none;
  }

  .hw-sheet.hw-sheet-frame {
    padding-top: 18px;
  }

  .hw-sheet-footer {
    padding-bottom: 18px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .bsft-dialog-panel:has(> .hw-sheet-frame),
  .bsft-dialog-overlay:has(> .bsft-dialog-panel > .hw-sheet-frame) {
    animation: hw-fade 0.16s ease-out !important;
  }

  .is-flashed {
    animation: hw-row-flash 1.4s ease-out !important;
  }
}

/* --- sheet questions, add rows and link rows ------------------------------------------------------------ */

/* A confirmation asked in a sheet's footer takes the whole line above its two answers. */
.hw-sheet-question {
  flex-basis: 100%;
  margin: 0;
  font-weight: 700;
}

/* The dashed last row of a list that opens the sheet for a new entry. */
.hw-add-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 48px;
  margin-top: 10px;
  padding: 8px 12px;
  border: 1.5px dashed var(--bsft-color-border);
  border-radius: 14px;
  background: transparent;
  color: var(--bsft-color-muted);
  font: inherit;
  cursor: pointer;
}

.hw-add-row:hover:not(:disabled) {
  border-color: var(--bsft-color-primary);
  color: var(--bsft-color-text);
}

/* A grouped list card of places to go: icon, label and a chevron, one row per destination. */
.hw-link-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.hw-link-list > li + li {
  border-top: 1px solid var(--bsft-color-border);
}

.hw-link-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 6px 0;
  color: var(--bsft-color-text);
  text-decoration: none;
}

.hw-link-row > .hw-icon {
  flex: none;
  color: var(--bsft-color-muted);
}

.hw-link-row-text {
  flex: 1;
  min-width: 0;
}

.hw-link-row-chevron {
  display: inline-flex;
  flex: none;
  color: var(--bsft-color-muted);
}

.hw-link-row:hover .hw-link-row-text {
  color: var(--bsft-color-primary);
}

/* --- snackbar (HwSnackbar, IHwSnackbar): the mock's toast ------------------------------------------------ */

.hw-snackbar {
  position: fixed;
  left: 14px;
  right: 14px;
  bottom: calc(var(--hw-tabbar-height) + 14px + env(safe-area-inset-bottom));
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 6px 8px 14px;
  border-radius: 14px;
  background: var(--bsft-color-text);
  color: var(--bsft-color-surface);
  font-size: 14px;
  box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
  animation: hw-fade 0.16s ease-out;
}

/* Above the entry dock where a page has one. */
.hw-app:has(.hw-entry-dock) .hw-snackbar {
  bottom: calc(var(--hw-tabbar-height) + 76px + env(safe-area-inset-bottom));
}

/* The text wraps inside its own box, so the action and the close button stay on the first line even at 360px. */
.hw-snackbar-text {
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: anywhere;
}

.hw-snackbar-actions,
.hw-snackbar-close {
  flex: none;
}

.hw-snackbar-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.hw-snackbar-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--hw-accent-soft);
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.hw-snackbar-action .hw-icon {
  width: 18px;
  height: 18px;
}

.hw-snackbar-action:focus-within,
.hw-snackbar-action:focus-visible {
  outline: 2px solid var(--hw-accent-soft);
  outline-offset: 1px;
}

.hw-snackbar-action.is-disabled,
.hw-snackbar-action:disabled {
  opacity: 0.6;
}

.hw-snackbar-close {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 0;
  background: transparent;
  color: inherit;
  opacity: 0.7;
  cursor: pointer;
}

.hw-snackbar-close .hw-icon {
  width: 16px;
  height: 16px;
}

@media (min-width: 900px) {
  .hw-snackbar {
    left: calc(var(--hw-desktop-nav-width) + max(32px, (100vw - var(--hw-desktop-nav-width) - var(--hw-content-width)) / 2 + 32px));
    right: auto;
    bottom: 24px;
    width: min(560px, calc(100vw - var(--hw-desktop-nav-width) - 64px));
  }

  .hw-app:has(.hw-entry-dock) .hw-snackbar {
    bottom: 96px;
  }
}

/* --- image viewer (HwImageViewer) ---------------------------------------------------------------------------
  A full-screen dark dialog over everything, in both themes. The picture fits the screen; the browser module moves it
  (the growth out of the thumbnail, swipes, zoom), so the stage takes every touch itself. The buttons are the shared
  app bar icons; only their tokens change on the dark ground. */

html.hw-viewer-is-open,
html.hw-viewer-is-open body {
  overflow: hidden;
}

.hw-viewer {
  --bsft-color-text: #FFFFFF;
  --bsft-color-muted: rgba(255, 255, 255, 0.88);
  --hw-surface-2: rgba(255, 255, 255, 0.16);
  position: fixed;
  inset: 0;
  z-index: 1900;
  color: #FFFFFF;
  outline: none;
}

.hw-viewer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 11, 9, 0.96);
}

.hw-viewer-stage {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: calc(60px + env(safe-area-inset-top)) calc(8px + env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) calc(8px + env(safe-area-inset-left));
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.hw-viewer-image {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  transform-origin: center;
  -webkit-touch-callout: default;
}

.hw-viewer-preload {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.hw-viewer-close {
  position: absolute;
  top: calc(8px + env(safe-area-inset-top));
  right: calc(8px + env(safe-area-inset-right));
}

.hw-viewer-counter {
  position: absolute;
  top: calc(18px + env(safe-area-inset-top));
  left: 50%;
  margin: 0;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  font-family: var(--hw-font-mono);
  font-size: 14px;
  translate: -50% 0;
  pointer-events: none;
}

.hw-viewer-previous,
.hw-viewer-next {
  position: absolute;
  top: calc(50% - 22px);
}

.hw-viewer-previous {
  left: calc(12px + env(safe-area-inset-left));
}

.hw-viewer-next {
  right: calc(12px + env(safe-area-inset-right));
}

/* Touch screens swipe; the arrow buttons are for a mouse. */
@media (hover: none) {
  .hw-viewer-previous,
  .hw-viewer-next {
    display: none;
  }
}

@media (min-width: 900px) {
  .hw-viewer-stage {
    padding: 64px 76px;
  }
}

/* A thumbnail that opens in the viewer. */
[data-hw-viewer-origin] {
  cursor: zoom-in;
}
