/* Shared motion for every page: page-to-page transitions, entrances, dialogs, toasts and feedback.
   Everything here is progressive: browsers without these features simply skip the animation. */
:root {
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --ease-spring: cubic-bezier(0.34, 1.4, 0.64, 1);
  --dur-fast: 140ms;
  --dur: 240ms;
  --dur-slow: 420ms;
  --toast-offset: 24px;
}

/* Page-to-page: the header stays put while the page content cross-fades and settles in. The opt-in itself,
   @view-transition { navigation: auto }, is a small <style> in each page's <head>, not in this file: Chrome decides
   very early whether the next page wants a transition, and from a stylesheet file the rule sometimes arrived too late,
   so Chrome skipped the transition ("ViewTransition opt-in disabled"). */
.topbar {
  view-transition-name: app-header;
  /* The header (and its account menu) must stay above the page content, which is its own layer. */
  position: relative;
  z-index: 30;
}
main {
  view-transition-name: app-main;
}
.site-credit {
  view-transition-name: app-credit;
}
::view-transition-group(root),
::view-transition-group(app-header),
::view-transition-group(app-credit) {
  animation-duration: var(--dur);
  animation-timing-function: var(--ease-in-out);
}
::view-transition-old(app-main) {
  animation: vt-out 160ms var(--ease-in-out) both;
}
::view-transition-new(app-main) {
  animation: fade-in 320ms var(--ease-out) 60ms both;
}
::view-transition-group(app-main) {
  animation-duration: 0s;
}
@keyframes vt-out {
  to {
    opacity: 0;
    transform: translateY(-6px);
  }
}
/* First paint of a page: sections rise in with a short top-to-bottom stagger.
   "backwards" fill keeps nothing applied afterwards, so fixed-position children are never affected. */
@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}
@keyframes fade-in {
  from {
    opacity: 0;
  }
}
main > *,
.workspace > form > .form-section,
.workspace > .preview-panel {
  animation: rise-in 420ms var(--ease-out) backwards;
  animation-delay: calc(var(--enter, 0) * 45ms);
}
main > .workspace {
  animation: none;
}
main > :nth-child(2) {
  --enter: 1;
}
main > :nth-child(3) {
  --enter: 2;
}
main > :nth-child(n + 4),
.workspace > form > .form-section {
  --enter: 3;
}
.workspace > form > .form-section:nth-of-type(2),
.workspace > .preview-panel {
  --enter: 4;
}
.workspace > form > .form-section:nth-of-type(3) {
  --enter: 5;
}
.workspace > form > .form-section:nth-of-type(n + 4) {
  --enter: 6;
}

/* Elements added or removed while you work. */
.motion-enter {
  animation: rise-in 320ms var(--ease-out) backwards;
}
.motion-leave {
  animation: leave 200ms var(--ease-in-out) both;
  pointer-events: none;
}
@keyframes leave {
  to {
    opacity: 0;
    transform: translateY(-4px) scale(0.985);
  }
}
.motion-flash {
  animation: flash 900ms var(--ease-out);
}
@keyframes flash {
  from {
    background-color: #fff3c4;
  }
}
.motion-pop {
  animation: pop 360ms var(--ease-spring);
}
@keyframes pop {
  from {
    transform: scale(0.6);
    opacity: 0.4;
  }
}

/* Controls respond immediately to touch and hover. */
.button,
.chip,
.app-nav a,
.icon-button,
.remove,
summary {
  transition:
    background-color var(--dur-fast) ease,
    border-color var(--dur-fast) ease,
    color var(--dur-fast) ease,
    box-shadow var(--dur) var(--ease-out),
    transform var(--dur-fast) var(--ease-out),
    opacity var(--dur-fast) ease;
}
.button:not(:disabled):active,
.chip:not(:disabled):active,
.icon-button:active {
  transform: translateY(1px) scale(0.985);
}
.primary:not(:disabled):hover {
  box-shadow: 0 8px 18px #1a71922e;
}
input,
select,
textarea {
  transition:
    border-color var(--dur-fast) ease,
    outline-color var(--dur-fast) ease,
    background-color var(--dur-fast) ease,
    box-shadow var(--dur-fast) ease;
}

