/* ==========================================================================
   Idun Hub — shared interaction layer
   Motion, feedback and small components used by both the storefront and the
   merchant workspace. Everything here is additive: it never restyles an
   existing selector, it only gives the apps a vocabulary for feeling finished.

   Every animation is opt-out via prefers-reduced-motion. Motion is here to
   explain what changed, never to decorate.
   ========================================================================== */

: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.56, 0.64, 1);
  --dur-fast: 140ms;
  --dur: 240ms;
  --dur-slow: 420ms;
  --z-toast: 900;
  --z-overlay: 800;
  --z-dialog: 850;
}

/* --------------------------------------------------------------------------
   Keyframes
   -------------------------------------------------------------------------- */

@keyframes idun-rise {
  from { opacity: 0; transform: translate3d(0, 10px, 0); }
  to   { opacity: 1; transform: none; }
}

@keyframes idun-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes idun-scale-in {
  from { opacity: 0; transform: translate3d(0, 12px, 0) scale(0.985); }
  to   { opacity: 1; transform: none; }
}

@keyframes idun-slide-from-right {
  from { opacity: 0; transform: translate3d(28px, 0, 0); }
  to   { opacity: 1; transform: none; }
}

@keyframes idun-toast-in {
  from { opacity: 0; transform: translate3d(0, 14px, 0) scale(0.97); }
  to   { opacity: 1; transform: none; }
}

@keyframes idun-toast-out {
  from { opacity: 1; transform: none; }
  to   { opacity: 0; transform: translate3d(0, -8px, 0) scale(0.97); }
}

@keyframes idun-shimmer {
  from { background-position: -160% 0; }
  to   { background-position: 260% 0; }
}

@keyframes idun-spin {
  to { transform: rotate(360deg); }
}

@keyframes idun-pulse-ring {
  0%   { box-shadow: 0 0 0 0 rgba(35, 115, 91, 0.35); }
  70%  { box-shadow: 0 0 0 10px rgba(35, 115, 91, 0); }
  100% { box-shadow: 0 0 0 0 rgba(35, 115, 91, 0); }
}

@keyframes idun-check-draw {
  to { stroke-dashoffset: 0; }
}

/* --------------------------------------------------------------------------
   Entrance choreography
   A view that changes should say so. Panels rise, and their children follow in
   a short stagger so the eye lands on the top of the list first.
   -------------------------------------------------------------------------- */

.view.is-active,
[data-view-panel].is-active {
  animation: idun-rise var(--dur-slow) var(--ease-out) both;
}

.u-stagger > * {
  animation: idun-rise 380ms var(--ease-out) both;
}
.u-stagger > *:nth-child(1) { animation-delay: 0ms; }
.u-stagger > *:nth-child(2) { animation-delay: 45ms; }
.u-stagger > *:nth-child(3) { animation-delay: 90ms; }
.u-stagger > *:nth-child(4) { animation-delay: 135ms; }
.u-stagger > *:nth-child(5) { animation-delay: 175ms; }
.u-stagger > *:nth-child(6) { animation-delay: 210ms; }
.u-stagger > *:nth-child(7) { animation-delay: 240ms; }
.u-stagger > *:nth-child(8) { animation-delay: 265ms; }
.u-stagger > *:nth-child(n + 9) { animation-delay: 285ms; }

.u-rise { animation: idun-rise 380ms var(--ease-out) both; }
.u-fade { animation: idun-fade var(--dur) var(--ease-out) both; }

/* --------------------------------------------------------------------------
   Interactive feedback
   -------------------------------------------------------------------------- */

button,
a,
.record,
.table-action,
input,
select,
textarea {
  transition:
    background-color var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-fast) var(--ease-out),
    transform var(--dur-fast) var(--ease-out),
    opacity var(--dur-fast) var(--ease-out);
}

.primary-button:not(:disabled):hover,
.secondary-button:not(:disabled):hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(16, 44, 37, 0.14);
}

.primary-button:not(:disabled):active,
.secondary-button:not(:disabled):active,
.table-action:not(:disabled):active {
  transform: translateY(0) scale(0.985);
  box-shadow: none;
}

