/* Sticky form action bar (#270, docs/rebuild/layout.md); markup components/action-bar.blade.php, behaviour
   public/js/action-bar.js. Wide screens: in the page flow, sticks below the red top bar (--action-bar-top) and
   becomes compact. Phones (< 768 px): fixed bottom bar, icons with short labels, rare actions behind "Mehr";
   page-nav.css/js read --action-bar-bottom to keep the scroll buttons and "Inhalt" above it.
   z-index 1020: above the page, below the scroll buttons (1030), the top bar, its panels (1040) and modals. */

:root {
  --action-bar-top: 0px;
  --action-bar-bottom: 0px;
  --action-bar-height: 0px;
  --action-bar-red: #ec0016;
}

/* style.css gives html and body overflow-x: hidden / overflow-y: auto, which makes body a scroll container that
   never scrolls, so position: sticky would never stick. `clip` cuts the same overflow without that. */
html:has(#action-bar),
html:has(#action-bar) body {
  overflow-x: clip !important;
  overflow-y: visible !important;
}

.action-bar-sentinel {
  height: 0;
}

.action-bar {
  position: sticky;
  top: var(--action-bar-top);
  z-index: 1020;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: nowrap;
  gap: 8px 16px;
  margin-bottom: 1rem;
  padding: 10px 14px;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.125);
  border-radius: 0.25rem;
  box-shadow: 0 0 1px rgba(0, 0, 0, 0.125), 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: padding 0.15s ease, box-shadow 0.15s ease;
}

.action-bar.is-stuck {
  padding: 4px 12px;
  border-radius: 0 0 0.25rem 0.25rem;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.18);
}

.action-bar__context {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 12px;
  min-width: 0;
  flex: 0 1 auto;
  max-width: 40%;
}

.action-bar__title {
  font-weight: 600;
  font-size: 1.05rem;
  color: #333;
  overflow-wrap: anywhere;
}

.action-bar.is-stuck .action-bar__title {
  font-size: 0.95rem;
}

.action-bar__dirty {
  color: var(--action-bar-red);
  font-size: 0.875rem;
  font-weight: 600;
  white-space: nowrap;
}

.action-bar__dirty[hidden] {
  display: none;
}

.action-bar__actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 6px;
  margin-left: auto;
}

/* Page buttons keep their own classes; spacing comes from the gap. */
.action-bar__actions .btn {
  margin: 0 !important;
  float: none !important;
  white-space: nowrap;
  padding: 0.3rem 0.7rem;
  font-size: 0.9rem;
}

.action-bar__actions .btn > .fas {
  margin-right: 4px;
}

.action-bar.is-stuck .action-bar__actions .btn {
  padding: 0.2rem 0.6rem;
  font-size: 0.875rem;
}

.action-bar .action-bar__off,
.action-bar .hide {
  display: none !important;
}

/* Unsaved changes: the save buttons stand out. */
.action-bar [data-action-bar-save].is-dirty:not(:disabled) {
  background: var(--action-bar-red);
  border-color: var(--action-bar-red);
  color: #fff;
  box-shadow: 0 0 0 3px rgba(236, 0, 22, 0.25);
}

/* Compact while stuck: one line, the rare actions as icons (their title attribute names them). */
@media (min-width: 768px) {
  .action-bar.is-stuck .action-bar__title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .action-bar.is-stuck .action-bar__more-menu .btn {
    font-size: 0;
    padding: 0.2rem 0.55rem;
  }

  .action-bar.is-stuck .action-bar__more-menu .btn > .fas {
    font-size: 0.875rem;
    margin: 0;
  }
}

/* Wide screens: the rare actions sit inline in front of the others; no "Mehr". */
.action-bar__more,
.action-bar__more-menu {
  display: contents;
}

.action-bar__more-toggle {
  display: none !important;
}

/* Phones: fixed bottom bar. */
@media (max-width: 767.98px) {
  .action-bar,
  .action-bar.is-stuck {
    position: fixed;
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    margin: 0;
    padding: 4px 6px calc(4px + env(safe-area-inset-bottom, 0px));
    border-radius: 0;
    border-width: 1px 0 0;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.15);
    flex-wrap: nowrap;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
  }

  body.has-action-bar-bottom .wrapper {
    padding-bottom: var(--action-bar-bottom);
  }

  /* Context stays in the page header; only the unsaved marker shows (a thin line above the buttons). */
  .action-bar__context {
    justify-content: center;
    max-width: none;
  }

  .action-bar__title {
    display: none;
  }

  .action-bar__dirty {
    font-size: 0.75rem;
    line-height: 1.2;
  }

  .action-bar:not(.is-dirty) .action-bar__context {
    display: none;
  }

  .action-bar__actions {
    flex-wrap: nowrap;
    justify-content: space-around;
    gap: 2px;
    margin: 0;
  }

  .action-bar__actions .btn,
  .action-bar.is-stuck .action-bar__actions .btn {
    flex: 1 1 0;
    min-width: 0;
    max-width: 96px;
    padding: 4px 2px;
    font-size: 0.6875rem;
    line-height: 1.15;
    white-space: normal;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    border-radius: 6px;
  }

  .action-bar__actions .btn > .fas {
    margin: 0;
    font-size: 1rem;
  }

  .action-bar__more {
    display: flex;
    order: 99;
    flex: 1 1 0;
    min-width: 0;
    max-width: 96px;
    position: relative;
  }

  .action-bar__more-toggle {
    display: flex !important;
    width: 100%;
  }

  .action-bar__more-menu {
    display: none;
    position: absolute;
    right: 0;
    bottom: calc(100% + 8px);
    min-width: 220px;
    max-width: calc(100vw - 16px);
    flex-direction: column;
    gap: 4px;
    padding: 6px;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  }

  .action-bar.more-open .action-bar__more-menu {
    display: flex;
  }

  /* The open menu lies over the scroll buttons (1030) and the section sheet (1031). */
  .action-bar.more-open {
    z-index: 1032;
  }

  .action-bar__more-menu .btn,
  .action-bar.is-stuck .action-bar__more-menu .btn {
    flex-direction: row;
    justify-content: flex-start;
    max-width: none;
    width: 100%;
    padding: 8px 12px;
    font-size: 0.875rem;
    gap: 8px;
    text-align: left;
  }
}

@media print {
  .action-bar {
    display: none !important;
  }
}
