/* ==========================================================================
   Form layout — the shapes admin forms keep needing.

   .form-stack          fields one under another, evenly spaced
   .form-inline         fields in a row that wraps (filter bars); buttons line up with the fields
   .form-horizontal     labels beside the fields on wide screens (one .field-horizontal for a single field)
   .form-section        settings pages: title + description on the left, fields on the right
   .form-actions        the buttons at the end; .form-actions-sticky keeps them at the bottom of the screen
   Unsaved changes: <form data-moey-dirty> gets .is-dirty while it differs from how it loaded
   (with .form-actions-dirty the bar only shows then) and warns before leaving the page.
   Side-by-side fields: use the grid (.grid + .span-12 .md:span-6 on each .field).
   ========================================================================== */

.form-stack { display: grid; gap: var(--mo-form-gap, 1rem); align-content: start; }

/* Inline: a row of fields that wraps */
.form-inline { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; }
.form-inline > .field { flex: 1 1 var(--mo-form-inline-min, 11rem); min-width: 0; }
.form-inline > :is(.btn, .btn-group) { flex: none; }
.form-inline > .form-check { align-self: center; }

/* Horizontal: label on the left (from 768px) */
@media (width >= 768px) {
  .form-horizontal .field:has(> .form-label),
  .field-horizontal {
    grid-template-columns: var(--mo-form-label-width, 12rem) minmax(0, 1fr);
    column-gap: 1.5rem;
    align-items: start;
  }
  :is(.form-horizontal .field, .field-horizontal) > .form-label {
    grid-column: 1;
    grid-row: 1;
    margin: 0;
    padding-top: calc((var(--mo-control-height) - 1.5em) / 2);
  }
  :is(.form-horizontal .field:has(> .form-label), .field-horizontal) > :not(.form-label) { grid-column: 2; }
  .form-horizontal > .form-actions,
  .form-horizontal .form-actions-indent { padding-inline-start: calc(var(--mo-form-label-width, 12rem) + 1.5rem); justify-content: flex-start; }
}

/* Settings sections */
.form-section {
  display: grid;
  gap: 1rem 2.5rem;
  padding-block: 1.75rem;
}
.form-section:first-child { padding-top: 0; }
.form-section + .form-section { border-top: var(--mo-border-width) solid var(--mo-border-color); }
@media (width >= 992px) { .form-section { grid-template-columns: minmax(0, var(--mo-form-section-aside, 17rem)) minmax(0, 1fr); } }
.form-section-header > :is(h2, h3, h4, .form-section-title) { margin: 0 0 .25rem; font-size: 1rem; }
.form-section-header > p { margin: 0; font-size: .875rem; color: var(--mo-fg-3); }
.form-section-body { display: grid; gap: var(--mo-form-gap, 1rem); min-width: 0; }

/* The buttons */
.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  align-items: center;
  justify-content: flex-end;
  padding-top: 1rem;
}
.form-actions-note { margin-inline-end: auto; font-size: .875rem; color: var(--mo-fg-3); }
.form-actions-start { justify-content: flex-start; }
@media (width < 576px) { .form-actions:not(.form-actions-start) > .btn { flex: 1 1 auto; } }

.form-actions-sticky {
  position: sticky;
  bottom: 0;
  z-index: 5;
  padding: .75rem 1rem calc(.75rem + env(safe-area-inset-bottom));
  margin-top: 1rem;
  background: color-mix(in oklab, var(--mo-bg-raised) 90%, transparent);
  border-radius: var(--mo-radius-card);
  box-shadow: 0 -.25rem 1.5rem rgb(0 0 0 / .08), 0 0 0 var(--mo-border-width) var(--mo-border-color);
  backdrop-filter: blur(.5rem);
}

/* Only while there are unsaved changes */
form:not(.is-dirty) .form-actions-dirty { display: none; }
@media (prefers-reduced-motion: no-preference) {
  form.is-dirty .form-actions-dirty { animation: mo-form-dirty .2s ease-out; }
  @keyframes mo-form-dirty { from { opacity: 0; translate: 0 .5rem; } }
}
.form-dirty-dot {
  display: inline-block;
  width: .5rem;
  height: .5rem;
  margin-inline-end: .375rem;
  background: var(--mo-amber-solid);
  border-radius: 50%;
}
