/*
 * SweetAlert2 in AppyMenu's look: every popup, alert, confirmation, loader
 * and toast. Loaded after nothing in particular: the selectors out-rank
 * SweetAlert's own (:where()-wrapped) rules.
 *
 * Colours, radii and focus rings are the design tokens in ui.css, which
 * every layout that loads this file loads too; dark mode comes with them.
 *
 * A popup's own button colour (confirmButtonColor, set inline) still wins:
 * red for destructive actions, green for restoring ones. Without one, the
 * primary button is the brand red. Cancel is always the outlined secondary
 * button, whatever colour a caller passed, so every dialog pairs the same way.
 */

/* ── The popup ─────────────────────────────────────────────────────────── */

/* SweetAlert's own defaults live on :root (purple); these are nearer to the
   buttons, and a caller's colour, set on the button itself, is nearer still. */
.swal2-container {
  --swal2-confirm-button-background-color: var(--am-primary);
  --swal2-outline: 0 0 0 3px rgb(var(--am-primary-rgb) / 0.3);
}

.swal2-container.swal2-backdrop-show {
  background: rgb(var(--am-scrim-rgb) / 0.45);
}

.swal2-container .swal2-popup:not(.swal2-toast) {
  width: min(28rem, calc(100vw - 2rem));
  padding: 1.75rem 1.5rem 1.5rem;
  font-family: inherit;
  color: var(--am-text);
  background: var(--am-surface);
  border: 1px solid var(--am-border);
  border-radius: var(--am-radius-card);
  box-shadow: 0 20px 45px -12px rgb(var(--am-scrim-rgb) / 0.25);
}

.swal2-container .swal2-popup .swal2-title {
  padding: 0.25rem 0.5rem 0;
  font-size: 1.125rem;
  font-weight: 600;
  line-height: 1.5rem;
  color: var(--am-text);
}

.swal2-container .swal2-popup .swal2-html-container {
  margin: 0.5rem 0.5rem 0;
  padding: 0;
  font-size: 0.875rem;
  font-weight: 400;
  line-height: 1.375rem;
  color: var(--am-text-muted);
}

.swal2-container .swal2-popup .swal2-close {
  color: var(--am-text-muted);
  border-radius: 10px;
  transition: color 150ms, background-color 150ms;
}

/* Close is neutral, like Cancel. */
.swal2-container .swal2-popup .swal2-close:hover {
  color: var(--am-text);
  background: var(--am-surface-muted);
}

.swal2-container .swal2-popup .swal2-close:focus-visible {
  box-shadow: 0 0 0 2px var(--am-focus-outline);
}

/* ── Buttons ───────────────────────────────────────────────────────────── */

.swal2-container .swal2-popup .swal2-actions {
  gap: 0.5rem;
  margin-top: 1.5rem;
}

.swal2-container .swal2-popup .swal2-styled {
  min-width: 6rem;
  margin: 0;
  padding: 0.625rem 1.25rem;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.25rem;
  border-radius: var(--am-radius-control);
  box-shadow: none;
  transition: background-color 150ms, border-color 150ms, filter 150ms, box-shadow 150ms;
}

/* A caller's confirmButtonColor arrives as this variable on the button. */
.swal2-container .swal2-popup .swal2-styled.swal2-confirm {
  color: var(--am-text-on-color);
  background-color: var(--swal2-confirm-button-background-color, var(--am-primary));
  border: 1px solid transparent;
}

.swal2-container .swal2-popup .swal2-styled.swal2-confirm:hover {
  background-image: none;
  filter: brightness(0.92);
}

.swal2-container .swal2-popup .swal2-styled.swal2-deny {
  color: var(--am-red-fg) !important;
  background-color: var(--am-surface) !important;
  border: 1px solid rgb(var(--am-primary-rgb) / 0.35) !important;
}

/* On the red tint the text goes a shade darker, to keep 4.5:1. */
.swal2-container .swal2-popup .swal2-styled.swal2-deny:hover {
  color: var(--am-red-text) !important;
  background-image: none;
  background-color: var(--am-red-soft) !important;
}

/* The same as .am-btn-secondary on the page. */
.swal2-container .swal2-popup .swal2-styled.swal2-cancel {
  color: var(--am-text) !important;
  background-color: var(--am-surface) !important;
  border: 1px solid var(--am-border) !important;
}