button:disabled,
.primary-button:disabled,
.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none !important;
  box-shadow: none !important;
}

/* A visible, consistent focus ring for keyboard users only. */
:where(button, a, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--leaf, #23735b);
  outline-offset: 2px;
  border-radius: 6px;
}

.nav-item {
  position: relative;
}

.nav-item::before {
  background: var(--lime, #d9ef6f);
  border-radius: 0 3px 3px 0;
  content: "";
  height: 0;
  left: -0.75rem;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  transition: height var(--dur) var(--ease-spring);
  width: 3px;
}

.nav-item.is-active::before { height: 60%; }

.nav-item:not(.is-active):hover {
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.9);
}

/* --------------------------------------------------------------------------
   Busy states
   -------------------------------------------------------------------------- */

.is-busy {
  pointer-events: none;
  position: relative;
  color: transparent !important;
}

.is-busy::after {
  animation: idun-spin 620ms linear infinite;
  border: 2px solid currentColor;
  border-radius: 50%;
  border-top-color: transparent;
  color: #fff;
  content: "";
  height: 15px;
  left: 50%;
  margin: -7.5px 0 0 -7.5px;
  position: absolute;
  top: 50%;
  width: 15px;
}

.secondary-button.is-busy::after,
.table-action.is-busy::after { color: var(--leaf, #23735b); }

.u-spinner {
  animation: idun-spin 620ms linear infinite;
  border: 2px solid var(--line, #dfe4df);
  border-radius: 50%;
  border-top-color: var(--leaf, #23735b);
  display: inline-block;
  height: 16px;
  width: 16px;
}

/* --------------------------------------------------------------------------
   Skeletons — shown while data is in flight so a panel is never blank.
   -------------------------------------------------------------------------- */

.u-skeleton {
  animation: idun-shimmer 1.5s linear infinite;
  background: linear-gradient(
    100deg,
    rgba(20, 41, 35, 0.06) 20%,
    rgba(20, 41, 35, 0.12) 42%,
    rgba(20, 41, 35, 0.06) 62%
  );
  background-size: 240% 100%;
  border-radius: 7px;
  display: block;
  height: 0.85rem;
}

.u-skeleton + .u-skeleton { margin-top: 0.55rem; }
.u-skeleton--title { height: 1.15rem; width: 42%; }
.u-skeleton--line { width: 100%; }
.u-skeleton--short { width: 58%; }
.u-skeleton--chip { border-radius: 999px; height: 1.5rem; width: 5.5rem; }
.u-skeleton--block { height: 4.5rem; }
.u-skeleton--thumb { border-radius: 10px; height: 3rem; width: 3rem; }

.u-skeleton-row {
  align-items: center;
  border-bottom: 1px solid var(--line, #dfe4df);
  display: grid;
  gap: 0.9rem;
  grid-template-columns: 3rem 1fr 6rem;
  padding: 0.9rem 0;
}

.u-skeleton-card {
  border: 1px solid var(--line, #dfe4df);
  border-radius: 12px;
  padding: 1.1rem;
}

/* --------------------------------------------------------------------------
   Toasts — transient confirmation that an action landed.
   -------------------------------------------------------------------------- */

.u-toasts {
  bottom: 1.25rem;
  display: grid;
  gap: 0.6rem;
  justify-items: end;
  left: 1.25rem;
  pointer-events: none;
  position: fixed;
  right: 1.25rem;
  z-index: var(--z-toast);
}

@media (min-width: 720px) {
  .u-toasts { left: auto; justify-items: end; width: min(420px, 40vw); }
}

.u-toast {
  align-items: flex-start;
  animation: idun-toast-in 320ms var(--ease-spring) both;
  background: var(--paper, #fffefa);
  border: 1px solid var(--line, #dfe4df);
  border-left: 3px solid var(--leaf, #23735b);
  border-radius: 11px;
  box-shadow: 0 18px 44px rgba(16, 44, 37, 0.18);
  color: var(--ink, #142923);
  display: grid;
  gap: 0.15rem 0.75rem;
  grid-template-columns: 20px 1fr auto;
  max-width: 100%;
  padding: 0.85rem 0.95rem;
  pointer-events: auto;
  width: 100%;
}

.u-toast.is-leaving { animation: idun-toast-out 200ms var(--ease-in-out) both; }
.u-toast--error { border-left-color: var(--rust, #b94e31); }
.u-toast--warn { border-left-color: var(--amber, #a86f14); }

.u-toast__icon {
  align-items: center;
  display: flex;
  height: 20px;
  justify-content: center;
  width: 20px;
}

.u-toast__icon svg { height: 18px; width: 18px; }
.u-toast__icon svg path,
.u-toast__icon svg circle {
  fill: none;
  stroke: var(--leaf, #23735b);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}
.u-toast--error .u-toast__icon svg path,
.u-toast--error .u-toast__icon svg circle { stroke: var(--rust, #b94e31); }
.u-toast--warn .u-toast__icon svg path,
.u-toast--warn .u-toast__icon svg circle { stroke: var(--amber, #a86f14); }

.u-toast__icon .u-check {
  stroke-dasharray: 24;
  stroke-dashoffset: 24;
  animation: idun-check-draw 380ms var(--ease-out) 120ms forwards;
}

.u-toast__body { font-size: 0.8rem; font-weight: 600; line-height: 1.45; min-width: 0; }
.u-toast__detail {
  color: var(--muted, #66756f);
  font-size: 0.72rem;
  font-weight: 500;
  grid-column: 2;
  line-height: 1.5;
  margin-top: 0.15rem;
}

.u-toast__close {
  align-self: start;
  background: transparent;
  border: 0;
  color: var(--muted, #66756f);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0.1rem 0.2rem;
}

.u-toast__close:hover { color: var(--ink, #142923); }

/* --------------------------------------------------------------------------
   Empty states — every list says what to do next, not just "nothing here".
   -------------------------------------------------------------------------- */

.u-empty {
  animation: idun-rise 380ms var(--ease-out) both;
  display: grid;
  gap: 0.35rem;
  justify-items: center;
  padding: 2.6rem 1.5rem;
  text-align: center;
}

.u-empty__art {
  color: var(--leaf, #23735b);
  height: 46px;
  margin-bottom: 0.5rem;
  opacity: 0.55;
  width: 46px;
}

.u-empty__art svg { height: 100%; width: 100%; }
.u-empty__art svg path,
.u-empty__art svg circle,
.u-empty__art svg rect {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.4;
}

.u-empty__title {
  color: var(--ink, #142923);
  font-size: 0.9rem;
  font-weight: 700;
  margin: 0;
}

.u-empty__hint {
  color: var(--muted, #66756f);
  font-size: 0.78rem;
  line-height: 1.6;
  margin: 0;
  max-width: 34ch;
}

.u-empty__action { margin-top: 0.9rem; }

/* --------------------------------------------------------------------------
   Pagination
   -------------------------------------------------------------------------- */

.u-pager {
  align-items: center;
  border-top: 1px solid var(--line, #dfe4df);
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: space-between;
  padding: 0.9rem 0 0.2rem;
}

.u-pager__count {
  color: var(--muted, #66756f);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
}

.u-pager__controls { align-items: center; display: flex; gap: 0.4rem; }

.u-pager__button {
  background: #fff;
  border: 1px solid var(--line, #dfe4df);
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.74rem;
  font-weight: 700;
  min-height: 36px;
  padding: 0 0.8rem;
}

.u-pager__button:not(:disabled):hover {
  border-color: var(--leaf, #23735b);
  color: var(--leaf, #23735b);
}

.u-pager__page {
  color: var(--muted, #66756f);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  padding: 0 0.4rem;
}

/* --------------------------------------------------------------------------
   Image dropzone and gallery
   -------------------------------------------------------------------------- */

.u-dropzone {
  align-items: center;
  background: rgba(35, 115, 91, 0.03);
  border: 1.5px dashed var(--line, #dfe4df);
  border-radius: 12px;
  cursor: pointer;
  display: grid;
  gap: 0.3rem;
  justify-items: center;
  min-height: 116px;
  padding: 1.1rem;
  text-align: center;
  transition: border-color var(--dur) var(--ease-out), background var(--dur) var(--ease-out),
    transform var(--dur) var(--ease-out);
}

.u-dropzone:hover,
.u-dropzone.is-dragging {
  background: rgba(35, 115, 91, 0.07);
  border-color: var(--leaf, #23735b);
}

.u-dropzone.is-dragging { transform: scale(1.01); }

.u-dropzone__icon { color: var(--leaf, #23735b); height: 26px; opacity: 0.7; width: 26px; }
.u-dropzone__icon svg { height: 100%; width: 100%; }
.u-dropzone__icon svg path {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.5;
}

.u-dropzone__title { font-size: 0.8rem; font-weight: 700; }
.u-dropzone__hint { color: var(--muted, #66756f); font-size: 0.7rem; line-height: 1.5; }
.u-dropzone input[type="file"] { display: none; }

.u-gallery {
  display: grid;
  gap: 0.6rem;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  margin-top: 0.75rem;
}

.u-gallery__item {
  animation: idun-scale-in 320ms var(--ease-spring) both;
  aspect-ratio: 1;
  background: var(--cream, #f4f1e9);
  border: 1px solid var(--line, #dfe4df);
  border-radius: 10px;
  overflow: hidden;
  position: relative;
}

.u-gallery__item img { height: 100%; object-fit: cover; width: 100%; }

.u-gallery__item.is-primary { border-color: var(--leaf, #23735b); box-shadow: 0 0 0 2px rgba(35, 115, 91, 0.18); }

.u-gallery__badge {
  background: var(--forest, #102c25);
  border-radius: 999px;
  color: var(--lime, #d9ef6f);
  font-size: 0.55rem;
  font-weight: 800;
  left: 5px;
  letter-spacing: 0.06em;
  padding: 0.16rem 0.4rem;
  position: absolute;
  text-transform: uppercase;
  top: 5px;
}

.u-gallery__actions {
  background: linear-gradient(to top, rgba(13, 44, 36, 0.82), rgba(13, 44, 36, 0));
  bottom: 0;
  display: flex;
  gap: 0.25rem;
  justify-content: center;
  left: 0;
  opacity: 0;
  padding: 1.2rem 0.3rem 0.35rem;
  position: absolute;
  right: 0;
  transition: opacity var(--dur) var(--ease-out);
}

.u-gallery__item:hover .u-gallery__actions,
.u-gallery__item:focus-within .u-gallery__actions { opacity: 1; }

.u-gallery__actions button {
  background: rgba(255, 255, 255, 0.92);
  border: 0;
  border-radius: 5px;
  cursor: pointer;
  font-size: 0.6rem;
  font-weight: 700;
  padding: 0.22rem 0.42rem;
}

.u-gallery__actions button:hover { background: #fff; }

.u-upload-progress {
  background: rgba(20, 41, 35, 0.1);
  border-radius: 999px;
  height: 3px;
  margin-top: 0.6rem;
  overflow: hidden;
}

.u-upload-progress span {
  background: var(--leaf, #23735b);
  display: block;
  height: 100%;
  transition: width 200ms var(--ease-out);
  width: 0;
}

/* --------------------------------------------------------------------------
   Small shared pieces
   -------------------------------------------------------------------------- */

.u-chip {
  align-items: center;
  border: 1px solid var(--line, #dfe4df);
  border-radius: 999px;
  display: inline-flex;
  font-size: 0.66rem;
  font-weight: 700;
  gap: 0.3rem;
  padding: 0.24rem 0.6rem;
}

.u-chip--ok { background: rgba(35, 115, 91, 0.1); border-color: rgba(35, 115, 91, 0.3); color: var(--leaf, #23735b); }
.u-chip--warn { background: rgba(168, 111, 20, 0.1); border-color: rgba(168, 111, 20, 0.3); color: var(--amber, #a86f14); }
.u-chip--bad { background: rgba(185, 78, 49, 0.1); border-color: rgba(185, 78, 49, 0.3); color: var(--rust, #b94e31); }

.u-dot {
  border-radius: 50%;
  display: inline-block;
  height: 6px;
  width: 6px;
}

.u-dot--live { animation: idun-pulse-ring 2.2s var(--ease-out) infinite; background: var(--leaf, #23735b); }

.u-count {
  font-variant-numeric: tabular-nums;
  transition: color var(--dur) var(--ease-out);
}

.u-count.is-updating { color: var(--leaf, #23735b); }

.u-timeline { display: grid; gap: 0; position: relative; }

.u-timeline__item {
  animation: idun-rise 340ms var(--ease-out) both;
  display: grid;
  gap: 0.15rem;
  grid-template-columns: 22px 1fr;
  padding-bottom: 1.1rem;
  position: relative;
}

.u-timeline__item::before {
  background: var(--line, #dfe4df);
  bottom: 0;
  content: "";
  left: 6px;
  position: absolute;
  top: 14px;
  width: 1px;
}

.u-timeline__item:last-child::before { display: none; }

.u-timeline__marker {
  background: var(--paper, #fffefa);
  border: 2px solid var(--line, #dfe4df);
  border-radius: 50%;
  grid-row: 1 / span 2;
  height: 13px;
  margin-top: 3px;
  width: 13px;
  z-index: 1;
}

.u-timeline__item.is-current .u-timeline__marker {
  animation: idun-pulse-ring 2.4s var(--ease-out) infinite;
  background: var(--leaf, #23735b);
  border-color: var(--leaf, #23735b);
}

.u-timeline__item.is-done .u-timeline__marker { background: var(--leaf, #23735b); border-color: var(--leaf, #23735b); }
.u-timeline__title { font-size: 0.82rem; font-weight: 700; }
.u-timeline__meta { color: var(--muted, #66756f); font-size: 0.7rem; grid-column: 2; }

/* Reveal-on-scroll, applied by ui.js where an IntersectionObserver is available. */
.u-reveal { opacity: 0; transform: translate3d(0, 16px, 0); }
.u-reveal.is-visible {
  opacity: 1;
  transform: none;
  transition: opacity 520ms var(--ease-out), transform 520ms var(--ease-out);
}

/* --------------------------------------------------------------------------
   Confirmation dialog — used before anything destructive or irreversible.
   -------------------------------------------------------------------------- */

.u-confirm-backdrop {
  align-items: center;
  animation: idun-fade 180ms var(--ease-out) both;
  backdrop-filter: blur(3px);
  background: rgba(13, 44, 36, 0.42);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 1.25rem;
  position: fixed;
  z-index: var(--z-dialog);
}

.u-confirm-backdrop.is-leaving { animation: idun-fade 160ms var(--ease-in-out) reverse both; }

.u-confirm {
  animation: idun-scale-in 260ms var(--ease-spring) both;
  background: var(--paper, #fffefa);
  border-radius: 16px;
  box-shadow: 0 30px 80px rgba(13, 44, 36, 0.3);
  max-width: 26rem;
  padding: 1.6rem;
  width: 100%;
}

.u-confirm h2 {
  font-family: var(--serif, Georgia, serif);
  font-size: 1.3rem;
  letter-spacing: -0.02em;
  margin: 0 0 0.5rem;
}

.u-confirm p {
  color: var(--muted, #66756f);
  font-size: 0.82rem;
  line-height: 1.6;
  margin: 0;
}

.u-confirm__reason { display: grid; gap: 0.4rem; margin-top: 1.1rem; }
.u-confirm__reason span { font-size: 0.72rem; font-weight: 700; }
.u-confirm__reason input.has-error {
  border-color: var(--rust, #b94e31);
  box-shadow: 0 0 0 3px rgba(185, 78, 49, 0.12);
}

.u-confirm__actions {
  display: flex;
  gap: 0.6rem;
  justify-content: flex-end;
  margin-top: 1.4rem;
}

.primary-button.is-danger {
  background: var(--rust, #b94e31);
  border-color: var(--rust, #b94e31);
}

.primary-button.is-danger:hover { background: #a34428; border-color: #a34428; }

/* --------------------------------------------------------------------------
   Reduced motion — honour the system preference completely.
   Elements still arrive at their final state; they simply stop moving to it.
   -------------------------------------------------------------------------- */

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

  .u-reveal { opacity: 1; transform: none; }

  .primary-button:not(:disabled):hover,
  .secondary-button:not(:disabled):hover { transform: none; }
}
