/* Progress tray (static/js/portal_progress_tray.js): uploads and background jobs, bottom right,
   kept across page loads. Built on the design tokens in base.css. */

.portal-progress-tray {
  --progress-tray-bg: var(--deal-landing-card-bg, #fffefb);
  --progress-tray-border: var(--color-border, #d2dee8);
  --progress-tray-track: rgba(44, 70, 104, 0.1);
  --progress-tray-fill: var(--color-midnight, #2c4668);
  position: fixed;
  right: var(--space-4, 16px);
  bottom: calc(var(--space-4, 16px) + var(--progress-tray-offset, 0px) + env(safe-area-inset-bottom, 0px));
  z-index: 1080; /* above Bootstrap modals (1055) and the cookie notice */
  width: min(22rem, calc(100vw - 2 * var(--space-4, 16px)));
  max-height: min(60vh, 28rem);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--progress-tray-border);
  border-radius: var(--radius-md, 10px);
  background: var(--progress-tray-bg);
  box-shadow: var(--shadow-3, 0 16px 40px rgba(44, 70, 104, 0.16));
  color: var(--color-text);
  font-size: var(--text-sm, 13px);
}

.portal-progress-tray__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2, 8px);
  padding: var(--space-2, 8px) var(--space-3, 12px);
  border-bottom: 1px solid var(--progress-tray-border);
}

.portal-progress-tray.is-collapsed .portal-progress-tray__header {
  border-bottom: 0;
}

.portal-progress-tray__title {
  margin: 0;
  font-size: var(--text-sm, 13px);
  font-weight: var(--weight-semibold, 600);
}

.portal-progress-tray__toggle,
.portal-progress-item__action {
  padding: 2px var(--space-2, 8px);
  border: 0;
  border-radius: var(--radius-pill, 999px);
  background: transparent;
  color: var(--color-text);
  font-size: var(--text-xs, 12px);
  font-weight: var(--weight-medium, 500);
  cursor: pointer;
}

.portal-progress-tray__toggle:hover,
.portal-progress-item__action:hover {
  background: var(--progress-tray-track);
}

.portal-progress-tray__toggle:focus-visible,
.portal-progress-item__action:focus-visible,
.portal-progress-item__link:focus-visible {
  outline: none;
  box-shadow: var(--nav-focus-ring, 0 0 0 2px rgba(200, 164, 77, 0.45));
}

.portal-progress-tray__list {
  margin: 0;
  padding: var(--space-1, 4px) 0;
  overflow-y: auto;
  list-style: none;
}

.portal-progress-tray.is-collapsed .portal-progress-tray__list {
  display: none;
}

.portal-progress-item {
  display: flex;
  flex-direction: column;
  gap: var(--space-1, 4px);
  padding: var(--space-2, 8px) var(--space-3, 12px);
}

.portal-progress-item + .portal-progress-item {
  border-top: 1px solid var(--progress-tray-border);
}

.portal-progress-item__top,
.portal-progress-item__bottom {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2, 8px);
  min-width: 0;
}

.portal-progress-item__label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: var(--weight-medium, 500);
}

.portal-progress-item__status {
  flex: 0 0 auto;
  font-size: var(--text-xs, 12px);
  font-weight: var(--weight-medium, 500);
  color: var(--color-text-muted, #6d665c);
}

.portal-progress-item--done .portal-progress-item__status {
  color: var(--status-done, #0b5c2c);
}

.portal-progress-item--failed .portal-progress-item__status,
.portal-progress-item--interrupted .portal-progress-item__status {
  color: var(--status-attention, #b42318);
}

.portal-progress-item__detail {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow-wrap: anywhere;
  font-size: var(--text-xs, 12px);
  color: var(--color-text-muted, #6d665c);
}

.portal-progress-item__bottom {
  justify-content: flex-end;
}

.portal-progress-item__actions {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: var(--space-1, 4px);
}

.portal-progress-item__link {
  font-size: var(--text-xs, 12px);
  font-weight: var(--weight-medium, 500);
  color: var(--color-text);
}

.portal-progress-item__bar {
  position: relative;
  height: 4px;
  overflow: hidden;
  border-radius: var(--radius-pill, 999px);
  background: var(--progress-tray-track);
}

.portal-progress-item__fill {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--progress-tray-fill);
  transition: width 0.2s ease;
}

.portal-progress-item__bar.is-indeterminate .portal-progress-item__fill {
  width: 35%;
  animation: portal-progress-indeterminate 1.4s ease-in-out infinite;
}

@keyframes portal-progress-indeterminate {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(290%); }
}

@media (prefers-reduced-motion: reduce) {
  .portal-progress-item__bar.is-indeterminate .portal-progress-item__fill {
    width: 100%;
    animation: none;
    opacity: 0.4;
  }
}

body.theme-dark .portal-progress-tray {
  --progress-tray-bg: var(--deal-landing-card-bg, var(--color-surface, #1b2533));
  --progress-tray-track: rgba(255, 255, 255, 0.1);
  --progress-tray-fill: var(--color-gold, #e6be78);
}

@media (max-width: 575.98px) {
  .portal-progress-tray {
    right: var(--space-2, 8px);
    left: var(--space-2, 8px);
    width: auto;
    bottom: calc(var(--space-2, 8px) + var(--progress-tray-offset, 0px) + env(safe-area-inset-bottom, 0px));
  }
}