.swal2-container .swal2-popup .swal2-styled.swal2-cancel:hover {
  background-image: none;
  background-color: var(--am-surface-muted) !important;
  border-color: var(--am-border-hover) !important;
}

/* Focus rings are for the keyboard. SweetAlert focuses a popup's default
   button on its own, and after a click or tap that ring only reads as a stray
   border around OK; ui.js puts .am-pointer on <html> while the mouse or touch
   was the last input, so the rings below wait for the keyboard.
   On a white button the ring is a red border and a ring; on a red (coloured)
   button it is a white ring, edged in the button's colour so it shows on white. */
.swal2-container .swal2-popup .swal2-styled:focus,
.swal2-container .swal2-popup .swal2-styled:focus-visible {
  outline: none;
}

html:not(.am-pointer) .swal2-container .swal2-popup .swal2-styled.swal2-confirm:focus-visible {
  border-color: var(--am-surface);
  box-shadow: 0 0 0 2px var(--am-surface), 0 0 0 4px var(--swal2-confirm-button-background-color, var(--am-primary));
}

html:not(.am-pointer) .swal2-container .swal2-popup .swal2-styled.swal2-cancel:focus-visible,
html:not(.am-pointer) .swal2-container .swal2-popup .swal2-styled.swal2-deny:focus-visible {
  border-color: var(--am-focus) !important;
  box-shadow: 0 0 0 3px rgb(var(--am-primary-rgb) / 0.25);
}

/* A popup whose only button closes it (Sync History): its confirm button
   ("Close") is drawn like Cancel (decision 3). The button still confirms. */
.swal2-container .swal2-popup .swal2-styled.swal2-confirm.am-swal-close {
  color: var(--am-text);
  background-color: var(--am-surface);
  border-color: var(--am-border);
}

.swal2-container .swal2-popup .swal2-styled.swal2-confirm.am-swal-close:hover {
  filter: none;
  background-color: var(--am-surface-muted);
  border-color: var(--am-border-hover);
}

html:not(.am-pointer) .swal2-container .swal2-popup .swal2-styled.swal2-confirm.am-swal-close:focus-visible {
  border-color: var(--am-focus);
  box-shadow: 0 0 0 3px rgb(var(--am-primary-rgb) / 0.25);
}

.swal2-container .swal2-popup .swal2-styled:disabled {
  opacity: var(--am-disabled-opacity);
}

.swal2-container .swal2-popup .swal2-loader {
  width: 1.75rem;
  height: 1.75rem;
  border-color: var(--am-primary) transparent var(--am-primary) transparent;
}

.swal2-container .swal2-popup .swal2-footer {
  margin-top: 1.25rem;
  padding-top: 1rem;
  font-size: 0.8125rem;
  color: var(--am-text-muted);
  border-top-color: var(--am-border);
}

/* ── Icons: the brand red for errors, softer amber for warnings ────────── */

.swal2-container .swal2-popup .swal2-icon {
  margin: 0.25rem auto 1rem;
  border-width: 0.2em;
}

.swal2-container .swal2-popup .swal2-icon.swal2-warning {
  color: var(--am-warning);
  border-color: var(--am-warning-ring);
}

.swal2-container .swal2-popup .swal2-icon.swal2-error {
  border-color: rgb(var(--am-primary-rgb) / 0.45);
}

.swal2-container .swal2-popup .swal2-icon.swal2-error [class^="swal2-x-mark-line"] {
  background-color: var(--am-primary);
}

.swal2-container .swal2-popup .swal2-icon.swal2-success {
  border-color: var(--am-success);
  color: var(--am-success);
}

.swal2-container .swal2-popup .swal2-icon.swal2-success .swal2-success-ring {
  border-color: rgb(var(--am-success-rgb) / 0.25);
}

.swal2-container .swal2-popup .swal2-icon.swal2-success [class^="swal2-success-line"] {
  background-color: var(--am-success);
}

.swal2-container .swal2-popup .swal2-icon.swal2-info,
.swal2-container .swal2-popup .swal2-icon.swal2-question {
  color: var(--am-text-muted);
  border-color: var(--am-border);
}

