/* The windows that talk to the visitor: success, information, error.
 * Markup in templates/includes/messages.html, behaviour in js/public/message.js.
 *
 * Self-contained, like the cookie banner and for the same reason: all four base
 * templates carry it, and the three legacy ones link only tokens.css beside it.
 * There is no base.css there, and Bootstrap's reset and styles.css are unlayered,
 * so every property this component relies on is written out here - the type
 * chain, the margins, the button's own look, the focus ring. No <b> or
 * <strong> inside: styles.css forces them to 700 with !important.
 *
 * One look, two ways of showing it. showModal() puts the dialog in the browser's
 * top layer, above everything. Where <dialog> has no showModal (Firefox 97, the
 * baseline) the script sets `open` instead, and the z-index below carries it
 * above Bootstrap's window at 1055. Both end up with `open`, so one rule set
 * serves both.
 */

/* The browser styles a <dialog> - border, padding, Canvas background,
   fit-content size, auto margins. Start from nothing. */
.ui-message {
  box-sizing: border-box;
  position: fixed;
  inset: 0;
  z-index: var(--ui-z-message);
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: var(--ui-space-5);
  border: 0;
  overflow: auto;
  overscroll-behavior: contain;
  background: var(--ui-color-scrim);
  color: var(--ui-color-ink);
  font-family: var(--ui-font-body);
  font-size: var(--ui-text-base);
  font-weight: var(--ui-weight-regular);
  line-height: var(--ui-leading-normal);
  letter-spacing: normal;
  text-align: left;
  text-transform: none;
}

.ui-message[open] {
  display: flex;
}

/* The script focuses the dialog itself, so a screen reader reads the heading
   before the buttons; the ring belongs on the controls. */
.ui-message:focus-visible {
  outline: none;
}

.ui-message__inner {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--ui-space-4);
  width: 100%;
  max-width: 30rem;
  margin: auto;
  padding: var(--ui-space-6);
  border-radius: var(--ui-radius-lg);
  background: var(--ui-color-surface);
  box-shadow: var(--ui-shadow-raised);
}

/* A drawn mark instead of the old photograph: it says which of the three this
   is before the heading is read, and it costs no request. */
.ui-message__mark {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: var(--ui-touch);
  height: var(--ui-touch);
  border-radius: var(--ui-radius-pill);
}

.ui-message--success .ui-message__mark {
  background: var(--ui-color-tint-1-bg);
  color: var(--ui-color-tint-1-ink);
}

.ui-message--info .ui-message__mark {
  background: var(--ui-color-tint-4-bg);
  color: var(--ui-color-tint-4-ink);
}

.ui-message--error .ui-message__mark {
  background: var(--ui-color-tint-5-bg);
  color: var(--ui-color-tint-5-ink);
}

/* Bootstrap's reboot styles h2 on the legacy pages; this sets all of it. */
.ui-message__title {
  margin: 0;
  padding: 0;
  color: var(--ui-color-ink);
  font-family: var(--ui-font-heading);
  font-size: var(--ui-text-xl);
  font-weight: var(--ui-weight-semibold);
  line-height: var(--ui-leading-tight);
  letter-spacing: normal;
  text-transform: none;
}

/* The body is HTML built in Python, so nothing inside it can carry a ui- class
   - and a component may not style bare elements. Both kinds therefore arrive as
   text separated by <br>, which needs no rules of its own: the message filters
   use linebreaksbr, not linebreaks. A message that one day needs a list or a
   link would have to become .ui-richtext, and base.css does not reach the
   legacy pages. */
.ui-message__text {
  max-width: 60ch;
  margin: 0;
  padding: 0;
  color: var(--ui-color-ink-soft);
  font: inherit;
}

.ui-message__actions {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  gap: var(--ui-space-3);
  margin: 0;
  padding: 0;
  list-style: none;
}

.ui-message__button,
.ui-message__button:visited {
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 8rem;
  min-height: var(--ui-touch);
  margin: 0;
  padding: var(--ui-space-2) var(--ui-space-5);
  border: 1px solid var(--ui-color-brand);
  border-radius: var(--ui-radius-pill);
  background: var(--ui-color-brand);
  color: var(--ui-color-on-band);
  font-family: inherit;
  font-size: var(--ui-text-md);
  font-weight: var(--ui-weight-semibold);
  line-height: 1.2;
  letter-spacing: normal;
  text-align: center;
  text-decoration: none;
  text-transform: none;
  cursor: pointer;
  appearance: none;
  transition: background-color var(--ui-duration);
}

.ui-message__button:hover {
  background: var(--ui-color-brand-hover);
  border-color: var(--ui-color-brand-hover);
  color: var(--ui-color-on-band);
  text-decoration: none;
}

.ui-message__button:focus-visible {
  outline: 2px solid var(--ui-color-focus);
  outline-offset: 2px;
}

@media (min-width: 600px) {
  .ui-message__inner {
    padding: var(--ui-space-7);
  }
}

/* An open window would otherwise print as a dimmed page. */
@media print {
  .ui-message,
  .ui-message[open] {
    display: none;
  }
}

/* Last, so it beats the rule above: a window hidden by attribute stays hidden.
   base.css supplies this with !important on the new pages; the legacy pages do
   not load base.css, so the component supplies it by specificity instead. */
.ui-message[hidden] {
  display: none;
}
