/* What the three <dialog class="modal"> need beyond the themes' .modal rules, which predate <dialog>.
   Position and size live in modals.css, colours in palette.css. */

/* The browser gives dialogs a box of their own; the themes style .modal-content as the box instead. */
dialog.modal {
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
}

/* The themes hide .modal, as Bootstrap showed it by script. */
dialog.modal[open] {
  display: block;
}

dialog.modal::backdrop {
  background: rgb(0 0 0 / 50%);
}

/* The page stays put behind a dialog. Its scrollbar's space is kept on every page, so where a scrollbar takes up
   space, hiding it doesn't shift the page, and a page too short to scroll doesn't shift when a gutter appears. */
html {
  scrollbar-gutter: stable;
}

html:has(dialog.modal[open]) {
  overflow: hidden;
}

/* Bootstrap's fade and slide. Opening starts from @starting-style; closing runs when dialog.js adds .closing, and it
   holds the dialog open until these transitions end. */
@media (prefers-reduced-motion: no-preference) {
  /* Opening, the backdrop comes first and the box after it; closing, the other way round. A transition takes its
     delay from the state being entered. */
  dialog.modal {
    transition: opacity .15s linear .15s;
  }

  dialog.modal::backdrop {
    transition: opacity .15s linear;
  }

  dialog.modal .modal-dialog {
    transition: transform .3s ease-out .15s;
  }

  dialog.modal.closing,
  dialog.modal.closing .modal-dialog {
    transition-delay: 0s;
  }

  dialog.modal.closing::backdrop {
    transition-delay: .15s;
  }

  @starting-style {
    dialog.modal[open],
    dialog.modal[open]::backdrop {
      opacity: 0;
    }

    dialog.modal[open] .modal-dialog {
      transform: translate(0, -25%);
    }
  }

  dialog.modal.closing,
  dialog.modal.closing::backdrop {
    opacity: 0;
  }

  dialog.modal.closing .modal-dialog {
    transform: translate(0, -25%);
  }
}

/* Drawn by the page rather than the browser, so its border matches the sign-in fields' .form-control. */
#sign-in-form input[type="checkbox"] {
  appearance: none;
  width: 14px;
  height: 14px;
  margin-top: 3px;
  border: 1px solid var(--field-edge);
  border-radius: 4px;
  background: var(--field-bg) center / 10px no-repeat;
  box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);
  /* Bootstrap gives a clicked checkbox the browser's focus ring; the keyboard keeps the fields' glow below. */
  outline: 0;
  transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
}

#sign-in-form input[type="checkbox"]:focus-visible {
  border-color: #66afe9;
  box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 8px rgba(102, 175, 233, .6);
}

#sign-in-form input[type="checkbox"]:checked {
  border-color: #d43f3a;
  background-color: #d9534f;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 6.2l2.3 2.3 4.7-5' fill='none' stroke='%23fff' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

/* High-contrast mode drops background colours and images, which would hide the tick. */
@media (forced-colors: active) {
  #sign-in-form input[type="checkbox"] {
    appearance: auto;
  }
}