/* Busy buttons keep their size and show a small spinner. */
.button.is-busy {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}
.button.is-busy::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-color: #ffffffb3 #ffffffb3 #ffffffb3 transparent;
  animation: spin 700ms linear infinite;
}
.button.secondary.is-busy::after {
  border-color: #287eb1 #287eb1 #287eb1 transparent;
}
/* A busy button that has focus keeps it (motion.mjs marks it aria-disabled, not disabled), so it gets the disabled look here. */
button[aria-busy="true"][aria-disabled="true"] {
  opacity: 0.55;
  cursor: wait;
}
.button[aria-busy="true"][aria-disabled="true"]:active {
  transform: none;
}
@keyframes spin {
  to {
    transform: rotate(1turn);
  }
}

/* Dialogs fade and lift in, and fade out when closed. */
dialog {
  opacity: 0;
  transform: translateY(14px) scale(0.985);
  transition:
    opacity var(--dur) var(--ease-out),
    transform var(--dur-slow) var(--ease-out),
    overlay var(--dur) allow-discrete,
    display var(--dur) allow-discrete;
}
dialog[open] {
  opacity: 1;
  transform: none;
}
@starting-style {
  dialog[open] {
    opacity: 0;
    transform: translateY(14px) scale(0.985);
  }
}
dialog::backdrop {
  background-color: rgb(16 54 77 / 0);
  backdrop-filter: blur(0);
  transition:
    background-color var(--dur) ease,
    backdrop-filter var(--dur) ease,
    overlay var(--dur) allow-discrete,
    display var(--dur) allow-discrete;
}
dialog[open]::backdrop {
  background-color: rgb(16 54 77 / 0.45);
  backdrop-filter: blur(3px);
}
@starting-style {
  dialog[open]::backdrop {
    background-color: rgb(16 54 77 / 0);
    backdrop-filter: blur(0);
  }
}

/* Expanding sections open smoothly where the browser supports animating to "auto". */
@supports (interpolate-size: allow-keywords) {
  :root {
    interpolate-size: allow-keywords;
  }
  details::details-content {
    height: 0;
    overflow: clip;
    transition:
      height var(--dur) var(--ease-out),
      content-visibility var(--dur) allow-discrete;
  }
  details[open]::details-content {
    height: auto;
  }
}

/* Loading placeholders. */
.skeleton {
  display: block;
  border-radius: 8px;
  background: linear-gradient(90deg, #e8eff4 25%, #f4f8fb 37%, #e8eff4 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease infinite;
  color: transparent !important;
}
.skeleton-line {
  height: 14px;
  margin: 10px 0;
}
.skeleton-card {
  height: 96px;
  margin: 12px 0;
  border-radius: 12px;
}
@keyframes shimmer {
  from {
    background-position: 100% 50%;
  }
  to {
    background-position: 0 50%;
  }
}

/* Thin progress bar while the next page loads. */
.nav-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  z-index: 1000;
  pointer-events: none;
  transform-origin: left;
  transform: scaleX(0);
  opacity: 0;
  background: linear-gradient(90deg, #287eb1, #5fb3e3);
}
html.is-navigating .nav-progress {
  opacity: 1;
  animation: nav-progress 2.4s var(--ease-out) forwards;
}
@keyframes nav-progress {
  from {
    transform: scaleX(0.05);
  }
  to {
    transform: scaleX(0.92);
  }
}

/* Toast notifications. */
.toast-region {
  position: fixed;
  left: 50%;
  bottom: calc(var(--toast-offset) + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 900;
  display: grid;
  gap: 10px;
  width: min(460px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 13px 14px 13px 16px;
  border-radius: 12px;
  background: #10364d;
  color: #fff;
  box-shadow:
    0 12px 32px #10364d40,
    0 2px 6px #10364d26;
  font-size: 0.9rem;
  line-height: 1.45;
  animation: toast-in 320ms var(--ease-spring) backwards;
}
.toast.leaving {
  animation: toast-out 200ms var(--ease-in-out) both;
}
.toast-icon {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.8rem;
  font-weight: 700;
  background: #ffffff26;
}
.toast-success .toast-icon {
  background: #2e9d62;
}
.toast-error .toast-icon {
  background: #c8483f;
}
.toast-warning .toast-icon {
  background: #d99a1e;
}
.toast-message {
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: anywhere;
}
.toast button {
  font: inherit;
  font-weight: 700;
  color: #9fd4f5;
  background: none;
  border: 0;
  padding: 0 2px;
  cursor: pointer;
}
.toast .toast-close {
  color: #ffffffb3;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0 0 0 4px;
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.96);
  }
}
@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
  .skeleton {
    animation: none !important;
  }
}