/* ── Inputs inside a popup: the same as .am-field on the page ──────────── */

.swal2-container .swal2-popup .swal2-input,
.swal2-container .swal2-popup .swal2-textarea,
.swal2-container .swal2-popup .swal2-select,
.swal2-container .swal2-popup .swal2-file {
  margin: 1rem auto 0;
  font-family: inherit;
  font-size: 0.875rem;
  color: var(--am-text);
  background: var(--am-field-bg);
  border: 1px solid var(--am-border);
  border-radius: var(--am-radius-control);
  box-shadow: none;
}

.swal2-container .swal2-popup .swal2-input {
  height: var(--am-control-height);
  padding: 0 0.875rem;
}

/* SweetAlert's own #ccc is 1.45:1 on the grey field. */
.swal2-container .swal2-popup :is(.swal2-input, .swal2-textarea)::placeholder {
  color: var(--am-placeholder);
}

.swal2-container .swal2-popup .swal2-input:focus,
.swal2-container .swal2-popup .swal2-textarea:focus,
.swal2-container .swal2-popup .swal2-select:focus {
  border-color: var(--am-focus);
  box-shadow: 0 0 0 3px var(--am-focus-ring);
  outline: none;
}

.swal2-container .swal2-popup .swal2-input-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--am-text);
}

.swal2-container .swal2-popup .swal2-validation-message {
  margin: 1rem 0 0;
  padding: 0.625rem 0.75rem;
  font-size: 0.8125rem;
  color: var(--am-red-text);
  background: var(--am-red-soft);
  border-radius: 10px;
}

.swal2-container .swal2-popup .swal2-validation-message::before {
  background-color: var(--am-primary);
}

.swal2-container .swal2-popup .swal2-checkbox input,
.swal2-container .swal2-popup .swal2-radio input {
  accent-color: var(--am-primary);
}

.swal2-container .swal2-popup .swal2-timer-progress-bar {
  background: rgb(var(--am-primary-rgb) / 0.45);
}

/* ── Toasts ────────────────────────────────────────────────────────────── */

.swal2-container .swal2-popup.swal2-toast {
  padding: 0.75rem 1rem;
  font-family: inherit;
  color: var(--am-text);
  background: var(--am-surface);
  border: 1px solid var(--am-border);
  border-radius: 12px;
  box-shadow: 0 10px 30px -10px rgb(var(--am-scrim-rgb) / 0.3);
}

.swal2-container .swal2-popup.swal2-toast .swal2-title {
  margin: 0 0.5rem;
  padding: 0;
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.25rem;
}

.swal2-container .swal2-popup.swal2-toast .swal2-html-container {
  margin: 0.25rem 0.5rem 0;
  font-size: 0.8125rem;
}

.swal2-container .swal2-popup.swal2-toast .swal2-icon {
  margin: 0 0.25rem 0 0;
}

/* ── Dark mode ─────────────────────────────────────────────────────────────
 * The tokens switch on their own; what is left are values with no token. */

/* Body text a step brighter than the dark muted token, for reading. */
.dark .swal2-container .swal2-popup .swal2-html-container,
.dark .swal2-container .swal2-popup .swal2-footer {
  color: var(--am-grey-text);
}

html.dark:not(.am-pointer) .swal2-container .swal2-popup .swal2-styled.swal2-confirm:focus-visible {
  box-shadow: 0 0 0 2px var(--am-text-on-color), 0 0 0 4px var(--swal2-confirm-button-background-color, var(--am-primary));
}

/* The Cancel-look Close keeps Cancel's focus in dark mode too. */
html.dark:not(.am-pointer) .swal2-container .swal2-popup .swal2-styled.swal2-confirm.am-swal-close:focus-visible {
  box-shadow: 0 0 0 3px rgb(var(--am-primary-rgb) / 0.25);
}

/* The success tick's masks have to be the popup's own colour. */
.dark .swal2-container .swal2-popup .swal2-icon.swal2-success .swal2-success-circular-line-left,
.dark .swal2-container .swal2-popup .swal2-icon.swal2-success .swal2-success-circular-line-right,
.dark .swal2-container .swal2-popup .swal2-icon.swal2-success .swal2-success-fix {
  background-color: var(--am-surface) !important;
}
