/* Ugarit Inventory: a small, optional motion layer.
 * Load after the existing styles and opt in on the document root with
 * .ugarit-motion-ready. Data, form layout and print geometry stay in the app.
 */
.ugarit-motion-ready {
  --ugarit-motion-ink: #452153;
  --ugarit-motion-press: #f9df72;
  --ugarit-motion-ease: cubic-bezier(.2, .75, .25, 1);
  --ugarit-motion-fast: 140ms;
  --ugarit-motion-enter: 260ms;
}

.ugarit-motion-ready :is(.ugarit-animated-number, .ugarit-number-visual, .ugarit-number-final) {
  /* Summary cards also style every descendant span as a small label. */
  display: inline;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

/* Announce the exact final number once; intermediate digits can be aria-hidden.
 * This helper never changes the accessible name or live-region policy itself.
 */
.ugarit-motion-ready .ugarit-sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  clip-path: inset(50%) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

@media screen {
  /* A page can contain fixed notices and active inputs. Opacity alone avoids
   * creating a new containing block or shifting a field under the user's hand.
   */
  .ugarit-motion-ready .ugarit-page-enter {
    animation: ugarit-page-appear var(--ugarit-motion-enter)
      var(--ugarit-motion-ease) backwards;
  }

  /* Only the small summary grids get staggered entrances, never stock rows. */
  .ugarit-motion-ready :is(.executive-stats, .order-summary-grid) > button {
    animation: ugarit-card-appear 320ms var(--ugarit-motion-ease) backwards;
  }
  .ugarit-motion-ready :is(.executive-stats, .order-summary-grid) > button:nth-child(2) {
    animation-delay: 35ms;
  }
  .ugarit-motion-ready :is(.executive-stats, .order-summary-grid) > button:nth-child(3) {
    animation-delay: 70ms;
  }
  .ugarit-motion-ready :is(.executive-stats, .order-summary-grid) > button:nth-child(4) {
    animation-delay: 105ms;
  }

  .ugarit-motion-ready .ugarit-number-changed {
    border-radius: .12em;
    animation: ugarit-number-feedback 520ms var(--ugarit-motion-ease);
  }

  .ugarit-motion-ready :is(button, .button) {
    transition:
      background-color var(--ugarit-motion-fast) ease-out,
      border-color var(--ugarit-motion-fast) ease-out,
      color var(--ugarit-motion-fast) ease-out,
      box-shadow 180ms ease-out,
      transform 120ms var(--ugarit-motion-ease);
  }
  .ugarit-motion-ready :is(button, .button):not(:disabled):not([aria-disabled="true"]):active {
    background-color: var(--ugarit-motion-press);
    border-color: var(--ugarit-motion-press);
    color: var(--ugarit-motion-ink);
    transform: translateY(1px);
  }
  .ugarit-motion-ready :is(button, .button):is(:disabled, [aria-disabled="true"]) {
    transform: none;
  }

  /* Navigation responds to the real selected state with no looping pulse. */
  .ugarit-motion-ready .sidebar nav button.selected {
    box-shadow: inset 3px 0 0 #76568b;
  }
  .ugarit-motion-ready .mobile-bottom-nav button.selected {
    box-shadow: inset 0 -2px 0 #76568b;
  }
  .ugarit-motion-ready :is(.sidebar nav, .mobile-bottom-nav) button.selected > svg {
    animation: ugarit-page-appear 200ms ease-out;
  }
  .ugarit-motion-ready .segmented button.active {
    transition:
      background-color 160ms ease-out,
      color 160ms ease-out,
      box-shadow 160ms ease-out;
  }

  /* Opening is brief; focusing any dialog field immediately ends its movement. */
  .ugarit-motion-ready .overlay {
    animation: ugarit-page-appear 150ms ease-out;
  }
  .ugarit-motion-ready .overlay > .modal {
    animation: ugarit-dialog-appear 210ms var(--ugarit-motion-ease) backwards;
  }
  .ugarit-motion-ready .overlay > .modal:focus-within {
    animation: none;
  }
  .ugarit-motion-ready :is(.entry-options, .lookup-options, .quantity-item-options) {
    animation: ugarit-page-appear 130ms ease-out;
  }

  .ugarit-motion-ready .toast {
    animation: ugarit-notice-appear 240ms var(--ugarit-motion-ease) backwards;
  }
  .ugarit-motion-ready .toast > svg {
    animation: ugarit-check-appear 220ms var(--ugarit-motion-ease) 60ms backwards;
  }
  .ugarit-motion-ready .error-banner {
    animation: ugarit-page-appear 180ms ease-out;
  }

  /* State changes tint existing rows without changing their size or position. */
  .ugarit-motion-ready :is(.order-line, .order-card, .staff-notification, .product-open-row) {
    transition:
      background-color 200ms ease-out,
      border-color 200ms ease-out,
      box-shadow 180ms ease-out;
  }

  /* Native progress bars remain semantic. A custom fill is also available for
   * browsers where native progress interpolation is limited. Its owner sets
   * the exact width and the containing progressbar's accessible values.
   */
  .ugarit-motion-ready progress::-webkit-progress-value {
    transition: width 440ms var(--ugarit-motion-ease);
  }
  .ugarit-motion-ready progress::-moz-progress-bar {
    transition: width 440ms var(--ugarit-motion-ease);
  }
  .ugarit-motion-ready .ugarit-progress-track {
    display: block;
    width: 100%;
    height: 7px;
    overflow: hidden;
    border: 0;
    border-radius: 12px;
    background-color: #eee8f2;
  }
  .ugarit-motion-ready .order-card .ugarit-progress-track {
    margin: 19px 0 12px;
  }
  .ugarit-motion-ready .order-progress-copy .ugarit-progress-track {
    margin: 10px 0 5px;
  }
  .ugarit-motion-ready .ugarit-progress-fill {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: inherit;
    background-color: var(--ugarit-progress-color, #6c477e);
    transform-origin: left center;
    transition:
      width 440ms var(--ugarit-motion-ease),
      transform 500ms var(--ugarit-motion-ease),
      background-color 200ms ease-out;
  }

  .ugarit-motion-ready .ugarit-save-status {
    position: fixed;
    right: 24px;
    bottom: calc(90px + env(safe-area-inset-bottom, 0px));
    z-index: 250;
    display: inline-flex;
    align-items: center;
    gap: 9px;
    max-width: calc(100vw - 28px);
    padding: 10px 15px;
    border: 1px solid #e3dbe8;
    border-radius: 999px;
    background: #fff;
    color: var(--ugarit-motion-ink);
    font-size: 12px;
    font-weight: 600;
    line-height: 1.4;
    box-shadow: 0 4px 20px #45215314;
    pointer-events: none;
    animation: ugarit-page-appear 160ms ease-out;
  }
  .ugarit-motion-ready .ugarit-save-status > .spinner {
    flex: 0 0 14px;
    width: 14px;
    height: 14px;
    border-width: 2px;
  }

  /* Infinite animation is reserved for an actual operation in progress. */
  .ugarit-motion-ready .spinner {
    animation: ugarit-working 800ms linear infinite;
  }
  .ugarit-motion-ready .ugarit-busy {
    cursor: progress;
  }
  .ugarit-motion-ready .ugarit-busy > :is(.lucide-loader, .lucide-loader-circle, .lucide-loader-2, .lucide-refresh-cw) {
    animation: ugarit-working 800ms linear infinite;
  }
  .ugarit-motion-ready button.ugarit-busy:not(:has(.spinner, .lucide-loader, .lucide-loader-circle, .lucide-loader-2, .lucide-refresh-cw))::after {
    content: "";
    display: inline-block;
    flex: 0 0 12px;
    width: 12px;
    height: 12px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    vertical-align: -.1em;
    animation: ugarit-working 800ms linear infinite;
  }
}

@media screen and (hover: hover) and (pointer: fine) {
  .ugarit-motion-ready :is(.executive-stats, .order-summary-grid) > button:not(:disabled):hover {
    border-color: #cfc0db;
    box-shadow: 0 5px 16px #4521530d;
  }
  .ugarit-motion-ready :is(.brand-card, .quick-links > button):not(:disabled):hover {
    border-color: #cfc0db;
    box-shadow: 0 4px 14px #4521530c;
  }
  .ugarit-motion-ready .order-card:has(.order-card-open:hover) {
    box-shadow: 0 5px 18px #4521530b;
  }
}

@media screen and (max-width: 760px) {
  .ugarit-motion-ready .sidebar {
    transition: transform 220ms var(--ugarit-motion-ease);
  }
  .ugarit-motion-ready .overlay > .modal {
    /* Mobile dialogs fill the screen; use a fade so fields stay aligned. */
    animation-name: ugarit-page-appear;
    animation-duration: 180ms;
  }
  .ugarit-motion-ready .ugarit-save-status {
    right: 14px;
    bottom: calc(86px + env(safe-area-inset-bottom, 0px));
  }
}

@keyframes ugarit-page-appear {
  from { opacity: .45; }
  to { opacity: 1; }
}
@keyframes ugarit-card-appear {
  from { opacity: .45; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
@keyframes ugarit-dialog-appear {
  from { opacity: .4; transform: translateY(7px); }
  to { opacity: 1; transform: none; }
}
@keyframes ugarit-notice-appear {
  from { opacity: .35; transform: translateY(5px); }
  to { opacity: 1; transform: none; }
}
@keyframes ugarit-check-appear {
  from { opacity: .5; transform: scale(.84); }
  to { opacity: 1; transform: none; }
}
@keyframes ugarit-number-feedback {
  0% { background-color: #fff1b8; }
  100% { background-color: transparent; }
}
@keyframes ugarit-working {
  to { transform: rotate(1turn); }
}

/* Applies to this layer and the application's pre-existing animation rules.
 * The counter component must also use matchMedia to skip numeric interpolation.
 * Do not reset every transform: the mobile sidebar uses one for its position.
 */
@media (prefers-reduced-motion: reduce) {
  .ugarit-motion-ready,
  .ugarit-motion-ready *,
  .ugarit-motion-ready *::before,
  .ugarit-motion-ready *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
  .ugarit-motion-ready :is(button, .button):active {
    transform: none !important;
  }
  .ugarit-motion-ready progress::-webkit-progress-value {
    transition: none !important;
  }
  .ugarit-motion-ready progress::-moz-progress-bar {
    transition: none !important;
  }
}

/* Leave the established quotation, packing and shelf-card print rules intact. */
@media print {
  .ugarit-motion-ready,
  .ugarit-motion-ready *,
  .ugarit-motion-ready *::before,
  .ugarit-motion-ready *::after {
    animation: none !important;
    transition: none !important;
  }
  .ugarit-motion-ready :is(.ugarit-page-enter, .ugarit-number-changed) {
    opacity: 1 !important;
    transform: none !important;
    background-color: transparent !important;
  }
  .ugarit-motion-ready button.ugarit-busy::after {
    display: none !important;
  }
  .ugarit-motion-ready .ugarit-save-status {
    display: none !important;
  }
  .ugarit-motion-ready .ugarit-number-visual {
    display: none !important;
  }
  .ugarit-motion-ready .ugarit-animated-number .ugarit-number-final {
    display: inline !important;
    position: static !important;
    width: auto !important;
    height: auto !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: visible !important;
    clip: auto !important;
    clip-path: none !important;
    white-space: normal !important;
    border: 0 !important;
  }
  .ugarit-motion-ready progress::-webkit-progress-value {
    transition: none !important;
  }
  .ugarit-motion-ready progress::-moz-progress-bar {
    transition: none !important;
  }
}
